Board index » cppbuilder » Building greyscale values for RGB bitmap?

Building greyscale values for RGB bitmap?

OK, what seemed at the start to be a simple graphics problem has turned
in to a bit of a nightmare for me. Help?

I've got a video device that produces a value of 0 to 65k (one WORD).
This value represents levels of light (as shades of grey).

I am attempting to scale and convert this level to a TColor grey scale
so that I can fill in the TColor values for the pixels of a TBitmap.

I thought I could scale (divide by 0x100) and then plug the same value
into the RGB bits and get a nice grey scale. This is not working. I
earlier thought CPPBuilder was defective, but alas, apparently I am.

I briefly played with the grey=.299R+.587G+.114B and quickly decided
that I had no idea what was going on (the most individual shades of grey
that I could produce were 20 - for a 256 color screen).

I am testing my routine by putting the value of a counter into the input
array.

Any graphics experts in the house that might be able to make since of
this for me?

 

Re:Building greyscale values for RGB bitmap?


Quote
>On Sat, 30 May 1998 09:42:05 -0700, Ken Miller <ken...@aol.com> wrote:
> OK, what seemed at the start to be a simple graphics problem has turned
> in to a bit of a nightmare for me. Help?

> I've got a video device that produces a value of 0 to 65k (one WORD).
> This value represents levels of light (as shades of grey).

> I am attempting to scale and convert this level to a TColor grey scale
> so that I can fill in the TColor values for the pixels of a TBitmap.

> I thought I could scale (divide by 0x100) and then plug the same value
> into the RGB bits and get a nice grey scale. This is not working. I
> earlier thought CPPBuilder was defective, but alas, apparently I am.

You can't just plug the value, you should do put that value in each of
the RGB parts:

NewVal = Value/0x100;
TheColor = NewVal;   // This only sets only the Blue component.

TheColor =
        NewVal<<16 +      //Red
        NewVal<<8 +       //Green
        NewVal;         //Blue

Quote
> I briefly played with the grey=.299R+.587G+.114B and quickly decided
> that I had no idea what was going on (the most individual shades of grey
> that I could produce were 20 - for a 256 color screen).

This is useful when you have a color bitmap and want to convert it to
gray scale.  Just do:

GrayScaleValue =
        ((TheColor>>16) & 0xff) * 0.299 +     //Red
        ((TheColor>>8) & 0xff) * 0.587 +      //Green
        ((TheColor) & 0xff) * 0.114;                //Blue

Now when you've got the grayscale value, if you want to color a
grayscale image, just plug in the color.  If you want to put this
grayscale on a colored image you should set all RGB components equal
to the grayscale value (just as before).

Quote
> I am testing my routine by putting the value of a counter into the input
> array.

> Any graphics experts in the house that might be able to make since of
> this for me?

I hope this is what you needed.  If not, you can email me
(ch...@usa.net) your project and I'll try to fix it.

Bye
  Chivo

--------------------
Marco Antonio Micheo
mailto:ch...@usa.net
http://uvg.edu.gt/~chivo

Other Threads