summaryrefslogtreecommitdiff
path: root/Master/xemtex/gslib/gs_icc.ps
blob: 323462342f1dafccb042cfd95e33616c1b32a816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
%    Copyright (C) 2001 Aladdin Enterprises.  All rights reserved.
% 
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
% Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 59 Temple Place, Suite 330, Boston, MA, 02111-1307.

% $Id: gs_icc.ps,v 1.2.2.1.2.1 2003/04/12 14:02:38 giles Exp $
% PostScript portion of ICCBased color space support

//userdict /.icc_comp_map_dict
  << 1 /DeviceGray  3 /DeviceRGB  4 /DeviceCMYK >>
put

colorspacedict /ICCBased
  {
    % Verify that the source object is an array, that it is at least of length
    % two, and that the second entry is a readable dictionary. If we got this
    % far, we know the top-level object exists and is readable, but it might
    % be a dictionary.
    dup type dup /arraytype ne exch /packedarraytype ne and
      { /setcolorspace /typecheck signalerror }
    if
    dup length 2 lt
      { /setcolorspace /rangecheck signalerror }
    if
    dup 1 get type /dicttype ne
      { /setcolorspace /typecheck signalerror }
    if
    dup 1 get rcheck not
      { /setcolorspace /invalidaccess signalerror }
    if

    % Verify that the dictionary defines the key N (number of components) and
    %  entry is provided and has a legitimate value
    dup 1 get /N .knownget
      {
        //.icc_comp_map_dict exch known not
          { 
            % generate the appropriate error
            /setcolorspace 
            1 index 1 get /N type type /integertype ne
              { /typecheck }
              { /rangecheck }
            ifelse
            signalerror
          }
        if
      }
      { /setcolorspace /undefined signalerror }
    ifelse

    % Verify DataSrouce and, if it is a string, convert it to a file
    dup 1 get /DataSource .knownget
      {
        dup rcheck not
          { pop /setcolorspace /invalidaccess signalerror }
        if
        type dup /stringtype eq
          {
            pop
            2 array copy
            dup 1
             2 copy get dup length dict copy
             dup /DataSource
              2 copy get /ReusableStreamDecode filter
             put
            put
          }
          {
            /filetype ne
              { /setcolorspace /typecheck signalerror }
            if
          }
        ifelse
      }
      { /setcolorspace /undefined signalerror }
    ifelse

    % set the alternate color space to be the current color space
    dup 1 get /Alternate .knownget not
      { dup 1 get /N get //.icc_comp_map_dict exch get }
    if
    setcolorspace

    % if CIE spaces are not use, just take the alternate space
    NOCIE
      { pop //null }
      { % check for native support
        /.seticcspace where
          { pop dup 1 get
	    % Acrobat Reader silently ignores errors with ICC profiles
	    % and uses the alternate color space -- do the same.
	    mark exch { .seticcspace } stopped
	      { cleartomark pop //null }
	      { pop }
	    ifelse
	  }
          { pop //null }
        ifelse
      }
    ifelse
  }
bind put

//userdict /.icc_comp_map_dict undef