eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'PNGReader':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: PNGReader


Inheritance:

   Object
   |
   +--ImageReader
      |
      +--PNGReader

Package:
stx:libview2
Category:
Graphics-Images-Readers
Version:
rev: 1.69 date: 2018/01/24 20:31:28
user: cg
file: PNGReader.st directory: libview2
module: stx stc-classLibrary: libview2
Author:
Claus Gittinger

Description:


This class provides methods for loading and saving PNG pictures.
It is currenty unfinished (some interlaced image formats are unsupported, for example: grayscale+alpha)
In the meantime, use a pngtoXXX converter for interlaced images, and read XXX.

[caveats:]
    writer can only store mask with depth24 images (for now).
    writer only generates unfiltered non-interlaced data.
    
[Special:]
    the EnforcedImageTypeQuery is asked for;
    if #rgb is returned AND the image is rgba, then the alpha channel is ignored
    and an rgb (Depth24Image) is returned instead.


Related information:

    Image
    Form
    Icon
    BlitImageReader
    FaceReader
    GIFReader
    JPEGReader
    PBMReader
    PCXReader
    ST80FormReader
    SunRasterReader
    TargaReader
    TIFFReader
    WindowsIconReader
    XBMReader
    XPMReader
    XWDReader

Class protocol:

accessing
o  pngHeader

initialization
o  initialize
install myself in the Image classes fileFormat table for the `.png' extension.

queries
o  canRepresent: anImage
return true, if anImage can be represented in my file format.
Any image without mask is supported;
only depth24 images with mask are (currently).

testing
o  isValidImageFile: aFileName
return true, if aFileName contains a PNG image
usage example(s):
     self isValidImageFile:'/home/cg/AudioExplorer_51_files/use_small.png'
     self isValidImageFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png'
     self isValidImageFile:'C:\Dokumente und Einstellungen\cg\Desktop\misc\PNGs\Delete.png'


Instance protocol:

accessing
o  makeImage
(comment from inherited method)
return the image as represented by the values found in my
instvars; these have been typically set as a side effect of
the fromStream:-method, which reads images.

o  pngHeader

** This is an obsolete interface - do not use it (it may vanish in future versions) **

hooks
o  specialChunkHandlerAt: chunkType put: aHandlerBlock
define a handler action, which processes unknown chunks.
The handler block will be called with one or two arguments:
the binary data of the chunk, and optionally the reader itself

reading
o  fromStream: aStream
read a stream containing a PNG image.
Leave the image description in instance variables
(i.e. to get the image, ask with image).

reading-private
o  generateMaskFromPaletteAlphaEntries
if there is only one entry to care for...

o  getChunk
ignored - for now

o  getIHDRChunk
for now - might be changed by setColorType.

o  handleText: text keyword: keyword
things like exif data etc.

o  setColorType: colorType
0

reading-private chunks
o  doPass: pass
Certain interlace passes are skipped with certain small image dimensions

o  processBKGDChunkLen: len

o  processCHRMChunkLen: len
cHRM Primary chromaticities chunk - currently unhandled

o  processChunk: type len: len
---since the compressed data can span multiple
chunks, stitch them all together first. later,
if memory is an issue, we need to figure out how
to do this on the fly---

o  processEXEXChunkLen: len
this cunk contains an expecco sample network.

o  processGAMAChunkLen: len

o  processGlobalIDATChunk

o  processHISTChunkLen: len
ignored

o  processICCPChunkLen: len
ignored

o  processIDATChunkLen: len

o  processIHDRChunkLen: len
ignored

o  processITXTChunkLen: len
international (i.e.utf8) textual data.

o  processInterlacedDATA: len

o  processInterlacedGlobalDATA
adam7 interlace method

o  processNIVIChunkLen: len
this cunk contains a labView vi.

o  processNonInterlacedDATA: len

o  processNonInterlacedGlobalDATA
data n

o  processPHYSChunkLen: len
physical pixel chunk - currently unhandled

o  processPLTEChunkLen: len
read a color palette

o  processSBITChunkLen: len

o  processSPALChunkLen: len
ignored

o  processTEXTChunkLen: len
textual data in iso8859 coding.

o  processTIMEChunkLen: len

o  processTRNSChunkLen: len
Modified (format): / 17-02-2017 / 16:57:27 / cg

o  processZTXTChunkLen: len
compressed text

reading-private filtering
o  filterAverage: count
Use the average of the pixel to the left and the pixel above as a predictor

o  filterHorizontal: count
use the pixel to the left as a predictor

o  filterNone: count
no filter - scanline is as is

o  filterPaeth: count
Select one of (the pixel to the left, the pixel above and the pixel to above left) to
predict the value of this pixel

o  filterScanline: filterType count: count

o  filterVertical: count
Use the pixel above as a predictor

o  paethPredictLeft: l above: a aboveLeft: al
Predicts the value of a pixel based on nearby pixels, based on Paeth (GG II, 1991)

reading-private pixel copy
o  copyPixels: y at: startX by: incX
Handle interlaced pixels of supported colorTypes

o  copyPixelsGray: y at: startX by: incX
Handle interlaced pixels of supported colorTypes.
Untested code - please verify

o  copyPixelsGrayAlpha: y at: startX by: incX
Handle interlaced pixels of supported colorTypes.

o  copyPixelsIndexed: y at: startX by: incX

o  copyPixelsRGB: y at: startX by: incX
Handle interlaced pixels of supported colorTypes.
Untested code - please verify

o  copyPixelsRGBA: y at: startX by: incX
Handle interlaced pixels of supported colorTypes.
Untested code - please verify

writing
o  save: image onStream: aStream
save image in PNG-file-format onto aStream

writing-private
o  determinePaletteIndexForMaskedPixels
if all masked pixels are 0, and 0 is not used elsewhere in the image,

writing-private chunks
o  determineColorTypeAndHasMask
sets colorType as side effect;
returns boolean if a mask is present

o  writeChunk: chunkTypeChars size: len with: aBlock

o  writeEndChunk

o  writeIHDRChunk
make it grayAlpha / rgba

o  writeImageDataChunk
for now - only support depth24 + mask

o  writePaletteChunk

o  writeTRNSChunk


Examples:


PNGReader fromFile:'/home/cg/AudioExplorer_51_files/use_small.png' PNGReader fromFile:'\\Exeptn\tmp\images\expeccoScreenshot4020_5526507.png' PNGReader fromFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png' PNGReader fromFile:'C:\Dokumente und Einstellungen\cg\Desktop\misc\PNGs\Delete.png' PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Delete.png' PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Down.png' |img img2 outStream png| img := ToolbarIconLibrary error32x32Icon. outStream := WriteStream on:(ByteArray new:100). PNGReader save:img onStream:outStream. png := outStream contents. img2 := PNGReader fromStream:(png readStream). self assert:(img bits = img2 bits). img inspect. img2 inspect.

ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Wed, 12 Dec 2018 09:44:10 GMT