1 % Copyright (C) 1995, 1996 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_l2img.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17 % Emulate the Level 2 dictionary-based image operator in Level 1,
18 % except for Interpolate (ignored) and MultipleDataSources = true;
19 % also, we require that the data source be either a procedure of a
20 % particular form or a stream, not a string or a general procedure.
22 % pdf2ps copies the portion of this file from %BEGIN to %END if Level 1
23 % compatible output is requested.
26 { pop currentglobal { setglobal } true setglobal }
32 { /packedarray { array astore readonly } bind def }
37 11 dict /.csncompdict 1 index def begin
38 /DeviceGray { 1 /setgray load } bind def
39 /DeviceRGB { 3 /setrgbcolor load } bind def
40 /DeviceCMYK { 4 /setcmykcolor load } bind def
42 { dup 1 index 1 get //.csncompdict exch get exec
43 % Stack: [/Indexed base hival map] ncomp basesetcolor
44 3 -1 roll 3 get mark 3 1 roll
45 % Stack: ncomp -mark- basesetcolor map
46 dup type /stringtype eq
48 { exch round cvi get 255 div
51 { exch round cvi 3 mul 2 copy 2 copy get 255 div
52 3 1 roll 1 add get 255 div
53 4 2 roll 2 add get 255 div
55 { exch round cvi 4 mul 2 copy 2 copy 2 copy get 255 div
56 3 1 roll 1 add get 255 div
57 4 2 roll 2 add get 255 div
58 5 3 roll 3 add get 255 div
61 4 index get aload pop counttomark -1 roll
63 { /exec load 3 -1 roll
64 % Stack: -mark- mapproc --exec-- basesetcolor
66 ifelse .packtomark cvx
70 { dup 2 index //.csncompdict exch get exec
71 % Stack: [/Separation name alt xform] ncomp altsetcolor
72 3 -1 roll 3 get /exec load 3 -1 roll 3 array astore readonly cvx
75 % Substitute device spaces for CIE spaces.
76 /CIEBasedA /DeviceGray load def
77 /CIEBasedABC /DeviceRGB load def
78 /CIEBasedDEF /DeviceRGB load def
79 /CIEBasedDEFG /DeviceCMYK load def
82 /.packtomark { counttomark packedarray exch pop } bind def
84 /.csinextbits % - .csinextbits <bits>
85 % Uses b, nnb, i, row, mask, BitsPerComponent;
87 { /nnb nnb BitsPerComponent add
88 { dup 0 le { exit } if
89 /b b 8 bitshift row i get add def
93 b nnb bitshift mask and
96 % Note that the ColorSpace key must be present in the image dictionary.
97 /.colorspaceimage % <imagedict> .colorspaceimage -
99 dup length 15 add dict begin { cvlit def } forall
100 ColorSpace dup dup type /nametype ne { 0 get } if
101 .csncompdict exch get exec
102 /setpixelcolor exch def /ncomp exch def pop
103 /row ncomp BitsPerComponent mul Width mul 7 add 8 idiv string def
104 /mask 1 BitsPerComponent bitshift 1 sub def
105 /nextbits BitsPerComponent 8 eq
106 { { row i get /i i 1 add def } }
107 { /.csinextbits load }
109 /nextpixel mark 0 2 ncomp 1 sub 2 mul
111 Decode exch 2 getinterval
112 dup aload pop exch sub
113 dup mask eq { pop } { mask div /mul load 3 -1 roll } ifelse
114 0 get dup 0 eq { pop } { /sub load 3 -1 roll } ifelse
117 /setpixelcolor load dup type /operatortype ne { /exec load } if
120 /DataSource load dup type
121 dup /arraytype eq exch /packedarraytype eq or
122 { % Must be { <file> <string> ... }
123 aload length 1 add array /pop load exch astore
127 % Adobe requires readstring to signal an error if given
128 % an empty string. Work around this nonsense here.
131 { { DataSource row readstring pop pop } }
135 ImageMatrix matrix invertmatrix concat
138 { imat 5 3 -1 roll neg put
140 /b 0 def /nnb 0 def /i 0 def
142 { imat 4 3 -1 roll neg put nextpixel
143 1 1 true imat {<80>} imagemask
153 currentfile closefile
156 /.cincompdict 3 dict begin
157 1 { {0 1} {/DeviceGray} } def
158 3 { {0 1 0 1 0 1} {/DeviceRGB} } def
159 4 { {0 1 0 1 0 1 0 1} {/DeviceCMYK} } def
162 /Decode /DataSource /ImageMatrix /BitsPerComponent /Height /Width
164 /colorimage % <width> <height> <bits/comp> <matrix>
165 % <datasrc> false <ncomp> colorimage -
166 { 1 index { /colorimage load /rangecheck signalerror } if exch pop
167 //.cincompdict exch get exec
168 7 dict begin /ColorSpace exch cvlit def
169 .imagekeys { exch cvlit def } forall
170 currentdict end .colorspaceimage
173 { dup type /dicttype ne
174 { 7 dict begin /ColorSpace /DeviceGray def [0 1]
175 .imagekeys { exch cvlit def } forall
178 { dup length 1 add dict .copydict dup /ColorSpace currentcolorspace put