home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / dvips583.zip / contrib.zip / dvips / contrib / colorsep.lpro next >
Text File  |  1998-11-03  |  4KB  |  185 lines

  1. %!
  2. % Colour separation. 
  3. % Ask dvips to do 4 pages. In bop-hook, cycle
  4. % round CMYK color spaces.
  5. %
  6. % Sebastian Rahtz 30.9.93
  7. % checked 7.1.94
  8. % from Green Book, and Kunkel Graphic Design with PostScript
  9. % (Green Book Listing 9-5, on page 153.)
  10. %
  11. /seppages  0  def 
  12. userdict begin
  13. /Min {% 3 items on stack
  14. 2 copy lt { pop }{ exch pop } ifelse
  15. 2 copy lt { pop }{ exch pop } ifelse
  16. } def
  17. /SetGray {
  18.  1 exch sub systemdict begin adjustdot setgray end    
  19. } def
  20. /sethsbcolor {systemdict begin
  21.   sethsbcolor currentrgbcolor end
  22.   userdict begin setrgbcolor end}def 
  23.  
  24. /ToCMYK
  25. % Red book p 305
  26.   {
  27. % subtract each colour from 1
  28.   3 { 1 exch sub 3 1 roll } repeat
  29. % define percent of black undercolor
  30. % find minimum (k)
  31.   3 copy  Min 
  32. % remove undercolor
  33.   blackUCR sub
  34.   dup 0 lt {pop 0} if 
  35.   /percent_UCR exch def 
  36. %
  37. % subtract that from each colour
  38. %
  39.   3 { percent_UCR sub 3 1 roll } repeat 
  40. % work out black itself
  41.   percent_UCR 1.25 mul % 1 exch sub
  42. % stack should now have C M Y K
  43. } def 
  44. %
  45. % crop marks
  46. %
  47. /cX 18 def 
  48. /CM{gsave TR 0 cX neg moveto 0 cX lineto stroke
  49. cX neg 0 moveto cX 0 lineto stroke grestore}def 
  50. %
  51. /bop-hook{cX dup TR
  52. %
  53. % which page are we producing
  54. %
  55.    seppages 1 add 
  56.     /seppages exch def
  57.      seppages 5 eq { /seppages  1  def } if
  58.      seppages 1 eq { 
  59.       /ColourName (CYAN) def 
  60.       CYAN setupcolor    
  61.       /WhichColour 3 def } if 
  62.    seppages 2 eq { 
  63.       /ColourName (MAGENTA) def 
  64.       MAGENTA setupcolor 
  65.      /WhichColour 2 def } if
  66.    seppages 3 eq { 
  67.       /ColourName (YELLOW) def
  68.       YELLOW setupcolor  
  69.       /WhichColour 1 def } if 
  70.    seppages 4 eq { 
  71.       /ColourName (BLACK) def 
  72.       BLACK setupcolor   
  73.       /WhichColour 0 def } if 
  74. %
  75. % crop marks
  76. %
  77. gsave .3 setlinewidth 
  78. 3 -7 moveto
  79. /Helvetica findfont 6 scalefont setfont
  80. ColourName show
  81. 0 0 CM 
  82. vsize cX 2 mul sub dup hsize cX 2 mul sub dup isls{4 2 roll}if 0 CM 
  83. exch CM 0 
  84. exch CM 
  85. grestore 0 cX -2 mul TR isls
  86. {cX -2 mul 0 TR}if
  87.       } def end
  88. /separations 48 dict def
  89. separations begin
  90.    /cmykprocs [ %def
  91.        % cyan
  92.     { pop pop  pop SetGray  }
  93.        % magenta
  94.     { pop pop exch pop SetGray  }
  95.        % yellow
  96.     { pop 3 1 roll pop pop SetGray  }
  97.        % black
  98.     { 4 1 roll pop pop pop SetGray  }
  99.    ] def
  100.    /rgbprocs [ %def
  101.        % cyan
  102.     { ToCMYK pop pop pop SetGray }
  103.        % magenta
  104.     { ToCMYK pop pop exch pop SetGray }
  105.        % yellow
  106.     { ToCMYK pop 3 1 roll pop pop SetGray }
  107.        % black
  108.     { ToCMYK 4 1 roll pop pop pop SetGray  }
  109.    ] def
  110.    /testprocs [ %def
  111.        % cyan
  112.     { ToCMYK pop pop pop  }
  113.        % magenta
  114.     { ToCMYK pop pop exch pop  }
  115.        % yellow
  116.     { ToCMYK pop 3 1 roll pop pop  }
  117.        % black
  118.     { ToCMYK 4 1 roll pop pop pop   }
  119.    ] def
  120.    /screenangles [ %def
  121.        105  % cyan
  122.        75    % magenta
  123.        0      % yellow
  124.        45    % black
  125.    ] def
  126. end  % separations
  127.  
  128. % setupcolortakes 0, 1, 2, or 3 as its argument,
  129. % for cyan, magenta, yellow, and black.
  130. /CYAN 0 def           /MAGENTA 1 def
  131. /YELLOW 2 def         /BLACK 3 def
  132. /setupcolor{ %def
  133.    userdict begin
  134.        dup separations /cmykprocs get exch get
  135.        /setcmykcolor exch def
  136.        dup separations /rgbprocs get exch get
  137.        /setrgbcolor exch def
  138.        dup separations /testprocs get exch get
  139.        /testrgbcolor exch def
  140.        separations /screenangles get exch get
  141.        currentscreen
  142.            exch pop 3 -1 roll exch
  143.        setscreen
  144.        /setscreen { pop pop pop } def
  145. %
  146. % redefine setgray so that it only shows on the black separation
  147. %
  148.       /setgray {
  149.        WhichColour 0 eq
  150.        {systemdict begin adjustdot setgray end} 
  151.        {pop systemdict begin 1 setgray end}
  152.        ifelse}def 
  153.    end
  154. } bind def
  155.  
  156. %
  157. % from Kunkel
  158. %
  159. /adjustdot { dup 0 eq { } { dup 1 exch sub .1 mul add} ifelse } def
  160. %
  161. % redefine existing operators
  162. %
  163. % Percent of undercolor removal
  164. /magentaUCR .3 def  
  165. /yellowUCR .07 def  
  166. /blackUCR .4 def 
  167. %
  168. % Correct yellow and magenta
  169. /correctMY {rgb2cym
  170.   1 index yellowUCR mul sub 3 1 roll
  171.   1 index magentaUCR mul sub 3 1 roll
  172.   3 1 roll rgb2cym}def
  173. %(bluely green ) =
  174. %CYAN setupcolor
  175. %.1 .4 .5  testrgbcolor =
  176. %MAGENTA setupcolor
  177. %.1 .4 .5  testrgbcolor =
  178. %YELLOW setupcolor
  179. %.1 .4 .5  testrgbcolor =
  180. %BLACK setupcolor
  181. %.1 .4 .5  testrgbcolor =
  182. %quit
  183.