|
Class: PNGReader
Object
|
+--ImageReader
|
+--PNGReader
- Package:
- stx:libview2
- Category:
- Graphics-Images-Readers
- Version:
- rev:
1.80
date: 2019/06/06 21:21:49
- user: cg
- file: PNGReader.st directory: libview2
- module: stx stc-classLibrary: libview2
- Author:
- Claus Gittinger
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.
Proprietary chunks can be extracted by defining a specialChunkHandler,
which is invoked (indexed by chunkType) with the chunk data when such a
chunk is encountered. This allows for private data to be extracted.
(labview does this, and expecco can do this)
Proprietary chunks can be written by setting the specialChunks collection
before writing.
Image
Form
Icon
BlitImageReader
FaceReader
GIFReader
JPEGReader
MacOSXIconReader
PBMReader
PCXReader
ST80FormReader
SunRasterReader
TargaReader
TIFFReader
WindowsIconReader
XBMReader
XPMReader
XWDReader
accessing
-
pngHeader
-
initialization
-
initialize
-
install myself in the Image classes fileFormat table for the `.png' extension.
queries
-
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
-
file: filename hasSpecialChunk: chunkTag
-
true if there is a special chunk with chunkTag in filename
-
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'
|
accessing
-
extractSpecialChunksOnly: aBoolean
-
if set to true, only special chunks will be processed via
corresponding specialChunkHandlers.
No image will be extracted.
The default is (of course) false.
-
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.
-
pngHeader
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
specialChunks: aDictionaryOfChunkTypesAndBlobs
-
Modified (format): / 27-10-2018 / 16:09:56 / Claus Gittinger
hooks
-
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
-
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
-
generateMaskFromPaletteAlphaEntries
-
if there is only one entry to care for...
-
getChunk
-
ignored - for now
-
getIHDRChunk
-
for now - might be changed by setColorType.
-
handleText: text keyword: keyword
-
things like exif data etc.
-
setColorType: colorType
-
0
reading-private chunks
-
doPass: pass
-
Certain interlace passes are skipped with certain small image dimensions
-
processBKGDChunkLen: len
-
-
processCHRMChunkLen: len
-
cHRM Primary chromaticities chunk - currently unhandled
-
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---
-
processEXEXChunkLen: len
-
this cunk contains an expecco sample network.
-
processGAMAChunkLen: len
-
-
processGlobalIDATChunk
-
-
processHISTChunkLen: len
-
ignored
-
processICCPChunkLen: len
-
ignored
-
processIDATChunkLen: len
-
-
processIHDRChunkLen: len
-
ignored
-
processITXTChunkLen: len
-
international (i.e.utf8) textual data.
-
processInterlacedDATA: len
-
-
processInterlacedGlobalDATA
-
adam7 interlace method
-
processNIVIChunkLen: len
-
this cunk contains a labView vi.
-
processNonInterlacedDATA: len
-
-
processNonInterlacedGlobalDATA
-
data n
-
processPHYSChunkLen: len
-
physical pixel chunk - currently unhandled
-
processPLTEChunkLen: len
-
read a color palette
-
processSBITChunkLen: len
-
-
processSPALChunkLen: len
-
ignored
-
processSRGBChunkLen: len
-
ignored
-
processTEXTChunkLen: len
-
textual data in iso8859 coding.
-
processTIMEChunkLen: len
-
-
processTRNSChunkLen: len
-
Modified (format): / 17-02-2017 / 16:57:27 / cg
-
processZTXTChunkLen: len
-
compressed text
reading-private filtering
-
filterAverage: count
-
Use the average of the pixel to the left and the pixel above as a predictor
-
filterHorizontal: count
-
use the pixel to the left as a predictor
-
filterNone: count
-
no filter - scanline is as is
-
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
-
filterScanline: filterType count: count
-
-
filterVertical: count
-
Use the pixel above as a predictor
-
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
-
copyPixels: y at: startX by: incX
-
Handle interlaced pixels of supported colorTypes
-
copyPixelsGray: y at: startX by: incX
-
Handle interlaced pixels of supported colorTypes.
Untested code - please verify
-
copyPixelsGrayAlpha: y at: startX by: incX
-
Handle interlaced pixels of supported colorTypes.
-
copyPixelsIndexed: y at: startX by: incX
-
-
copyPixelsRGB: y at: startX by: incX
-
Handle interlaced pixels of supported colorTypes.
Untested code - please verify
-
copyPixelsRGBA: y at: startX by: incX
-
Handle interlaced pixels of supported colorTypes.
Untested code - please verify
writing
-
save: image onStream: aStream
-
save image in PNG-file-format onto aStream
writing-private
-
determinePaletteIndexForMaskedPixels
-
if all masked pixels are 0, and 0 is not used elsewhere in the image,
writing-private chunks
-
determineColorTypeAndHasMask
-
sets colorType as side effect;
returns boolean if a mask is present
-
writeChunk: chunkTypeChars size: len with: aBlock
-
-
writeEndChunk
-
-
writeIHDRChunk
-
make it grayAlpha / rgba
-
writeImageDataChunk
-
for now - only support depth24 + mask
-
writePaletteChunk
-
-
writeSpecialChunks
-
-
writeTRNSChunk
-
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.
|