Skip to content

Commit

Permalink
REVIEWED: ColorLerp() formatting #4310
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Sep 15, 2024
1 parent 68e7cad commit b807f63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1431,11 +1431,11 @@ RLAPI Color ColorBrightness(Color color, float factor); // G
RLAPI Color ColorContrast(Color color, float contrast); // Get color with contrast correction, contrast values between -1.0f and 1.0f
RLAPI Color ColorAlpha(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f
RLAPI Color ColorAlphaBlend(Color dst, Color src, Color tint); // Get src alpha-blended into dst color with tint
RLAPI Color ColorLerp(Color color1, Color color2, float factor); // Get color lerp interpolation between two colors, factor [0.0f..1.0f]
RLAPI Color GetColor(unsigned int hexValue); // Get Color structure from hexadecimal value
RLAPI Color GetPixelColor(void *srcPtr, int format); // Get Color from a source pixel pointer of certain format
RLAPI void SetPixelColor(void *dstPtr, Color color, int format); // Set color formatted into destination pixel pointer
RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes for certain format
RLAPI Color ColorLerp(Color color1, Color color2, float d); // Mix 2 Colors Together

//------------------------------------------------------------------------------------
// Font Loading and Text Drawing Functions (Module: text)
Expand Down
34 changes: 16 additions & 18 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -5185,6 +5185,22 @@ Color ColorAlphaBlend(Color dst, Color src, Color tint)
return out;
}

// Get color lerp interpolation between two colors, factor [0.0f..1.0f]
Color ColorLerp(Color color1, Color color2, float factor)
{
Color color = { 0 };

if (d < 0) d = 0.0f;
else if (d > 1) d = 1.0f;

color.r = (unsigned char)((1.0f - factor)*color1.r + factor*color2.r);
color.g = (unsigned char)((1.0f - factor)*color1.g + factor*color2.g);
color.b = (unsigned char)((1.0f - factor)*color1.b + factor*color2.b);
color.a = (unsigned char)((1.0f - factor)*color1.a + factor*color2.a);

return color;
}

// Get a Color struct from hexadecimal value
Color GetColor(unsigned int hexValue)
{
Expand Down Expand Up @@ -5424,24 +5440,6 @@ int GetPixelDataSize(int width, int height, int format)
return dataSize;
}


// Mix 2 Colors togehter.
// d = dominance. 0.5 for equal
Color ColorLerp(Color color1, Color color2, float d)
{
Color newColor = { 0, 0, 0, 0 };
if (d < 0) {d=0.0f;}
else if(d>1) {d=1.0f;}

newColor.r = (unsigned char)((1.0f-d) * color1.r + d * color2.r);
newColor.g = (unsigned char)((1.0f-d) * color1.g + d * color2.g);
newColor.b = (unsigned char)((1.0f-d) * color1.b + d * color2.b);
newColor.a = (unsigned char)((1.0f-d) * color1.a + d * color2.a);

return newColor;
}


//----------------------------------------------------------------------------------
// Module specific Functions Definition
//----------------------------------------------------------------------------------
Expand Down

0 comments on commit b807f63

Please sign in to comment.