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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
% Copyright (C) 1989, 1992, 1993 Aladdin Enterprises. All rights reserved.
%
% This file is part of GNU Ghostscript.
%
% GNU Ghostscript is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to
% anyone for the consequences of using it or for whether it serves any
% particular purpose or works at all, unless he says so in writing. Refer to
% the GNU General Public License for full details.
%
% Everyone is granted permission to copy, modify and redistribute GNU
% Ghostscript, but only under the conditions described in the GNU General
% Public License. A copy of this license is supposed to have been given to
% you along with GNU Ghostscript so you can know your rights and
% responsibilities. It should be in a file named COPYING. Among other
% things, the copyright notice and this notice must be preserved on all
% copies.
%
% Aladdin Enterprises is not affiliated with the Free Software Foundation or
% the GNU Project. GNU Ghostscript, as distributed by Aladdin Enterprises,
% does not depend on any other GNU software.
% viewgif.ps
% Display a GIF file.
/read1 % <file> read1 <int>
{ read pop
} bind def
/read2 % <file> read2 <int>
{ dup read1 exch read1 8 bitshift add
} bind def
/readGIFheader % <file> readGIFheader <dict>
{ 20 dict begin
dup 6 string readstring pop
dup (GIF87a) eq exch (GIF89a) eq or not
{ (Not a GIF file.\n) print cleartomark stop
} if
dup read2 /Width exch def
dup read2 /Height exch def
dup read1
dup 128 ge /GlobalColor exch def
dup -4 bitshift 7 and 1 add /BitsPerPixel exch def %***BOGUS?***
dup 8 and 0 ne /PaletteSorted exch def
7 and 1 add dup /BitsPerPixel exch def
1 exch bitshift /PaletteSize exch def
dup read1 /BackgroundIndex exch def
dup read1 15 add 64 div /AspectRatio exch def
GlobalColor
{ PaletteSize 3 mul string readstring pop
/GlobalPalette exch def
} if
currentdict end
} bind def
/readGIFimageHeader % <file> readGIFimageHeader <dict>
% Note: GIF header must be on dict stack
{ 10 dict begin
{ dup read1
dup (!) 0 get ne { exit } if pop % extension
dup read1 pop
{ dup read1 dup 0 eq { pop exit } if { dup read1 pop } repeat
} loop
} loop
(,) 0 get ne
{ (Not a GIF image.\n) print stop
} if
dup read2 /Left exch def
dup read2 /Top exch def
dup read2 /Width exch def
dup read2 /Height exch def
dup read1
dup 128 ge /LocalColor exch def
dup 64 and 0 ne /Interlaced exch def
LocalColor
{ 7 and 1 add /BitsPerPixel exch def
1 BitsPerPixel bitshift 3 mul string readstring pop
/Palette exch def
}
{ pop pop /Palette GlobalPalette def
}
ifelse
currentdict end
} bind def
/imageGIF % <imagedict> imageGIF
{ /ImageOut where
{ pop
% We know BitsPerComponent = 8, Decode = [0 255].
% and there is only a single data source which is
% either a filter or a string whose size is exactly
% the width of the row.
dup /DataSource get dup type /stringtype eq
{ ImageOut exch writestring
}
{ pop dup /Width get string
1 index /Height get
{ 1 index /DataSource get 1 index readstring pop
ImageOut exch writestring
}
repeat pop pop
}
ifelse
}
{ image
}
ifelse
} bind def
/viewGIF % <file|string> viewGIF -
{ save 20 dict begin
/saved exch def
dup type /stringtype eq { (r) file } if
/F exch def
/ImageOutFile where { /ImageOut ImageOutFile (w) file def } if
F readGIFheader /Header exch def
currentdict Header end begin begin
DEBUG { Header { exch == == } forall (----------------\n) print flush } if
F readGIFimageHeader /ImageHeader exch def
currentdict ImageHeader end begin begin
DEBUG { ImageHeader { exch == == } forall (----------------\n) print flush } if
/D F
<< /InitialCodeLength F read1
/FirstBitLowOrder true
/BlockData true
/EarlyChange 0
>> /LZWDecode filter def
[/Indexed /DeviceRGB 1 BitsPerPixel bitshift 1 sub Palette] setcolorspace
matrix currentmatrix
0 1 3 { 2 copy get dup 0 ne { dup abs div } if 3 copy put pop pop } for
setmatrix
<< /ImageType 1
/ImageMatrix [1 0 0 -1 0 Height]
/BitsPerComponent 8
/Decode [0 255]
Interlaced
{ /Width Width /Height 1
/row Width string def
/DataSource row
>> /I exch def
/inter % <num> <denom> inter -
{ /denom exch def /num exch def
gsave
/lines Height denom 1 sub add num sub denom idiv def
0 num neg translate
/delta denom neg def
lines
{ D row readstring pop pop
I imageGIF
0 delta translate
} repeat
grestore
}
bind def
0 8 inter
4 8 inter
2 4 inter
1 2 inter
}
{ /Width Width /Height Height
/DataSource D
>> imageGIF
}
ifelse
saved end end end restore
} bind def
|