PNGReader.st
changeset 3904 f9baf7a194d9
parent 3903 754f50ffb404
child 3909 a275bdd921fc
equal deleted inserted replaced
3903:754f50ffb404 3904:f9baf7a194d9
   933     "Modified: 21.6.1996 / 21:20:42 / cg"
   933     "Modified: 21.6.1996 / 21:20:42 / cg"
   934 !
   934 !
   935 
   935 
   936 processTRNSChunkLen:len
   936 processTRNSChunkLen:len
   937     paletteAlphaEntries := inStream nextBytes:len.
   937     paletteAlphaEntries := inStream nextBytes:len.
   938     ^ true
   938     
   939 
   939     colorType == ColorTypeRGB ifTrue:[
   940     "Modified: / 17-02-2017 / 09:39:25 / cg"
   940         len ~~ 3 ifTrue:[
       
   941             Logger warning:'PNG: bad trns chunk size'.
       
   942             paletteAlphaEntries := nil.
       
   943         ].
       
   944         ^ true
       
   945     ].    
       
   946     colorType == ColorTypePalette ifTrue:[
       
   947         len ~~ 1 ifTrue:[
       
   948             Logger warning:'PNG: bad trns chunk size'.
       
   949             paletteAlphaEntries := nil.
       
   950         ].
       
   951         ^ true
       
   952     ].        
       
   953     colorType == ColorTypeGray ifTrue:[
       
   954         len ~~ 2 ifTrue:[
       
   955             Logger warning:'PNG: bad trns chunk size'.
       
   956             paletteAlphaEntries := nil.
       
   957         ].
       
   958         ^ true
       
   959     ].        
       
   960     paletteAlphaEntries := nil.
       
   961     ^ true
       
   962 
       
   963     "Modified (format): / 17-02-2017 / 16:57:27 / cg"
   941 !
   964 !
   942 
   965 
   943 processZTXTChunkLen:len
   966 processZTXTChunkLen:len
   944     "/ compressed text
   967     "/ compressed text
   945     
   968     
  1369     depth := self bitsPerPixel.
  1392     depth := self bitsPerPixel.
  1370 
  1393 
  1371     outStream nextPutAll:(self pngHeader).
  1394     outStream nextPutAll:(self pngHeader).
  1372     
  1395     
  1373     image mask notNil ifTrue:[
  1396     image mask notNil ifTrue:[
  1374         (photometric ~~ #rgba) ifTrue: [
  1397         ((photometric ~~ #rgb) and:[(photometric ~~ #rgba)]) ifTrue: [
  1375             image maskedPixelsAre0 ifTrue:[
  1398             image maskedPixelsAre0 ifTrue:[
  1376                 paletteIndexForMaskedPixels := 0
  1399                 paletteIndexForMaskedPixels := 0
  1377             ] ifFalse:[
  1400             ] ifFalse:[
  1378                 self determinePaletteIndexForMaskedPixels
  1401                 self determinePaletteIndexForMaskedPixels
  1379             ]
  1402             ]
  1380         ].
  1403         ] ifFalse:[
       
  1404             photometric := #rgba.
       
  1405         ].    
  1381     ].
  1406     ].
  1382 
  1407 
  1383     self writeIHDRChunk.
  1408     self writeIHDRChunk.
  1384     photometric == #palette ifTrue: [self writePaletteChunk].
  1409     photometric == #palette ifTrue: [self writePaletteChunk].
  1385     paletteIndexForMaskedPixels notNil ifTrue: [self writeTRNSChunk].
  1410     paletteIndexForMaskedPixels notNil ifTrue: [self writeTRNSChunk].
  1386     self writeImageDataChunk.
  1411     self writeImageDataChunk.
  1387     self writeEndChunk
  1412     self writeEndChunk
  1388 
  1413 
  1389     "Modified: / 16-02-2017 / 21:18:05 / cg"
  1414     "Modified: / 17-02-2017 / 17:27:52 / cg"
  1390 ! !
  1415 ! !
  1391 
  1416 
  1392 !PNGReader methodsFor:'writing-private'!
  1417 !PNGReader methodsFor:'writing-private'!
  1393 
  1418 
  1394 determinePaletteIndexForMaskedPixels
  1419 determinePaletteIndexForMaskedPixels
  1532         0 to:height-1 do:[:y |
  1557         0 to:height-1 do:[:y |
  1533             |dstIdx maskRow|
  1558             |dstIdx maskRow|
  1534 
  1559 
  1535             "/ expand rgb to rgba
  1560             "/ expand rgb to rgba
  1536             maskRow := mask rowAt:y.
  1561             maskRow := mask rowAt:y.
  1537             self halt.
       
  1538             
  1562             
  1539             dstIdx := 1.
  1563             dstIdx := 1.
  1540             1 to:width do:[:x |
  1564             1 to:width do:[:x |
  1541                 row32 at:dstIdx put:(data at:idx).
  1565                 row32 at:dstIdx put:(data at:idx).
  1542                 row32 at:dstIdx+1 put:(data at:idx+1).
  1566                 row32 at:dstIdx+1 put:(data at:idx+1).
  1569         size:(compressedBytes size)
  1593         size:(compressedBytes size)
  1570         with:[ 
  1594         with:[ 
  1571             outStream nextPutAll:compressedBytes
  1595             outStream nextPutAll:compressedBytes
  1572         ]
  1596         ]
  1573 
  1597 
  1574     "Modified: / 16-02-2017 / 21:13:26 / cg"
  1598     "Modified: / 17-02-2017 / 17:02:16 / cg"
  1575 !
  1599 !
  1576 
  1600 
  1577 writePaletteChunk
  1601 writePaletteChunk
  1578     self 
  1602     self 
  1579         writeChunk: 'PLTE'
  1603         writeChunk: 'PLTE'