CLIM mail archive

[Prev][Next][Index][Thread]

Re: Semantics of flipping inks



   Date:	Sat, 23 Apr 1994 13:13:56 -0700
   From:	Lawrence.G.Mayka@att.com

   I'm having some difficulty with the semantics of flipping inks.  The
   documentation is clear, for example, as to what CLIM:+FLIPPING-INK+
   does to output whose color happens to exactly match either
   CLIM:+FOREGROUND-INK+ or CLIM:+BACKGROUND-INK+.  But what does it do
   to any other color?  Are the consequences entirely unspecified?  

Lifting the covers a little, you will find that flipping ink is
nothing more than an interface to the tried-and-true raster graphics
technique of XORing pixels together.  On the typical 8-bit
pseudo-color display you find on many computers, CLIM can hack the
bits such that any two specified colors get swapped when the XOR
happens, and due to the nature of XOR, they will get swapped back if
you do the operation again.  While you can't determine
This kind of XOR-based highlighting is so
useful that we thought we had to provide some kind of access to it in
the CLIM graphics model.

Possibly-boring raster graphics tutorial follows:

On an 8-bit screen each pixel has a number between 0 and 255.  That
number is used as an index into a color table which determines what
color is displayed for pixels with a given numeric value.

Say that red just happens to have been assigned the number 5 and blue
the number 14.  In binary you have:

red	00000101
blue	00001110

CLIM can construct a bit pattern that, when XORed into the screen,
will turn all the 5's into 14's and 14's into 5's:

flip	00001011

Thus, the number 11, when XORed into a group of screen pixels, will
change all the 5's to 14's and vice versa.

(The beauty of this is that the flipping pixel value is computed
simply by XORing the two "target" color pixel values together.)

Of course, this pattern happens to also turn the number 27 (which
might represent the color green) into the number 16 (which might
represent, say, purple):

	00011011
XOR	00001011
        --------
        00010000

So all the other colors on the screen get arbitrarily re-assigned.

If you have direct control over the color map you can arrange for the
XOR operation to make other defined swaps as well (e.g. by assigning
green's desired complimentary color to pixel value 16 in the example
above).  However, this can be pretty platform-dependent.

Are you sorry you asked?

Follow-Ups: References:

Main Index | Thread Index