Skip to content

Commit f1368c3

Browse files
committed
ADDED: ColorBrightness()
1 parent 4de64f5 commit f1368c3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/raylib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ RLAPI Vector4 ColorNormalize(Color color); // G
13311331
RLAPI Color ColorFromNormalized(Vector4 normalized); // Get Color from normalized values [0..1]
13321332
RLAPI Vector3 ColorToHSV(Color color); // Get HSV values for a Color, hue [0..360], saturation/value [0..1]
13331333
RLAPI Color ColorFromHSV(float hue, float saturation, float value); // Get a Color from HSV values, hue [0..360], saturation/value [0..1]
1334+
RLAPI Color ColorBrightness(Color color, float factor); // Get color with brightness correction, brightness factor goes from 0.0f to 1.0f
13341335
RLAPI Color ColorAlpha(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f
13351336
RLAPI Color ColorAlphaBlend(Color dst, Color src, Color tint); // Get src alpha-blended into dst color with tint
13361337
RLAPI Color GetColor(unsigned int hexValue); // Get Color structure from hexadecimal value

src/rtextures.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,39 @@ Color ColorFromHSV(float hue, float saturation, float value)
39443944
return color;
39453945
}
39463946

3947+
// Get color with brightness correction, brightness factor goes from 0.0f to 1.0f
3948+
Color ColorBrightness(Color color, float factor)
3949+
{
3950+
Color result = color;
3951+
3952+
if (factor > 1.0f) factor = 1.0f;
3953+
else if (factor < -1.0f) factor = -1.0f;
3954+
3955+
float red = (float)color.r;
3956+
float green = (float)color.g;
3957+
float blue = (float)color.b;
3958+
3959+
if (factor < 0.0f)
3960+
{
3961+
factor = 1.0f + factor;
3962+
red *= factor;
3963+
green *= factor;
3964+
blue *= factor;
3965+
}
3966+
else
3967+
{
3968+
red = (255 - red)*factor + red;
3969+
green = (255 - green)*factor + green;
3970+
blue = (255 - blue)*factor + blue;
3971+
}
3972+
3973+
result.r = (unsigned char)red;
3974+
result.g = (unsigned char)green;
3975+
result.b = (unsigned char)blue;
3976+
3977+
return result;
3978+
}
3979+
39473980
// Get color with alpha applied, alpha goes from 0.0f to 1.0f
39483981
Color ColorAlpha(Color color, float alpha)
39493982
{

0 commit comments

Comments
 (0)