Portable Network Graphics (PNG) decoder (more or less) for Common Lisp.
All critical chunks are implemented. Most ancillary chunks are. It should be able to read back any file produced by ZPNG. Interlaced files can be read, but without progressive loading.
Usage:
read-png-file (file)
and read-png-datastream (stream)
, both return a png-state object and a
boolean to indicate if CRC was successful, which most interesting property is image-data
, a two
(grayscale) or three dimensional array containing image data. Other properties are width
,
height
, bit-depth
and colour-type
. If file was loaded by read-png-file
slot png-file
contains pathname used.
Dynamic variable *crc-fail-behaviour*
can be set to one of :error
, :warn
or :no-action
(default is :error
), and controls what happens on checksum failure. Error signalled is of type
png-read:crc-failure
, and restart png-read:ignore-crc-failure
is established.
For indexed images slot index-data contains an array with indices in palette (stored in palette
slot), and image-data
contains decoded colors.
The library loads all files from PNG Suite , but I did not check whether it does so correctly.
Note that ancillary chunks are mostly untested. They never modify primary image data array directly,
but provide additional information in slots of png-state object. Of the ancillary chunks specified
in specification missing are: cHRM
, iCCP
and
sPLT
. gAMA
is present, but using it is responsibility of library user.
Dynamic variable *warn-missing-ancillaries*
controls whether library warns on encountering unknown
ancillary chunk.
Ancillary chunks:
-
tRNS
- if present, additional alpha map is stored in slottransparency
-
gAMA
- if present, image gamma is stored in slotgamma
-
sBIT
- if present, the original number of significant bits is stored in slotsignificant-bits
as a property list -
sRGB
- if present, rendering intent is stored in slotrendering-intent
as a keyword symbol -
tEXt
- if present, text strings are collected in slottextual-data
as an association list of keyword and string -
zTXt
- if present, text strings are collected in slottextual-data
as an association list of keyword and string -
iTXt
- if present, text strings are collected in slottextual-data
as an association list of keyword and a list of language tag, translated keyword and translated text -
bKGD
- if present, preferred background is stored in slotpreferred-background
as an array of color components (RGB), greyscale datum or palette index -
hIST
- if present, image histogram is stored in slotimage-histogram
as an array -
pHYS
- if present, intended pixel size is stored in slotphysical-dimensions
as a property list -
tIME
- if present, last modification time is stored in slotlast-modification
as an universal time