class: WindowsIconReader
changed: #fromWindowsICOStream:alreadyRead:
added support for 32bit per pixel images.
--- a/WindowsIconReader.st Sun Nov 23 17:56:09 2014 +0100
+++ b/WindowsIconReader.st Wed Nov 26 13:45:44 2014 +0100
@@ -987,8 +987,8 @@
"read the header"
header := ByteArray uninitializedNew:(6 + 16 + 40).
- bytesAlreadyRead size > 0 ifTrue:[
- header replaceFrom:1 with:bytesAlreadyRead
+ bytesAlreadyRead notEmptyOrNil ifTrue:[
+ header replaceFrom:1 with:bytesAlreadyRead
].
aStream nextBytes:((6 + 16 + 40)-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size).
@@ -1006,22 +1006,21 @@
inDepth := header at:16r25.
"/ mhmh - some depth4 icons seem to have a 0 in the depth field ...
inDepth == 0 ifTrue:[
- inDepth := 4
+ inDepth := 4
].
- (#(4 8) includes:inDepth) ifFalse:[
- "/ only tested for depth 4/8 images.
- ^ self fileFormatError:'only depth 4/8 ico-images supported (depth is ' , inDepth printString , ')'.
+ (#(4 8 32) includes:inDepth) ifFalse:[
+ "/ only tested for depth 4/8 images.
+ ^ self fileFormatError:'only depth 4/8/32 ico-images supported (depth is ' , inDepth printString , ')'.
"/ self halt:'only depth 4 ico-images supported (depth is ' , inDepth printString , ')'.
].
self reportDimension.
- "read the colormap"
- cmapSize := (1 bitShift:inDepth).
+ nColor > 0 ifTrue:[
+ "read the colormap"
+ cmapSize := (1 bitShift:inDepth).
- colorMap := self
- readColorMap:cmapSize
- numBytesPerColor:4
- from:aStream.
+ colorMap := self readColorMap:cmapSize numBytesPerColor:4 from:aStream.
+ ].
"read the data bits"
@@ -1042,27 +1041,28 @@
srcIndex := 1.
dstIndex := (height - 1) * bytesPerRow + 1.
1 to:height do:[:row |
- tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
- with:rawData startingAt:srcIndex.
- srcIndex := srcIndex + bytesPerRow.
- dstIndex := dstIndex - bytesPerRow.
+ tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
+ with:rawData startingAt:srcIndex.
+ srcIndex := srcIndex + bytesPerRow.
+ dstIndex := dstIndex - bytesPerRow.
].
rawData := tmp.
- photometric := #palette.
- samplesPerPixel := 1.
-
- false ifTrue:[
- "expand into bytes"
+ nColor > 0 ifTrue:[
+ photometric := #palette.
+ samplesPerPixel := 1.
+ bitsPerSample := (Array with:inDepth).
+ ] ifFalse:[
+ inDepth == 32 ifTrue:[
+ photometric := #rgba.
+ samplesPerPixel := 4.
+ bitsPerSample := #(8 8 8 8).
+ ] ifFalse:[
+ ^ self fileFormatError:'unsupported image depth: ' , inDepth printString.
+ ]
+ ].
- data := ByteArray new:(width * height).
- rawData expandPixels:inDepth width:width height:height
- into:data mapping:nil.
- bitsPerSample := #(8).
- ] ifFalse:[
- data := rawData.
- bitsPerSample := (Array with:inDepth).
- ].
+ data := rawData.
^ self image
"
@@ -1318,11 +1318,11 @@
!WindowsIconReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.67 2013-08-10 11:25:55 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.68 2014-11-26 12:45:44 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.67 2013-08-10 11:25:55 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.68 2014-11-26 12:45:44 cg Exp $'
! !