Newsgroups: comp.sys.next
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!swatsun!garth
From: garth@cs.swarthmore.edu (Garth Snyder)
Subject: Re: A simple question or two
Message-ID: <KFL1T2Y@cs.swarthmore.edu>
Organization: Swarthmore College, PA, USA
References: <1991Apr11.212629.25773@athena.mit.edu>
Distribution: na
Date: Fri, 12 Apr 1991 20:21:11 GMT

patl@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.

Operations of this sort are difficult to perform in PostScript.  You
pretty much have to read the bitmap and process the data yourself.

In simple cases you can do this without actually messing with the bits
directly.  For example, to process a rectangular region, you can use
readimage to pick up the bits, set the PostScript transfer function to
invert (or whatever operation you want) the grays, and re-image the
rectangle.

Below is a wrap that will do just that.  I don't think it's fully
debugged, so you will probably have to play around with it to make it
work.  It expects you to have previously set up a gstate object with
the inverted transfer function; this is a performance optimization
needed because executing the settransfer operator takes quite a long
time (on the order of half a second).

This still doesn't get you the ability to XOR along a line or path,
but you can probably work that with an offscreen drawing area and some
extra compositing operations.

If anyone has come up with a better solution to this problem, I would
love to hear about it.

defineps PSInvertRect(float x, y, width, height; userobject xorGstate)
    gsave
	x y width height matrix sizeimage % pxwd pxhi bps matrix multi ncolor
	pop pop {} % pxwd pxhi bps matrix {}
	4 index 3 index 8 exch div div .5 add round cvi 10 mul
	% pxwd pxhi bps matrix {} #bytes/scan * 10
	string % pxwd pxhi bps matrix {} scanstring
	mark 
	    x y width height {dup length string copy counttomark 1 roll} 
	    7 -1 roll 
	    % pxwd pxhi bps matrix {} mark [ x y width height proc string 
	    false readimage 
	    % pxwide pxhigh bps matrix {} mark strings...
	    counttomark 6 add -5 roll 
	    % mark strings pxwide pxhigh bps matrix {}
	    xorGstate setgstate
	    image
	pop 
   grestore
endps

--
Garth Snyder         |  UUCP: {bpa,liberty}!swatsun!garth
Swarthmore College   |   NET: garth@cs.swarthmore.edu
500 College Avenue   |  DOD#: 0085
Swarthmore, PA 19081 | QUOTE: "Quidquid latine dictum sit, altum viditur"
