lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | PngMinus |
| 2 | -------- |
| 3 | (copyright Willem van Schaik, 1999) |
| 4 | |
| 5 | |
| 6 | License |
| 7 | ------- |
| 8 | |
| 9 | Permission to use, copy, modify, and distribute this software and |
| 10 | its documentation for any purpose and without fee is hereby granted, |
| 11 | provided that the above copyright notice appear in all copies and |
| 12 | that both that copyright notice and this permission notice appear in |
| 13 | supporting documentation. This software is provided "as is" without |
| 14 | express or implied warranty. |
| 15 | |
| 16 | |
| 17 | Some history |
| 18 | ------------ |
| 19 | Soon after the creation of PNG in 1995, the need was felt for a set of |
| 20 | pnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I |
| 21 | (Willem van Schaik) started such a project. Luckily we discovered this |
| 22 | and merged the two together into pnmtopng.tar.gz, which is available |
| 23 | from a/o ftp://swrinde.nde.swri.edu/pub/png/. |
| 24 | |
| 25 | These two utilities have many, many options and make use of most of the |
| 26 | features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes |
| 27 | the utilities quite complex and by now not anymore very maintainable. |
| 28 | When we wrote these programs, libpng was still in an early stage. |
| 29 | Therefore, lots of the functionality that we put in our software can now |
| 30 | be done using transform-functions in libpng. |
| 31 | |
| 32 | Finally, to compile these programs, you need to have installed and |
| 33 | compiled three libraries: libpng, zlib and netpbm. Especially the latter |
| 34 | makes the whole setup a bit bulky. But that's unavoidable given the many |
| 35 | features of pnmtopng. |
| 36 | |
| 37 | |
| 38 | What now |
| 39 | -------- |
| 40 | At this moment libpng is in a very stable state and can do much of the |
| 41 | work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new |
| 42 | interface of libpng. Hence, it is time for a rewrite from the ground up |
| 43 | of pnmtopng and pngtopnm. This will happen in the near future (stay |
| 44 | tuned). The new package will get a different name to distinguish it from |
| 45 | the old one: PngPlus. |
| 46 | |
| 47 | To experiment a bit with the new interface of libpng, I started off with |
| 48 | a small prototype that contains only the basic functionality. It doesn't |
| 49 | have any of the options to read or write special chunks and it will do |
| 50 | no gamma correction. But this makes it also a simple program that is |
| 51 | quite easy to understand and can serve well as a template for other |
| 52 | software developments. (By now there are of course a couple of programs, |
| 53 | like Greg Roelofs' rpng/wpng, that can be used just as good.) |
| 54 | |
| 55 | |
| 56 | Can and can not |
| 57 | --------------- |
| 58 | As this is the small brother of the future PngPlus, I called this fellow |
| 59 | PngMinus. Because I started this development in good-old Turbo-C, I |
| 60 | avoided the use the netpbm library, which requires DOS extenders. Again, |
| 61 | another reason to call it PngMinus (minus netpbm :-). So, part of the |
| 62 | program are some elementary routines to read / write pgm- and ppm-files. |
| 63 | It does not read b&w pbm-files. |
| 64 | |
| 65 | The downside of this approach is that you can not use them on images |
| 66 | that require blocks of memory bigger than 64k (the DOS version). For |
| 67 | larger images you will get an out-of-memory error. |
| 68 | |
| 69 | As said before, PngMinus doesn't correct for gamma. When reading |
| 70 | png-files you can do this just as well by piping the output of png2pnm |
| 71 | to pnmgamma, one of the standard PbmPlus tools. This same scenario will |
| 72 | most probably also be followed in the full-blown future PngPlus, with |
| 73 | the addition of course of the possibility to create gamma-chunks when |
| 74 | writing png-files. |
| 75 | |
| 76 | On the other hand it supports alpha-channels. When reading a png-image |
| 77 | you can write the alpha-channel into a pgm-file. And when creating an |
| 78 | RGB+A png-image, you just combine a ppm-file with a corresponding |
| 79 | pgm-file containing the alpha-channel. When reading, transparency chunks |
| 80 | are converted into an alpha-channel and from there on treated the same |
| 81 | way. |
| 82 | |
| 83 | Finally you can opt for writing ascii or binary pgm- and ppm-files. When |
| 84 | the bit-depth is 16, the format will always be ascii. |
| 85 | |
| 86 | |
| 87 | Using it |
| 88 | -------- |
| 89 | To distinguish them from pnmtopng and PngPlus, the utilities are named |
| 90 | png2pnm and pnm2png (2 instead of to). The input- and output-files can |
| 91 | be given as parameters or through redirection. Therefore the programs |
| 92 | can be part of a pipe. |
| 93 | |
| 94 | To list the options type "png2pnm -h" or "pnm2png -h". |
| 95 | |
| 96 | |
| 97 | Just like Scandinavian furniture |
| 98 | -------------------------------- |
| 99 | You have to put it together yourself. I did test the software under |
| 100 | MS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both |
| 101 | cases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK, |
| 102 | however some older libpng versions have a bug in pngmem.c when using |
| 103 | Turbo-C 3.0 (see below). |
| 104 | |
| 105 | You can build it using one of the two makefiles (make -f makefile.###) |
| 106 | or use the batch/script files pngminus.bat / pngminus.sh. This assumes |
| 107 | that you have built the libraries in ../libpng and ../zlib. Using Linux, |
| 108 | make sure that you have built libpng with makefile.std and not |
| 109 | makefile.linux (also called .lnx in earlier versions of libpng). The |
| 110 | latter creates a .so shared-library, while the PngMinus makefile assumes |
| 111 | a normal .a static library. |
| 112 | |
| 113 | If you create a ../pngsuite directory and then store the basn####.png |
| 114 | files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can |
| 115 | test in one go the proper functioning of PngMinus, see png2pnm.bat and |
| 116 | pnm2png.bat (or the .sh versions). |
| 117 | |
| 118 | |
| 119 | Warranty |
| 120 | ------- |
| 121 | Please, remember that this was just a small experiment to learn a few |
| 122 | things. It will have many unforeseen features <vbg>. Who said bugs? Use |
| 123 | it when you are in need for something simple or when you want to start |
| 124 | developing your own stuff. |
| 125 | |
| 126 | |
| 127 | The Turbo bug |
| 128 | ------------- |
| 129 | ** pngmem.old |
| 130 | hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); |
| 131 | hptr += 16L; |
| 132 | ** pngmem.c |
| 133 | hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); |
| 134 | hptr = hptr + 16L; |
| 135 | ** |
| 136 | |
| 137 | ** pngmem.old |
| 138 | png_ptr->offset_table_ptr[i] = (png_bytep)hptr; |
| 139 | hptr += (png_uint_32)65536L; |
| 140 | ** pngmem.c |
| 141 | png_ptr->offset_table_ptr[i] = (png_bytep)hptr; |
| 142 | hptr = hptr + 65536L; |
| 143 | ** |
| 144 | |
| 145 | |
| 146 | The end |
| 147 | ------- |
| 148 | Willem van Schaik |
| 149 | mailto:willem@schaik.com |
| 150 | http://www.schaik.com/png/ |
| 151 | ------- |
| 152 | Oct 1999 |
| 153 | |