Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!caen!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!uunet!rosie!aozer From: aozer@next.com (Ali Ozer) Newsgroups: comp.sys.next Subject: Re: Caching Images for Views .... Message-ID: <742@rosie.NeXT.COM> Date: 16 May 91 19:00:49 GMT References: <1991May15.161837.27550@noose.ecn.purdue.edu> <1991May15.183632.22391@agate.berkeley.edu> Sender: news@NeXT.COM Organization: Next Computer, Inc. Lines: 39 Nntp-Posting-Host: twinpeaks.next.com In article <1991May15.183632.22391@agate.berkeley.edu> Izumi Ohzawa writes: >Bitmap object is obsolete. Its functionality has been >expanded by NXImage object. > > myImage = [[NXImage alloc] initSize:&myRect.size]; > [myImage useCacheWithDepth: NX_TwoBitGrayDepth]; > [myImage lockFocus]; /* focus on NXImage to work on */ Nice description! However, one point: Caling "useCacheWithDepth:" with the NX_TwoBitGrayDepth argument forces the cache to be 2 bits; you really want a cache which can hold the cached image in its full glory. Thus you should use NX_DefaultDepth as the argument, which causes the cache to be depth limited to the depth limit of the system. And, because of the lazy depth promotion, the cache will remain at 2 bits (even on a deep machine) as long as you happen to draw 2-bits worth of gray into it (which is what most views do). But if the view happens to draw color, and you are on a color machine, you'd really like your cache to hold color as well. (You might want to refer to the recent discussions on window depths and depth limits.) It turns out that if your image has no representations, simply calling lockFocus creates a cache with the default depth. Thus calling useCacheWithDepth: becomes unnecessary. (This is a feature which allows Bitmap based apps to be converted more easily.) A final point is that the lockFocus method for NXImage returns a BOOL to indicate errors. Thus the correct way to use the lockFocus/unlockFocus pair is to if ([myImage lockFocus]) { // ... draw ... [myImage unlockFocus]; } You probably won't get any errors trying to focus on a simple cache; however, you might get errors if the image was built from an EPS or TIFF file, which are interpreted lazily, at time of composite: or lockFocus. Ali, Ali_Ozer@NeXT.com