gs_indxd.ps 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. % Copyright (C) 2001, 2002 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: gs_indxd.ps,v 1.2 2002/11/13 20:23:10 alexcher Exp $
  16. % Indexed color space method dictionary
  17. % verify that Indexed color spaces are supported
  18. /.setindexedspace where
  19. { pop }
  20. { currentfile closefile }
  21. ifelse
  22. .currentglobal true .setglobal
  23. .cspace_util begin
  24. %
  25. % <num> <array> restrict_index <int> <array>
  26. %
  27. % Restrict the operand to setcolor for an Indexed color space to be an
  28. % integer in the applicable range.
  29. %
  30. /restrict_index
  31. {
  32. exch round cvi
  33. dup 0 lt
  34. { pop 0 }
  35. {
  36. 1 index 2 get 2 copy gt
  37. { exch }
  38. if
  39. pop
  40. }
  41. ifelse
  42. exch
  43. }
  44. bind def
  45. %
  46. % <num> <array> get_indexed_base_color <c1> ... <cn> <array>
  47. %
  48. % Get the base color corresponding to an indexed color value.
  49. %
  50. /get_indexed_base_color
  51. {
  52. % just in case, set the index into the appropriate range
  53. //restrict_index exec
  54. % lookup in the string or use the lookup proc
  55. mark 1 index 3 get dup type /stringtype eq
  56. {
  57. 2 index 1 get //.cs_get_ncomps exec dup 6 -1 roll mul exch getinterval
  58. { 255 div }
  59. forall
  60. }
  61. { 4 -1 roll exch exec }
  62. ifelse
  63. counttomark 2 add -2 roll pop
  64. }
  65. bind def
  66. colorspacedict
  67. /Indexed
  68. mark
  69. /cs_potential_indexed_base false
  70. /cs_potential_pattern_base true
  71. /cs_potential_alternate false
  72. /cs_potential_icc_alternate false
  73. /cs_get_ncomps //ncomps_1
  74. /cs_get_range { 0 exch 2 get 2 array astore } bind
  75. /cs_get_default_color { pop 0 } bind
  76. /cs_get_currentgray
  77. { //get_indexed_base_color exec 1 get //.cs_get_currentgray exec }
  78. bind
  79. /cs_get_currentrgb
  80. { //get_indexed_base_color exec 1 get //.cs_get_currentrgb exec }
  81. bind
  82. /cs_get_currentcmyk
  83. { //get_indexed_base_color exec 1 get //.cs_get_currentcmyk exec }
  84. bind
  85. % a lot of validation is done by the cs_validate method
  86. /cs_validate
  87. {
  88. //check_array exec
  89. dup 1 get //.cs_validate exec //.cs_potential_indexed_base exec not
  90. //setcspace_rangecheck
  91. if
  92. dup 2 get dup type /integertype ne
  93. //setcspace_typecheck
  94. {
  95. dup 0 lt exch 4095 gt or
  96. //setcspace_rangecheck
  97. if
  98. }
  99. ifelse
  100. dup 3 get dup type /stringtype eq
  101. {
  102. length
  103. 1 index dup 2 get 1 add exch 1 get //.cs_get_ncomps exec mul
  104. lt
  105. //setcspace_rangecheck
  106. if
  107. }
  108. {
  109. //check_array exec xcheck not
  110. //setcspace_typecheck
  111. if
  112. }
  113. ifelse
  114. }
  115. bind
  116. % substitute the base space if appropriate
  117. /cs_substitute
  118. {
  119. dup 1 get //.cs_substitute exec 2 copy eq
  120. { pop pop dup }
  121. {
  122. % retain only the new base space
  123. exch pop
  124. % build all new structures in local VM
  125. .currentglobal 3 1 roll //false .setglobal
  126. % construct a new array and insert the new base color space
  127. 1 index dup length array copy dup 1 4 -1 roll put
  128. % restore VM mode
  129. 3 -1 roll .setglobal
  130. }
  131. ifelse
  132. }
  133. bind
  134. /cs_prepare {}
  135. %
  136. % Install the current color space. Note that the alternative color
  137. % space will already have been set as the current color space.
  138. %
  139. % The current Ghostscript color space implementation requires that
  140. % color spaces that provide a base or alternative color space set
  141. % that base/alternative color space to be the current color space
  142. % before attempting to set the original color space.
  143. %
  144. /cs_install
  145. {
  146. % save the current color space
  147. currentcolorspace
  148. % set the base color space as the current color space
  149. 1 index 1 get //forcesetcolorspace
  150. % set the indexed color space; restore the earlier space on error
  151. mark 2 index
  152. { .setindexedspace }
  153. stopped
  154. { cleartomark setcolorspace stop }
  155. { pop pop pop }
  156. ifelse
  157. }
  158. bind
  159. /cs_prepare_color //validate_1
  160. %
  161. % Adobe implementations always execute a lookup procedure when setcolor
  162. % is invoked. Ghostscript samples the lookup procedure when
  163. % setcolorspace is invoked, and then does not access it again. In the
  164. % unlikely event that an application depends on the Adobe-specific
  165. % behavior, it is replicated in this method.
  166. %
  167. /cs_complete_setcolor
  168. {
  169. 3 get dup type /stringtype eq
  170. { pop }
  171. {
  172. currentcolor exch exec
  173. currentcolorspace 1 get //clear_setcolor_operands exec
  174. }
  175. ifelse
  176. }
  177. bind
  178. .dicttomark
  179. put
  180. end % .cspace_util
  181. .setglobal