+----------------------------------------------------------------------+ | tiff2png - converts a Tagged Image File Format (TIFF) file into | | a Portable Network Graphics (PNG) file | | | | Copyright 1996 Willem van Schaik, Singapore (willem@schaik.com) | | Copyright 1999-2000 Greg Roelofs (newt@pobox.com) | | | | version 0.81c - November 2000 [see GRR NOTES at end of this file] | +----------------------------------------------------------------------+ This is the first attempt for a tiff2png program. Reason to develop it was the lack of conversion possibilities for TIFF files containing alpha channels. Especially NeXT users create lots of TIFF files that have the rather exceptional 2-bit gray and 4-bit color formats, where both can have an alpha channel besides the graphics info. Because PBMplus is not supporting alpha, that path "tifftopnm | pnmtopng > " makes that the alpha and transparency gets lost. I have chosen to use PNG formats as similar as possible to the format of the original TIFF file. Thus, paletted TIFF files will be converted into PNG files with color-type 3 (= paletted). Only for some cased the bit-depth had to be altered to accommodate both standards. The major decoding and coding work is done by the libtiff, libpng and zlib libraries. So you need to get those as well. For the latter two have a look at: ftp://swrinde.nde.swri.edu/pub/png/src/libpng-*.zip ftp://swrinde.nde.swri.edu/pub/png/src/zlib-*.zip [GRR: or see http://www.libpng.org/pub/png/apps/tiff2png.html] For the libtiff library there are two archives. The major with the latest version is: ftp://ftp.sgi.com/graphics/libtiff/tiff-v3.4-tar.gz [GRR: ftp://ftp.sgi.com/graphics/tiff/tiff-v3.4-tar.gz as of mid-1999] [GRR: http://www.libtiff.org/ as of late 1999] An older (v2.4) but recommendable version (see later) can be found as part of the PBMplus/netpbm package: ftp://ftp.x.org/R5contrib/netpbm-1mar1994.tar.gz [GRR: I recommend version 3.5.5 or later from libtiff.org instead] At this moment the program supports gray-scale images, full-color rgb images as well as paletted ones. This all in 1 to 16 bits. The compression is as good as libtiff is, which is pretty OK. I also implemented support for both single-image-planes as well as separated-color-planes. Support for so-called tiled images I have left out, for the time being. Major headache were the PhotometricInterpretation parameters "min-is-white" and "min-is-black". I couldn't yet figure it out for 100%, but I suspect incompatibilities between older (netpbm) version 2.4 of libtiff and the latest v3.4. I got best results with the old library, which is therefore included in this archive. To build, first make libtiff (cd libtiff ; make). Then look at the Makefile in this directory if the pointers to libpng and zlib are correct. That done, you can make. To test, I provided test-files in the directory ./alpha. The script Alpha.sh will convert all TIFFs (and overwrite the .PNGs at the same time :-). When you have a Web- browser that has adequate alpha support, you can test the result by loading Alpha.html in your browser and check what happens when you change the background color. I tested this utility also against the test-pictures at ftp.sgi.com. With the exception of the tiled-images, with good results. But there can and will still be many TIFF files that don't convert correctly. Please send me a copy if you come across such a beast. For the time being I concentrated on straight forward support of as many formats as possible. Future plans are to create PNG chunks for all those informational fields that TIFF also contains, like Name, Date, Position, Resolution, etc. A somewhat bolder plan is to convert the ColorResponseCurves field into a PNG gamma chunk. Let's see. At this moment there is a command-line parameter to add a gamma-chunk to your PNG file. (Do it please !) If you have any feedback for me: gwillem@ntuvax.ntu.ac.sg is the way to go. Or try http://mht3.gintic.ntu.ac.sg:8000/wwwillem.html. [GRR: willem@schaik.com and http://www.schaik.com/ as of 1999] +----------------------------------------------------------------------+ GRR NOTES: ========= 16 September 1999: I updated tiff2png 0.6 of May 1996 to version 0.7 in July 1999. My changes include the following: - slightly generalized Makefile, including static-library build - updated libpng interface - new libpng error handler (avoids jmp_buf size mismatches between library and application) - new usage() function - PNG pHYs support (aspect ratio, resolution) - optional new -faxpect option (only if compiled with FAXPECT defined) The last item is somewhat special-purpose, which is why it's ifdef'd. At least in my tests with efax 0.9, a Supra fax modem, and the various fax machines to which I have access at work (including all of their "fineness" options), *all* incoming faxes arrive with doubled horizontal resolution. With -faxpect, tiff2png will detect if the aspect ratio is close to 2:1 and, if so, halve the horizontal resolution to give a near-1:1 aspect ratio. The algorithm is trivial: if both neighboring pixels are white, the result pixel is white; if both black, black; and if there's one of each, the result is mid-level gray (127). (This necessarily means the output file is 2-bit palette-based, not grayscale, since only 8-bit PNG grayscale includes the mid-level gray, and compression can't recover the factor-of-four increase in pixel depth.) The results look pretty decent. Also note that even libtiff 3.4beta028 needs the OLDTIFF macro defined (see the Makefile comments), at least in all the cases I was able to test. I don't know what the difference is between my system and Willem's. Finally, I've removed the (very) old libtiff from the tiff2png 0.7 tar distribution; newer versions are available from the SGI web site mentioned above (ftp://ftp.sgi.com/graphics/tiff/). 26 January 2000: I updated tiff2png 0.7 to version 0.8 in January 2000 and tested it with libpng 3.5.4. Changes include: - improved Makefile (thanks to tenthumbs@cybernex.net) - improved memory/resource management (TIFFClose(), fclose(), etc.) - added -compression option to set zlib compression level - added multi-file support, including -destdir option The last item breaks command-line compatibility with earlier versions (which required exactly one TIFF input name and one PNG output name), but it brings tiff2png more in line with gif2png--that is, you can now do "tiff2png *.tif *.tiff" and get the expected conversion of many TIFF files all at once. (Alternatively, you can do "tiff2png -destdir /here /there/*.tif" to convert TIFFs /there to PNGs /here. The destination directory must exist and be writable, of course.) The program replaces the ".tif" or ".tiff" extension with ".png"; if neither extension is found, ".png" is simply appended to the TIFF filename. Oh, and I also took the liberty of changing the capitalization to "tiff2png"; not only does that match both the actual binary name and gif2png's convention, it also seemed more logical. (That is, "TIFF" is an acronym; either all letters should be capitalized or none of them should be. Ditto for PNG.) 13 February 2000: Version 0.81 consists only of fixes/improvements to the -destdir option; now if no target directory is given, the current directory is assumed. Thanks to TenThumbs once again. (Well, I also fixed a compiler warning and made a minor modification to the makefile, but you get the general idea.) 5 August 2000: Willem is back and will be taking over maintenance of tiff2png once again! (Also, tiff2png URL corrected above.) 4 November 2000: Willem released a version 0.82 in July, but it doesn't include the changes from either 0.8 or 0.81 (see above). In particular, it still expects both an input name and an output name on the command line, and it doesn't check whether the output file exists before overwriting it, which is quite dan- gerous for those of us who have grown accustomed to typing "tiff2png *.tiff" under Unix. (In such a case, the second TIFF file would be overwritten with the PNG conversion of the first TIFF file.) Willem's version can be found at http://www.schaik.com/png/tiff2png.html, for those who want to try it anyway. In the meantime, back in September I made a version 0.81b with the following two bug fixes: - fixed 16-bit-per-sample support (copied from Willem's version 0.82) - fixed Makefile (no attempt to install non-existent man page) Presumably Willem will reintegrate his other changes (e.g., -invert option and contributed multipage support) at some point in the near future. 12 November 2000: Oops, I overlooked one of Willem's 16-bit changes, and both of us missed an earlier, critical bug in the 16-bit code. Thanks to some 16-bit grayscale test images supplied by Ron Emaus of Pfizer, I was able to do a bit of real testing and track down the latter problem; version 0.81c fixes all known 16-bit bugs (although I still don't have any big-endian test files). It also includes Willem's -invert option, support for YCbCr images with JPEG compression and for Log(L) images with SGILog compression, and a new Win32 makefile (tested with MSVC 5.0, libtiff 3.5.5, libjpeg 6b, libpng 1.0.8, and zlib 1.1.3). Greg Roelofs newt@pobox.com