Search code examples
c#mathcolorsformulaphotoshop

How to replicate Photoshop's increase brightness operation?


I have figured out how to increase the "Value" of a color by using HSV, now I was looking into the formula photoshop uses for the operation increase brightness.

In photoshop there is an option to increase brightness: Image > Adjustments > Brightness/Contrast

here are the results of using brightness VS increasing value in HSV: enter image description here

As you see the brightness operation is treating each shade of color in a different way while the value operation is increasing the value of each color at a flat rate, as such the result on the bottom produces more "washed with white" colors than when increasing brightness.

I wonder if anyone could point me in the direction of the formula that is being used here by photoshop when you increase the brightness of a color. I'm interested purely in math, I want to have an input RGB color and an "amount of brightness increase" and return an output RGB color back. ( For reference in the above image I increased the brightness by 150)

I think the answer to this might be valid for any programming language, but for the sake of the argument here is what I am looking for in C# for example:

//ARGB color
public Color m_color = new Color( 255,255,0,255 );

public Color IncreaseBrightness( Color colorToModify, float brightnessAmount ){

newColor = colorToModify;

//Increase brightness RGB values of new color by using brightnessAmount using photoshop's formula (Question at hand)

return newColor ;
}

IncreaseBrightness(m_color ,150f);//should give the results as the above image for any given pixel


Solution

  • Instead of using HSV, you should use HSL (hue, saturation, lightness). You can then adjust the lightness variable.

    First convert the RGB to HSL, then adjust the lightness value, then convert back to RGB (if needed).