WindowsIconReader.st
changeset 1569 3954e576ff38
parent 1507 9bae072abf64
child 1734 290f382d40e9
--- a/WindowsIconReader.st	Tue May 14 11:20:51 2002 +0200
+++ b/WindowsIconReader.st	Thu May 16 17:37:41 2002 +0200
@@ -773,7 +773,7 @@
 
     | header inDepth
       rawMap rMap gMap bMap srcIndex dstIndex
-      data4 mask tmp bytesPerRow nColor|
+      rawData mask tmp bytesPerRow nColor cmapSize|
 
     inStream := aStream.
     aStream binary.
@@ -798,20 +798,21 @@
     inDepth == 0 ifTrue:[
         inDepth := 4
     ].
-    inDepth ~~ 4 ifTrue:[
-        "/ can only handle depth4 images - for now.
-        ^ self fileFormatError:'only depth 4 ico-images supported (depth is ' , inDepth printString , ')'.
+    (#(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 , ')'.
+"/        self halt:'only depth 4 ico-images supported (depth is ' , inDepth printString , ')'.
     ].
 
     "read the colormap"
-
-    rawMap := ByteArray uninitializedNew:(16*4).
-    aStream nextBytes:(16*4) into:rawMap.
-    rMap := ByteArray new:16.
-    gMap := ByteArray new:16.
-    bMap := ByteArray new:16.
+    cmapSize := (1 bitShift:inDepth).
+    rawMap := ByteArray uninitializedNew:(cmapSize*4).
+    aStream nextBytes:(cmapSize*4) into:rawMap.
+    rMap := ByteArray new:cmapSize.
+    gMap := ByteArray new:cmapSize.
+    bMap := ByteArray new:cmapSize.
     srcIndex := 1.
-    1 to:16 do:[:i |
+    1 to:cmapSize do:[:i |
         bMap at:i put:(rawMap at:srcIndex).
         srcIndex := srcIndex + 1.
         gMap at:i put:(rawMap at:srcIndex).
@@ -823,12 +824,9 @@
 
     "read the data bits"
 
-    inDepth == 0 ifTrue:[
-        inDepth := 4.
-    ].
     bytesPerRow := width * inDepth + 7 // 8.
-    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
-    aStream nextBytes:(height * bytesPerRow) into:data4.
+    rawData := ByteArray uninitializedNew:(height * bytesPerRow).
+    aStream nextBytes:(height * bytesPerRow) into:rawData.
 
     "read mask"
 
@@ -844,11 +842,11 @@
     dstIndex := (height - 1) * bytesPerRow + 1.
     1 to:height do:[:row |
         tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
-                   with:data4 startingAt:srcIndex.
+                   with:rawData startingAt:srcIndex.
         srcIndex := srcIndex + bytesPerRow.
         dstIndex := dstIndex - bytesPerRow.
     ].
-    data4 := tmp.
+    rawData := tmp.
 
 
     photometric := #palette.
@@ -857,15 +855,15 @@
     colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
 
     false ifTrue:[
-    "expand into bytes"
+        "expand into bytes"
 
         data := ByteArray new:(width * height).
-        data4 expandPixels:inDepth width:width height:height
+        rawData expandPixels:inDepth width:width height:height
                       into:data mapping:nil.
         bitsPerSample := #(8).
     ] ifFalse:[
-        data := data4.
-        bitsPerSample := #(4).
+        data := rawData.
+        bitsPerSample := (Array with:inDepth).
     ].
 
     "
@@ -1121,6 +1119,6 @@
 !WindowsIconReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.49 2001-09-13 13:00:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.50 2002-05-16 15:37:41 cg Exp $'
 ! !
 WindowsIconReader initialize!