class: PNGReader
authorClaus Gittinger <cg@exept.de>
Tue, 06 May 2014 16:34:49 +0200
changeset 3327 4758853d1abe
parent 3326 3de14efde773
child 3328 7303f72cc0eb
class: PNGReader added: #copyPixelsRGBA:at:by: changed: #processInterlacedGlobalDATA read (some) intrlaced image format
PNGReader.st
--- a/PNGReader.st	Sun Apr 20 23:53:00 2014 +0200
+++ b/PNGReader.st	Tue May 06 16:34:49 2014 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1996 by Claus Gittinger
               All Rights Reserved
@@ -247,17 +249,22 @@
 !
 
 processInterlacedGlobalDATA
+    "adam7 interlace method"
+
     | zlibReader filter bytesPerPass startingCol colIncrement rowIncrement 
-      startingRow cx sc temp "filtersSeen" bitsPerPixel|
+      startingRow cx sc temp "filtersSeen" bitsPerPixel cy|
 
-    self error:'interlaced pictures not yet supported'.
+    interlaceMode == 1 ifFalse: [
+        self error:'unsupported interlaced mode'.
+        ^ self
+    ].
 
     "/ filtersSeen := Set new.
 
     startingCol := #(0 4 0 2 0 1 0 ).
+    startingRow := #(0 0 4 0 2 0 1 ).
     colIncrement := #(8 8 4 4 2 2 1 ).
     rowIncrement := #(8 8 8 4 4 2 2 ).
-    startingRow := #(0 0 4 0 2 0 1 ).
 
     zlibReader := ZipStream readOpenAsZipStreamOn:(globalDataChunk readStream) suppressHeaderAndChecksum:false.
     zlibReader binary.
@@ -268,10 +275,11 @@
         (self doPass: pass) ifTrue:[
             cx := colIncrement at: pass.
             sc := startingCol at: pass.
+            cy := rowIncrement at: pass.
             bytesPerPass := width - sc + cx - 1 // cx * bitsPerPixel + 7 // 8.
             prevScanline := ByteArray new: bytesPerPass.
             thisScanline := ByteArray new: bytesPerScanline.
-            (startingRow at: pass) to: height - 1 by: (rowIncrement at: pass) do: [:y |
+            (startingRow at: pass) to: height - 1 by: cy do: [:y |
                 filter := zlibReader next.
                 "/ filtersSeen add: filter.
                 (filter isNil or: [(filter between: 0 and: 4) not])
@@ -549,6 +557,28 @@
     self perform:(s asSymbol) with:y with:startX with:incX
 
     "Modified: / 03-05-2011 / 12:02:45 / cg"
+!
+
+copyPixelsRGBA:y at:startX by:incX 
+    "Handle interlaced pixels of supported colorTypes.
+     Untested code - please verify"
+
+    |srcIndex nPixels dstIndex n r g b a|
+
+    srcIndex := 1.
+    dstIndex := y * bytesPerScanline.
+    n := width // incX.
+
+    nPixels := thisScanline size.
+    [srcIndex < nPixels] whileTrue:[
+        r := thisScanline at:srcIndex.
+        g := thisScanline at:srcIndex+1.
+        b := thisScanline at:srcIndex+2.
+        a := thisScanline at:srcIndex+3.
+        data replaceFrom:dstIndex+1 to:(dstIndex+3) with:thisScanline startingAt:srcIndex.
+        srcIndex := srcIndex + 4.
+        dstIndex := dstIndex + (incX * 4)
+    ].
 ! !
 
 !PNGReader methodsFor:'private-reading'!
@@ -880,11 +910,11 @@
 !PNGReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.32 2013-06-20 22:43:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.33 2014-05-06 14:34:49 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.32 2013-06-20 22:43:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.33 2014-05-06 14:34:49 cg Exp $'
 ! !