fukasawa e60969
PngMinus
fukasawa e60969
--------
fukasawa e60969
(copyright Willem van Schaik, 1999)
fukasawa e60969
fukasawa e60969
fukasawa e60969
License
fukasawa e60969
-------
fukasawa e60969
fukasawa e60969
Permission to use, copy, modify, and distribute this software and
fukasawa e60969
its documentation for any purpose and without fee is hereby granted,
fukasawa e60969
provided that the above copyright notice appear in all copies and
fukasawa e60969
that both that copyright notice and this permission notice appear in
fukasawa e60969
supporting documentation. This software is provided "as is" without
fukasawa e60969
express or implied warranty.
fukasawa e60969
fukasawa e60969
fukasawa e60969
Some history
fukasawa e60969
------------
fukasawa e60969
Soon after the creation of PNG in 1995, the need was felt for a set of
fukasawa e60969
pnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I
fukasawa e60969
(Willem van Schaik) started such a project. Luckily we discovered this
fukasawa e60969
and merged the two together into pnmtopng.tar.gz, which is available
fukasawa e60969
from a/o ftp://ftp.simplesystems.org/pub/libpng/png/.
fukasawa e60969
fukasawa e60969
These two utilities have many, many options and make use of most of the
fukasawa e60969
features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes
fukasawa e60969
the utilities quite complex and by now not anymore very maintainable.
fukasawa e60969
When we wrote these programs, libpng was still in an early stage.
fukasawa e60969
Therefore, lots of the functionality that we put in our software can now
fukasawa e60969
be done using transform-functions in libpng.
fukasawa e60969
fukasawa e60969
Finally, to compile these programs, you need to have installed and
fukasawa e60969
compiled three libraries: libpng, zlib and netpbm. Especially the latter
fukasawa e60969
makes the whole setup a bit bulky. But that's unavoidable given the many
fukasawa e60969
features of pnmtopng.
fukasawa e60969
fukasawa e60969
fukasawa e60969
What now
fukasawa e60969
--------
fukasawa e60969
At this moment libpng is in a very stable state and can do much of the
fukasawa e60969
work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new
fukasawa e60969
interface of libpng. Hence, it is time for a rewrite from the ground up
fukasawa e60969
of pnmtopng and pngtopnm. This will happen in the near future (stay
fukasawa e60969
tuned). The new package will get a different name to distinguish it from
fukasawa e60969
the old one: PngPlus.
fukasawa e60969
fukasawa e60969
To experiment a bit with the new interface of libpng, I started off with
fukasawa e60969
a small prototype that contains only the basic functionality. It doesn't
fukasawa e60969
have any of the options to read or write special chunks and it will do
fukasawa e60969
no gamma correction. But this makes it also a simple program that is
fukasawa e60969
quite easy to understand and can serve well as a template for other
fukasawa e60969
software developments. (By now there are of course a couple of programs,
fukasawa e60969
like Greg Roelofs' rpng/wpng, that can be used just as good.)
fukasawa e60969
fukasawa e60969
fukasawa e60969
Can and can not
fukasawa e60969
---------------
fukasawa e60969
As this is the small brother of the future PngPlus, I called this fellow
fukasawa e60969
PngMinus. Because I started this development in good-old Turbo-C, I
fukasawa e60969
avoided the use the netpbm library, which requires DOS extenders. Again,
fukasawa e60969
another reason to call it PngMinus (minus netpbm :-). So, part of the
fukasawa e60969
program are some elementary routines to read / write pgm- and ppm-files.
fukasawa e60969
It does not read b&w pbm-files.
fukasawa e60969
fukasawa e60969
The downside of this approach is that you can not use them on images
fukasawa e60969
that require blocks of memory bigger than 64k (the DOS version). For
fukasawa e60969
larger images you will get an out-of-memory error.
fukasawa e60969
fukasawa e60969
As said before, PngMinus doesn't correct for gamma. When reading
fukasawa e60969
png-files you can do this just as well by piping the output of png2pnm
fukasawa e60969
to pnmgamma, one of the standard PbmPlus tools. This same scenario will
fukasawa e60969
most probably also be followed in the full-blown future PngPlus, with
fukasawa e60969
the addition of course of the possibility to create gamma-chunks when
fukasawa e60969
writing png-files.
fukasawa e60969
fukasawa e60969
On the other hand it supports alpha-channels. When reading a png-image
fukasawa e60969
you can write the alpha-channel into a pgm-file. And when creating an
fukasawa e60969
RGB+A png-image, you just combine a ppm-file with a corresponding
fukasawa e60969
pgm-file containing the alpha-channel. When reading, transparency chunks
fukasawa e60969
are converted into an alpha-channel and from there on treated the same
fukasawa e60969
way.
fukasawa e60969
fukasawa e60969
Finally you can opt for writing ascii or binary pgm- and ppm-files. When
fukasawa e60969
the bit-depth is 16, the format will always be ascii.
fukasawa e60969
fukasawa e60969
fukasawa e60969
Using it
fukasawa e60969
--------
fukasawa e60969
To distinguish them from pnmtopng and PngPlus, the utilities are named
fukasawa e60969
png2pnm and pnm2png (2 instead of to). The input- and output-files can
fukasawa e60969
be given as parameters or through redirection. Therefore the programs
fukasawa e60969
can be part of a pipe.
fukasawa e60969
fukasawa e60969
To list the options type "png2pnm -h" or "pnm2png -h".
fukasawa e60969
fukasawa e60969
fukasawa e60969
Just like Scandinavian furniture
fukasawa e60969
--------------------------------
fukasawa e60969
You have to put it together yourself. I did test the software under
fukasawa e60969
MS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both
fukasawa e60969
cases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK,
fukasawa e60969
however some older libpng versions have a bug in pngmem.c when using
fukasawa e60969
Turbo-C 3.0 (see below).
fukasawa e60969
fukasawa e60969
You can build it using one of the two makefiles (make -f makefile.###)
fukasawa e60969
or use the batch/script files pngminus.bat / pngminus.sh. This assumes
fukasawa e60969
that you have built the libraries in ../libpng and ../zlib. Using Linux,
fukasawa e60969
make sure that you have built libpng with makefile.std and not
fukasawa e60969
makefile.linux (also called .lnx in earlier versions of libpng). The
fukasawa e60969
latter creates a .so shared-library, while the PngMinus makefile assumes
fukasawa e60969
a normal .a static library.
fukasawa e60969
fukasawa e60969
If you create a ../pngsuite directory and then store the basn####.png
fukasawa e60969
files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can
fukasawa e60969
test in one go the proper functioning of PngMinus, see png2pnm.bat and
fukasawa e60969
pnm2png.bat (or the .sh versions).
fukasawa e60969
fukasawa e60969
fukasawa e60969
Warranty
fukasawa e60969
-------
fukasawa e60969
Please, remember that this was just a small experiment to learn a few
fukasawa e60969
things. It will have many unforeseen features <vbg>. Who said bugs? Use</vbg>
fukasawa e60969
it when you are in need for something simple or when you want to start
fukasawa e60969
developing your own stuff.
fukasawa e60969
fukasawa e60969
fukasawa e60969
The Turbo bug
fukasawa e60969
-------------
fukasawa e60969
** pngmem.old
fukasawa e60969
          hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
fukasawa e60969
          hptr += 16L;
fukasawa e60969
** pngmem.c
fukasawa e60969
          hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
fukasawa e60969
          hptr = hptr + 16L;
fukasawa e60969
**
fukasawa e60969
fukasawa e60969
** pngmem.old
fukasawa e60969
          png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
fukasawa e60969
          hptr += (png_uint_32)65536L;
fukasawa e60969
** pngmem.c
fukasawa e60969
          png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
fukasawa e60969
          hptr = hptr + 65536L;
fukasawa e60969
**
fukasawa e60969
fukasawa e60969
fukasawa e60969
The end
fukasawa e60969
-------
fukasawa e60969
Willem van Schaik
fukasawa e60969
mailto:willem@schaik.com
fukasawa e60969
http://www.schaik.com/png/
fukasawa e60969
-------
fukasawa e60969
Oct 1999
fukasawa e60969