How To Transform Color?



I have a bitmap file that I use as part of a skin in my GUI. Never mind that
its a GUI or Windows based, that part isn't important.

The problem is that say the graphic is blue, but the user selects a green
color scheme. I want the graphic skin to be green-ish instead of blue-ish.

My idea was to shift the R,G,B values of each pixel in the bitmap towards
the R,G,B values of the foreground color. I figured this would maintain the
shape and "lighting" of the bitmap. A sort of blending the original color
with the new foreground color. I came up with this:

rgbq.rgbRed += (10 + ((GetRValue(cr) - rgbq.rgbRed) * 5 / 8));
rgbq.rgbGreen += (10 + ((GetGValue(cr) - rgbq.rgbGreen) * 5 / 8));
rgbq.rgbBlue += (10 + ((GetBValue(cr) - rgbq.rgbBlue) * 5 / 8));

1) I get the new foreground color in cr
2) rgbq is a struct that represents a pixel (this code is in a for loop
going through each pixel in the bitmap)
3) I take take the difference of the red values * 5/8 and add it to the
original red value
4) I add 10 to "lighten" the color a bit...

This seems to work OK, the original "grayish" bitmap is now "purpleish" or
whatever... but the problem is the original bitmap was a sort of spherish
shape (use of lighting from the upper left going to the lower right), but
the resulting bitmap, although in the right color realm, seems to have
"flattened" the image... ie.. it lost the lighting effect.

I've checked to make sure the value never goes above 255. And I am POSITIVE
that the getpixel and setpixel portion of the code is correct since I am
successfully using the same function to apply other effects to the bitmap.
Just this transforming thing seems to be flattening it.

Any ideas?


.



Relevant Pages

  • Re: Signature control - 1 BPP bitmap
    ... > as the foreground color on the destination surface, so if you blit a 1bpp ... then you'll see red and blue for the 1's/0's of the bitmap. ... > closest color match of the foreground/background colors to the DIB color ... Maybe Blt-ing to the DIBSection is still ...
    (microsoft.public.pocketpc.developer)
  • Re: How to "TINT" bitmap?
    ... > Not sure if "TINT" is the effect I'm looking for, but I have a bitmap that ... > select blue as the foreground color, the gray-ish bitmap should now be ... I've tried a few formulas to calculate the new per pixel colors, ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Canvas extension: point item?
    ... Here's basically what you do to create a color bitmap and control the ... create a new image of type photo ... put it your GUI ... If you can draw your pixels sequentially, the scanline method is the way to ...
    (comp.lang.tcl)
  • Custom bitmap UI
    ... I'm trying to create a custom UI using a bitmap. ... skin. ... But in addition to text labels, I also want to add functionality for ...
    (microsoft.public.win32.programmer.ui)
  • Re: A question on threading
    ... Do you send some kind of data to the gui that does ... executing the compression code inside the gui thread. ... refresh to display the changes in image during processing. ... My code actually modifies the bitmap that I'm going to display. ...
    (microsoft.public.dotnet.languages.csharp)