Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 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
 
16
% $Id: gs_indxd.ps,v 1.2 2002/11/13 20:23:10 alexcher Exp $
17
% Indexed color space method dictionary
18
 
19
 
20
% verify that Indexed color spaces are supported
21
/.setindexedspace where
22
  { pop }
23
  { currentfile closefile }
24
ifelse
25
 
26
.currentglobal true .setglobal
27
.cspace_util begin
28
 
29
%
30
%   <num>  <array>   restrict_index   <int>  <array>
31
%
32
% Restrict the operand to setcolor for an Indexed color space to be an
33
% integer in the applicable range.
34
%
35
/restrict_index
36
  {
37
    exch round cvi
38
    dup 0 lt
39
      { pop 0 }
40
      {
41
        1 index 2 get 2 copy gt
42
          { exch }
43
        if
44
        pop
45
      } 
46
    ifelse
47
    exch
48
  }
49
bind def
50
 
51
%
52
%   <num>  <array>   get_indexed_base_color   <c1> ... <cn>  <array>
53
%
54
% Get the base color corresponding to an indexed color value.
55
%
56
/get_indexed_base_color
57
  {
58
    % just in case, set the index into the appropriate range
59
    //restrict_index exec
60
 
61
    % lookup in the string or use the lookup proc
62
    mark 1 index 3 get dup type /stringtype eq
63
      {
64
        2 index 1 get //.cs_get_ncomps exec dup 6 -1 roll mul exch getinterval
65
          { 255 div }
66
        forall
67
      }
68
      { 4 -1 roll exch exec }
69
    ifelse
70
    counttomark 2 add -2 roll pop
71
  }
72
bind def
73
 
74
 
75
colorspacedict
76
/Indexed
77
  mark
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
85
 
86
    /cs_get_currentgray
87
      { //get_indexed_base_color exec 1 get //.cs_get_currentgray exec }
88
    bind
89
    /cs_get_currentrgb
90
      { //get_indexed_base_color exec 1 get //.cs_get_currentrgb exec }
91
    bind
92
    /cs_get_currentcmyk
93
      { //get_indexed_base_color exec 1 get //.cs_get_currentcmyk exec }
94
    bind
95
 
96
    % a lot of validation is done by the cs_validate method
97
    /cs_validate
98
      {
99
        //check_array exec
100
        dup 1 get //.cs_validate exec //.cs_potential_indexed_base exec not
101
          //setcspace_rangecheck
102
        if
103
        dup 2 get dup type /integertype ne
104
          //setcspace_typecheck
105
          {
106
            dup 0 lt exch 4095 gt or
107
              //setcspace_rangecheck
108
            if
109
          }
110
        ifelse
111
        dup 3 get dup type /stringtype eq
112
          {
113
            length
114
            1 index dup 2 get 1 add exch 1 get //.cs_get_ncomps exec mul
115
            lt
116
              //setcspace_rangecheck
117
            if
118
          }
119
          {
120
            //check_array exec xcheck not
121
              //setcspace_typecheck
122
            if
123
          }
124
        ifelse
125
      }
126
    bind
127
 
128
    % substitute the base space if appropriate
129
    /cs_substitute
130
      {
131
        dup 1 get //.cs_substitute exec 2 copy eq
132
          { pop pop dup }
133
          {
134
            % retain only the new base space
135
            exch pop
136
 
137
            % build all new structures in local VM
138
            .currentglobal 3 1 roll //false .setglobal
139
 
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
142
 
143
            % restore VM mode
144
            3 -1 roll .setglobal
145
          }
146
        ifelse
147
      }
148
    bind
149
 
150
    /cs_prepare {}
151
 
152
    %
153
    % Install the current color space. Note that the alternative color
154
    % space will already have been set as the current color space.
155
    %
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.
160
    %
161
    /cs_install
162
      {
163
        % save the current color space
164
        currentcolorspace
165
 
166
        % set the base color space as the current color space
167
        1 index 1 get //forcesetcolorspace
168
 
169
        % set the indexed color space; restore the earlier space on error
170
        mark 2 index
171
          { .setindexedspace }
172
        stopped
173
          { cleartomark setcolorspace stop }
174
          { pop pop pop }
175
        ifelse
176
      }
177
    bind
178
 
179
    /cs_prepare_color //validate_1
180
 
181
    %
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.
187
    %
188
    /cs_complete_setcolor
189
      {
190
        3 get dup type /stringtype eq
191
          { pop }
192
          {
193
            currentcolor exch exec
194
            currentcolorspace 1 get //clear_setcolor_operands exec
195
          }
196
        ifelse
197
      }
198
    bind
199
 
200
  .dicttomark
201
put
202
 
203
end     % .cspace_util
204
.setglobal