tomc@mntgfx.mentor.com (Tom Carstensen) (05/12/88)
I'm having a slight problem in getting Copy Bits to work correctly. The following is an example of how I get it to copy the 4-bit depth screen correctly, but simply copies it to another location on the screen. ----------------------------------------------------- !! This works: !! mypm = NewPixMap() Set mypm bounds rectangle Set mypm row bytes Set sourcerect = some small rectangle in the window HLock((Handle)mypm); CopyBits(¤tWindow->portBits, *mypm, &sourcerect, &(*mypm)->bounds, srcCopy, NULL) ... do stuff ... .. then copy back CopyBits(*mypm, ¤tWindow-portBits, &(*mypm)->bounds, &sourcerect, srcCopy, NULL); ----------------------------------------------------- This works great, expect that it copies it to another rectangle on the screen. So, if I want to copy it somewhere else, can't I just set the (*mypm)->baseAddr to newly allocated space, by inserting the following statement before the first CopyBits: (*mypm)->baseAddr = NewPtr(#bytes * (*mypm)->pixelSize); (Assume here the mypm is Locked) 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. Thanks :------------------------------------------------------------: : Tom Carstensen Usenet: tomc@mntgfx.MENTOR.COM : : Mentor Graphics Delphi: CARSTENSEN : : GEnie: CARSTENSEN : : : : . . . This is Edison Carter coming to you very much : : live and direct from Network 23 . . . : : - Edison Carter : :------------------------------------------------------------:
bytebug@dhw68k.cts.com (Roger L. Long) (05/15/88)
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