author | Claus Gittinger <cg@exept.de> |
Fri, 14 Feb 2014 01:23:38 +0100 | |
changeset 3282 | 57d0f3cef4ef |
parent 3120 | ed7676f65f22 |
child 3283 | e32b39c8647f |
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 |
" |
|
1393
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
12 |
"{ Package: 'stx:libview2' }" |
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
13 |
|
0 | 14 |
ImageReader subclass:#GIFReader |
1739 | 15 |
instanceVariableNames:'pass xpos ypos rowByteSize remainBitCount bufByte bufStream |
16 |
prefixTable suffixTable clearCode eoiCode freeCode codeSize |
|
17 |
maxCode interlace frameDelay iterationCount leftOffs topOffs' |
|
708 | 18 |
classVariableNames:'ImageSeparator Extension Terminator' |
154 | 19 |
poolDictionaries:'' |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
20 |
category:'Graphics-Images-Readers' |
0 | 21 |
! |
22 |
||
339 | 23 |
!GIFReader class methodsFor:'documentation'! |
0 | 24 |
|
21 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
26 | 28 |
All Rights Reserved |
21 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
0 | 39 |
documentation |
40 |
" |
|
41 |
this class provides methods for loading and saving GIF pictures. |
|
21 | 42 |
It has been tested with some different GIF87a pictures, I dont |
0 | 43 |
know, if it works with other GIF versions. |
44 |
GIF extension blocks are not handled. |
|
45 |
||
21 | 46 |
legal stuff extracted from GIF87a documentation: |
0 | 47 |
|
48 |
CompuServe Incorporated hereby grants a limited, non-exclusive, royalty-free |
|
49 |
license for the use of the Graphics Interchange Format(sm) in computer |
|
50 |
software; computer software utilizing GIF(sm) must acknowledge ownership of the |
|
51 |
Graphics Interchange Format and its Service Mark by CompuServe Incorporated, in |
|
52 |
User and Technical Documentation. |
|
53 |
||
54 |
The Graphics Interchange Format(c) is the Copyright property of |
|
55 |
CompuServe Incorporated. GIF(sm) is a Service Mark property of |
|
56 |
CompuServe Incorporated. |
|
194 | 57 |
|
3120 | 58 |
Notice: |
59 |
there has been some annoyance regarding a patent on the compression algorithm |
|
60 |
used in gif. This patent is now obsolete. However, there is no warranty from |
|
61 |
exept, regarding any legal problems, when using GIF. |
|
62 |
We therefore highly recommend to use newer (and especially: royalty-free) formats, |
|
63 |
such as PNG. |
|
64 |
||
194 | 65 |
[See also:] |
3120 | 66 |
Image Form Icon |
67 |
BlitImageReader FaceReader JPEGReader PBMReader PCXReader |
|
68 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
|
69 |
XBMReader XPMReader XWDReader |
|
220 | 70 |
|
71 |
[author:] |
|
3120 | 72 |
Claus Gittinger |
0 | 73 |
" |
74 |
! ! |
|
75 |
||
339 | 76 |
!GIFReader class methodsFor:'initialization'! |
26 | 77 |
|
78 |
initialize |
|
198 | 79 |
"install myself in the Image classes fileFormat table |
398 | 80 |
for the `.gif' extensions." |
198 | 81 |
|
1952
5009754ae556
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
1846
diff
changeset
|
82 |
ImageSeparator := $, codePoint. |
5009754ae556
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
1846
diff
changeset
|
83 |
Extension := $!! codePoint. |
5009754ae556
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
1846
diff
changeset
|
84 |
Terminator := $; codePoint. |
708 | 85 |
|
647 | 86 |
MIMETypes defineImageType:'image/gif' suffix:'gif' reader:self. |
198 | 87 |
|
708 | 88 |
"Modified: 14.10.1997 / 18:47:27 / cg" |
26 | 89 |
! ! |
90 |
||
339 | 91 |
!GIFReader class methodsFor:'testing'! |
1 | 92 |
|
713 | 93 |
canRepresent:anImage |
94 |
"return true, if anImage can be represented in my file format. |
|
95 |
GIF supports depth 8 images only." |
|
96 |
||
1521 | 97 |
anImage depth == 8 ifTrue:[^ true]. |
2030 | 98 |
('GIFReader [info]: images depth is ~~ 8.') infoPrintCR. |
99 |
^ false. |
|
713 | 100 |
|
101 |
"Created: 17.10.1997 / 20:19:20 / cg" |
|
102 |
! |
|
103 |
||
1 | 104 |
isValidImageFile:aFileName |
105 |
"return true, if aFileName contains a GIF image" |
|
106 |
||
107 |
|id inStream| |
|
108 |
||
9 | 109 |
inStream := self streamReadingFile:aFileName. |
1 | 110 |
inStream isNil ifTrue:[^ false]. |
111 |
||
332 | 112 |
inStream text. |
113 |
||
1 | 114 |
id := String new:6. |
115 |
inStream nextBytes:6 into:id. |
|
116 |
inStream close. |
|
117 |
||
118 |
(id = 'GIF87a') ifFalse:[ |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
119 |
(id startsWith:'GIF') ifFalse:[^ false]. |
1 | 120 |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
121 |
id ~= 'GIF89a' ifTrue:[ |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
122 |
'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
123 |
] |
1 | 124 |
]. |
125 |
^ true |
|
174 | 126 |
|
355 | 127 |
"Modified: 10.1.1997 / 15:40:34 / cg" |
1 | 128 |
! ! |
129 |
||
2694 | 130 |
!GIFReader methodsFor:'image reading'! |
154 | 131 |
|
2596 | 132 |
fromStream:aStream |
133 |
"read a stream containing a GIF image (or an image sequence). |
|
134 |
Leave image description in instance variables." |
|
135 |
||
136 |
|byte index flag count fileColorMap |
|
137 |
colorMapSize bitsPerPixel scrWidth scrHeight |
|
138 |
hasColorMap hasLocalColorMap interlaced id |
|
139 |
codeLen |
|
140 |
compressedData compressedSize |
|
141 |
tmp srcOffset dstOffset isGif89 atEnd |
|
142 |
h "{ Class: SmallInteger }" |
|
143 |
img firstImage firstOffset firstFrameDelay frame imageCount| |
|
144 |
||
145 |
inStream := aStream. |
|
146 |
aStream binary. |
|
147 |
||
148 |
"GIF-files are always lsb (intel-world)" |
|
149 |
byteOrder := #lsb. |
|
150 |
||
151 |
id := ByteArray new:6. |
|
152 |
(aStream nextBytes:6 into:id startingAt:1) ~~ 6 ifTrue:[ |
|
153 |
^ self fileFormatError:'not a gif file (short read)'. |
|
154 |
]. |
|
155 |
id := id asString. |
|
156 |
||
157 |
"all I had for testing where GIF87a files; |
|
158 |
I hope later versions work too ..." |
|
159 |
||
160 |
isGif89 := false. |
|
161 |
(id ~= 'GIF87a') ifTrue:[ |
|
162 |
(id startsWith:'GIF') ifFalse:[ |
|
163 |
^ self fileFormatError:('not a gif file (id=''' , id , ''')'). |
|
164 |
]. |
|
165 |
id ~= 'GIF89a' ifTrue:[ |
|
166 |
'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR. |
|
167 |
] |
|
168 |
]. |
|
169 |
||
170 |
"get screen dimensions (not used)" |
|
171 |
scrWidth := aStream nextShortMSB:false. |
|
172 |
scrHeight := aStream nextShortMSB:false. |
|
173 |
||
174 |
"get flag byte" |
|
175 |
flag := aStream nextByte. |
|
176 |
hasColorMap := (flag bitAnd:2r10000000) ~~ 0. |
|
177 |
"bitsPerRGB := ((flag bitAnd:2r01110000) bitShift:-4) + 1. " |
|
178 |
"colorMapSorted := ((flag bitAnd:2r00001000) ~~ 0. " |
|
179 |
bitsPerPixel := (flag bitAnd:2r00000111) + 1. |
|
180 |
colorMapSize := 1 bitShift:bitsPerPixel. |
|
181 |
||
182 |
"get background (not used)" |
|
183 |
aStream nextByte. |
|
184 |
||
185 |
"aspect ratio (not used)" |
|
186 |
aStream nextByte. |
|
187 |
||
188 |
"get colorMap" |
|
189 |
hasColorMap ifTrue:[ |
|
190 |
fileColorMap := self readColorMap:colorMapSize. |
|
191 |
]. |
|
192 |
colorMap := fileColorMap. |
|
193 |
||
194 |
photometric := #palette. |
|
195 |
samplesPerPixel := 1. |
|
196 |
bitsPerSample := #(8). |
|
197 |
||
198 |
imageCount := 0. |
|
199 |
atEnd := false. |
|
200 |
[atEnd] whileFalse:[ |
|
201 |
"gif89a extensions" |
|
202 |
||
203 |
byte := aStream nextByte. |
|
204 |
byte isNil ifTrue:[ |
|
205 |
"/ atEnd-Terminator missing |
|
206 |
atEnd := true |
|
207 |
] ifFalse:[ |
|
208 |
byte == Extension ifTrue:[ |
|
209 |
"/ 'Ext' infoPrintCR. |
|
210 |
self readExtension:aStream. |
|
211 |
] ifFalse:[ |
|
212 |
(byte == Terminator) ifTrue:[ |
|
213 |
atEnd := true |
|
214 |
] ifFalse:[ |
|
215 |
"must be image separator" |
|
216 |
(byte ~~ ImageSeparator) ifTrue:[ |
|
217 |
^ self fileFormatError:('corrupted gif file (no IMAGESEP): ' , (byte printStringRadix:16)). |
|
218 |
]. |
|
219 |
"/ 'Img' infoPrintCR. |
|
220 |
||
221 |
fileColorMap notNil ifTrue:[ |
|
222 |
colorMap := fileColorMap. |
|
223 |
]. |
|
224 |
Object primitiveFailureSignal handle:[:ex | |
|
225 |
^ self fileFormatError:('corrupted gif file'). |
|
226 |
] do:[ |
|
227 |
self readImage:aStream. |
|
228 |
]. |
|
229 |
||
230 |
maskPixel notNil ifTrue:[ |
|
231 |
"/ |
|
232 |
"/ ok, there is a maskValue |
|
233 |
"/ build a Depth1Image for it. |
|
234 |
"/ |
|
235 |
self buildMaskFromColor:maskPixel |
|
236 |
]. |
|
237 |
||
238 |
imageCount == 0 ifTrue:[ |
|
239 |
img := self makeImage. |
|
240 |
"/ remember first image in case more come later. |
|
241 |
firstImage := img. |
|
242 |
firstFrameDelay := frameDelay. |
|
243 |
firstOffset := (leftOffs @ topOffs). |
|
244 |
] ifFalse:[ |
|
245 |
imageCount == 1 ifTrue:[ |
|
246 |
imageSequence := ImageSequence new. |
|
247 |
img imageSequence:imageSequence. |
|
248 |
||
249 |
"/ add frame for first image. |
|
250 |
frame := ImageFrame new image:firstImage. |
|
251 |
frame delay:firstFrameDelay. |
|
252 |
frame offset:firstOffset. |
|
253 |
imageSequence add:frame. |
|
254 |
]. |
|
255 |
img := self makeImage. |
|
256 |
img imageSequence:imageSequence. |
|
257 |
||
258 |
"/ add frame for this image. |
|
259 |
frame := ImageFrame new image:img. |
|
260 |
frame delay:frameDelay. |
|
261 |
frame offset:(leftOffs @ topOffs). |
|
262 |
imageSequence add:frame. |
|
263 |
]. |
|
264 |
||
265 |
imageCount := imageCount + 1. |
|
266 |
||
267 |
frameDelay := nil. |
|
268 |
||
269 |
aStream atEnd ifTrue:[ |
|
270 |
atEnd := true. |
|
271 |
] |
|
272 |
] |
|
273 |
]. |
|
274 |
]. |
|
275 |
]. |
|
276 |
||
277 |
imageSequence notNil ifTrue:[ |
|
278 |
iterationCount notNil ifTrue:[ |
|
279 |
iterationCount == 0 ifTrue:[ |
|
280 |
imageSequence loop:true. |
|
281 |
] ifFalse:[ |
|
282 |
imageSequence loop:false. |
|
283 |
imageSequence iterationCount:iterationCount. |
|
284 |
] |
|
285 |
] |
|
286 |
]. |
|
287 |
||
288 |
" |
|
289 |
Image fromFile:'/home/cg/work/stx/goodies/bitmaps/gifImages/animated/vrml.gif' |
|
290 |
Image fromFile:'/home/cg/work/stx/goodies/bitmaps/gifImages/animated/arrow.gif' |
|
291 |
" |
|
292 |
||
293 |
"Modified: / 5.7.1996 / 17:32:01 / stefan" |
|
294 |
"Modified: / 21.8.1998 / 22:20:00 / cg" |
|
2694 | 295 |
! ! |
296 |
||
297 |
!GIFReader methodsFor:'private-reading'! |
|
298 |
||
299 |
makeGreyscale |
|
300 |
"not yet implemented/needed" |
|
301 |
! |
|
302 |
||
303 |
readColorMap:colorMapSize |
|
304 |
"get a gif colormap consisting of colorMapSize entries" |
|
305 |
||
306 |
|rgbVector| |
|
307 |
||
308 |
rgbVector := inStream nextBytes:colorMapSize*3. |
|
309 |
^ MappedPalette rgbBytesVector:rgbVector |
|
2596 | 310 |
! |
311 |
||
154 | 312 |
readExtension:aStream |
882 | 313 |
"get gif89 extension" |
154 | 314 |
|
315 |
|type blockSize subBlockSize |
|
304 | 316 |
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
|
317 |
animationType animationTime animationMask |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
318 |
appID appAUTH |
888 | 319 |
b ok| |
154 | 320 |
|
321 |
type := aStream nextByte. |
|
1952
5009754ae556
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
1846
diff
changeset
|
322 |
type == $R codePoint ifTrue:[ |
882 | 323 |
"/ |
324 |
"/ Ratio extension |
|
325 |
"/ |
|
2844 | 326 |
"/ 'GIFREADER [info]: ratio extension ignored' infoPrintCR. |
882 | 327 |
blockSize := aStream nextByte. |
328 |
(blockSize == 2) ifTrue:[ |
|
329 |
aspNum := aStream nextByte. |
|
330 |
aspDen := aStream nextByte |
|
331 |
] ifFalse:[ |
|
332 |
aStream skip:blockSize |
|
333 |
]. |
|
2844 | 334 |
|
882 | 335 |
"/ eat subblocks |
336 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
|
337 |
aStream skip:subBlockSize |
|
338 |
]. |
|
339 |
^ self |
|
239 | 340 |
]. |
341 |
||
342 |
type == 16r01 ifTrue:[ |
|
882 | 343 |
"/ |
344 |
"/ plaintext extension |
|
345 |
"/ |
|
2844 | 346 |
"/ 'GIFREADER [info]: plaintext extension ignored' infoPrintCR. |
882 | 347 |
subBlockSize := aStream nextByte. |
348 |
left := aStream nextShortMSB:false. |
|
349 |
top := aStream nextShortMSB:false. |
|
350 |
width := aStream nextShortMSB:false. |
|
351 |
height := aStream nextShortMSB:false. |
|
352 |
cWidth := aStream nextByte. |
|
353 |
cHeight := aStream nextByte. |
|
354 |
fg := aStream nextByte. |
|
355 |
bg := aStream nextByte. |
|
356 |
aStream skip:12. |
|
2844 | 357 |
"/ eat subblocks |
882 | 358 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
359 |
aStream skip:subBlockSize |
|
360 |
]. |
|
361 |
^ self |
|
239 | 362 |
]. |
363 |
||
364 |
type == 16rF9 ifTrue:[ |
|
882 | 365 |
"/ |
366 |
"/ graphic control extension |
|
367 |
"/ |
|
2844 | 368 |
"/ 'GIFREADER [info]: graphic control extension' infoPrintCR. |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
369 |
|
2595
37dc71e1e59b
be tolerant to corrupted gif files (subblock size in extension)
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
370 |
[(subBlockSize := aStream nextByte) ~~ 0 and:[subBlockSize notNil]] whileTrue:[ |
882 | 371 |
"/ type bitAnd:1 means: animationMask is transparent pixel |
372 |
"/ to be implemented in Image ... |
|
305 | 373 |
|
882 | 374 |
animationType := aStream nextByte. |
375 |
animationTime := aStream nextShortMSB:false. |
|
376 |
animationMask := aStream nextByte. |
|
2595
37dc71e1e59b
be tolerant to corrupted gif files (subblock size in extension)
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
377 |
|
882 | 378 |
subBlockSize := subBlockSize - 4. |
307
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
379 |
|
882 | 380 |
(animationType bitTest: 1) ifTrue:[ |
381 |
maskPixel := animationMask. |
|
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
382 |
"/ 'GIFREADER [info]: mask: ' infoPrint. (maskPixel printStringRadix:16) infoPrintCR. |
882 | 383 |
]. |
670
6a7f628ee66c
oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
384 |
"/ 'GIFREADER [info]: animationTime: ' infoPrint. (animationTime * (1/100)) infoPrintCR. |
1429 | 385 |
"/ 'GIFREADER [info]: animationType: ' infoPrint. (animationType) infoPrintCR. |
386 |
"/ 'GIFREADER [info]: animationMask: ' infoPrint. (animationMask) infoPrintCR. |
|
307
9eaeaca798a5
create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
387 |
|
888 | 388 |
frameDelay := (animationTime * (1/100)) * 1000. |
389 |
||
882 | 390 |
subBlockSize ~~ 0 ifTrue:[ |
391 |
aStream skip:subBlockSize |
|
392 |
]. |
|
393 |
]. |
|
394 |
^ self |
|
239 | 395 |
]. |
396 |
||
519 | 397 |
type == 16rFE ifTrue:[ |
882 | 398 |
"/ |
399 |
"/ comment extension |
|
400 |
"/ |
|
2844 | 401 |
"/ 'GIFREADER [info]: comment extension' infoPrintCR. |
882 | 402 |
[(blockSize := aStream nextByte) ~~ 0] whileTrue:[ |
403 |
aStream skip:blockSize |
|
404 |
]. |
|
405 |
^ self |
|
519 | 406 |
]. |
407 |
||
239 | 408 |
type == 16rFF ifTrue:[ |
882 | 409 |
"/ |
410 |
"/ application extension |
|
411 |
"/ |
|
2844 | 412 |
"/ 'GIFREADER [info]: application extension' infoPrintCR. |
882 | 413 |
subBlockSize := aStream nextByte. |
414 |
appID := (aStream nextBytes:8 ) asString. |
|
415 |
appAUTH := aStream nextBytes:3. |
|
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
416 |
|
882 | 417 |
subBlockSize := aStream nextByte. |
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
418 |
|
882 | 419 |
ok := false. |
420 |
appID = 'NETSCAPE' ifTrue:[ |
|
421 |
appAUTH asString = '2.0' ifTrue:[ |
|
422 |
subBlockSize == 3 ifTrue:[ |
|
423 |
b := aStream nextByte. |
|
424 |
iterationCount := aStream nextShortMSB:false. |
|
425 |
subBlockSize := aStream nextByte. |
|
426 |
ok := true. |
|
888 | 427 |
"/ ('GIFREADER [info]: NETSCAPE application extension - iterationCount = ') infoPrint. |
428 |
"/ iterationCount infoPrintCR. |
|
882 | 429 |
] |
430 |
] |
|
431 |
]. |
|
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
432 |
|
882 | 433 |
ok ifFalse:[ |
434 |
('GIFREADER [info]: application extension (' , appID , ') ignored') infoPrintCR. |
|
435 |
]. |
|
625 | 436 |
|
882 | 437 |
[subBlockSize > 0] whileTrue:[ |
438 |
aStream skip:subBlockSize. |
|
439 |
subBlockSize := aStream nextByte. |
|
440 |
]. |
|
441 |
^ self |
|
618
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
442 |
]. |
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
443 |
|
ab83e72fd105
support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents:
563
diff
changeset
|
444 |
type == 16r2C ifTrue:[ |
882 | 445 |
"/ |
446 |
"/ image descriptor extension |
|
447 |
"/ |
|
1429 | 448 |
"/ 'GIFREADER [info]: image descriptor extension ignored' infoPrintCR. |
882 | 449 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
450 |
aStream skip:subBlockSize |
|
451 |
]. |
|
452 |
^ self |
|
239 | 453 |
]. |
454 |
||
455 |
"/ |
|
456 |
"/ unknown extension |
|
457 |
"/ |
|
354
b4d2ce853c24
stefans suggested info/warning/error/fatal
Claus Gittinger <cg@exept.de>
parents:
339
diff
changeset
|
458 |
'GIFREADER [info]: unknown extension ignored' infoPrintCR. |
239 | 459 |
[(subBlockSize := aStream nextByte) > 0] whileTrue:[ |
882 | 460 |
aStream skip:subBlockSize |
154 | 461 |
] |
462 |
||
2844 | 463 |
"Modified: / 02-06-2010 / 12:21:53 / cg" |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
464 |
! |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
465 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
466 |
readImage:aStream |
882 | 467 |
"read a single image from aStream." |
468 |
||
1429 | 469 |
| flag interlaced hasLocalColorMap bitsPerPixel colorMapSize |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
470 |
codeLen compressedData compressedSize index count h tmp srcOffset dstOffset |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
471 |
initialBuffSize| |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
472 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
473 |
"get image data" |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
474 |
leftOffs := aStream nextShortMSB:false. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
475 |
topOffs := aStream nextShortMSB:false. |
1429 | 476 |
"/ 'GIFReader: leftOffs ' infoPrint. leftOffs infoPrintCR. |
477 |
"/ 'GIFReader: topOffs ' infoPrint. topOffs infoPrintCR. |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
478 |
width := aStream nextShortMSB:false. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
479 |
height := aStream nextShortMSB:false. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
480 |
|
1846 | 481 |
self reportDimension. |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
482 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
483 |
"/ |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
484 |
"/ 'width ' print. width printNewline. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
485 |
"/ 'height ' print. height printNewline. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
486 |
"/ |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
487 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
488 |
"another flag byte" |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
489 |
flag := aStream nextByte. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
490 |
interlaced := (flag bitAnd:2r01000000) ~~ 0. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
491 |
hasLocalColorMap := (flag bitAnd:2r10000000) ~~ 0. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
492 |
"localColorMapSorted := (flag bitAnd:2r00100000) ~~ 0. " |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
493 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
494 |
"if image has a local colormap, this one is used" |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
495 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
496 |
hasLocalColorMap ifTrue:[ |
882 | 497 |
"local descr. overwrites" |
498 |
bitsPerPixel := (flag bitAnd:2r00000111) + 1. |
|
499 |
colorMapSize := 1 bitShift:bitsPerPixel. |
|
500 |
"overwrite colormap" |
|
1739 | 501 |
colorMap := self readColorMap:colorMapSize. |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
502 |
]. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
503 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
504 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
505 |
"get codelen for decompression" |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
506 |
codeLen := aStream nextByte. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
507 |
(aStream respondsTo:#fileSize) ifTrue:[ |
882 | 508 |
initialBuffSize := aStream fileSize. |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
509 |
] ifFalse:[ |
882 | 510 |
initialBuffSize := 512. |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
511 |
]. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
512 |
compressedData := ByteArray uninitializedNew:initialBuffSize. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
513 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
514 |
"get compressed data" |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
515 |
index := 1. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
516 |
count := aStream nextByte. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
517 |
[count notNil and:[count ~~ 0]] whileTrue:[ |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
518 |
(compressedData size < (index+count)) ifTrue:[ |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
519 |
|t| |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
520 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
521 |
t := ByteArray uninitializedNew:(index+count*3//2). |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
522 |
t replaceBytesFrom:1 to:index-1 with:compressedData startingAt:1. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
523 |
compressedData := t. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
524 |
]. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
525 |
|
882 | 526 |
aStream nextBytes:count into:compressedData startingAt:index blockSize:4096. |
527 |
index := index + count. |
|
528 |
count := aStream nextByte |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
529 |
]. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
530 |
compressedSize := index - 1. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
531 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
532 |
h := height. |
1037
90d38c8e3f5f
use initialized byteArrays, in case rows are padded
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
533 |
data := ByteArray new:((width + 1) * (h + 1)). |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
534 |
"/ 'GIFReader: decompressing ...' infoPrintCR. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
535 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
536 |
self class decompressGIFFrom:compressedData |
882 | 537 |
count:compressedSize |
538 |
into:data |
|
539 |
startingAt:1 |
|
540 |
codeLen:(codeLen + 1). |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
541 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
542 |
interlaced ifTrue:[ |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
543 |
"/ 'GIFREADER: deinterlacing ...' infoPrintCR. |
1037
90d38c8e3f5f
use initialized byteArrays, in case rows are padded
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
544 |
tmp := ByteArray new:(data size). |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
545 |
|
882 | 546 |
"phase 1: 0, 8, 16, 24, ..." |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
547 |
|
882 | 548 |
srcOffset := 1. |
549 |
0 to:(h - 1) by:8 do:[:dstRow | |
|
550 |
dstOffset := dstRow * width + 1. |
|
551 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
|
552 |
with:data startingAt:srcOffset. |
|
553 |
srcOffset := srcOffset + width. |
|
554 |
]. |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
555 |
|
882 | 556 |
"phase 2: 4, 12, 20, 28, ..." |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
557 |
|
882 | 558 |
4 to:(h - 1) by:8 do:[:dstRow | |
559 |
dstOffset := dstRow * width + 1. |
|
560 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
|
561 |
with:data startingAt:srcOffset. |
|
562 |
srcOffset := srcOffset + width. |
|
563 |
]. |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
564 |
|
882 | 565 |
"phase 3: 2, 6, 10, 14, ..." |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
566 |
|
882 | 567 |
2 to:(h - 1) by:4 do:[:dstRow | |
568 |
dstOffset := dstRow * width + 1. |
|
569 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
|
570 |
with:data startingAt:srcOffset. |
|
571 |
srcOffset := srcOffset + width. |
|
572 |
]. |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
573 |
|
882 | 574 |
"phase 4: 1, 3, 5, 7, ..." |
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
575 |
|
882 | 576 |
1 to:(h - 1) by:2 do:[:dstRow | |
577 |
dstOffset := dstRow * width + 1. |
|
578 |
tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
|
579 |
with:data startingAt:srcOffset. |
|
580 |
srcOffset := srcOffset + width. |
|
581 |
]. |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
582 |
|
882 | 583 |
data := tmp. |
584 |
tmp := nil. |
|
757
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
585 |
]. |
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
586 |
|
094c6c7c4ce6
extracted raw image reading (i.e. after header & extensions have been read)
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
587 |
"Created: / 13.1.1998 / 10:44:05 / cg" |
1037
90d38c8e3f5f
use initialized byteArrays, in case rows are padded
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
588 |
"Modified: / 12.8.1998 / 13:55:32 / cg" |
0 | 589 |
! ! |
43 | 590 |
|
1805 | 591 |
!GIFReader methodsFor:'private-writing'! |
592 |
||
593 |
assignTransparentPixelIn:image |
|
594 |
"find an usused pixelValue in the colorMap (or image)." |
|
595 |
||
2056
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
596 |
|cmap usedPixelValues unusedValues| |
1805 | 597 |
|
598 |
(cmap := image colorMap) size > 0 ifTrue:[ |
|
2056
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
599 |
cmap size < 256 ifTrue:[ |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
600 |
maskPixel := cmap size. |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
601 |
^ self |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
602 |
] |
1805 | 603 |
]. |
3009 | 604 |
image compressColorMap. |
1805 | 605 |
usedPixelValues := image usedValues. |
2056
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
606 |
usedPixelValues size < (1 bitShift:image depth) ifFalse:[ |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
607 |
Image informationLostQuerySignal |
3009 | 608 |
raiseRequestWith:image |
2056
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
609 |
errorString:('GIF writer cannot assign a transparent pixel - all pixelValues used by image'). |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
610 |
]. |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
611 |
|
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
612 |
"/ there must be an unused pixelValue |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
613 |
unusedValues := (0 to:(1 bitShift:image depth)-1) asSet. |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
614 |
unusedValues removeAll:usedPixelValues. |
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
615 |
|
b7eea50081f2
fixed transparency-pixel bug (with full colormap)
Claus Gittinger <cg@exept.de>
parents:
2032
diff
changeset
|
616 |
maskPixel := unusedValues first. |
3009 | 617 |
|
618 |
"Modified: / 17-07-2012 / 12:25:24 / anwild" |
|
1805 | 619 |
! |
620 |
||
621 |
checkCodeSize |
|
622 |
(freeCode > maxCode and: [codeSize < 12]) |
|
623 |
ifTrue: |
|
624 |
[codeSize := codeSize + 1. |
|
625 |
maxCode := (1 bitShift: codeSize) - 1] |
|
626 |
||
627 |
"Created: 14.10.1997 / 18:42:01 / cg" |
|
628 |
! |
|
629 |
||
630 |
flushBits |
|
631 |
remainBitCount = 0 |
|
632 |
ifFalse: |
|
633 |
[self nextBytePut: bufByte. |
|
634 |
remainBitCount := 0]. |
|
635 |
self flushBuffer |
|
636 |
||
637 |
"Modified: 14.10.1997 / 18:58:06 / cg" |
|
638 |
! |
|
639 |
||
640 |
flushBuffer |
|
641 |
bufStream isEmpty ifTrue: [^ self]. |
|
642 |
outStream nextPut: bufStream size. |
|
643 |
outStream nextPutAll: bufStream contents. |
|
644 |
bufStream := WriteStream on: (ByteArray new: 256) |
|
645 |
||
646 |
"Modified: 14.10.1997 / 20:46:04 / cg" |
|
647 |
! |
|
648 |
||
649 |
flushCode |
|
650 |
self flushBits |
|
651 |
||
652 |
"Created: 14.10.1997 / 18:57:33 / cg" |
|
653 |
! |
|
654 |
||
655 |
nextBitsPut: anInteger |
|
656 |
| integer writeBitCount shiftCount | |
|
657 |
shiftCount := 0. |
|
658 |
remainBitCount = 0 |
|
659 |
ifTrue: |
|
660 |
[writeBitCount := 8. |
|
661 |
integer := anInteger] |
|
662 |
ifFalse: |
|
663 |
[writeBitCount := remainBitCount. |
|
664 |
integer := bufByte + (anInteger bitShift: 8 - remainBitCount)]. |
|
665 |
[writeBitCount < codeSize] |
|
666 |
whileTrue: |
|
667 |
[self nextBytePut: ((integer bitShift: shiftCount) bitAnd: 255). |
|
668 |
shiftCount := shiftCount - 8. |
|
669 |
writeBitCount := writeBitCount + 8]. |
|
670 |
(remainBitCount := writeBitCount - codeSize) = 0 |
|
671 |
ifTrue: [self nextBytePut: (integer bitShift: shiftCount)] |
|
672 |
ifFalse: [bufByte := integer bitShift: shiftCount]. |
|
673 |
^anInteger |
|
674 |
||
675 |
"Modified: 15.10.1997 / 16:50:30 / cg" |
|
676 |
! |
|
677 |
||
678 |
nextBytePut: aByte |
|
679 |
bufStream nextPut: aByte. |
|
680 |
bufStream size >= 254 ifTrue: [self flushBuffer] |
|
681 |
||
682 |
"Modified: 15.10.1997 / 16:50:52 / cg" |
|
683 |
! |
|
684 |
||
685 |
readPixelFrom: bits |
|
686 |
| pixel | |
|
687 |
ypos >= height ifTrue: [^ nil]. |
|
688 |
(maskPixel notNil |
|
689 |
and:[(mask pixelAtX:xpos y:ypos) == 0]) ifTrue:[ |
|
690 |
pixel := maskPixel |
|
691 |
] ifFalse:[ |
|
692 |
pixel := bits at: ypos * rowByteSize + xpos + 1. |
|
693 |
]. |
|
694 |
self updatePixelPosition. |
|
695 |
^ pixel |
|
696 |
||
697 |
"Created: 14.10.1997 / 18:43:50 / cg" |
|
698 |
"Modified: 15.10.1997 / 16:46:43 / cg" |
|
699 |
! |
|
700 |
||
701 |
setParameters:bitsPerPixel |
|
702 |
clearCode := 1 bitShift:bitsPerPixel. |
|
703 |
eoiCode := clearCode + 1. |
|
704 |
freeCode := clearCode + 2. |
|
705 |
codeSize := bitsPerPixel + 1. |
|
706 |
maxCode := (1 bitShift: codeSize) - 1 |
|
707 |
||
708 |
"Modified: 14.10.1997 / 20:09:48 / cg" |
|
709 |
! |
|
710 |
||
711 |
updatePixelPosition |
|
712 |
(xpos := xpos + 1) >= width ifFalse: [^ self]. |
|
713 |
||
714 |
xpos := 0. |
|
715 |
interlace == true ifFalse:[ |
|
716 |
ypos := ypos + 1. |
|
717 |
^ self |
|
718 |
]. |
|
719 |
||
720 |
pass == 0 ifTrue:[ |
|
721 |
(ypos := ypos + 8) >= height ifTrue:[ |
|
722 |
pass := pass + 1. |
|
723 |
ypos := 4 |
|
724 |
]. |
|
725 |
^ self |
|
726 |
]. |
|
727 |
pass == 1 ifTrue:[ |
|
728 |
(ypos := ypos + 8) >= height ifTrue:[ |
|
729 |
pass := pass + 1. |
|
730 |
ypos := 2 |
|
731 |
]. |
|
732 |
^ self |
|
733 |
]. |
|
734 |
pass == 2 ifTrue:[ |
|
735 |
(ypos := ypos + 4) >= height ifTrue:[ |
|
736 |
pass := pass + 1. |
|
737 |
ypos := 1 |
|
738 |
]. |
|
739 |
^ self |
|
740 |
]. |
|
741 |
pass == 3 ifTrue:[ |
|
742 |
ypos := ypos + 2. |
|
743 |
^ self |
|
744 |
]. |
|
745 |
^ self error: 'can''t happen' |
|
746 |
||
747 |
"Modified: 14.10.1997 / 18:44:27 / cg" |
|
748 |
! |
|
749 |
||
2032 | 750 |
writeBitDataFor: image |
751 |
"using modified Lempel-Ziv Welch algorithm." |
|
752 |
||
753 |
| bits bitsPerPixel t1 |
|
754 |
maxBits maxMaxCode tSize initCodeSize ent tShift fCode pixel index disp nomatch | |
|
755 |
||
756 |
outStream nextPut:ImageSeparator. |
|
3282 | 757 |
self writeShort:0. "/ leftOffs |
758 |
self writeShort:0. "/ topOffs |
|
2032 | 759 |
self writeShort:width. "/ image size |
760 |
self writeShort:height. |
|
761 |
||
762 |
interlace == true ifTrue:[ |
|
763 |
t1 := 64 |
|
764 |
] ifFalse:[ |
|
3282 | 765 |
t1 := 0 "/ no local colormap |
2032 | 766 |
]. |
767 |
outStream nextPut:t1. "/ another flag |
|
768 |
||
769 |
bitsPerPixel := image bitsPerPixel. |
|
770 |
bits := image bits. |
|
771 |
||
772 |
pass := 0. |
|
773 |
xpos := 0. |
|
774 |
ypos := 0. |
|
775 |
rowByteSize := image bytesPerRow. "/ width * 8 + 31 // 32 * 4. |
|
776 |
remainBitCount := 0. |
|
777 |
bufByte := 0. |
|
778 |
bufStream := WriteStream on: (ByteArray new: 256). |
|
779 |
||
780 |
maxBits := 12. |
|
781 |
maxMaxCode := 1 bitShift: maxBits. |
|
782 |
tSize := 5003. |
|
783 |
prefixTable := Array new: tSize. |
|
784 |
suffixTable := Array new: tSize. |
|
785 |
||
786 |
initCodeSize := bitsPerPixel <= 1 ifTrue: [2] ifFalse: [bitsPerPixel]. |
|
787 |
outStream nextPut: initCodeSize. |
|
788 |
self setParameters: initCodeSize. |
|
789 |
||
790 |
tShift := 0. |
|
791 |
fCode := tSize. |
|
2845
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
792 |
[fCode < 65536] whileTrue:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
793 |
tShift := tShift + 1. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
794 |
fCode := fCode * 2 |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
795 |
]. |
2032 | 796 |
tShift := 8 - tShift. |
797 |
1 to: tSize do: [:i | suffixTable at: i put: -1]. |
|
798 |
||
799 |
self writeCodeAndCheckCodeSize: clearCode. |
|
800 |
ent := self readPixelFrom: bits. |
|
2845
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
801 |
[(pixel := self readPixelFrom: bits) == nil] whileFalse:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
802 |
fCode := (pixel bitShift: maxBits) + ent. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
803 |
index := ((pixel bitShift: tShift) bitXor: ent) + 1. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
804 |
(suffixTable at: index) = fCode |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
805 |
ifTrue: [ent := prefixTable at: index] |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
806 |
ifFalse:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
807 |
nomatch := true. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
808 |
(suffixTable at: index) >= 0 |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
809 |
ifTrue:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
810 |
disp := tSize - index + 1. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
811 |
index = 1 ifTrue: [disp := 1]. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
812 |
"probe" |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
813 |
[(index := index - disp) < 1 ifTrue: [index := index + tSize]. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
814 |
(suffixTable at: index) = fCode |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
815 |
ifTrue:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
816 |
ent := prefixTable at: index. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
817 |
nomatch := false. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
818 |
"continue whileFalse:"]. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
819 |
nomatch and: [(suffixTable at: index) > 0]] |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
820 |
whileTrue: ["probe"]]. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
821 |
"nomatch" |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
822 |
nomatch ifTrue:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
823 |
self writeCodeAndCheckCodeSize: ent. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
824 |
ent := pixel. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
825 |
freeCode < maxMaxCode |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
826 |
ifTrue:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
827 |
prefixTable at: index put: freeCode. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
828 |
suffixTable at: index put: fCode. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
829 |
freeCode := freeCode + 1] |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
830 |
ifFalse:[ |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
831 |
self writeCodeAndCheckCodeSize: clearCode. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
832 |
1 to: tSize do: [:i | suffixTable at: i put: -1]. |
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
833 |
self setParameters: initCodeSize]]]]. |
2032 | 834 |
prefixTable := suffixTable := nil. |
835 |
self writeCodeAndCheckCodeSize: ent. |
|
836 |
self writeCodeAndCheckCodeSize: eoiCode. |
|
837 |
self flushCode. |
|
838 |
outStream nextPut: 0. "zero-length packet" |
|
839 |
||
2845
62d4128bb923
comment/format in: #writeBitDataFor:
Claus Gittinger <cg@exept.de>
parents:
2844
diff
changeset
|
840 |
"Modified: / 02-06-2010 / 12:24:20 / cg" |
2032 | 841 |
! |
842 |
||
1805 | 843 |
writeCode: aCode |
844 |
self nextBitsPut: aCode |
|
845 |
||
846 |
"Created: 14.10.1997 / 18:38:35 / cg" |
|
847 |
"Modified: 15.10.1997 / 17:01:47 / cg" |
|
848 |
! |
|
849 |
||
850 |
writeCodeAndCheckCodeSize: t1 |
|
851 |
self writeCode: t1. |
|
852 |
self checkCodeSize |
|
853 |
||
854 |
"Created: 14.10.1997 / 18:38:24 / cg" |
|
855 |
"Modified: 14.10.1997 / 18:40:56 / cg" |
|
2032 | 856 |
! |
857 |
||
858 |
writeHeaderFor:image |
|
859 |
"write the gif header" |
|
860 |
||
861 |
|bitsPerPixel t1| |
|
862 |
||
863 |
bitsPerPixel := image bitsPerPixel. |
|
864 |
||
865 |
outStream nextPutAll: 'GIF89a' asByteArray. |
|
866 |
self writeShort:width. "/ screen size |
|
867 |
self writeShort:height. |
|
868 |
t1 := 128. |
|
869 |
t1 := t1 bitOr:(bitsPerPixel - 1 bitShift:5). |
|
870 |
t1 := t1 bitOr:(bitsPerPixel - 1). |
|
871 |
outStream nextPut:t1. "/ flag |
|
872 |
outStream nextPut:0. "/ background (not used) |
|
873 |
outStream nextPut:0. "/ aspect ratio |
|
874 |
||
875 |
0 to:(1 bitShift:bitsPerPixel)-1 do:[:pixel | |
|
876 |
|clr red green blue| |
|
877 |
||
878 |
clr := image colorFromValue:pixel. |
|
879 |
clr isNil ifTrue:[ |
|
880 |
"/ unused colorMap slot |
|
881 |
red := green := blue := 0. |
|
882 |
] ifFalse:[ |
|
883 |
red := (clr redByte). |
|
884 |
green := (clr greenByte). |
|
885 |
blue := (clr blueByte). |
|
886 |
]. |
|
887 |
outStream |
|
888 |
nextPut:red; nextPut:green; nextPut:blue. |
|
889 |
]. |
|
890 |
||
891 |
"Created: / 14.10.1997 / 17:41:28 / cg" |
|
892 |
"Modified: / 31.10.1997 / 16:12:13 / cg" |
|
893 |
! |
|
894 |
||
895 |
writeMaskExtensionHeaderFor:image |
|
896 |
"write an extension header for the transparent pixel" |
|
897 |
||
898 |
outStream nextPut:Extension. |
|
899 |
outStream nextPut:16rF9. "/ graphic control extension |
|
900 |
outStream nextPut:4. "/ subBlockSize |
|
901 |
||
902 |
outStream nextPut:1. "/ animationType |
|
903 |
outStream nextPutShort:1 MSB:false. "/ animationTime |
|
904 |
outStream nextPut:maskPixel. "/ animationMask |
|
905 |
||
906 |
outStream nextPut:0. |
|
1805 | 907 |
! ! |
908 |
||
708 | 909 |
!GIFReader methodsFor:'writing to file'! |
910 |
||
911 |
save:image onFile:aFileName |
|
912 |
"save image as GIF file on aFileName" |
|
913 |
||
1813
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1811
diff
changeset
|
914 |
|convertedImage| |
1206
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
915 |
|
718
41ade132da98
raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents:
714
diff
changeset
|
916 |
image depth ~~ 8 ifTrue:[ |
3119 | 917 |
Error handle:[:ex | |
1811 | 918 |
^ Image cannotRepresentImageSignal |
919 |
raiseWith:image |
|
920 |
errorString:('GIF failed to convert image to depth8: ', ex description). |
|
921 |
"/ ex return. |
|
1393
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
922 |
] do:[ |
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
923 |
convertedImage := Image newForDepth:8. |
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
924 |
convertedImage fromImage:image photometric:#palette. |
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
925 |
]. |
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
926 |
convertedImage notNil ifTrue:[ |
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
927 |
^ self save:convertedImage onFile:aFileName |
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
928 |
]. |
1206
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
929 |
^ Image cannotRepresentImageSignal |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
930 |
raiseWith:image |
1393
abed635fb3ce
convert non-depth8 images when trying to save
Claus Gittinger <cg@exept.de>
parents:
1313
diff
changeset
|
931 |
errorString:('GIF (currently) only supports depth8 images (cannot convert)'). |
718
41ade132da98
raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents:
714
diff
changeset
|
932 |
]. |
41ade132da98
raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents:
714
diff
changeset
|
933 |
|
1813
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1811
diff
changeset
|
934 |
super save:image onFile:aFileName. |
1206
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
935 |
|
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
936 |
" |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
937 |
|i| |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
938 |
|
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
939 |
i := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
940 |
GIFReader save:i onFile:'foo.gif'. |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
941 |
(Image fromFile:'./foo.gif') inspect |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
942 |
" |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
943 |
|
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
944 |
"Created: / 14.10.1997 / 17:40:12 / cg" |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
945 |
"Modified: / 27.10.1997 / 22:42:31 / cg" |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
946 |
! |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
947 |
|
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
948 |
save:image onStream:aStream |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
949 |
"save image in GIF-file-format onto aStream" |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
950 |
|
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
951 |
image depth ~~ 8 ifTrue:[ |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
952 |
^ Image cannotRepresentImageSignal |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
953 |
raiseWith:image |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
954 |
errorString:('GIF (currently) only supports depth8 images'). |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
955 |
]. |
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
956 |
|
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
957 |
outStream := aStream. |
708 | 958 |
outStream binary. |
959 |
||
714 | 960 |
mask := image mask. |
961 |
mask notNil ifTrue:[ |
|
1206
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
962 |
self assignTransparentPixelIn:image |
708 | 963 |
]. |
964 |
||
965 |
byteOrder := #lsb. |
|
966 |
width := image width. |
|
967 |
height := image height. |
|
968 |
photometric := image photometric. |
|
969 |
samplesPerPixel := image samplesPerPixel. |
|
970 |
bitsPerSample := image bitsPerSample. |
|
971 |
colorMap := image colorMap. |
|
972 |
data := image bits. |
|
973 |
||
974 |
self writeHeaderFor:image. |
|
714 | 975 |
maskPixel notNil ifTrue:[ |
1206
fe2354feee01
separated image writer for stream writing
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
976 |
self writeMaskExtensionHeaderFor:image. |
714 | 977 |
]. |
978 |
||
708 | 979 |
self writeBitDataFor:image. |
714 | 980 |
|
3282 | 981 |
image imageSequence notEmptyOrNil ifTrue:[ |
982 |
image imageSequence do:[:eachFrame | |
|
983 |
outStream nextPut:Extension. |
|
984 |
outStream nextPut:16rF9. "/ graphic control extension |
|
985 |
outStream nextPut:4. "/ sub block size |
|
986 |
outStream nextPut:0. "/ animation type 0 |
|
987 |
outStream nextPutShort:(eachFrame delay / 10) rounded asInteger MSB:false. |
|
988 |
outStream nextPut:0. "/ animation mask |
|
989 |
outStream nextPut:0. "/ subblock size |
|
990 |
||
991 |
self writeBitDataFor:eachFrame image. |
|
992 |
||
993 |
]. |
|
994 |
]. |
|
995 |
||
714 | 996 |
outStream nextPut: Terminator. |
708 | 997 |
|
998 |
" |
|
999 |
|i| |
|
1000 |
||
1001 |
i := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
|
1002 |
GIFReader save:i onFile:'foo.gif'. |
|
1003 |
(Image fromFile:'./foo.gif') inspect |
|
1004 |
" |
|
1005 |
||
718
41ade132da98
raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents:
714
diff
changeset
|
1006 |
"Created: / 14.10.1997 / 17:40:12 / cg" |
41ade132da98
raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents:
714
diff
changeset
|
1007 |
"Modified: / 27.10.1997 / 22:42:31 / cg" |
708 | 1008 |
! ! |
1009 |
||
339 | 1010 |
!GIFReader class methodsFor:'documentation'! |
135 | 1011 |
|
1012 |
version |
|
3282 | 1013 |
^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.102 2014-02-14 00:23:38 cg Exp $' |
2844 | 1014 |
! |
1015 |
||
1016 |
version_CVS |
|
3282 | 1017 |
^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.102 2014-02-14 00:23:38 cg Exp $' |
135 | 1018 |
! ! |
1711
b3ba13167ee7
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1521
diff
changeset
|
1019 |
|
3119 | 1020 |
|
43 | 1021 |
GIFReader initialize! |