1 % Copyright (C) 1989, 1992, 1993, 1998 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: viewgif.ps,v 1.5 2003/04/12 18:08:18 ray Exp $
20 /read1 % <file> read1 <int>
23 /read2 % <file> read2 <int>
24 { dup read1 exch read1 8 bitshift add
27 /readGIFheader % <file> readGIFheader <dict>
29 dup 6 string readstring pop
30 dup (GIF87a) eq exch (GIF89a) eq or not
31 { (Not a GIF file.\n) print cleartomark stop
33 dup read2 /Width exch def
34 dup read2 /Height exch def
36 dup 128 ge /GlobalColor exch def
37 dup -4 bitshift 7 and 1 add /BitsPerPixel exch def %***BOGUS?***
38 dup 8 and 0 ne /PaletteSorted exch def
39 7 and 1 add dup /BitsPerPixel exch def
40 1 exch bitshift /PaletteSize exch def
41 dup read1 /BackgroundIndex exch def
42 dup read1 15 add 64 div /AspectRatio exch def
44 { PaletteSize 3 mul string readstring pop
45 /GlobalPalette exch def
50 /readGIFimageHeader % <file> readGIFimageHeader <dict>
51 % Note: GIF header must be on dict stack
54 dup (!) 0 get ne { exit } if pop % extension
56 { dup read1 dup 0 eq { pop exit } if { dup read1 pop } repeat
60 { (Not a GIF image.\n) print stop
62 dup read2 /Left exch def
63 dup read2 /Top exch def
64 dup read2 /Width exch def
65 dup read2 /Height exch def
67 dup 128 ge /LocalColor exch def
68 dup 64 and 0 ne /Interlaced exch def
70 { 7 and 1 add /BitsPerPixel exch def
71 1 BitsPerPixel bitshift 3 mul string readstring pop
74 { pop pop /Palette GlobalPalette def
80 /imageGIF % <imagedict> imageGIF
83 % We know BitsPerComponent = 8, Decode = [0 255].
84 % and there is only a single data source which is
85 % either a filter or a string whose size is exactly
86 % the width of the row.
87 dup /DataSource get dup type /stringtype eq
88 { ImageOut exch writestring
90 { pop dup /Width get string
92 { 1 index /DataSource get 1 index readstring pop
93 ImageOut exch writestring
104 /viewGIF % <file|string> viewGIF -
107 dup type /stringtype eq { (r) file } if
109 /ImageOutFile where { /ImageOut ImageOutFile (w) file def } if
110 F readGIFheader /Header exch def
111 currentdict Header end begin begin
112 VGIFDEBUG { Header { exch == == } forall (----------------\n) print flush } if
113 F readGIFimageHeader /ImageHeader exch def
114 currentdict ImageHeader end begin begin
115 VGIFDEBUG { ImageHeader { exch == == } forall (----------------\n) print flush } if
117 << /InitialCodeLength F read1
118 /FirstBitLowOrder true
121 >> /LZWDecode filter def
123 [/Indexed /DeviceRGB 1 BitsPerPixel bitshift 1 sub Palette] setcolorspace
125 0 1 3 { 2 copy get dup 0 ne { dup abs div } if 3 copy put pop pop } for
128 /ImageMatrix [1 0 0 -1 0 Height]
132 { /Width Width /Height 1
133 /row Width string def
136 /inter % <num> <denom> inter -
137 { /denom exch def /num exch def
139 /lines Height denom 1 sub add num sub denom idiv def
141 Height exch denom mul num add sub
142 I /ImageMatrix get 5 3 -1 roll put
143 D row readstring pop pop
154 { /Width Width /Height Height
159 saved end end end restore