--- a/WindowsIconReader.st Mon Mar 07 00:45:45 2016 +0100
+++ b/WindowsIconReader.st Mon Mar 07 01:56:08 2016 +0100
@@ -361,31 +361,23 @@
needPixelProcessing := false.
inDepth == 16 ifTrue:[
- (redShift ~~ 0
- or:[ greenShift ~~ 5
- or:[ blueShift ~~ 10
- or:[ numRedBits ~~ 5
- or:[ numGreenBits ~~ 5
- or:[ numBlueBits ~~ 5
- or:[ alphaMask ~~ 0]]]]]]
- ) ifTrue:[
- needPixelProcessing := true.
- alphaMask == 0 ifTrue:[
- bitsPerSample := {numRedBits. numGreenBits. numBlueBits}.
- photometric := #rgb
- ] ifFalse:[
- bitsPerSample := {numRedBits. numGreenBits. numBlueBits. numAlphaBits }.
- photometric := #rgba
- ].
+ alphaMask == 0 ifTrue:[
+ bitsPerSample := {numRedBits. numGreenBits. numBlueBits}.
+ colorMap := FixedPalette
+ redShift:redShift redMask:(redMask >> redShift)
+ greenShift:greenShift greenMask:(greenMask >> greenShift)
+ blueShift:blueShift blueMask:(blueMask >> blueShift).
+ photometric := #palette.
] ifFalse:[
- swapAction := [:bytes | data swapBytes].
- colorMap := FixedPalette
- redShift:10 redMask:16r1f
- greenShift:5 greenMask:16r1f
- blueShift:0 blueMask:16r1F.
- bitsPerSample := #(5 5 5).
- photometric := #palette
- ].
+ bitsPerSample := {numRedBits. numGreenBits. numBlueBits. numAlphaBits }.
+ colorMap := FixedPaletteWithAlpha
+ redShift:redShift redMask:(redMask >> redShift)
+ greenShift:greenShift greenMask:(greenMask >> greenShift)
+ blueShift:blueShift blueMask:(blueMask >> blueShift).
+ colorMap alphaShift:alphaShift alphaMask:(alphaMask >> alphaShift).
+ photometric := #palette.
+ ].
+ swapAction := [:bytes | data swapBytes].
].
inDepth == 24 ifTrue:[
(redShift ~~ 0
@@ -443,49 +435,22 @@
needPixelProcessing ifTrue:[
alphaMask == 0 ifTrue:[
- inDepth == 16 ifTrue:[
- colorMap := FixedPalette
- redShift:redShift redMask:(redMask >> redShift)
- greenShift:greenShift greenMask:(greenMask >> greenShift)
- blueShift:blueShift blueMask:(blueMask >> blueShift).
- photometric := #palette.
- swapAction := [:bytes | data swapBytes].
-"/ pixelAction := [:v |
-"/ |r g b|
-"/ r := (v bitAnd:redMask) >> redShift.
-"/ g := (v bitAnd:greenMask) >> greenShift.
-"/ b := (v bitAnd:blueMask) >> blueShift.
-"/ (((b bitShift:5) bitOr:g) bitShift:5) bitOr:r
-"/ ].
- ] ifFalse:[
- pixelAction := [:v |
- |r g b|
- r := (v bitAnd:redMask) >> redShift.
- g := (v bitAnd:greenMask) >> greenShift.
- b := (v bitAnd:blueMask) >> blueShift.
- (((b bitShift:8) bitOr:g) bitShift:8) bitOr:r
- ].
- ]
+ pixelAction := [:v |
+ |r g b|
+ r := (v bitAnd:redMask) >> redShift.
+ g := (v bitAnd:greenMask) >> greenShift.
+ b := (v bitAnd:blueMask) >> blueShift.
+ (((b bitShift:8) bitOr:g) bitShift:8) bitOr:r
+ ].
] ifFalse:[
- inDepth == 16 ifTrue:[
- pixelAction := [:v |
- |r g b a|
- r := (v bitAnd:redMask) >> redShift.
- g := (v bitAnd:greenMask) >> greenShift.
- b := (v bitAnd:blueMask) >> blueShift.
- a := (v bitAnd:alphaMask) >> alphaShift.
- (((((a bitShift:5) bitOr:b) bitShift:5) bitOr:g) bitShift:5) bitOr:r
- ].
- ] ifFalse:[
- pixelAction := [:v |
- |r g b a|
- r := (v bitAnd:redMask) >> redShift.
- g := (v bitAnd:greenMask) >> greenShift.
- b := (v bitAnd:blueMask) >> blueShift.
- a := (v bitAnd:alphaMask) >> alphaShift.
- (((((a bitShift:8) bitOr:b) bitShift:8) bitOr:g) bitShift:8) bitOr:r
- ].
- ].
+ pixelAction := [:v |
+ |r g b a|
+ r := (v bitAnd:redMask) >> redShift.
+ g := (v bitAnd:greenMask) >> greenShift.
+ b := (v bitAnd:blueMask) >> blueShift.
+ a := (v bitAnd:alphaMask) >> alphaShift.
+ (((((a bitShift:8) bitOr:b) bitShift:8) bitOr:g) bitShift:8) bitOr:r
+ ].
].
].
] ifFalse:[
@@ -1237,7 +1202,7 @@
aStream nextBytes:(iSize-4) into:bitmapHeader startingAt:(1+4).
dataStart := fileHeader doubleWordAt:(10 + 1) MSB:false.
-self halt.
+
((iSize == 40) or:[iSize == 108 or:[iSize == 124]]) ifTrue:[ "header-size"
"/
"/ a Windows3.x BMP file (40)
@@ -1362,13 +1327,9 @@
"/ colormap only allowed up to 12bit
^ self fileFormatError:'unreasonable colormap size'.
].
- (dataStart - inStream position) < (numBytesPerColorInColormap*numColor) ifTrue:[
- self halt
- ] ifFalse:[
- (dataStart - inStream position) > (numBytesPerColorInColormap*numColor) ifTrue:[
- self halt
- ].
- ].
+"/ (dataStart - inStream position) ~= (numBytesPerColorInColormap*numColor) ifTrue:[
+"/ self halt
+"/ ].
colorMap := self
readColorMap:numColor
@@ -1413,7 +1374,7 @@
].
dataStart notNil ifTrue:[
- (dataStart - inStream position) ~~ 0 ifTrue:[self halt].
+ "/ (dataStart - inStream position) ~~ 0 ifTrue:[self halt].
aStream position:dataStart.
].