1 % Copyright (C) 2001, 2002 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
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.
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.
16 % $Id: gs_sepr.ps,v 1.3 2003/04/26 18:40:16 dan Exp $
17 % Separation color space method dictionary
20 % verify that Separation color spaces are supported
21 /.setseparationspace where
23 { currentfile closefile }
26 .currentglobal true .setglobal
31 % <c1> <array> apply_sepr_tint_xform <c1>' ... <cn>' <array>
33 % Apply the tint transform for a Separation color space color intensity
36 /apply_sepr_tint_xform
39 mark exch 2 index 3 get exec
40 counttomark 2 add -2 roll pop
46 % <cspace_array> build_tintxform_function <cspace_array> <proc>
48 % Convert a tint transformation into a function, if possible. If this is
49 % successful, <proc> will be a function procedure (a two-element,
50 % execute-only, executable array whose first element is the function
51 % data structure and whose second element is the operator %execfunction.
52 % If it is not successful, <proc> will be the same as the tint transform
55 % Note that, for PDF files, the tint transform will likely already be a
56 % function-array. In this case, <proc> will be this array, and thus will
57 % also be identical to the original tint transform.
59 % This procedure is used for both Separation and DeviceN color spaces.
61 /build_tintxform_function
63 dup 3 get dup .isencapfunction not
65 % Try a FunctionType 4 function first; build the function dictionary
67 .currentglobal exch //false .setglobal
68 % Make the dictionary a couple of elements large in case this fails
69 % and we need the dictionary to build a sampled function.
73 /Domain 2 index //.cs_get_range exec def
74 /Range 2 index 2 get //.cs_get_range exec def
77 .internalstopped % If .buildfunction fails then not type 4 func.
78 { % If not then try building a sampled (type 0) func.
79 % We are using the dictionary which was created before .buildfunction
81 dup /BitsPerSample 16 put
82 { .buildsampledfunction }
83 .internalstopped % If .buildsamplefunction fails then invalid func.
84 { % Failed - Create a dummy tint transform function
85 % We are using the dictionary which was created before .buildfunction
86 dup /Function {} put % Replace invalid tint transform with dummy
89 if % Check status from .buildsamplefunction/.internalstopped
91 if % check status from .buildfunction/.intermalstopped
100 % <array1> <array2> converttinttransform <array1> <array2'>
102 % Convert a Separation/DeviceN color space to use a function as a tint
103 % transformation, if this is possible. Possible outcomes are:
105 % 1. The tint transform already is a function, or is a procedure that
106 % cannot be converted to a function. In either case, <array2> is
107 % left unchanged (<array2> == <array2'>).
109 % 2. The tint transform is not already a function but can be converted
110 % to a function, and <array1> != <array2>. In this case, <array2>
111 % is modified directly.
113 % 3. The tint transform is not already a function but can be converted
114 % to a function, and <array1> == <array2>. In this case, <array2>
115 % is copied, and the copy is modified (i.e., after the operation
116 % <array1> != <array2>
118 % This slightly complex approach avoids creating an extra color space
119 % array unnecessarily.
121 /converttinttransform
123 % convert the tint transform to a fucntion
124 //build_tintxform_function exec
126 % see if anything needs to be modified
127 1 index 3 get 2 copy eq
132 % see if the color space must be copied
135 % copy the array into local VM
136 .currentglobal //false .setglobal
137 3 -1 roll dup length array copy 3 1 roll
141 1 index exch 3 exch put
151 /cs_potential_indexed_base true
152 /cs_potential_pattern_base true
153 /cs_potential_alternate false
154 /cs_potential_icc_alternate false
155 /cs_get_ncomps //ncomps_1
156 /cs_get_range //get_range_1
157 /cs_get_default_color { pop 1 } bind
160 { //apply_sepr_tint_xform exec 2 get //.cs_get_currentgray exec }
163 { //apply_sepr_tint_xform exec 2 get //.cs_get_currentrgb exec }
166 { //apply_sepr_tint_xform exec 2 get //.cs_get_currentcmyk exec }
169 % a lot of validation is done by the cs_validate method
173 dup 1 get type dup /nametype ne exch /stringtype ne and
174 //setcspace_typecheck
176 dup 2 get //.cs_validate exec //.cs_potential_alternate exec not
177 //setcspace_rangecheck
179 dup 3 get //check_array exec xcheck not
180 //setcspace_typecheck
185 % substitute the base space if appropriate
188 dup 2 get //.cs_substitute exec 2 copy eq
191 % retain only the new alternate space
194 % build all new structures in local VM
195 .currentglobal 3 1 roll //false .setglobal
197 % construct a new array and insert the new base color space
198 1 index dup length array copy dup 2 4 -1 roll put
208 % The Ghostscript interpreter works better when tinttransform procedures
209 % are translated into functions. Attempt to do that here.
211 /cs_prepare //converttinttransform
214 % Install the current color space.
216 % The current Ghostscript color space implementation requires that
217 % color spaces that provide a base or alternative color space set
218 % that base/alternative color space to be the current color space
219 % before attempting to set the original color space.
223 % save the current color space
226 % set the base color space as the current color space
227 1 index 2 get //forcesetcolorspace
229 % set the indexed color space; restore the earlier space on error
231 { .setseparationspace }
233 { cleartomark setcolorspace stop }
239 /cs_prepare_color //validate_1
242 % If a Separation color space is not supported in native mode by
243 % the current process color model, Adobe implementations will always
244 % execute the tint transform procedure when setcolor is invoked.
245 % Ghostscript may have turned this transform into a sampled function,
246 % and even if this is not the case, will have sampled the transform
247 % when the color space is first set. Some applications may depend
248 % on the Adobe behavior, so we implement it via the
249 % cs_complete_setcolor method.
251 /cs_complete_setcolor
255 currentcolor exch 3 get exec
256 currentcolorspace 2 get //clear_setcolor_operands exec