summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2022-12-05 00:24:55 +0100
committerRay <[email protected]>2022-12-05 00:24:55 +0100
commitf1368c36dd38dd912782485ce827fb8b35b86365 (patch)
treec31c5397f0ffce8dbc1c5c8e46dbda01dad5a6fb /src
parent4de64f5750eacd5d7acfb7b41d5b9f251cb502fb (diff)
downloadraylib-f1368c36dd38dd912782485ce827fb8b35b86365.tar.gz
raylib-f1368c36dd38dd912782485ce827fb8b35b86365.zip
ADDED: `ColorBrightness()`
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h1
-rw-r--r--src/rtextures.c33
2 files changed, 34 insertions, 0 deletions
diff --git a/src/raylib.h b/src/raylib.h
index c48380d8..6642bc8d 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -1331,6 +1331,7 @@ RLAPI Vector4 ColorNormalize(Color color); // G
RLAPI Color ColorFromNormalized(Vector4 normalized); // Get Color from normalized values [0..1]
RLAPI Vector3 ColorToHSV(Color color); // Get HSV values for a Color, hue [0..360], saturation/value [0..1]
RLAPI Color ColorFromHSV(float hue, float saturation, float value); // Get a Color from HSV values, hue [0..360], saturation/value [0..1]
+RLAPI Color ColorBrightness(Color color, float factor); // Get color with brightness correction, brightness factor 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 GetColor(unsigned int hexValue); // Get Color structure from hexadecimal value
diff --git a/src/rtextures.c b/src/rtextures.c
index 82de0478..66434c11 100644
--- a/src/rtextures.c
+++ b/src/rtextures.c
@@ -3944,6 +3944,39 @@ Color ColorFromHSV(float hue, float saturation, float value)
return color;
}
+// Get color with brightness correction, brightness factor goes from 0.0f to 1.0f
+Color ColorBrightness(Color color, float factor)
+{
+ Color result = color;
+
+ if (factor > 1.0f) factor = 1.0f;
+ else if (factor < -1.0f) factor = -1.0f;
+
+ float red = (float)color.r;
+ float green = (float)color.g;
+ float blue = (float)color.b;
+
+ if (factor < 0.0f)
+ {
+ factor = 1.0f + factor;
+ red *= factor;
+ green *= factor;
+ blue *= factor;
+ }
+ else
+ {
+ red = (255 - red)*factor + red;
+ green = (255 - green)*factor + green;
+ blue = (255 - blue)*factor + blue;
+ }
+
+ result.r = (unsigned char)red;
+ result.g = (unsigned char)green;
+ result.b = (unsigned char)blue;
+
+ return result;
+}
+
// Get color with alpha applied, alpha goes from 0.0f to 1.0f
Color ColorAlpha(Color color, float alpha)
{