PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Fastest way to create a brightness control

I want to add a brightness setting that will make everything brighter or darker. What is the fastest (performance wise) way to go about doing this?
Fastest way to do this is to apply a brightning filter to all the loaded graphics immediately after gamma has been applied (A simple alpha later over the top of the images may do the job). Then to save that gamma setting and apply the same brightness filter ontop of all new graphics you load in.

You're basically just color shifting the RGBs up, but since the Alphablitter is already highly optimized you may find it faster to just alphablit a white surface with varying levels of transparency on top of things rather then writing your own color shift routines.
Alpha blt with white seems to just wash out the graphics, does anyone know a true way to brighten. (Might be time to go break out the graphics gems books)
The white alpha blit would just adjust brightness of the image. My apologies. Brain fart.

"Gamma correction is a technique to change the brightness of bitmap pictures in a harmonic way. This is being done by multiplying the image's rgb components (r: red, g: green, b: blue) by a factor that depends on their actual values. For the Gamma correction we use this formula:

value_new = pow (value, 1.0 / factor)

This formula works, if rgb had been normalized. By normalization we mean dividing the values by their maximal possible value."

Some ideas to speed up the gamma filter (Since you NEVER want to be doing floating point divides on the PocketPC in time important areas) would be to create a gamma correction table that stores the processed value based on the original un-normalized original color. With 16 bit graphics you may want to create 2 tables, 1 for green, 1 for red and blue. You could even hard-code this tables values to further speed things up (removes the need to generate the table programmatically).

Here's some code to generate the lookup table

Code:

for(i = 0; i< 256; i++)
LUT[i] = (unsigned char) (255.0f * pow((i/255.0), gamma));


Edit:
I should note that this table is currently meant for 24 bit RGB colors where each color component has 256 color shades. With 16-bit you'd want to change the 255.0 and 256, etc. Additionally you could speed up the generation of the gamma table through fixed point arithmetic, though I'd test the time this takes before spending time doing so.

How fast this would be I don't know. A lot of PC cards actually have built in Gamma correction... you could always do like Halflife does. When adjusting gamma they run the filter in realtime on an image to the right of the gamma control.
That's a very nice piece of code.

Does anyone knows how to adjust the color saturation? I suppose there is a formula along the same lines, but I can't seem to locate anything on the web...

Thanks!

--Eric
No, thank you! :)

If you just want to do the classic colorize, GapiDraw has that built into Blt via GDBLTFAST_TINT, GDBLTFAST_TINTOPACITY, GDBLTFAST_COLORIZE, and GDBLTFAST_COLORIZEOPACITY.

If you want per channel hue changes, this is just a guess, but I would think applying the gamma filter to just one or two color channels would work well.
Hmm, I probably didn't explain what I wanted to do properly. Let me start over.

I would like to programatically increase/decrease the color saturation of an image, before I blit it. By saturation I mean the Hue-Saturation-Luminosity kind of saturation.

I was told I needed to extract the HSL from the RGB, increase the saturation and put back the HSL to RGB, but I don't know how to go about it. Isn't there a way to do this without that conversion?

I know this is a bit out of topic, but I would appreciate the help nonetheless.

--Eric
Going back to this topic, has anyone created any gamma adjustment control on their app using gapidraw?
The last gamma adjustment control I saw in a game was for a Jimmy Soft game, which were all done using Jimmy's custom graphics library. I don't recall if his just adjusted the brightness of the backlight or not however.

On the PC gamma is done through the video card so it's nice and fast. In the past it was done through the equations I posted in this article earlier. Obviously an optimized version there of.

If noone else has, I think I'll go ahead and start on one this coming week.
I was just wondering if anyone knows of a good webpage that explains "phoshop like effects" and how they went about them. Basically just some image manipulation like you guys are looking at now.
http://webcvs.kde.org/cgi-bin/cvsweb.cg ... web-markup


Some code for various photoshop like effects ( the code uses Qt GUI library but it is very easy to follow)