%!
%  COLORIZING BLACK AND WHITE POSTSCRIPT
%  =====================================
%  by  Don Lancaster

%  ======================================================================
%  copyright c 1996 by Don Lancaster and Synergetics, Box 809, Thatcher,
%  AZ, 85552. synergetics@tinaja.com (520) 428-4073.  All commercial rights
%  and all electronic media rights **fully** reserved. Reposting forbidden.

%  Support on www.tinaja.com   Consulting services via don@tinaja.com
%  ====================================================================

%  CAUTION: Read first as textfile. Then extract relevant modules below.
%           Remove leading %% from modules before use

%  Suppose you have bunches of original PostScript files intended to
%  print LIGHT grays in their B/W hard copy. Is there some sneaky trick you
%  can pull to make these grays appear in color on a screen or over the net?

%  Here is one sneaky and seamless approach I use. Unfortunately, the color
%  choices are somewhat restricted for the lightest grays. But it otherwise
%  works like a champ.

%  What you do is redefine your -setgray- operator at the start of each
%  document to really do a -setrgbcolor-. The tricky part is getting the
%  printer to undo back to gray at the same level you started with.

%  The rule for RGB to gray conversion in PostScript is the same as NTSC
%  video (per the red book, chapter six). Namely...

%          Gray   =   0.3 Red  +  0.59 Green  +   0.11 Blue

%  Let's generate three primary colors by holding back on one gun only...

%  BLUE
%  ====
%
%  Let blue = 1  and    red = green    
%  red = green =  (gray - .11)/.89    for  gray = .89 to 1.0
%  for lower grays, use 0 red 0 green, blue/.89
%  thussly...

%%   % light blue tinter for gray PostScript code. Insert at beginning.
%%   /setgray {dup 0.11 ge {0.11 sub 0.89 div dup 1 setrgbcolor}
%%                 {0.11 div 0 exch 0 exch setrgbcolor} ifelse} def

%%   % light red tinter for gray PostScript code. Insert at beginning.
%%   /setgray {dup 0.3 ge {0.3 sub 0.7 div 1 exch dup setrgbcolor}
%%                   {0.3 div 0 0 setrgbcolor} ifelse} def 

%%   % light green tinter for gray PostScript code. Insert at beginning.
%%   /setgray {dup 0.59 ge {0.59 sub 0.41 div dup 1 exch setrgbcolor}
%%                   {0.59 div 0 exch 0 setrgbcolor} ifelse} def 

%  And three primary complementary by holding back on two guns...

%%   % light turquoise tinter for gray PostScript code. Insert at beginning.
%%   /setgray {dup 0.7 ge {0.7 sub 0.3 div 1 1 setrgbcolor}
%%                   {0.7 div 0 exch dup setrgbcolor} ifelse} def

%%   % light magenta tinter for gray PostScript code. Insert at beginning.

%%   /setgray {dup 0.41 ge {0.41 sub 0.59 div 1 exch 1 setrgbcolor}
%%                   {0.41 div dup 0 exch setrgbcolor} ifelse} def 

%%   % bright yellow tinter for gray PostScript code. Insert at beginning.

%%   /setgray {dup 0.89 ge {0.89 sub 0.11 div 1 exch 1 exch setrgbcolor}
%%                   {0.89 div dup 0 setrgbcolor} ifelse} def 

% for a 0.96 light gray, all of these are too subtle, except for yellow
% which is way too harsh. Here is a useful lime green compromise...

%%  % nice lime tinter for gray PostScript code. Insert at beginning.

%%  /setgray {dup 0.842 ge {dup .7 mul .59 sub .11 div 1 exch setrgbcolor}
%%  {0.89 div dup 1.1233 div exch 1.1233 mul 0 setrgbcolor} ifelse} def

% and my current favorite...

%%  % best beige tinter for gray PostScript code. Insert at beginning.
%%  /setgray {dup 0.731 ge {dup .41 mul .30 sub .11 div 1 exch setrgbcolor}
%%  {0.856 div dup 1.155 mul exch 1.55 div 0 setrgbcolor} ifelse} def 

% Any of these routines may be placed at the beginning of the PostScript
% code. At a point where -setgray- is interceptable and redefinable.

% An alternate route is to select a desired tint from a matrix...



/tintmat [

 {dup 0.11 ge {0.11 sub 0.89 div dup 1 setrgbcolor}              % 0 blue
 {0.11 div 0 exch 0 exch setrgbcolor} ifelse}    
 
{dup 0.3 ge {0.3 sub 0.7 div 1 exch dup setrgbcolor}             % 1 red
 {0.3 div 0 0 setrgbcolor} ifelse}

{dup 0.59 ge {0.59 sub 0.41 div dup 1 exch setrgbcolor}          % 2 green
 {0.59 div 0 exch 0 setrgbcolor} ifelse} 
 
 {dup 0.7 ge {0.7 sub 0.3 div 1 1 setrgbcolor}                   % 3 turquoise
 {0.7 div 0 exch dup setrgbcolor} ifelse} 
 
 {dup 0.41 ge {0.41 sub 0.59 div 1 exch 1 setrgbcolor}           % 4 magenta
 {0.41 div dup 0 exch setrgbcolor} ifelse} 
  
 {dup 0.89 ge {0.89 sub 0.11 div 1 exch 1 exch setrgbcolor}      % 5 yellow
 {0.89 div dup 0 setrgbcolor} ifelse} 

{dup 0.842 ge {dup .7 mul .59 sub .11 div 1 exch setrgbcolor}    % 6 lime
{0.89 div dup 1.1233 div exch 1.1233 mul 0 setrgbcolor} ifelse} 

 {dup 0.731 ge {1 exch dup .41 mul .30 sub .11 div  setrgbcolor} % 7 beige
{0.856 div dup 1.155 mul exch 1.55 div 0 setrgbcolor} ifelse}  

 ] def

 /tint 7 def
 /setgray {tintmat tint get cvx exec} bind def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% What if the document is ALREADY in Acrobat?

% First do a LEVEL I print to disk of POSTSCRIPT CODE. View the file with 
% word processor to verify the /G setgray command is always used, and never
% the /:F setrgbcolor command.
% then redefine /rg as {.11 mul exch .89 mul add exch .3 mul add G} 
% Then redefine /G and redistill. 

%%  For a demo of the results, see MUSE109.PDF on www.tinaja.com
%%
%%                           < end of text >

%  ======================================================================
%  Copyright c 1996 by Don Lancaster and Synergetics, Box 809, Thatcher,
%  AZ, 85552. synergetics@tinaja.com (520) 428-4073.  All commercial rights
%  and all electronic media rights **fully** reserved. Reposting forbidden.

%  Support on www.tinaja.com   Consulting services via don@tinaja.com
%  ====================================================================