home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 February / INTERNET88.ISO / pc / software / windows / bits / pdf995 / data1.cab / Program_Executable_Files / res / docie.ps < prev    next >
Encoding:
Text File  |  2001-12-08  |  7.3 KB  |  222 lines

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