gs_devcs.ps 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. % Copyright (C) 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_devcs.ps,v 1.7 2005/09/12 11:34:50 leonardo Exp $
  16. % Device-specific color space method dictionaries.
  17. %
  18. % This file implements the method dictionaries for the Device-specific
  19. % color spaces. See gs_cspace.ps for information.
  20. %
  21. % Note that, because these color spaces are parameter-less, no color
  22. % space validation is required: if we can get to the color space methods,
  23. % we know the color space is legitimate.
  24. %
  25. % The colorspace substitution routines for these color spaces
  26. % (cs_substitute) will fail in a Level 1 system, but this is not a
  27. % problem as .getuseciecolor will always return false for such systems.
  28. %
  29. .currentglobal true .setglobal
  30. .cspace_util begin
  31. %
  32. % <r> <g> <b> rgb_2_gray <gray>
  33. %
  34. % Convert RGB colors to gray. This includes a special check for
  35. % r == g == b, and avoids roundoff error if this is the case.
  36. %
  37. /rgb_2_gray
  38. {
  39. 3 copy 1 index eq 3 1 roll eq and
  40. { pop pop }
  41. { .11 mul exch .59 mul add exch .3 mul add }
  42. ifelse
  43. }
  44. bind def
  45. systemdict /..page_default_spaces 3 dict put
  46. % <color_space_name> ..includecolorspace -
  47. /..includecolorspace
  48. { % Only includes ones explicitly defined by the document.
  49. systemdict /..page_default_spaces get 1 index known {
  50. pop
  51. } {
  52. mark exch
  53. { dup /ColorSpace resourcestatus {
  54. pop 0 eq {
  55. systemdict /..page_default_spaces get 1 index //true put
  56. gsave
  57. { dup /ColorSpace findresource //_setcolorspace_nosub exec .includecolorspace
  58. } stopped pop
  59. grestore
  60. } if
  61. } if
  62. } stopped pop
  63. cleartomark
  64. } ifelse
  65. } bind def
  66. % <color_space> <color_space_name> cs_substitute_generic <color_space1> <color_space2>
  67. /cs_substitute_generic
  68. { .getuseciecolor
  69. { NOSUBSTDEVICECOLORS
  70. { //..includecolorspace exec dup }
  71. { /ColorSpace findresource }
  72. ifelse
  73. }
  74. { pop dup }
  75. ifelse
  76. }
  77. bind def
  78. % <color_space> <color_space_name> cs_substitute_DeviceRGB_for_PDFX <color_space1> <color_space2>
  79. /cs_substitute_DeviceRGB_for_PDFX
  80. { systemdict /PDFX .knownget not { false } if {
  81. dup /ColorSpace resourcestatus {
  82. pop pop
  83. } {
  84. (Error: Need a /DefaultRGB /ColorSpace resource for generating a PDF/X document.) =
  85. /cs_substitute_DeviceRGB_for_PDFX /undefined signalerror
  86. } ifelse
  87. /ColorSpace findresource
  88. } {
  89. //cs_substitute_generic exec
  90. } ifelse
  91. } bind def
  92. colorspacedict
  93. dup
  94. /DeviceGray
  95. mark
  96. /cs_potential_indexed_base true
  97. /cs_potential_pattern_base true
  98. /cs_potential_alternate true
  99. /cs_potential_icc_alternate true
  100. /cs_get_ncomps //ncomps_1
  101. /cs_get_range //get_range_1
  102. /cs_get_default_color { pop 0 } bind
  103. /cs_get_currentgray //pop_1
  104. /cs_get_currentrgb { pop dup dup } bind
  105. /cs_get_currentcmyk { pop 1 exch sub 0 0 0 4 -1 roll } bind
  106. /cs_validate {}
  107. /cs_substitute
  108. { /DefaultGray //cs_substitute_generic exec
  109. }
  110. bind
  111. /cs_prepare {}
  112. /cs_install { pop 0 .setdevcspace } bind
  113. /cs_prepare_color //validate_1
  114. /cs_complete_setcolor //pop_1
  115. .dicttomark
  116. put
  117. /DeviceRGB
  118. mark
  119. /cs_potential_indexed_base true
  120. /cs_potential_pattern_base true
  121. /cs_potential_alternate true
  122. /cs_potential_icc_alternate true
  123. /cs_get_ncomps //ncomps_3
  124. /cs_get_range //get_range_3
  125. /cs_get_default_color { pop 0 0 0 } bind
  126. /cs_get_currentgray { pop //rgb_2_gray exec } bind
  127. /cs_get_currentrgb //pop_1
  128. % to convert to cmyk use blackgeneration and undercolorremoval
  129. /cs_get_currentcmyk
  130. {
  131. pop
  132. % convert to subtractive (CMY) color space
  133. 3
  134. { 1 exch sub 3 1 roll }
  135. repeat
  136. % find the minimum (initial k component)
  137. 3 copy
  138. 2
  139. {
  140. 2 copy gt
  141. { exch }
  142. if
  143. pop
  144. }
  145. repeat
  146. % apply undercolorremoval
  147. dup 5 1 roll currentundercolorremoval exec 4 1 roll
  148. 3
  149. { 3 index sub //bound_0_1 exec 3 1 roll }
  150. repeat
  151. % apply blackgeneration
  152. 5 3 roll pop currentblackgeneration exec //bound_0_1 exec
  153. }
  154. bind
  155. /cs_validate {}
  156. /cs_substitute
  157. { /DefaultRGB //cs_substitute_DeviceRGB_for_PDFX exec
  158. }
  159. bind
  160. /cs_prepare {}
  161. /cs_install { pop 1 .setdevcspace } bind
  162. /cs_prepare_color //validate_3
  163. /cs_complete_setcolor //pop_1
  164. .dicttomark
  165. put
  166. end % .cspace_util
  167. .setglobal
  168. % Only create the DeviceCMYK color space if setcolorscreen is present
  169. /setcolorscreen where
  170. { pop }
  171. { currentfile closefile }
  172. ifelse
  173. .currentglobal true .setglobal
  174. .cspace_util begin
  175. colorspacedict
  176. /DeviceCMYK
  177. mark
  178. /cs_potential_indexed_base true
  179. /cs_potential_pattern_base true
  180. /cs_potential_alternate true
  181. /cs_potential_icc_alternate true
  182. /cs_get_ncomps //ncomps_4
  183. /cs_get_range //get_range_4
  184. /cs_get_default_color { pop 0 0 0 1 } bind
  185. /cs_get_currentgray
  186. { pop 4 1 roll //rgb_2_gray exec add 1 exch sub //bound_0_1 exec }
  187. bind
  188. /cs_get_currentrgb
  189. {
  190. pop
  191. 4 1 roll 3
  192. { 3 index add 1 exch sub //bound_0_1 exec 3 1 roll }
  193. repeat
  194. 4 -1 roll pop
  195. }
  196. bind
  197. /cs_get_currentcmyk //pop_1
  198. /cs_validate {}
  199. /cs_substitute
  200. { /DefaultCMYK //cs_substitute_generic exec
  201. }
  202. bind
  203. /cs_prepare {}
  204. /cs_install { pop 2 .setdevcspace } bind
  205. /cs_prepare_color //validate_4
  206. /cs_complete_setcolor //pop_1
  207. .dicttomark
  208. put
  209. currentdict /..includecolorspace .undef
  210. currentdict /cs_substitute_generic .undef
  211. end % .cspace_util
  212. .setglobal