author | Jan Vrany <jan.vrany@labware.com> |
Tue, 04 Apr 2023 14:22:18 +0200 | |
branch | jv |
changeset 4473 | 3675eb1de41b |
parent 4132 | 7e5528572373 |
permissions | -rw-r--r-- |
308 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
4132 | 3 |
COPYRIGHT (c) 2015-2016 Jan Vrany |
308 | 4 |
All Rights Reserved |
5 |
||
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
1671 | 13 |
"{ Package: 'stx:libview2' }" |
14 |
||
3461 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
308 | 17 |
ImageReader subclass:#PNGReader |
3821 | 18 |
instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod |
19 |
interlaceMode bytesPerScanline globalDataChunk thisScanline |
|
20 |
prevScanline processTextChunks' |
|
21 |
classVariableNames:'Verbose' |
|
22 |
poolDictionaries:'' |
|
23 |
category:'Graphics-Images-Readers' |
|
308 | 24 |
! |
25 |
||
398 | 26 |
!PNGReader class methodsFor:'documentation'! |
308 | 27 |
|
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
4132 | 31 |
COPYRIGHT (c) 2015-2016 Jan Vrany |
308 | 32 |
All Rights Reserved |
33 |
||
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
||
42 |
||
43 |
! |
|
44 |
||
45 |
documentation |
|
46 |
" |
|
2725 | 47 |
This class will provide methods for loading and saving PNG pictures. |
3599 | 48 |
It is currenty unfinished (some interlaced image formats are unsupported, for example: grayscale+alpha) |
3437 | 49 |
In the meantime, use a pngtoXXX converter for interlaced images, and read XXX. |
308 | 50 |
|
2725 | 51 |
[caveats:] |
52 |
writer ignores any mask (for now). |
|
3599 | 53 |
writer only generates unfiltered non-interlaced data |
2725 | 54 |
|
308 | 55 |
[See also:] |
56 |
Image Form Icon |
|
57 |
BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader |
|
58 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
|
59 |
XBMReader XPMReader XWDReader |
|
60 |
||
61 |
[author:] |
|
62 |
Claus Gittinger |
|
63 |
" |
|
1694 | 64 |
! |
308 | 65 |
|
1694 | 66 |
examples |
67 |
" |
|
68 |
PNGReader fromFile:'/home/cg/AudioExplorer_51_files/use_small.png' |
|
2509 | 69 |
PNGReader fromFile:'\\Exeptn\tmp\images\expeccoScreenshot4020_5526507.png' |
2683 | 70 |
|
71 |
PNGReader fromFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png' |
|
2695 | 72 |
PNGReader fromFile:'C:\Dokumente und Einstellungen\cg\Desktop\misc\PNGs\Delete.png' |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
73 |
PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Delete.png' |
2699 | 74 |
PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Down.png' |
2703 | 75 |
|
76 |
||
77 |
|img img2 outStream png| |
|
2725 | 78 |
|
2703 | 79 |
img := ToolbarIconLibrary error32x32Icon. |
80 |
outStream := WriteStream on:(ByteArray new:100). |
|
81 |
PNGReader save:img onStream:outStream. |
|
82 |
png := outStream contents. |
|
83 |
img2 := PNGReader fromStream:(png readStream). |
|
2708 | 84 |
self assert:(img bits = img2 bits). |
85 |
img inspect. |
|
2703 | 86 |
img2 inspect. |
1694 | 87 |
" |
308 | 88 |
! ! |
89 |
||
398 | 90 |
!PNGReader class methodsFor:'initialization'! |
308 | 91 |
|
92 |
initialize |
|
2699 | 93 |
"install myself in the Image classes fileFormat table for the `.png' extension." |
308 | 94 |
|
2709 | 95 |
MIMETypes defineImageType:'image/png' suffix:'png' reader:self. |
96 |
"/ backward compatibility from times when png was not yet so common... |
|
97 |
MIMETypes defineImageType:'image/x-png' suffix:nil reader:self. |
|
308 | 98 |
! ! |
99 |
||
2705 | 100 |
!PNGReader class methodsFor:'queries'! |
101 |
||
102 |
canRepresent:anImage |
|
103 |
"return true, if anImage can be represented in my file format. |
|
104 |
Any image is supported." |
|
105 |
||
106 |
^ true |
|
107 |
! ! |
|
108 |
||
398 | 109 |
!PNGReader class methodsFor:'testing'! |
308 | 110 |
|
111 |
isValidImageFile:aFileName |
|
112 |
"return true, if aFileName contains a PNG image" |
|
113 |
||
114 |
|inStream magic| |
|
115 |
||
116 |
inStream := self streamReadingFile:aFileName. |
|
117 |
inStream isNil ifTrue:[^ false]. |
|
118 |
||
119 |
inStream binary. |
|
120 |
||
121 |
magic := ByteArray new:8. |
|
122 |
inStream nextBytes:8 into:magic. |
|
123 |
inStream close. |
|
124 |
||
125 |
^ (magic = #[137 80 78 71 13 10 26 10]) |
|
126 |
||
1694 | 127 |
" |
128 |
self isValidImageFile:'/home/cg/AudioExplorer_51_files/use_small.png' |
|
2683 | 129 |
self isValidImageFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png' |
2695 | 130 |
self isValidImageFile:'C:\Dokumente und Einstellungen\cg\Desktop\misc\PNGs\Delete.png' |
1694 | 131 |
" |
132 |
||
308 | 133 |
"Modified: 21.6.1996 / 20:38:46 / cg" |
134 |
! ! |
|
135 |
||
2696 | 136 |
!PNGReader methodsFor:'private-chunks'! |
308 | 137 |
|
2699 | 138 |
doPass: pass |
139 |
"Certain interlace passes are skipped with certain small image dimensions" |
|
140 |
||
141 |
pass = 1 ifTrue: [ ^ true ]. |
|
142 |
((width = 1) and: [height = 1]) ifTrue: [ ^ false ]. |
|
143 |
pass = 2 ifTrue: [ ^ width >= 5 ]. |
|
144 |
pass = 3 ifTrue: [ ^ height >= 5 ]. |
|
145 |
pass = 4 ifTrue: [ ^ (width >=3 ) or: [height >= 5] ]. |
|
146 |
pass = 5 ifTrue: [ ^ height >=3 ]. |
|
147 |
pass = 6 ifTrue: [ ^ width >=2 ]. |
|
148 |
pass = 7 ifTrue: [ ^ height >=2 ]. |
|
149 |
||
150 |
self error:'invalid argument'. |
|
151 |
^ true |
|
152 |
! |
|
153 |
||
308 | 154 |
processBKGDChunkLen:len |
155 |
inStream skip:len. |
|
156 |
^ true |
|
157 |
||
158 |
"Created: 21.6.1996 / 21:15:49 / cg" |
|
159 |
! |
|
160 |
||
2707 | 161 |
processCHRMChunkLen:len |
162 |
"cHRM Primary chromaticities chunk - currently unhandled" |
|
163 |
||
164 |
|whitePointX whitePointY redX redY greenX greenY blueX blueY| |
|
165 |
||
3554 | 166 |
whitePointX := (inStream nextInt32MSB:true) / 100000.0. |
167 |
whitePointY := (inStream nextInt32MSB:true) / 100000.0. |
|
168 |
redX := (inStream nextInt32MSB:true) / 100000.0. |
|
169 |
redY := (inStream nextInt32MSB:true) / 100000.0. |
|
170 |
greenX := (inStream nextInt32MSB:true) / 100000.0. |
|
171 |
greenY := (inStream nextInt32MSB:true) / 100000.0. |
|
172 |
blueX := (inStream nextInt32MSB:true) / 100000.0. |
|
173 |
blueY := (inStream nextInt32MSB:true) / 100000.0. |
|
2707 | 174 |
|
175 |
Verbose == true ifTrue:[ |
|
176 |
'PNGReader: CHRM chunk ignored:' infoPrintCR. |
|
177 |
'PNGReader: whitePointX:' infoPrint. whitePointX infoPrintCR. |
|
178 |
'PNGReader: whitePointY:' infoPrint. whitePointX infoPrintCR. |
|
179 |
'PNGReader: redX:' infoPrint. redX infoPrintCR. |
|
180 |
'PNGReader: redY:' infoPrint. redY infoPrintCR. |
|
181 |
'PNGReader: greenX:' infoPrint. greenX infoPrintCR. |
|
182 |
'PNGReader: greenY:' infoPrint. greenY infoPrintCR. |
|
183 |
'PNGReader: blueX:' infoPrint. blueX infoPrintCR. |
|
184 |
'PNGReader: blueY:' infoPrint. blueY infoPrintCR. |
|
185 |
]. |
|
186 |
^ true |
|
187 |
! |
|
188 |
||
308 | 189 |
processChunk:type len:len |
2509 | 190 |
|chunk| |
191 |
||
192 |
type = 'IDAT' ifTrue:[ |
|
193 |
"---since the compressed data can span multiple |
|
194 |
chunks, stitch them all together first. later, |
|
195 |
if memory is an issue, we need to figure out how |
|
196 |
to do this on the fly---" |
|
197 |
chunk := inStream next:len. |
|
3821 | 198 |
globalDataChunk isNil ifTrue:[ |
199 |
globalDataChunk := ReadWriteStream on:(ByteArray new:(height * self bytesPerRow)). |
|
200 |
]. |
|
201 |
globalDataChunk nextPutAll:chunk. |
|
2509 | 202 |
^ true |
203 |
]. |
|
204 |
||
308 | 205 |
type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len]. |
206 |
type = 'sBIT' ifTrue:[^ self processSBITChunkLen:len]. |
|
207 |
type = 'tEXt' ifTrue:[^ self processTEXTChunkLen:len]. |
|
208 |
type = 'tIME' ifTrue:[^ self processTIMEChunkLen:len]. |
|
209 |
type = 'bKGD' ifTrue:[^ self processBKGDChunkLen:len]. |
|
210 |
type = 'zTXt' ifTrue:[^ self processZTXTChunkLen:len]. |
|
211 |
type = 'PLTE' ifTrue:[^ self processPLTEChunkLen:len]. |
|
212 |
||
1671 | 213 |
type = 'pHYs' ifTrue:[^ self processPHYSChunkLen:len]. |
2707 | 214 |
type = 'cHRM' ifTrue:[^ self processCHRMChunkLen:len]. |
1671 | 215 |
type = 'tRNS' ifTrue:[^ self processTRNSChunkLen:len]. |
216 |
type = 'IHDR' ifTrue:[^ self processIHDRChunkLen:len]. |
|
217 |
||
3762 | 218 |
type = 'iTXt' ifTrue:[^ self processITXTChunkLen:len]. |
219 |
type = 'iCCP' ifTrue:[^ self processICCPChunkLen:len]. |
|
220 |
||
308 | 221 |
('PNGReader: unrecognized chunk: ' , type , ' ignored.') infoPrintCR. |
222 |
||
223 |
inStream skip:len. |
|
224 |
^ true. |
|
225 |
||
226 |
"Created: 21.6.1996 / 21:10:37 / cg" |
|
227 |
"Modified: 21.6.1996 / 21:22:37 / cg" |
|
228 |
! |
|
229 |
||
230 |
processGAMAChunkLen:len |
|
231 |
inStream skip:len. |
|
232 |
^ true |
|
233 |
||
234 |
"Created: 21.6.1996 / 21:10:52 / cg" |
|
235 |
! |
|
236 |
||
2509 | 237 |
processGlobalIDATChunk |
238 |
interlaceMode == 0 ifTrue: [ |
|
239 |
^ self processNonInterlacedGlobalDATA |
|
240 |
]. |
|
241 |
^ self processInterlacedGlobalDATA |
|
242 |
! |
|
243 |
||
3762 | 244 |
processICCPChunkLen:len |
245 |
"/ ignored |
|
246 |
"/ inStream nextBytes:len. |
|
247 |
||
248 |
inStream skip:len. |
|
249 |
^ true |
|
250 |
||
251 |
"Created: 21.6.1996 / 21:15:58 / cg" |
|
252 |
! |
|
253 |
||
308 | 254 |
processIDATChunkLen:len |
1671 | 255 |
interlaceMode == 0 ifTrue: [ |
256 |
^ self processNonInterlacedDATA:len |
|
257 |
]. |
|
258 |
^ self processInterlacedDATA:len |
|
259 |
! |
|
260 |
||
3762 | 261 |
processIHDRChunkLen:len |
262 |
"/ ignored |
|
263 |
||
264 |
inStream skip:len. |
|
265 |
^ true |
|
266 |
||
267 |
"Created: 21.6.1996 / 21:15:58 / cg" |
|
268 |
! |
|
269 |
||
270 |
processITXTChunkLen:len |
|
271 |
"/ international (i.e.utf8) textual data. |
|
272 |
||
273 |
"/ currently ignored - not needed to display png images |
|
274 |
"/ |
|
275 |
"/ Keyword: 1-79 bytes (character string) |
|
276 |
"/ Null separator: 1 byte |
|
277 |
"/ Compression flag: 1 byte |
|
278 |
"/ Compression method: 1 byte |
|
279 |
"/ Language tag: 0 or more bytes (character string) |
|
280 |
"/ Null separator: 1 byte |
|
281 |
"/ Translated keyword: 0 or more bytes |
|
282 |
"/ Null separator: 1 byte |
|
283 |
"/ Text: 0 or more bytes |
|
284 |
||
285 |
"/ if needed, set processTextChunks to true somewhere... |
|
286 |
processTextChunks == true ifTrue:[ |
|
287 |
|chunkData keyword text i1 i2 i3 |
|
288 |
compressionFlag compressionMethod languageTag |
|
289 |
xlatedKeyword textBytes| |
|
290 |
||
291 |
chunkData := inStream nextBytes:len. |
|
292 |
i1 := chunkData indexOf:0. |
|
293 |
keyword := (chunkData copyTo:i1-1) asString. |
|
294 |
compressionFlag := chunkData at:i1+1. |
|
295 |
compressionMethod := chunkData at:i1+2. |
|
296 |
i2 := chunkData indexOf:0 startingAt:i1+3. |
|
297 |
languageTag := (chunkData copyFrom:i1+3 to:i2-1) asString. |
|
298 |
i3 := chunkData indexOf:0 startingAt:i2+1. |
|
299 |
xlatedKeyword := (chunkData copyFrom:i2+1 to:i3-1) asString. |
|
300 |
textBytes := chunkData copyFrom:i3+1. |
|
301 |
compressionFlag == 0 ifTrue:[ |
|
302 |
text := textBytes |
|
303 |
] ifFalse:[ |
|
304 |
compressionFlag == 1 ifTrue:[ |
|
305 |
"/ for now, only zlib compression is supported... |
|
306 |
'zlib compression currently unsupported' infoPrintCR. |
|
307 |
] ifFalse:[ |
|
308 |
'unsupported compression method' infoPrintCR. |
|
309 |
]. |
|
310 |
]. |
|
311 |
text := text utf8Decoded. |
|
312 |
self handleText:text keyword:keyword. |
|
313 |
] ifFalse:[ |
|
314 |
inStream skip:len. |
|
315 |
]. |
|
316 |
^ true |
|
317 |
||
318 |
"Created: 21.6.1996 / 21:15:58 / cg" |
|
319 |
! |
|
320 |
||
1671 | 321 |
processInterlacedDATA:len |
308 | 322 |
inStream skip:len. |
323 |
^ true |
|
1671 | 324 |
! |
308 | 325 |
|
2699 | 326 |
processInterlacedGlobalDATA |
3327 | 327 |
"adam7 interlace method" |
328 |
||
3612 | 329 |
| zlibReader filter |
330 |
bytesPerPass startingCol colIncrement rowIncrement |
|
331 |
startingRow |
|
332 |
temp "filtersSeen" |
|
333 |
cx "{ Class: SmallInteger }" |
|
334 |
sc "{ Class: SmallInteger }" |
|
335 |
cy "{ Class: SmallInteger }" |
|
336 |
startRow "{ Class: SmallInteger }" |
|
337 |
w "{ Class: SmallInteger }" |
|
338 |
h "{ Class: SmallInteger }" |
|
339 |
| |
|
2699 | 340 |
|
3327 | 341 |
interlaceMode == 1 ifFalse: [ |
342 |
self error:'unsupported interlaced mode'. |
|
343 |
^ self |
|
344 |
]. |
|
2699 | 345 |
|
346 |
"/ filtersSeen := Set new. |
|
347 |
||
348 |
startingCol := #(0 4 0 2 0 1 0 ). |
|
3327 | 349 |
startingRow := #(0 0 4 0 2 0 1 ). |
2699 | 350 |
colIncrement := #(8 8 4 4 2 2 1 ). |
351 |
rowIncrement := #(8 8 8 4 4 2 2 ). |
|
352 |
||
3821 | 353 |
globalDataChunk reset. |
354 |
zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false. |
|
2699 | 355 |
zlibReader binary. |
356 |
||
3612 | 357 |
h := height. |
358 |
w := width. |
|
2699 | 359 |
1 to: 7 do: [:pass | |
360 |
(self doPass: pass) ifTrue:[ |
|
361 |
cx := colIncrement at: pass. |
|
362 |
sc := startingCol at: pass. |
|
3327 | 363 |
cy := rowIncrement at: pass. |
3612 | 364 |
bytesPerPass := (((w - sc + cx - 1) // cx * depth) + 7) // 8. |
2699 | 365 |
prevScanline := ByteArray new: bytesPerPass. |
366 |
thisScanline := ByteArray new: bytesPerScanline. |
|
3612 | 367 |
startRow := startingRow at: pass. |
368 |
startRow to: h-1 by: cy do: [:y | |
|
3343 | 369 |
filter := zlibReader nextByte. |
2699 | 370 |
"/ filtersSeen add: filter. |
371 |
(filter isNil or: [(filter between: 0 and: 4) not]) |
|
372 |
ifTrue: [^ self]. |
|
373 |
zlibReader next: bytesPerPass into: thisScanline startingAt: 1. |
|
374 |
filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerPass ]. |
|
375 |
self copyPixels:y at:sc by:cx. |
|
376 |
temp := prevScanline. |
|
377 |
prevScanline := thisScanline. |
|
378 |
thisScanline := temp. |
|
379 |
] |
|
380 |
] |
|
381 |
]. |
|
382 |
zlibReader atEnd ifFalse:[self error:'Unexpected data']. |
|
2909 | 383 |
|
384 |
"Modified: / 03-05-2011 / 12:03:33 / cg" |
|
2699 | 385 |
! |
386 |
||
1671 | 387 |
processNonInterlacedDATA:len |
2701 | 388 |
self halt:'not used' |
389 |
"/ |
|
390 |
"/ | zlibReader filter temp prevScanline thisScanline bytesPerScanline filtersSeen| |
|
391 |
"/ |
|
392 |
"/ zlibReader := ZipStream readOpenAsZipStreamOn:inStream suppressHeaderAndChecksum:false. |
|
393 |
"/ "/ zlibReader := ZLibReadStream on:inStream from: 1 to:len. |
|
394 |
"/ |
|
395 |
"/ prevScanline := ByteArray new: self bytesPerRow. |
|
396 |
"/ thisScanline := ByteArray new: self bytesPerRow. |
|
397 |
"/ 0 to: height - 1 do:[:index | |
|
398 |
"/ filter := (zlibReader next: 1) first. |
|
399 |
"/ filtersSeen add: filter. |
|
400 |
"/ (filter isNil or: [(filter between: 0 and: 4) not]) ifTrue: [^self]. |
|
401 |
"/ thisScanline := zlibReader next: bytesPerScanline into: thisScanline startingAt: 1. |
|
402 |
"/ self filterScanline: filter count: bytesPerScanline. |
|
403 |
"/ self copyPixels: index. |
|
404 |
"/ temp := prevScanline. |
|
405 |
"/ prevScanline := thisScanline. |
|
406 |
"/ thisScanline := temp |
|
407 |
"/ ] |
|
2509 | 408 |
! |
409 |
||
410 |
processNonInterlacedGlobalDATA |
|
3821 | 411 |
| "data n" zlibReader filter temp "filtersSeen" i| |
2696 | 412 |
|
413 |
"/ filtersSeen := Set new. |
|
2695 | 414 |
|
415 |
"/ data := ByteArray new:(self bytesPerRow * height)+1000. |
|
416 |
"/ n := ZipStream uncompress: globalDataChunk into: data. |
|
417 |
"/ self halt. |
|
2509 | 418 |
|
3821 | 419 |
globalDataChunk reset. |
420 |
zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false. |
|
2696 | 421 |
zlibReader binary. |
2509 | 422 |
|
1671 | 423 |
prevScanline := ByteArray new: bytesPerScanline. |
424 |
thisScanline := ByteArray new: bytesPerScanline. |
|
2725 | 425 |
0 to: height - 1 do:[:y | |
3343 | 426 |
filter := zlibReader nextByte. |
2696 | 427 |
"/ filtersSeen add: filter. |
2725 | 428 |
(filter notNil and: [filter between: 0 and: 4]) ifFalse: [ |
3673 | 429 |
'PNGReader: unsupported filter: ' infoPrint. filter infoPrintCR. |
2725 | 430 |
^ self |
431 |
]. |
|
2696 | 432 |
zlibReader next: bytesPerScanline into: thisScanline startingAt: 1. |
433 |
filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerScanline ]. |
|
2725 | 434 |
|
435 |
i := y * bytesPerScanline. |
|
436 |
data replaceFrom:i+1 to:(i+bytesPerScanline) with:thisScanline startingAt:1. |
|
437 |
||
2695 | 438 |
temp := prevScanline. |
439 |
prevScanline := thisScanline. |
|
440 |
thisScanline := temp |
|
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
441 |
]. |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
442 |
"/ Fill in mask if image contains alpha channel |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
443 |
photometric == #rgba ifTrue:[ |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
444 |
| maskBits | |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
445 |
|
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
446 |
mask := AlphaMask width: width height: height. |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
447 |
maskBits := ByteArray new: width * height. |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
448 |
|
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
449 |
0 to: height - 1 do:[:y | |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
450 |
0 to: width - 1 do:[:x | |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
451 |
| alpha | |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
452 |
|
3854 | 453 |
alpha := data at: (y * bytesPerScanline) + (x * 4) + 1. |
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
454 |
maskBits at: (y*width) + x + 1 put: alpha |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
455 |
] |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
456 |
]. |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
457 |
mask bits: maskBits |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
458 |
]. |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
459 |
|
3642
79f73b8182e2
PNGReader: Remove obsolete wrong check for depth
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3619
diff
changeset
|
460 |
"Modified: / 11-04-2016 / 08:39:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1671 | 461 |
! |
462 |
||
463 |
processPHYSChunkLen:len |
|
464 |
"physical pixel chunk - currently unhandled" |
|
465 |
||
2705 | 466 |
|pixelPerUnitX pixelPerUnitY unit| |
467 |
||
3554 | 468 |
pixelPerUnitX := inStream nextInt32MSB:true. |
469 |
pixelPerUnitY := inStream nextInt32MSB:true. |
|
2705 | 470 |
unit := inStream nextByte. |
471 |
||
2707 | 472 |
Verbose == true ifTrue:[ |
473 |
'PNGReader: PHYS chunk ignored:' infoPrintCR. |
|
474 |
'PNGReader: ppuX:' infoPrint. pixelPerUnitX infoPrintCR. |
|
475 |
'PNGReader: ppuY:' infoPrint. pixelPerUnitY infoPrintCR. |
|
476 |
'PNGReader: unit:' infoPrint. unit infoPrintCR. |
|
477 |
]. |
|
478 |
||
2705 | 479 |
^ true |
308 | 480 |
! |
481 |
||
482 |
processPLTEChunkLen:len |
|
1671 | 483 |
"read a color palette" |
484 |
||
2725 | 485 |
|n "{ Class: SmallInteger }" |
486 |
redBytes greenBytes blueBytes| |
|
308 | 487 |
|
488 |
(len \\ 3) ~~ 0 ifTrue:[ |
|
489 |
'PNGReader: invalid size of PLTE chunk' infoPrintCR. |
|
490 |
^ false |
|
491 |
]. |
|
492 |
n := len // 3. |
|
493 |
redBytes := ByteArray new:n. |
|
494 |
greenBytes := ByteArray new:n. |
|
495 |
blueBytes := ByteArray new:n. |
|
496 |
||
497 |
1 to:n do:[:i | |
|
498 |
redBytes at:i put:(inStream nextByte). |
|
499 |
greenBytes at:i put:(inStream nextByte). |
|
500 |
blueBytes at:i put:(inStream nextByte) |
|
501 |
]. |
|
502 |
||
2725 | 503 |
colorMap := MappedPalette |
504 |
redVector:redBytes |
|
505 |
greenVector:greenBytes |
|
506 |
blueVector:blueBytes. |
|
507 |
||
308 | 508 |
^ true |
509 |
||
510 |
"Created: 21.6.1996 / 21:22:28 / cg" |
|
511 |
"Modified: 21.6.1996 / 21:43:01 / cg" |
|
512 |
! |
|
513 |
||
514 |
processSBITChunkLen:len |
|
515 |
inStream skip:len. |
|
516 |
^ true |
|
517 |
||
518 |
"Created: 21.6.1996 / 21:13:09 / cg" |
|
519 |
! |
|
520 |
||
3762 | 521 |
processTEXTChunkLen:len |
522 |
"/ textual data in iso8859 coding. |
|
523 |
||
524 |
"/ currently ignored - not needed to display png images |
|
525 |
"/ Keyword: 1-79 bytes (character string) |
|
526 |
"/ Null separator: 1 byte |
|
527 |
"/ Text: n bytes (character string) |
|
528 |
||
529 |
"/ if needed, set processTextChunks to true somewhere... |
|
530 |
processTextChunks == true ifTrue:[ |
|
531 |
|chunkData keyword text i| |
|
532 |
||
533 |
chunkData := inStream nextBytes:len. |
|
534 |
i := chunkData indexOf:0. |
|
535 |
keyword := (chunkData copyTo:i-1) asString. |
|
536 |
text := (chunkData copyFrom:i+1) asString. |
|
537 |
self handleText:text keyword:keyword. |
|
538 |
] ifFalse:[ |
|
539 |
inStream skip:len. |
|
540 |
]. |
|
308 | 541 |
^ true |
542 |
||
543 |
"Modified: 21.6.1996 / 21:15:27 / cg" |
|
544 |
! |
|
545 |
||
546 |
processTIMEChunkLen:len |
|
547 |
inStream skip:len. |
|
548 |
^ true |
|
549 |
||
550 |
"Created: 21.6.1996 / 21:15:43 / cg" |
|
551 |
"Modified: 21.6.1996 / 21:20:42 / cg" |
|
552 |
! |
|
553 |
||
2707 | 554 |
processTRNSChunkLen:len |
555 |
inStream skip:len. |
|
556 |
^ true |
|
557 |
! |
|
558 |
||
308 | 559 |
processZTXTChunkLen:len |
3762 | 560 |
"/ compressed text |
561 |
||
562 |
"/ currently ignored - not needed to display png images |
|
308 | 563 |
inStream skip:len. |
564 |
^ true |
|
565 |
||
566 |
"Created: 21.6.1996 / 21:15:58 / cg" |
|
567 |
! ! |
|
568 |
||
2696 | 569 |
!PNGReader methodsFor:'private-filtering'! |
570 |
||
2909 | 571 |
filterAverage:count |
2699 | 572 |
"Use the average of the pixel to the left and the pixel above as a predictor" |
2909 | 573 |
|
574 |
|delta| |
|
2699 | 575 |
|
3609 | 576 |
%{ |
577 |
if (__isByteArray(__INST(thisScanline)) |
|
578 |
&& __isByteArray(__INST(prevScanline)) |
|
579 |
&& __isSmallInteger(__INST(depth)) |
|
580 |
&& __isSmallInteger(count)) { |
|
581 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
582 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
583 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
584 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
585 |
INT __count = __intVal(count); |
|
586 |
INT __delta = __intVal(__INST(depth)) / 8; |
|
587 |
int __i; |
|
588 |
||
589 |
if (__delta < 1) __delta = 1; |
|
590 |
for (__i=0; __i<__delta; __i++) { |
|
591 |
__thisScanline[__i] += (__prevScanline[__i] >> 1); |
|
592 |
} |
|
593 |
for (; __i < __count; __i++) { |
|
594 |
__thisScanline[__i] += ((__prevScanline[__i] + __thisScanline[__i-__delta]) >> 1); |
|
595 |
} |
|
596 |
RETURN(self); |
|
597 |
} |
|
598 |
%}. |
|
599 |
||
600 |
delta := depth // 8 max:1. |
|
2909 | 601 |
1 to:delta do:[:i | |
3384 | 602 |
thisScanline at:i put:((thisScanline at:i) + ((prevScanline at:i) // 2) bitAnd:255) |
2909 | 603 |
]. |
604 |
delta + 1 to:count do:[:i | |
|
3384 | 605 |
thisScanline at:i put:((thisScanline at:i) + (((prevScanline at:i) + (thisScanline at:i - delta)) // 2) bitAnd:255) |
2909 | 606 |
] |
607 |
||
608 |
"Modified: / 03-05-2011 / 12:14:01 / cg" |
|
2699 | 609 |
! |
610 |
||
2696 | 611 |
filterHorizontal:count |
612 |
"use the pixel to the left as a predictor" |
|
613 |
||
614 |
|delta| |
|
615 |
||
3608 | 616 |
%{ |
617 |
if (__isByteArray(__INST(thisScanline)) |
|
618 |
&& __isByteArray(__INST(prevScanline)) |
|
619 |
&& __isSmallInteger(__INST(depth)) |
|
620 |
&& __isSmallInteger(count)) { |
|
621 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
622 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
623 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
624 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
625 |
INT __count = __intVal(count); |
|
626 |
INT __delta = __intVal(__INST(depth)) / 8; |
|
627 |
int __i; |
|
628 |
||
629 |
if (__delta < 1) __delta = 1; |
|
630 |
for (__i = __delta; __i < __count; __i++) { |
|
631 |
__thisScanline[__i] = __thisScanline[__i] + __thisScanline[__i-__delta]; |
|
632 |
} |
|
633 |
RETURN(self); |
|
634 |
} |
|
635 |
%}. |
|
636 |
||
637 |
delta := depth // 8 max:1. |
|
2696 | 638 |
delta+1 to:count do:[:i| |
639 |
thisScanline at:i put:(((thisScanline at:i)+ (thisScanline at:i-delta)) bitAnd:255) |
|
640 |
] |
|
641 |
! |
|
642 |
||
2699 | 643 |
filterNone: count |
2909 | 644 |
"/ no filter - scanline is as is |
645 |
||
646 |
"Modified: / 03-05-2011 / 12:14:20 / cg" |
|
2699 | 647 |
! |
648 |
||
2909 | 649 |
filterPaeth:count |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
650 |
"Select one of (the pixel to the left, the pixel above and the pixel to above left) to |
2909 | 651 |
predict the value of this pixel" |
652 |
||
653 |
|delta| |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
654 |
|
3607 | 655 |
%{ |
656 |
if (__isByteArray(__INST(thisScanline)) |
|
657 |
&& __isByteArray(__INST(prevScanline)) |
|
658 |
&& __isSmallInteger(__INST(depth)) |
|
659 |
&& __isSmallInteger(count)) { |
|
660 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
661 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
662 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
663 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
664 |
INT __count = __intVal(count); |
|
665 |
INT __delta = __intVal(__INST(depth)) / 8; |
|
666 |
int __i; |
|
667 |
||
668 |
if (__delta < 1) __delta = 1; |
|
669 |
for (__i=0; __i<__delta; __i++) { |
|
670 |
unsigned int __pix = __thisScanline[__i] + __prevScanline[__i]; |
|
671 |
__thisScanline[__i] = __pix; |
|
672 |
} |
|
673 |
for (; __i < __count; __i++) { |
|
674 |
int __pCenter = __thisScanline[__i]; |
|
675 |
int __pLeft = __thisScanline[__i - __delta]; |
|
676 |
int __pAbove = __prevScanline[__i]; |
|
677 |
int __pAboveLeft = __prevScanline[__i - __delta]; |
|
678 |
int __pa, __pb, __pc; |
|
679 |
int __p; |
|
680 |
||
681 |
__pa = (__pAbove - __pAboveLeft); |
|
682 |
__pa = __pa < 0 ? -__pa : __pa; |
|
683 |
__pb = (__pLeft - __pAboveLeft); |
|
684 |
__pb = __pb < 0 ? -__pb : __pb; |
|
685 |
__pc = __pLeft + __pAbove - __pAboveLeft - __pAboveLeft; |
|
686 |
__pc = __pc < 0 ? -__pc : __pc; |
|
687 |
if ((__pa <= __pb) && (__pa <= __pc)) __p = __pLeft; |
|
688 |
else if (__pb <= __pc) __p = __pAbove; |
|
689 |
else __p = __pAboveLeft; |
|
690 |
||
691 |
__thisScanline[__i] = __pCenter + __p; |
|
692 |
} |
|
693 |
RETURN(self); |
|
694 |
} |
|
695 |
%}. |
|
696 |
||
697 |
delta := depth // 8 max:1. |
|
2909 | 698 |
1 to:delta do:[:i | |
699 |
thisScanline |
|
700 |
at:i |
|
701 |
put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255) |
|
702 |
]. |
|
703 |
delta + 1 to:count do:[:i | |
|
704 |
thisScanline |
|
705 |
at:i |
|
706 |
put:(((thisScanline at:i) + (self |
|
707 |
paethPredictLeft:(thisScanline at:i - delta) |
|
708 |
above:(prevScanline at:i) |
|
709 |
aboveLeft:(prevScanline at:i - delta))) |
|
710 |
bitAnd:255) |
|
711 |
] |
|
712 |
||
713 |
"Modified: / 03-05-2011 / 12:14:43 / cg" |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
714 |
! |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
715 |
|
2696 | 716 |
filterScanline:filterType count:count |
3612 | 717 |
filterType == 0 ifTrue:[^ self]. |
718 |
||
2696 | 719 |
self |
3612 | 720 |
perform:(#(filterHorizontal: filterVertical: filterAverage: filterPaeth:) at:filterType) |
2696 | 721 |
with:count |
2909 | 722 |
|
723 |
"Modified: / 03-05-2011 / 12:13:31 / cg" |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
724 |
! |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
725 |
|
2909 | 726 |
filterVertical:count |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
727 |
"Use the pixel above as a predictor" |
2909 | 728 |
|
3608 | 729 |
%{ |
730 |
if (__isByteArray(__INST(thisScanline)) |
|
731 |
&& __isByteArray(__INST(prevScanline)) |
|
732 |
&& __isSmallInteger(count)) { |
|
733 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
734 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
735 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
736 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
737 |
INT __count = __intVal(count); |
|
738 |
int __i; |
|
739 |
||
740 |
for (__i=0; __i<__count; __i++) { |
|
741 |
unsigned int __pix = __thisScanline[__i] + __prevScanline[__i]; |
|
742 |
__thisScanline[__i] = __pix; |
|
743 |
} |
|
744 |
RETURN(self); |
|
745 |
} |
|
746 |
%}. |
|
747 |
||
2909 | 748 |
1 to:count do:[:i | |
749 |
thisScanline |
|
750 |
at:i |
|
751 |
put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255) |
|
752 |
] |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
753 |
|
2909 | 754 |
"Modified: / 03-05-2011 / 12:14:34 / cg" |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
755 |
! |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
756 |
|
3607 | 757 |
paethPredictLeft: l above: a aboveLeft: al |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
758 |
"Predicts the value of a pixel based on nearby pixels, based on Paeth (GG II, 1991)" |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
759 |
|
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
760 |
| pa pb pc | |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
761 |
|
3607 | 762 |
pa := a > al ifTrue: [a - al] ifFalse: [al - a]. |
763 |
pb := l > al ifTrue: [l - al] ifFalse: [al - l]. |
|
764 |
pc := l + a - al - al. |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
765 |
pc < 0 ifTrue: [ |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
766 |
pc := pc * -1 |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
767 |
]. |
3607 | 768 |
((pa <= pb) and: [pa <= pc]) ifTrue: [^ l]. |
769 |
(pb <= pc) ifTrue: [^ a]. |
|
770 |
^ al |
|
2696 | 771 |
! ! |
772 |
||
2699 | 773 |
!PNGReader methodsFor:'private-pixel copy'! |
774 |
||
2909 | 775 |
copyPixels:y at:startX by:incX |
2704 | 776 |
"Handle interlaced pixels of supported colorTypes" |
2909 | 777 |
|
778 |
|s| |
|
2699 | 779 |
|
3598 | 780 |
"/ per color type copy methods |
781 |
s := #( |
|
782 |
#copyPixelsGray:at:by: "/ 0 |
|
2909 | 783 |
nil |
3598 | 784 |
#copyPixelsRGB:at:by: "/ 2 |
785 |
#copyPixelsIndexed:at:by: "/ 3 |
|
786 |
#copyPixelsGrayAlpha:at:by: "/ 4 |
|
2909 | 787 |
nil |
3598 | 788 |
#copyPixelsRGBA:at:by: "/ 6 |
2909 | 789 |
) at:colorType + 1. |
3437 | 790 |
self perform:s with:y with:startX with:incX |
1848 | 791 |
|
2909 | 792 |
"Modified: / 03-05-2011 / 12:02:45 / cg" |
3327 | 793 |
! |
794 |
||
3598 | 795 |
copyPixelsGray:y at:startX by:incX |
796 |
"Handle interlaced pixels of supported colorTypes. |
|
797 |
Untested code - please verify" |
|
798 |
||
3611 | 799 |
|srcIndex "{ Class: SmallInteger }" |
800 |
srcMask "{ Class: SmallInteger }" |
|
801 |
nPixels "{ Class: SmallInteger }" |
|
802 |
dstIndex "{ Class: SmallInteger }" |
|
803 |
dstMask "{ Class: SmallInteger }" |
|
804 |
x "{ Class: SmallInteger }" |
|
805 |
bits "{ Class: SmallInteger }" |
|
806 |
bitMask "{ Class: SmallInteger }" |
|
807 |
rS "{ Class: SmallInteger }" |
|
808 |
lS "{ Class: SmallInteger }" |
|
809 |
rowIndex "{ Class: SmallInteger }"| |
|
3598 | 810 |
|
811 |
nPixels := width // incX. |
|
812 |
srcIndex := 0. srcMask := 0. x := startX. |
|
813 |
||
814 |
depth == 1 ifTrue:[ |
|
815 |
dstIndex := (y * bytesPerScanline) + (startX // 8) + 1. |
|
816 |
dstMask := 16r80 >> (x \\ 8). |
|
817 |
||
818 |
1 to:nPixels do:[:cnt | |
|
819 |
srcMask == 0 ifTrue:[ |
|
820 |
srcMask := 16r80. |
|
821 |
srcIndex := srcIndex + 1. |
|
822 |
bits := thisScanline at:srcIndex. |
|
823 |
]. |
|
824 |
bitMask := (bits bitAnd:srcMask) == 0 ifTrue:[0] ifFalse:[dstMask]. |
|
825 |
bitMask ~~ 0 ifTrue:[ |
|
826 |
data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
827 |
]. |
|
828 |
x := x + incX. |
|
829 |
dstMask := dstMask >> incX. |
|
830 |
dstMask == 0 ifTrue:[ |
|
831 |
dstIndex := dstIndex + 1. |
|
832 |
dstMask := 16r80 >> (x \\ 8). |
|
833 |
]. |
|
834 |
srcMask := srcMask bitShift:-1. |
|
835 |
]. |
|
836 |
^ self. |
|
837 |
]. |
|
838 |
||
839 |
depth == 2 ifTrue:[ |
|
840 |
dstIndex := (y * bytesPerScanline) + (startX // 4) + 1. |
|
841 |
lS := 6 - ((x \\ 4) * 2). |
|
842 |
rS := -1. |
|
843 |
1 to:nPixels do:[:cnt | |
|
844 |
rS < 0 ifTrue:[ |
|
845 |
srcIndex := srcIndex + 1. |
|
846 |
bits := thisScanline at:srcIndex. |
|
847 |
rS := 6. |
|
848 |
]. |
|
849 |
bitMask := ((bits >> rS) bitAnd:2r11). |
|
850 |
bitMask ~~ 0 ifTrue:[ |
|
851 |
bitMask := bitMask << lS. |
|
852 |
data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
853 |
]. |
|
854 |
lS := lS - (incX * 2). |
|
855 |
lS < 0 ifTrue:[ |
|
856 |
lS <= -8 ifTrue:[ |
|
857 |
dstIndex := dstIndex + 2. |
|
858 |
lS := lS + 8 + 8. |
|
859 |
] ifFalse:[ |
|
860 |
dstIndex := dstIndex + 1. |
|
861 |
lS := lS + 8. |
|
862 |
]. |
|
863 |
]. |
|
864 |
rS := rS - 2. |
|
865 |
]. |
|
866 |
^ self. |
|
867 |
]. |
|
868 |
||
869 |
depth == 4 ifTrue:[ |
|
870 |
rowIndex := (y * bytesPerScanline) + 1. |
|
871 |
dstIndex := rowIndex + (x // 2). |
|
872 |
rS := -1. |
|
873 |
1 to:nPixels do:[:cnt | |
|
874 |
rS < 0 ifTrue:[ |
|
875 |
srcIndex := srcIndex + 1. |
|
876 |
bits := thisScanline at:srcIndex. |
|
877 |
rS := 4. |
|
878 |
]. |
|
879 |
bitMask := ((bits >> rS) bitAnd:2r1111). |
|
880 |
x even ifTrue:[ |
|
881 |
bitMask := bitMask bitShift:4. |
|
882 |
]. |
|
883 |
data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
884 |
x := x + incX. |
|
885 |
dstIndex := rowIndex + (x // 2). |
|
886 |
rS := rS - 4. |
|
887 |
]. |
|
888 |
^ self. |
|
889 |
]. |
|
890 |
||
891 |
depth == 8 ifTrue:[ |
|
892 |
srcIndex := 1. |
|
893 |
dstIndex := (y * bytesPerScanline) + (startX) + 1. |
|
894 |
||
895 |
1 to:nPixels do:[:n | |
|
896 |
data at:dstIndex put:(thisScanline at:srcIndex). |
|
897 |
srcIndex := srcIndex + 1. |
|
898 |
dstIndex := dstIndex + incX |
|
899 |
]. |
|
900 |
^ self. |
|
901 |
]. |
|
902 |
||
903 |
depth == 16 ifTrue:[ |
|
904 |
srcIndex := 1. |
|
905 |
dstIndex := (y * bytesPerScanline) + (startX*2) + 1. |
|
906 |
||
907 |
1 to:nPixels do:[:n | |
|
3601 | 908 |
data unsignedInt16At:dstIndex put:(thisScanline unsignedInt16At:srcIndex). |
3598 | 909 |
srcIndex := srcIndex + 2. |
910 |
dstIndex := dstIndex + (incX * 2) |
|
911 |
]. |
|
912 |
^ self. |
|
913 |
]. |
|
914 |
self error:'unsupported depth'. |
|
915 |
! |
|
916 |
||
917 |
copyPixelsIndexed:y at:startX by:incX |
|
918 |
self copyPixelsGray:y at:startX by:incX |
|
919 |
! |
|
920 |
||
921 |
copyPixelsRGB:y at:startX by:incX |
|
922 |
"Handle interlaced pixels of supported colorTypes. |
|
923 |
Untested code - please verify" |
|
924 |
||
3611 | 925 |
|srcIndex "{ Class: SmallInteger }" |
926 |
nPixels "{ Class: SmallInteger }" |
|
927 |
dstIndex "{ Class: SmallInteger }" |
|
928 |
dstInc "{ Class: SmallInteger }" |
|
929 |
bpp "{ Class: SmallInteger }"| |
|
3598 | 930 |
|
931 |
bpp := bytesPerScanline // width. |
|
932 |
||
933 |
"/ 1 byte per r,g,b |
|
934 |
srcIndex := 1. |
|
935 |
dstIndex := (y * bytesPerScanline) + (startX * bpp) + 1. |
|
936 |
dstInc := incX * bpp. |
|
937 |
||
938 |
nPixels := width // incX. |
|
939 |
1 to:nPixels do:[:n | |
|
940 |
data replaceFrom:dstIndex to:dstIndex+bpp-1 with:thisScanline startingAt:srcIndex. |
|
941 |
srcIndex := srcIndex + bpp. |
|
942 |
dstIndex := dstIndex + dstInc |
|
943 |
]. |
|
944 |
! |
|
945 |
||
3327 | 946 |
copyPixelsRGBA:y at:startX by:incX |
947 |
"Handle interlaced pixels of supported colorTypes. |
|
948 |
Untested code - please verify" |
|
949 |
||
3611 | 950 |
|srcIndex "{ Class: SmallInteger }" |
951 |
nPixels "{ Class: SmallInteger }" |
|
952 |
dstIndex "{ Class: SmallInteger }" |
|
953 |
dstInc "{ Class: SmallInteger }"| |
|
3327 | 954 |
|
955 |
srcIndex := 1. |
|
3437 | 956 |
dstIndex := (y * bytesPerScanline) + (startX * 4) + 1. |
957 |
dstInc := incX * 4. |
|
3327 | 958 |
|
959 |
nPixels := thisScanline size. |
|
960 |
[srcIndex < nPixels] whileTrue:[ |
|
3437 | 961 |
data replaceFrom:dstIndex to:dstIndex+3 with:thisScanline startingAt:srcIndex. |
3327 | 962 |
srcIndex := srcIndex + 4. |
3437 | 963 |
dstIndex := dstIndex + dstInc |
3327 | 964 |
]. |
2699 | 965 |
! ! |
966 |
||
967 |
!PNGReader methodsFor:'private-reading'! |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
968 |
|
2683 | 969 |
getChunk |
970 |
|len type crc| |
|
971 |
||
972 |
inStream atEnd ifTrue:[^ false]. |
|
973 |
||
3554 | 974 |
len := inStream nextInt32MSB:true. |
2683 | 975 |
type := String new:4. |
976 |
(inStream nextBytes:4 into:type) ~~ 4 ifTrue:[^ false]. |
|
977 |
||
2707 | 978 |
Verbose == true ifTrue:[ |
979 |
'len: ' infoPrint. len infoPrint. ' type: ' infoPrint. type infoPrintCR. |
|
980 |
]. |
|
2683 | 981 |
|
982 |
type = 'IEND' ifTrue:[^ false]. |
|
983 |
||
984 |
(self processChunk:type len:len) ifFalse:[^ false]. |
|
985 |
||
3554 | 986 |
crc := inStream nextInt32MSB:true. "/ ignored - for now |
2683 | 987 |
^ true |
988 |
||
989 |
"Created: 21.6.1996 / 21:09:36 / cg" |
|
990 |
"Modified: 21.6.1996 / 21:20:26 / cg" |
|
991 |
! |
|
992 |
||
993 |
getIHDRChunk |
|
994 |
|len type crc| |
|
995 |
||
3554 | 996 |
len := inStream nextInt32MSB:true. |
2683 | 997 |
|
998 |
type := String new:4. |
|
999 |
inStream nextBytes:4 into:type. |
|
1000 |
||
3183 | 1001 |
type = 'IHDR' ifFalse:[self halt:'expected IHDR magic'. ^ false]. |
1002 |
len == 13 ifFalse:[self halt:'unexpected IHDR length'. ^ false]. |
|
2683 | 1003 |
|
3554 | 1004 |
width := inStream nextInt32MSB:true. |
1005 |
height := inStream nextInt32MSB:true. |
|
2683 | 1006 |
|
1007 |
(width <= 0 or:[height <= 0]) ifTrue:[ |
|
1008 |
'PNGReader: invalid dimension(s)' infoPrintCR. |
|
1009 |
^ false. |
|
1010 |
]. |
|
1011 |
self reportDimension. |
|
1012 |
||
3607 | 1013 |
bitsPerChannel := inStream nextByte. |
1014 |
depth := bitsPerChannel. "/ will be changed by setColorType. |
|
2683 | 1015 |
colorType := inStream nextByte. |
1016 |
||
1017 |
compressionMethod := inStream nextByte. |
|
1018 |
filterMethod := inStream nextByte. |
|
1019 |
interlaceMode := inStream nextByte. |
|
1020 |
||
2707 | 1021 |
Verbose == true ifTrue:[ |
1022 |
'PNGReader: IHDR:' infoPrintCR. |
|
1023 |
'PNGReader: width: ' infoPrint. width infoPrintCR. |
|
1024 |
'PNGReader: height: ' infoPrint. height infoPrintCR. |
|
3607 | 1025 |
'PNGReader: bitsPerChannel: ' infoPrint. bitsPerChannel infoPrintCR. |
2707 | 1026 |
'PNGReader: colorType: ' infoPrint. colorType infoPrintCR. |
1027 |
'PNGReader: compressionMethod: ' infoPrint. compressionMethod infoPrintCR. |
|
1028 |
'PNGReader: filterMethod: ' infoPrint. filterMethod infoPrintCR. |
|
1029 |
'PNGReader: interlaceMode: ' infoPrint. interlaceMode infoPrintCR. |
|
1030 |
]. |
|
1031 |
||
3554 | 1032 |
crc := inStream nextInt32MSB:true. |
2683 | 1033 |
^ true |
1034 |
||
1035 |
"Modified: 21.6.1996 / 21:38:35 / cg" |
|
1036 |
! |
|
1037 |
||
3762 | 1038 |
handleText:text keyword:keyword |
1039 |
"/ things like exif data etc. |
|
1040 |
"/ self halt. |
|
1041 |
||
1042 |
"/Standard keywords for text chunks: |
|
1043 |
"/ |
|
1044 |
"/ Title Short (one line) title or caption for image |
|
1045 |
"/ Author Name of image's creator |
|
1046 |
"/ Description Description of image (possibly long) |
|
1047 |
"/ Copyright Copyright notice |
|
1048 |
"/ Creation Time Time of original image creation |
|
1049 |
"/ Software Software used to create the image |
|
1050 |
"/ Disclaimer Legal disclaimer |
|
1051 |
"/ Warning Warning of nature of content |
|
1052 |
"/ Source Device used to create the image |
|
1053 |
"/ Comment Miscellaneous comment; conversion from |
|
1054 |
"/ GIF comment |
|
1055 |
! |
|
1056 |
||
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1057 |
setColorType:pngColorType |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1058 |
pngColorType == 0 ifTrue:[ |
1848 | 1059 |
photometric := #blackIs0. |
1060 |
samplesPerPixel := 1. |
|
3607 | 1061 |
bitsPerSample := Array with:bitsPerChannel. |
1062 |
depth := bitsPerChannel. |
|
1848 | 1063 |
^ true. |
1064 |
]. |
|
1065 |
||
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1066 |
pngColorType == 2 ifTrue:[ |
3607 | 1067 |
bitsPerChannel < 8 ifTrue:[ |
1848 | 1068 |
'PNGReader: invalid colorType/depth combination' infoPrintCR. |
1069 |
^ false. |
|
1070 |
]. |
|
1071 |
photometric := #rgb. |
|
1072 |
samplesPerPixel := 3. |
|
3607 | 1073 |
bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel. |
1074 |
depth := bitsPerChannel * 3. |
|
1848 | 1075 |
^ true. |
1076 |
]. |
|
1077 |
||
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1078 |
pngColorType == 3 ifTrue:[ |
3607 | 1079 |
bitsPerChannel == 16 ifTrue:[ |
1848 | 1080 |
'PNGReader: invalid colorType/depth combination' infoPrintCR. |
1081 |
^ false. |
|
1082 |
]. |
|
1083 |
photometric := #palette. |
|
1084 |
samplesPerPixel := 1. |
|
3607 | 1085 |
bitsPerSample := Array with:bitsPerChannel. |
1086 |
depth := bitsPerChannel. |
|
1848 | 1087 |
^ true. |
1088 |
]. |
|
1089 |
||
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1090 |
pngColorType == 4 ifTrue:[ |
3607 | 1091 |
bitsPerChannel < 8 ifTrue:[ |
1848 | 1092 |
'PNGReader: invalid colorType/depth combination' infoPrintCR. |
1093 |
^ false. |
|
1094 |
]. |
|
1095 |
photometric := #blackIs0. |
|
1096 |
samplesPerPixel := 2. |
|
3607 | 1097 |
bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel. |
1098 |
depth := bitsPerChannel * 2. |
|
1848 | 1099 |
^ true. |
1100 |
]. |
|
1101 |
||
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1102 |
pngColorType == 6 ifTrue:[ |
3607 | 1103 |
bitsPerChannel < 8 ifTrue:[ |
1848 | 1104 |
'PNGReader: invalid colorType/depth combination' infoPrintCR. |
1105 |
^ false. |
|
1106 |
]. |
|
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1107 |
photometric := #rgba. |
1848 | 1108 |
samplesPerPixel := 4. |
3607 | 1109 |
bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel. |
1110 |
depth := bitsPerChannel * 4. |
|
1848 | 1111 |
^ true. |
1112 |
]. |
|
1113 |
||
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1114 |
('PNGReader: invalid colorType: ' , pngColorType printString , '.') infoPrintCR. |
1848 | 1115 |
^ false |
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1116 |
|
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1117 |
"Modified: / 01-09-2015 / 16:02:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1848 | 1118 |
! ! |
1119 |
||
1805 | 1120 |
!PNGReader methodsFor:'reading'! |
308 | 1121 |
|
1122 |
fromStream:aStream |
|
1123 |
"read a stream containing a PNG image. |
|
1124 |
Leave image description in instance variables." |
|
1125 |
||
1126 |
|header| |
|
1127 |
||
1128 |
inStream := aStream. |
|
1129 |
aStream binary. |
|
1130 |
||
1671 | 1131 |
"PNG-files are always msb (network-world)" |
308 | 1132 |
byteOrder := #msb. |
1133 |
||
1134 |
header := ByteArray new:8. |
|
1135 |
aStream nextBytes:8 into:header. |
|
1136 |
||
2683 | 1137 |
header ~= (self pngHeader) ifTrue:[ |
308 | 1138 |
'PNGReader: not a png file.' infoPrintCR. |
3598 | 1139 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: not a png file'. |
308 | 1140 |
^ nil |
1141 |
]. |
|
2695 | 1142 |
|
308 | 1143 |
(self getIHDRChunk) ifFalse:[ |
1144 |
'PNGReader: required IHDR chunk missing.' infoPrintCR. |
|
3598 | 1145 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: required IHDR chunk missing'. |
308 | 1146 |
^ nil |
1147 |
]. |
|
1148 |
||
1149 |
compressionMethod ~~ 0 ifTrue:[ |
|
3598 | 1150 |
('PNGReader: compressionMethod %s not supported.' printfWith:compressionMethod printString) infoPrintCR. |
1151 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: unsupported compression method'. |
|
308 | 1152 |
^ nil |
1153 |
]. |
|
1154 |
filterMethod > 0 ifTrue:[ |
|
1155 |
'PNGReader: invalid filterMethod' infoPrintCR. |
|
3598 | 1156 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported filterMethod'. |
308 | 1157 |
^ nil. |
1158 |
]. |
|
1159 |
interlaceMode > 1 ifTrue:[ |
|
3598 | 1160 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported interlaceMode'. |
308 | 1161 |
'PNGReader: invalid interlaceMode' infoPrintCR. |
1162 |
^ nil. |
|
1163 |
]. |
|
1671 | 1164 |
(self setColorType:colorType) ifFalse:[ |
308 | 1165 |
^ nil |
1671 | 1166 |
]. |
2706 | 1167 |
|
1671 | 1168 |
[self getChunk] whileTrue. |
308 | 1169 |
|
3598 | 1170 |
bytesPerScanline := self bytesPerRow. |
1171 |
data := ByteArray new:(bytesPerScanline * height). |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1172 |
|
2509 | 1173 |
globalDataChunk notNil ifTrue:[ |
3343 | 1174 |
self processGlobalIDATChunk. |
1175 |
globalDataChunk := nil. |
|
2509 | 1176 |
]. |
1177 |
||
308 | 1178 |
photometric == #palette ifTrue:[ |
2725 | 1179 |
colorMap isNil ifTrue:[ |
3598 | 1180 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: palette chunk missing'. |
1181 |
'PNGReader: palette chunk missing.' infoPrintCR. |
|
2725 | 1182 |
"/ ^ nil |
308 | 1183 |
]. |
1184 |
]. |
|
1185 |
||
1186 |
" |
|
1187 |
PNGReader fromFile:'/home/cg/libpng-0.89c/pngtest.png' |
|
1188 |
" |
|
1189 |
||
2910
d5171b9245e6
comment/format in: #fromStream:
Claus Gittinger <cg@exept.de>
parents:
2909
diff
changeset
|
1190 |
"Modified: / 03-05-2011 / 12:17:34 / cg" |
1805 | 1191 |
! ! |
1192 |
||
2683 | 1193 |
!PNGReader methodsFor:'writing to file'! |
1194 |
||
1195 |
pngHeader |
|
1196 |
^ #[137 80 78 71 13 10 26 10] |
|
1197 |
! |
|
1198 |
||
1199 |
save:image onStream:aStream |
|
1200 |
"save image in PNG-file-format onto aStream" |
|
1201 |
||
1202 |
outStream := aStream. |
|
1203 |
outStream binary. |
|
1204 |
||
2703 | 1205 |
byteOrder := #msb. |
2683 | 1206 |
width := image width. |
1207 |
height := image height. |
|
1208 |
photometric := image photometric. |
|
1209 |
samplesPerPixel := image samplesPerPixel. |
|
1210 |
bitsPerSample := image bitsPerSample. |
|
1211 |
colorMap := image colorMap. |
|
1212 |
data := image bits. |
|
1213 |
||
2703 | 1214 |
outStream nextPutAll:(self pngHeader). |
1215 |
self writeIHDRChunk. |
|
1216 |
photometric == #palette ifTrue: [self writePaletteChunk]. |
|
1217 |
self writeImageDataChunk. |
|
2683 | 1218 |
self writeEndChunk |
1219 |
! |
|
1220 |
||
2703 | 1221 |
writeChunk:chunkTypeChars size:len with:aBlock |
2708 | 1222 |
|crc realOutStream chunkBytes| |
1223 |
||
1224 |
realOutStream := outStream. |
|
1225 |
outStream := WriteStream on:(ByteArray new:len). |
|
1226 |
||
2703 | 1227 |
outStream nextPutBytes:4 from:chunkTypeChars startingAt:1. |
1228 |
aBlock value. |
|
2708 | 1229 |
|
1230 |
chunkBytes := outStream contents. |
|
1231 |
crc := CRC32Stream hashValueOf:chunkBytes. |
|
1232 |
||
1233 |
outStream := realOutStream. |
|
1234 |
||
3554 | 1235 |
realOutStream nextPutInt32:len MSB:true. |
2708 | 1236 |
realOutStream nextPutAll:chunkBytes. |
3554 | 1237 |
realOutStream nextPutInt32:crc MSB:true. |
2703 | 1238 |
! |
2683 | 1239 |
|
2703 | 1240 |
writeEndChunk |
1241 |
self |
|
1242 |
writeChunk: 'IEND' |
|
1243 |
size: 0 |
|
1244 |
with:[ ] |
|
2683 | 1245 |
! |
1246 |
||
1247 |
writeFileHeader |
|
1248 |
outStream nextPutAll:(self pngHeader) |
|
1249 |
! |
|
1250 |
||
2703 | 1251 |
writeIHDRChunk |
3100 | 1252 |
((photometric == #whiteIs0) or:[ (photometric == #blackIs0)]) ifTrue:[ |
2703 | 1253 |
colorType := 0. |
3461 | 1254 |
samplesPerPixel > 1 ifTrue:[ colorType := colorType + 4]. "/ +alpha |
2703 | 1255 |
]. |
3724 | 1256 |
((photometric == #rgb) or:[(photometric == #rgba)]) ifTrue:[ |
2703 | 1257 |
colorType := 2. |
3461 | 1258 |
samplesPerPixel > 3 ifTrue:[ colorType := colorType + 4]. "/ +alpha |
2703 | 1259 |
]. |
1260 |
(photometric == #palette) ifTrue:[ |
|
1261 |
colorType := 3. |
|
3461 | 1262 |
samplesPerPixel > 1 ifTrue:[ colorType := colorType + 4]. "/ +alpha |
2703 | 1263 |
]. |
3100 | 1264 |
colorType isNil ifTrue:[ |
3461 | 1265 |
self error:'unhandled photometric' |
3100 | 1266 |
]. |
2703 | 1267 |
|
2683 | 1268 |
self |
1269 |
writeChunk: 'IHDR' |
|
1270 |
size: 13 |
|
1271 |
with:[ |
|
1272 |
self writeLong:width. |
|
1273 |
self writeLong:height. |
|
2703 | 1274 |
outStream nextPut: 8. "Assume that all colors are 24bit" "/ depth |
1275 |
outStream nextPut: colorType. |
|
2683 | 1276 |
outStream nextPut: 0. "Compression" |
1277 |
outStream nextPut: 0. "Filter method" |
|
1278 |
outStream nextPut: 0 "Non-interlaced" |
|
1279 |
] |
|
1280 |
! |
|
1281 |
||
2703 | 1282 |
writeImageDataChunk |
3821 | 1283 |
|compressedByteStream compressedBytes zlibWriter idx| |
2703 | 1284 |
|
1285 |
bytesPerScanline := self bytesPerRow. |
|
3821 | 1286 |
|
1287 |
compressedByteStream := WriteStream on:(ByteArray new:(bytesPerScanline*height)). |
|
1288 |
zlibWriter := ZipStream writeOpenAsZipStreamOn:compressedByteStream suppressHeaderAndChecksum:false. |
|
1289 |
zlibWriter binary. |
|
2703 | 1290 |
|
2708 | 1291 |
idx := 1. |
1292 |
0 to:height-1 do:[:y | |
|
1293 |
|row| |
|
1294 |
||
1295 |
row := data copyFrom:idx to:(idx+bytesPerScanline-1). |
|
1296 |
zlibWriter nextPutAll:#[0]. "/ no filter |
|
1297 |
zlibWriter nextPutAll:row. |
|
1298 |
idx := idx + bytesPerScanline. |
|
2703 | 1299 |
]. |
2708 | 1300 |
|
1301 |
zlibWriter close. |
|
1302 |
compressedBytes := compressedByteStream contents. |
|
1303 |
||
1304 |
self |
|
1305 |
writeChunk: 'IDAT' |
|
1306 |
size:(compressedBytes size) |
|
1307 |
with:[ |
|
1308 |
outStream nextPutAll:compressedBytes |
|
1309 |
] |
|
2703 | 1310 |
! |
1311 |
||
2683 | 1312 |
writePaletteChunk |
1313 |
self |
|
1314 |
writeChunk: 'PLTE' |
|
1315 |
size: 3 * colorMap size |
|
1316 |
with:[ |
|
2703 | 1317 |
colorMap do:[:color | |
1318 |
outStream |
|
1319 |
nextPut: color redByte; |
|
1320 |
nextPut: color greenByte; |
|
1321 |
nextPut: color blueByte |
|
2683 | 1322 |
] |
1323 |
] |
|
1324 |
! ! |
|
1325 |
||
398 | 1326 |
!PNGReader class methodsFor:'documentation'! |
308 | 1327 |
|
1328 |
version |
|
3554 | 1329 |
^ '$Header$' |
2909 | 1330 |
! |
1331 |
||
1332 |
version_CVS |
|
3554 | 1333 |
^ '$Header$' |
3505
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1334 |
! |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1335 |
|
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1336 |
version_HG |
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1337 |
|
af4fb19df063
PNGReader: added support for reading 8bit alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3461
diff
changeset
|
1338 |
^ '$Changeset: <not expanded> $' |
308 | 1339 |
! ! |
1671 | 1340 |
|
3100 | 1341 |
|
308 | 1342 |
PNGReader initialize! |