[comp.lang.postscript] transfer function

bradlee@cg-atla.UUCP (Rob Bradlee) (02/21/90)

I would like to adjust the transfer function by providing a 256 entry lookup
table for values 0-255.  I'd also like to be able to switch back to the
default sometimes.  Any advice from the experienced PS gurus would be most
appreciated.

				Rob


-- 
Rob Bradlee  w:(508)-658-5600 X5153  h:(617)-944-5595
AGFA Compugraphic Division.    ...!{decvax,samsung}!cg-atla!bradlee
200 Ballardvale St.                        bradlee@cg-atla.agfa.com
Wilmington, Mass. 01887           The Nordic Way: Ski till it hurts!

jwz@lucid.com (Jamie Zawinski) (09/29/90)

In article <20829@well.sf.ca.us> shiva@well.sf.ca.us (Kenneth Porter) writes:
>
> As Jamie Zawinski points out, settransfer can also be used,
> but you should modify his example to concatenate the new
> transfer proc with the result of currenttransfer, so that
> the result can be combined with previous transfer ops (the
> most important being any builtin engine compensation).

Hmm, how would you do that?  I don't think

	{ { currenttransfer exec 1 exch sub fade-factor mul 1 exch sub } 
	  settransfer }

will work, because currenttransfer is going to return the currently-executing
procedure, leading to infinite recursion.  You could do something like

	/saved-transfer currenttransfer def
	{ { saved-transfer 1 exch sub fade-factor mul 1 exch sub }
	  settransfer }

but that doesn't seem especially foolproof.

		-- Jamie

wiml@milton.u.washington.edu (William Lewis) (09/29/90)

In article <JWZ.90Sep28150050@kolyma.lucid.com> jwz@lucid.com (Jamie Zawinski) writes:
>In article <20829@well.sf.ca.us> shiva@well.sf.ca.us (Kenneth Porter) writes:
>Hmm, how would you do that?  I don't think
>
>	{ { currenttransfer exec 1 exch sub fade-factor mul 1 exch sub } 
>	  settransfer }
>
>will work, because currenttransfer is going to return the currently-executing
>procedure, leading to infinite recursion.  You could do something like
>
>	/saved-transfer currenttransfer def
>	{ { saved-transfer 1 exch sub fade-factor mul 1 exch sub }
>	  settransfer }
>
>but that doesn't seem especially foolproof.

  [ /currenttransfer load /exec cvx 1 /exch cvx /sub cvx fade-factor /mul cvx 
1 /exch  cvx /sub  cvx ] cvx settransfer ?

   I think that'll work .. the reason "currenttransfer" is load/exec'd
rather than just cvx'd is that otherwise it would be identical to the
first example up there, with infinite recursion... Or, you could do

  { currenttransfer 1 exch sub fade-factor mul 1 exch sub } bind settransfer

  in which the bind does about the same thing as building the proc as an
array did up there, except it binds *all* of it, not just the /currenttransfer.



-- 
 wiml@milton.acs.washington.edu       Seattle, Washington   
     (William Lewis)   |  47 41' 15" N   122 42' 58" W  
"These 2 cents will cost the net thousands upon thousands of 
dollars to send everywhere. Are you sure you want to do this?"

jwz@lucid.com (Jamie Zawinski) (09/29/90)

In article <8301@milton.u.washington.edu> wiml@milton.u.washington.edu (William Lewis) writes:
>
> [ /currenttransfer load /exec cvx 1 /exch cvx /sub cvx fade-factor /mul cvx 
>   1 /exch  cvx /sub  cvx ] cvx settransfer ?
[ ... ]
>  { currenttransfer 1 exch sub fade-factor mul 1 exch sub } bind settransfer
>
> in which the bind does about the same thing as building the proc as an
> array did up there, except it binds *all* of it, not just the
> /currenttransfer.

Hmm... I think both of these are equivalent to my second example, 

>	/saved-transfer currenttransfer def
>	{ { saved-transfer 1 exch sub fade-factor mul 1 exch sub }
>	  settransfer }

which now that I think about it some more, I don't think has any problems.
To be extra careful, you could do

	{ /--dummy-- 1 exch sub fade-factor mul 1 exch sub }
	dup 0 currenttransfer put
	bind settransfer

assuming I don't have "put"'s arguments in the wrong order.

 -- Jamie

shiva@well.sf.ca.us (Kenneth Porter) (10/05/90)

Actually, I think you want to put the old transfer function at
the *end* of the new transfer procedure to get the right
effect, since there's no guarantee that the two procedures are
commutative:
 
/newstuff { .... } def
% remember to disable packing so put can write into executable array
false setpacking        % real code should save current packing state
{ newstuff 0 exec } dup 1 currenttransfer put settransfer
 
The resulting transfer proc is
 
{ newstuff <oldtransfer> exec }
 
Is currenttransfer a variable or an operator?  If an operator, then the
following doesn't work:
 
{ currenttransfer } bind
 
If it's a variable, then you can just do this:
 
{ //currenttransfer exec }
 
Ken (shiva@well.sf.ca.us)