[comp.sys.mac.programmer] Bitplanes: take 2

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

On March 14 in <53450@bbn.COM> I posted an article asking for tips about
bitplaning on the MacII.  Since then I've gotten several replies none of
which solved my problem.

The end of this message contains a summary of the interesting replies
(i.e. those that didn't quote InsideMac at me).  A number of people
thought I was asking how to set the colors of a colormap or some such
thing that is clearly explained in IM.  This makes me think I didn't
explain myself clearly.  So, I'll try to rephrase my problem in the form
of a specific question:

Assume that I start with a color window painted entirely in color 0
appearing on an eight-bit indexed monitor (i.e. a CLUT device).  If the
following code is executed the window should appear as described at each
comment.

	SetRect(&R1, 10, 10, 100, 100);
	SetRect(&R2, 50, 50, 150, 150);

	PenMode(MODE_A);
	PmForeColor(2);
	PaintRect(&R1);
	/* A single rectangle appears.  Its color is exactly the color
	 * specified by color 2 in the window's palette.
         */

	PenMode(MODE_A);
	PmForeColor(4);
	PaintRect(&R2);
	/* Another rectangle appears.  Its color is color 4 from the
	 * window's palette.  Where the two rectangles overlap, will
	 * appear as color 6 (since 4 | 2 == 6) _no_matter_what_the_
	 * _actual_RGB_values_are.  Actually, the color of the overlap
	 * isn't so important to me.  What I REALLY want is for the next
	 * two steps to happen as described:
         */

	PenMode(MODE_B);
	PmForeColor(2);
	PaintRect(&R1);
	/* The first rectangle disappears.  A single rectangle is now
	 * the only thing visible, is the second rectangle.  The area
	 * where the two used to overlap now appears as color 4.
	 */

	PenMode(MODE_B);
	PmForeColor(4);
	PaintRect(&R2);
	/* The window is restored to its original state (all color 0).
	 */

What I need to know is:

 *** Is this possible as I've written it?  
   If so:
     --> What drawing mode do I use for MODE_A and MODE_B above?
     --> What value do I use for the Usage field for the colors in the
         palette (i.e. the 'pltt' resource)?
   If not:
     --> Is it possible by accessing the Color Manager directly
         (by-passing the Palette Manager)?  Can you provide an example?
 
------
Summary of interesting responses:

A number of people confirmed my impression that since the Palette
Manager and Quickdraw are entirely hardware independent, there's no way
to do what I want without mucking around somewhere else (i.e. the Color
Manager).  IOW, all drawing operations take place in RGB space, there's
no way to access "CLUT-index space" even if you use pmExplicit colors.

Jeremy Grodberg had a cute way around this: use pmAnimated+pmExplicit
colors and set them to gray ramps (so color 0 is {R=0,G=0,B=0}, 1 is
{1,1,1}, etc.  This effectively, makes RBG space behave like
index-space.  [I think] this would require creating an offscreen pixmap
with a GDevice which has the gray ramp as its color map.  All drawing
would be done on this pixmap and then CopyBits'ed onto the real window.
   This may actually work, but it sounds like a fairly rude hack.  Also,
my application is a real-time air-traffic control simulation.  Even if
I'm clever about CopyBits'ing the smallest possible area, it'll still be
a big performance bottleneck.

Jon W{tte suggested tweaking the bits of the portBits pixMap.  An
interesting idea, but I have to do some fairly complex drawing.  Much as
I'd like to reimplement Quickdraw, I don't have the time this month :-)

In a followup message, Robert Dorsett restates the problem rather well
(in case anyone STILL doesn't get it):

>I'd like to use an arbitrary background color, and draw 
>lines in an arbitrary foreground RGB color. I would like the foreground lines
>to behave, in essence, like they were drawn xor'd (as black lines would on a 
>monochrome system).  I don't care what color any overlap is, provided that 
>overlap disappears when all lines are erased again.

----

Thanks in advance for any suggestions.  (And thanks for your patience.)

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