laurent
laurent

Reputation: 90776

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).

Upvotes: 4

Views: 2499

Answers (2)

Martin Beckett
Martin Beckett

Reputation: 96109

What do you mean by a pixel?

You can set the brightness of a pixel in an image with '=' you just need to know the memory layout of the image

To set a pixel on the screen is a little more complicated

Upvotes: -1

aioobe
aioobe

Reputation: 421030

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.

Upvotes: 5

Related Questions