equal
deleted
inserted
replaced
12 "{ Package: 'stx:libview2' }" |
12 "{ Package: 'stx:libview2' }" |
13 |
13 |
14 "{ NameSpace: Smalltalk }" |
14 "{ NameSpace: Smalltalk }" |
15 |
15 |
16 ImageReader subclass:#PNGReader |
16 ImageReader subclass:#PNGReader |
17 instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod |
17 instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod |
18 interlaceMode bytesPerScanline globalDataChunk thisScanline |
18 interlaceMode bytesPerScanline globalDataChunk thisScanline |
19 prevScanline processTextChunks' |
19 prevScanline processTextChunks' |
20 classVariableNames:'Verbose' |
20 classVariableNames:'Verbose' |
21 poolDictionaries:'' |
21 poolDictionaries:'' |
22 category:'Graphics-Images-Readers' |
22 category:'Graphics-Images-Readers' |
23 ! |
23 ! |
24 |
24 |
25 !PNGReader class methodsFor:'documentation'! |
25 !PNGReader class methodsFor:'documentation'! |
26 |
26 |
27 copyright |
27 copyright |
191 "---since the compressed data can span multiple |
191 "---since the compressed data can span multiple |
192 chunks, stitch them all together first. later, |
192 chunks, stitch them all together first. later, |
193 if memory is an issue, we need to figure out how |
193 if memory is an issue, we need to figure out how |
194 to do this on the fly---" |
194 to do this on the fly---" |
195 chunk := inStream next:len. |
195 chunk := inStream next:len. |
196 globalDataChunk := globalDataChunk isNil |
196 globalDataChunk isNil ifTrue:[ |
197 ifTrue: [chunk] |
197 globalDataChunk := ReadWriteStream on:(ByteArray new:(height * self bytesPerRow)). |
198 ifFalse:[globalDataChunk,chunk]. |
198 ]. |
|
199 globalDataChunk nextPutAll:chunk. |
199 ^ true |
200 ^ true |
200 "/ ^ self processIDATChunkLen:len |
|
201 ]. |
201 ]. |
202 |
202 |
203 type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len]. |
203 type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len]. |
204 type = 'sBIT' ifTrue:[^ self processSBITChunkLen:len]. |
204 type = 'sBIT' ifTrue:[^ self processSBITChunkLen:len]. |
205 type = 'tEXt' ifTrue:[^ self processTEXTChunkLen:len]. |
205 type = 'tEXt' ifTrue:[^ self processTEXTChunkLen:len]. |
346 startingCol := #(0 4 0 2 0 1 0 ). |
346 startingCol := #(0 4 0 2 0 1 0 ). |
347 startingRow := #(0 0 4 0 2 0 1 ). |
347 startingRow := #(0 0 4 0 2 0 1 ). |
348 colIncrement := #(8 8 4 4 2 2 1 ). |
348 colIncrement := #(8 8 4 4 2 2 1 ). |
349 rowIncrement := #(8 8 8 4 4 2 2 ). |
349 rowIncrement := #(8 8 8 4 4 2 2 ). |
350 |
350 |
351 zlibReader := ZipStream |
351 globalDataChunk reset. |
352 readOpenAsZipStreamOn:(globalDataChunk readStream) |
352 zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false. |
353 suppressHeaderAndChecksum:false. |
|
354 zlibReader binary. |
353 zlibReader binary. |
355 |
354 |
356 h := height. |
355 h := height. |
357 w := width. |
356 w := width. |
358 1 to: 7 do: [:pass | |
357 1 to: 7 do: [:pass | |
405 "/ thisScanline := temp |
404 "/ thisScanline := temp |
406 "/ ] |
405 "/ ] |
407 ! |
406 ! |
408 |
407 |
409 processNonInterlacedGlobalDATA |
408 processNonInterlacedGlobalDATA |
410 | "data n" zlibReader filter temp bytesPerScanline "filtersSeen" i| |
409 | "data n" zlibReader filter temp "filtersSeen" i| |
411 |
410 |
412 "/ filtersSeen := Set new. |
411 "/ filtersSeen := Set new. |
413 |
412 |
414 "/ data := ByteArray new:(self bytesPerRow * height)+1000. |
413 "/ data := ByteArray new:(self bytesPerRow * height)+1000. |
415 "/ n := ZipStream uncompress: globalDataChunk into: data. |
414 "/ n := ZipStream uncompress: globalDataChunk into: data. |
416 "/ self halt. |
415 "/ self halt. |
417 |
416 |
418 zlibReader := ZipStream |
417 globalDataChunk reset. |
419 readOpenAsZipStreamOn:(globalDataChunk readStream) |
418 zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false. |
420 suppressHeaderAndChecksum:false. |
|
421 zlibReader binary. |
419 zlibReader binary. |
422 bytesPerScanline := self bytesPerRow. |
|
423 |
420 |
424 prevScanline := ByteArray new: bytesPerScanline. |
421 prevScanline := ByteArray new: bytesPerScanline. |
425 thisScanline := ByteArray new: bytesPerScanline. |
422 thisScanline := ByteArray new: bytesPerScanline. |
426 0 to: height - 1 do:[:y | |
423 0 to: height - 1 do:[:y | |
427 filter := zlibReader nextByte. |
424 filter := zlibReader nextByte. |
1258 outStream nextPut: 0 "Non-interlaced" |
1255 outStream nextPut: 0 "Non-interlaced" |
1259 ] |
1256 ] |
1260 ! |
1257 ! |
1261 |
1258 |
1262 writeImageDataChunk |
1259 writeImageDataChunk |
1263 |compressedByteStream compressedBytes zlibWriter bytesPerScanline idx| |
1260 |compressedByteStream compressedBytes zlibWriter idx| |
1264 |
1261 |
1265 compressedByteStream := WriteStream on:(ByteArray new:100). |
1262 bytesPerScanline := self bytesPerRow. |
1266 zlibWriter := ZipStream |
1263 |
1267 writeOpenAsZipStreamOn:compressedByteStream |
1264 compressedByteStream := WriteStream on:(ByteArray new:(bytesPerScanline*height)). |
1268 suppressHeaderAndChecksum:false. |
1265 zlibWriter := ZipStream writeOpenAsZipStreamOn:compressedByteStream suppressHeaderAndChecksum:false. |
1269 zlibWriter binary. |
1266 zlibWriter binary. |
1270 |
|
1271 bytesPerScanline := self bytesPerRow. |
|
1272 |
1267 |
1273 idx := 1. |
1268 idx := 1. |
1274 0 to:height-1 do:[:y | |
1269 0 to:height-1 do:[:y | |
1275 |row| |
1270 |row| |
1276 |
1271 |