[comp.windows.ms.programmer] RGB

dkemper@oracle.com (David J. Kemper) (03/14/91)

I'm having problems with specifying/reading RGB colors on the display
device context.

First of all, I have a Compaq 1024 graphics board, which gives me
1024x768 resolution with a 256 color lookup table. I've noticed that
writing colored pixels or creating a brush (CreateSolidBrush()) using
the RGB macro (which creates direct colorrefs of the form 0x00bbggrr)
doesn't work with the enhanced colors. The brush created consists of a
dithering of the base 16 Windows colors. I do, however, get the
correct results by using the PALETTERGB macro (which creates colorrefs
of the form 0x02bbggrr), which becomes a palette index on those
devices (like mine) that support them. Fine. I can display my enhanced
colors on the screen.

The problem arises when I want to read pixels from the display. I
create a screen device context (CreateDC("DISPLAY", NULL, NULL, NULL)
and try to read from it using GetPixel(). Well, the DWORD colorref I
get back ALWAYS has the high byte of 0, meaning it's a direct RGB (?).
The problem is that this direct color is WRONG. It's a match when the
color happens to be a standard Windows color (as in window title bars,
menu backgrounds, etc), but is "garbage" when it is one of my enhanced
color palette entries.

In other words, I can write beautiful 256 color images to the display,
but I can't read them from the display. Doing a PrintScreen to the
clipboard also runs into the same problem. Am I going about this
wrong? Is this a problem with Windows? With my device driver? Help!

-djk
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-djk David Kemper         | No, no!  You are all individuals.
dkemper@oracle.com        | We are all individuals.
My opinions are just that | I'm not.                            -M. Python
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

johnm@spudge.UUCP (John Munsch) (03/15/91)

In article <DKEMPER.91Mar13150624@hqsun2.oracle.com> dkemper@oracle.com (David J. Kemper) writes:
>The problem arises when I want to read pixels from the display. I
>create a screen device context (CreateDC("DISPLAY", NULL, NULL, NULL)
>and try to read from it using GetPixel(). Well, the DWORD colorref I
>get back ALWAYS has the high byte of 0, meaning it's a direct RGB (?).
>The problem is that this direct color is WRONG. It's a match when the
>color happens to be a standard Windows color (as in window title bars,
>menu backgrounds, etc), but is "garbage" when it is one of my enhanced
>color palette entries.

Hmm...  I've never tried doing that sort of thing with a CreateDC.

I assume you have the handle to the window you're doing all this in available.
If so, try doing a GetDC() on the window handle and performing the GetPixels
on that DC handle instead.

P.S.  If you are grabbing large sections of the screen via GetPixel() you may
find it more economical (timewise) to use something like GetDIBits() instead.

John Munsch