--- a/WindowsIconReader.st Mon Aug 08 17:06:34 2016 +0200
+++ b/WindowsIconReader.st Tue Aug 09 04:37:32 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
@@ -264,7 +266,7 @@
"return true, if anImage can be represented in my file format.
BMP supports depth 1,4,8 and 24."
- (#(1 4 8 24) includes:anImage depth) ifTrue:[^true].
+ (#(1 4 8 24 32) includes:anImage depth) ifTrue:[^true].
('WindwsIconReader [info]: image depth is not 1,4,8 or 24.') infoPrintCR.
^ false
@@ -1635,7 +1637,7 @@
width := image width.
height := image height.
- (#(1 4 8 24) includes:depth) ifFalse:[
+ (#(1 4 8 24 32) includes:depth) ifFalse:[
^ Image cannotRepresentImageSignal
raiseWith:image
errorString:('BMP format only supports depths 1,4,8 and 24').
@@ -1651,7 +1653,7 @@
biClrUsed := (depth >= 24) ifTrue:[0] ifFalse:[1 bitShift: depth]. "No. color table entries"
bfOffBits := biSize + bhSize + (4*biClrUsed).
"/ bmp aligns rows on a longword boundary
- rowBytes := (((depth min:24) * width + 31) // 32) * 4.
+ rowBytes := (((depth min:32) * width + 31) // 32) * 4.
biSizeImage := height * rowBytes.
outStream := fileName asFilename writeStream.
@@ -1670,7 +1672,7 @@
self writeLong:width. "biWidth"
self writeLong:height. "biHeight"
self writeShort:1. "biPlanes"
- self writeShort:(depth min:24). "biBitCount"
+ self writeShort:(depth min:32). "biBitCount"
self writeLong:0. "biCompression"
self writeLong:biSizeImage. "size of image section in bytes"
self writeLong:2800. "biXPelsPerMeter"
@@ -1710,9 +1712,13 @@
1 to:height do:[:i |
srcIndex := srcIndex - imgBytesPerRow.
row replaceFrom:1 to:imgBytesPerRow with:bits startingAt:srcIndex.
- depth == 24 ifTrue:[
+ depth >= 24 ifTrue:[
"/ stupid must swap red & blue bytes
- self class swap:row size bytesFromRGB_to_BGR_in:row startingAt:1.
+ depth >= 32 ifTrue:[
+ self class swap:row size bytesFromRGBA_to_BGRA_in:row startingAt:1.
+ ] ifFalse:[
+ self class swap:row size bytesFromRGB_to_BGR_in:row startingAt:1.
+ ]
].
outStream nextPutAll:row.
].