Path: utzoo!attcan!uunet!samsung!uakari.primate.wisc.edu!ames!zodiac!jdevries From: jdevries@zodiac.ADS.COM (Jeff De Vries) Newsgroups: comp.sys.mac.programmer,ads.mac Subject: PaletteManager vs. CopyBits (long; gurus only) Message-ID: <10713@zodiac.ADS.COM> Date: 1 Feb 90 22:28:08 GMT Distribution: na Organization: Advanced Decision Systems, Mountain View, CA 94043, (415) 960-7300 Lines: 86 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-1230