home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / docie.ps < prev    next >
Text File  |  2000-03-09  |  7KB  |  221 lines

  1. %    Copyright (C) 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % $Id: docie.ps,v 1.1 2000/03/09 08:40:39 lpd Exp $
  16. % docie.ps
  17. % Emulate CIE algorithms in PostScript.
  18.  
  19. % ---------------- Auxiliary procedures ---------------- %
  20.  
  21. /r1default [0 1] def
  22. /r3default [0 1 0 1 0 1] def
  23.  
  24. /apply3        % <u> <v> <w> [<pu> <pv> <pw>] apply3 <u'> <v'> <w'>
  25.  {  { 4 -1 roll exch exec } forall
  26.  } bind def
  27.  
  28. /restrict    % <u> <min> <max> restrict <u'>
  29.  { 3 1 roll .max .min
  30.  } bind def
  31.  
  32. /restrict3    % <u> <v> <w> [<minu> ... <maxw>] restrict3 <u'> <v'> <w'>
  33.  { aload pop
  34.    7 -1 roll 3 1 roll restrict 7 1 roll
  35.    5 -1 roll 3 1 roll restrict 5 1 roll
  36.    restrict 3 1 roll
  37.  } bind def
  38.  
  39. /rescale    % <u> <min> <max> rescale <u'>
  40.  { 1 index sub 3 1 roll sub exch div 0 .max 1 .min
  41.  } bind def
  42.  
  43. /rescale3    % <u> <v> <w> [<minu> ... <maxw>] rescale3 <u'> <v'> <w'>
  44.  { aload pop
  45.    7 -1 roll 3 1 roll rescale 7 1 roll
  46.    5 -1 roll 3 1 roll rescale 5 1 roll
  47.    rescale 3 1 roll
  48.  } bind def
  49.  
  50. /mmult3        % <u> <v> <w> [<uu> <uv> ... <wv> <ww>] mmult3
  51.         %   <u'> <v'> <w'>
  52.  { 4 -1 roll dup dup 6 -1 roll dup dup 8 -1 roll dup dup
  53.    10 -1 roll { 10 -1 roll mul } forall
  54.         % Stack: u1 v1 w1 u2 v2 w2 u3 v3 w3
  55.    4 -1 roll add 6 -1 roll add
  56.         % Stack: u1 v1 u2 v2 u3 v3 w'
  57.    7 1 roll 3 -1 roll add 4 -1 roll add
  58.         % Stack: w' u1 u2 u3 v'
  59.    5 1 roll add add 3 1 roll
  60.  } bind def
  61.  
  62. /minvert3    % [<uu> <uv> ... <wv> <ww>] minvert3
  63.         %   [<uu'> <uv'> ... <wv'> <ww'>]
  64.  { 16 dict begin
  65.    aload pop { I H G F E D C B A } { exch def } forall
  66.    /coa E I mul F H mul sub def
  67.    /cob F G mul D I mul sub def
  68.    /coc D H mul E G mul sub def
  69.    /det A coa mul B cob mul add C coc mul add def
  70.    [ coa det div
  71.      C H mul B I mul sub det div
  72.      B F mul C E mul sub det div
  73.      cob det div
  74.      A I mul C G mul sub det div
  75.      C D mul A F mul sub det div
  76.      coc det div
  77.      B G mul A H mul sub det div
  78.      A E mul B D mul sub det div
  79.    ]
  80.    end
  81.  } bind def
  82.  
  83. /print1
  84.  { print dup ==
  85.  } bind def
  86.  
  87. /print3
  88.  { print 3 array astore dup == aload pop
  89.  } bind def
  90.  
  91. % ---------------- Mapping to XYZ ---------------- %
  92.  
  93. /csmap        % <csdict> <l> <m> <n> csmap <csdict> <x> <y> <z>
  94.  { 3 index /RangeLMN .knownget not { r3default } if restrict3
  95. DEBUG { (After RangeLMN Decode: ) print3 } if
  96.    3 index /DecodeLMN .knownget { apply3 } if
  97. DEBUG { (After DecodeLMN Decode: ) print3 } if
  98.    3 index /MatrixLMN .knownget { mmult3 } if
  99. DEBUG { (After MatrixLMN Decode: ) print3 } if
  100.  } bind def
  101.  
  102. /csciea        % <csdict> <a> csciea <csdict> <x> <y> <z>
  103.  { 1 index /RangeA .knownget not { r1default } if restrict
  104. DEBUG { (After RangeA Decode: ) print1 } if
  105.    1 index /DecodeA .knownget { exec } if
  106. DEBUG { (After DecodeA Decode: ) print1 } if
  107.    1 index /MatrixA .knownget
  108.     { { 1 index mul exch } forall pop }
  109.     { dup dup }
  110.    ifelse
  111. DEBUG { (After MatrixA Decode: ) print3 } if
  112.    csmap
  113.  } bind def
  114.  
  115. /cscieabc    % <csdict> <a> <b> <c> cscieabc <csdict> <x> <y> <z>
  116.  { 3 index /RangeABC .knownget not { r3default } if restrict3
  117. DEBUG { (After RangeABC Decode: ) print3 } if
  118.    3 index /DecodeABC .knownget { apply3 } if
  119. DEBUG { (After DecodeABC Decode: ) print3 } if
  120.    3 index /MatrixABC .knownget { mmult3 } if
  121. DEBUG { (After MatrixABC Decode: ) print3 } if
  122.    csmap
  123.  } bind def
  124.  
  125. % ---------------- Rendering from XYZ ---------------- %
  126.  
  127. /lookup3    % <rtable> <a[0..1]> <b[0..1]> <c[0..1]> lookup3
  128.         %   <rtable> <bytes>
  129.  { 3 -1 roll 3 index 0 get 1 sub mul
  130.    3 -1 roll 3 index 1 get 1 sub mul
  131.    3 -1 roll 3 index 2 get 1 sub mul
  132.         % Stack: rtable ia ib ic
  133. DEBUG { (RenderTable indices: ) print3 mark 5 1 roll } if
  134.    3 -1 roll round cvi 3 index 3 get exch get
  135.         % Stack: rtable ib ic string
  136.    3 -1 roll round cvi 3 index 2 get mul
  137.         % Stack: rtable ic string ib*nc
  138.    3 -1 roll round cvi add 2 index 4 get mul
  139.         % Stack: rtable string index
  140.    2 index 4 get getinterval
  141.         % Stack: rtable bytes
  142. DEBUG { (RenderTable values: ) print (<) print (%stdout) (w) file 1 index writehexstring (>) = } if
  143.  } bind def
  144.  
  145. /bpdefault [0 0 0] def
  146.  
  147. /crmap        % <csdict> <crdict> <x> <y> <z> crmap <v1> ...
  148.  {
  149. DEBUG { (CIE XYZ = ) print3 } if
  150.    3 index /MatrixPQR .knownget { mmult3 } if
  151. DEBUG { (After MatrixPQR: ) print3 } if
  152.    4 index /WhitePoint get
  153.    5 index /BlackPoint .knownget not { bpdefault } if
  154.    5 index /WhitePoint get
  155.    6 index /BlackPoint .knownget not { bpdefault } if
  156.    4
  157.      { 4 -1 roll aload pop
  158.             % Stack: csdict crdict x y z pt pt pt px py pz
  159.        3 copy 12 index /MatrixPQR .knownget { mmult3 } if 6 array astore
  160.      }
  161.    repeat
  162.             % Stack: csdict crdict x y z wps+ bps+ wpd+ bpd+
  163.    9 -1 roll pop        % get rid of csdict
  164.    7 4 roll
  165.    7 index /TransformPQR get
  166.     {            % Stack: crdict wps+ bps+ wpd+ bpd+ u v w proc
  167.       8 copy exch pop exch pop
  168.       exec exch pop 4 -1 roll pop
  169.     }
  170.    forall
  171.    7 3 roll pop pop pop pop    % get rid of White/BlackPoints
  172. DEBUG { (After TransformPQR: ) print3 } if
  173.    3 index /MatrixPQR .knownget { minvert3 mmult3 } if
  174. DEBUG { (After MatrixPQR': ) print3 } if
  175.    3 index /MatrixLMN .knownget { mmult3 } if
  176. DEBUG { (After MatrixLMN Encode: ) print3 } if
  177.    3 index /EncodeLMN .knownget { apply3 } if
  178. DEBUG { (After EncodeLMN Encode: ) print3 } if
  179.    3 index /RangeLMN .knownget not { r3default } if restrict3
  180. DEBUG { (After RangeLMN Encode: ) print3 } if
  181.    3 index /MatrixABC .knownget { mmult3 } if
  182. DEBUG { (After MatrixABC Encode: ) print3 } if
  183.    3 index /EncodeABC .knownget { apply3 } if
  184. DEBUG { (After EncodeABC Encode: ) print3 } if
  185.    3 index /RangeABC .knownget not { r3default } if
  186.    5 -1 roll /RenderTable .knownget
  187.     {        % Stack: u v w ranges rtable
  188.       5 1 roll rescale3
  189. DEBUG { (Rescaled ABC: ) print3 } if
  190.         % Stack: rtable a b c
  191.       lookup3
  192.         % Stack: rtable bytes
  193.       0 1 3 index 4 get 1 sub
  194.        {    % Stack: values rtable bytes c
  195.      2 copy get 255 div
  196.         % Stack: values rtable bytes c v
  197.      3 index 3 -1 roll 5 add get exec 3 1 roll
  198.        }
  199.       for pop pop
  200. DEBUG { (After RenderTableT: ) print ] dup == aload pop } if
  201.     }
  202.     { restrict3
  203. DEBUG { (After RangeABC Encode: ) print3 } if
  204.     }
  205.    ifelse
  206.  } bind def
  207.  
  208. % ---------------- Top level control ---------------- %
  209.  
  210. /mapdict mark
  211.   /CIEBasedA { 1 get exch csciea currentcolorrendering 4 1 roll crmap } bind
  212.   /CIEBasedABC { 1 get 4 1 roll cscieabc currentcolorrendering 4 1 roll crmap } bind
  213. .dicttomark def
  214. /mapcie        % <a> mapcie <v1> ...
  215.         % <a> <b> <c> mapcie <v1> ...
  216.  { currentcolorspace dup 0 get //mapdict exch get exec
  217.  } bind def
  218.