--- a/GIFReader.st Tue Mar 31 11:42:45 1998 +0200
+++ b/GIFReader.st Wed Apr 01 14:17:37 1998 +0200
@@ -308,7 +308,7 @@
!
fromStream:aStream
- "read a stream containing a GIF image.
+ "read a stream containing a GIF image (or an image sequence).
Leave image description in instance variables."
|byte index flag count fileColorMap
@@ -408,7 +408,7 @@
self buildMaskFromColor:maskPixel
].
- imageSequence add:(self image).
+ imageSequence add:(self makeImage).
aStream atEnd ifTrue:[
atEnd := true.
@@ -418,7 +418,7 @@
].
"Modified: / 5.7.1996 / 17:32:01 / stefan"
- "Modified: / 3.2.1998 / 17:53:37 / cg"
+ "Modified: / 1.4.1998 / 14:17:26 / cg"
!
makeGreyscale
@@ -445,7 +445,7 @@
!
readExtension:aStream
- "get gif89 extension - this is currently ignored"
+ "get gif89 extension"
|type blockSize subBlockSize
aspNum aspDen left top width height cWidth cHeight fg bg
@@ -455,127 +455,127 @@
type := aStream nextByte.
type == $R asciiValue ifTrue:[
- "/
- "/ Ratio extension
- "/
- 'GIFREADER [info]: ratio extension ignored' infoPrintCR.
- blockSize := aStream nextByte.
- (blockSize == 2) ifTrue:[
- aspNum := aStream nextByte.
- aspDen := aStream nextByte
- ] ifFalse:[
- aStream skip:blockSize
- ].
- "/ eat subblocks
+ "/
+ "/ Ratio extension
+ "/
+ 'GIFREADER [info]: ratio extension ignored' infoPrintCR.
+ blockSize := aStream nextByte.
+ (blockSize == 2) ifTrue:[
+ aspNum := aStream nextByte.
+ aspDen := aStream nextByte
+ ] ifFalse:[
+ aStream skip:blockSize
+ ].
+ "/ eat subblocks
- [(subBlockSize := aStream nextByte) > 0] whileTrue:[
- aStream skip:subBlockSize
- ].
- ^ self
+ [(subBlockSize := aStream nextByte) > 0] whileTrue:[
+ aStream skip:subBlockSize
+ ].
+ ^ self
].
type == 16r01 ifTrue:[
- "/
- "/ plaintext extension
- "/
+ "/
+ "/ plaintext extension
+ "/
"/ 'GIFREADER [info]: plaintext extension ignored' infoPrintCR.
- subBlockSize := aStream nextByte.
- left := aStream nextShortMSB:false.
- top := aStream nextShortMSB:false.
- width := aStream nextShortMSB:false.
- height := aStream nextShortMSB:false.
- cWidth := aStream nextByte.
- cHeight := aStream nextByte.
- fg := aStream nextByte.
- bg := aStream nextByte.
- aStream skip:12.
- [(subBlockSize := aStream nextByte) > 0] whileTrue:[
- aStream skip:subBlockSize
- ].
- ^ self
+ subBlockSize := aStream nextByte.
+ left := aStream nextShortMSB:false.
+ top := aStream nextShortMSB:false.
+ width := aStream nextShortMSB:false.
+ height := aStream nextShortMSB:false.
+ cWidth := aStream nextByte.
+ cHeight := aStream nextByte.
+ fg := aStream nextByte.
+ bg := aStream nextByte.
+ aStream skip:12.
+ [(subBlockSize := aStream nextByte) > 0] whileTrue:[
+ aStream skip:subBlockSize
+ ].
+ ^ self
].
type == 16rF9 ifTrue:[
- "/
- "/ graphic control extension
- "/
+ "/
+ "/ graphic control extension
+ "/
"/ 'GIFREADER [info]: graphic control extension ignored' infoPrintCR.
- [(subBlockSize := aStream nextByte) ~~ 0] whileTrue:[
- "/ type bitAnd:1 means: animationMask is transparent pixel
- "/ to be implemented in Image ...
+ [(subBlockSize := aStream nextByte) ~~ 0] whileTrue:[
+ "/ type bitAnd:1 means: animationMask is transparent pixel
+ "/ to be implemented in Image ...
- animationType := aStream nextByte.
- animationTime := aStream nextShortMSB:false.
- animationMask := aStream nextByte.
- subBlockSize := subBlockSize - 4.
+ animationType := aStream nextByte.
+ animationTime := aStream nextShortMSB:false.
+ animationMask := aStream nextByte.
+ subBlockSize := subBlockSize - 4.
- (animationType bitTest: 1) ifTrue:[
- maskPixel := animationMask.
+ (animationType bitTest: 1) ifTrue:[
+ maskPixel := animationMask.
"/ 'GIFREADER [info]: mask: ' infoPrint. (maskPixel printStringRadix:16) infoPrintCR.
- ].
+ ].
"/ 'GIFREADER [info]: animationTime: ' infoPrint. (animationTime * (1/100)) infoPrintCR.
- subBlockSize ~~ 0 ifTrue:[
- aStream skip:subBlockSize
- ].
- ].
- ^ self
+ subBlockSize ~~ 0 ifTrue:[
+ aStream skip:subBlockSize
+ ].
+ ].
+ ^ self
].
type == 16rFE ifTrue:[
- "/
- "/ comment extension
- "/
+ "/
+ "/ comment extension
+ "/
"/ 'GIFREADER [info]: comment extension ignored' infoPrintCR.
- [(blockSize := aStream nextByte) ~~ 0] whileTrue:[
- aStream skip:blockSize
- ].
- ^ self
+ [(blockSize := aStream nextByte) ~~ 0] whileTrue:[
+ aStream skip:blockSize
+ ].
+ ^ self
].
type == 16rFF ifTrue:[
- "/
- "/ application extension
- "/
- subBlockSize := aStream nextByte.
- appID := (aStream nextBytes:8 ) asString.
- appAUTH := aStream nextBytes:3.
+ "/
+ "/ application extension
+ "/
+ subBlockSize := aStream nextByte.
+ appID := (aStream nextBytes:8 ) asString.
+ appAUTH := aStream nextBytes:3.
- subBlockSize := aStream nextByte.
+ subBlockSize := aStream nextByte.
- ok := false.
- appID = 'NETSCAPE' ifTrue:[
- appAUTH asString = '2.0' ifTrue:[
- subBlockSize == 3 ifTrue:[
- b := aStream nextByte.
- iterationCount := aStream nextShortMSB:false.
- subBlockSize := aStream nextByte.
- ok := true.
- ]
- ]
- ].
+ ok := false.
+ appID = 'NETSCAPE' ifTrue:[
+ appAUTH asString = '2.0' ifTrue:[
+ subBlockSize == 3 ifTrue:[
+ b := aStream nextByte.
+ iterationCount := aStream nextShortMSB:false.
+ subBlockSize := aStream nextByte.
+ ok := true.
+ ]
+ ]
+ ].
- ok ifFalse:[
- ('GIFREADER [info]: application extension (' , appID , ') ignored') infoPrintCR.
- ].
+ ok ifFalse:[
+ ('GIFREADER [info]: application extension (' , appID , ') ignored') infoPrintCR.
+ ].
- [subBlockSize > 0] whileTrue:[
- aStream skip:subBlockSize.
- subBlockSize := aStream nextByte.
- ].
- ^ self
+ [subBlockSize > 0] whileTrue:[
+ aStream skip:subBlockSize.
+ subBlockSize := aStream nextByte.
+ ].
+ ^ self
].
type == 16r2C ifTrue:[
- "/
- "/ image descriptor extension
- "/
- 'GIFREADER [info]: image descriptor extension ignored' infoPrintCR.
- [(subBlockSize := aStream nextByte) > 0] whileTrue:[
- aStream skip:subBlockSize
- ].
- ^ self
+ "/
+ "/ image descriptor extension
+ "/
+ 'GIFREADER [info]: image descriptor extension ignored' infoPrintCR.
+ [(subBlockSize := aStream nextByte) > 0] whileTrue:[
+ aStream skip:subBlockSize
+ ].
+ ^ self
].
"/
@@ -583,13 +583,15 @@
"/
'GIFREADER [info]: unknown extension ignored' infoPrintCR.
[(subBlockSize := aStream nextByte) > 0] whileTrue:[
- aStream skip:subBlockSize
+ aStream skip:subBlockSize
]
- "Modified: 24.7.1997 / 18:02:49 / cg"
+ "Modified: / 1.4.1998 / 14:00:37 / cg"
!
readImage:aStream
+ "read a single image from aStream."
+
|leftOffs topOffs flag interlaced hasLocalColorMap bitsPerPixel colorMapSize
codeLen compressedData compressedSize index count h tmp srcOffset dstOffset
initialBuffSize|
@@ -601,7 +603,7 @@
height := aStream nextShortMSB:false.
dimensionCallBack notNil ifTrue:[
- dimensionCallBack value:self
+ dimensionCallBack value:self
].
"/
@@ -618,24 +620,24 @@
"if image has a local colormap, this one is used"
hasLocalColorMap ifTrue:[
- "local descr. overwrites"
- bitsPerPixel := (flag bitAnd:2r00000111) + 1.
- colorMapSize := 1 bitShift:bitsPerPixel.
- "overwrite colormap"
- self readColorMap:colorMapSize.
- colorMap := Colormap
- redVector:redMap
- greenVector:greenMap
- blueVector:blueMap.
+ "local descr. overwrites"
+ bitsPerPixel := (flag bitAnd:2r00000111) + 1.
+ colorMapSize := 1 bitShift:bitsPerPixel.
+ "overwrite colormap"
+ self readColorMap:colorMapSize.
+ colorMap := Colormap
+ redVector:redMap
+ greenVector:greenMap
+ blueVector:blueMap.
].
"get codelen for decompression"
codeLen := aStream nextByte.
(aStream respondsTo:#fileSize) ifTrue:[
- initialBuffSize := aStream fileSize.
+ initialBuffSize := aStream fileSize.
] ifFalse:[
- initialBuffSize := 512.
+ initialBuffSize := 512.
].
compressedData := ByteArray uninitializedNew:initialBuffSize.
@@ -651,9 +653,9 @@
compressedData := t.
].
- aStream nextBytes:count into:compressedData startingAt:index blockSize:4096.
- index := index + count.
- count := aStream nextByte
+ aStream nextBytes:count into:compressedData startingAt:index blockSize:4096.
+ index := index + count.
+ count := aStream nextByte
].
compressedSize := index - 1.
@@ -662,58 +664,58 @@
"/ 'GIFReader: decompressing ...' infoPrintCR.
self class decompressGIFFrom:compressedData
- count:compressedSize
- into:data
- startingAt:1
- codeLen:(codeLen + 1).
+ count:compressedSize
+ into:data
+ startingAt:1
+ codeLen:(codeLen + 1).
interlaced ifTrue:[
"/ 'GIFREADER: deinterlacing ...' infoPrintCR.
- tmp := ByteArray uninitializedNew:(data size).
+ tmp := ByteArray uninitializedNew:(data size).
- "phase 1: 0, 8, 16, 24, ..."
+ "phase 1: 0, 8, 16, 24, ..."
- srcOffset := 1.
- 0 to:(h - 1) by:8 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
+ srcOffset := 1.
+ 0 to:(h - 1) by:8 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
- "phase 2: 4, 12, 20, 28, ..."
+ "phase 2: 4, 12, 20, 28, ..."
- 4 to:(h - 1) by:8 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
+ 4 to:(h - 1) by:8 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
- "phase 3: 2, 6, 10, 14, ..."
+ "phase 3: 2, 6, 10, 14, ..."
- 2 to:(h - 1) by:4 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
+ 2 to:(h - 1) by:4 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
- "phase 4: 1, 3, 5, 7, ..."
+ "phase 4: 1, 3, 5, 7, ..."
- 1 to:(h - 1) by:2 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
+ 1 to:(h - 1) by:2 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
- data := tmp.
- tmp := nil.
+ data := tmp.
+ tmp := nil.
].
- "Modified: / 13.1.1998 / 10:41:05 / cg"
"Created: / 13.1.1998 / 10:44:05 / cg"
+ "Modified: / 1.4.1998 / 14:00:27 / cg"
! !
!GIFReader methodsFor:'writing to file'!
@@ -939,6 +941,6 @@
!GIFReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.67 1998-02-03 16:54:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.68 1998-04-01 12:17:37 cg Exp $'
! !
GIFReader initialize!