--- a/PNGReader.st Fri Aug 07 16:09:17 2009 +0200
+++ b/PNGReader.st Fri Aug 07 17:31:40 2009 +0200
@@ -13,8 +13,8 @@
ImageReader subclass:#PNGReader
instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod
- interlaceMode redBytes greenBytes blueBytes bytesPerScanline
- globalDataChunk thisScanline prevScanline'
+ interlaceMode bytesPerScanline globalDataChunk thisScanline
+ prevScanline'
classVariableNames:'Verbose'
poolDictionaries:''
category:'Graphics-Images-Readers'
@@ -40,10 +40,14 @@
documentation
"
- This class will provide methods for loading PNG pictures.
+ This class will provide methods for loading and saving PNG pictures.
It is currenty unfinished (interlaced image support is missing).
- In the meantime, use a pngtoXXX converter.
+ In the meantime, use a pngtoXXX converter for interlaced images.
+ [caveats:]
+ writer ignores any mask (for now).
+ writer only generates unfiltered rows or interlace data
+
[See also:]
Image Form Icon
BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader
@@ -67,6 +71,7 @@
|img img2 outStream png|
+
img := ToolbarIconLibrary error32x32Icon.
outStream := WriteStream on:(ByteArray new:100).
PNGReader save:img onStream:outStream.
@@ -310,7 +315,7 @@
!
processNonInterlacedGlobalDATA
- | "data n" zlibReader filter temp bytesPerScanline "filtersSeen"|
+ | "data n" zlibReader filter temp bytesPerScanline "filtersSeen" i|
"/ filtersSeen := Set new.
@@ -324,13 +329,19 @@
prevScanline := ByteArray new: bytesPerScanline.
thisScanline := ByteArray new: bytesPerScanline.
- 0 to: height - 1 do:[:index |
+ 0 to: height - 1 do:[:y |
filter := (zlibReader next: 1) first.
"/ filtersSeen add: filter.
- (filter notNil and: [filter between: 0 and: 4]) ifFalse: [^self].
+ (filter notNil and: [filter between: 0 and: 4]) ifFalse: [
+ 'PNGReader: unsupported filter' infoPrintCR.
+ ^ self
+ ].
zlibReader next: bytesPerScanline into: thisScanline startingAt: 1.
filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerScanline ].
- self copyPixels:index.
+
+ i := y * bytesPerScanline.
+ data replaceFrom:i+1 to:(i+bytesPerScanline) with:thisScanline startingAt:1.
+
temp := prevScanline.
prevScanline := thisScanline.
thisScanline := temp
@@ -359,7 +370,8 @@
processPLTEChunkLen:len
"read a color palette"
- |n "{ Class: SmallInteger }"|
+ |n "{ Class: SmallInteger }"
+ redBytes greenBytes blueBytes|
(len \\ 3) ~~ 0 ifTrue:[
'PNGReader: invalid size of PLTE chunk' infoPrintCR.
@@ -376,6 +388,11 @@
blueBytes at:i put:(inStream nextByte)
].
+ colorMap := MappedPalette
+ redVector:redBytes
+ greenVector:greenBytes
+ blueVector:blueBytes.
+
^ true
"Created: 21.6.1996 / 21:22:28 / cg"
@@ -500,18 +517,7 @@
!PNGReader methodsFor:'private-pixel copy'!
-copyPixels: y
- "in stx, the same copy method is used for all formats"
-
- |bpr i|
-
- bpr := self bytesPerRow.
- i := y * bpr.
-
- data replaceFrom:1+i to:(i+bpr) with:thisScanline startingAt:1.
-!
-
-copyPixels: y at: startX by: incX
+copyPixels:y at:startX by:incX
"Handle interlaced pixels of supported colorTypes"
| s |
@@ -699,15 +705,10 @@
].
photometric == #palette ifTrue:[
- redBytes isNil ifTrue:[
+ colorMap isNil ifTrue:[
'PNGReader: missing palette chunk.' infoPrintCR.
- ^ nil
+ "/ ^ nil
].
-
- colorMap := MappedPalette
- redVector:redBytes
- greenVector:greenBytes
- blueVector:blueBytes.
].
"
@@ -852,7 +853,7 @@
!PNGReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.27 2009-08-05 13:23:41 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.28 2009-08-07 15:31:40 cg Exp $'
! !
PNGReader initialize!