I know there is formula for going RGB -> Luminance, but I need given a brightness parameter to modify the RGB values of an image. How do I do that?
Thanks
The easiest way is to multiply each of the R,G,B values by some constant - if the constant is >1 it will make it brighter, and if <1 it will be darker. If you're making it brighter then you must test each value to make sure it doesn't go over the maximum (usually 255).
Not only is this simpler than the translation from RGB to HSL and back again, but it more closely approximates what happens when you shine a different amount of light at a physical object.
Adding to Mark Ransom's Answer: It would be better to use the said factor with a 255 constant and add it to the current color-value:
float brightnessFac = //between -1.0 and 1.0
byte brightnessRed = red + (255f * brightnessFac);
If you just do with a factor between 0.0 and 1.0
byte brightnessRed = red * brightnessFac;
A value of 0 stays zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With