[comp.windows.x] How does the X protocol deal with colors ?

TRANLE@INTELLICORP.COM (Minh Tran-Le) (07/26/89)

When you have 2 colors: color1 and color2 on 2 pixmaps and you are doing
a copyarea with a specific logical op (something more complex than just
the GxCopy).
Does it use the 2 colormap entries (pixel value) or does it use the rgb
values to do the logical combination ?

Thanks, Tran Le

Internet: tranle@intellicorp.com
uucp:  ...sun!icmv!mtranle
-------

rws@EXPO.LCS.MIT.EDU (07/27/89)

    Does it use the 2 colormap entries (pixel value) or does it use the rgb
    values to do the logical combination ?

*All* graphics ops (even those in windows) are based purely on pixel values.
(Another hint of this for pixmaps: pixmaps don't *have* visuals or colormaps.)

rws@EXPO.LCS.MIT.EDU (07/27/89)

    What is the correct way to do consistent color operation across platforms ?

That depends a lot on exactly what you're trying to do, but it sounds like you
have some basic knowledge missing.  Try reading some of the introductory
materials on color, e.g. in one of the O'Reilly books (a chapter of which is
excerpted in MIT X11R3 in doc/tutorials/) or in Oliver Jone's book or in
Doug Young's book or ...

TRANLE@INTELLICORP.COM (Minh Tran-Le) (07/27/89)

>>    Does it use the 2 colormap entries (pixel value) or does it use the rgb
>>    values to do the logical combination ?
> 
> *All* graphics ops (even those in windows) are based purely on pixel values.
> (Another hint of this for pixmaps: pixmaps don't *have* visuals or colormaps.
> 

What is the correct way to do consistent color operation across platforms ?

This is because I am building and application that will run different
platforms using black&white or color displays.  And I have seen that a 
black pixel is usually 0 on a B&W display but on my color PS2 it is also 0 
while on my color vax decwindows display it is 252.

Should I use only logical functions that always do the same thing on all the
displays like GXclear, GXcopy, GXnoop and GXset. But that is pretty 
restrictive about what you can do with these operations.

Should I use my own colormap where I would know where all the colormap
entries are .  But some machines will not allow you to install multiple 
colormaps. And also it would interfere with the other applications running 
on the same display.


Thanks, Tran Le.

Internet: tranle@intellicorp.com
uucp:   ..sun!icmv!mtranle
-------

karlton@fudge.sgi.com (Phil Karlton) (07/27/89)

In article <8907261545.AA28766@expo.lcs.mit.edu> TRANLE@INTELLICORP.COM (Minh Tran-Le) writes:
>When you have 2 colors: color1 and color2 on 2 pixmaps and you are doing
>a copyarea with a specific logical op (something more complex than just
>the GxCopy).
>Does it use the 2 colormap entries (pixel value) or does it use the rgb
>values to do the logical combination ?

From Page 400 of the Digital Press "X Window System" book

    In graphics operations, given a source and estination pixel, the
    result is computed bitwise on the corresponding bits of the pixels:
    that is, a Boolean operation is performated in each bit plane.

PK
Phil Karlton			karlton@sgi.com
				415-964-1459 ext. 3018

mlm@calmasd.Prime.COM (Monte Meals) (07/27/89)

In article <8907261545.AA28766@expo.lcs.mit.edu>, TRANLE@INTELLICORP.COM (Minh Tran-Le) writes:
> Does it use the 2 colormap entries (pixel value) or does it use the rgb
> values to do the logical combination ?
> 
Copyarea operates on pixel values. For a good description take a look at
chapter 7 in O'Reilly's book. It is included in the X11.3 distribution:
   X11.3/doc/tutorials/color.tbl.ms

Monte

bobtl@toolbox.WV.TEK.COM (07/28/89)

In article <8907262013.AA05801@expo.lcs.mit.edu> TRANLE@INTELLICORP.COM (Minh Tran-Le) writes:
>What is the correct way to do consistent color operation across platforms ?
>
>This is because I am building and application that will run different
>platforms using black&white or color displays.  And I have seen that a 
>black pixel is usually 0 on a B&W display but on my color PS2 it is also 0 
>while on my color vax decwindows display it is 252.
>
>Should I use only logical functions that always do the same thing on all the
>displays like GXclear, GXcopy, GXnoop and GXset. But that is pretty 
>restrictive about what you can do with these operations.

I infer from your question that you want to use any logical function and
keep your image black and white on any display.  Using these four functions
only is your best bet.  You have no control over what the screen Black/White
Pixel is.
Restrictive, yes, but you cannot use other logical functions unless you
can control the relationship of colors within the map.  Which leads to the
next point.

>Should I use my own colormap where I would know where all the colormap
>entries are .  But some machines will not allow you to install multiple 
>colormaps. And also it would interfere with the other applications running 
>on the same display.

Switching colormaps has its problems but is sometimes necessary.
You can use XAllocColorCells to set up a relationship within a portion
of the colormap, if there is space.  Set up your own black and white pixels
with colors=1 and planes=1.

Even setting up your own colormap doesn't solve the basic problem of controlling
black and white.  Suppose a screen has a pseudocolor visual with depth 8
and 254 entries in a map.  If BlackPixel is 0, inverting it gives 255,
which isn't even in your map.

>Thanks, Tran Le.

Bob Toole
bobtl@toolbox.WV.TEK.COM

mikey@decwrl.dec.com (Mike Yang) (07/28/89)

In article <8907262013.AA05801@expo.lcs.mit.edu> TRANLE@INTELLICORP.COM (Minh Tran-Le) writes:
>Should I use only logical functions that always do the same thing on all the
>displays like GXclear, GXcopy, GXnoop and GXset. But that is pretty 
>restrictive about what you can do with these operations.

In article <4044@orca.WV.TEK.COM> bobtl@toolbox.WV.TEK.COM () writes:
>Even setting up your own colormap doesn't solve the basic problem of controlling
>black and white.  Suppose a screen has a pseudocolor visual with depth 8
>and 254 entries in a map.  If BlackPixel is 0, inverting it gives 255,
>which isn't even in your map.

You can use GXxor to "invert" between your two colors if you set the
plane mask of your GC to the bitwise exclusive or of the two pixel
values.

For instance, if you want to deal with the default foreground and
background colors, set the plane mask of your GC to

	BlackPixel(dpy, screen) ^ WhitePixel(dpy, screen)

and set the function to GXxor.  Then, if you want to "invert" an area
use XFillRectangle on the area with this GC.

-----------------------------------------------------------------------------
Mike Yang	  Western Software Laboratory	Digital Equipment Corporation
mikey@wsl.dec.com	 decwrl!mikey			(415) 853-6677

reb@DINORAH.WUSTL.EDU (07/29/89)

>Does it use the 2 colormap entries (pixel value) or does it use the rgb
>values to do the logical combination ?
 
It uses the pixel values (colormap locations).