WindowsIconReader.st
changeset 3593 cba067f384d3
parent 3592 6a70bc638877
child 3594 695b4c2f1b83
--- a/WindowsIconReader.st	Mon Mar 07 10:18:27 2016 +0100
+++ b/WindowsIconReader.st	Mon Mar 07 10:31:02 2016 +0100
@@ -1211,6 +1211,8 @@
 
     dataStart := fileHeader doubleWordAt:(10 + 1) MSB:false.
 
+    alphaMask := 0.
+
     ((iSize == 40) or:[iSize == 52 or:[iSize == 56 or:[iSize == 108 or:[iSize == 124]]]]) ifTrue:[    "header-size"
         "/
         "/ a Windows3.x BMP file (40)
@@ -1231,28 +1233,37 @@
         numImportantColor := bitmapHeader doubleWordAt:(36 + 1) MSB:false.
         
         (compression > 3) ifTrue:[
+            compression == 4 ifTrue:[
+                "/ JPG in data
+                aStream position:dataStart.
+                pngOrJPGImage := JPEGReader fromStream:aStream.
+                ^ pngOrJPGImage
+            ].    
             compression == 5 ifTrue:[
                 "/ PNG in data
                 aStream position:dataStart.
                 pngOrJPGImage := PNGReader fromStream:aStream.
                 ^ pngOrJPGImage
             ].    
-            compression == 4 ifTrue:[
-                "/ JPG in data
-                aStream position:dataStart.
-                pngOrJPGImage := JPEGReader fromStream:aStream.
-                ^ pngOrJPGImage
+            compression == 6 ifTrue:[
+                "/ very seldom - alphamask compression
+            ] ifFalse:[    
+                ^ self fileFormatError:'unhandled compression'.
             ].    
-            ^ self fileFormatError:'unhandled compression'.
         ].
         
-        (iSize == 40 and:[compression == 3]) ifTrue:[
+        (iSize == 40 and:[(compression == 3) or:[compression == 6]]) ifTrue:[
             "/ masks are not counted in header (sigh)
-            aStream next:4*3 into:bitmapHeader startingAt:iSize+1.
+            compression == 6 ifTrue:[
+                aStream next:4*4 into:bitmapHeader startingAt:iSize+1.
+                alphaMask := bitmapHeader doubleWordAt:(52 + 1) MSB:false.
+                compression := 3.
+            ] ifFalse:[        
+                aStream next:4*3 into:bitmapHeader startingAt:iSize+1.
+            ].    
             redMask := bitmapHeader doubleWordAt:(40 + 1) MSB:false.
             greenMask := bitmapHeader doubleWordAt:(44 + 1) MSB:false.
             blueMask := bitmapHeader doubleWordAt:(48 + 1) MSB:false.
-            alphaMask := 0.
         ] ifFalse:[        
             iSize > 40 ifTrue:[
                 "/ masks are counted in header (sigh)
@@ -1421,7 +1432,7 @@
 
     data := ByteArray uninitializedNew:(height * bytesPerRow).
     "/ when compressed, there may be holes, which need to be filled with zeros
-    compression ~~ 0 ifTrue:[
+    ((compression ~~ 0) and:[compression ~~ 3]) ifTrue:[
         data atAllPut:0
     ].