PostScript Web Colorizer Utilities
By Don Lancaster                                                                   
Version 1.3 February 25, 1998
Copyright c. 1998 by Don Lancaster and Synergetics, Box 809, Thatcher AZ, 85552
(520) 428-4073. synergetics@tinaja.com All commercial rights and all electronic media
rights are *fully* reserved. Linking welcome. Reposting is expressly forbidden.

Consulting services available.
Further support on www.tinaja.com/info01.html  


(The following is believed correct. Please report any errors or differing experiences.)

% Much of the content to be transferred to web or cd is in its
% its original black and white form. Quite often, it is desired to
% add color tints on the web while preserving exact original
% grays for black and white printing.

% To do this properly, special and obscure constant luminescence tints
% may be required. Otherwise the final grays will be unacceptable.

% This happens because of the gray = 0.3 red + 0.59 green + 0.11 blue
% formula used for RGB color. This utility shows one solution.

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

% The GENERAL PROCEDURE for using PostScript-as-language is as
% follows:

%%%%%%%%% (A) INSTALL AND RUN GONZO UTILITIES %%%%%%%%%%%%%%%%%%

% These utilities optionally use my gonzo utilities from
% http://www.tinaja.com/psutils/gonzo20.ps

% (C:\\windows\\desktop\\gonzo\\gonzo.ps) run % run the gonzo utilities

% gonzo begin                       % activate the gonzo utilities
% ps.util.1 begin
% % printerror
% nuisance begin

%%%%%%%%% (B) POSTSCRIPT WEB COLORIZER UTILITIES %%%%%%%%%%%%%%%%%%%%%

!%

% IMPROVED POSTSCRIPT WEB COLORIZER UTILITIES
% ===========================================
% by  Don Lancaster

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

% Version 2.2  December 12, 1996 

% Copyright c 1996 by Don Lancaster and Synergetics, Box 809, Thatcher,
% AZ, 85552 (520) 428-4073. www.tinaja.com don@tinaja.com All commercial
% rights and all electronic media rights **fully** reserved. Linking
% is welcome, but reposting is expressly forbidden.

% Consulting services available through don@tinaja.com or (520) 428-4073.

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

% This is a greatly improved (v2.1) version of my PostScript colorizer. 

% The new continuous tints have the magical property that they can take
% a preexisting gray, show it in color onscreen and yet still print 
% the original gray to a B/W hard copy printer. They are especially 
% well suited to online display of older printed documents.

% Install in existing program where -setgray- can be redefined.

% The -settint- variable is a max saturated constant luminescence hue. 
% 0 = red, 0.33 = green  0.67 = blue  1.0 = red. See COLORZD2.PDF demo.

% To use, the colorizer module is installed near the beginning of the
% existing grayscale code at a point where /setgray can be redefined.

% Tints are selected when and as needed by using either * 0.43 settint *
% or a predefined convenience operator such as  * beige *.

% A /currenttint convenience operator is also defined.

% Two versions of the colorizer code are shown below. One is annotated.
% The second is compacted.


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

% PostScript colorizer module. Allows pre-existing grays to appear as
% fully saturated colors online, yet still print normally on B/W printer.

% Insert in program or .eps file at any point where /setgray can be redefined.
% Affects only B/W color space.

% /settint is a 0-1 self-generating proc that sets the current saturated
% color. Preceed with *hue* variable. As in 0.27 settint for lime.  

%    red-yellow      0  to .16
%    yellow-green   .16 to .33
%    green-aqua     .33 to .50
%    aqua-blue      .50 to .66
%    blue-magenta   .66 to .87 
%    magenta-red    .87 to  1



/settint {dup /currenttint exch store   % save for possible later use
 
 5.999 mul dup floor cvi                % pick one of six color rules
 /&cbar exch store 
 dup floor sub /&cwt exch store         % find offset into rule


[                         % start an array of six "color range" rules


{ % red-yellow rule0  0  to .16  hold red, adjust green, minimize blue


/setgray [                       %  redefine DEFERRED setgray rule0 proc

  /dup cvx 0.3 &cwt 0.59 mul add /ge cvx    % calculate high-low rule

     [                           % start high rule

1                                % set saturated red 

/exch cvx


&cwt 0.59 mul 0.30 add           % set minimized blue
/sub cvx
1 &cwt sub 0.59 mul 0.11 add        
/div cvx                             

/dup cvx

1 &cwt sub /mul cvx              % set green per tint rule
&cwt /add cvx                     
 
/exch cvx                        % swap blue and green

     ] cvx                       % complete high rule
     

     [                           % start low rule  

&cwt 0.59 mul 0.3 add /div cvx   % how much red and green
/dup cvx                         % set red 
&cwt /mul cvx                    % set green
0                                % set blue
     ] cvx                       % complete low rule
                        
/ifelse cvx                      % pick high or low rule
/setrgbcolor cvx                 % set rgb colors
] cvx
/def cvx
   }                             % complete tint array proc for rule0


{  % yellow-green rule1 .16 to .33 adjust red, hold green, minimize blue



/setgray [                      %  redefine DEFERRED setgray rule1 proc

 /dup cvx 0.59 1 &cwt sub 0.3 mul add /ge cvx  % calculate high-low rule

     [                          % start high rule

                                % Note that colors advance "frontwards"
                                % in rules 0,2,4 and "backwards" in
                                % rules 1,3,5. "1 &cwt sub" reverses.


1 &cwt sub 0.3 mul 0.59 add     % set minimized blue
/sub cvx
&cwt 0.3 mul 0.11 add        
/div cvx                             

/dup cvx

&cwt /mul cvx                   % set red per tint rule
1 &cwt sub /add cvx                     % full red + part red
 
/exch cvx                       % swap blue and red

1 /exch cvx                     % swap blue and green

     ] cvx                      % complete high rule
     

     [                          % start low rule  

1 &cwt sub 0.3 mul 0.59 add /div cvx    % how much red and green

/dup cvx                        % set green
1 &cwt sub /mul cvx             % set red
/exch cvx                       % swap red and green
0                               % set blue
     ] cvx                      % complete low rule
                        
/ifelse cvx                     % pick high or low rule
/setrgbcolor cvx                % set rgb colors
] cvx
/def cvx
   }                            % complete tint array proc for rule1


{% green - aqua  rule2 .33 to .50  minimize red, hold green, adjust blue



/setgray [                      %  redefine DEFERRED setgray rule2 proc

  /dup cvx 0.59 &cwt 0.11 mul add /ge cvx    % calculate high-low rule

     [                          % start high rule

                               

&cwt 0.11 mul 0.59 add          % set minimized red
/sub cvx
1 &cwt sub 0.11 mul 0.30 add        
/div cvx                             

/dup cvx

1 &cwt sub /mul cvx             % set blue per tint rule
&cwt /add cvx                     
 


1                               % set saturated green

/exch cvx                       % swap blue and green


     ] cvx                      % complete high rule
     

     [                          % start low rule  

0                               % set red 

/exch cvx

&cwt 0.11 mul 0.59 add /div cvx % how much blue and green
/dup cvx                        % set green 
&cwt /mul cvx                   % set blue

     ] cvx                      % complete low rule
                        
/ifelse cvx                     % pick high or low rule
/setrgbcolor cvx                % set rgb colors
] cvx
/def cvx
   }                            % complete tint array proc for rule2



{ % aqua - blue rule3 .50 to .67  minimize red, hold blue, adjust green

/setgray [                      %  redefine DEFERRED setgray proc rule3

  /dup cvx 0.59 1 &cwt sub mul 0.11 add /ge cvx    % calculate high-low rule

     [                          % start high rule

                               

1 &cwt sub 0.59 mul 0.11 add    % set minimized red
/sub cvx
&cwt 0.59 mul 0.30 add        
/div cvx                             

/dup cvx

&cwt /mul cvx                   % set green per tint rule
1 &cwt sub /add cvx                     
 

1                               % set saturated blue

     ] cvx                      % complete high rule
     
     [                          % start low rule  

0                               % set red 

/exch cvx

1 &cwt sub 0.59 mul 0.11 add /div cvx   % how much blue and green

/dup cvx                        % set blue 
1 &cwt sub /mul cvx             % set green

/exch cvx                       % swap blue and green

     ] cvx                      % complete low rule
                        
/ifelse cvx                     % pick high or low rule
/setrgbcolor cvx                % set rgb colors
] cvx
/def cvx
   }                            % complete tint array proc for rule3


{ % blue - magenta rule4 .67 to .83 adjust red, minimize green, hold blue


/setgray [                      %  redefine DEFERRED setgray rule 4 proc

  /dup cvx 0.11 &cwt 0.30 mul add /ge cvx    % calculate high-low rule

     [                          % start high rule

                               

&cwt 0.30 mul 0.11 add          % set minimized green
/sub cvx
1 &cwt sub 0.30 mul 0.59 add        
/div cvx                             

/dup cvx

1 &cwt sub /mul cvx             % set red per tint rule
&cwt /add cvx                     
 
/exch cvx                       % swap red and green

1                               % set saturated blue

     ] cvx                      % complete high rule
     
     [                          % start low rule  


&cwt 0.30 mul 0.11 add /div cvx % how much red and blue
/dup cvx                        % set blue
&cwt /mul cvx                   % set red

/exch cvx                       % interchange red and blue
0 /exch cvx                     % set green


     ] cvx                      % complete low rule
                        
/ifelse cvx                     % pick high or low rule
/setrgbcolor cvx                % set rgb colors
] cvx
/def cvx
   }                            % complete tint array proc rule4


{ % magenta - red rule5 .83 to 1.00  hold red, minimize green, adjust blue


/setgray [                      %  redefine DEFERRED setgray rule5 proc

  /dup cvx 0.30 1 &cwt sub 0.11 mul add /ge cvx    % calculate high-low rule

     [                          % start high rule

        
1  /exch cvx                    % set saturated red                       

1 &cwt sub 0.11 mul 0.30 add    % set minimized green
/sub cvx
&cwt 0.11 mul 0.59 add        
/div cvx                             

/dup cvx

&cwt /mul cvx                   % set blue per tint rule
1 &cwt sub /add cvx                     
 
     ] cvx                      % complete high rule
     
     [                          % start low rule  


1 &cwt sub 0.11 mul 0.30 add /div cvx   % how much red and blue

/dup cvx                        % set red
1 &cwt sub /mul cvx             % set blue
0 /exch cvx                     % set green


     ] cvx                      % complete low rule
                        
/ifelse cvx                     % pick high or low rule
/setrgbcolor cvx                % set rgb colors
] cvx
/def cvx
   }                            % complete tint array proc for rule5

] &cbar get exec exec           % redefine chosen setgray

}  def                          % complete /settint definition

0.08 settint                    % set initial tint shades



%%%%%%%%%%%%%% COMPACT  VERSION OF  COLORIZER II %%%%%%%%%%%%%%%%%%%%%%

/settint {dup /currenttint exch store 5.999 mul dup floor cvi /&cbar
          exch store dup floor sub /&cwt exch store [
{/setgray [ /dup cvx 0.3 &cwt 0.59 mul add /ge cvx
 [1 /exch cvx &cwt 0.59 mul 0.30 add /sub cvx 1 &cwt sub
 0.59 mul 0.11 add /div cvx /dup cvx 1 &cwt sub /mul cvx
 &cwt /add cvx /exch cvx ] cvx [ &cwt 0.59 mul 0.3 add /div
 cvx /dup cvx &cwt /mul cvx 0] cvx /ifelse cvx /setrgbcolor
 cvx] cvx /def cvx}
{/setgray [/dup cvx 0.59 1 &cwt sub 0.3 mul add /ge cvx
 [1 &cwt sub 0.3 mul 0.59 add /sub cvx &cwt 0.3 mul 0.11 add
 /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx /exch cvx
 1 /exch cvx] cvx [1 &cwt sub 0.3 mul 0.59 add /div cvx /dup
 cvx 1 &cwt sub /mul cvx /exch cvx 0] cvx /ifelse cvx
 /setrgbcolor cvx] cvx /def cvx}
{/setgray [/dup cvx 0.59 &cwt 0.11 mul add /ge cvx [&cwt
 0.11 mul 0.59 add /sub cvx 1 &cwt sub 0.11 mul 0.30 add
 /div cvx /dup cvx 1 &cwt sub /mul cvx &cwt /add cvx 1 /exch
 cvx] cvx [0 /exch cvx &cwt 0.11 mul 0.59 add /div cvx /dup cvx
 &cwt /mul cvx] cvx /ifelse cvx /setrgbcolor cvx] cvx
 /def cvx}
{/setgray [/dup cvx 0.59 1 &cwt sub mul 0.11 add /ge cvx [1 &cwt
 sub 0.59 mul 0.11 add /sub cvx &cwt 0.59 mul 0.30 add /div cvx
 /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx 1] cvx [0 /exch cvx
 1 &cwt sub 0.59 mul 0.11 add /div cvx /dup cvx 1 &cwt sub /mul
 cvx /exch cvx] cvx /ifelse cvx /setrgbcolor cvx] cvx
/def cvx}
{/setgray [/dup cvx 0.11 &cwt 0.30 mul add /ge cvx[&cwt 0.30 mul
 0.11 add /sub cvx 1 &cwt sub 0.30 mul 0.59 add /div cvx /dup
 cvx 1 &cwt sub /mul cvx &cwt /add cvx /exch cvx 1] cvx [ &cw
 0.30 mul 0.11 add /div cvx /dup cvx &cwt /mul cvx /exch cvx 0
 /exch cvx ] cvx /ifelse cvx /setrgbcolor cvx ] cvx /def cvx}
{/setgray [ /dup cvx 0.30 1 &cwt sub 0.11 mul add /ge cvx[ 1
 /exch cvx 1 &cwt sub 0.11 mul 0.30 add /sub cvx &cwt 0.11 mul
 0.59 add /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx
 ] cvx [ 1 &cwt sub 0.11 mul 0.30 add /div cvx /dup cvx
 1 &cwt sub /mul cvx 0 /exch cvx] cvx /ifelse cvx /setrgbcolor
 cvx ] cvx /def cvx}

] &cbar get exec exec} bind def

/beige  {0.11 settint} def      % examples of convenience operators
/aqua   {0.52 settint} def

% For even more compact code, isolate only desired /setgray procs
% actually used for the selected tints.

%%%%%%%%%%%%%%%%%%%%%%%%%% USE  EXAMPLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Prepend colorizer module at appropriate place early in preexisting
% gray code. To colorize an area where existing grays are in use and
% /setgray can be redefined, simply do a ...

0.78 settint                     % colorize grays to chosen magenta

% or else a ...

beige                            % colorize grays to beige and brown

% Note that a "beige" setting gives you black for 0 setgray, a deep
% text brown for 0.25 setgray, a rich chocolate for 0.33 setgray, 
% a bright orange for 0.6 setgray, a nice beige tint for 0.9 setgray
% and white for 1 setgray.
% To select a tint, use 0 for red, 0.33 for green, 0.67 for blue,
% up to 1.0 back to red. Or any shade inbetween.

% For even more compact code, isolate only desired /setgray procs
% actually used for the selected tints.

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

% Copyright c 1997 by Don Lancaster and Synergetics, Box 809, Thatcher,
% AZ, 85552 (520) 428-4073. www.tinaja.com don@tinaja.com All commercial
% rights and all electronic media rights **fully** reserved. Linking
% is welcome, but reposting is expressly forbidden.

% Consulting services available through don@tinaja.com or (520) 428-4073.
% Also see http://www.tinaja.com/info01.html

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



Please click here to...