# HG changeset patch # User Claus Gittinger # Date 1491907332 -7200 # Node ID 4009057d48a368b340ef1691276cfbc8cd7a980c # Parent 9ad96814b90d849a818ff15f8e2dfbfedcd374fa #REFACTORING by cg class: PNGReader added: #determineColorTypeAndHasMask comment/format in: #writeImageDataChunk changed: #save:onStream: #writeIHDRChunk diff -r 9ad96814b90d -r 4009057d48a3 PNGReader.st --- a/PNGReader.st Mon Apr 10 03:48:41 2017 +0000 +++ b/PNGReader.st Tue Apr 11 12:42:12 2017 +0200 @@ -1404,11 +1404,7 @@ image mask notNil ifTrue:[ ((photometric ~~ #rgb) and:[(photometric ~~ #rgba)]) ifTrue: [ - image maskedPixelsAre0 ifTrue:[ - paletteIndexForMaskedPixels := 0 - ] ifFalse:[ - self determinePaletteIndexForMaskedPixels - ] + self determinePaletteIndexForMaskedPixels ] ifFalse:[ photometric := #rgba. ]. @@ -1420,7 +1416,7 @@ self writeImageDataChunk. self writeEndChunk - "Modified: / 22-02-2017 / 11:00:26 / cg" + "Modified: / 11-04-2017 / 12:35:19 / cg" ! ! !PNGReader methodsFor:'writing-private'! @@ -1467,6 +1463,29 @@ !PNGReader methodsFor:'writing-private chunks'! +determineColorTypeAndHasMask + ((photometric == #whiteIs0) or:[ (photometric == #blackIs0)]) ifTrue:[ + colorType := ColorTypeGray. + ^ (samplesPerPixel > 1) + ]. + (photometric == #rgb) ifTrue:[ + colorType := ColorTypeRGB. + ^ (samplesPerPixel > 3) + ]. + (photometric == #rgba) ifTrue:[ + colorType := ColorTypeRGBAlpha. + ^ (samplesPerPixel > 3) + ]. + (photometric == #palette) ifTrue:[ + colorType := ColorTypePalette. + ^ (samplesPerPixel > 1) + ]. + self error:'unhandled photometric: ',photometric asString. + ^ false. + + "Created: / 11-04-2017 / 12:39:30 / cg" +! + writeChunk:chunkTypeChars size:len with:aBlock |crc realOutStream chunkBytes| @@ -1496,31 +1515,7 @@ writeIHDRChunk |hasMask| - hasMask := 0. - - ((photometric == #whiteIs0) or:[ (photometric == #blackIs0)]) ifTrue:[ - colorType := ColorTypeGray. - hasMask := (samplesPerPixel > 1) - ]. - (photometric == #rgb) ifTrue:[ - colorType := ColorTypeRGB. - hasMask := (samplesPerPixel > 3) - ]. - (photometric == #rgba) ifTrue:[ - colorType := ColorTypeRGBAlpha. - hasMask := (samplesPerPixel > 3) - ]. - (photometric == #palette) ifTrue:[ - colorType := ColorTypePalette. - hasMask := (samplesPerPixel > 1) - ]. - colorType isNil ifTrue:[ - self error:'unhandled photometric' - ]. - - mask notNil ifTrue:[ - hasMask := true. - ]. + hasMask := self determineColorTypeAndHasMask. hasMask ifTrue:[ "/ make it grayAlpha / rgba ((colorType == ColorTypeGray) or:[colorType == ColorTypeGray]) ifTrue:[ @@ -1530,7 +1525,7 @@ self writeChunk: 'IHDR' - size: 13 + size: (4+4+5) with:[ self writeLong:width. self writeLong:height. @@ -1541,7 +1536,7 @@ outStream nextPut: 0 "Non-interlaced" ] - "Modified (format): / 16-02-2017 / 21:24:22 / cg" + "Modified: / 11-04-2017 / 12:40:53 / cg" ! writeImageDataChunk @@ -1556,8 +1551,6 @@ (mask notNil and:[photometric ~~ #palette]) ifTrue:[ (depth == 32) ifTrue:[ - "/ on-the-fly put mask into the alpha channel. - bytesPerPixel := 4 ] ifFalse:[ "/ for now - only support depth24 + mask @@ -1566,7 +1559,6 @@ ]. "/ on-the-fly place mask into the alpha channel. - row32 := ByteArray new:(4 * width). self assert:(bytesPerScanline == (bytesPerPixel * width)). @@ -1613,6 +1605,7 @@ ] "Modified: / 25-02-2017 / 14:27:34 / cg" + "Modified (format): / 11-04-2017 / 12:41:22 / cg" ! writePaletteChunk