#TUNING by cg
authorClaus Gittinger <cg@exept.de>
Wed, 18 Jan 2017 17:06:24 +0100
changeset 3821 940aaefb5f77
parent 3820 057cf3cc3b1c
child 3822 b513fec53287
child 3854 4afd107bc911
#TUNING by cg class: PNGReader changed: #processChunk:len: #processInterlacedGlobalDATA #processNonInterlacedGlobalDATA #writeImageDataChunk use a stream-buffer to collect globalIDATA
PNGReader.st
--- a/PNGReader.st	Wed Jan 18 04:59:13 2017 +0000
+++ b/PNGReader.st	Wed Jan 18 17:06:24 2017 +0100
@@ -14,12 +14,12 @@
 "{ NameSpace: Smalltalk }"
 
 ImageReader subclass:#PNGReader
-	instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod
-		interlaceMode bytesPerScanline globalDataChunk thisScanline
-		prevScanline processTextChunks'
-	classVariableNames:'Verbose'
-	poolDictionaries:''
-	category:'Graphics-Images-Readers'
+        instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod
+                interlaceMode bytesPerScanline globalDataChunk thisScanline
+                prevScanline processTextChunks'
+        classVariableNames:'Verbose'
+        poolDictionaries:''
+        category:'Graphics-Images-Readers'
 !
 
 !PNGReader class methodsFor:'documentation'!
@@ -193,11 +193,11 @@
         if memory is an issue, we need to figure out how
         to do this on the fly---"
         chunk := inStream next:len.
-        globalDataChunk := globalDataChunk isNil 
-                                ifTrue: [chunk] 
-                                ifFalse:[globalDataChunk,chunk].
+        globalDataChunk isNil ifTrue:[
+            globalDataChunk := ReadWriteStream on:(ByteArray new:(height * self bytesPerRow)).
+        ].
+        globalDataChunk nextPutAll:chunk.
         ^ true
-"/        ^ self processIDATChunkLen:len
     ].
 
     type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len].
@@ -348,9 +348,8 @@
     colIncrement := #(8 8 4 4 2 2 1 ).
     rowIncrement := #(8 8 8 4 4 2 2 ).
 
-    zlibReader := ZipStream 
-                    readOpenAsZipStreamOn:(globalDataChunk readStream) 
-                    suppressHeaderAndChecksum:false.
+    globalDataChunk reset.
+    zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false.
     zlibReader binary.
 
     h := height.
@@ -407,7 +406,7 @@
 !
 
 processNonInterlacedGlobalDATA
-    | "data n" zlibReader filter temp bytesPerScanline "filtersSeen" i|
+    | "data n" zlibReader filter temp "filtersSeen" i|
 
     "/ filtersSeen := Set new.
 
@@ -415,11 +414,9 @@
 "/    n := ZipStream uncompress: globalDataChunk into: data.
 "/    self halt.
 
-    zlibReader := ZipStream 
-                    readOpenAsZipStreamOn:(globalDataChunk readStream) 
-                    suppressHeaderAndChecksum:false.
+    globalDataChunk reset.
+    zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false.
     zlibReader binary.
-    bytesPerScanline := self bytesPerRow.
 
     prevScanline := ByteArray new: bytesPerScanline.
     thisScanline := ByteArray new: bytesPerScanline.
@@ -1260,15 +1257,13 @@
 !
 
 writeImageDataChunk
-    |compressedByteStream compressedBytes zlibWriter bytesPerScanline idx|
-
-    compressedByteStream := WriteStream on:(ByteArray new:100).
-    zlibWriter := ZipStream 
-                    writeOpenAsZipStreamOn:compressedByteStream 
-                    suppressHeaderAndChecksum:false.
-    zlibWriter binary.
+    |compressedByteStream compressedBytes zlibWriter idx|
 
     bytesPerScanline := self bytesPerRow.
+    
+    compressedByteStream := WriteStream on:(ByteArray new:(bytesPerScanline*height)).
+    zlibWriter := ZipStream writeOpenAsZipStreamOn:compressedByteStream suppressHeaderAndChecksum:false.
+    zlibWriter binary.
 
     idx := 1.
     0 to:height-1 do:[:y |