Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!rosie!aozer From: aozer@next.com (Ali Ozer) Newsgroups: comp.sys.next Subject: Re: A simple question or two Message-ID: <494@rosie.NeXT.COM> Date: 12 Apr 91 23:17:30 GMT References: <1991Apr11.212629.25773@athena.mit.edu> Sender: news@NeXT.COM Distribution: na Organization: Next Computer, Inc. Lines: 54 Nntp-Posting-Host: twinpeaks.next.com In article <1991Apr11.212629.25773@athena.mit.edu> Patrick J. LoPresti writes: >I want to draw a line across a View so that black pixels along the line >become white and white pixels along the line become black. In other >words, I want an XOR transfer mode for my pen. I don't care what >happens to shades of gray. Do you really want to do this or do you want to highlight or frame an area in your view? If it's the former, ie, your app really requires that you reverse the pixels in an area, then PostScript doesn't provide a way: In the PostScript model you cannot do drawing based on the pixels which have already been painted. Pixels which are drawn always replace the pixels under them. Thus you cannot draw in XOR mode (or any other mode where the color of the pixels would end up being dependent on the pixels that are already there). This leaves redrawing your image as one way to get it to show up differently. You could get the exact effect you want (black->white, white->black) by redrawing the view with the appropriate "negate" transfer function. (For instance, {1.0 exch sub}. See settransfer.) Another way to invert an image is to take advantage of some of the NeXTstep extensions to Display PostScript. These provide ways to read pixels back from windows (readimage or initData:fromRect: in NXBitmapImageRep), and ways to composite areas of pixels together. As you discovered, the XOR mode can be used by drawing your image in an offscreen window (using transparency for white, say), and then using compositerect to invert it and then compositing it to your on-screen window. Coming back to the original question: If what you wanted to do was to highlight or frame an area of your view, then using an XOR-based inversion might not be the best idea. XORing is often used as a means of highlighting because it's easy, cheap, and reversible. However, it seldom makes visual sense (especially with color images based on palettes). Depending on the situation, there are different ways of highlighting an item: sometimes you want to redraw it brighter or darker, sometimes you want to change one or more colors, sometimes you want to change the background, sometimes you want to draw a box or little knobbies around it, etc. NeXTstep provides the "highlight" composite operator, which is used to highlight monochrome text (by reversing the white & the light gray, which makes the background change color). It's also useful in some other cases, like highlighting the standard grayscale buttons used in NeXTstep. In other situations, you can simply do whatever drawing you need to do to highlight the area, then redraw the area when to unhighlight. If redrawing it is too slow, then cache the image and composite from the cache to refresh. This might seem like overkill, but it makes the interface cleaner and highlighting and selections more intuitive and visually appealing to the end user. Ali, Ali_Ozer@NeXT.com