Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

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