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