Path: utzoo!mnetor!uunet!mcvax!prlb2!bernard From: bernard@prlb2.UUCP (Bernard Yves) Newsgroups: comp.sys.mac Subject: Problem with Color CopyBits and Pictures Message-ID: <405@prlb2.UUCP> Date: 18 Jan 88 11:21:12 GMT Organization: Philips Research Laboratory, Brussels Lines: 83 I have a problem with CopyBits and Pictures : CopyBits seems to crash the machine when made after an OpenPicture. First of all, the environment : mac II with 1mb, 256 colors, internal hd40, system 4.2, Finder 6.0, LSC 2.11 (or 2.13 ?, not sure now) I want to write a little program to display files produced by a small ray tracer. The file format is quite simple : a binary file with the resolution (e.g. 256) and the red, green, blue byte values for pixels. I want also to produce a PICT equivalent file; to ease the problem, the CLUT is fixed (it is read from a resource). After some reading of IM, there seems to be a quite simple solution : makes an offscreen pixmap containing the pixel values of my image, open a picture, then copybit the pixmap in my window, then close the picture and puts the pic handle in the window record. But that does not work. Here is some part of the code : ... WindowPtr w; /* the window where the image is displayed */ Rect br; /* the bounding rect of the image */ PixMapHandle pm, pm2; /* pm is the handle to the offscreen pixmap */ PicHandle pic; ... /* creates the window w with the right rect centered on the screen */ ... pm2 = ( (CGrafPtr) w) -> portPixMap; /* pm2 is a handle to the window pixmap */ /* intialise the pixmap pm : allocates space for it, makes its clut pointer be the same as the window clut */ ... /* read the file and fill the pixmap pm with the pixel values computed from the r,g,b values by using Color2Index */ ... /* now open the picture and CopyBits ... */ SetPort(w); pic = OpenPicture(&br); CopyBits( (*pm), (*pm2), &br, &br, scrCopy, nil); ClosePicture(); SetWindowPic(w,pic); printf("size of Pic : %ld \n", GetHandleSize(pic) ); Seems easy, but does not work. The program crashes before the printf with system error = 01! If I do not open a picture, (suppress the statements with OpenPicture, ClosePicture,...), that works : the window is filled with my image. Is it a memory problem with CopyBits and OpenPicture ? (it crashes even with small image of 128*128 ). In fact, there is another solution which I tried and works but used too much memory and was really too slow; it does not use an offscreen pixmap and CopyBits, but SetCPixel. The code looks like this : ... RGBColor rgb; int h,v ; ... SetPort(w); pic = OpenPicture(&br); for (v =0; v < yres; v++) for (h=0; h < xres; h++) { ReadPixelFromFile(rgb); SetCPixel(h,v, &rgb); }; ClosePicture(); SetWindowPic(w,pic); Why the same scheme does not work with an offscreen pixmap and CopyBits ? Yves Bernard (bernard@prlb2.uucp) Philips Res. Lab, Brussels.