[comp.lang.postscript] Negative needed

rfutscher@pbs.org (04/11/91)

I have a printed circuit layout that I drew using my CAD program.
When I went to make the board I discovered that I need a negative.
If I plot to a postscript file is there a way to edit the 
postscript file so that the drawing is printed as a negitive?

Robert Futscher   rfutscher@pbs.org

brownd@agnes.acc.stolaf.edu (David H. Brown) (04/14/91)

In article <1947@chinacat.Unicom.COM> woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) writes:
>In article <1991Apr11.124626.12325@pbs.org>, rfutscher@pbs.org writes:
>> If I plot to a postscript file is there a way to edit the 
>> postscript file so that the drawing is printed as a negitive?
>> 
>Look through the file for the word setray.  It may be used in
>a procedure definition to make the file more compact.  IF it is, then
>examine it carefuly, and see what the incoming parameter is.  You can then
>modify the definition to complement the incoming paramater.
>
>Alternatly, you could search for every occurance of setgray or the
>re-defintion of it, and alter the parameter.
>
>Cheers'
>Woody

	Aargh! This might not work, and there's a much faster way! The
<settransfer> function controls the mapping of input values for <setgray> to
halftones created by <setscreen>.

	So all you need to do is insert the command:

{1 exch sub} settransfer

in the PostScript file before it starts drawing, and the complements will be
used automatically.

Of course, this won't work just by itself, as Woody's probably won't, for the
simple reason that you'll be drawing white lines on white paper! This line:

0 0 moveto 0 792 lineto 612 792 lineto 612 0 lineto closepath 0 setgray fill

will plot a box around a 8-1/2 by 11" page and fill it with black. Of course,
this line should occur _before_ you redefine <settransfer>. If you put it
after, you'll just have to make it:
	[...]	1 setgray fill

The <settransfer> can be enclosed in a gsave/grestore if non-negative drawing
needs to be done.

Also, the routine to fill the page with black must be done for each page; if
the document has multiple pages, insert the "1 setgray" version after each
<showpage> call.

And, I guess, there's always the possibility that the code would use
settransfer itself. Then things would be more complicated...

Dave Brown
brownd@agnes.acc.stolaf.edu

woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) (04/15/91)

In article <1991Apr11.124626.12325@pbs.org>, rfutscher@pbs.org writes:
> If I plot to a postscript file is there a way to edit the 
> postscript file so that the drawing is printed as a negitive?
> 
Look through the file for the word setray.  It may be used in
a procedure definition to make the file more compact.  IF it is, then
examine it carefuly, and see what the incoming parameter is.  You can then
modify the definition to complement the incoming paramater.

Alternatly, you could search for every occurance of setgray or the
re-defintion of it, and alter the parameter.

Cheers'
Woody

rcd@ico.isc.com (Dick Dunn) (04/16/91)

woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) writes:
> In article <1991Apr11.124626.12325@pbs.org>, rfutscher@pbs.org writes:
> > If I plot to a postscript file is there a way to edit the 
> > postscript file so that the drawing is printed as a negitive?

> Look through the file for the word setray.  It may be used in
> a procedure definition to make the file more compact...
[more on how to find/change uses of setgray]

A better way is to change the transfer function; that way you only have to
make one change and not worry about whatever "setgray" commands may exist.
(You're much less likely to find settransfer commands in a PostScript
file.)

In fact, there's an example in the "red book" (PS reference manual) - sec.
4.8 in the first edition, 6.3 in the second edition - which suggests
	{ 1 exch sub }
as a transfer function (give it to "settransfer") that gives you a
negative result.  Transfer functions have domain and range [0,1]; the
above procedure just flips the argument around.
-- 
Dick Dunn     rcd@ico.isc.com -or- ico!rcd       Boulder, CO   (303)449-2870
   ...While you were reading this, Motif grew by another kilobyte.

phys59@jetson.uh.edu (04/16/91)

In article <1991Apr11.124626.12325@pbs.org>, rfutscher@pbs.org writes:
> I have a printed circuit layout that I drew using my CAD program.
> When I went to make the board I discovered that I need a negative.
> If I plot to a postscript file is there a way to edit the 
> postscript file so that the drawing is printed as a negitive?
> 
> Robert Futscher   rfutscher@pbs.org

Try prefacing the file with
{1 exch sub} settransfer
for black and white files (which I assume this one is).
--
Ronald Parker, phys59@jetson.uh.edu
#include <stddisclaim.h>
Clever .sig held up pending FCC type acceptance.

lee@leo (Bill Lee) (04/17/91)

In article <1947@chinacat.Unicom.COM> woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) writes:
>In article <1991Apr11.124626.12325@pbs.org>, rfutscher@pbs.org writes:
>> If I plot to a postscript file is there a way to edit the 
>> postscript file so that the drawing is printed as a negitive?
>> 
>Look through the file for the word setray.  It may be used in
>a procedure definition to make the file more compact.  IF it is, then
>examine it carefuly, and see what the incoming parameter is.  You can then
>modify the definition to complement the incoming paramater.
>
>Alternatly, you could search for every occurance of setgray or the
>re-defintion of it, and alter the parameter.
>
>Cheers'
>Woody


From the red book (rev.1) pg 82-83:

	"The transfer function may also be redefined to produce specific
	 effects. For example, the transfer function
		{1 exch sub}
	 will invert the output image; this is useful for producing
	 photographic negatives...."

This seems like a reasonable way to do the job: searching through a PS
file (that could be quite large) for all occurences of a setgray command
is not (IMHO) reasonable.

Bill Lee			lee@shell.com
Shell Oil Co.

cet1@cl.cam.ac.uk (C.E. Thompson) (04/19/91)

In article <1991Apr17.141806.20838@shell.shell.com> lee@leo (Bill Lee) writes:
>
>From the red book (rev.1) pg 82-83:
>
>	"The transfer function may also be redefined to produce specific
>	 effects. For example, the transfer function
>		{1 exch sub}
>	 will invert the output image; this is useful for producing
>	 photographic negatives...."
>
>This seems like a reasonable way to do the job: searching through a PS
>file (that could be quite large) for all occurences of a setgray command
>is not (IMHO) reasonable.
>
and there have been other postings along the same lines. It may be worth
quoting the substantially more subdued version in the new LRM (p.309):

  In addition to their intended use for gamma correction, transfer functions
  can be used to produce a variety of special, device-dependant effects.
  For example, on a monochrome device, the transfer function

    {1 exch sub}

  inverts the output colors, producing a negative rendition of the page.
  In general, this method does not work for color devices; inversion can be 
  more complicated than merely inverting each of the components. Because
  the effects produced are device dependant, transfer functions should not
  be altered by a page description that is intended to be device independant.

Adobe presumably realise by now that it was a bad mistake to recommend   
using a device-dependant part of the graphics state to achieve device-  
independant effects (in particular the white/black inversion of images: of
course this is made redudant by the /Decode entry in the new level 2 form 
of "image", but in level 1 there was really no way to do it *except*     
fiddling with transfer functions). Read the paragraph after the one quoted
above to see the unclean spec in CMYK devices necessitated by existing
practice.

By the way, neither the old nor the new LRM guarantees that the default  
transfer function is the identity function, even for a monochrome printer.
The more paranoid among you will therefore prefer

   { 1 exch sub null exec } dup 3 currenttransfer put settransfer 

or the like. In all cases I know about, though, the default is the identity
function --- any known exceptions?

Chris Thompson
JANET:    cet1@uk.ac.cam.phx
Internet: cet1%phx.cam.ac.uk@nsfnet-relay.ac.uk

taft@adobe.com (Ed Taft) (04/23/91)

In article <1991Apr18.224028.21519@cl.cam.ac.uk> cet1@cl.cam.ac.uk (C.E. Thompson) writes:

>Adobe presumably realise by now that it was a bad mistake to recommend   
>using a device-dependant part of the graphics state to achieve device-  
>independant effects.

Indeed so! The most troublesome example of this is the "pattern fill"
technique, using a halftone screen to produce a repeating pattern. This
technique seemed clever at the time it was invented, but it has caused no
end of compatibility headaches. This is what led us to distinguish between
"specification" and "rendering" and to describe them in separate chapters in
the second edition of the red book.

Although Chris's advice regarding device-independent effects is excellent,
it may not apply in this case. I no longer have the original article in this
thread, but I believe its author wished to take an existing PostScript
document and render its output as negatives instead of positives. It's
reasonable to use the transfer function to achieve this, since the user
desires to obtain a specific effect on a specific device. This is quite
different from the case in which the application generating the document
fiddles with the transfer function as part of specifying colors.

Don't forget to do an erasepage after settransfer so the background color is
correctly mapped through the new transfer function.

Ed Taft      taft@adobe.com      ...decwrl!adobe!taft