[comp.graphics] color bitplanes on a Mac?

mesard@bbn.com (Wayne Mesard) (03/14/90)

Summary:
--------
I want to use bitplanes on a MacII.  How to do this isn't at all clear
to me.  I'm hoping that I'm revealing some profound ignorance on my part
about Mac color or graphics or both and that someone can set me
straight.


Painfully verbose elaboration:
--------- ------- ------------
I'm just getting into my first color Mac application.  
I hope someone can straighten me out on something:

  Suppose I want to draw N (where N <= 7) objects in a window.
  The objects may overlap, and can be drawn and erased in an
  arbitrary order.

Now, in a conventional 8-bit color lookup table (CLUT) system, I would
use a technique known as bitplaning: Assign each object to a bit in the
8 bit color table index and construct the color table in such a way that
the rendered color reflects the high bit of the index.  For example, if
I have 5 objects, I'll need 5 bitplanes (i.e. a CLUT of size 2^5 == 32):

  Index  In binary  Color
  -----  ---------  -----
    0     00000000  black
    1     00000001  blue
   2-3    0000001x  salmon
   4-7    000001xx  green
  8-15    00001xxx  orange
  16-31   0001xxxx  magenta

So, to draw object 3 (green), simply do a binary Xor with 4 on each
pixel value.  Pixels that were black, blue or salmon will appear green.
Pixels that were orange and magenta will appear unchanged.  (Erasing
simply Xors the region again.  Details left as an exercise for the
reader.)

My problem [finally] is that transfer modes described in Inside Mac
volume V all operate on the _RGB_ values of the pixel, as opposed to the
_index_ values.  I really expected the patXor mode to do what I wanted,
but it seems that they really mean it when they say if "used on a
colored destination, the color of the [result] isn't defined."

Two possible solutions that come to mind are: 1) using the addOver and
subOver drawing modes.  2) add a SearchProc for the device.  But these
are just stabs in the dark.  A concrete solution doesn't leap out at me.

Bitplaning is such an immensely useful thing, that I can't believe that
the Mac doesn't provide something similar without resorting to all kinds
of contortions and ugly hacks.  I've been all through the relevant
chapters of IM-V, and I've come up empty-handed.  Can anyone point me in
the right direction?

Thanks in advance.

-- 
void Wayne_Mesard();   Mesard@BBN.COM   Bolt Beranek and Newman, Cambridge, MA

mesard@bbn.com (Wayne Mesard) (03/15/90)

Summary:
--------
I want to use bitplanes on a MacII.  How to do this isn't at all clear
to me.  I'm hoping that I'm revealing some profound ignorance on my part
about Mac color or graphics or both and that someone can set me
straight.


Painfully verbose elaboration:
--------- ------- ------------
I'm just getting into my first color Mac application.  
I hope someone can straighten me out on something:

  Suppose I want to draw N (where N <= 7) objects in a window.
  The objects may overlap, and can be drawn and erased in an
  arbitrary order.

Now, in a conventional 8-bit color lookup table (CLUT) system, I would
use a technique known as bitplaning: Assign each object to a bit in the
8 bit color table index and construct the color table in such a way that
the rendered color reflects the high bit of the index.  For example, if
I have 5 objects, I'll need 5 bitplanes (i.e. a CLUT of size 2^5 == 32):

  Index  In binary  Color
  -----  ---------  -----
    0     00000000  black
    1     00000001  blue
   2-3    0000001x  salmon
   4-7    000001xx  green
  8-15    00001xxx  orange
  16-31   0001xxxx  magenta

So, to draw object 3 (green), simply do a binary Or with 4 on each pixel
value.  Pixels that were black, blue or salmon will appear green.
Pixels that were orange and magenta will appear unchanged.  To erase,
simply Xor the image.  Details left as an exercise for the reader.
[I've oversimplified a lot here, but that's the basic idea.]

My problem [finally] is that transfer modes described in Inside Mac
volume V all operate on the _RGB_ values of the pixel, as opposed to the
_index_ values.  I really expected the patXor mode to do what I wanted,
but it seems that they really mean it when they say if "used on a
colored destination, the color of the [result] isn't defined."

Two possible solutions that come to mind are: 1) using the addOver and
subOver drawing modes.  2) add a SearchProc for the device.  But these
are just stabs in the dark.  A Right solution doesn't leap out at me.

Bitplaning is such an immensely useful thing, that I can't believe that
the Mac doesn't provide something similar without resorting to all kinds
of contortions and ugly hacks.  I've been all through the relevant
chapters of IM-V, and I've come up empty-handed.  Can anyone point me in
the right direction?

Thanks in advance.

-- 
void Wayne_Mesard();   Mesard@BBN.COM   Bolt Beranek and Newman, Cambridge, MA

sierra@das.llnl.gov (Frankie Sierra) (03/15/90)

Wayne, if you are dealing directly with the color manager without using
the palette manager, then you should be able to XOR by yourself.  Now,
if you are using the Palette manager, specify the color entry usage for
all the entries as "pmExplicit + pmTolerant" and set the tolerance to
zero.  This instruct the palette manager to use the colors exactly as
they were defined (pmTolerant == 0), and exactly in the entry position
they were defined (pmExplicit).  You can do these when creating the
palette, or by using SetEntryUsage over the entries you want control.
Hope this help. -Frankie-

rotberg@dms.UUCP (Ed Rotberg) (03/16/90)

From article <53503@bbn.COM>, by mesard@bbn.com (Wayne Mesard):
> Summary:
> --------
> I want to use bitplanes on a MacII.  How to do this isn't at all clear
> to me.  I'm hoping that I'm revealing some profound ignorance on my part
> about Mac color or graphics or both and that someone can set me
> straight.

Wayne,

The Macintosh documentation on Color Quickdraw (Inside Macintosh vol V)
does talk about 3 different methods of implementing color.  I'm doing
this from memory, but I beleive that they refer to them as Chunky (which
is the CLUT type), Planar (the kind you are looking for) and Chunky
Planar (I'm not sure on all the details here).  In any event, after allowing
you to specifiy which type of data your bitmap is in things such as cicn's
and cursors, I beleive that the only one currently supported is the
Chunky type.  Once again, I read all this stuff a while ago, and really
haven't had a need to deal with it recently, but I recall bemoaning the
fact that the Planar type was not fully supported for just your reasons.

This info is rather sketchy, and shouldn't be taken as gospel.  What I 
really recommend is getting IM v V and checking up on it.  My copy is at
home, otherwise I would quote you the important sections.  If you can't
get the document, email me & I try to remember to bring in vol V
tomorrow.

	- Ed Rotberg -
	- Atari Games -

yerga@cory.Berkeley.EDU (Chris Yerga) (03/16/90)

In article <53503@bbn.COM> mesard@BBN.COM (Wayne Mesard) writes:
>I want to use bitplanes on a MacII.  How to do this isn't at all clear
>to me.  I'm hoping that I'm revealing some profound ignorance on my partu
>about Mac color or graphics or both and that someone can set me
>straight.

What you need to read is the Palette Manager chapter in Inside Mac V.
You can assign colors to your palette in a variety of ways, including
"explicit colors" which are colors you refer to by their CLUT index,
not their RGB value. Using this method, you have complete control over
which color tabe entries you use for drawing. This method is only
supported for CLUT devices (of course), so be sure to check the
gDevice flags to determine the nature of your output device.

Hope it helps!

Chris Yerga
yerga@cory.berkeley.edu