author | convert-repo |
Mon, 30 Oct 2017 04:34:51 +0000 | |
changeset 4022 | 76677ba2ad6a |
parent 4017 | 0fea2b021ca6 |
child 4044 | 9400ab00cbfc |
permissions | -rw-r--r-- |
308 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1671 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
3461 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
308 | 16 |
ImageReader subclass:#PNGReader |
4005 | 17 |
instanceVariableNames:'colorType bitsPerChannel compressionMethod filterMethod |
3889 | 18 |
interlaceMode bytesPerScanline globalDataChunk thisScanline |
3900 | 19 |
prevScanline processTextChunks specialChunkHandlers |
4017 | 20 |
paletteAlphaEntries paletteIndexForMaskedPixels image forceRGB |
21 |
depthImage' |
|
3909 | 22 |
classVariableNames:'ColorTypeGray ColorTypeGrayAlpha ColorTypePalette ColorTypeRGB |
23 |
ColorTypeRGBAlpha Verbose' |
|
3889 | 24 |
poolDictionaries:'' |
25 |
category:'Graphics-Images-Readers' |
|
308 | 26 |
! |
27 |
||
398 | 28 |
!PNGReader class methodsFor:'documentation'! |
308 | 29 |
|
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
||
43 |
||
44 |
! |
|
45 |
||
46 |
documentation |
|
47 |
" |
|
3893 | 48 |
This class provides methods for loading and saving PNG pictures. |
3599 | 49 |
It is currenty unfinished (some interlaced image formats are unsupported, for example: grayscale+alpha) |
3437 | 50 |
In the meantime, use a pngtoXXX converter for interlaced images, and read XXX. |
308 | 51 |
|
2725 | 52 |
[caveats:] |
3893 | 53 |
writer can only store mask with depth24 images (for now). |
54 |
writer only generates unfiltered non-interlaced data. |
|
2725 | 55 |
|
308 | 56 |
[See also:] |
57 |
Image Form Icon |
|
58 |
BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader |
|
59 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
|
60 |
XBMReader XPMReader XWDReader |
|
61 |
||
62 |
[author:] |
|
63 |
Claus Gittinger |
|
64 |
" |
|
1694 | 65 |
! |
308 | 66 |
|
1694 | 67 |
examples |
68 |
" |
|
69 |
PNGReader fromFile:'/home/cg/AudioExplorer_51_files/use_small.png' |
|
2509 | 70 |
PNGReader fromFile:'\\Exeptn\tmp\images\expeccoScreenshot4020_5526507.png' |
2683 | 71 |
|
72 |
PNGReader fromFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png' |
|
2695 | 73 |
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
|
74 |
PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Delete.png' |
2699 | 75 |
PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Down.png' |
2703 | 76 |
|
77 |
||
78 |
|img img2 outStream png| |
|
2725 | 79 |
|
2703 | 80 |
img := ToolbarIconLibrary error32x32Icon. |
81 |
outStream := WriteStream on:(ByteArray new:100). |
|
82 |
PNGReader save:img onStream:outStream. |
|
83 |
png := outStream contents. |
|
84 |
img2 := PNGReader fromStream:(png readStream). |
|
2708 | 85 |
self assert:(img bits = img2 bits). |
86 |
img inspect. |
|
2703 | 87 |
img2 inspect. |
1694 | 88 |
" |
308 | 89 |
! ! |
90 |
||
398 | 91 |
!PNGReader class methodsFor:'initialization'! |
308 | 92 |
|
93 |
initialize |
|
2699 | 94 |
"install myself in the Image classes fileFormat table for the `.png' extension." |
308 | 95 |
|
2709 | 96 |
MIMETypes defineImageType:'image/png' suffix:'png' reader:self. |
97 |
"/ backward compatibility from times when png was not yet so common... |
|
98 |
MIMETypes defineImageType:'image/x-png' suffix:nil reader:self. |
|
3900 | 99 |
|
100 |
ColorTypeGray := 0. |
|
101 |
ColorTypeRGB := 2. |
|
102 |
ColorTypePalette := 3. |
|
103 |
ColorTypeGrayAlpha := 4. |
|
104 |
ColorTypeRGBAlpha := 6. |
|
105 |
||
106 |
"Modified: / 16-02-2017 / 19:41:40 / cg" |
|
308 | 107 |
! ! |
108 |
||
3909 | 109 |
!PNGReader class methodsFor:'accessing'! |
110 |
||
111 |
pngHeader |
|
112 |
^ #[137 80 78 71 13 10 26 10] |
|
113 |
! ! |
|
114 |
||
2705 | 115 |
!PNGReader class methodsFor:'queries'! |
116 |
||
117 |
canRepresent:anImage |
|
118 |
"return true, if anImage can be represented in my file format. |
|
3893 | 119 |
Any image without mask is supported; |
120 |
only depth24 images with mask are (currently)." |
|
2705 | 121 |
|
3893 | 122 |
anImage mask notNil ifTrue:[ |
123 |
"/ for now, can only write depth24 images with mask |
|
124 |
^ anImage depth == 24 |
|
125 |
]. |
|
2705 | 126 |
^ true |
3893 | 127 |
|
128 |
"Modified (comment): / 16-02-2017 / 16:28:53 / cg" |
|
2705 | 129 |
! ! |
130 |
||
398 | 131 |
!PNGReader class methodsFor:'testing'! |
308 | 132 |
|
133 |
isValidImageFile:aFileName |
|
134 |
"return true, if aFileName contains a PNG image" |
|
135 |
||
136 |
|inStream magic| |
|
137 |
||
138 |
inStream := self streamReadingFile:aFileName. |
|
139 |
inStream isNil ifTrue:[^ false]. |
|
140 |
||
141 |
inStream binary. |
|
142 |
||
143 |
magic := ByteArray new:8. |
|
144 |
inStream nextBytes:8 into:magic. |
|
145 |
inStream close. |
|
146 |
||
147 |
^ (magic = #[137 80 78 71 13 10 26 10]) |
|
148 |
||
1694 | 149 |
" |
150 |
self isValidImageFile:'/home/cg/AudioExplorer_51_files/use_small.png' |
|
2683 | 151 |
self isValidImageFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png' |
2695 | 152 |
self isValidImageFile:'C:\Dokumente und Einstellungen\cg\Desktop\misc\PNGs\Delete.png' |
1694 | 153 |
" |
154 |
||
308 | 155 |
"Modified: 21.6.1996 / 20:38:46 / cg" |
156 |
! ! |
|
157 |
||
3900 | 158 |
!PNGReader methodsFor:'accessing'! |
159 |
||
160 |
makeImage |
|
161 |
image isNil ifTrue:[ |
|
162 |
image := super makeImage. |
|
163 |
]. |
|
164 |
^ image |
|
165 |
||
166 |
"Created: / 17-02-2017 / 11:14:45 / cg" |
|
167 |
! |
|
168 |
||
169 |
pngHeader |
|
3909 | 170 |
<resource: #obsolete> |
171 |
^ self class pngHeader |
|
172 |
||
173 |
"Modified: / 22-02-2017 / 11:00:44 / cg" |
|
3900 | 174 |
! ! |
175 |
||
3889 | 176 |
!PNGReader methodsFor:'hooks'! |
177 |
||
178 |
specialChunkHandlerAt:chunkType put:aHandlerBlock |
|
179 |
"define a handler action, which processes unknown chunks. |
|
180 |
The handler block will be called with one or two arguments: |
|
181 |
the binary data of the chunk, and optionally the reader itself" |
|
182 |
||
183 |
specialChunkHandlers isNil ifTrue:[ |
|
184 |
specialChunkHandlers := Dictionary new |
|
185 |
]. |
|
186 |
specialChunkHandlers at:chunkType put:aHandlerBlock |
|
187 |
||
188 |
"Created: / 14-02-2017 / 11:43:33 / cg" |
|
189 |
! ! |
|
190 |
||
3900 | 191 |
!PNGReader methodsFor:'reading'! |
192 |
||
193 |
fromStream:aStream |
|
194 |
"read a stream containing a PNG image. |
|
195 |
Leave the image description in instance variables |
|
196 |
(i.e. to get the image, ask with image)." |
|
197 |
||
4017 | 198 |
|header bitsPerSampleOut bytesPerScanlineOut| |
3900 | 199 |
|
200 |
inStream := aStream. |
|
201 |
aStream binary. |
|
202 |
||
203 |
"PNG-files are always msb (network-world)" |
|
204 |
byteOrder := #msb. |
|
205 |
||
206 |
header := ByteArray new:8. |
|
207 |
aStream nextBytes:8 into:header. |
|
208 |
||
3909 | 209 |
header = (self class pngHeader) ifFalse:[ |
3900 | 210 |
Logger warning:'PNGReader: not a png file (%1)' with:aStream. |
211 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: not a png file'. |
|
212 |
^ nil |
|
213 |
]. |
|
214 |
||
215 |
(self getIHDRChunk) ifFalse:[ |
|
216 |
Logger warning:'PNGReader: required IHDR chunk missing (%1)' with:aStream. |
|
217 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: required IHDR chunk missing'. |
|
218 |
^ nil |
|
219 |
]. |
|
220 |
||
221 |
compressionMethod ~~ 0 ifTrue:[ |
|
222 |
('PNGReader: compressionMethod %s not supported.' printfWith:compressionMethod printString) infoPrintCR. |
|
223 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: unsupported compression method'. |
|
224 |
^ nil |
|
225 |
]. |
|
226 |
filterMethod > 0 ifTrue:[ |
|
227 |
'PNGReader: invalid filterMethod' infoPrintCR. |
|
228 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported filterMethod'. |
|
229 |
^ nil. |
|
230 |
]. |
|
231 |
interlaceMode > 1 ifTrue:[ |
|
232 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported interlaceMode'. |
|
233 |
'PNGReader: invalid interlaceMode' infoPrintCR. |
|
234 |
^ nil. |
|
235 |
]. |
|
236 |
(self setColorType:colorType) ifFalse:[ |
|
237 |
^ nil |
|
238 |
]. |
|
239 |
||
240 |
[self getChunk] whileTrue. |
|
241 |
||
4017 | 242 |
"/ kludge: if we get a grey image with alpha, |
243 |
"/ load as rgb+alpha |
|
244 |
forceRGB := false. |
|
245 |
depthImage := depth. |
|
246 |
||
247 |
"/ bytesPerScanline is always the in-bytesPerScanline |
|
3900 | 248 |
bytesPerScanline := self bytesPerRow. |
4017 | 249 |
bytesPerScanlineOut := bytesPerScanline. |
250 |
||
251 |
samplesPerPixel == 2 ifTrue:[ |
|
252 |
photometric == #blackIs0 ifTrue:[ |
|
253 |
depth == 16 ifTrue:[ |
|
254 |
"/ force to r8+g8+b8+a8 |
|
255 |
forceRGB := true. |
|
256 |
depthImage := 32. |
|
257 |
bytesPerScanlineOut := width * 4. |
|
258 |
bitsPerSampleOut := #[8 8 8 8]. |
|
259 |
] ifFalse:[ |
|
260 |
depth == 32 ifTrue:[ |
|
261 |
"/ force to r8+g8+b8+a8 |
|
262 |
forceRGB := true. |
|
263 |
depthImage := 32. |
|
264 |
bytesPerScanlineOut := width * 4. |
|
265 |
bitsPerSampleOut := #[8 8 8 8]. |
|
266 |
] ifFalse:[ |
|
267 |
self halt. |
|
268 |
]. |
|
269 |
]. |
|
270 |
]. |
|
271 |
]. |
|
272 |
||
273 |
data := ByteArray new:(bytesPerScanlineOut * height). |
|
274 |
||
3900 | 275 |
globalDataChunk notNil ifTrue:[ |
276 |
self processGlobalIDATChunk. |
|
277 |
globalDataChunk := nil. |
|
278 |
]. |
|
279 |
||
280 |
photometric == #palette ifTrue:[ |
|
281 |
colorMap isNil ifTrue:[ |
|
282 |
Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: palette chunk missing'. |
|
283 |
'PNGReader: palette chunk missing.' infoPrintCR. |
|
284 |
"/ ^ nil |
|
285 |
]. |
|
286 |
]. |
|
287 |
||
288 |
paletteAlphaEntries notNil ifTrue:[ |
|
289 |
"/ this vector now provides alpha values. |
|
290 |
"/ for now, we can only deal with 0/255 alpha values... |
|
3903 | 291 |
self generateMaskFromPaletteAlphaEntries |
3900 | 292 |
]. |
293 |
||
4017 | 294 |
forceRGB ifTrue:[ |
295 |
depth := depthImage. |
|
296 |
photometric := #rgba. |
|
297 |
bitsPerSample := bitsPerSampleOut. |
|
298 |
samplesPerPixel := 4. |
|
299 |
]. |
|
300 |
||
3900 | 301 |
" |
302 |
PNGReader fromFile:'/home/cg/libpng-0.89c/pngtest.png' |
|
3903 | 303 |
|
304 |
Verbose := true. |
|
305 |
PNGReader fromFile:(RegressionTests::ImageReaderTest packageDirectory construct:'testData/pngImages/tbbn3p08.png') |
|
306 |
||
3900 | 307 |
" |
308 |
||
4017 | 309 |
"Modified: / 17-09-2017 / 15:30:45 / cg" |
3900 | 310 |
! ! |
311 |
||
312 |
!PNGReader methodsFor:'reading-private'! |
|
313 |
||
314 |
generateMaskFromPaletteAlphaEntries |
|
315 |
image isNil ifTrue:[ |
|
316 |
self makeImage |
|
317 |
]. |
|
318 |
||
3972 | 319 |
colorType == ColorTypePalette ifTrue:[ |
320 |
image depth == 8 ifTrue:[ |
|
321 |
"/ if there is only one entry to care for... |
|
322 |
(paletteAlphaEntries occurrencesOf:0) == 1 ifTrue:[ |
|
323 |
(paletteAlphaEntries conform:[:alpha | (alpha == 0) or:[alpha == 255]]) ifTrue:[ |
|
324 |
image mask:(self class |
|
325 |
buildMaskFromColor:(paletteAlphaEntries indexOf:0)-1 |
|
326 |
for:data depth:(image depth) |
|
327 |
width:width height:height). |
|
328 |
^ self |
|
329 |
]. |
|
3900 | 330 |
]. |
3972 | 331 |
]. |
332 |
||
3900 | 333 |
"/ multiple masked pixels... |
334 |
paletteAlphaEntries keysAndValuesDo:[:pixelIndex :alpha | |
|
3972 | 335 |
alpha == 255 ifTrue:[ |
3900 | 336 |
image createMaskForPixelValue:pixelIndex |
337 |
] ifFalse:[ |
|
3972 | 338 |
alpha == 0 ifTrue:[ |
3900 | 339 |
"/ ok; already |
340 |
] ifFalse:[ |
|
341 |
self error:'should generate an alpha image' |
|
342 |
] |
|
343 |
]. |
|
344 |
]. |
|
3972 | 345 |
"/ image mask:nil. |
3900 | 346 |
^ self. |
347 |
]. |
|
348 |
||
349 |
colorType == ColorTypeGray ifTrue:[ |
|
350 |
|maskPixel| |
|
351 |
||
352 |
maskPixel := paletteAlphaEntries unsignedInt16At:1 MSB:true. |
|
353 |
image createMaskForPixelValue:maskPixel. |
|
354 |
^ self |
|
355 |
]. |
|
356 |
colorType == ColorTypeRGB ifTrue:[ |
|
357 |
|mr mg mb maskPixel| |
|
358 |
||
359 |
mr := paletteAlphaEntries unsignedInt16At:1 MSB:true. |
|
360 |
mg := paletteAlphaEntries unsignedInt16At:3 MSB:true. |
|
361 |
mb := paletteAlphaEntries unsignedInt16At:5 MSB:true. |
|
362 |
depth <= 32 ifTrue:[ |
|
363 |
"/ only use the low bits... |
|
364 |
mr > 255 ifTrue:[ self error:'only 8bit RGB supported']. |
|
365 |
mg > 255 ifTrue:[ self error:'only 8bit RGB supported']. |
|
366 |
mb > 255 ifTrue:[ self error:'only 8bit RGB supported']. |
|
367 |
maskPixel := ((mr bitShift:16) bitOr:(mg bitShift:8)) bitOr:mb. |
|
368 |
] ifFalse:[ |
|
369 |
maskPixel := ((mr bitShift:32) bitOr:(mg bitShift:16)) bitOr:mb. |
|
370 |
]. |
|
371 |
image createMaskForPixelValue:maskPixel. |
|
372 |
^ self |
|
373 |
]. |
|
374 |
||
375 |
"Created: / 17-02-2017 / 08:07:04 / cg" |
|
3972 | 376 |
"Modified: / 23-08-2017 / 17:24:30 / cg" |
3900 | 377 |
! |
378 |
||
379 |
getChunk |
|
380 |
|len type crc| |
|
381 |
||
382 |
inStream atEnd ifTrue:[^ false]. |
|
383 |
||
384 |
len := inStream nextInt32MSB:true. |
|
385 |
type := String new:4. |
|
386 |
(inStream nextBytes:4 into:type) ~~ 4 ifTrue:[^ false]. |
|
387 |
||
388 |
Verbose == true ifTrue:[ |
|
389 |
'len: ' infoPrint. len infoPrint. ' type: ' infoPrint. type infoPrintCR. |
|
390 |
]. |
|
391 |
||
392 |
type = 'IEND' ifTrue:[^ false]. |
|
393 |
||
394 |
(self processChunk:type len:len) ifFalse:[^ false]. |
|
395 |
||
396 |
crc := inStream nextInt32MSB:true. "/ ignored - for now |
|
397 |
^ true |
|
398 |
||
399 |
"Created: 21.6.1996 / 21:09:36 / cg" |
|
400 |
"Modified: 21.6.1996 / 21:20:26 / cg" |
|
401 |
! |
|
402 |
||
403 |
getIHDRChunk |
|
404 |
|len type crc| |
|
405 |
||
406 |
len := inStream nextInt32MSB:true. |
|
407 |
||
408 |
type := String new:4. |
|
409 |
inStream nextBytes:4 into:type. |
|
410 |
||
411 |
type = 'IHDR' ifFalse:[ |
|
412 |
Logger warning:'PNGReader: expected IHDR magic (%1)' with:inStream. |
|
413 |
^ false |
|
414 |
]. |
|
415 |
len == 13 ifFalse:[ |
|
416 |
Logger warning:'PNGReader: bad IHDR size (%1)' with:inStream. |
|
417 |
^ false |
|
418 |
]. |
|
419 |
||
420 |
width := inStream nextInt32MSB:true. |
|
421 |
height := inStream nextInt32MSB:true. |
|
422 |
||
423 |
(width <= 0 or:[height <= 0]) ifTrue:[ |
|
424 |
Logger warning:'PNGReader: invalid dimension(s) (%1)' with:inStream. |
|
425 |
^ false. |
|
426 |
]. |
|
427 |
self reportDimension. |
|
428 |
||
429 |
bitsPerChannel := inStream nextByte. |
|
4005 | 430 |
depth := bitsPerChannel. "/ for now - might be changed by setColorType. |
3900 | 431 |
colorType := inStream nextByte. |
432 |
||
433 |
compressionMethod := inStream nextByte. |
|
434 |
filterMethod := inStream nextByte. |
|
435 |
interlaceMode := inStream nextByte. |
|
436 |
||
437 |
Verbose == true ifTrue:[ |
|
438 |
'PNGReader: IHDR:' infoPrintCR. |
|
439 |
'PNGReader: width: ' infoPrint. width infoPrintCR. |
|
440 |
'PNGReader: height: ' infoPrint. height infoPrintCR. |
|
441 |
'PNGReader: bitsPerChannel: ' infoPrint. bitsPerChannel infoPrintCR. |
|
442 |
'PNGReader: colorType: ' infoPrint. colorType infoPrintCR. |
|
443 |
'PNGReader: compressionMethod: ' infoPrint. compressionMethod infoPrintCR. |
|
444 |
'PNGReader: filterMethod: ' infoPrint. filterMethod infoPrintCR. |
|
445 |
'PNGReader: interlaceMode: ' infoPrint. interlaceMode infoPrintCR. |
|
446 |
]. |
|
447 |
||
448 |
crc := inStream nextInt32MSB:true. |
|
449 |
^ true |
|
450 |
||
451 |
"Modified: / 17-02-2017 / 11:35:20 / cg" |
|
4005 | 452 |
"Modified (comment): / 31-08-2017 / 18:03:41 / cg" |
3900 | 453 |
! |
454 |
||
455 |
handleText:text keyword:keyword |
|
456 |
"/ things like exif data etc. |
|
457 |
"/ self halt. |
|
458 |
||
459 |
"/Standard keywords for text chunks: |
|
460 |
"/ |
|
461 |
"/ Title Short (one line) title or caption for image |
|
462 |
"/ Author Name of image's creator |
|
463 |
"/ Description Description of image (possibly long) |
|
464 |
"/ Copyright Copyright notice |
|
465 |
"/ Creation Time Time of original image creation |
|
466 |
"/ Software Software used to create the image |
|
467 |
"/ Disclaimer Legal disclaimer |
|
468 |
"/ Warning Warning of nature of content |
|
469 |
"/ Source Device used to create the image |
|
470 |
"/ Comment Miscellaneous comment; conversion from |
|
471 |
"/ GIF comment |
|
472 |
! |
|
473 |
||
474 |
setColorType:colorType |
|
4005 | 475 |
colorType == ColorTypeGray "0" ifTrue:[ |
3900 | 476 |
photometric := #blackIs0. |
477 |
samplesPerPixel := 1. |
|
478 |
bitsPerSample := Array with:bitsPerChannel. |
|
479 |
depth := bitsPerChannel. |
|
480 |
^ true. |
|
481 |
]. |
|
482 |
||
4005 | 483 |
colorType == ColorTypeRGB "2" ifTrue:[ |
3900 | 484 |
photometric := #rgb. |
485 |
samplesPerPixel := 3. |
|
486 |
bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel. |
|
487 |
depth := bitsPerChannel * 3. |
|
4005 | 488 |
|
489 |
bitsPerChannel < 8 ifTrue:[ |
|
490 |
bitsPerChannel == 5 ifTrue:[ |
|
491 |
depth := 16 |
|
492 |
] ifFalse:[ |
|
493 |
('PNGReader: unsupported bitsPerChannel:%1 for colorType rgb' bindWith:bitsPerChannel) infoPrintCR. |
|
494 |
]. |
|
495 |
]. |
|
3900 | 496 |
^ true. |
497 |
]. |
|
498 |
||
4005 | 499 |
colorType == ColorTypePalette "3" ifTrue:[ |
3900 | 500 |
bitsPerChannel == 16 ifTrue:[ |
4005 | 501 |
'PNGReader: invalid unsupported bitsPerChannel:%1 for colorType palette' infoPrintCR. |
3900 | 502 |
^ false. |
503 |
]. |
|
504 |
photometric := #palette. |
|
505 |
samplesPerPixel := 1. |
|
506 |
bitsPerSample := Array with:bitsPerChannel. |
|
507 |
depth := bitsPerChannel. |
|
508 |
^ true. |
|
509 |
]. |
|
510 |
||
4005 | 511 |
colorType == ColorTypeGrayAlpha "4" ifTrue:[ |
3900 | 512 |
bitsPerChannel < 8 ifTrue:[ |
4005 | 513 |
'PNGReader: unsupported colorType/depth combination' infoPrintCR. |
3900 | 514 |
^ false. |
515 |
]. |
|
516 |
photometric := #blackIs0. |
|
517 |
samplesPerPixel := 2. |
|
518 |
bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel. |
|
519 |
depth := bitsPerChannel * 2. |
|
520 |
^ true. |
|
521 |
]. |
|
522 |
||
4005 | 523 |
colorType == ColorTypeRGBAlpha "6" ifTrue:[ |
3900 | 524 |
bitsPerChannel < 8 ifTrue:[ |
4005 | 525 |
'PNGReader: unsupported colorType/depth combination' infoPrintCR. |
3900 | 526 |
^ false. |
527 |
]. |
|
528 |
photometric := #rgba. |
|
529 |
samplesPerPixel := 4. |
|
530 |
bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel. |
|
531 |
depth := bitsPerChannel * 4. |
|
532 |
^ true. |
|
533 |
]. |
|
534 |
||
4005 | 535 |
('PNGReader: unsupported or invalid colorType: ' , colorType printString , '.') infoPrintCR. |
3900 | 536 |
^ false |
537 |
||
4005 | 538 |
"Modified: / 31-08-2017 / 17:58:18 / cg" |
3900 | 539 |
! ! |
540 |
||
541 |
!PNGReader methodsFor:'reading-private chunks'! |
|
308 | 542 |
|
2699 | 543 |
doPass: pass |
544 |
"Certain interlace passes are skipped with certain small image dimensions" |
|
545 |
||
546 |
pass = 1 ifTrue: [ ^ true ]. |
|
547 |
((width = 1) and: [height = 1]) ifTrue: [ ^ false ]. |
|
548 |
pass = 2 ifTrue: [ ^ width >= 5 ]. |
|
549 |
pass = 3 ifTrue: [ ^ height >= 5 ]. |
|
550 |
pass = 4 ifTrue: [ ^ (width >=3 ) or: [height >= 5] ]. |
|
551 |
pass = 5 ifTrue: [ ^ height >=3 ]. |
|
552 |
pass = 6 ifTrue: [ ^ width >=2 ]. |
|
553 |
pass = 7 ifTrue: [ ^ height >=2 ]. |
|
554 |
||
555 |
self error:'invalid argument'. |
|
556 |
^ true |
|
557 |
! |
|
558 |
||
308 | 559 |
processBKGDChunkLen:len |
560 |
inStream skip:len. |
|
561 |
^ true |
|
562 |
||
563 |
"Created: 21.6.1996 / 21:15:49 / cg" |
|
564 |
! |
|
565 |
||
2707 | 566 |
processCHRMChunkLen:len |
567 |
"cHRM Primary chromaticities chunk - currently unhandled" |
|
568 |
||
569 |
|whitePointX whitePointY redX redY greenX greenY blueX blueY| |
|
570 |
||
3554 | 571 |
whitePointX := (inStream nextInt32MSB:true) / 100000.0. |
572 |
whitePointY := (inStream nextInt32MSB:true) / 100000.0. |
|
573 |
redX := (inStream nextInt32MSB:true) / 100000.0. |
|
574 |
redY := (inStream nextInt32MSB:true) / 100000.0. |
|
575 |
greenX := (inStream nextInt32MSB:true) / 100000.0. |
|
576 |
greenY := (inStream nextInt32MSB:true) / 100000.0. |
|
577 |
blueX := (inStream nextInt32MSB:true) / 100000.0. |
|
578 |
blueY := (inStream nextInt32MSB:true) / 100000.0. |
|
2707 | 579 |
|
580 |
Verbose == true ifTrue:[ |
|
581 |
'PNGReader: CHRM chunk ignored:' infoPrintCR. |
|
582 |
'PNGReader: whitePointX:' infoPrint. whitePointX infoPrintCR. |
|
583 |
'PNGReader: whitePointY:' infoPrint. whitePointX infoPrintCR. |
|
584 |
'PNGReader: redX:' infoPrint. redX infoPrintCR. |
|
585 |
'PNGReader: redY:' infoPrint. redY infoPrintCR. |
|
586 |
'PNGReader: greenX:' infoPrint. greenX infoPrintCR. |
|
587 |
'PNGReader: greenY:' infoPrint. greenY infoPrintCR. |
|
588 |
'PNGReader: blueX:' infoPrint. blueX infoPrintCR. |
|
589 |
'PNGReader: blueY:' infoPrint. blueY infoPrintCR. |
|
590 |
]. |
|
591 |
^ true |
|
592 |
! |
|
593 |
||
308 | 594 |
processChunk:type len:len |
2509 | 595 |
|chunk| |
596 |
||
597 |
type = 'IDAT' ifTrue:[ |
|
598 |
"---since the compressed data can span multiple |
|
599 |
chunks, stitch them all together first. later, |
|
600 |
if memory is an issue, we need to figure out how |
|
601 |
to do this on the fly---" |
|
602 |
chunk := inStream next:len. |
|
3821 | 603 |
globalDataChunk isNil ifTrue:[ |
604 |
globalDataChunk := ReadWriteStream on:(ByteArray new:(height * self bytesPerRow)). |
|
605 |
]. |
|
606 |
globalDataChunk nextPutAll:chunk. |
|
2509 | 607 |
^ true |
608 |
]. |
|
609 |
||
308 | 610 |
type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len]. |
611 |
type = 'sBIT' ifTrue:[^ self processSBITChunkLen:len]. |
|
612 |
type = 'tEXt' ifTrue:[^ self processTEXTChunkLen:len]. |
|
613 |
type = 'tIME' ifTrue:[^ self processTIMEChunkLen:len]. |
|
614 |
type = 'bKGD' ifTrue:[^ self processBKGDChunkLen:len]. |
|
615 |
type = 'zTXt' ifTrue:[^ self processZTXTChunkLen:len]. |
|
616 |
type = 'PLTE' ifTrue:[^ self processPLTEChunkLen:len]. |
|
617 |
||
1671 | 618 |
type = 'pHYs' ifTrue:[^ self processPHYSChunkLen:len]. |
2707 | 619 |
type = 'cHRM' ifTrue:[^ self processCHRMChunkLen:len]. |
1671 | 620 |
type = 'tRNS' ifTrue:[^ self processTRNSChunkLen:len]. |
621 |
type = 'IHDR' ifTrue:[^ self processIHDRChunkLen:len]. |
|
622 |
||
3762 | 623 |
type = 'iTXt' ifTrue:[^ self processITXTChunkLen:len]. |
624 |
type = 'iCCP' ifTrue:[^ self processICCPChunkLen:len]. |
|
3900 | 625 |
type = 'hIST' ifTrue:[^ self processHISTChunkLen:len]. |
626 |
type = 'spAL' ifTrue:[^ self processSPALChunkLen:len]. |
|
3889 | 627 |
|
628 |
specialChunkHandlers notNil ifTrue:[ |
|
629 |
|handler chunkData| |
|
630 |
||
631 |
handler := specialChunkHandlers at:type ifAbsent:nil. |
|
632 |
handler notNil ifTrue:[ |
|
633 |
chunkData := inStream nextBytes:len. |
|
634 |
handler value:chunkData optionalArgument:self. |
|
635 |
^ true. |
|
636 |
]. |
|
637 |
]. |
|
638 |
||
3891 | 639 |
type = 'niVI' ifTrue:[^ self processNIVIChunkLen:len]. |
3950 | 640 |
type = 'exEX' ifTrue:[^ self processEXEXChunkLen:len]. |
3891 | 641 |
|
308 | 642 |
('PNGReader: unrecognized chunk: ' , type , ' ignored.') infoPrintCR. |
643 |
||
644 |
inStream skip:len. |
|
645 |
^ true. |
|
646 |
||
3889 | 647 |
"Created: / 21-06-1996 / 21:10:37 / cg" |
3950 | 648 |
"Modified: / 11-04-2017 / 17:04:12 / cg" |
649 |
! |
|
650 |
||
651 |
processEXEXChunkLen:len |
|
652 |
"/ this cunk contains an expecco sample network. |
|
653 |
"/ ...to read it (using the expecco importer), |
|
654 |
"/ create a reader with a chunkHook and extract it there. |
|
655 |
Logger info:('PNG: skip exEX chunk'). |
|
656 |
inStream skip:len. |
|
657 |
^ true. |
|
658 |
||
659 |
"Created: / 11-04-2017 / 17:06:27 / cg" |
|
308 | 660 |
! |
661 |
||
662 |
processGAMAChunkLen:len |
|
663 |
inStream skip:len. |
|
664 |
^ true |
|
665 |
||
666 |
"Created: 21.6.1996 / 21:10:52 / cg" |
|
667 |
! |
|
668 |
||
2509 | 669 |
processGlobalIDATChunk |
670 |
interlaceMode == 0 ifTrue: [ |
|
671 |
^ self processNonInterlacedGlobalDATA |
|
672 |
]. |
|
673 |
^ self processInterlacedGlobalDATA |
|
674 |
! |
|
675 |
||
3900 | 676 |
processHISTChunkLen:len |
677 |
"/ ignored |
|
678 |
"/ inStream nextBytes:len. |
|
679 |
||
680 |
inStream skip:len. |
|
681 |
^ true |
|
682 |
||
683 |
"Created: / 17-02-2017 / 11:31:36 / cg" |
|
684 |
! |
|
685 |
||
3762 | 686 |
processICCPChunkLen:len |
687 |
"/ ignored |
|
688 |
"/ inStream nextBytes:len. |
|
689 |
||
690 |
inStream skip:len. |
|
691 |
^ true |
|
692 |
||
693 |
"Created: 21.6.1996 / 21:15:58 / cg" |
|
694 |
! |
|
695 |
||
308 | 696 |
processIDATChunkLen:len |
1671 | 697 |
interlaceMode == 0 ifTrue: [ |
698 |
^ self processNonInterlacedDATA:len |
|
699 |
]. |
|
700 |
^ self processInterlacedDATA:len |
|
701 |
! |
|
702 |
||
3762 | 703 |
processIHDRChunkLen:len |
704 |
"/ ignored |
|
705 |
||
706 |
inStream skip:len. |
|
707 |
^ true |
|
708 |
||
709 |
"Created: 21.6.1996 / 21:15:58 / cg" |
|
710 |
! |
|
711 |
||
712 |
processITXTChunkLen:len |
|
713 |
"/ international (i.e.utf8) textual data. |
|
714 |
||
715 |
"/ currently ignored - not needed to display png images |
|
716 |
"/ |
|
717 |
"/ Keyword: 1-79 bytes (character string) |
|
718 |
"/ Null separator: 1 byte |
|
719 |
"/ Compression flag: 1 byte |
|
720 |
"/ Compression method: 1 byte |
|
721 |
"/ Language tag: 0 or more bytes (character string) |
|
722 |
"/ Null separator: 1 byte |
|
723 |
"/ Translated keyword: 0 or more bytes |
|
724 |
"/ Null separator: 1 byte |
|
725 |
"/ Text: 0 or more bytes |
|
726 |
||
727 |
"/ if needed, set processTextChunks to true somewhere... |
|
728 |
processTextChunks == true ifTrue:[ |
|
729 |
|chunkData keyword text i1 i2 i3 |
|
730 |
compressionFlag compressionMethod languageTag |
|
731 |
xlatedKeyword textBytes| |
|
732 |
||
733 |
chunkData := inStream nextBytes:len. |
|
734 |
i1 := chunkData indexOf:0. |
|
735 |
keyword := (chunkData copyTo:i1-1) asString. |
|
736 |
compressionFlag := chunkData at:i1+1. |
|
737 |
compressionMethod := chunkData at:i1+2. |
|
738 |
i2 := chunkData indexOf:0 startingAt:i1+3. |
|
739 |
languageTag := (chunkData copyFrom:i1+3 to:i2-1) asString. |
|
740 |
i3 := chunkData indexOf:0 startingAt:i2+1. |
|
741 |
xlatedKeyword := (chunkData copyFrom:i2+1 to:i3-1) asString. |
|
742 |
textBytes := chunkData copyFrom:i3+1. |
|
743 |
compressionFlag == 0 ifTrue:[ |
|
744 |
text := textBytes |
|
745 |
] ifFalse:[ |
|
746 |
compressionFlag == 1 ifTrue:[ |
|
747 |
"/ for now, only zlib compression is supported... |
|
3900 | 748 |
"/ ... no - not even that is |
749 |
Logger warning:'PNG: zlib compressed text currently unsupported'. |
|
3762 | 750 |
] ifFalse:[ |
3900 | 751 |
Logger warning:'PNG: unsupported text compression method'. |
3762 | 752 |
]. |
753 |
]. |
|
754 |
text := text utf8Decoded. |
|
755 |
self handleText:text keyword:keyword. |
|
756 |
] ifFalse:[ |
|
757 |
inStream skip:len. |
|
758 |
]. |
|
759 |
^ true |
|
760 |
||
3900 | 761 |
"Created: / 21-06-1996 / 21:15:58 / cg" |
762 |
"Modified: / 16-02-2017 / 19:51:21 / cg" |
|
3762 | 763 |
! |
764 |
||
1671 | 765 |
processInterlacedDATA:len |
308 | 766 |
inStream skip:len. |
767 |
^ true |
|
1671 | 768 |
! |
308 | 769 |
|
2699 | 770 |
processInterlacedGlobalDATA |
3327 | 771 |
"adam7 interlace method" |
772 |
||
3612 | 773 |
| zlibReader filter |
774 |
bytesPerPass startingCol colIncrement rowIncrement |
|
775 |
startingRow |
|
776 |
temp "filtersSeen" |
|
777 |
cx "{ Class: SmallInteger }" |
|
778 |
sc "{ Class: SmallInteger }" |
|
779 |
cy "{ Class: SmallInteger }" |
|
780 |
startRow "{ Class: SmallInteger }" |
|
781 |
w "{ Class: SmallInteger }" |
|
782 |
h "{ Class: SmallInteger }" |
|
783 |
| |
|
2699 | 784 |
|
3327 | 785 |
interlaceMode == 1 ifFalse: [ |
786 |
self error:'unsupported interlaced mode'. |
|
787 |
^ self |
|
788 |
]. |
|
2699 | 789 |
|
790 |
"/ filtersSeen := Set new. |
|
791 |
||
792 |
startingCol := #(0 4 0 2 0 1 0 ). |
|
3327 | 793 |
startingRow := #(0 0 4 0 2 0 1 ). |
2699 | 794 |
colIncrement := #(8 8 4 4 2 2 1 ). |
795 |
rowIncrement := #(8 8 8 4 4 2 2 ). |
|
796 |
||
3821 | 797 |
globalDataChunk reset. |
798 |
zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false. |
|
2699 | 799 |
zlibReader binary. |
800 |
||
3612 | 801 |
h := height. |
802 |
w := width. |
|
2699 | 803 |
1 to: 7 do: [:pass | |
804 |
(self doPass: pass) ifTrue:[ |
|
805 |
cx := colIncrement at: pass. |
|
806 |
sc := startingCol at: pass. |
|
3327 | 807 |
cy := rowIncrement at: pass. |
3612 | 808 |
bytesPerPass := (((w - sc + cx - 1) // cx * depth) + 7) // 8. |
2699 | 809 |
prevScanline := ByteArray new: bytesPerPass. |
810 |
thisScanline := ByteArray new: bytesPerScanline. |
|
3612 | 811 |
startRow := startingRow at: pass. |
812 |
startRow to: h-1 by: cy do: [:y | |
|
3343 | 813 |
filter := zlibReader nextByte. |
2699 | 814 |
"/ filtersSeen add: filter. |
815 |
(filter isNil or: [(filter between: 0 and: 4) not]) |
|
816 |
ifTrue: [^ self]. |
|
817 |
zlibReader next: bytesPerPass into: thisScanline startingAt: 1. |
|
818 |
filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerPass ]. |
|
819 |
self copyPixels:y at:sc by:cx. |
|
820 |
temp := prevScanline. |
|
821 |
prevScanline := thisScanline. |
|
822 |
thisScanline := temp. |
|
823 |
] |
|
824 |
] |
|
825 |
]. |
|
826 |
zlibReader atEnd ifFalse:[self error:'Unexpected data']. |
|
2909 | 827 |
|
828 |
"Modified: / 03-05-2011 / 12:03:33 / cg" |
|
2699 | 829 |
! |
830 |
||
3890 | 831 |
processNIVIChunkLen:len |
3889 | 832 |
"/ this cunk contains a labView vi. |
833 |
"/ ignored for now... |
|
3890 | 834 |
"/ ...to read it (using the expecco importer), |
835 |
"/ create a reader with a chunkHook and extract it there. |
|
3891 | 836 |
Logger info:('PNG: skip niVI chunk'). |
3890 | 837 |
inStream skip:len. |
838 |
^ true. |
|
3889 | 839 |
|
840 |
"Created: / 14-02-2017 / 08:57:29 / cg" |
|
3891 | 841 |
"Modified: / 14-02-2017 / 22:36:34 / cg" |
3889 | 842 |
! |
843 |
||
1671 | 844 |
processNonInterlacedDATA:len |
2701 | 845 |
self halt:'not used' |
846 |
"/ |
|
847 |
"/ | zlibReader filter temp prevScanline thisScanline bytesPerScanline filtersSeen| |
|
848 |
"/ |
|
849 |
"/ zlibReader := ZipStream readOpenAsZipStreamOn:inStream suppressHeaderAndChecksum:false. |
|
850 |
"/ "/ zlibReader := ZLibReadStream on:inStream from: 1 to:len. |
|
851 |
"/ |
|
852 |
"/ prevScanline := ByteArray new: self bytesPerRow. |
|
853 |
"/ thisScanline := ByteArray new: self bytesPerRow. |
|
854 |
"/ 0 to: height - 1 do:[:index | |
|
855 |
"/ filter := (zlibReader next: 1) first. |
|
856 |
"/ filtersSeen add: filter. |
|
857 |
"/ (filter isNil or: [(filter between: 0 and: 4) not]) ifTrue: [^self]. |
|
858 |
"/ thisScanline := zlibReader next: bytesPerScanline into: thisScanline startingAt: 1. |
|
859 |
"/ self filterScanline: filter count: bytesPerScanline. |
|
860 |
"/ self copyPixels: index. |
|
861 |
"/ temp := prevScanline. |
|
862 |
"/ prevScanline := thisScanline. |
|
863 |
"/ thisScanline := temp |
|
864 |
"/ ] |
|
2509 | 865 |
! |
866 |
||
867 |
processNonInterlacedGlobalDATA |
|
3821 | 868 |
| "data n" zlibReader filter temp "filtersSeen" i| |
2696 | 869 |
|
870 |
"/ filtersSeen := Set new. |
|
2695 | 871 |
|
872 |
"/ data := ByteArray new:(self bytesPerRow * height)+1000. |
|
873 |
"/ n := ZipStream uncompress: globalDataChunk into: data. |
|
874 |
"/ self halt. |
|
2509 | 875 |
|
3821 | 876 |
globalDataChunk reset. |
877 |
zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false. |
|
2696 | 878 |
zlibReader binary. |
2509 | 879 |
|
1671 | 880 |
prevScanline := ByteArray new: bytesPerScanline. |
881 |
thisScanline := ByteArray new: bytesPerScanline. |
|
3972 | 882 |
0 to: height-1 do:[:y | |
3343 | 883 |
filter := zlibReader nextByte. |
3893 | 884 |
zlibReader next: bytesPerScanline into: thisScanline startingAt: 1. |
885 |
filter ~~ 0 ifTrue:[ |
|
886 |
"/ filtersSeen add: filter. |
|
887 |
(filter notNil and: [filter between: 0 and: 4]) ifFalse: [ |
|
888 |
'PNGReader: unsupported filter: ' infoPrint. filter infoPrintCR. |
|
889 |
^ self |
|
890 |
]. |
|
891 |
self filterScanline: filter count: bytesPerScanline |
|
2725 | 892 |
]. |
893 |
||
894 |
i := y * bytesPerScanline. |
|
895 |
data replaceFrom:i+1 to:(i+bytesPerScanline) with:thisScanline startingAt:1. |
|
896 |
||
2695 | 897 |
temp := prevScanline. |
898 |
prevScanline := thisScanline. |
|
899 |
thisScanline := temp |
|
900 |
] |
|
3893 | 901 |
|
902 |
"Modified: / 16-02-2017 / 16:45:52 / cg" |
|
3972 | 903 |
"Modified (format): / 23-08-2017 / 17:05:01 / cg" |
1671 | 904 |
! |
905 |
||
906 |
processPHYSChunkLen:len |
|
907 |
"physical pixel chunk - currently unhandled" |
|
908 |
||
2705 | 909 |
|pixelPerUnitX pixelPerUnitY unit| |
910 |
||
3554 | 911 |
pixelPerUnitX := inStream nextInt32MSB:true. |
912 |
pixelPerUnitY := inStream nextInt32MSB:true. |
|
2705 | 913 |
unit := inStream nextByte. |
914 |
||
2707 | 915 |
Verbose == true ifTrue:[ |
916 |
'PNGReader: PHYS chunk ignored:' infoPrintCR. |
|
917 |
'PNGReader: ppuX:' infoPrint. pixelPerUnitX infoPrintCR. |
|
918 |
'PNGReader: ppuY:' infoPrint. pixelPerUnitY infoPrintCR. |
|
919 |
'PNGReader: unit:' infoPrint. unit infoPrintCR. |
|
920 |
]. |
|
921 |
||
2705 | 922 |
^ true |
308 | 923 |
! |
924 |
||
925 |
processPLTEChunkLen:len |
|
1671 | 926 |
"read a color palette" |
927 |
||
2725 | 928 |
|n "{ Class: SmallInteger }" |
3972 | 929 |
redBytes greenBytes blueBytes |
930 |
triple| |
|
308 | 931 |
|
932 |
(len \\ 3) ~~ 0 ifTrue:[ |
|
933 |
'PNGReader: invalid size of PLTE chunk' infoPrintCR. |
|
934 |
^ false |
|
935 |
]. |
|
936 |
n := len // 3. |
|
937 |
redBytes := ByteArray new:n. |
|
938 |
greenBytes := ByteArray new:n. |
|
939 |
blueBytes := ByteArray new:n. |
|
940 |
||
3972 | 941 |
triple := ByteArray new:3. |
942 |
||
308 | 943 |
1 to:n do:[:i | |
3972 | 944 |
inStream next:3 into:triple startingAt:1. |
945 |
redBytes at:i put:(triple at:1). |
|
946 |
greenBytes at:i put:(triple at:2). |
|
947 |
blueBytes at:i put:(triple at:3) |
|
308 | 948 |
]. |
949 |
||
2725 | 950 |
colorMap := MappedPalette |
951 |
redVector:redBytes |
|
952 |
greenVector:greenBytes |
|
953 |
blueVector:blueBytes. |
|
954 |
||
308 | 955 |
^ true |
956 |
||
3972 | 957 |
"Created: / 21-06-1996 / 21:22:28 / cg" |
958 |
"Modified: / 23-08-2017 / 16:58:04 / cg" |
|
308 | 959 |
! |
960 |
||
961 |
processSBITChunkLen:len |
|
962 |
inStream skip:len. |
|
963 |
^ true |
|
964 |
||
965 |
"Created: 21.6.1996 / 21:13:09 / cg" |
|
966 |
! |
|
967 |
||
3900 | 968 |
processSPALChunkLen:len |
969 |
"/ ignored |
|
970 |
"/ inStream nextBytes:len. |
|
971 |
||
972 |
inStream skip:len. |
|
973 |
^ true |
|
974 |
||
975 |
"Created: / 17-02-2017 / 11:31:40 / cg" |
|
976 |
! |
|
977 |
||
3762 | 978 |
processTEXTChunkLen:len |
979 |
"/ textual data in iso8859 coding. |
|
980 |
||
981 |
"/ currently ignored - not needed to display png images |
|
982 |
"/ Keyword: 1-79 bytes (character string) |
|
983 |
"/ Null separator: 1 byte |
|
984 |
"/ Text: n bytes (character string) |
|
985 |
||
986 |
"/ if needed, set processTextChunks to true somewhere... |
|
987 |
processTextChunks == true ifTrue:[ |
|
988 |
|chunkData keyword text i| |
|
989 |
||
990 |
chunkData := inStream nextBytes:len. |
|
991 |
i := chunkData indexOf:0. |
|
992 |
keyword := (chunkData copyTo:i-1) asString. |
|
993 |
text := (chunkData copyFrom:i+1) asString. |
|
994 |
self handleText:text keyword:keyword. |
|
995 |
] ifFalse:[ |
|
996 |
inStream skip:len. |
|
997 |
]. |
|
308 | 998 |
^ true |
999 |
||
1000 |
"Modified: 21.6.1996 / 21:15:27 / cg" |
|
1001 |
! |
|
1002 |
||
1003 |
processTIMEChunkLen:len |
|
1004 |
inStream skip:len. |
|
1005 |
^ true |
|
1006 |
||
1007 |
"Created: 21.6.1996 / 21:15:43 / cg" |
|
1008 |
"Modified: 21.6.1996 / 21:20:42 / cg" |
|
1009 |
! |
|
1010 |
||
2707 | 1011 |
processTRNSChunkLen:len |
3900 | 1012 |
paletteAlphaEntries := inStream nextBytes:len. |
3904 | 1013 |
|
1014 |
colorType == ColorTypeRGB ifTrue:[ |
|
1015 |
len ~~ 3 ifTrue:[ |
|
1016 |
Logger warning:'PNG: bad trns chunk size'. |
|
1017 |
paletteAlphaEntries := nil. |
|
1018 |
]. |
|
1019 |
^ true |
|
1020 |
]. |
|
1021 |
colorType == ColorTypePalette ifTrue:[ |
|
1022 |
len ~~ 1 ifTrue:[ |
|
1023 |
Logger warning:'PNG: bad trns chunk size'. |
|
1024 |
paletteAlphaEntries := nil. |
|
1025 |
]. |
|
1026 |
^ true |
|
1027 |
]. |
|
1028 |
colorType == ColorTypeGray ifTrue:[ |
|
1029 |
len ~~ 2 ifTrue:[ |
|
1030 |
Logger warning:'PNG: bad trns chunk size'. |
|
1031 |
paletteAlphaEntries := nil. |
|
1032 |
]. |
|
1033 |
^ true |
|
1034 |
]. |
|
1035 |
paletteAlphaEntries := nil. |
|
2707 | 1036 |
^ true |
3900 | 1037 |
|
3904 | 1038 |
"Modified (format): / 17-02-2017 / 16:57:27 / cg" |
2707 | 1039 |
! |
1040 |
||
308 | 1041 |
processZTXTChunkLen:len |
3762 | 1042 |
"/ compressed text |
1043 |
||
1044 |
"/ currently ignored - not needed to display png images |
|
308 | 1045 |
inStream skip:len. |
1046 |
^ true |
|
1047 |
||
1048 |
"Created: 21.6.1996 / 21:15:58 / cg" |
|
1049 |
! ! |
|
1050 |
||
3900 | 1051 |
!PNGReader methodsFor:'reading-private filtering'! |
2696 | 1052 |
|
2909 | 1053 |
filterAverage:count |
2699 | 1054 |
"Use the average of the pixel to the left and the pixel above as a predictor" |
2909 | 1055 |
|
1056 |
|delta| |
|
2699 | 1057 |
|
3609 | 1058 |
%{ |
1059 |
if (__isByteArray(__INST(thisScanline)) |
|
1060 |
&& __isByteArray(__INST(prevScanline)) |
|
1061 |
&& __isSmallInteger(__INST(depth)) |
|
1062 |
&& __isSmallInteger(count)) { |
|
1063 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
1064 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
1065 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
1066 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
1067 |
INT __count = __intVal(count); |
|
1068 |
INT __delta = __intVal(__INST(depth)) / 8; |
|
1069 |
int __i; |
|
1070 |
||
1071 |
if (__delta < 1) __delta = 1; |
|
1072 |
for (__i=0; __i<__delta; __i++) { |
|
1073 |
__thisScanline[__i] += (__prevScanline[__i] >> 1); |
|
1074 |
} |
|
1075 |
for (; __i < __count; __i++) { |
|
1076 |
__thisScanline[__i] += ((__prevScanline[__i] + __thisScanline[__i-__delta]) >> 1); |
|
1077 |
} |
|
1078 |
RETURN(self); |
|
1079 |
} |
|
1080 |
%}. |
|
1081 |
||
1082 |
delta := depth // 8 max:1. |
|
2909 | 1083 |
1 to:delta do:[:i | |
3384 | 1084 |
thisScanline at:i put:((thisScanline at:i) + ((prevScanline at:i) // 2) bitAnd:255) |
2909 | 1085 |
]. |
1086 |
delta + 1 to:count do:[:i | |
|
3384 | 1087 |
thisScanline at:i put:((thisScanline at:i) + (((prevScanline at:i) + (thisScanline at:i - delta)) // 2) bitAnd:255) |
2909 | 1088 |
] |
1089 |
||
1090 |
"Modified: / 03-05-2011 / 12:14:01 / cg" |
|
2699 | 1091 |
! |
1092 |
||
2696 | 1093 |
filterHorizontal:count |
1094 |
"use the pixel to the left as a predictor" |
|
1095 |
||
1096 |
|delta| |
|
1097 |
||
3608 | 1098 |
%{ |
1099 |
if (__isByteArray(__INST(thisScanline)) |
|
1100 |
&& __isByteArray(__INST(prevScanline)) |
|
1101 |
&& __isSmallInteger(__INST(depth)) |
|
1102 |
&& __isSmallInteger(count)) { |
|
1103 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
1104 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
1105 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
1106 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
1107 |
INT __count = __intVal(count); |
|
1108 |
INT __delta = __intVal(__INST(depth)) / 8; |
|
1109 |
int __i; |
|
1110 |
||
1111 |
if (__delta < 1) __delta = 1; |
|
1112 |
for (__i = __delta; __i < __count; __i++) { |
|
1113 |
__thisScanline[__i] = __thisScanline[__i] + __thisScanline[__i-__delta]; |
|
1114 |
} |
|
1115 |
RETURN(self); |
|
1116 |
} |
|
1117 |
%}. |
|
1118 |
||
1119 |
delta := depth // 8 max:1. |
|
2696 | 1120 |
delta+1 to:count do:[:i| |
1121 |
thisScanline at:i put:(((thisScanline at:i)+ (thisScanline at:i-delta)) bitAnd:255) |
|
1122 |
] |
|
1123 |
! |
|
1124 |
||
2699 | 1125 |
filterNone: count |
2909 | 1126 |
"/ no filter - scanline is as is |
1127 |
||
1128 |
"Modified: / 03-05-2011 / 12:14:20 / cg" |
|
2699 | 1129 |
! |
1130 |
||
2909 | 1131 |
filterPaeth:count |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1132 |
"Select one of (the pixel to the left, the pixel above and the pixel to above left) to |
2909 | 1133 |
predict the value of this pixel" |
1134 |
||
1135 |
|delta| |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1136 |
|
3607 | 1137 |
%{ |
1138 |
if (__isByteArray(__INST(thisScanline)) |
|
1139 |
&& __isByteArray(__INST(prevScanline)) |
|
1140 |
&& __isSmallInteger(__INST(depth)) |
|
1141 |
&& __isSmallInteger(count)) { |
|
1142 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
1143 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
1144 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
1145 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
1146 |
INT __count = __intVal(count); |
|
1147 |
INT __delta = __intVal(__INST(depth)) / 8; |
|
1148 |
int __i; |
|
1149 |
||
1150 |
if (__delta < 1) __delta = 1; |
|
1151 |
for (__i=0; __i<__delta; __i++) { |
|
1152 |
unsigned int __pix = __thisScanline[__i] + __prevScanline[__i]; |
|
1153 |
__thisScanline[__i] = __pix; |
|
1154 |
} |
|
1155 |
for (; __i < __count; __i++) { |
|
1156 |
int __pCenter = __thisScanline[__i]; |
|
1157 |
int __pLeft = __thisScanline[__i - __delta]; |
|
1158 |
int __pAbove = __prevScanline[__i]; |
|
1159 |
int __pAboveLeft = __prevScanline[__i - __delta]; |
|
1160 |
int __pa, __pb, __pc; |
|
1161 |
int __p; |
|
1162 |
||
1163 |
__pa = (__pAbove - __pAboveLeft); |
|
1164 |
__pa = __pa < 0 ? -__pa : __pa; |
|
1165 |
__pb = (__pLeft - __pAboveLeft); |
|
1166 |
__pb = __pb < 0 ? -__pb : __pb; |
|
1167 |
__pc = __pLeft + __pAbove - __pAboveLeft - __pAboveLeft; |
|
1168 |
__pc = __pc < 0 ? -__pc : __pc; |
|
1169 |
if ((__pa <= __pb) && (__pa <= __pc)) __p = __pLeft; |
|
1170 |
else if (__pb <= __pc) __p = __pAbove; |
|
1171 |
else __p = __pAboveLeft; |
|
1172 |
||
1173 |
__thisScanline[__i] = __pCenter + __p; |
|
1174 |
} |
|
1175 |
RETURN(self); |
|
1176 |
} |
|
1177 |
%}. |
|
1178 |
||
1179 |
delta := depth // 8 max:1. |
|
2909 | 1180 |
1 to:delta do:[:i | |
1181 |
thisScanline |
|
1182 |
at:i |
|
1183 |
put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255) |
|
1184 |
]. |
|
1185 |
delta + 1 to:count do:[:i | |
|
1186 |
thisScanline |
|
1187 |
at:i |
|
1188 |
put:(((thisScanline at:i) + (self |
|
1189 |
paethPredictLeft:(thisScanline at:i - delta) |
|
1190 |
above:(prevScanline at:i) |
|
1191 |
aboveLeft:(prevScanline at:i - delta))) |
|
1192 |
bitAnd:255) |
|
1193 |
] |
|
1194 |
||
1195 |
"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
|
1196 |
! |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1197 |
|
2696 | 1198 |
filterScanline:filterType count:count |
3612 | 1199 |
filterType == 0 ifTrue:[^ self]. |
1200 |
||
2696 | 1201 |
self |
3612 | 1202 |
perform:(#(filterHorizontal: filterVertical: filterAverage: filterPaeth:) at:filterType) |
2696 | 1203 |
with:count |
2909 | 1204 |
|
1205 |
"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
|
1206 |
! |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1207 |
|
2909 | 1208 |
filterVertical:count |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1209 |
"Use the pixel above as a predictor" |
2909 | 1210 |
|
3608 | 1211 |
%{ |
1212 |
if (__isByteArray(__INST(thisScanline)) |
|
1213 |
&& __isByteArray(__INST(prevScanline)) |
|
1214 |
&& __isSmallInteger(count)) { |
|
1215 |
unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline)); |
|
1216 |
unsigned int __sz_this = __byteArraySize(__INST(thisScanline)); |
|
1217 |
unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline)); |
|
1218 |
unsigned int __sz_prev = __byteArraySize(__INST(prevScanline)); |
|
1219 |
INT __count = __intVal(count); |
|
1220 |
int __i; |
|
1221 |
||
1222 |
for (__i=0; __i<__count; __i++) { |
|
1223 |
unsigned int __pix = __thisScanline[__i] + __prevScanline[__i]; |
|
1224 |
__thisScanline[__i] = __pix; |
|
1225 |
} |
|
1226 |
RETURN(self); |
|
1227 |
} |
|
1228 |
%}. |
|
1229 |
||
2909 | 1230 |
1 to:count do:[:i | |
1231 |
thisScanline |
|
1232 |
at:i |
|
1233 |
put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255) |
|
1234 |
] |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1235 |
|
2909 | 1236 |
"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
|
1237 |
! |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1238 |
|
3607 | 1239 |
paethPredictLeft: l above: a aboveLeft: al |
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1240 |
"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
|
1241 |
|
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1242 |
| pa pb pc | |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1243 |
|
3607 | 1244 |
pa := a > al ifTrue: [a - al] ifFalse: [al - a]. |
1245 |
pb := l > al ifTrue: [l - al] ifFalse: [al - l]. |
|
1246 |
pc := l + a - al - al. |
|
2697
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1247 |
pc < 0 ifTrue: [ |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1248 |
pc := pc * -1 |
8e8223bf25af
more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents:
2696
diff
changeset
|
1249 |
]. |
3607 | 1250 |
((pa <= pb) and: [pa <= pc]) ifTrue: [^ l]. |
1251 |
(pb <= pc) ifTrue: [^ a]. |
|
1252 |
^ al |
|
2696 | 1253 |
! ! |
1254 |
||
3900 | 1255 |
!PNGReader methodsFor:'reading-private pixel copy'! |
2699 | 1256 |
|
2909 | 1257 |
copyPixels:y at:startX by:incX |
2704 | 1258 |
"Handle interlaced pixels of supported colorTypes" |
2909 | 1259 |
|
1260 |
|s| |
|
2699 | 1261 |
|
3598 | 1262 |
"/ per color type copy methods |
1263 |
s := #( |
|
3900 | 1264 |
#copyPixelsGray:at:by: "/ 0 = ColorTypeGray |
2909 | 1265 |
nil |
3900 | 1266 |
#copyPixelsRGB:at:by: "/ 2 = ColorTypeRGB |
1267 |
#copyPixelsIndexed:at:by: "/ 3 = ColorTypePalette |
|
1268 |
#copyPixelsGrayAlpha:at:by: "/ 4 = ColorTypeGrayAlpha |
|
2909 | 1269 |
nil |
3900 | 1270 |
#copyPixelsRGBA:at:by: "/ 6 = ColorTypeRGBA |
2909 | 1271 |
) at:colorType + 1. |
3437 | 1272 |
self perform:s with:y with:startX with:incX |
1848 | 1273 |
|
2909 | 1274 |
"Modified: / 03-05-2011 / 12:02:45 / cg" |
3900 | 1275 |
"Modified (comment): / 16-02-2017 / 19:42:47 / cg" |
3327 | 1276 |
! |
1277 |
||
3598 | 1278 |
copyPixelsGray:y at:startX by:incX |
1279 |
"Handle interlaced pixels of supported colorTypes. |
|
1280 |
Untested code - please verify" |
|
1281 |
||
3611 | 1282 |
|srcIndex "{ Class: SmallInteger }" |
1283 |
srcMask "{ Class: SmallInteger }" |
|
1284 |
nPixels "{ Class: SmallInteger }" |
|
1285 |
dstIndex "{ Class: SmallInteger }" |
|
1286 |
dstMask "{ Class: SmallInteger }" |
|
1287 |
x "{ Class: SmallInteger }" |
|
1288 |
bits "{ Class: SmallInteger }" |
|
1289 |
bitMask "{ Class: SmallInteger }" |
|
1290 |
rS "{ Class: SmallInteger }" |
|
1291 |
lS "{ Class: SmallInteger }" |
|
1292 |
rowIndex "{ Class: SmallInteger }"| |
|
3598 | 1293 |
|
1294 |
nPixels := width // incX. |
|
1295 |
srcIndex := 0. srcMask := 0. x := startX. |
|
1296 |
||
1297 |
depth == 1 ifTrue:[ |
|
1298 |
dstIndex := (y * bytesPerScanline) + (startX // 8) + 1. |
|
1299 |
dstMask := 16r80 >> (x \\ 8). |
|
1300 |
||
1301 |
1 to:nPixels do:[:cnt | |
|
1302 |
srcMask == 0 ifTrue:[ |
|
1303 |
srcMask := 16r80. |
|
1304 |
srcIndex := srcIndex + 1. |
|
1305 |
bits := thisScanline at:srcIndex. |
|
1306 |
]. |
|
1307 |
bitMask := (bits bitAnd:srcMask) == 0 ifTrue:[0] ifFalse:[dstMask]. |
|
1308 |
bitMask ~~ 0 ifTrue:[ |
|
1309 |
data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
1310 |
]. |
|
1311 |
x := x + incX. |
|
1312 |
dstMask := dstMask >> incX. |
|
1313 |
dstMask == 0 ifTrue:[ |
|
1314 |
dstIndex := dstIndex + 1. |
|
1315 |
dstMask := 16r80 >> (x \\ 8). |
|
1316 |
]. |
|
1317 |
srcMask := srcMask bitShift:-1. |
|
1318 |
]. |
|
1319 |
^ self. |
|
1320 |
]. |
|
1321 |
||
1322 |
depth == 2 ifTrue:[ |
|
1323 |
dstIndex := (y * bytesPerScanline) + (startX // 4) + 1. |
|
1324 |
lS := 6 - ((x \\ 4) * 2). |
|
1325 |
rS := -1. |
|
1326 |
1 to:nPixels do:[:cnt | |
|
1327 |
rS < 0 ifTrue:[ |
|
1328 |
srcIndex := srcIndex + 1. |
|
1329 |
bits := thisScanline at:srcIndex. |
|
1330 |
rS := 6. |
|
1331 |
]. |
|
1332 |
bitMask := ((bits >> rS) bitAnd:2r11). |
|
1333 |
bitMask ~~ 0 ifTrue:[ |
|
1334 |
bitMask := bitMask << lS. |
|
1335 |
data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
1336 |
]. |
|
1337 |
lS := lS - (incX * 2). |
|
1338 |
lS < 0 ifTrue:[ |
|
1339 |
lS <= -8 ifTrue:[ |
|
1340 |
dstIndex := dstIndex + 2. |
|
1341 |
lS := lS + 8 + 8. |
|
1342 |
] ifFalse:[ |
|
1343 |
dstIndex := dstIndex + 1. |
|
1344 |
lS := lS + 8. |
|
1345 |
]. |
|
1346 |
]. |
|
1347 |
rS := rS - 2. |
|
1348 |
]. |
|
1349 |
^ self. |
|
1350 |
]. |
|
1351 |
||
1352 |
depth == 4 ifTrue:[ |
|
1353 |
rowIndex := (y * bytesPerScanline) + 1. |
|
1354 |
dstIndex := rowIndex + (x // 2). |
|
1355 |
rS := -1. |
|
1356 |
1 to:nPixels do:[:cnt | |
|
1357 |
rS < 0 ifTrue:[ |
|
1358 |
srcIndex := srcIndex + 1. |
|
1359 |
bits := thisScanline at:srcIndex. |
|
1360 |
rS := 4. |
|
1361 |
]. |
|
1362 |
bitMask := ((bits >> rS) bitAnd:2r1111). |
|
1363 |
x even ifTrue:[ |
|
1364 |
bitMask := bitMask bitShift:4. |
|
1365 |
]. |
|
1366 |
data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
1367 |
x := x + incX. |
|
1368 |
dstIndex := rowIndex + (x // 2). |
|
1369 |
rS := rS - 4. |
|
1370 |
]. |
|
1371 |
^ self. |
|
1372 |
]. |
|
1373 |
||
1374 |
depth == 8 ifTrue:[ |
|
1375 |
srcIndex := 1. |
|
1376 |
dstIndex := (y * bytesPerScanline) + (startX) + 1. |
|
1377 |
||
1378 |
1 to:nPixels do:[:n | |
|
1379 |
data at:dstIndex put:(thisScanline at:srcIndex). |
|
1380 |
srcIndex := srcIndex + 1. |
|
1381 |
dstIndex := dstIndex + incX |
|
1382 |
]. |
|
1383 |
^ self. |
|
1384 |
]. |
|
1385 |
||
1386 |
depth == 16 ifTrue:[ |
|
1387 |
srcIndex := 1. |
|
1388 |
dstIndex := (y * bytesPerScanline) + (startX*2) + 1. |
|
1389 |
||
1390 |
1 to:nPixels do:[:n | |
|
3601 | 1391 |
data unsignedInt16At:dstIndex put:(thisScanline unsignedInt16At:srcIndex). |
3598 | 1392 |
srcIndex := srcIndex + 2. |
1393 |
dstIndex := dstIndex + (incX * 2) |
|
1394 |
]. |
|
1395 |
^ self. |
|
1396 |
]. |
|
1397 |
self error:'unsupported depth'. |
|
1398 |
! |
|
1399 |
||
4017 | 1400 |
copyPixelsGrayAlpha:y at:startX by:incX |
1401 |
"Handle interlaced pixels of supported colorTypes." |
|
1402 |
||
1403 |
|srcIndex "{ Class: SmallInteger }" |
|
1404 |
srcMask "{ Class: SmallInteger }" |
|
1405 |
nPixels "{ Class: SmallInteger }" |
|
1406 |
dstIndex "{ Class: SmallInteger }" |
|
1407 |
dstMask "{ Class: SmallInteger }" |
|
1408 |
x "{ Class: SmallInteger }" |
|
1409 |
bits "{ Class: SmallInteger }" |
|
1410 |
bitMask "{ Class: SmallInteger }" |
|
1411 |
rS "{ Class: SmallInteger }" |
|
1412 |
lS "{ Class: SmallInteger }" |
|
1413 |
rowIndex "{ Class: SmallInteger }" |
|
1414 |
pix alpha gray| |
|
1415 |
||
1416 |
nPixels := width // incX. |
|
1417 |
srcIndex := 0. srcMask := 0. x := startX. |
|
1418 |
||
1419 |
"/ depth == 1 ifTrue:[ |
|
1420 |
"/ dstIndex := (y * bytesPerScanline) + (startX // 8) + 1. |
|
1421 |
"/ dstMask := 16r80 >> (x \\ 8). |
|
1422 |
"/ |
|
1423 |
"/ 1 to:nPixels do:[:cnt | |
|
1424 |
"/ srcMask == 0 ifTrue:[ |
|
1425 |
"/ srcMask := 16r80. |
|
1426 |
"/ srcIndex := srcIndex + 1. |
|
1427 |
"/ bits := thisScanline at:srcIndex. |
|
1428 |
"/ ]. |
|
1429 |
"/ bitMask := (bits bitAnd:srcMask) == 0 ifTrue:[0] ifFalse:[dstMask]. |
|
1430 |
"/ bitMask ~~ 0 ifTrue:[ |
|
1431 |
"/ data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
1432 |
"/ ]. |
|
1433 |
"/ x := x + incX. |
|
1434 |
"/ dstMask := dstMask >> incX. |
|
1435 |
"/ dstMask == 0 ifTrue:[ |
|
1436 |
"/ dstIndex := dstIndex + 1. |
|
1437 |
"/ dstMask := 16r80 >> (x \\ 8). |
|
1438 |
"/ ]. |
|
1439 |
"/ srcMask := srcMask bitShift:-1. |
|
1440 |
"/ ]. |
|
1441 |
"/ ^ self. |
|
1442 |
"/ ]. |
|
1443 |
"/ |
|
1444 |
"/ depth == 2 ifTrue:[ |
|
1445 |
"/ dstIndex := (y * bytesPerScanline) + (startX // 4) + 1. |
|
1446 |
"/ lS := 6 - ((x \\ 4) * 2). |
|
1447 |
"/ rS := -1. |
|
1448 |
"/ 1 to:nPixels do:[:cnt | |
|
1449 |
"/ rS < 0 ifTrue:[ |
|
1450 |
"/ srcIndex := srcIndex + 1. |
|
1451 |
"/ bits := thisScanline at:srcIndex. |
|
1452 |
"/ rS := 6. |
|
1453 |
"/ ]. |
|
1454 |
"/ bitMask := ((bits >> rS) bitAnd:2r11). |
|
1455 |
"/ bitMask ~~ 0 ifTrue:[ |
|
1456 |
"/ bitMask := bitMask << lS. |
|
1457 |
"/ data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
1458 |
"/ ]. |
|
1459 |
"/ lS := lS - (incX * 2). |
|
1460 |
"/ lS < 0 ifTrue:[ |
|
1461 |
"/ lS <= -8 ifTrue:[ |
|
1462 |
"/ dstIndex := dstIndex + 2. |
|
1463 |
"/ lS := lS + 8 + 8. |
|
1464 |
"/ ] ifFalse:[ |
|
1465 |
"/ dstIndex := dstIndex + 1. |
|
1466 |
"/ lS := lS + 8. |
|
1467 |
"/ ]. |
|
1468 |
"/ ]. |
|
1469 |
"/ rS := rS - 2. |
|
1470 |
"/ ]. |
|
1471 |
"/ ^ self. |
|
1472 |
"/ ]. |
|
1473 |
"/ |
|
1474 |
"/ depth == 4 ifTrue:[ |
|
1475 |
"/ rowIndex := (y * bytesPerScanline) + 1. |
|
1476 |
"/ dstIndex := rowIndex + (x // 2). |
|
1477 |
"/ rS := -1. |
|
1478 |
"/ 1 to:nPixels do:[:cnt | |
|
1479 |
"/ rS < 0 ifTrue:[ |
|
1480 |
"/ srcIndex := srcIndex + 1. |
|
1481 |
"/ bits := thisScanline at:srcIndex. |
|
1482 |
"/ rS := 4. |
|
1483 |
"/ ]. |
|
1484 |
"/ bitMask := ((bits >> rS) bitAnd:2r1111). |
|
1485 |
"/ x even ifTrue:[ |
|
1486 |
"/ bitMask := bitMask bitShift:4. |
|
1487 |
"/ ]. |
|
1488 |
"/ data at:dstIndex put:((data at:dstIndex) bitOr:bitMask). |
|
1489 |
"/ x := x + incX. |
|
1490 |
"/ dstIndex := rowIndex + (x // 2). |
|
1491 |
"/ rS := rS - 4. |
|
1492 |
"/ ]. |
|
1493 |
"/ ^ self. |
|
1494 |
"/ ]. |
|
1495 |
"/ |
|
1496 |
"/ depth == 8 ifTrue:[ |
|
1497 |
"/ srcIndex := 1. |
|
1498 |
"/ dstIndex := (y * bytesPerScanline) + (startX) + 1. |
|
1499 |
"/ |
|
1500 |
"/ 1 to:nPixels do:[:n | |
|
1501 |
"/ data at:dstIndex put:(thisScanline at:srcIndex). |
|
1502 |
"/ srcIndex := srcIndex + 1. |
|
1503 |
"/ dstIndex := dstIndex + incX |
|
1504 |
"/ ]. |
|
1505 |
"/ ^ self. |
|
1506 |
"/ ]. |
|
1507 |
||
1508 |
forceRGB ifTrue:[ |
|
1509 |
(depth == 16 and:[depthImage == 32]) ifTrue:[ |
|
1510 |
"/ converting gray8+alpha8 to r8+g8+b8+alpha8 |
|
1511 |
||
1512 |
srcIndex := 1. |
|
1513 |
dstIndex := (y * (width * 4)) + (startX*4) + 1. |
|
1514 |
||
1515 |
1 to:nPixels do:[:n | |
|
1516 |
pix := thisScanline unsignedInt16At:srcIndex. |
|
1517 |
alpha := pix bitAnd:16rFF. |
|
1518 |
gray := (pix rightShift:8) bitAnd:16rFF. |
|
1519 |
"/ put r-g-b-a |
|
1520 |
data at:dstIndex put:gray. |
|
1521 |
data at:dstIndex+1 put:gray. |
|
1522 |
data at:dstIndex+2 put:gray. |
|
1523 |
data at:dstIndex+3 put:alpha. |
|
1524 |
||
1525 |
srcIndex := srcIndex + 2. |
|
1526 |
dstIndex := dstIndex + (incX * 4) |
|
1527 |
]. |
|
1528 |
^ self. |
|
1529 |
]. |
|
1530 |
(depth == 32 and:[depthImage == 32]) ifTrue:[ |
|
1531 |
"/ converting gray16+alpha16 to r8+g8+b8+alpha8 |
|
1532 |
||
1533 |
srcIndex := 1. |
|
1534 |
dstIndex := (y * (width * 4)) + (startX*4) + 1. |
|
1535 |
||
1536 |
1 to:nPixels do:[:n | |
|
1537 |
pix := thisScanline unsignedInt32At:srcIndex. |
|
1538 |
||
1539 |
alpha := pix bitAnd:16rFFFF. |
|
1540 |
gray := (pix rightShift:16) bitAnd:16rFFFF. |
|
1541 |
"/ reduce to 8 bit |
|
1542 |
alpha := alpha rightShift:8. |
|
1543 |
gray := gray rightShift:8. |
|
1544 |
||
1545 |
"/ put r-g-b-a |
|
1546 |
data at:dstIndex put:gray. |
|
1547 |
data at:dstIndex+1 put:gray. |
|
1548 |
data at:dstIndex+2 put:gray. |
|
1549 |
data at:dstIndex+3 put:alpha. |
|
1550 |
||
1551 |
srcIndex := srcIndex + 4. |
|
1552 |
dstIndex := dstIndex + (incX * 4) |
|
1553 |
]. |
|
1554 |
^ self. |
|
1555 |
]. |
|
1556 |
]. |
|
1557 |
self error:'unsupported depth'. |
|
1558 |
||
1559 |
"Created: / 17-09-2017 / 14:20:24 / cg" |
|
1560 |
"Modified: / 17-09-2017 / 15:28:38 / cg" |
|
1561 |
! |
|
1562 |
||
3598 | 1563 |
copyPixelsIndexed:y at:startX by:incX |
1564 |
self copyPixelsGray:y at:startX by:incX |
|
1565 |
! |
|
1566 |
||
1567 |
copyPixelsRGB:y at:startX by:incX |
|
1568 |
"Handle interlaced pixels of supported colorTypes. |
|
1569 |
Untested code - please verify" |
|
1570 |
||
3611 | 1571 |
|srcIndex "{ Class: SmallInteger }" |
1572 |
nPixels "{ Class: SmallInteger }" |
|
1573 |
dstIndex "{ Class: SmallInteger }" |
|
1574 |
dstInc "{ Class: SmallInteger }" |
|
1575 |
bpp "{ Class: SmallInteger }"| |
|
3598 | 1576 |
|
1577 |
bpp := bytesPerScanline // width. |
|
1578 |
||
1579 |
"/ 1 byte per r,g,b |
|
1580 |
srcIndex := 1. |
|
1581 |
dstIndex := (y * bytesPerScanline) + (startX * bpp) + 1. |
|
1582 |
dstInc := incX * bpp. |
|
1583 |
||
1584 |
nPixels := width // incX. |
|
1585 |
1 to:nPixels do:[:n | |
|
1586 |
data replaceFrom:dstIndex to:dstIndex+bpp-1 with:thisScanline startingAt:srcIndex. |
|
1587 |
srcIndex := srcIndex + bpp. |
|
1588 |
dstIndex := dstIndex + dstInc |
|
1589 |
]. |
|
1590 |
! |
|
1591 |
||
3327 | 1592 |
copyPixelsRGBA:y at:startX by:incX |
1593 |
"Handle interlaced pixels of supported colorTypes. |
|
1594 |
Untested code - please verify" |
|
1595 |
||
3611 | 1596 |
|srcIndex "{ Class: SmallInteger }" |
1597 |
nPixels "{ Class: SmallInteger }" |
|
1598 |
dstIndex "{ Class: SmallInteger }" |
|
1599 |
dstInc "{ Class: SmallInteger }"| |
|
3327 | 1600 |
|
1601 |
srcIndex := 1. |
|
3437 | 1602 |
dstIndex := (y * bytesPerScanline) + (startX * 4) + 1. |
1603 |
dstInc := incX * 4. |
|
3327 | 1604 |
|
1605 |
nPixels := thisScanline size. |
|
1606 |
[srcIndex < nPixels] whileTrue:[ |
|
3437 | 1607 |
data replaceFrom:dstIndex to:dstIndex+3 with:thisScanline startingAt:srcIndex. |
3327 | 1608 |
srcIndex := srcIndex + 4. |
3437 | 1609 |
dstIndex := dstIndex + dstInc |
3327 | 1610 |
]. |
2699 | 1611 |
! ! |
1612 |
||
3900 | 1613 |
!PNGReader methodsFor:'writing'! |
2683 | 1614 |
|
1615 |
save:image onStream:aStream |
|
1616 |
"save image in PNG-file-format onto aStream" |
|
1617 |
||
1618 |
outStream := aStream. |
|
1619 |
outStream binary. |
|
1620 |
||
2703 | 1621 |
byteOrder := #msb. |
4004 | 1622 |
|
2683 | 1623 |
width := image width. |
1624 |
height := image height. |
|
1625 |
photometric := image photometric. |
|
1626 |
samplesPerPixel := image samplesPerPixel. |
|
1627 |
bitsPerSample := image bitsPerSample. |
|
1628 |
colorMap := image colorMap. |
|
1629 |
data := image bits. |
|
3893 | 1630 |
mask := image mask. |
1631 |
depth := self bitsPerPixel. |
|
3900 | 1632 |
|
3909 | 1633 |
outStream nextPutAll:(self class pngHeader). |
3893 | 1634 |
|
3900 | 1635 |
image mask notNil ifTrue:[ |
3972 | 1636 |
((photometric ~~ #rgb) and:[(photometric ~~ #rgba) and:[(photometric ~~ #argb)]]) ifTrue: [ |
3949 | 1637 |
self determinePaletteIndexForMaskedPixels |
3904 | 1638 |
] ifFalse:[ |
1639 |
photometric := #rgba. |
|
1640 |
]. |
|
3900 | 1641 |
]. |
1642 |
||
2703 | 1643 |
self writeIHDRChunk. |
1644 |
photometric == #palette ifTrue: [self writePaletteChunk]. |
|
3900 | 1645 |
paletteIndexForMaskedPixels notNil ifTrue: [self writeTRNSChunk]. |
2703 | 1646 |
self writeImageDataChunk. |
2683 | 1647 |
self writeEndChunk |
3893 | 1648 |
|
3972 | 1649 |
"Modified: / 23-08-2017 / 16:25:00 / cg" |
4004 | 1650 |
"Modified (format): / 31-08-2017 / 17:26:28 / cg" |
3900 | 1651 |
! ! |
1652 |
||
1653 |
!PNGReader methodsFor:'writing-private'! |
|
1654 |
||
1655 |
determinePaletteIndexForMaskedPixels |
|
1656 |
"/ if all masked pixels are 0, and 0 is not used elsewhere in the image, |
|
1657 |
"/ write it as such. |
|
1658 |
"/ Otherwise, find an unallocated palette index, and assign masked pixels to it. |
|
1659 |
||
1660 |
|usedPixels freePixels pixelIdx| |
|
1661 |
||
1662 |
colorMap size < 256 ifTrue:[ |
|
1663 |
paletteIndexForMaskedPixels := colorMap size. |
|
1664 |
] ifFalse:[ |
|
1665 |
usedPixels := data usedValues. |
|
1666 |
usedPixels size == 256 ifTrue:[ |
|
1667 |
self error:'cannot represent image (no palette slot for mask)' |
|
1668 |
]. |
|
1669 |
freePixels := (0 to:255) asSet removeAllFoundIn:usedPixels. |
|
1670 |
paletteIndexForMaskedPixels := freePixels first. |
|
1671 |
]. |
|
1672 |
||
1673 |
"/ rewrite data: wherever masked, change pixel to paletteIndexForMaskedPixels |
|
1674 |
||
1675 |
data := data copy. |
|
1676 |
pixelIdx := 1. |
|
1677 |
0 to:height-1 do:[:y | |
|
1678 |
0 to:width-1 do:[:x | |
|
1679 |
(mask pixelAtX:x y:y) == 0 ifTrue:[ |
|
1680 |
data at:pixelIdx put:paletteIndexForMaskedPixels. |
|
1681 |
]. |
|
1682 |
pixelIdx := pixelIdx + 1 |
|
1683 |
] |
|
1684 |
]. |
|
1685 |
||
1686 |
" |
|
1687 |
PNGReader save:(ToolbarIconLibrary systemBrowserIcon) onFile:'/tmp/icon.png' |
|
1688 |
ImageEditor openOnFile:'/tmp/icon.png' |
|
1689 |
" |
|
1690 |
||
1691 |
"Created: / 16-02-2017 / 19:59:39 / cg" |
|
1692 |
"Modified: / 17-02-2017 / 09:25:57 / cg" |
|
1693 |
! ! |
|
1694 |
||
1695 |
!PNGReader methodsFor:'writing-private chunks'! |
|
2683 | 1696 |
|
3949 | 1697 |
determineColorTypeAndHasMask |
4004 | 1698 |
"sets colorType as side effect; |
1699 |
returns boolean if a mask is present" |
|
1700 |
||
3949 | 1701 |
((photometric == #whiteIs0) or:[ (photometric == #blackIs0)]) ifTrue:[ |
1702 |
colorType := ColorTypeGray. |
|
1703 |
^ (samplesPerPixel > 1) |
|
1704 |
]. |
|
1705 |
(photometric == #rgb) ifTrue:[ |
|
1706 |
colorType := ColorTypeRGB. |
|
1707 |
^ (samplesPerPixel > 3) |
|
1708 |
]. |
|
1709 |
(photometric == #rgba) ifTrue:[ |
|
1710 |
colorType := ColorTypeRGBAlpha. |
|
1711 |
^ (samplesPerPixel > 3) |
|
1712 |
]. |
|
1713 |
(photometric == #palette) ifTrue:[ |
|
1714 |
colorType := ColorTypePalette. |
|
1715 |
^ (samplesPerPixel > 1) |
|
1716 |
]. |
|
1717 |
self error:'unhandled photometric: ',photometric asString. |
|
1718 |
^ false. |
|
1719 |
||
1720 |
"Created: / 11-04-2017 / 12:39:30 / cg" |
|
4004 | 1721 |
"Modified (comment): / 31-08-2017 / 17:24:31 / cg" |
3949 | 1722 |
! |
1723 |
||
2703 | 1724 |
writeChunk:chunkTypeChars size:len with:aBlock |
2708 | 1725 |
|crc realOutStream chunkBytes| |
1726 |
||
1727 |
realOutStream := outStream. |
|
1728 |
outStream := WriteStream on:(ByteArray new:len). |
|
1729 |
||
2703 | 1730 |
outStream nextPutBytes:4 from:chunkTypeChars startingAt:1. |
1731 |
aBlock value. |
|
2708 | 1732 |
|
1733 |
chunkBytes := outStream contents. |
|
1734 |
crc := CRC32Stream hashValueOf:chunkBytes. |
|
1735 |
||
1736 |
outStream := realOutStream. |
|
1737 |
||
3554 | 1738 |
realOutStream nextPutInt32:len MSB:true. |
2708 | 1739 |
realOutStream nextPutAll:chunkBytes. |
3554 | 1740 |
realOutStream nextPutInt32:crc MSB:true. |
2703 | 1741 |
! |
2683 | 1742 |
|
2703 | 1743 |
writeEndChunk |
1744 |
self |
|
1745 |
writeChunk: 'IEND' |
|
1746 |
size: 0 |
|
1747 |
with:[ ] |
|
2683 | 1748 |
! |
1749 |
||
2703 | 1750 |
writeIHDRChunk |
4005 | 1751 |
|hasMask bitsPerChannel| |
3893 | 1752 |
|
3949 | 1753 |
hasMask := self determineColorTypeAndHasMask. |
3893 | 1754 |
hasMask ifTrue:[ |
3900 | 1755 |
"/ make it grayAlpha / rgba |
1756 |
((colorType == ColorTypeGray) or:[colorType == ColorTypeGray]) ifTrue:[ |
|
1757 |
colorType := colorType bitOr:4. "/ +alpha |
|
1758 |
]. |
|
3893 | 1759 |
]. |
4005 | 1760 |
|
1761 |
"bitsperchannel" |
|
1762 |
depth <= 8 ifTrue:[ |
|
1763 |
bitsPerChannel := depth |
|
1764 |
] ifFalse:[ |
|
4010 | 1765 |
(colorType == ColorTypeRGB or:[colorType == ColorTypeRGBAlpha]) ifTrue:[ |
4005 | 1766 |
"/ all channels must have the same nr of bits |
1767 |
self assert:(bitsPerSample asSet size == 1). |
|
1768 |
bitsPerChannel := bitsPerSample first |
|
1769 |
] ifFalse:[ |
|
1770 |
bitsPerChannel := depth |
|
1771 |
] |
|
1772 |
]. |
|
3893 | 1773 |
|
2683 | 1774 |
self |
1775 |
writeChunk: 'IHDR' |
|
3949 | 1776 |
size: (4+4+5) |
2683 | 1777 |
with:[ |
4004 | 1778 |
outStream nextPutInt32:width MSB:true. |
1779 |
outStream nextPutInt32:height MSB:true. |
|
4005 | 1780 |
outStream nextPut: bitsPerChannel. |
2703 | 1781 |
outStream nextPut: colorType. |
2683 | 1782 |
outStream nextPut: 0. "Compression" |
1783 |
outStream nextPut: 0. "Filter method" |
|
1784 |
outStream nextPut: 0 "Non-interlaced" |
|
1785 |
] |
|
3893 | 1786 |
|
4010 | 1787 |
"Modified: / 04-09-2017 / 18:34:15 / cg" |
2683 | 1788 |
! |
1789 |
||
2703 | 1790 |
writeImageDataChunk |
3893 | 1791 |
|compressedByteStream compressedBytes zlibWriter idx |
3935 | 1792 |
row32 bytesPerPixel| |
2703 | 1793 |
|
1794 |
bytesPerScanline := self bytesPerRow. |
|
3821 | 1795 |
|
1796 |
compressedByteStream := WriteStream on:(ByteArray new:(bytesPerScanline*height)). |
|
1797 |
zlibWriter := ZipStream writeOpenAsZipStreamOn:compressedByteStream suppressHeaderAndChecksum:false. |
|
1798 |
zlibWriter binary. |
|
2703 | 1799 |
|
3900 | 1800 |
(mask notNil and:[photometric ~~ #palette]) ifTrue:[ |
3935 | 1801 |
(depth == 32) ifTrue:[ |
1802 |
bytesPerPixel := 4 |
|
1803 |
] ifFalse:[ |
|
1804 |
"/ for now - only support depth24 + mask |
|
1805 |
self assert:(depth == 24). |
|
1806 |
bytesPerPixel := 3. |
|
1807 |
]. |
|
3893 | 1808 |
|
3935 | 1809 |
"/ on-the-fly place mask into the alpha channel. |
3893 | 1810 |
row32 := ByteArray new:(4 * width). |
3935 | 1811 |
self assert:(bytesPerScanline == (bytesPerPixel * width)). |
1812 |
||
3893 | 1813 |
idx := 1. |
1814 |
0 to:height-1 do:[:y | |
|
1815 |
|dstIdx maskRow| |
|
2708 | 1816 |
|
3893 | 1817 |
"/ expand rgb to rgba |
1818 |
maskRow := mask rowAt:y. |
|
3935 | 1819 |
|
3893 | 1820 |
dstIdx := 1. |
1821 |
1 to:width do:[:x | |
|
1822 |
row32 at:dstIdx put:(data at:idx). |
|
1823 |
row32 at:dstIdx+1 put:(data at:idx+1). |
|
1824 |
row32 at:dstIdx+2 put:(data at:idx+2). |
|
1825 |
row32 at:dstIdx+3 put:((maskRow at:x) == 0 ifTrue:[0] ifFalse:[16rFF]). |
|
3935 | 1826 |
idx := idx + bytesPerPixel. |
3893 | 1827 |
dstIdx := dstIdx + 4. |
1828 |
]. |
|
3935 | 1829 |
|
3893 | 1830 |
zlibWriter nextPutAll:#[0]. "/ no filter |
1831 |
zlibWriter nextPutAll:row32. |
|
1832 |
]. |
|
1833 |
] ifFalse:[ |
|
1834 |
idx := 1. |
|
1835 |
0 to:height-1 do:[:y | |
|
1836 |
|row| |
|
1837 |
||
1838 |
row := data copyFrom:idx to:(idx+bytesPerScanline-1). |
|
1839 |
zlibWriter nextPutAll:#[0]. "/ no filter |
|
1840 |
zlibWriter nextPutAll:row. |
|
1841 |
idx := idx + bytesPerScanline. |
|
1842 |
]. |
|
2703 | 1843 |
]. |
2708 | 1844 |
|
1845 |
zlibWriter close. |
|
1846 |
compressedBytes := compressedByteStream contents. |
|
1847 |
||
1848 |
self |
|
1849 |
writeChunk: 'IDAT' |
|
1850 |
size:(compressedBytes size) |
|
1851 |
with:[ |
|
1852 |
outStream nextPutAll:compressedBytes |
|
1853 |
] |
|
3893 | 1854 |
|
3935 | 1855 |
"Modified: / 25-02-2017 / 14:27:34 / cg" |
3949 | 1856 |
"Modified (format): / 11-04-2017 / 12:41:22 / cg" |
2703 | 1857 |
! |
1858 |
||
2683 | 1859 |
writePaletteChunk |
1860 |
self |
|
1861 |
writeChunk: 'PLTE' |
|
1862 |
size: 3 * colorMap size |
|
1863 |
with:[ |
|
2703 | 1864 |
colorMap do:[:color | |
1865 |
outStream |
|
1866 |
nextPut: color redByte; |
|
1867 |
nextPut: color greenByte; |
|
1868 |
nextPut: color blueByte |
|
2683 | 1869 |
] |
1870 |
] |
|
3900 | 1871 |
! |
1872 |
||
1873 |
writeTRNSChunk |
|
1874 |
self |
|
1875 |
writeChunk: 'tRNS' |
|
1876 |
size: 1 |
|
1877 |
with:[ |
|
1878 |
outStream nextPut: paletteIndexForMaskedPixels |
|
1879 |
] |
|
1880 |
||
1881 |
"Created: / 16-02-2017 / 19:58:06 / cg" |
|
2683 | 1882 |
! ! |
1883 |
||
398 | 1884 |
!PNGReader class methodsFor:'documentation'! |
308 | 1885 |
|
1886 |
version |
|
3554 | 1887 |
^ '$Header$' |
2909 | 1888 |
! |
1889 |
||
1890 |
version_CVS |
|
3554 | 1891 |
^ '$Header$' |
308 | 1892 |
! ! |
1671 | 1893 |
|
3100 | 1894 |
|
308 | 1895 |
PNGReader initialize! |