Path: utzoo!attcan!uunet!ccicpg!felix!dhw68k!bytebug From: bytebug@dhw68k.cts.com (Roger L. Long) Newsgroups: comp.sys.mac.programmer Subject: Re: Using PixMaps in CopyBits Keywords: pixmap, bitmap copybits Message-ID: <7990@dhw68k.cts.com> Date: 14 May 88 17:17:17 GMT References: <1988May11.125956.642@mntgfx.mentor.com> Organization: Wolfskill residence; Anaheim, CA (USA) Lines: 69 In article <1988May11.125956.642@mntgfx.mentor.com> tomc@mntgfx.mentor.com (Tom Carstensen) writes: >I'm having a slight problem in getting Copy Bits to >work correctly. >mypm = NewPixMap() >Set mypm bounds rectangle >Set mypm row bytes >Set sourcerect = some small rectangle in the window > >HLock((Handle)mypm); >(*mypm)->baseAddr = NewPtr(#bytes * (*mypm)->pixelSize); >CopyBits(¤tWindow->portBits, *mypm, > &sourcerect, &(*mypm)->bounds, srcCopy, NULL) > >... do stuff ... >.. then copy back > >CopyBits(*mypm, ¤tWindow-portBits, > &(*mypm)->bounds, &sourcerect, srcCopy, NULL); >Well, I've checked all of the above code in the debugger, >and all of it looks fine, but it DOESN'T work. It does >copies the bits back, but the color is messed up, like >it's copying to/from a 1 or 2 bits screen. > >Does anyone see my problem, are had success doing something >like this. First, a disclaimer. I've only been programming on the Mac II for a little over a month, and thus far, I consider people who can get fancy color programming to work with JUST Inside Mac vol V something close to gods. However I have dealt with offscreen pixmaps, and think I see your problem. If you take a look at the IM-V description of NewPixMap, you'll see the statement: "All fields of the pixMap are copied from the current device's pixMap except the color table. A handle to the color table is allocated but not initialized." Thus, what I'd add are the statements (which come to us from TN120, but I've translated them to C): CTabHandle ourCMHandle; GDHandle theMaxDevice; ourCMHandle = (*((*theMaxDevice)->gdPMap))->pmTable; err = HandToHand(&CTabHandle); for (i=0; i<(*ourCMHandle)->ctSize; i++) (*ourCMHandle)->ctTable[i].value = i; (*ourCMHandle)->transIndex &= 0x7FFF; (*mypm)->pmTable = ourCMTable; Basically, what this code does is clone the color table from the device with the deepest pixels (you should be figuring out theMaxDevice already to figure out things like how much storage to allocate to the actual pixel storage. Then, you make this new color map that you cloned look like a PixMap color table instead of a device color table. Once you've done that, just stick the handle into your PixMap. You really should get hold of a copy of "TN120: Drawing into an Offscreen PixMap". -- Roger L. Long dhw68k!bytebug