Vebjorn Ljosa

CL-PNG

CL-PNG is a Common Lisp package for reading and writing PNG (Portable Network Graphics) files. CL-PNG was originally written by Harald Musum, and is now maintained by Vebjorn Ljosa. New versions can be found at the CL-PNG homepage, http://www.ljosa.com/~ljosa/software/cl-png/.

Copyright (C) 2001--2004 by the authors (see the file AUTHORS). Licensed under the GNU Lesser General Public License; see the file COPYING for details.

Status

The PNG specification "PNG (Portable Network Graphics) Specification, Version 1.2", obtainable at http://www.libpng.org/pub/png/, describes the different chunks that a PNG file format consists of. These are divided into critical chunks and auxiliary chunks. All critical PNG chunks are supported for reading (so it should be possible to read all types of PNG images). Writing images with sample depth 16 bits is not supported yet.

Previous versions of this library contained a Lisp implementation of the zlib compressed data format (defined in RFC 1950). Unfortunately, the implementation was very slow, particularly the compression function. In the current version, the Lisp implementation has been replaced with UFFI bindings to libz.

I tested the performance of CL-PNG on Lispworks by decoding and encoding a 768 x 512 pixel RGB image with a depth of 8 bits per channel. From version 0.2 to 0.4, the time to decode the image stayed the same at about 7 seconds. The time to encode the image went down from 45 seconds to 3.7 seconds.

I also tested the performance on CMUCL. Here, from version 0.2 to 0.4, the time to decode stayed the same (well, it went down from 1.2 s to 1.0 s), whereas the time to encode went down from 8.9 s to 2.4 s.

Improving the performance further is a major goal for future versions.

Please note that the interface is likely to change in future versions.

Download

The laters version is 0.4, and can be downloaded here: http://www.ljosa.com/~ljosa/software/cl-png/download/cl-png-0.4.tar.gz. Older versions can be downloaded here: http://www.ljosa.com/~ljosa/software/cl-png/download/.

The individual source code files are available here, in case you would like to take a look at the code before downloading.

Installation

Symlink the file png.asd to one of the directories in ASDF:*CENTRAL-REGISTRY*. In order to compile and load CL-PNG, execute

	(asdf:oos 'asdf:load-op '#:png)

Decoding

	(png:decode-file <PNG-file>)

decodes a file and returns an array with the result

	(png:decode-file <PNG-file> :output-file <PPM-file>)

decodes the file and writes the result to a PGM or PNM file so you can see the result with an external viewer.

Encoding

ENCODE-FILE takes an image array (as produced by DECODE-FILE, for instance) and a file to write the result to as arguments:

	(png:encode-file image-array <PNG-file>)

or

	(png:encode-file (png:decode-file <PNG-file>) <PNG-file>) 

will write an image to <PNG file> (check the options to ENCODE-FILE to see the different combinations of bit depths and color types that are possible).

It is also possible to read from and to a stream with DECODE-STREAM and ENCODE-STREAM.


Last updated: 2004-03-06