jdevries@zodiac.ADS.COM (Jeff De Vries) (02/02/90)
In response to an update event I'm trying to use CopyBits to blast an
offscreen pixmap into a window that has an associated palette. I'm going
to first describe what I've got, what works, what doesn't work, and then
ask a few questions.
Disclaimer: I try to describe what I think is going on at various points;
these are my *guesses*! Do not assume that they are correct!
Ingredients-
First, I have an offscreen pixmap. This pixmap has an associated color table
that indicates what RGB color I want for each of the possible index values in
the data area. In this particular case, the index values run from 0 to 255
because the pixel size is 8. From now on, I'll refer to this as the pixmap.
Second, I have a small window using a palette and pmExplicit so I can monitor
the device color table. This appears to always work. I'll refer to this
window as the color-watcher.
Third, I have my real, display CWindow. I have a palette associated with this
window that is constructed from the same color table that is used by the
offscreen pixmap above. The result of this is that I should be able to
say PmForeColor(x) and draw something in my window and the resulting color
should match (within the palette tolerance) the color in the offscreen
pixmap for index value x. I'll refer to this window as the window.
What Works -
If I set the pmUsage on the window palette to pmTolerant, and set the
tolerance to 0 (i.e. exact match only) the following events appear
to happen:
1) The window gets an activate event. This causes ActivatePalette() to be
called which causes the palette manager to do its magic to make sure the
colors in the palette are available. An interesting result of this is
that the color_watcher, just for a moment, shows that the device color
table indices contain the same colors as the palette, and in the same
order. (I can tell because the colors in the palette are in a different
order than the standard Apple color map). They colors in the device then
seem to scramble around; see question #1.
2) I do the CopyBits from my offscreen pixmap to the window. This appears
to work, but see question #2.
What Doesn't Work (and possibly why) -
If I set the pmUsage to pmAnimated, (so I can animate the colormap), the
following events occur:
1) The window gets an activate event. ActivatePalette() grabs the colors
that I need. Part of grabbing animated colors involves making those
indices unavailable to other windows. By the time ActivatePalette() has
grabbed all the indices that I want, the only ones that are left available
to other windows are the ones for black and white. The color_watcher
shows the same colors as in the pmTolerant case above, then goes to
black and white.
2) CopyBits from pixmap to window. Result? A black and white image and a
black and white color_watcher. Possible culprit? CopyBits uses the
color table of the gDevice of the destination, since it (appears) to need
an inverse map. Unfortunately, after the PaletteManager has grabbed
its colors, the gDevice colormap is only left with black and white, so
everything ends up black and white. See (obvious) question #3.
Questions -
1) After the Palette Manager has given me the colors I want, does it then try
to re-order the device table so that the difference between my colors and
the colors that other windows are expecting is minimized? After the
shuffle described above, the resulting device color table looks similiar
to the original Apple color map, with my closest color going where the
equivalent Apple color used to be.
1a) Is the PaletteManager smart enough to know what colors my palette is
currently not actually using and re-use those indices for other windows?
2) Does CopyBits try to preserve absolute colors across pixmaps? Stated
another way, does CopyBits do something like the following: Grab a pixel
from the source, find the absolute color for that pixel by looking at the
source color table, look at the (inverse) destination color table to find
the index of the color that most closely matches the absolute color, stuff
the index that was found into the destination pixmap.
3) How do you use CopyBits with an animated palette?
Thanks for any clarification and answers!!
Jeff
--
Jeff De Vries Advanced Decision Systems
Sr. Software Engineer 1500 Plymouth Street
jdevries@ads.com; (415) 960-7300 Mountain View, CA 94043-1230herbw@midas.WR.TEK.COM (Herb Weiner) (02/23/90)
In Article <10713@zodiac.ADS.COM> jdevries@zodiac.ADS.COM (Jeff De Vries) writes: > If I set the pmUsage to pmAnimated, (so I can animate the colormap), the > following events occur: > 2) CopyBits from pixmap to window. Result? A black and white image and a > black and white color_watcher. ... See (obvious) question #3. > > Questions - > > 3) How do you use CopyBits with an animated palette? In my opinion, Apple screwed up badly on this one. To make it work, you need to implement a custom search procedure. If your window is active (you have received an Activate Event, but have not received a deactivate event), You need to install it immediately before you do your CopyBits, and you need to remove it immediately after your CopyBits. (If you do all this, you do not need to worry about the client ID, because your CopyBits is the only possible client.) Refer to Inside Mac Volume V for more info on all this.
dplatt@coherent.com (Dave Platt) (02/23/90)
In article <1919@wrgate.WR.TEK.COM> herbw@midas.WR.TEK.COM (Herb Weiner) writes: > In Article <10713@zodiac.ADS.COM> jdevries@zodiac.ADS.COM (Jeff De Vries) writes: > > > 3) How do you use CopyBits with an animated palette? > > In my opinion, Apple screwed up badly on this one. To make it work, you need > to implement a custom search procedure. If your window is active (you have > received an Activate Event, but have not received a deactivate event), You > need to install it immediately before you do your CopyBits, and you need to > remove it immediately after your CopyBits. (If you do all this, you do not > need to worry about the client ID, because your CopyBits is the only possible > client.) There's a much better way to do this if you have 32-bit Color QuickDraw installed. You can tag your off-screen PixMap so that [a] it uses the same palette as the window, and [b] the values in the PixMap represent palette indices, NOT colortable indices. When you CopyBits() the off-screen PixMap to the screen, CopyBits performs a palette-index-to colortable-index lookup, and stores the correct [animated or non- animated] color into the screen PixMap. This lookup takes the place of the usual colortable-index->RGBcolor->screen-colortable-index search... which will not handle animated colors properly. This feature works very well even if your destination window touches multiple screens. It's VERY hard to CopyBits() animated colors to a multi-screen window with any other technique... and every other technique I've tried or encountered is UGLY! > Refer to Inside Mac Volume V for more info on all this. Also the 32-bit Color QuickDraw documentation, available from APDA or on Phil&Dave's Excellent but Generally Unavailable CD-ROM. -- Dave Platt VOICE: (415) 493-8805 UUCP: ...!{ames,apple,uunet}!coherent!dplatt DOMAIN: dplatt@coherent.com INTERNET: coherent!dplatt@ames.arpa, ...@uunet.uu.net USNAIL: Coherent Thought Inc. 3350 West Bayshore #205 Palo Alto CA 94303
jimo@phred.UUCP (Jim Osborn) (03/01/90)
In article <47531@improper.coherent.com> dplatt@coherent.com (Dave Platt) writes: >>... >> > 3) How do you use CopyBits with an animated palette? >There's a much better way to do this if you have 32-bit Color QuickDraw >installed. You can tag your off-screen PixMap so that [a] it uses the >same palette as the window, and [b] the values in the PixMap represent >palette indices, NOT colortable indices. >> Refer to Inside Mac Volume V for more info on all this. >Also the 32-bit Color QuickDraw documentation, available from APDA or on >Phil&Dave's Excellent but Generally Unavailable CD-ROM. I couldn't find any reference to this in any of the info on the 32-bit Color QuickDraw discs or on the CD-ROM, but it is mentioned in the "All about the palette manager" article in Develop #1. As the summary says: CTabHandle myCT; ... (*myCT)->ctFlags |= 0x4000; Now if only 32-bit QuickDraw weren't so slooooow. 8-( -- pilchuck!jimo@phred Jim Osborn, Physio Control Corp 11811 Willows Rd, Redmond, WA, 98073 206-867-4704 direct to my desk