ofImage brightness (brighten/lighten image)

Not sure if this is “beginner” or “expert”. Perhaps somewhere in between? I guess it depends on what oF supports… Anyway:

I’m wondering if it’s possible to relatively easily brighten an image (ofImage)? I’m not seeing a built-in method to control things like brightness/contrast, so I’m guessing it has to be hand-coded.

One thought I had was to overlay a semi-transparent all-white image over the source image that I want to brighten. (Issues: I’d have to somehow mask the all-white image vis-a-vis the alpha channel in my source image so that I’m not just brightening a white rectangle.)

Another thought is to just simply increase each of the red/blue/green channels in the image’s pixel data. That might be an OK compromise, but I don’t think it’s really “true brightening”.

Anyone have any suggestions? Thanks in advance.

This should do it:

  
unsigned char * pix = img.getPixels();  
int brightness = 100;  
  
//for a 3 channel rgb image  
for(int i = 0; i < img.width * img.height * 3; i++){  
    pix[i] += MIN(brightness, 255-pix[i]); //this makes sure it doesn't go over 255 as it will wrap to 0 otherwise.   
}  
  
img.update(); //refresh the image from the pixels.   

Hope that helps
Theo

Thanks theo. That’s definitely on the right track. I think I’ll have to tweak it a bit for my case, since I have an alpha channel too (4-channels instead of 3), but this is a great start. Thanks for your help!