Search code examples
algorithmgraphicspixelbrightness

Generic algorithm to get and set the brightness of a pixel?


I've been looking around for a simple algorithm to get and set the brightness of a pixel, but can't find anything - only research papers and complex libraries.

So does anyone know what is the formula to calculate the brightness of a pixel? And which formula should I use to change the brightness?

Edit: to clarify the question. I'm using Qt with C++ but I'm mainly looking for a generic math formula - I will adapt it to the language. I'm talking about RGB pixels of an image in memory. By "brightness", I mean the same as in Photoshop - changing the brightness makes the image more "white" (a brightness value of 1.0 is completely white), decreasing it makes it more "black" (value of 0.0).


Solution

  • Change the color representation to HSV. The V component stands for value and represents the brightness!

    • Here the algorithm implemented in PHP.
    • Here is a description of how to do it in C.