#FEATURE by cg
class: PNGReader
changed: #writeImageDataChunk
writing 32bit images
--- a/PNGReader.st Fri Feb 24 02:05:07 2017 +0100
+++ b/PNGReader.st Sat Feb 25 19:31:46 2017 +0100
@@ -1546,7 +1546,7 @@
writeImageDataChunk
|compressedByteStream compressedBytes zlibWriter idx
- row32|
+ row32 bytesPerPixel|
bytesPerScanline := self bytesPerRow.
@@ -1555,30 +1555,38 @@
zlibWriter binary.
(mask notNil and:[photometric ~~ #palette]) ifTrue:[
- "/ on-the-fly expand mask into the alpha channel.
+ (depth == 32) ifTrue:[
+ "/ on-the-fly put mask into the alpha channel.
+
+ bytesPerPixel := 4
+ ] ifFalse:[
+ "/ for now - only support depth24 + mask
+ self assert:(depth == 24).
+ bytesPerPixel := 3.
+ ].
- "/ for now - only support depth24 + mask
- self assert:(depth == 24).
+ "/ on-the-fly place mask into the alpha channel.
+
row32 := ByteArray new:(4 * width).
- self assert:(bytesPerScanline == (3 * width)).
-
+ self assert:(bytesPerScanline == (bytesPerPixel * width)).
+
idx := 1.
0 to:height-1 do:[:y |
|dstIdx maskRow|
"/ expand rgb to rgba
maskRow := mask rowAt:y.
-
+
dstIdx := 1.
1 to:width do:[:x |
row32 at:dstIdx put:(data at:idx).
row32 at:dstIdx+1 put:(data at:idx+1).
row32 at:dstIdx+2 put:(data at:idx+2).
row32 at:dstIdx+3 put:((maskRow at:x) == 0 ifTrue:[0] ifFalse:[16rFF]).
- idx := idx + 3.
+ idx := idx + bytesPerPixel.
dstIdx := dstIdx + 4.
].
-
+
zlibWriter nextPutAll:#[0]. "/ no filter
zlibWriter nextPutAll:row32.
].
@@ -1604,7 +1612,7 @@
outStream nextPutAll:compressedBytes
]
- "Modified: / 17-02-2017 / 17:02:16 / cg"
+ "Modified: / 25-02-2017 / 14:27:34 / cg"
!
writePaletteChunk