1
0

docie.ps 7.0 KB

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