--- a/PNGReader.st Sat Oct 27 16:10:05 2018 +0200
+++ b/PNGReader.st Sat Oct 27 17:40:05 2018 +0200
@@ -20,7 +20,7 @@
interlaceMode bytesPerScanline globalDataChunk thisScanline
prevScanline processTextChunks specialChunkHandlers
paletteAlphaEntries paletteIndexForMaskedPixels image forceRGB
- depthImage specialChunks'
+ depthImage specialChunks extractSpecialChunksOnly'
classVariableNames:'ColorTypeGray ColorTypeGrayAlpha ColorTypePalette ColorTypeRGB
ColorTypeRGBAlpha Verbose'
poolDictionaries:''
@@ -172,6 +172,17 @@
!PNGReader methodsFor:'accessing'!
+extractSpecialChunksOnly:aBoolean
+ "if set to true, only special chunks will be processed via
+ corresponding specialChunkHandlers.
+ No image will be extracted.
+ The default is (of course) false."
+
+ extractSpecialChunksOnly := aBoolean.
+
+ "Modified (comment): / 27-10-2018 / 17:39:50 / Claus Gittinger"
+!
+
makeImage
image isNil ifTrue:[
image := super makeImage.
@@ -260,6 +271,8 @@
[self getChunk] whileTrue.
+ extractSpecialChunksOnly == true ifTrue:[^nil].
+
"/ kludge: if we get a grey image with alpha,
"/ load as rgb+alpha
forceRGB := false.
@@ -328,7 +341,7 @@
"
"Modified: / 17-09-2017 / 15:30:45 / cg"
- "Modified (format): / 02-06-2018 / 06:55:59 / Claus Gittinger"
+ "Modified: / 27-10-2018 / 17:29:21 / Claus Gittinger"
! !
!PNGReader methodsFor:'reading-private'!
@@ -618,8 +631,22 @@
!
processChunk:type len:len
- |chunk|
+ |chunk handler chunkData|
+ specialChunkHandlers notNil ifTrue:[
+ handler := specialChunkHandlers at:type ifAbsent:nil.
+ handler notNil ifTrue:[
+ chunkData := inStream nextBytes:len.
+ handler value:chunkData optionalArgument:self.
+ ^ true.
+ ].
+ ].
+
+ extractSpecialChunksOnly == true ifTrue:[
+ inStream skip:len.
+ ^ true.
+ ].
+
type = 'IDAT' ifTrue:[
"---since the compressed data can span multiple
chunks, stitch them all together first. later,
@@ -651,17 +678,6 @@
type = 'hIST' ifTrue:[^ self processHISTChunkLen:len].
type = 'spAL' ifTrue:[^ self processSPALChunkLen:len].
- specialChunkHandlers notNil ifTrue:[
- |handler chunkData|
-
- handler := specialChunkHandlers at:type ifAbsent:nil.
- handler notNil ifTrue:[
- chunkData := inStream nextBytes:len.
- handler value:chunkData optionalArgument:self.
- ^ true.
- ].
- ].
-
type = 'niVI' ifTrue:[^ self processNIVIChunkLen:len].
type = 'exEX' ifTrue:[^ self processEXEXChunkLen:len].
@@ -672,7 +688,7 @@
"Created: / 21-06-1996 / 21:10:37 / cg"
"Modified: / 11-04-2017 / 17:04:12 / cg"
- "Modified: / 02-06-2018 / 06:43:03 / Claus Gittinger"
+ "Modified: / 27-10-2018 / 17:38:14 / Claus Gittinger"
!
processEXEXChunkLen:len