Browse Source

REVIEWED: `ColorLerp()` formatting #4310

Ray 11 months ago
parent
commit
b807f633d9
2 changed files with 17 additions and 19 deletions
  1. 1 1
      src/raylib.h
  2. 16 18
      src/rtextures.c

+ 1 - 1
src/raylib.h

@@ -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 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 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 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 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 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 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 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)
 // Font Loading and Text Drawing Functions (Module: text)

+ 16 - 18
src/rtextures.c

@@ -5185,6 +5185,22 @@ Color ColorAlphaBlend(Color dst, Color src, Color tint)
     return out;
     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
 // Get a Color struct from hexadecimal value
 Color GetColor(unsigned int hexValue)
 Color GetColor(unsigned int hexValue)
 {
 {
@@ -5424,24 +5440,6 @@ int GetPixelDataSize(int width, int height, int format)
     return dataSize;
     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
 // Module specific Functions Definition
 //----------------------------------------------------------------------------------
 //----------------------------------------------------------------------------------