[comp.windows.ms.programmer] Help setting 16 palette VGA entries

blackwoo@hplred.HP.COM (Craig Blackwood) (05/15/91)

Hi,

Does anyone know how I can "trick" windows into using different colors?

Specifically, I have a VGA card and a driver which supports 16 pure
colors;  I want to write directly to the VGA card and have it change
one or more of the palette entries so that I have control over the
displayed color (it is even OK if windows resets the palette when
another application is run.)

To do this I need to know how to talk directly with the VGA card
AND do this without windows knowing that I have done it.

Any advice or help is appreciated.

Thank you,

Craig Blackwood
(415) 857-8880
Hewlett Packard

mh2620@sarek.sbc.com (Mark Horstman) (05/15/91)

In article <108350001@hplred.HP.COM>, blackwoo@hplred.HP.COM (Craig Blackwood) writes:

> Specifically, I have a VGA card and a driver which supports 16 pure
> colors;  I want to write directly to the VGA card and have it change
> one or more of the palette entries so that I have control over the
> displayed color (it is even OK if windows resets the palette when
> another application is run.)
> 
> To do this I need to know how to talk directly with the VGA card
> AND do this without windows knowing that I have done it.
> 

If you are using the standard VGA driver that comes with Win 3.0 the
only way to get all sixteen mode 12 colors is behind Windows back.  If
you ask Microsoft, the official answer is 'buy the device driver kit
for Windows and write your own VGA driver'.  I found that unacceptable.
With a little help I got around the limitation. I was able to find out 
that the standard System Palette w/20 colors maps into the 16 VGA mode 
12 palette registers (the middle four colors are combinations).  
Unfortunately they don't map directly (i.e. 1->1, ..., 16->16) but in 
the following fashion:

        /* This is really ugly.  Each of the standard VGA System Palette
         * entries don't map intuitively into the VGA palette registers.
         * Here is how they map out:
         *
         *      VGAPAL    SYSPAL          VGAPAL     SYSPAL
         *        00        00              08        07
         *        01        01              09        13
         *        02        02              10        14
         *        03        03              11        15
         *        04        04              12        16
         *        05        05              13        17
         *        06        06              14        18
         *        07        12              15        19
         */

My application just waits to get a WM_SETFOCUS event, then saves the current
state of the hardware colormap and installs the one I want.  When I get a 
WM_KILLFOCUS event I put them back. I tried installing the colormap when
the mouse enters my window/client area, and un-installing it when the mouse
leaves but I could never tell when the mouse left (WM_NCMOUSEMOVE? only
tells you when the mouse moves into YOUR non-client area, not that it just
left your window :-( ).  Windows never knows whats going on.  Don't mess 
directly with the pallette registers tho', modify the color registers that 
they point to.

Of course this will probably break under the Win 3.1?, but hey, I had
a deadline to meet :-).

-- 
Mark Horstman
mh2620@sarek.sbc.com
Southwestern Bell Telephone
St. Louis, MO

ebergman@isis.cs.du.edu (Eric Bergman-Terrell) (05/15/91)

Charles Petzold's "Environments" column in PC Magazine has covered color
management in Windows in detail.  Go to a library and check out the issues
from Feb. 1991 to present.

Terrell

risto@tuura.UUCP (Risto Lankinen) (05/16/91)

mh2620@sarek.sbc.com (Mark Horstman) writes:

>        /* This is really ugly.  Each of the standard VGA System Palette
>         * entries don't map intuitively into the VGA palette registers.
>         * Here is how they map out:
>         *
>         *      VGAPAL    SYSPAL          VGAPAL     SYSPAL
>         *        00        00              08        07
>         *        01        01              09        13
>         *        02        02              10        14
>         *        03        03              11        15
>         *        04        04              12        16
>         *        05        05              13        17
>         *        06        06              14        18
>         *        07        12              15        19
>         */

Hi!

Amazingly, the above arrangement makes some sense:

If you viewed the system colors as 0..9,-10..-1 instead of 0..19, then colors
having their sum = -1 are 'opposite', thus a color is inverted by XOR-op.
The above arrangement preserves this property on the indexes of the same
colors, therefore speeding up many graphic operations by not having to invert
the color, but only its index.

When the same colors are assigned to a palette with 256 entries, the index
values used are 0..9 and 246..255, so the property above still holds.  Since
the designers of Windows have chosen to use 20 colors, the 'extra' four have
had to be inserted in the middle of the 'standard' 16 colors.

This doesn't explain the system colors 7 and 12 being exchanged, however.  It
may have something similar to do with palette tables *smaller* than 16 (EGA).

Terveisin: Risto Lankinen
-- 
Risto Lankinen / product specialist ***************************************
Nokia Data Systems, Technology Dept *  2                              3   *
THIS SPACE INTENTIONALLY LEFT BLANK * 2 +1 is PRIME!  Now working on 2 -1 *
replies: risto@yj.data.nokia.fi     ***************************************