author | Claus Gittinger <cg@exept.de> |
Wed, 15 Oct 1997 19:58:09 +0200 | |
changeset 712 | 6403dd3407eb |
parent 710 | c644d7932605 |
child 713 | 548898fdd1dc |
permissions | -rw-r--r-- |
0 | 1 |
" |
6 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
26 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ImageReader subclass:#GIFReader |
|
708 | 14 |
instanceVariableNames:'redMap greenMap blueMap pass xpos ypos rowByteSize remainBitCount |
15 |
bufByte bufStream prefixTable suffixTable clearCode eoiCode |
|
16 |
freeCode codeSize maxCode interlace' |
|
17 |
classVariableNames:'ImageSeparator Extension Terminator' |
|
154 | 18 |
poolDictionaries:'' |
259 | 19 |
category:'Graphics-Images-Support' |
0 | 20 |
! |
21 |
||
339 | 22 |
!GIFReader class methodsFor:'documentation'! |
0 | 23 |
|
21 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
26 | 27 |
All Rights Reserved |
21 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
0 | 38 |
documentation |
39 |
" |
|
40 |
this class provides methods for loading and saving GIF pictures. |
|
21 | 41 |
It has been tested with some different GIF87a pictures, I dont |
0 | 42 |
know, if it works with other GIF versions. |
43 |
GIF extension blocks are not handled. |
|
44 |
||
45 |
GIF file writing is not implemented (use TIFF). |
|
46 |
||
21 | 47 |
legal stuff extracted from GIF87a documentation: |
0 | 48 |
|
49 |
CompuServe Incorporated hereby grants a limited, non-exclusive, royalty-free |
|
50 |
license for the use of the Graphics Interchange Format(sm) in computer |
|
51 |
software; computer software utilizing GIF(sm) must acknowledge ownership of the |
|
52 |
Graphics Interchange Format and its Service Mark by CompuServe Incorporated, in |
|
53 |
User and Technical Documentation. |
|
54 |
||
55 |
The Graphics Interchange Format(c) is the Copyright property of |
|
56 |
CompuServe Incorporated. GIF(sm) is a Service Mark property of |
|
57 |
CompuServe Incorporated. |
|
194 | 58 |
|
59 |
[See also:] |
|
234 | 60 |
Image Form Icon |
194 | 61 |
BlitImageReader FaceReader JPEGReader PBMReader PCXReader |
210 | 62 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
209 | 63 |
XBMReader XPMReader XWDReader |
220 | 64 |
|
65 |
[author:] |
|
66 |
Claus Gittinger |
|
0 | 67 |
" |
68 |
! ! |
|
69 |
||
339 | 70 |
!GIFReader class methodsFor:'initialization'! |
26 | 71 |
|
72 |
initialize |
|
198 | 73 |
"install myself in the Image classes fileFormat table |
398 | 74 |
for the `.gif' extensions." |
198 | 75 |
|
708 | 76 |
ImageSeparator := $, asciiValue. |
77 |
Extension := $!! asciiValue. |
|
78 |
Terminator := $; asciiValue. |
|
79 |
||
647 | 80 |
MIMETypes defineImageType:'image/gif' suffix:'gif' reader:self. |
198 | 81 |
|
708 | 82 |
"Modified: 14.10.1997 / 18:47:27 / cg" |
26 | 83 |
! ! |
84 |
||
339 | 85 |
!GIFReader class methodsFor:'testing'! |
1 | 86 |
|
87 |
isValidImageFile:aFileName |
|
88 |
"return true, if aFileName contains a GIF image" |
|
89 |
||
90 |
|id inStream| |
|
91 |
||
9 | 92 |
inStream := self streamReadingFile:aFileName. |
1 | 93 |
inStream isNil ifTrue:[^ false]. |
94 |
||
332 | 95 |
inStream text. |
96 |
||
1 | 97 |
id := String new:6. |
98 |
inStream nextBytes:6 into:id. |
|
99 |
inStream close. |
|
100 |
||
101 |
(id = 'GIF87a') ifFalse:[ |
|
174 | 102 |
(id startsWith:'GIF') ifFalse:[^ false]. |
1 | 103 |
|
174 | 104 |
id ~= 'GIF89a' ifTrue:[ |
355 | 105 |
'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR. |
174 | 106 |
] |
1 | 107 |
]. |
108 |
^ true |
|
174 | 109 |
|
355 | 110 |
"Modified: 10.1.1997 / 15:40:34 / cg" |
1 | 111 |
! ! |
112 |
||
708 | 113 |
!GIFReader methodsFor:'private - writing'! |
114 |
||
115 |
checkCodeSize |
|
116 |
(freeCode > maxCode and: [codeSize < 12]) |
|
117 |
ifTrue: |
|
118 |
[codeSize := codeSize + 1. |
|
119 |
maxCode := (1 bitShift: codeSize) - 1] |
|
120 |
||
121 |
"Created: 14.10.1997 / 18:42:01 / cg" |
|
122 |
! |
|
123 |
||
124 |
flushBits |
|
125 |
remainBitCount = 0 |
|
126 |
ifFalse: |
|
127 |
[self nextBytePut: bufByte. |
|
128 |
remainBitCount := 0]. |
|
129 |
self flushBuffer |
|
130 |
||
131 |
"Modified: 14.10.1997 / 18:58:06 / cg" |
|
132 |
! |
|
133 |
||
134 |
flushBuffer |
|
135 |
bufStream isEmpty ifTrue: [^ self]. |
|
136 |
outStream nextPut: bufStream size. |
|
137 |
outStream nextPutAll: bufStream contents. |
|
138 |
bufStream := WriteStream on: (ByteArray new: 256) |
|
139 |
||
140 |
"Modified: 14.10.1997 / 20:46:04 / cg" |
|
141 |
! |
|
142 |
||
143 |
flushCode |
|
144 |
self flushBits |
|
145 |
||
146 |
"Created: 14.10.1997 / 18:57:33 / cg" |
|
147 |
! |
|
148 |
||
710 | 149 |
nextBitsPut: anInteger |
150 |
| integer writeBitCount shiftCount | |
|
151 |
shiftCount _ 0. |
|
152 |
remainBitCount = 0 |
|
153 |
ifTrue: |
|
154 |
[writeBitCount _ 8. |
|
155 |
integer _ anInteger] |
|
156 |
ifFalse: |
|
157 |
[writeBitCount _ remainBitCount. |
|
158 |
integer _ bufByte + (anInteger bitShift: 8 - remainBitCount)]. |
|
159 |
[writeBitCount < codeSize] |
|
160 |
whileTrue: |
|
161 |
[self nextBytePut: ((integer bitShift: shiftCount) bitAnd: 255). |
|
162 |
shiftCount _ shiftCount - 8. |
|
163 |
writeBitCount _ writeBitCount + 8]. |
|
164 |
(remainBitCount _ writeBitCount - codeSize) = 0 |
|
165 |
ifTrue: [self nextBytePut: (integer bitShift: shiftCount)] |
|
166 |
ifFalse: [bufByte _ integer bitShift: shiftCount]. |
|
167 |
^anInteger |
|
708 | 168 |
|
710 | 169 |
"Modified: 15.10.1997 / 16:50:30 / cg" |
708 | 170 |
! |
171 |
||
710 | 172 |
nextBytePut: aByte |
173 |
bufStream nextPut: aByte. |
|
174 |
bufStream size >= 254 ifTrue: [self flushBuffer] |
|
708 | 175 |
|
710 | 176 |
"Modified: 15.10.1997 / 16:50:52 / cg" |
708 | 177 |
! |
178 |
||
710 | 179 |
readPixelFrom: bits |
180 |
| pixel | |
|
708 | 181 |
ypos >= height ifTrue: [^ nil]. |
710 | 182 |
pixel := bits at: ypos * rowByteSize + xpos + 1. |
708 | 183 |
self updatePixelPosition. |
710 | 184 |
^ pixel |
708 | 185 |
|
186 |
"Created: 14.10.1997 / 18:43:50 / cg" |
|
710 | 187 |
"Modified: 15.10.1997 / 16:46:43 / cg" |
708 | 188 |
! |
189 |
||
190 |
setParameters:bitsPerPixel |
|
191 |
clearCode := 1 bitShift:bitsPerPixel. |
|
192 |
eoiCode := clearCode + 1. |
|
193 |
freeCode := clearCode + 2. |
|
194 |
codeSize := bitsPerPixel + 1. |
|
195 |
maxCode := (1 bitShift: codeSize) - 1 |
|
196 |
||
197 |
"Modified: 14.10.1997 / 20:09:48 / cg" |
|
198 |
! |
|
199 |
||
200 |
updatePixelPosition |
|
201 |
(xpos _ xpos + 1) >= width ifFalse: [^ self]. |
|
202 |
xpos _ 0. |
|
203 |
interlace == true |
|
204 |
ifFalse: |
|
205 |
[ypos _ ypos + 1. |
|
206 |
^ self]. |
|
207 |
pass = 0 |
|
208 |
ifTrue: |
|
209 |
[(ypos _ ypos + 8) >= height |
|
210 |
ifTrue: |
|
211 |
[pass _ pass + 1. |
|
212 |
ypos _ 4]. |
|
213 |
^ self]. |
|
214 |
pass = 1 |
|
215 |
ifTrue: |
|
216 |
[(ypos _ ypos + 8) >= height |
|
217 |
ifTrue: |
|
218 |
[pass _ pass + 1. |
|
219 |
ypos _ 2]. |
|
220 |
^ self]. |
|
221 |
pass = 2 |
|
222 |
ifTrue: |
|
223 |
[(ypos _ ypos + 4) >= height |
|
224 |
ifTrue: |
|
225 |
[pass _ pass + 1. |
|
226 |
ypos _ 1]. |
|
227 |
^ self]. |
|
228 |
pass = 3 |
|
229 |
ifTrue: |
|
230 |
[ypos _ ypos + 2. |
|
231 |
^ self]. |
|
232 |
^ self error: 'can''t happen' |
|
233 |
||
234 |
"Modified: 14.10.1997 / 18:44:27 / cg" |
|
235 |
! |
|
236 |
||
710 | 237 |
writeCode: aCode |
238 |
self nextBitsPut: aCode |
|
708 | 239 |
|
240 |
"Created: 14.10.1997 / 18:38:35 / cg" |
|
710 | 241 |
"Modified: 15.10.1997 / 17:01:47 / cg" |
708 | 242 |
! |
243 |
||
244 |
writeCodeAndCheckCodeSize: t1 |
|
245 |
self writeCode: t1. |
|
246 |
self checkCodeSize |
|
247 |
||
248 |
"Created: 14.10.1997 / 18:38:24 / cg" |
|
249 |
"Modified: 14.10.1997 / 18:40:56 / cg" |
|
250 |
! ! |
|
251 |
||
0 | 252 |
!GIFReader methodsFor:'reading from file'! |
253 |
||
1 | 254 |
checkGreyscaleColormap |
239 | 255 |
"return true, if colormap is actually a greymap. |
256 |
Could be used to convert it into a greyScale image - which is not yet done." |
|
1 | 257 |
|
20 | 258 |
|sz "{ Class: SmallInteger }" |
259 |
redVal| |
|
260 |
||
261 |
sz := redMap size. |
|
262 |
||
263 |
1 to:sz do:[:i | |
|
239 | 264 |
redVal := redMap at:i. |
265 |
redVal ~~ (greenMap at:i) ifTrue:[^ false]. |
|
266 |
redVal ~~ (blueMap at:i) ifTrue:[^ false]. |
|
1 | 267 |
]. |
268 |
^ true |
|
239 | 269 |
|
270 |
"Modified: 2.5.1996 / 17:54:40 / cg" |
|
1 | 271 |
! |
272 |
||
43 | 273 |
fromStream:aStream |
192 | 274 |
"read a stream containing a GIF image. |
275 |
Leave image description in instance variables." |
|
43 | 276 |
|
708 | 277 |
|byte index flag count fileColorMap |
43 | 278 |
colorMapSize bitsPerPixel scrWidth scrHeight |
279 |
hasColorMap hasLocalColorMap interlaced id |
|
280 |
leftOffs topOffs codeLen |
|
281 |
compressedData compressedSize |
|
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
282 |
tmp srcOffset dstOffset isGif89 atEnd |
64 | 283 |
h "{ Class: SmallInteger }"| |
43 | 284 |
|
285 |
inStream := aStream. |
|
286 |
aStream binary. |
|
287 |
||
288 |
"GIF-files are always lsb (intel-world)" |
|
289 |
byteOrder := #lsb. |
|
290 |
||
331
304f9c439efa
allow reading from ByteArray-readStreams
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
291 |
id := ByteArray new:6. |
304f9c439efa
allow reading from ByteArray-readStreams
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
292 |
aStream nextBytes:6 into:id startingAt:1. |
304f9c439efa
allow reading from ByteArray-readStreams
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
293 |
id := id asString. |
43 | 294 |
|
295 |
"all I had for testing where GIF87a files; |
|
296 |
I hope later versions work too ..." |
|
297 |
||
154 | 298 |
isGif89 := false. |
43 | 299 |
(id ~= 'GIF87a') ifTrue:[ |
154 | 300 |
(id startsWith:'GIF') ifFalse:[ |
355 | 301 |
'GIFReader [info]: not a gif file' infoPrintCR. |
154 | 302 |
^ nil |
303 |
]. |
|
304 |
id ~= 'GIF89a' ifTrue:[ |
|
355 | 305 |
'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR. |
154 | 306 |
] |
43 | 307 |
]. |
308 |
||
309 |
"get screen dimensions (not used)" |
|
310 |
scrWidth := aStream nextShortMSB:false. |
|
311 |
scrHeight := aStream nextShortMSB:false. |
|
312 |
||
313 |
"get flag byte" |
|
314 |
flag := aStream nextByte. |
|
315 |
hasColorMap := (flag bitAnd:2r10000000) ~~ 0. |
|
316 |
"bitsPerRGB := ((flag bitAnd:2r01110000) bitShift:-4) + 1. " |
|
317 |
"colorMapSorted := ((flag bitAnd:2r00001000) ~~ 0. " |
|
318 |
bitsPerPixel := (flag bitAnd:2r00000111) + 1. |
|
319 |
colorMapSize := 1 bitShift:bitsPerPixel. |
|
320 |
||
321 |
"get background (not used)" |
|
322 |
aStream nextByte. |
|
323 |
||
324 |
"aspect ratio (not used)" |
|
325 |
aStream nextByte. |
|
326 |
||
327 |
"get colorMap" |
|
328 |
hasColorMap ifTrue:[ |
|
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
329 |
self readColorMap:colorMapSize. |
708 | 330 |
fileColorMap := Colormap |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
331 |
redVector:redMap |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
332 |
greenVector:greenMap |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
333 |
blueVector:blueMap. |
43 | 334 |
]. |
708 | 335 |
colorMap := fileColorMap. |
43 | 336 |
|
337 |
photometric := #palette. |
|
338 |
samplesPerPixel := 1. |
|
339 |
bitsPerSample := #(8). |
|
340 |
||
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
341 |
atEnd := false. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
342 |
[atEnd] whileFalse:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
343 |
"gif89a extensions" |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
344 |
byte := aStream nextByte. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
345 |
|
708 | 346 |
byte == Extension ifTrue:[ |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
347 |
self readExtension:aStream. |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
348 |
] ifFalse:[ |
708 | 349 |
(byte == Terminator) ifTrue:[ |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
350 |
atEnd := true |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
351 |
] ifFalse:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
352 |
"must be image separator" |
708 | 353 |
(byte ~~ ImageSeparator) ifTrue:[ |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
354 |
('GIFReader [info]: corrupted gif file (no IMAGESEP): ' , (byte printStringRadix:16)) infoPrintCR. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
355 |
^ nil |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
356 |
]. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
357 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
358 |
"get image data" |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
359 |
leftOffs := aStream nextShortMSB:false. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
360 |
topOffs := aStream nextShortMSB:false. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
361 |
width := aStream nextShortMSB:false. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
362 |
height := aStream nextShortMSB:false. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
363 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
364 |
dimensionCallBack notNil ifTrue:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
365 |
dimensionCallBack value:self |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
366 |
]. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
367 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
368 |
"/ |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
369 |
"/ 'width ' print. width printNewline. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
370 |
"/ 'height ' print. height printNewline. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
371 |
"/ |
43 | 372 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
373 |
"another flag byte" |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
374 |
flag := aStream nextByte. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
375 |
interlaced := (flag bitAnd:2r01000000) ~~ 0. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
376 |
hasLocalColorMap := (flag bitAnd:2r10000000) ~~ 0. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
377 |
"localColorMapSorted := (flag bitAnd:2r00100000) ~~ 0. " |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
378 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
379 |
"if image has a local colormap, this one is used" |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
380 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
381 |
hasLocalColorMap ifTrue:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
382 |
"local descr. overwrites" |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
383 |
bitsPerPixel := (flag bitAnd:2r00000111) + 1. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
384 |
colorMapSize := 1 bitShift:bitsPerPixel. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
385 |
"overwrite colormap" |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
386 |
self readColorMap:colorMapSize. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
387 |
colorMap := Colormap |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
388 |
redVector:redMap |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
389 |
greenVector:greenMap |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
390 |
blueVector:blueMap. |
708 | 391 |
] ifFalse:[ |
392 |
colorMap := fileColorMap |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
393 |
]. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
394 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
395 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
396 |
"get codelen for decompression" |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
397 |
codeLen := aStream nextByte. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
398 |
|
691 | 399 |
compressedData := ByteArray uninitializedNew:(aStream fileSize). |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
400 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
401 |
"get compressed data" |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
402 |
index := 1. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
403 |
count := aStream nextByte. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
404 |
[count notNil and:[count ~~ 0]] whileTrue:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
405 |
aStream nextBytes:count into:compressedData startingAt:index blockSize:4096. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
406 |
index := index + count. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
407 |
count := aStream nextByte |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
408 |
]. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
409 |
compressedSize := index - 1. |
83 | 410 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
411 |
h := height. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
412 |
data := ByteArray new:((width + 1) * (h + 1)). |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
413 |
"/ 'GIFReader: decompressing ...' infoPrintCR. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
414 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
415 |
self class decompressGIFFrom:compressedData |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
416 |
count:compressedSize |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
417 |
into:data |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
418 |
startingAt:1 |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
419 |
codeLen:(codeLen + 1). |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
420 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
421 |
interlaced ifTrue:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
422 |
"/ 'GIFREADER: deinterlacing ...' infoPrintCR. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
423 |
tmp := ByteArray new:(data size). |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
424 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
425 |
"phase 1: 0, 8, 16, 24, ..." |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
426 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
427 |
srcOffset := 1. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
428 |
0 to:(h - 1) by:8 do:[:dstRow | |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
429 |
dstOffset := dstRow * width + 1. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
430 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
431 |
with:data startingAt:srcOffset. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
432 |
srcOffset := srcOffset + width. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
433 |
]. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
434 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
435 |
"phase 2: 4, 12, 20, 28, ..." |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
436 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
437 |
4 to:(h - 1) by:8 do:[:dstRow | |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
438 |
dstOffset := dstRow * width + 1. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
439 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
440 |
with:data startingAt:srcOffset. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
441 |
srcOffset := srcOffset + width. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
442 |
]. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
443 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
444 |
"phase 3: 2, 6, 10, 14, ..." |
43 | 445 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
446 |
2 to:(h - 1) by:4 do:[:dstRow | |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
447 |
dstOffset := dstRow * width + 1. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
448 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
449 |
with:data startingAt:srcOffset. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
450 |
srcOffset := srcOffset + width. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
451 |
]. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
452 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
453 |
"phase 4: 1, 3, 5, 7, ..." |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
454 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
455 |
1 to:(h - 1) by:2 do:[:dstRow | |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
456 |
dstOffset := dstRow * width + 1. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
457 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
458 |
with:data startingAt:srcOffset. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
459 |
srcOffset := srcOffset + width. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
460 |
]. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
461 |
|
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
462 |
data := tmp. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
463 |
tmp := nil. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
464 |
]. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
465 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
466 |
imageSequence isNil ifTrue:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
467 |
imageSequence := OrderedCollection new. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
468 |
]. |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
469 |
maskPixel notNil ifTrue:[ |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
470 |
"/ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
471 |
"/ ok, there is a maskValue |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
472 |
"/ build a Depth1Image for it. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
473 |
"/ |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
474 |
self buildMaskFromColor:maskPixel |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
475 |
]. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
476 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
477 |
imageSequence add:(self image). |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
478 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
479 |
aStream atEnd ifTrue:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
480 |
atEnd := true. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
481 |
] |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
482 |
] |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
483 |
]. |
307
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
484 |
]. |
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
485 |
|
43 | 486 |
" |
487 |
GIFReader fromFile:'../fileIn/bitmaps/claus.gif |
|
488 |
GIFReader fromFile:'../fileIn/bitmaps/garfield.gif' |
|
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
489 |
GIFReader new fromStream:('/home2/cg/.misc/circum.gif' asFilename readStream) |
43 | 490 |
" |
154 | 491 |
|
315
506e0ce38534
Moved #buildMask from GIFReader to ImageReader>>#buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents:
312
diff
changeset
|
492 |
"Modified: 5.7.1996 / 17:32:01 / stefan" |
708 | 493 |
"Modified: 14.10.1997 / 20:45:57 / cg" |
135 | 494 |
! |
495 |
||
496 |
makeGreyscale |
|
497 |
"not yet implemented/needed" |
|
498 |
! |
|
499 |
||
500 |
readColorMap:colorMapSize |
|
501 |
"get gif colormap consisting of colorMapSize entries" |
|
502 |
||
503 |
|sz "{ Class: SmallInteger }"| |
|
504 |
||
505 |
redMap := ByteArray uninitializedNew:colorMapSize. |
|
506 |
greenMap := ByteArray uninitializedNew:colorMapSize. |
|
507 |
blueMap := ByteArray uninitializedNew:colorMapSize. |
|
239 | 508 |
|
135 | 509 |
sz := colorMapSize. |
510 |
1 to:sz do:[:i | |
|
239 | 511 |
redMap at:i put:(inStream nextByte). |
512 |
greenMap at:i put:(inStream nextByte). |
|
513 |
blueMap at:i put:(inStream nextByte) |
|
307
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
514 |
]. |
239 | 515 |
|
307
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
516 |
"Modified: 21.6.1996 / 12:32:43 / cg" |
154 | 517 |
! |
518 |
||
519 |
readExtension:aStream |
|
239 | 520 |
"get gif89 extension - this is currently ignored" |
154 | 521 |
|
522 |
|type blockSize subBlockSize |
|
304 | 523 |
aspNum aspDen left top width height cWidth cHeight fg bg |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
524 |
animationType animationTime animationMask |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
525 |
appID appAUTH |
625 | 526 |
iterationCount b ok| |
154 | 527 |
|
528 |
type := aStream nextByte. |
|
529 |
type == $R asciiValue ifTrue:[ |
|
239 | 530 |
"/ |
154 | 531 |
"/ Ratio extension |
239 | 532 |
"/ |
354
b4d2ce853c24
stefans suggested info/warning/error/fatal
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
533 |
'GIFREADER [info]: ratio extension ignored' infoPrintCR. |
154 | 534 |
blockSize := aStream nextByte. |
535 |
(blockSize == 2) ifTrue:[ |
|
536 |
aspNum := aStream nextByte. |
|
537 |
aspDen := aStream nextByte |
|
538 |
] ifFalse:[ |
|
539 |
aStream skip:blockSize |
|
540 |
]. |
|
541 |
"/ eat subblocks |
|
542 |
||
543 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
|
544 |
aStream skip:subBlockSize |
|
239 | 545 |
]. |
546 |
^ self |
|
547 |
]. |
|
548 |
||
549 |
type == 16r01 ifTrue:[ |
|
550 |
"/ |
|
551 |
"/ plaintext extension |
|
552 |
"/ |
|
625 | 553 |
"/ 'GIFREADER [info]: plaintext extension ignored' infoPrintCR. |
239 | 554 |
subBlockSize := aStream nextByte. |
555 |
left := aStream nextShortMSB:false. |
|
556 |
top := aStream nextShortMSB:false. |
|
557 |
width := aStream nextShortMSB:false. |
|
558 |
height := aStream nextShortMSB:false. |
|
559 |
cWidth := aStream nextByte. |
|
560 |
cHeight := aStream nextByte. |
|
561 |
fg := aStream nextByte. |
|
562 |
bg := aStream nextByte. |
|
563 |
aStream skip:12. |
|
564 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
|
565 |
aStream skip:subBlockSize |
|
566 |
]. |
|
567 |
^ self |
|
568 |
]. |
|
569 |
||
570 |
type == 16rF9 ifTrue:[ |
|
571 |
"/ |
|
572 |
"/ graphic control extension |
|
573 |
"/ |
|
354
b4d2ce853c24
stefans suggested info/warning/error/fatal
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
574 |
"/ 'GIFREADER [info]: graphic control extension ignored' infoPrintCR. |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
575 |
|
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
576 |
[(subBlockSize := aStream nextByte) ~~ 0] whileTrue:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
577 |
"/ type bitAnd:1 means: animationMask is transparent pixel |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
578 |
"/ to be implemented in Image ... |
305 | 579 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
580 |
animationType := aStream nextByte. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
581 |
animationTime := aStream nextShortMSB:false. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
582 |
animationMask := aStream nextByte. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
583 |
subBlockSize := subBlockSize - 4. |
307
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
584 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
585 |
(animationType bitTest: 1) ifTrue:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
586 |
maskPixel := animationMask. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
587 |
"/ 'GIFREADER [info]: mask: ' infoPrint. (maskPixel printStringRadix:16) infoPrintCR. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
588 |
]. |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
589 |
"/ 'GIFREADER [info]: animationTime: ' infoPrint. (animationTime * (1/100)) infoPrintCR. |
307
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
590 |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
591 |
subBlockSize ~~ 0 ifTrue:[ |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
592 |
aStream skip:subBlockSize |
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
593 |
]. |
239 | 594 |
]. |
595 |
^ self |
|
596 |
]. |
|
597 |
||
519 | 598 |
type == 16rFE ifTrue:[ |
599 |
"/ |
|
600 |
"/ comment extension |
|
601 |
"/ |
|
625 | 602 |
"/ 'GIFREADER [info]: comment extension ignored' infoPrintCR. |
519 | 603 |
[(blockSize := aStream nextByte) ~~ 0] whileTrue:[ |
604 |
aStream skip:blockSize |
|
605 |
]. |
|
606 |
^ self |
|
607 |
]. |
|
608 |
||
239 | 609 |
type == 16rFF ifTrue:[ |
610 |
"/ |
|
611 |
"/ application extension |
|
612 |
"/ |
|
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
613 |
subBlockSize := aStream nextByte. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
614 |
appID := (aStream nextBytes:8 ) asString. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
615 |
appAUTH := aStream nextBytes:3. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
616 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
617 |
subBlockSize := aStream nextByte. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
618 |
|
625 | 619 |
ok := false. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
620 |
appID = 'NETSCAPE' ifTrue:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
621 |
appAUTH asString = '2.0' ifTrue:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
622 |
subBlockSize == 3 ifTrue:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
623 |
b := aStream nextByte. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
624 |
iterationCount := aStream nextShortMSB:false. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
625 |
subBlockSize := aStream nextByte. |
625 | 626 |
ok := true. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
627 |
] |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
628 |
] |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
629 |
]. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
630 |
|
625 | 631 |
ok ifFalse:[ |
632 |
('GIFREADER [info]: application extension (' , appID , ') ignored') infoPrintCR. |
|
633 |
]. |
|
634 |
||
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
635 |
[subBlockSize > 0] whileTrue:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
636 |
aStream skip:subBlockSize. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
637 |
subBlockSize := aStream nextByte. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
638 |
]. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
639 |
^ self |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
640 |
]. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
641 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
642 |
type == 16r2C ifTrue:[ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
643 |
"/ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
644 |
"/ image descriptor extension |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
645 |
"/ |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
646 |
'GIFREADER [info]: image descriptor extension ignored' infoPrintCR. |
239 | 647 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
648 |
aStream skip:subBlockSize |
|
649 |
]. |
|
650 |
^ self |
|
651 |
]. |
|
652 |
||
653 |
"/ |
|
654 |
"/ unknown extension |
|
655 |
"/ |
|
354
b4d2ce853c24
stefans suggested info/warning/error/fatal
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
656 |
'GIFREADER [info]: unknown extension ignored' infoPrintCR. |
239 | 657 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
658 |
aStream skip:subBlockSize |
|
154 | 659 |
] |
660 |
||
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
661 |
"Modified: 24.7.1997 / 18:02:49 / cg" |
0 | 662 |
! ! |
43 | 663 |
|
708 | 664 |
!GIFReader methodsFor:'writing to file'! |
665 |
||
666 |
save:image onFile:aFileName |
|
667 |
"save image as GIF file on aFileName" |
|
668 |
||
669 |
outStream := FileStream newFileNamed:aFileName. |
|
670 |
outStream isNil ifTrue:[ |
|
671 |
^ Image fileCreationErrorSignal |
|
672 |
raiseWith:image |
|
673 |
errorString:('file creation error: ' , aFileName asString). |
|
674 |
]. |
|
675 |
outStream binary. |
|
676 |
||
677 |
image mask notNil ifTrue:[ |
|
678 |
Image informationLostQuerySignal |
|
679 |
raiseWith:image |
|
680 |
errorString:('GFF writer does not (yet) support an imageMask'). |
|
681 |
]. |
|
682 |
||
683 |
byteOrder := #lsb. |
|
684 |
width := image width. |
|
685 |
height := image height. |
|
686 |
photometric := image photometric. |
|
687 |
samplesPerPixel := image samplesPerPixel. |
|
688 |
bitsPerSample := image bitsPerSample. |
|
689 |
colorMap := image colorMap. |
|
690 |
data := image bits. |
|
691 |
||
692 |
self writeHeaderFor:image. |
|
693 |
self writeBitDataFor:image. |
|
694 |
outStream close. |
|
695 |
||
696 |
" |
|
697 |
|i| |
|
698 |
||
699 |
i := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
|
700 |
GIFReader save:i onFile:'foo.gif'. |
|
701 |
(Image fromFile:'./foo.gif') inspect |
|
702 |
" |
|
703 |
||
704 |
"Created: 14.10.1997 / 17:40:12 / cg" |
|
705 |
"Modified: 14.10.1997 / 18:59:22 / cg" |
|
706 |
! |
|
707 |
||
710 | 708 |
writeBitDataFor: image |
709 |
"using modified Lempel-Ziv Welch algorithm." |
|
710 |
||
711 |
| bits bitsPerPixel |
|
712 |
maxBits maxMaxCode tSize initCodeSize ent tShift fCode pixel index disp nomatch | |
|
713 |
||
714 |
bitsPerPixel := image bitsPerPixel. |
|
715 |
bits := image bits. |
|
716 |
||
717 |
pass := 0. |
|
718 |
xpos := 0. |
|
719 |
ypos := 0. |
|
712 | 720 |
rowByteSize := image bytesPerRow. "/ width * 8 + 31 // 32 * 4. |
710 | 721 |
remainBitCount := 0. |
722 |
bufByte := 0. |
|
723 |
bufStream := WriteStream on: (ByteArray new: 256). |
|
708 | 724 |
|
710 | 725 |
maxBits := 12. |
726 |
maxMaxCode := 1 bitShift: maxBits. |
|
727 |
tSize := 5003. |
|
728 |
prefixTable := Array new: tSize. |
|
729 |
suffixTable := Array new: tSize. |
|
730 |
||
731 |
initCodeSize := bitsPerPixel <= 1 ifTrue: [2] ifFalse: [bitsPerPixel]. |
|
732 |
outStream nextPut: initCodeSize. |
|
733 |
self setParameters: initCodeSize. |
|
734 |
||
735 |
tShift := 0. |
|
736 |
fCode := tSize. |
|
737 |
[fCode < 65536] whileTrue: |
|
738 |
[tShift := tShift + 1. |
|
739 |
fCode := fCode * 2]. |
|
740 |
tShift := 8 - tShift. |
|
741 |
1 to: tSize do: [:i | suffixTable at: i put: -1]. |
|
708 | 742 |
|
710 | 743 |
self writeCodeAndCheckCodeSize: clearCode. |
744 |
ent := self readPixelFrom: bits. |
|
745 |
[(pixel := self readPixelFrom: bits) == nil] whileFalse: |
|
708 | 746 |
[ |
710 | 747 |
fCode := (pixel bitShift: maxBits) + ent. |
748 |
index := ((pixel bitShift: tShift) bitXor: ent) + 1. |
|
749 |
(suffixTable at: index) = fCode |
|
750 |
ifTrue: [ent := prefixTable at: index] |
|
751 |
ifFalse: |
|
752 |
[nomatch := true. |
|
753 |
(suffixTable at: index) >= 0 |
|
754 |
ifTrue: |
|
755 |
[disp := tSize - index + 1. |
|
756 |
index = 1 ifTrue: [disp := 1]. |
|
757 |
"probe" |
|
758 |
[(index := index - disp) < 1 ifTrue: [index := index + tSize]. |
|
759 |
(suffixTable at: index) = fCode |
|
760 |
ifTrue: |
|
761 |
[ent := prefixTable at: index. |
|
762 |
nomatch := false. |
|
763 |
"continue whileFalse:"]. |
|
764 |
nomatch and: [(suffixTable at: index) > 0]] |
|
765 |
whileTrue: ["probe"]]. |
|
766 |
"nomatch" |
|
767 |
nomatch ifTrue: |
|
768 |
[self writeCodeAndCheckCodeSize: ent. |
|
769 |
ent := pixel. |
|
770 |
freeCode < maxMaxCode |
|
771 |
ifTrue: |
|
772 |
[prefixTable at: index put: freeCode. |
|
773 |
suffixTable at: index put: fCode. |
|
774 |
freeCode := freeCode + 1] |
|
775 |
ifFalse: |
|
776 |
[self writeCodeAndCheckCodeSize: clearCode. |
|
777 |
1 to: tSize do: [:i | suffixTable at: i put: -1]. |
|
778 |
self setParameters: initCodeSize]]]]. |
|
779 |
prefixTable := suffixTable := nil. |
|
780 |
self writeCodeAndCheckCodeSize: ent. |
|
781 |
self writeCodeAndCheckCodeSize: eoiCode. |
|
782 |
self flushCode. |
|
708 | 783 |
|
710 | 784 |
outStream nextPut: 0. "zero-length packet" |
785 |
outStream nextPut: Terminator. |
|
786 |
||
712 | 787 |
"Modified: 15.10.1997 / 19:56:28 / cg" |
708 | 788 |
! |
789 |
||
790 |
writeHeaderFor:image |
|
791 |
"save image as GIF file on aFileName" |
|
792 |
||
793 |
|bitsPerPixel t1 n| |
|
794 |
||
795 |
bitsPerPixel := image bitsPerPixel. |
|
796 |
||
797 |
outStream nextPutAll: 'GIF87a' asByteArray. |
|
712 | 798 |
self writeShort:width. "/ screen size |
799 |
self writeShort:height. |
|
708 | 800 |
t1 := 128. |
712 | 801 |
t1 := t1 bitOr:(bitsPerPixel - 1 bitShift:5). |
802 |
t1 := t1 bitOr:(bitsPerPixel - 1). |
|
803 |
outStream nextPut:t1. "/ flag |
|
804 |
outStream nextPut:0. "/ background (not used) |
|
805 |
outStream nextPut:0. "/ aspect ratio |
|
708 | 806 |
|
807 |
n := 0. |
|
808 |
image colorMap notNil ifTrue:[ |
|
809 |
image colorMap do:[:clr | |
|
712 | 810 |
|red green blue| |
811 |
||
812 |
clr isNil ifTrue:[ |
|
813 |
"/ unused colorMap slot |
|
814 |
red := green := blue := 0. |
|
815 |
] ifFalse:[ |
|
816 |
red := (clr redByte). |
|
817 |
green := (clr greenByte). |
|
818 |
blue := (clr blueByte). |
|
819 |
]. |
|
708 | 820 |
outStream |
712 | 821 |
nextPut:red; nextPut:green; nextPut:blue. |
708 | 822 |
n := n + 1. |
823 |
] |
|
824 |
]. |
|
825 |
n+1 to:(1 bitShift:bitsPerPixel) do:[:i | |
|
826 |
outStream nextPut:0; nextPut:0; nextPut:0 |
|
827 |
]. |
|
828 |
outStream nextPut:ImageSeparator. |
|
829 |
self writeShort:0. "/ |
|
830 |
self writeShort:0. "/ |
|
831 |
self writeShort:width. "/ image size |
|
832 |
self writeShort:height. |
|
833 |
||
834 |
interlace == true ifTrue:[ |
|
835 |
t1 := 64 |
|
836 |
] ifFalse:[ |
|
837 |
t1 := 0 |
|
838 |
]. |
|
839 |
outStream nextPut:t1 "/ another flag |
|
840 |
||
841 |
"Created: 14.10.1997 / 17:41:28 / cg" |
|
712 | 842 |
"Modified: 15.10.1997 / 19:54:30 / cg" |
708 | 843 |
! ! |
844 |
||
339 | 845 |
!GIFReader class methodsFor:'documentation'! |
135 | 846 |
|
847 |
version |
|
712 | 848 |
^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.59 1997-10-15 17:58:09 cg Exp $' |
135 | 849 |
! ! |
43 | 850 |
GIFReader initialize! |