--- a/WindowsIconReader.st Sun Feb 04 16:35:54 1996 +0100
+++ b/WindowsIconReader.st Sun Feb 04 18:12:12 1996 +0100
@@ -34,7 +34,7 @@
!
version
- ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.19 1995-11-11 16:05:34 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.20 1996-02-04 17:12:12 cg Exp $'
!
documentation
@@ -101,39 +101,60 @@
!WindowsIconReader methodsFor:'private'!
loadBMPWidth:w height:h depth:d compression:c from:aStream into:data
+ |buff idx1 idx2 bytesPerRow|
+
d == 8 ifTrue:[
(self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
'BMP: read/decompression failed' errorPrintNL.
^ false
- ]
- ] ifFalse:[
- d == 4 ifTrue:[
- (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
- 'BMP: read/decompression failed' errorPrintNL.
- ^ false
- ]
- ] ifFalse:[
- d == 2 ifTrue:[
- (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
- 'BMP: read failed' errorPrintNL.
- ^ false
- ]
- ] ifFalse:[
- d == 1 ifTrue:[
- (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
- 'BMP: read failed' errorPrintNL.
- ^ false
- ]
- ] ifFalse:[
- 'BMP: unsupported depth:' errorPrint. d errorPrintNL.
- ^ false
- ]
- ]
- ]
+ ].
+ ^ true
+ ].
+ d == 4 ifTrue:[
+ (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
+ 'BMP: read/decompression failed' errorPrintNL.
+ ^ false
+ ].
+ ^ true
+ ].
+ d == 2 ifTrue:[
+ (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
+ 'BMP: read failed' errorPrintNL.
+ ^ false
+ ].
+ ^ true
].
- ^ true
+ d == 1 ifTrue:[
+ (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
+ 'BMP: read failed' errorPrintNL.
+ ^ false
+ ].
+ ^ true
+ ].
+ d == 24 ifTrue:[
+ bytesPerRow := w * 3.
+ ((aStream nextBytes:(h * bytesPerRow) into:data) ~~ (h * bytesPerRow)) ifTrue:[
+ 'BMP: read failed' errorPrintNL.
+ ^ false
+ ].
+ "/ stupid - last row comes first
+
+ buff := ByteArray uninitializedNew:bytesPerRow.
+ idx1 := 1.
+ idx2 := 1 + (h-1 * bytesPerRow).
+ [idx1 < idx2] whileTrue:[
+ buff replaceFrom:1 to:bytesPerRow with:data startingAt:idx1.
+ data replaceFrom:idx1 to:(idx1 + bytesPerRow - 1) with:data startingAt:idx2.
+ data replaceFrom:idx2 to:(idx2 + bytesPerRow - 1) with:buff startingAt:1.
+ idx1 := idx1 + bytesPerRow.
+ idx2 := idx2 - bytesPerRow.
+ ].
+ ^ true
+ ].
+ 'BMP: unsupported depth:' errorPrint. d errorPrintNL.
"Created: 17.9.1995 / 18:48:11 / claus"
+ "Modified: 4.2.1996 / 18:04:44 / cg"
! !
!WindowsIconReader methodsFor:'reading from file'!
@@ -297,12 +318,17 @@
"
some bmp-writers seem to leave this as zero (which is wrong)
"
- numColor := 1 bitShift:inDepth.
- 'BMP: missing nColor in header - assume ' errorPrint. numColor errorPrintNL
+ inDepth <= 8 ifTrue:[
+ numColor := 1 bitShift:inDepth.
+ 'BMP: missing nColor in header - assume ' errorPrint. numColor errorPrintNL
+ ]
].
- rawMap := ByteArray uninitializedNew:(numColor * 4).
- aStream nextBytes:(numColor * 4) into:rawMap.
- fourBytesPerColorInfo := true.
+
+ numColor ~~ 0 ifTrue:[
+ rawMap := ByteArray uninitializedNew:(numColor * 4).
+ aStream nextBytes:(numColor * 4) into:rawMap.
+ fourBytesPerColorInfo := true.
+ ].
dataStart := header wordAt:(16r0A + 1) MSB:false
] ifFalse:[
((header at:(16r0E + 1)) == 12) ifTrue:[ "core-info header size"
@@ -328,22 +354,24 @@
].
].
- "read the colormap"
+ numColor ~~ 0 ifTrue:[
+ "read the colormap"
- rMap := Array new:numColor.
- gMap := Array new:numColor.
- bMap := Array new:numColor.
- srcIndex := 1.
- 1 to:numColor do:[:i |
- bMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- gMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- rMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- fourBytesPerColorInfo ifTrue:[
+ rMap := Array new:numColor.
+ gMap := Array new:numColor.
+ bMap := Array new:numColor.
+ srcIndex := 1.
+ 1 to:numColor do:[:i |
+ bMap at:i put:(rawMap at:srcIndex).
srcIndex := srcIndex + 1.
- ]
+ gMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ rMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ fourBytesPerColorInfo ifTrue:[
+ srcIndex := srcIndex + 1.
+ ]
+ ].
].
"/ "
@@ -396,14 +424,14 @@
"/ some compression
compression == 1 ifTrue:[
"/ RLE8 - must be depth-8
- inDepth == 8 ifFalse:[
+ inDepth ~~ 8 ifTrue:[
'BMP: RLE8 compression only allowed with depth8 images' errorPrintNL.
^ nil
].
].
compression == 2 ifTrue:[
"/ RLE4 - must be depth-4
- inDepth == 4 ifFalse:[
+ inDepth ~~ 4 ifTrue:[
'BMP: RLE4 compression only allowed with depth4 images' errorPrintNL.
^ nil
].
@@ -420,11 +448,20 @@
inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
aStream position:(dataStart + 1).
- data := ByteArray uninitializedNew:(height * width "bytesPerRow").
+ data := ByteArray uninitializedNew:(height * bytesPerRow).
+ "read & possibly decompress"
(self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
^ nil
].
- "expand into bytes"
+
+ numColor == 0 ifTrue:[
+ inDepth == 24 ifTrue:[
+ photometric := #rgb.
+ samplesPerPixel := 3.
+ bitsPerSample := #(8 8 8).
+ ^ self
+ ]
+ ].
photometric := #palette.
samplesPerPixel := 1.
@@ -432,6 +469,7 @@
colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
"Modified: 17.9.1995 / 18:48:46 / claus"
+ "Modified: 4.2.1996 / 17:57:50 / cg"
!
fromStream:aStream