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_indxd.ps,v 1.2 2002/11/13 20:23:10 alexcher Exp $
17 % Indexed color space method dictionary
20 % verify that Indexed color spaces are supported
21 /.setindexedspace where
23 { currentfile closefile }
26 .currentglobal true .setglobal
30 % <num> <array> restrict_index <int> <array>
32 % Restrict the operand to setcolor for an Indexed color space to be an
33 % integer in the applicable range.
41 1 index 2 get 2 copy gt
52 % <num> <array> get_indexed_base_color <c1> ... <cn> <array>
54 % Get the base color corresponding to an indexed color value.
56 /get_indexed_base_color
58 % just in case, set the index into the appropriate range
61 % lookup in the string or use the lookup proc
62 mark 1 index 3 get dup type /stringtype eq
64 2 index 1 get //.cs_get_ncomps exec dup 6 -1 roll mul exch getinterval
68 { 4 -1 roll exch exec }
70 counttomark 2 add -2 roll pop
78 /cs_potential_indexed_base false
79 /cs_potential_pattern_base true
80 /cs_potential_alternate false
81 /cs_potential_icc_alternate false
82 /cs_get_ncomps //ncomps_1
83 /cs_get_range { 0 exch 2 get 2 array astore } bind
84 /cs_get_default_color { pop 0 } bind
87 { //get_indexed_base_color exec 1 get //.cs_get_currentgray exec }
90 { //get_indexed_base_color exec 1 get //.cs_get_currentrgb exec }
93 { //get_indexed_base_color exec 1 get //.cs_get_currentcmyk exec }
96 % a lot of validation is done by the cs_validate method
100 dup 1 get //.cs_validate exec //.cs_potential_indexed_base exec not
101 //setcspace_rangecheck
103 dup 2 get dup type /integertype ne
104 //setcspace_typecheck
106 dup 0 lt exch 4095 gt or
107 //setcspace_rangecheck
111 dup 3 get dup type /stringtype eq
114 1 index dup 2 get 1 add exch 1 get //.cs_get_ncomps exec mul
116 //setcspace_rangecheck
120 //check_array exec xcheck not
121 //setcspace_typecheck
128 % substitute the base space if appropriate
131 dup 1 get //.cs_substitute exec 2 copy eq
134 % retain only the new base space
137 % build all new structures in local VM
138 .currentglobal 3 1 roll //false .setglobal
140 % construct a new array and insert the new base color space
141 1 index dup length array copy dup 1 4 -1 roll put
153 % Install the current color space. Note that the alternative color
154 % space will already have been set as the current color space.
156 % The current Ghostscript color space implementation requires that
157 % color spaces that provide a base or alternative color space set
158 % that base/alternative color space to be the current color space
159 % before attempting to set the original color space.
163 % save the current color space
166 % set the base color space as the current color space
167 1 index 1 get //forcesetcolorspace
169 % set the indexed color space; restore the earlier space on error
173 { cleartomark setcolorspace stop }
179 /cs_prepare_color //validate_1
182 % Adobe implementations always execute a lookup procedure when setcolor
183 % is invoked. Ghostscript samples the lookup procedure when
184 % setcolorspace is invoked, and then does not access it again. In the
185 % unlikely event that an application depends on the Adobe-specific
186 % behavior, it is replicated in this method.
188 /cs_complete_setcolor
190 3 get dup type /stringtype eq
193 currentcolor exch exec
194 currentcolorspace 1 get //clear_setcolor_operands exec