WindowsIconReader.st
changeset 2034 08a022c3faee
parent 2031 c8527bd15f50
child 2333 a93f1f5392bd
--- a/WindowsIconReader.st	Tue Feb 01 16:34:08 2005 +0100
+++ b/WindowsIconReader.st	Wed Feb 02 11:44:31 2005 +0100
@@ -769,62 +769,33 @@
 fromWindowsICOStream:aStream
     "read an image from a windows ICO stream"
 
-    |header numImages inDepth nPlanes nBitsPerPixel nBytesInResource imageOffset
-     bmHeader srcIndex dstIndex
-     rawData tmp bytesPerRow nColor cmapSize szHeader planes bitCount compression szImage xPelsPerMeter yPelsPerMeter 
-     nImportantColor widthBM heightBM nColorBM|
+    |header inDepth
+     srcIndex dstIndex
+     rawData tmp bytesPerRow nColor cmapSize|
 
     inStream := aStream.
     aStream binary.
-    byteOrder := #lsb.
 
     "read the header"
 
-    header := ByteArray uninitializedNew:(6 + 16).
-    aStream nextBytes:(6 + 16) into:header.
-    numImages := header wordAt:(4+1) MSB:false.
-
+    header := ByteArray uninitializedNew:(6 + 16 + 40).
+    aStream nextBytes:(6 + 16 + 40) into:header.
     width := header at:(6+1).
     height := header at:(7+1).
     nColor := header at:(8+1).
     "/ reserved := header at:(9+1).
-    nPlanes := header wordAt:(10+1) MSB:false.
-    nBitsPerPixel := header wordAt:(12+1) MSB:false.
-    nBytesInResource := header doubleWordAt:(14+1) MSB:false.
-    imageOffset := header doubleWordAt:(18+1) MSB:false.
-
-    aStream position:imageOffset.
-.
-    bmHeader := ByteArray uninitializedNew:40.
-    aStream nextBytes:40 into:bmHeader.
+    "/ nPlanes := header wordAt:(10+1).
+    "/ nBitsPerPel := header wordAt:(12+1).
+    "/ nBytesInResource := header doubleWordAt:(14+1).
+    "/ ordinal := header wordAt:(18+1).
+    "21, 22               ?"
+    "23, ... , 62         ?"
 
-    szHeader := bmHeader doubleWordAt:(0+1) MSB:false.
-    widthBM := bmHeader doubleWordAt:(4+1) MSB:false.
-    heightBM := bmHeader doubleWordAt:(8+1) MSB:false.
-    planes := bmHeader wordAt:(12+1) MSB:false.
-    inDepth := bmHeader wordAt:(14+1) MSB:false.
-    compression := bmHeader wordAt:(16+1) MSB:false.
-    szImage := bmHeader doubleWordAt:(20+1) MSB:false.
-    xPelsPerMeter := bmHeader doubleWordAt:(24+1) MSB:false.
-    yPelsPerMeter := bmHeader doubleWordAt:(28+1) MSB:false.
-    nColorBM := bmHeader doubleWordAt:(32+1) MSB:false.
-    nImportantColor := bmHeader doubleWordAt:(36+1) MSB:false.
-
-    szHeader ~~ 40 ifTrue:[
-        "/ not a bm-header
-        ^ self fileFormatError:'unhandled ico-image format (szBMHeader is ' , szHeader printString , ')'.
+    inDepth := header at:16r25.
+    "/ mhmh - some depth4 icons seem to have a 0 in the depth field ...
+    inDepth == 0 ifTrue:[
+        inDepth := 4
     ].
-
-    nColor := nColorBM.
-    nColor == 0 ifTrue:[
-        "
-         some bmp-writers seem to leave this as zero (which is wrong)
-        "
-        inDepth <= 8 ifTrue:[
-            nColor := 1 bitShift:inDepth.
-        ]
-    ].
-
     (#(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 , ')'.
@@ -832,24 +803,22 @@
     ].
     self reportDimension.
 
-self halt.
-    nColor > 0 ifTrue:[
-        "read the colormap"
-        colorMap := self
-                readColorMap:nColor
+    "read the colormap"
+    cmapSize := (1 bitShift:inDepth).
+
+    colorMap := self
+                readColorMap:cmapSize
                 numBytesPerColor:4
                 from:aStream.
-    ].
 
-    "read the bitmap data"
-
+    "read the data bits"
 
     bytesPerRow := width * inDepth + 7 // 8.
     rawData := ByteArray uninitializedNew:(height * bytesPerRow).
     aStream nextBytes:(height * bytesPerRow) into:rawData.
 
     "read mask"
-self halt.
+
 "
     mask := ByteArray new:(width * height / 8).
     aStream nextBytes:(width * height / 8) into:mask.
@@ -1136,7 +1105,7 @@
 !WindowsIconReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.59 2005-01-20 15:26:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.60 2005-02-02 10:44:31 cg Exp $'
 ! !
 
 WindowsIconReader initialize!