WindowsIconReader.st
changeset 4014 17853d377ead
parent 4012 af495a29eafa
child 4102 853f7162fc69
--- a/WindowsIconReader.st	Wed Sep 13 10:26:28 2017 +0200
+++ b/WindowsIconReader.st	Wed Sep 13 18:12:19 2017 +0200
@@ -1942,17 +1942,19 @@
 
     depth := image depth.
 
-    depth > 8 ifTrue:[
+    (#(1 2 4 8 24 32) includes:depth) ifFalse:[
         ^ Image cannotRepresentImageSignal
             raiseWith:image
-            errorString:('ICO format (currently) only supports depth up to 8').
+            errorString:('ICO format (currently) only supports depths 1,2,4,8,24 or 32').
     ].
 
     width := image width.
     height := image height.
 
     "/ align rows on a longword boundary
-    numColors := (1 bitShift:depth).
+    numColors := depth <= 8 
+                    ifTrue:[ (1 bitShift:depth) ]
+                    ifFalse:[ 0 ].
     
     outStream := fileName asFilename writeStream.
     outStream binary.
@@ -1966,15 +1968,15 @@
     "Write the ICONDIRECTORY structure"
     outStream nextPut:width.                    "/ 0
     outStream nextPut:height.                   "/ 1
-    outStream nextPut:numColors.                "/ 2 # of colors
+    outStream nextPut:numColors.                "/ 2 # of colors in colormap
     outStream nextPut:0.                        "/ 3 reserved
-    "/ for ICO: color planes (should be 0 or 1)
-    "/ for CUR: hotspot-X
-    outStream nextPutInt16:0 MSB:false.         "/ 4 color planes
+    "/ 4 for ICO: color planes (should be 0 or 1)
+    "/ 4 for CUR: hotspot-X
+    outStream nextPutInt16:((depth <= 8) ifTrue:[0] ifFalse:[1]) MSB:false.         
     
-    "/ for ICO: bits per pixel
-    "/ for CUR: hotspot-Y
-    outStream nextPutInt16:depth MSB:false.         "/ 6 bits per pixel
+    "/ 6 for ICO: bits per pixel
+    "/ 6 for CUR: hotspot-Y
+    outStream nextPutInt16:depth MSB:false.      
 
     savOutStream := outStream.
     [
@@ -1987,8 +1989,8 @@
         outStream := savOutStream
     ].
     
-    outStream nextPutInt32:(bmpData size) MSB:false.   "/ 8 size of image data
-    outStream nextPutInt32:(outStream position + 4) MSB:false.       "/ 12 offset in file
+    outStream nextPutInt32:(bmpData size) MSB:false.            "/ 8 size of image data
+    outStream nextPutInt32:(outStream position + 4) MSB:false.  "/ 12 offset in file
 
     "/ followed by bmp format image without bitmap-file-header
 
@@ -2005,7 +2007,7 @@
      WindowsIconReader new saveICO:i onFile:'test.ico'.
     "
 
-    "Modified: / 13-09-2017 / 10:19:36 / cg"
+    "Modified (format): / 13-09-2017 / 17:13:58 / cg"
 ! !
 
 !WindowsIconReader class methodsFor:'documentation'!