1*a67afe4dSAndroid Build Coastguard Worker =========================== 2*a67afe4dSAndroid Build Coastguard Worker PNG: The Definitive Guide 3*a67afe4dSAndroid Build Coastguard Worker =========================== 4*a67afe4dSAndroid Build Coastguard Worker 5*a67afe4dSAndroid Build Coastguard Worker Source Code 6*a67afe4dSAndroid Build Coastguard Worker 7*a67afe4dSAndroid Build Coastguard WorkerChapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free, 8*a67afe4dSAndroid Build Coastguard Workercross-platform demo programs that show how to use the libpng reference 9*a67afe4dSAndroid Build Coastguard Workerlibrary: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is 10*a67afe4dSAndroid Build Coastguard Workera very simple example that that shows how a standard file-viewer might use 11*a67afe4dSAndroid Build Coastguard Workerlibpng, while the second is designed to process streaming data and shows 12*a67afe4dSAndroid Build Coastguard Workerhow a web browser might be written. wpng is a simple command-line program 13*a67afe4dSAndroid Build Coastguard Workerthat reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets 14*a67afe4dSAndroid Build Coastguard Workerof PBMPLUS/NetPBM) and converts them to PNG. 15*a67afe4dSAndroid Build Coastguard Worker 16*a67afe4dSAndroid Build Coastguard WorkerThe source code for all three demo programs currently compiles under 17*a67afe4dSAndroid Build Coastguard WorkerUnix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser, 18*a67afe4dSAndroid Build Coastguard Workerzinser at decus.de, for making the necessary changes for OpenVMS and for 19*a67afe4dSAndroid Build Coastguard Workerproviding an appropriate build script.) Build instructions can be found 20*a67afe4dSAndroid Build Coastguard Workerbelow. 21*a67afe4dSAndroid Build Coastguard Worker 22*a67afe4dSAndroid Build Coastguard WorkerFiles: 23*a67afe4dSAndroid Build Coastguard Worker 24*a67afe4dSAndroid Build Coastguard Worker README this file 25*a67afe4dSAndroid Build Coastguard Worker LICENSE terms of distribution and reuse (BSD-like or GNU GPL) 26*a67afe4dSAndroid Build Coastguard Worker COPYING GNU General Public License (GPL) 27*a67afe4dSAndroid Build Coastguard Worker 28*a67afe4dSAndroid Build Coastguard Worker Makefile.unx Unix makefile 29*a67afe4dSAndroid Build Coastguard Worker Makefile.w32 Windows (MSVC) makefile 30*a67afe4dSAndroid Build Coastguard Worker makevms.com OpenVMS build script 31*a67afe4dSAndroid Build Coastguard Worker 32*a67afe4dSAndroid Build Coastguard Worker rpng-win.c Windows front end for the basic viewer 33*a67afe4dSAndroid Build Coastguard Worker rpng-x.c X Window System (Unix, OpenVMS) front end 34*a67afe4dSAndroid Build Coastguard Worker readpng.c generic back end for the basic viewer 35*a67afe4dSAndroid Build Coastguard Worker readpng.h header file for the basic viewer 36*a67afe4dSAndroid Build Coastguard Worker 37*a67afe4dSAndroid Build Coastguard Worker rpng2-win.c Windows front end for the progressive viewer 38*a67afe4dSAndroid Build Coastguard Worker rpng2-x.c X front end for the progressive viewer 39*a67afe4dSAndroid Build Coastguard Worker readpng2.c generic back end for the progressive viewer 40*a67afe4dSAndroid Build Coastguard Worker readpng2.h header file for the progressive viewer 41*a67afe4dSAndroid Build Coastguard Worker 42*a67afe4dSAndroid Build Coastguard Worker wpng.c generic (text) front end for the converter 43*a67afe4dSAndroid Build Coastguard Worker writepng.c generic back end for the converter 44*a67afe4dSAndroid Build Coastguard Worker writepng.h header file for the converter 45*a67afe4dSAndroid Build Coastguard Worker 46*a67afe4dSAndroid Build Coastguard Worker toucan.png transparent PNG for testing (by Stefan Schneider) 47*a67afe4dSAndroid Build Coastguard Worker 48*a67afe4dSAndroid Build Coastguard WorkerNote that, although the programs are designed to be functional, their 49*a67afe4dSAndroid Build Coastguard Workerprimary purpose is to illustrate how to use libpng to add PNG support to 50*a67afe4dSAndroid Build Coastguard Workerother programs. As such, their user interfaces are crude and definitely 51*a67afe4dSAndroid Build Coastguard Workerare not intended for everyday use. 52*a67afe4dSAndroid Build Coastguard Worker 53*a67afe4dSAndroid Build Coastguard WorkerPlease see http://www.libpng.org/pub/png/pngbook.html for further infor- 54*a67afe4dSAndroid Build Coastguard Workermation and links to the latest version of the source code, and Chapters 55*a67afe4dSAndroid Build Coastguard Worker13-15 of the book for detailed discussion of the three programs. 56*a67afe4dSAndroid Build Coastguard Worker 57*a67afe4dSAndroid Build Coastguard WorkerGreg Roelofs 58*a67afe4dSAndroid Build Coastguard Workerhttps://pobox.com/~newt/greg_contact.html 59*a67afe4dSAndroid Build Coastguard Worker16 March 2008 60*a67afe4dSAndroid Build Coastguard Worker 61*a67afe4dSAndroid Build Coastguard Worker 62*a67afe4dSAndroid Build Coastguard WorkerBUILD INSTRUCTIONS 63*a67afe4dSAndroid Build Coastguard Worker 64*a67afe4dSAndroid Build Coastguard Worker - Prerequisites (in order of compilation): 65*a67afe4dSAndroid Build Coastguard Worker 66*a67afe4dSAndroid Build Coastguard Worker - zlib https://zlib.net/ 67*a67afe4dSAndroid Build Coastguard Worker - libpng http://www.libpng.org/pub/png/libpng.html 68*a67afe4dSAndroid Build Coastguard Worker - pngbook http://www.libpng.org/pub/png/book/sources.html 69*a67afe4dSAndroid Build Coastguard Worker 70*a67afe4dSAndroid Build Coastguard Worker The pngbook demo programs are explicitly designed to demonstrate proper 71*a67afe4dSAndroid Build Coastguard Worker coding techniques for using the libpng reference library. As a result, 72*a67afe4dSAndroid Build Coastguard Worker you need to download and build both zlib (on which libpng depends) and 73*a67afe4dSAndroid Build Coastguard Worker libpng. A common build setup is to place the zlib, libpng and pngbook 74*a67afe4dSAndroid Build Coastguard Worker subdirectory trees ("folders") in the same parent directory. Then the 75*a67afe4dSAndroid Build Coastguard Worker libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]), 76*a67afe4dSAndroid Build Coastguard Worker and similarly for the pngbook build. 77*a67afe4dSAndroid Build Coastguard Worker 78*a67afe4dSAndroid Build Coastguard Worker Note that all three packages are designed to be built from a command 79*a67afe4dSAndroid Build Coastguard Worker line by default; those who wish to use a graphical or other integrated 80*a67afe4dSAndroid Build Coastguard Worker development environments are on their own. 81*a67afe4dSAndroid Build Coastguard Worker 82*a67afe4dSAndroid Build Coastguard Worker 83*a67afe4dSAndroid Build Coastguard Worker - Unix: 84*a67afe4dSAndroid Build Coastguard Worker 85*a67afe4dSAndroid Build Coastguard Worker Unpack the latest pngbook sources (which should correspond to this 86*a67afe4dSAndroid Build Coastguard Worker README file) into a directory and change into that directory. 87*a67afe4dSAndroid Build Coastguard Worker 88*a67afe4dSAndroid Build Coastguard Worker Copy Makefile.unx to Makefile and edit the PNG* and Z* variables 89*a67afe4dSAndroid Build Coastguard Worker appropriately (possibly also the X* variables if necessary). 90*a67afe4dSAndroid Build Coastguard Worker 91*a67afe4dSAndroid Build Coastguard Worker make 92*a67afe4dSAndroid Build Coastguard Worker 93*a67afe4dSAndroid Build Coastguard Worker There is no "install" target, so copy the three executables somewhere 94*a67afe4dSAndroid Build Coastguard Worker in your path or run them from the current directory. All three will 95*a67afe4dSAndroid Build Coastguard Worker print a basic usage screen when run without any command-line arguments; 96*a67afe4dSAndroid Build Coastguard Worker see the book for more details. 97*a67afe4dSAndroid Build Coastguard Worker 98*a67afe4dSAndroid Build Coastguard Worker 99*a67afe4dSAndroid Build Coastguard Worker - Windows: 100*a67afe4dSAndroid Build Coastguard Worker 101*a67afe4dSAndroid Build Coastguard Worker Unpack the latest pngbook sources (which should correspond to this 102*a67afe4dSAndroid Build Coastguard Worker README file) into a folder, open a "DOS shell" or "command prompt" 103*a67afe4dSAndroid Build Coastguard Worker or equivalent command-line window, and cd into the folder where you 104*a67afe4dSAndroid Build Coastguard Worker unpacked the source code. 105*a67afe4dSAndroid Build Coastguard Worker 106*a67afe4dSAndroid Build Coastguard Worker For MSVC, set up the necessary environment variables by invoking 107*a67afe4dSAndroid Build Coastguard Worker 108*a67afe4dSAndroid Build Coastguard Worker %devstudio%\vc\bin\vcvars32.bat 109*a67afe4dSAndroid Build Coastguard Worker 110*a67afe4dSAndroid Build Coastguard Worker where where %devstudio% is the installation directory for MSVC / 111*a67afe4dSAndroid Build Coastguard Worker DevStudio. If you get "environment out of space" errors under 95/98, 112*a67afe4dSAndroid Build Coastguard Worker create a desktop shortcut with "c:\windows\command.com /e:4096" as 113*a67afe4dSAndroid Build Coastguard Worker the program command line and set the working directory to the pngbook 114*a67afe4dSAndroid Build Coastguard Worker directory. Then double-click to open the new DOS-prompt window with 115*a67afe4dSAndroid Build Coastguard Worker a bigger environment and retry the commands above. 116*a67afe4dSAndroid Build Coastguard Worker 117*a67afe4dSAndroid Build Coastguard Worker Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables 118*a67afe4dSAndroid Build Coastguard Worker appropriately (possibly also the "INC" and "LIB" variables if needed). 119*a67afe4dSAndroid Build Coastguard Worker Note that the names of the dynamic and static libpng and zlib libraries 120*a67afe4dSAndroid Build Coastguard Worker used in the makefile may change in later releases of the libraries. 121*a67afe4dSAndroid Build Coastguard Worker Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work. 122*a67afe4dSAndroid Build Coastguard Worker This makefile therefore builds statically linked executables, but if 123*a67afe4dSAndroid Build Coastguard Worker the DLL problems ever get fixed, uncommenting the appropriate PNGLIB 124*a67afe4dSAndroid Build Coastguard Worker and ZLIB lines will build dynamically linked executables instead. 125*a67afe4dSAndroid Build Coastguard Worker 126*a67afe4dSAndroid Build Coastguard Worker Do the build by typing 127*a67afe4dSAndroid Build Coastguard Worker 128*a67afe4dSAndroid Build Coastguard Worker nmake 129*a67afe4dSAndroid Build Coastguard Worker 130*a67afe4dSAndroid Build Coastguard Worker The result should be three executables: rpng-win.exe, rpng2-win.exe, 131*a67afe4dSAndroid Build Coastguard Worker and wpng.exe. Copy them somewhere in your PATH or run them from the 132*a67afe4dSAndroid Build Coastguard Worker current folder. Like the Unix versions, the two windowed programs 133*a67afe4dSAndroid Build Coastguard Worker (rpng and rpng2) now display a usage screen in a console window when 134*a67afe4dSAndroid Build Coastguard Worker invoked without command-line arguments; this is new behavior as of 135*a67afe4dSAndroid Build Coastguard Worker the June 2001 release. Note that the programs use the Unix-style "-" 136*a67afe4dSAndroid Build Coastguard Worker character to specify options, instead of the more common DOS/Windows 137*a67afe4dSAndroid Build Coastguard Worker "/" character. (For example: "rpng2-win -bgpat 4 foo.png", not 138*a67afe4dSAndroid Build Coastguard Worker "rpng2-win /bgpat 4 foo.png") 139*a67afe4dSAndroid Build Coastguard Worker 140*a67afe4dSAndroid Build Coastguard Worker 141*a67afe4dSAndroid Build Coastguard Worker - OpenVMS: 142*a67afe4dSAndroid Build Coastguard Worker 143*a67afe4dSAndroid Build Coastguard Worker Unpack the pngbook sources into a subdirectory and change into that 144*a67afe4dSAndroid Build Coastguard Worker subdirectory. 145*a67afe4dSAndroid Build Coastguard Worker 146*a67afe4dSAndroid Build Coastguard Worker Edit makevms.com appropriately, specifically the zpath and pngpath 147*a67afe4dSAndroid Build Coastguard Worker variables. 148*a67afe4dSAndroid Build Coastguard Worker 149*a67afe4dSAndroid Build Coastguard Worker @makevms 150*a67afe4dSAndroid Build Coastguard Worker 151*a67afe4dSAndroid Build Coastguard Worker To run the programs, they probably first need to be set up as "foreign 152*a67afe4dSAndroid Build Coastguard Worker symbols," with "disk" and "dir" set appropriately: 153*a67afe4dSAndroid Build Coastguard Worker 154*a67afe4dSAndroid Build Coastguard Worker $ rpng == "$disk:[dir]rpng-x.exe" 155*a67afe4dSAndroid Build Coastguard Worker $ rpng2 == "$disk:[dir]rpng2-x.exe" 156*a67afe4dSAndroid Build Coastguard Worker $ wpng == "$disk:[dir]wpng.exe" 157*a67afe4dSAndroid Build Coastguard Worker 158*a67afe4dSAndroid Build Coastguard Worker All three will print a basic usage screen when run without any command- 159*a67afe4dSAndroid Build Coastguard Worker line arguments; see the book for more details. Note that the options 160*a67afe4dSAndroid Build Coastguard Worker style is Unix-like, i.e., preceded by "-" rather than "/". 161*a67afe4dSAndroid Build Coastguard Worker 162*a67afe4dSAndroid Build Coastguard Worker 163*a67afe4dSAndroid Build Coastguard WorkerRUNNING THE PROGRAMS: (VERY) BRIEF INTRO 164*a67afe4dSAndroid Build Coastguard Worker 165*a67afe4dSAndroid Build Coastguard Worker rpng is a simple PNG viewer that can display transparent PNGs with a 166*a67afe4dSAndroid Build Coastguard Worker specified background color; for example, 167*a67afe4dSAndroid Build Coastguard Worker 168*a67afe4dSAndroid Build Coastguard Worker rpng -bgcolor \#ff0000 toucan.png 169*a67afe4dSAndroid Build Coastguard Worker 170*a67afe4dSAndroid Build Coastguard Worker would display the image with a red background. rpng2 is a progressive 171*a67afe4dSAndroid Build Coastguard Worker viewer that simulates a web browser in some respects; it can display 172*a67afe4dSAndroid Build Coastguard Worker images against either a background color or a dynamically generated 173*a67afe4dSAndroid Build Coastguard Worker background image. For example: 174*a67afe4dSAndroid Build Coastguard Worker 175*a67afe4dSAndroid Build Coastguard Worker rpng2 -bgpat 16 toucan.png 176*a67afe4dSAndroid Build Coastguard Worker 177*a67afe4dSAndroid Build Coastguard Worker wpng is a purely command-line image converter from binary PBMPLUS/NetPBM 178*a67afe4dSAndroid Build Coastguard Worker format (.pgm or .ppm) to PNG; for example, 179*a67afe4dSAndroid Build Coastguard Worker 180*a67afe4dSAndroid Build Coastguard Worker wpng -time < toucan-notrans.ppm > toucan-notrans.png 181*a67afe4dSAndroid Build Coastguard Worker 182*a67afe4dSAndroid Build Coastguard Worker would convert the specified PPM file (using redirection) to PNG, auto- 183*a67afe4dSAndroid Build Coastguard Worker matically setting the PNG modification-time chunk. 184*a67afe4dSAndroid Build Coastguard Worker 185*a67afe4dSAndroid Build Coastguard Worker All options can be abbreviated to the shortest unique value; for example, 186*a67afe4dSAndroid Build Coastguard Worker "-bgc" for -bgcolor (versus "-bgp" for -bgpat), or "-g" for -gamma. 187