git clone ''

(ql:quickload :png-read)

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.


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 pallete (stored in pallete 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: