fukasawa e60969
                     ===========================
fukasawa e60969
                      PNG: The Definitive Guide
fukasawa e60969
                     ===========================
fukasawa e60969
fukasawa e60969
                             Source Code
fukasawa e60969
fukasawa e60969
Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free,
fukasawa e60969
cross-platform demo programs that show how to use the libpng reference
fukasawa e60969
library:  rpng, rpng2 and wpng.  rpng and rpng2 are viewers; the first is
fukasawa e60969
a very simple example that that shows how a standard file-viewer might use
fukasawa e60969
libpng, while the second is designed to process streaming data and shows
fukasawa e60969
how a web browser might be written.  wpng is a simple command-line program
fukasawa e60969
that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets
fukasawa e60969
of PBMPLUS/NetPBM) and converts them to PNG.
fukasawa e60969
fukasawa e60969
The source code for all three demo programs currently compiles under
fukasawa e60969
Unix, OpenVMS, and 32-bit Windows.  (Special thanks to Martin Zinser,
fukasawa e60969
zinser@decus.de, for making the necessary changes for OpenVMS and for
fukasawa e60969
providing an appropriate build script.)  Build instructions can be found
fukasawa e60969
below.
fukasawa e60969
fukasawa e60969
Files:
fukasawa e60969
fukasawa e60969
   README             this file
fukasawa e60969
   LICENSE            terms of distribution and reuse (BSD-like or GNU GPL)
fukasawa e60969
   COPYING            GNU General Public License (GPL)
fukasawa e60969
fukasawa e60969
   Makefile.unx       Unix makefile
fukasawa e60969
   Makefile.w32       Windows (MSVC) makefile
fukasawa e60969
   makevms.com        OpenVMS build script
fukasawa e60969
fukasawa e60969
   rpng-win.c         Windows front end for the basic viewer
fukasawa e60969
   rpng-x.c           X Window System (Unix, OpenVMS) front end
fukasawa e60969
   readpng.c          generic back end for the basic viewer
fukasawa e60969
   readpng.h          header file for the basic viewer
fukasawa e60969
fukasawa e60969
   rpng2-win.c        Windows front end for the progressive viewer
fukasawa e60969
   rpng2-x.c          X front end for the progressive viewer
fukasawa e60969
   readpng2.c         generic back end for the progressive viewer
fukasawa e60969
   readpng2.h         header file for the progressive viewer
fukasawa e60969
fukasawa e60969
   wpng.c             generic (text) front end for the converter
fukasawa e60969
   writepng.c         generic back end for the converter
fukasawa e60969
   writepng.h         header file for the converter
fukasawa e60969
fukasawa e60969
   toucan.png         transparent PNG for testing (by Stefan Schneider)
fukasawa e60969
fukasawa e60969
Note that, although the programs are designed to be functional, their
fukasawa e60969
primary purpose is to illustrate how to use libpng to add PNG support to
fukasawa e60969
other programs.  As such, their user interfaces are crude and definitely
fukasawa e60969
are not intended for everyday use.
fukasawa e60969
fukasawa e60969
Please see http://www.libpng.org/pub/png/pngbook.html for further infor-
fukasawa e60969
mation and links to the latest version of the source code, and Chapters
fukasawa e60969
13-15 of the book for detailed discussion of the three programs.
fukasawa e60969
fukasawa e60969
Greg Roelofs
fukasawa e60969
http://pobox.com/~newt/greg_contact.html
fukasawa e60969
16 March 2008
fukasawa e60969
fukasawa e60969
fukasawa e60969
BUILD INSTRUCTIONS
fukasawa e60969
fukasawa e60969
 - Prerequisites (in order of compilation):
fukasawa e60969
fukasawa e60969
      - zlib            http://zlib.net/
fukasawa e60969
      - libpng          http://www.libpng.org/pub/png/libpng.html
fukasawa e60969
      - pngbook         http://www.libpng.org/pub/png/book/sources.html
fukasawa e60969
fukasawa e60969
     The pngbook demo programs are explicitly designed to demonstrate proper
fukasawa e60969
     coding techniques for using the libpng reference library.  As a result,
fukasawa e60969
     you need to download and build both zlib (on which libpng depends) and
fukasawa e60969
     libpng.  A common build setup is to place the zlib, libpng and pngbook
fukasawa e60969
     subdirectory trees ("folders") in the same parent directory.  Then the
fukasawa e60969
     libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]),
fukasawa e60969
     and similarly for the pngbook build.
fukasawa e60969
fukasawa e60969
     Note that all three packages are designed to be built from a command
fukasawa e60969
     line by default; those who wish to use a graphical or other integrated
fukasawa e60969
     development environments are on their own.
fukasawa e60969
fukasawa e60969
fukasawa e60969
 - Unix:
fukasawa e60969
fukasawa e60969
     Unpack the latest pngbook sources (which should correspond to this
fukasawa e60969
     README file) into a directory and change into that directory.
fukasawa e60969
fukasawa e60969
     Copy Makefile.unx to Makefile and edit the PNG* and Z* variables
fukasawa e60969
     appropriately (possibly also the X* variables if necessary).
fukasawa e60969
fukasawa e60969
     make
fukasawa e60969
fukasawa e60969
     There is no "install" target, so copy the three executables somewhere
fukasawa e60969
     in your path or run them from the current directory.  All three will
fukasawa e60969
     print a basic usage screen when run without any command-line arguments;
fukasawa e60969
     see the book for more details.
fukasawa e60969
fukasawa e60969
fukasawa e60969
 - Windows:
fukasawa e60969
fukasawa e60969
     Unpack the latest pngbook sources (which should correspond to this
fukasawa e60969
     README file) into a folder, open a "DOS shell" or "command prompt"
fukasawa e60969
     or equivalent command-line window, and cd into the folder where you
fukasawa e60969
     unpacked the source code.
fukasawa e60969
fukasawa e60969
     For MSVC, set up the necessary environment variables by invoking
fukasawa e60969
fukasawa e60969
        %devstudio%\vc\bin\vcvars32.bat
fukasawa e60969
fukasawa e60969
     where where %devstudio% is the installation directory for MSVC /
fukasawa e60969
     DevStudio.  If you get "environment out of space" errors under 95/98,
fukasawa e60969
     create a desktop shortcut with "c:\windows\command.com /e:4096" as
fukasawa e60969
     the program command line and set the working directory to the pngbook
fukasawa e60969
     directory.  Then double-click to open the new DOS-prompt window with
fukasawa e60969
     a bigger environment and retry the commands above.
fukasawa e60969
fukasawa e60969
     Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables
fukasawa e60969
     appropriately (possibly also the "INC" and "LIB" variables if needed).
fukasawa e60969
     Note that the names of the dynamic and static libpng and zlib libraries
fukasawa e60969
     used in the makefile may change in later releases of the libraries.
fukasawa e60969
     Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work.
fukasawa e60969
     This makefile therefore builds statically linked executables, but if
fukasawa e60969
     the DLL problems ever get fixed, uncommenting the appropriate PNGLIB
fukasawa e60969
     and ZLIB lines will build dynamically linked executables instead.
fukasawa e60969
fukasawa e60969
     Do the build by typing
fukasawa e60969
fukasawa e60969
        nmake
fukasawa e60969
fukasawa e60969
     The result should be three executables:  rpng-win.exe, rpng2-win.exe,
fukasawa e60969
     and wpng.exe.  Copy them somewhere in your PATH or run them from the
fukasawa e60969
     current folder.  Like the Unix versions, the two windowed programs
fukasawa e60969
     (rpng and rpng2) now display a usage screen in a console window when
fukasawa e60969
     invoked without command-line arguments; this is new behavior as of
fukasawa e60969
     the June 2001 release.  Note that the programs use the Unix-style "-"
fukasawa e60969
     character to specify options, instead of the more common DOS/Windows
fukasawa e60969
     "/" character.  (For example:  "rpng2-win -bgpat 4 foo.png", not
fukasawa e60969
     "rpng2-win /bgpat 4 foo.png")
fukasawa e60969
fukasawa e60969
fukasawa e60969
 - OpenVMS:
fukasawa e60969
fukasawa e60969
     Unpack the pngbook sources into a subdirectory and change into that
fukasawa e60969
     subdirectory.
fukasawa e60969
fukasawa e60969
     Edit makevms.com appropriately, specifically the zpath and pngpath
fukasawa e60969
     variables.
fukasawa e60969
fukasawa e60969
     @makevms
fukasawa e60969
fukasawa e60969
     To run the programs, they probably first need to be set up as "foreign
fukasawa e60969
     symbols," with "disk" and "dir" set appropriately:
fukasawa e60969
fukasawa e60969
     $ rpng  == "$disk:[dir]rpng-x.exe"
fukasawa e60969
     $ rpng2 == "$disk:[dir]rpng2-x.exe"
fukasawa e60969
     $ wpng  == "$disk:[dir]wpng.exe"
fukasawa e60969
fukasawa e60969
     All three will print a basic usage screen when run without any command-
fukasawa e60969
     line arguments; see the book for more details.  Note that the options
fukasawa e60969
     style is Unix-like, i.e., preceded by "-" rather than "/".
fukasawa e60969
fukasawa e60969
fukasawa e60969
RUNNING THE PROGRAMS:  (VERY) BRIEF INTRO
fukasawa e60969
fukasawa e60969
     rpng is a simple PNG viewer that can display transparent PNGs with a
fukasawa e60969
     specified background color; for example,
fukasawa e60969
fukasawa e60969
        rpng -bgcolor \#ff0000 toucan.png
fukasawa e60969
fukasawa e60969
     would display the image with a red background.  rpng2 is a progressive
fukasawa e60969
     viewer that simulates a web browser in some respects; it can display
fukasawa e60969
     images against either a background color or a dynamically generated
fukasawa e60969
     background image.  For example:
fukasawa e60969
fukasawa e60969
        rpng2 -bgpat 16 toucan.png
fukasawa e60969
fukasawa e60969
     wpng is a purely command-line image converter from binary PBMPLUS/NetPBM
fukasawa e60969
     format (.pgm or .ppm) to PNG; for example,
fukasawa e60969
fukasawa e60969
        wpng -time < toucan-notrans.ppm > toucan-notrans.png
fukasawa e60969
fukasawa e60969
     would convert the specified PPM file (using redirection) to PNG, auto-
fukasawa e60969
     matically setting the PNG modification-time chunk.
fukasawa e60969
fukasawa e60969
     All options can be abbreviated to the shortest unique value; for example,
fukasawa e60969
     "-bgc" for -bgcolor (versus "-bgp" for -bgpat), or "-g" for -gamma.