Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!agate!shelby!polya!ali From: ali@polya.Stanford.EDU (Ali T. Ozer) Newsgroups: comp.sys.next Subject: Re: How do I display a byte image ??? Message-ID: <11651@polya.Stanford.EDU> Date: 4 Sep 89 17:07:15 GMT References: <438@dftsrv.gsfc.nasa.gov> <11638@polya.Stanford.EDU> <1989Sep2.235409.8890@agate.uucp> Sender: Ali T. Ozer Reply-To: aozer@NeXT.com (Ali Ozer) Organization: . Lines: 55 In article <1989Sep2.235409.8890@agate.uucp> Izumi Ohzawa writes: >Thanks Ali, but is there a way to use the `image` operator >in a PSWRAPped function which can receive a pointer to >binary image data directly? > >I think Bob's image file contains a straight binary image. >For occasional viewing, your method of viewing with Yap will >work well. However, it seems that I should be able to use >a pswrapped function of the form: > >defineps displayBinaryImage( > float x, y, width, height; > int xnum_pixels, ynum_pixels; int bits_per_pixel; > unsigned char *imagedata) > ..... >endps Yes, image can take binary data; in fact, if you append that header to a bunch of binary data and stuff it in Yap it works fine. As far as creating the above pswrap, I believe NXImageBitmap() does what you want. (Bob mentioned NXImageBitmap() in his original message, in fact...) You first lockFocus on the appropriate view or bitmap, then provide the rectangle to image to, the size of the image data (1024 by 1024, in this case), the bits per pixel (8), samples per pixel (1), the data format (NX_PLANAR), mask (0), and five pointers to data: NXRect rect = bounds; // In a view, for instance, you can image to bounds char *data; // // Here point "data" to your image data // NXImageBitmap (&rect, 1024, 1024, 8, 1, NX_PLANAR, 0, data, NULL, NULL, NULL, NULL); Depending on how fast you want to redraw the data, you might want to NXImageBitmap() into a view or bitmap. If are not concerned about redraw speed on scroll or resize, simply lockFocus in your view and call NXImageBitmap(). If you like to redraw the image real fast, then create a bitmap, and draw the image in that. Then composite from the bitmap to your actual view. That way you can forget about the original data and never again incur the cost of imaging the 8 bits down to 2 (as long as your program is running, of course...). Finally, how do you get at the data? Best approach is to probably memory map the file using streams: int maxSize, size; char *data = NULL; NXStream *s = NXMapFile ("datafile", NX_READONLY); if (s) NXGetMemoryBuffer (s, &data, &size, &maxSize); if (data) // You can use the data (there are size bytes of it) Ali Ozer, NeXT Developer Support aozer@NeXT.com