Compare commits
148 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7836e21894 | ||
|
|
270a623b90 | ||
|
|
afbb32433c | ||
|
|
e058ce14ea | ||
|
|
1e73a532f5 | ||
|
|
073070791a | ||
|
|
4049c1ac2a | ||
|
|
4fa097d58b | ||
|
|
bceda5f9d6 | ||
|
|
53ab12bb91 | ||
|
|
1f6c3eb4e0 | ||
|
|
c802480614 | ||
|
|
0b86d89622 | ||
|
|
ebfd716fc4 | ||
|
|
19a2ee7a55 | ||
|
|
5314d4afa8 | ||
|
|
196d964a5c | ||
|
|
d061149ae8 | ||
|
|
62fef7d0ca | ||
|
|
a22f977a29 | ||
|
|
e8c732dffb | ||
|
|
212ff60146 | ||
|
|
fb4edffd05 | ||
|
|
ab85e8f491 | ||
|
|
ac9a0378fd | ||
|
|
cf77d0d594 | ||
|
|
6b0bf2742b | ||
|
|
49838313fc | ||
|
|
881e55a189 | ||
|
|
0303ee804d | ||
|
|
3f6e7d5e64 | ||
|
|
ac278cc06a | ||
|
|
dc2e72f1a2 | ||
|
|
38f0418ee7 | ||
|
|
4f66bef47f | ||
|
|
80d4e25c9d | ||
|
|
be5217de8c | ||
|
|
f9b9775253 | ||
|
|
b007817932 | ||
|
|
fd4078cb1b | ||
|
|
ad57dbb530 | ||
|
|
39acfab5bc | ||
|
|
43a349ae4a | ||
|
|
02f800dbd6 | ||
|
|
f9d6ce301d | ||
|
|
725c747abe | ||
|
|
3f7bcb635e | ||
|
|
cb15afd5ce | ||
|
|
0e0798b796 | ||
|
|
a41eecbdd4 | ||
|
|
01f17eee9e | ||
|
|
430d11ea06 | ||
|
|
bfb1ddd2c9 | ||
|
|
0a7bbf8697 | ||
|
|
59e559b2a2 | ||
|
|
9bc3a1fdd4 | ||
|
|
14ae6c1d94 | ||
|
|
1719fac606 | ||
|
|
c79c23c0d5 | ||
|
|
918dc976d5 | ||
|
|
928d84e713 | ||
|
|
764b52ad45 | ||
|
|
551892bb60 | ||
|
|
1a2e75ccf1 | ||
|
|
fb088b9cca | ||
|
|
a3a5d7c172 | ||
|
|
295e9df783 | ||
|
|
ef860dab8f | ||
|
|
e696c7205a | ||
|
|
1ff473f3fd | ||
|
|
b88935a8b2 | ||
|
|
64b481e714 | ||
|
|
0f5e1e5a39 | ||
|
|
6fbb54d253 | ||
|
|
fba872492b | ||
|
|
82282113b9 | ||
|
|
a095d92224 | ||
|
|
ff518067c3 | ||
|
|
db576fa76b | ||
|
|
b6c4193528 | ||
|
|
df8fc6680e | ||
|
|
f47b4b1bf7 | ||
|
|
4fc3118b59 | ||
|
|
3bdb7fed6e | ||
|
|
0e928a62e9 | ||
|
|
88f07c8451 | ||
|
|
787081f75b | ||
|
|
80b4f15ae3 | ||
|
|
e68f5a361b | ||
|
|
328353990f | ||
|
|
82ae383331 | ||
|
|
e1eff58f87 | ||
|
|
f64a06f5ec | ||
|
|
87c6bc984a | ||
|
|
13cfbac075 | ||
|
|
e164447858 | ||
|
|
1909560348 | ||
|
|
d4e8109a48 | ||
|
|
be9de0f428 | ||
|
|
cdf140beec | ||
|
|
231e687411 | ||
|
|
76e5fd642e | ||
|
|
f05f8033b8 | ||
|
|
408b421265 | ||
|
|
2ad31ae31f | ||
|
|
f6b4f45c7e | ||
|
|
d56aca7104 | ||
|
|
f5ed0e130c | ||
|
|
fbbb5ecb52 | ||
|
|
5e5c1e1f56 | ||
|
|
32fc5ceb91 | ||
|
|
4766a244b2 | ||
|
|
a4d54bdb4a | ||
|
|
ff9c947a1a | ||
|
|
15dac0b14e | ||
|
|
316f97a063 | ||
|
|
3d5a520610 | ||
|
|
98b0ff4998 | ||
|
|
1394480f4b | ||
|
|
1f2d559f70 | ||
|
|
db66d44801 | ||
|
|
d436672048 | ||
|
|
104622bebb | ||
|
|
fc4a143ec6 | ||
|
|
ec61c23d56 | ||
|
|
1ef65b6742 | ||
|
|
752945701e | ||
|
|
98c9d73605 | ||
|
|
6942d53c25 | ||
|
|
326320e5a9 | ||
|
|
228bd390ac | ||
|
|
4accabb590 | ||
|
|
38e6e77419 | ||
|
|
81fdf8aca1 | ||
|
|
68ea243ca3 | ||
|
|
520a764cd7 | ||
|
|
a77ef625a6 | ||
|
|
61c32d9e66 | ||
|
|
166c5a397e | ||
|
|
074af5e9ca | ||
|
|
5379b24536 | ||
|
|
6d8f3b080a | ||
|
|
860ab2b1c0 | ||
|
|
ad5dd1f0fb | ||
|
|
33b25bf1a8 | ||
|
|
18c415f5b5 | ||
|
|
310faa8ec9 | ||
|
|
ab1e583c44 |
166
ANNOUNCE
@@ -1,85 +1,95 @@
|
|||||||
|
|
||||||
Libpng 1.0.4c - October 1, 1999
|
Libpng 1.0.51 - December 3, 2009
|
||||||
|
|
||||||
This is not intended to be a public release. It will be replaced
|
This is a public release of libpng, intended for use in production codes.
|
||||||
within a few weeks by a public version or by another test version.
|
|
||||||
|
|
||||||
Changes since the last public release (1.0.3):
|
Files available for download:
|
||||||
|
|
||||||
version 1.0.3a [August 12, 1999]
|
Source files with LF line endings (for Unix/Linux) and with a
|
||||||
Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
|
"configure" script
|
||||||
if an attempt is made to read an interlaced image when it's not supported.
|
|
||||||
Added check if png_ptr->trans is defined before free'ing it in pngread.c
|
|
||||||
Modified the Y2K statement to include versions back to version 0.71
|
|
||||||
Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c
|
|
||||||
Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments)
|
|
||||||
Replaced leading blanks with tab characters in makefile.hux
|
|
||||||
Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents.
|
|
||||||
Changed (float)red and (float)green to (double)red, (double)green
|
|
||||||
in png_set_rgb_to_gray() to avoid "promotion" problems in AIX.
|
|
||||||
Fixed a bug in pngconf.h that omitted <stdio.h> when PNG_DEBUG==0 (K Bracey).
|
|
||||||
Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt).
|
|
||||||
Updated documentation to refer to the PNG-1.2 specification.
|
|
||||||
Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c
|
|
||||||
in makefile.knr, INSTALL, and README (L. Peter Deutsch)
|
|
||||||
Fixed bugs in calculation of the length of rowbytes when adding alpha
|
|
||||||
channels to 16-bit images, in pngrtran.c (Chris Nokleberg)
|
|
||||||
Added function png_set_user_transform_info() to store user_transform_ptr,
|
|
||||||
user_depth, and user_channels into the png_struct, and a function
|
|
||||||
png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg)
|
|
||||||
Added function png_set_empty_plte_permitted() to make libpng useable
|
|
||||||
in MNG applications.
|
|
||||||
Corrected the typedef for png_free_ptr in png.h (Jesse Jones).
|
|
||||||
Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be
|
|
||||||
consistent with PNG-1.2, and allow variance of 500 before complaining.
|
|
||||||
Added assembler code contributed by Intel in file pngvcrd.c and modified
|
|
||||||
makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, Gilles Vollant)
|
|
||||||
Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy.
|
|
||||||
Added some aliases for png_set_expand() in pngrtran.c, namely
|
|
||||||
png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS()
|
|
||||||
(Greg Roelofs, in "PNG: The Definitive Guide").
|
|
||||||
Added makefile.beo for BEOS on X86, contributed by Sander Stok.
|
|
||||||
version 1.0.3b [August 26, 1999]
|
|
||||||
Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h
|
|
||||||
Changed leading blanks to tabs in all makefiles.
|
|
||||||
Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code.
|
|
||||||
Made alternate versions of png_set_expand() in pngrtran.c, namely
|
|
||||||
png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha
|
|
||||||
(Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases.
|
|
||||||
Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h
|
|
||||||
Revised calculation of num_blocks in pngmem.c to avoid a potentially
|
|
||||||
negative shift distance, whose results are undefined in the C language.
|
|
||||||
Added a check in pngset.c to prevent writing multiple tIME chunks.
|
|
||||||
Added a check in pngwrite.c to detect invalid small window_bits sizes.
|
|
||||||
version 1.0.3d [September 4, 1999]
|
|
||||||
Fixed type casting of igamma in pngrutil.c
|
|
||||||
Added new png_expand functions to scripts/pngdef.pas and pngos2.def
|
|
||||||
Added a demo read_user_transform_fn that examines the row filters in pngtest.c
|
|
||||||
version 1.0.4 [September 24, 1999]
|
|
||||||
Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined
|
|
||||||
Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h
|
|
||||||
Made several minor corrections to pngtest.c
|
|
||||||
Changed "hptr += 16L" to "hptr = hptr + 16L" in pngmem.c for Turbo 3.0
|
|
||||||
Renamed the makefiles with longer but more user friendly extensions.
|
|
||||||
Copied the PNG copyright and license to a separate LICENSE file.
|
|
||||||
Revised documentation, png.h, and example.c to remove reference to
|
|
||||||
"viewing_gamma" which no longer appears in the PNG specification.
|
|
||||||
Revised pngvcrd.c to use MMX code for interlacing only on the final pass.
|
|
||||||
Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a
|
|
||||||
Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX
|
|
||||||
assembler code) and makefile.vcwin32 (doesn't).
|
|
||||||
Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)
|
|
||||||
version 1.0.4a September 25, 1999
|
|
||||||
Increase max_pixel_depth in pngrutil.c if a user transform needs it.
|
|
||||||
Changed several division operations to right-shifts in pngvcrd.c
|
|
||||||
version 1.0.4b September 30, 1999
|
|
||||||
Added parentheses in line 3732 of pngvcrd.c
|
|
||||||
Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1
|
|
||||||
version 1.0.4c [October 1, 1999]
|
|
||||||
Added a "png_check_version" function in png.c and pngtest.c that will generate
|
|
||||||
a helpful compiler error if an old png.h is found in the search path.
|
|
||||||
|
|
||||||
Send comments/corrections/commendations to
|
libpng-1.0.51.tar.xz (LZMA-compressed, recommended)
|
||||||
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
|
libpng-1.0.51.tar.gz
|
||||||
|
libpng-1.0.51.tar.bz2
|
||||||
|
|
||||||
|
Source files with LF line endings (for Unix/Linux) without the
|
||||||
|
"configure" script
|
||||||
|
|
||||||
|
libpng-1.0.51-no-config.tar.xz (LZMA-compressed, recommended)
|
||||||
|
libpng-1.0.51-no-config.tar.gz
|
||||||
|
libpng-1.0.51-no-config.tar.bz2
|
||||||
|
|
||||||
|
Source files with CRLF line endings (for Windows), without the
|
||||||
|
"configure" script
|
||||||
|
|
||||||
|
lpng1051.zip
|
||||||
|
lpng1051.7z
|
||||||
|
lpng1051.tar.bz2
|
||||||
|
|
||||||
|
Project files
|
||||||
|
|
||||||
|
libpng-1.0.51-project-netware.zip
|
||||||
|
libpng-1.0.51-project-wince.zip
|
||||||
|
|
||||||
|
Other information:
|
||||||
|
|
||||||
|
libpng-1.0.51-README.txt
|
||||||
|
libpng-1.0.51-KNOWNBUGS.txt
|
||||||
|
libpng-1.0.51-LICENSE.txt
|
||||||
|
libpng-1.0.51-Y2K-compliance.txt
|
||||||
|
|
||||||
|
Changes since the last public release (1.0.50):
|
||||||
|
|
||||||
|
version 1.0.51 [December 3, 2009]
|
||||||
|
|
||||||
|
Moved redundant IHDR checking into new png_check_IHDR() in png.c
|
||||||
|
and report all errors found in the IHDR data.
|
||||||
|
Eliminated useless call to png_check_cHRM() from pngset.c
|
||||||
|
Expanded TAB characters in pngrtran.c
|
||||||
|
Added "xcode" project similar one already in libpng-1.4.0beta (Alam Arias).
|
||||||
|
Eliminated a shadowed declaration of "pp" in png_handle_sPLT().
|
||||||
|
Revised pngconf.h to make it easier to enable iTXt support. From libpng
|
||||||
|
version 1.2.9 through 1.2.40, defining PNG_iTXt_SUPPORTED did not work
|
||||||
|
as expected.
|
||||||
|
Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h
|
||||||
|
Changed many "#if defined(x)" to "#ifdef x" and fixed some indentation.
|
||||||
|
Added png_calloc() as a non-exported function.
|
||||||
|
Relocated png_do_chop() ahead of building gamma tables in pngrtran.c
|
||||||
|
This avoids building 16-bit gamma tables unnecessarily.
|
||||||
|
Removed a harmless extra png_set_invert_alpha() from pngwrite.c
|
||||||
|
Bugfixes and improvements to CMakeLists.txt (Philip Lowman)
|
||||||
|
Moved CMakeLists.txt from scripts into the main libpng directory.
|
||||||
|
Patched ltmain.sh for wince support.
|
||||||
|
Added PNG_CONVERT_tIME_SUPPORTED macro.
|
||||||
|
Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED
|
||||||
|
Updated scripts/pngw32.def and projects/wince/png32ce.def
|
||||||
|
Copied projects/wince/png32ce.def to the scripts directory.
|
||||||
|
Added scripts/makefile.cegcc
|
||||||
|
Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and
|
||||||
|
PNG_ALLOCATED macros to detect deprecated direct access to the
|
||||||
|
png_struct or info_struct members and other deprecated usage in
|
||||||
|
applications (John Bowler).
|
||||||
|
Removed three direct references to read_info_ptr members in pngtest.c
|
||||||
|
that were detected by the new PNG_DEPSTRUCT macro.
|
||||||
|
Marked deprecated function prototypes with PNG_DEPRECATED.
|
||||||
|
Marked memory allocation function prototypes with PNG_ALLOCATED.
|
||||||
|
Changed png_check_sig() to !png_sig_cmp() in contrib programs.
|
||||||
|
Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c
|
||||||
|
Marked nonexported functions with PNG_PRIVATE macro.
|
||||||
|
Revised scripts/*.def to reflect functions actually exported by libpng.
|
||||||
|
Updated the copyright year in scripts/pngw32.rc from 2004 to 2009.
|
||||||
|
Moved descriptions of makefiles and other scripts out of INSTALL into
|
||||||
|
scripts/README.txt
|
||||||
|
Rebuilt the configure scripts with autoconf-2.65
|
||||||
|
Disabled the new pedantic warnings about deprecated function use and
|
||||||
|
deprecated structure access unless the user defines PNG_PEDANTIC_WARNINGS.
|
||||||
|
Added "#define PNG_NO_PEDANTIC_WARNINGS" in the libpng source files.
|
||||||
|
Updated the list of files and made some cosmetic changes in README.
|
||||||
|
|
||||||
|
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||||
|
|
||||||
|
(subscription required; visit
|
||||||
|
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||||
|
to subscribe) or to glennrp at users.sourceforge.net
|
||||||
|
|
||||||
Glenn R-P
|
Glenn R-P
|
||||||
|
|||||||
178
INSTALL
@@ -1,17 +1,53 @@
|
|||||||
|
|
||||||
Installing libpng version 1.0.4c - October 1, 1999
|
Installing libpng version 1.0.51 - December 3, 2009
|
||||||
|
|
||||||
Before installing libpng, you must first install zlib. zlib
|
On Unix/Linux and similar systems, you can simply type
|
||||||
can usually be found wherever you got libpng. zlib can be
|
|
||||||
placed in another directory, at the same level as libpng.
|
./configure [--prefix=/path]
|
||||||
Note that your system might already have a preinstalled
|
make check
|
||||||
zlib, but you will still need to have access to the
|
make install
|
||||||
zlib.h and zconf.h include files that correspond to the
|
|
||||||
version of zlib that's installed.
|
and ignore the rest of this document.
|
||||||
|
|
||||||
|
If configure does not work on your system and you have a reasonably
|
||||||
|
up-to-date set of tools, running ./autogen.sh before running ./configure
|
||||||
|
may fix the problem. You can also run the individual commands in
|
||||||
|
autogen.sh with the --force option, if supported by your version of
|
||||||
|
the tools. If you run 'libtoolize --force', though, this will replace
|
||||||
|
the distributed, patched, version of ltmain.sh with an unpatched version
|
||||||
|
and your shared library builds may fail to produce libraries with the
|
||||||
|
correct version numbers.
|
||||||
|
|
||||||
|
Instead, you can use one of the custom-built makefiles in the
|
||||||
|
"scripts" directory
|
||||||
|
|
||||||
|
cp scripts/makefile.system makefile
|
||||||
|
make test
|
||||||
|
make install
|
||||||
|
|
||||||
|
The files that are presently available in the scripts directory
|
||||||
|
are listed and described in scripts/README.txt.
|
||||||
|
|
||||||
|
Or you can use one of the "projects" in the "projects" directory.
|
||||||
|
|
||||||
|
Before installing libpng, you must first install zlib, if it
|
||||||
|
is not already on your system. zlib can usually be found
|
||||||
|
wherever you got libpng. zlib can be placed in another directory,
|
||||||
|
at the same level as libpng.
|
||||||
|
|
||||||
|
If you want to use "cmake" (see www.cmake.org), type
|
||||||
|
|
||||||
|
cmake . -DCMAKE_INSTALL_PREFIX=/path
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
|
||||||
|
If your system already has a preinstalled zlib you will still need
|
||||||
|
to have access to the zlib.h and zconf.h include files that
|
||||||
|
correspond to the version of zlib that's installed.
|
||||||
|
|
||||||
You can rename the directories that you downloaded (they
|
You can rename the directories that you downloaded (they
|
||||||
might be called "libpng-1.0.4c" or "lpng103" and "zlib-1.1.3"
|
might be called "libpng-1.0.51" or "libpng10" and "zlib-1.2.3"
|
||||||
or "zlib113") so that you have directories called "zlib" and "libpng".
|
or "zlib123") so that you have directories called "zlib" and "libpng".
|
||||||
|
|
||||||
Your directory structure should look like this:
|
Your directory structure should look like this:
|
||||||
|
|
||||||
@@ -21,8 +57,28 @@ Your directory structure should look like this:
|
|||||||
README
|
README
|
||||||
*.h
|
*.h
|
||||||
*.c
|
*.c
|
||||||
|
CMakeLists.txt => "cmake" script
|
||||||
|
configuration files:
|
||||||
|
configure.ac, configure, Makefile.am, Makefile.in,
|
||||||
|
%12-% autogen.sh, config.guess, ltmain.sh, missing,
|
||||||
|
%12-% aclocal.m4, config.h.in, config.sub,
|
||||||
|
%14+% autogen.sh, config.guess, ltmain.sh, missing, libpng-pc.in,
|
||||||
|
%14+% libpng-config.in, aclocal.m4, config.h.in, config.sub,
|
||||||
|
depcomp, install-sh, mkinstalldirs, test-pngtest.sh
|
||||||
|
contrib
|
||||||
|
gregbook
|
||||||
|
pngminim
|
||||||
|
pngminus
|
||||||
|
pngsuite
|
||||||
|
visupng
|
||||||
|
projects
|
||||||
|
cbuilder5 (Borland)
|
||||||
|
visualc6 (msvc)
|
||||||
|
visualc71
|
||||||
|
xcode
|
||||||
scripts
|
scripts
|
||||||
makefile.*
|
makefile.*
|
||||||
|
*.def (module definition files)
|
||||||
pngtest.png
|
pngtest.png
|
||||||
etc.
|
etc.
|
||||||
zlib
|
zlib
|
||||||
@@ -32,52 +88,22 @@ Your directory structure should look like this:
|
|||||||
contrib
|
contrib
|
||||||
etc.
|
etc.
|
||||||
|
|
||||||
First enter the zlib directory and follow the instructions
|
If the line endings in the files look funny, you may wish to get the other
|
||||||
in zlib/README. Then come back here and choose the
|
distribution of libpng. It is available in both tar.gz (UNIX style line
|
||||||
appropriate makefile.sys in the scripts directory.
|
endings) and zip (DOS style line endings) formats.
|
||||||
The files that are presently available in the scripts directory
|
|
||||||
include
|
|
||||||
|
|
||||||
descrip.mms => VMS makefile for MMS or MMK
|
If you are building libpng with MSVC, you can enter the
|
||||||
makefile.std => Generic UNIX makefile
|
libpng projects\visualc6 or visualc71 directory and follow the instructions
|
||||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
in README.txt.
|
||||||
ansi2knr (Requires ansi2knr.c from
|
|
||||||
ftp://ftp.cs.wisc.edu/ghost)
|
Otherwise enter the zlib directory and follow the instructions in zlib/README,
|
||||||
makefile.dec => DEC Alpha UNIX makefile
|
then come back here and run "configure" or choose the appropriate
|
||||||
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
makefile.sys in the scripts directory.
|
||||||
makefile.sgi => Silicon Graphics IRIX makefile
|
|
||||||
makefile.sunos => Sun makefile
|
|
||||||
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.4c)
|
|
||||||
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.4c)
|
|
||||||
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
|
|
||||||
makefile.mips => MIPS makefile
|
|
||||||
makefile.acorn => Acorn makefile
|
|
||||||
makefile.amiga => Amiga makefile
|
|
||||||
smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
|
|
||||||
(Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
|
|
||||||
makefile.atari => Atari makefile
|
|
||||||
makefile.beos => BEOS makefile for X86
|
|
||||||
makefile.borland => Borland makefile
|
|
||||||
build.bat => MS-DOS batch file for Borland compiler
|
|
||||||
makefile.dj2 => DJGPP 2 makefile
|
|
||||||
makefile.msc => Microsoft C makefile
|
|
||||||
makefile.vcawin32 => makefile for Microsoft Visual C++ 5.0 and later (uses
|
|
||||||
assembler code)
|
|
||||||
makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and later (does not
|
|
||||||
use assembler code)
|
|
||||||
makefile.turboc3 => Turbo C 3.0 makefile
|
|
||||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
|
||||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
|
||||||
makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
|
|
||||||
makevms.com => VMS build script
|
|
||||||
pngdll.mak => To make a png32bd.dll with Borland C++ 4.5
|
|
||||||
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
|
|
||||||
SCOPTIONS.ppc => Used with smakefile.ppc
|
|
||||||
|
|
||||||
Copy the file (or files) that you need from the
|
Copy the file (or files) that you need from the
|
||||||
scripts directory into this directory, for example
|
scripts directory into this directory, for example
|
||||||
|
|
||||||
MSDOS example: copy scripts\makefile.msd makefile
|
MSDOS example: copy scripts\makefile.msc makefile
|
||||||
UNIX example: cp scripts/makefile.std makefile
|
UNIX example: cp scripts/makefile.std makefile
|
||||||
|
|
||||||
Read the makefile to see if you need to change any source or
|
Read the makefile to see if you need to change any source or
|
||||||
@@ -86,14 +112,54 @@ target directories to match your preferences.
|
|||||||
Then read pngconf.h to see if you want to make any configuration
|
Then read pngconf.h to see if you want to make any configuration
|
||||||
changes.
|
changes.
|
||||||
|
|
||||||
Then just run "make test" which will create the libpng library in
|
Then just run "make" which will create the libpng library in
|
||||||
this directory and run a quick test that reads the "pngtest.png"
|
this directory and "make test" which will run a quick test that reads
|
||||||
file and writes a "pngout.png" file that should be identical to it.
|
the "pngtest.png" file and writes a "pngout.png" file that should be
|
||||||
|
identical to it. Look for "9782 zero samples" in the output of the
|
||||||
|
test. For more confidence, you can run another test by typing
|
||||||
|
"pngtest pngnow.png" and looking for "289 zero samples" in the output.
|
||||||
|
Also, you can run "pngtest -m contrib/pngsuite/*.png" and compare
|
||||||
|
your output with the result shown in contrib/pngsuite/README.
|
||||||
|
|
||||||
Most of the makefiles will allow you to run "make install" to
|
Most of the makefiles will allow you to run "make install" to
|
||||||
put the library in its final resting place (if you want to
|
put the library in its final resting place (if you want to
|
||||||
do that, run "make install" in the zlib directory first if necessary).
|
do that, run "make install" in the zlib directory first if necessary).
|
||||||
|
Some also allow you to run "make test-installed" after you have
|
||||||
|
run "make install".
|
||||||
|
|
||||||
|
If you encounter a compiler error message complaining about the
|
||||||
|
lines
|
||||||
|
|
||||||
|
__png.h__ already includes setjmp.h;
|
||||||
|
__dont__ include it again.;
|
||||||
|
|
||||||
|
this means you have compiled another module that includes setjmp.h,
|
||||||
|
which is hazardous because the two modules might not include exactly
|
||||||
|
the same setjmp.h. If you are sure that you know what you are doing
|
||||||
|
and that they are exactly the same, then you can comment out or
|
||||||
|
delete the two lines. Better yet, use the cexcept interface
|
||||||
|
instead, as demonstrated in contrib/visupng of the libpng distribution.
|
||||||
|
|
||||||
Further information can be found in the README and libpng.txt
|
Further information can be found in the README and libpng.txt
|
||||||
files, in the individual makefiles, and in png.h, and the manual
|
files, in the individual makefiles, in png.h, and the manual pages
|
||||||
pages libpng.3 and png.5.
|
libpng.3 and png.5.
|
||||||
|
|
||||||
|
|
||||||
|
Using the ./configure script -- 16 December 2002.
|
||||||
|
=================================================
|
||||||
|
|
||||||
|
|
||||||
|
The ./configure script should work compatibly with what scripts/makefile.*
|
||||||
|
did, however there are some options you need to add to configure explicitly,
|
||||||
|
which previously was done semi-automatically (if you didn't edit
|
||||||
|
scripts/makefile.* yourself, that is)
|
||||||
|
|
||||||
|
|
||||||
|
CFLAGS="-Wall -O -funroll-loops \
|
||||||
|
-malign-loops=2 -malign-functions=2" ./configure --prefix=/usr/include \
|
||||||
|
--with-pkgconfigdir=/usr/lib/pkgconfig --includedir=/usr/include
|
||||||
|
|
||||||
|
You can alternatively specify --includedir=/usr/include, /usr/local/include,
|
||||||
|
/usr/include/png12, or whatever.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
48
KNOWNBUG
@@ -1,40 +1,22 @@
|
|||||||
|
|
||||||
Known bugs and suggested enhancements in libpng-1.0.4
|
Known bugs in libpng version 1.0.51
|
||||||
|
|
||||||
|
1. February 23, 2006: The custom makefiles don't build libpng with -lz.
|
||||||
|
|
||||||
1. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
|
STATUS: This is a subject of debate. The change will probably be made
|
||||||
|
as a part of a major overhaul of the makefiles in libpng version 1.4.0.
|
||||||
|
|
||||||
Loops need to be optimized everywhere
|
2. February 24, 2006: The Makefile generated by the "configure" script
|
||||||
|
fails to install symbolic links
|
||||||
|
libpng12.so => libpng12.so.0.1.2.9betaN
|
||||||
|
that are generated by the custom makefiles.
|
||||||
|
|
||||||
Make them count down instead of up -- Kevin Bracey
|
3. September 4, 2007: There is a report that pngtest crashes on MacOS 10.
|
||||||
|
|
||||||
Optimizing compilers don't need this, and making
|
STATUS: workarounds are
|
||||||
the change would be error prone -- Tom Lane, Glenn R-P
|
1) Compile without optimization (crashes are observed with
|
||||||
|
-arch i386 and -O2 or -O3, using gcc-4.0.1).
|
||||||
Question whether i-- or --i is better.
|
2) Compile pngtest.c with PNG_DEBUG defined (the bug goes away if
|
||||||
|
you try to look at it).
|
||||||
STATUS: Under investigation, postponed until after
|
3) Ignore the crash. The library itself seems to be OK.
|
||||||
libpng-1.0.5. About 160 loops will be turned around
|
|
||||||
in libpng-1.0.Nn, for testing.
|
|
||||||
|
|
||||||
2. July 4, 1998 -- ENHANCEMENT -- Glenn R-P
|
|
||||||
|
|
||||||
libpng-1.0.5 and earlier transform colors to gamma=1.0 space for
|
|
||||||
merging with background, and then back to the image's gamma. The
|
|
||||||
bit_depth of the intermediate (gamma=1.0) representation is probably
|
|
||||||
not sufficient. In the typical gamma=1/2.2 situation, the linear
|
|
||||||
pixels need about 4 more bits than the gamma-encoded ones, to avoid
|
|
||||||
loss of precision. A similar situation exists with the rgb_to_gray
|
|
||||||
operation.
|
|
||||||
|
|
||||||
STATUS: under development.
|
|
||||||
|
|
||||||
3. September 1999 -- ENHANCEMENT --
|
|
||||||
|
|
||||||
It should be possible to use libpng without floating-point aritmetic.
|
|
||||||
|
|
||||||
STATUS: Under investigation, implementation postponed until after
|
|
||||||
libpng-1.0.5. The application interface will change because replacements
|
|
||||||
for the png_set_gAMA(), png_set_cHRM(), and corresponding png_get_()
|
|
||||||
functions will be needed.
|
|
||||||
|
|
||||||
|
|||||||
102
LICENSE
@@ -1,28 +1,71 @@
|
|||||||
COPYRIGHT NOTICE:
|
|
||||||
|
|
||||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
This copy of the libpng notices is provided for your convenience. In case of
|
||||||
(libpng versions 0.5, May 1995, through 0.89c, May 1996)
|
any discrepancy between this copy and the notices in the file png.h that is
|
||||||
|
included in the libpng distribution, the latter shall prevail.
|
||||||
|
|
||||||
|
COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
|
||||||
|
|
||||||
|
If you modify libpng you may insert additional notices immediately following
|
||||||
|
this sentence.
|
||||||
|
|
||||||
|
This code is released under the libpng license.
|
||||||
|
|
||||||
|
libpng versions 1.2.6, August 15, 2004, through 1.0.51, December 3, 2009, are
|
||||||
|
Copyright (c) 2004, 2006-2009 Glenn Randers-Pehrson, and are
|
||||||
|
distributed according to the same disclaimer and license as libpng-1.2.5
|
||||||
|
with the following individual added to the list of Contributing Authors
|
||||||
|
|
||||||
|
Cosmin Truta
|
||||||
|
|
||||||
|
libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
|
||||||
|
Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
|
||||||
|
distributed according to the same disclaimer and license as libpng-1.0.6
|
||||||
|
with the following individuals added to the list of Contributing Authors
|
||||||
|
|
||||||
|
Simon-Pierre Cadieux
|
||||||
|
Eric S. Raymond
|
||||||
|
Gilles Vollant
|
||||||
|
|
||||||
|
and with the following additions to the disclaimer:
|
||||||
|
|
||||||
|
There is no warranty against interference with your enjoyment of the
|
||||||
|
library or against infringement. There is no warranty that our
|
||||||
|
efforts or the library will fulfill any of your particular purposes
|
||||||
|
or needs. This library is provided with all faults, and the entire
|
||||||
|
risk of satisfactory quality, performance, accuracy, and effort is with
|
||||||
|
the user.
|
||||||
|
|
||||||
|
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
|
||||||
|
Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
|
||||||
|
distributed according to the same disclaimer and license as libpng-0.96,
|
||||||
|
with the following individuals added to the list of Contributing Authors:
|
||||||
|
|
||||||
|
Tom Lane
|
||||||
|
Glenn Randers-Pehrson
|
||||||
|
Willem van Schaik
|
||||||
|
|
||||||
|
libpng versions 0.89, June 1996, through 0.96, May 1997, are
|
||||||
Copyright (c) 1996, 1997 Andreas Dilger
|
Copyright (c) 1996, 1997 Andreas Dilger
|
||||||
(libpng versions 0.90, December 1996, through 0.96, May 1997)
|
Distributed according to the same disclaimer and license as libpng-0.88,
|
||||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
with the following individuals added to the list of Contributing Authors:
|
||||||
(libpng versions 0.97, January 1998, through 1.0.4c, October 1, 1999)
|
|
||||||
|
|
||||||
For the purposes of this copyright and license, "Contributing Authors"
|
|
||||||
is defined as the following set of individuals:
|
|
||||||
|
|
||||||
John Bowler
|
John Bowler
|
||||||
Kevin Bracey
|
Kevin Bracey
|
||||||
Sam Bushell
|
Sam Bushell
|
||||||
Andreas Dilger
|
|
||||||
Magnus Holmgren
|
Magnus Holmgren
|
||||||
Tom Lane
|
|
||||||
Dave Martindale
|
|
||||||
Glenn Randers-Pehrson
|
|
||||||
Greg Roelofs
|
Greg Roelofs
|
||||||
|
Tom Tanner
|
||||||
|
|
||||||
|
libpng versions 0.5, May 1995, through 0.88, January 1996, are
|
||||||
|
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||||
|
|
||||||
|
For the purposes of this copyright and license, "Contributing Authors"
|
||||||
|
is defined as the following set of individuals:
|
||||||
|
|
||||||
|
Andreas Dilger
|
||||||
|
Dave Martindale
|
||||||
Guy Eric Schalnat
|
Guy Eric Schalnat
|
||||||
Paul Schmidt
|
Paul Schmidt
|
||||||
Tom Tanner
|
|
||||||
Willem van Schaik
|
|
||||||
Tim Wegner
|
Tim Wegner
|
||||||
|
|
||||||
The PNG Reference Library is supplied "AS IS". The Contributing Authors
|
The PNG Reference Library is supplied "AS IS". The Contributing Authors
|
||||||
@@ -37,16 +80,13 @@ Permission is hereby granted to use, copy, modify, and distribute this
|
|||||||
source code, or portions hereof, for any purpose, without fee, subject
|
source code, or portions hereof, for any purpose, without fee, subject
|
||||||
to the following restrictions:
|
to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this source code must not be
|
1. The origin of this source code must not be misrepresented.
|
||||||
misrepresented.
|
|
||||||
|
|
||||||
2. Altered versions must be plainly marked as such
|
2. Altered versions must be plainly marked as such and must not
|
||||||
and must not be misrepresented as being the
|
be misrepresented as being the original source.
|
||||||
original source.
|
|
||||||
|
|
||||||
3. This Copyright notice may not be removed or
|
3. This Copyright notice may not be removed or altered from any
|
||||||
altered from any source or altered source
|
source or altered source distribution.
|
||||||
distribution.
|
|
||||||
|
|
||||||
The Contributing Authors and Group 42, Inc. specifically permit, without
|
The Contributing Authors and Group 42, Inc. specifically permit, without
|
||||||
fee, and encourage the use of this source code as a component to
|
fee, and encourage the use of this source code as a component to
|
||||||
@@ -54,6 +94,18 @@ supporting the PNG file format in commercial products. If you use this
|
|||||||
source code in a product, acknowledgment is not required but would be
|
source code in a product, acknowledgment is not required but would be
|
||||||
appreciated.
|
appreciated.
|
||||||
|
|
||||||
|
|
||||||
|
A "png_get_copyright" function is available, for convenient use in "about"
|
||||||
|
boxes and the like:
|
||||||
|
|
||||||
|
printf("%s",png_get_copyright(NULL));
|
||||||
|
|
||||||
|
Also, the PNG logo (in PNG format, of course) is supplied in the
|
||||||
|
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
|
||||||
|
|
||||||
|
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
|
||||||
|
certification mark of the Open Source Initiative.
|
||||||
|
|
||||||
Glenn Randers-Pehrson
|
Glenn Randers-Pehrson
|
||||||
randeg@alum.rpi.edu
|
glennrp at users.sourceforge.net
|
||||||
October 1, 1999
|
December 3, 2009
|
||||||
|
|||||||
152
Makefile.am
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
# Makefile.am:
|
||||||
|
# Source file for Makefile.in (and hence Makefile)
|
||||||
|
#
|
||||||
|
# Makefile.am need only be changed on a major version number
|
||||||
|
# change (e.g. libpng12 --> libpng14). In that case seach
|
||||||
|
# this file for every instance of the old base name (libpng12)
|
||||||
|
# and change to the new one (libpng14), then change the
|
||||||
|
# -version-number settings below so that the new values have
|
||||||
|
# the correct major part (first field).
|
||||||
|
|
||||||
|
PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
|
||||||
|
|
||||||
|
# libpng does not follow GNU file name conventions
|
||||||
|
AUTOMAKE_OPTIONS = foreign
|
||||||
|
|
||||||
|
# test programs - run on make check, make distcheck
|
||||||
|
check_PROGRAMS= pngtest
|
||||||
|
pngtest_SOURCES = pngtest.c
|
||||||
|
pngtest_LDADD = libpng10.la
|
||||||
|
TESTS = test-pngtest.sh
|
||||||
|
TESTS_ENVIRONMENT= srcdir=$(srcdir)
|
||||||
|
|
||||||
|
# man pages
|
||||||
|
dist_man_MANS= libpng.3 libpngpf.3 png.5
|
||||||
|
|
||||||
|
# generate the -config scripts if required
|
||||||
|
binconfigs= libpng10-config
|
||||||
|
EXTRA_SCRIPTS= libpng-config libpng10-config
|
||||||
|
bin_SCRIPTS= @binconfigs@
|
||||||
|
|
||||||
|
# rules to build libpng, only build the old library on request
|
||||||
|
lib_LTLIBRARIES=libpng10.la @compatlib@
|
||||||
|
EXTRA_LTLIBRARIES= libpng.la
|
||||||
|
libpng10_la_SOURCES = png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
|
||||||
|
pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
|
||||||
|
pngwtran.c pngmem.c pngerror.c pngpread.c \
|
||||||
|
png.h pngconf.h
|
||||||
|
libpng_la_SOURCES = $(libpng10_la_SOURCES)
|
||||||
|
|
||||||
|
libpng_la_CPPFLAGS = @LIBPNG_DEFINES@
|
||||||
|
libpng10_la_CPPFLAGS = @LIBPNG_DEFINES@
|
||||||
|
|
||||||
|
# MAJOR UPGRADE: the version-number settings below must be changed.
|
||||||
|
libpng10_la_LDFLAGS = -no-undefined -export-dynamic \
|
||||||
|
-version-number 0:@PNGLIB_RELEASE@:0
|
||||||
|
# -rpath is needed as automake doesn't know the directory
|
||||||
|
libpng_la_LDFLAGS = -rpath '$(libdir)' -no-undefined -export-dynamic \
|
||||||
|
-version-number 2:@PNGLIB_RELEASE@:0
|
||||||
|
|
||||||
|
if HAVE_LD_VERSION_SCRIPT
|
||||||
|
# Versioned symbols and restricted exports
|
||||||
|
libpng10_la_LDFLAGS += -Wl,--version-script=libpng.vers
|
||||||
|
libpng10_la_DEPENDENCIES = libpng.vers
|
||||||
|
else
|
||||||
|
# Only restricted exports when possible
|
||||||
|
libpng10_la_LDFLAGS += -export-symbols libpng.sym
|
||||||
|
libpng10_la_DEPENDENCIES = libpng.sym
|
||||||
|
endif
|
||||||
|
libpng_la_DEPENDENCIES = $(libpng10_la_DEPENDENCIES)
|
||||||
|
|
||||||
|
# Avoid depending upon Character Ranges.
|
||||||
|
AN = '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
|
|
||||||
|
#distribute headers in /usr/include/libpng/*
|
||||||
|
pkgincludedir= $(includedir)/$(PNGLIB_BASENAME)
|
||||||
|
pkginclude_HEADERS= png.h pngconf.h
|
||||||
|
|
||||||
|
# pkg-config stuff, note that libpng.pc is always required in order
|
||||||
|
# to get the correct library
|
||||||
|
pkgconfigdir = @pkgconfigdir@
|
||||||
|
pkgconfig_DATA = libpng10.pc
|
||||||
|
|
||||||
|
#extra source distribution files.
|
||||||
|
EXTRA_DIST= \
|
||||||
|
ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO \
|
||||||
|
pngtest.png pngbar.png pngnow.png pngbar.jpg autogen.sh \
|
||||||
|
${srcdir}/projects/cbuilder5/* \
|
||||||
|
${srcdir}/projects/beos/* \
|
||||||
|
${srcdir}/projects/visualc6/* \
|
||||||
|
${srcdir}/projects/visualc71/* \
|
||||||
|
${srcdir}/projects/wince.txt \
|
||||||
|
${srcdir}/projects/netware.txt \
|
||||||
|
${srcdir}/scripts/* \
|
||||||
|
${srcdir}/contrib/gregbook/* \
|
||||||
|
${srcdir}/contrib/pngminus/* \
|
||||||
|
${srcdir}/contrib/pngsuite/* \
|
||||||
|
${srcdir}/contrib/visupng/* \
|
||||||
|
$(TESTS) \
|
||||||
|
example.c libpng-1.0.51.txt pngvcrd.c
|
||||||
|
|
||||||
|
CLEANFILES= pngout.png libpng10.pc libpng10-config libpng.vers \
|
||||||
|
libpng.sym
|
||||||
|
|
||||||
|
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess config.h.in \
|
||||||
|
config.sub configure depcomp install-sh ltmain.sh missing
|
||||||
|
|
||||||
|
$(PNGLIB_BASENAME).pc: libpng.pc
|
||||||
|
cp libpng.pc $@
|
||||||
|
|
||||||
|
$(PNGLIB_BASENAME)-config: libpng-config
|
||||||
|
cp libpng-config $@
|
||||||
|
|
||||||
|
libpng.sym: png.h pngconf.h
|
||||||
|
rm -f $@ $@.new
|
||||||
|
$(CPP) @LIBPNG_DEFINES@ $(CPPFLAGS) -DPNG_BUILDSYMS $(srcdir)/png.h | \
|
||||||
|
$(SED) -n -e \
|
||||||
|
's|^.*PNG_FUNCTION_EXPORT[ ]*\([$(AN)]*\).*$$|$(SYMBOL_PREFIX)\1|p' \
|
||||||
|
-e 's|^.*PNG_DATA_EXPORT[ ]*\([$(AN)]*\).*$$|$(SYMBOL_PREFIX)\1|p' \
|
||||||
|
>$@.new
|
||||||
|
mv $@.new $@
|
||||||
|
|
||||||
|
libpng.vers: libpng.sym
|
||||||
|
rm -f $@ $@.new
|
||||||
|
echo PNG@PNGLIB_MAJOR@@PNGLIB_MINOR@_0 '{global:' > $@.new
|
||||||
|
$(SED) s/$$/\;/ libpng.sym >> $@.new
|
||||||
|
echo 'local: *; };' >> $@.new
|
||||||
|
mv $@.new $@
|
||||||
|
|
||||||
|
test: check
|
||||||
|
|
||||||
|
# install the .../include headers as links to the new ones
|
||||||
|
install-data-hook:
|
||||||
|
cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h
|
||||||
|
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/png.h png.h
|
||||||
|
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pngconf.h pngconf.h
|
||||||
|
cd $(DESTDIR)$(pkgconfigdir); rm -f libpng.pc
|
||||||
|
cd $(DESTDIR)$(pkgconfigdir); $(LN_S) $(PNGLIB_BASENAME).pc libpng.pc
|
||||||
|
|
||||||
|
# do evil things to libpng to cause libpng10 to be used
|
||||||
|
install-exec-hook:
|
||||||
|
cd $(DESTDIR)$(bindir); rm -f libpng-config
|
||||||
|
cd $(DESTDIR)$(bindir); $(LN_S) $(PNGLIB_BASENAME)-config libpng-config
|
||||||
|
@set -x;\
|
||||||
|
cd $(DESTDIR)$(libdir);\
|
||||||
|
for ext in a la so sl dylib; do\
|
||||||
|
rm -f libpng.$$ext;\
|
||||||
|
if test -f $(PNGLIB_BASENAME).$$ext; then\
|
||||||
|
$(LN_S) $(PNGLIB_BASENAME).$$ext libpng.$$ext;\
|
||||||
|
fi;\
|
||||||
|
done
|
||||||
|
|
||||||
|
uninstall-hook:
|
||||||
|
cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h
|
||||||
|
rm -f $(DESTDIR)$(pkgconfigdir)/libpng.pc
|
||||||
|
rm -f $(DESTDIR)$(bindir)/libpng-config
|
||||||
|
@if test -n "@compatlib@"; then\
|
||||||
|
set -x;\
|
||||||
|
cd $(DESTDIR)$(libdir);\
|
||||||
|
for ext in a la so sl dylib; do\
|
||||||
|
rm -f libpng.$$ext;\
|
||||||
|
done;\
|
||||||
|
fi
|
||||||
1408
Makefile.in
Normal file
174
README
@@ -1,14 +1,23 @@
|
|||||||
README for libpng 1.0.4c - October 1, 1999 (shared library 2.1)
|
README for libpng version 1.0.51 - December 3, 2009 (shared library 10.0)
|
||||||
See the note about version numbers near the top of png.h
|
See the note about version numbers near the top of png.h
|
||||||
|
|
||||||
See INSTALL for instructions on how to install libpng.
|
See INSTALL for instructions on how to install libpng.
|
||||||
|
|
||||||
This is the first official release of libpng. Don't let the fact that
|
Libpng comes in several distribution formats. Get libpng-*.tar.gz,
|
||||||
it's the first release fool you. The libpng library has been in
|
libpng-*.tar.xz, or libpng-*.tar.bz2 if you want UNIX-style line
|
||||||
extensive use and testing for about two and a half years. However, it's
|
endings in the text files, or lpng*.7z or lpng*.zip if you want DOS-style
|
||||||
finally gotten to the stage where there haven't been significant
|
line endings. You can get UNIX-style line endings from the *.zip file
|
||||||
|
by using "unzip -a" but there seems to be no simple way to recover
|
||||||
|
UNIX-style line endings from the *.7z file. The *.tar.xz file is
|
||||||
|
recommended for *NIX users instead.
|
||||||
|
|
||||||
|
Version 0.89 was the first official release of libpng. Don't let the
|
||||||
|
fact that it's the first release fool you. The libpng library has been in
|
||||||
|
extensive use and testing since mid-1995. By late 1997 it had
|
||||||
|
finally gotten to the stage where there hadn't been significant
|
||||||
changes to the API in some time, and people have a bad feeling about
|
changes to the API in some time, and people have a bad feeling about
|
||||||
libraries with versions < 1.0.
|
libraries with versions < 1.0. Version 1.0.0 was released in
|
||||||
|
March 1998.
|
||||||
|
|
||||||
****
|
****
|
||||||
Note that some of the changes to the png_info structure render this
|
Note that some of the changes to the png_info structure render this
|
||||||
@@ -28,8 +37,8 @@ directly, to avoid such problems in the future.
|
|||||||
It is important to note that the APIs do not make current programs
|
It is important to note that the APIs do not make current programs
|
||||||
that access the info struct directly incompatible with the new
|
that access the info struct directly incompatible with the new
|
||||||
library. However, it is strongly suggested that new programs use
|
library. However, it is strongly suggested that new programs use
|
||||||
the new APIs (as shown in example.c), and older programs be converted
|
the new APIs (as shown in example.c and pngtest.c), and older programs
|
||||||
to the new format, to facilitate upgrades in the future.
|
be converted to the new format, to facilitate upgrades in the future.
|
||||||
****
|
****
|
||||||
|
|
||||||
Additions since 0.90 include the ability to compile libpng as a
|
Additions since 0.90 include the ability to compile libpng as a
|
||||||
@@ -49,8 +58,9 @@ to set different actions based on whether the CRC error occurred in a
|
|||||||
critical or an ancillary chunk.
|
critical or an ancillary chunk.
|
||||||
|
|
||||||
The changes made to the library, and bugs fixed are based on discussions
|
The changes made to the library, and bugs fixed are based on discussions
|
||||||
on the PNG implementation mailing list <png-implement@ccrc.wustl.edu>
|
on the png-mng-implement mailing list and not on material submitted
|
||||||
and not on material submitted to Guy.
|
privately to Guy, Andreas, or Glenn. They will forward any good
|
||||||
|
suggestions to the list.
|
||||||
|
|
||||||
For a detailed description on using libpng, read libpng.txt. For
|
For a detailed description on using libpng, read libpng.txt. For
|
||||||
examples of libpng in a program, see example.c and pngtest.c. For usage
|
examples of libpng in a program, see example.c and pngtest.c. For usage
|
||||||
@@ -71,16 +81,15 @@ compression library that is useful for more things than just PNG files.
|
|||||||
You can use zlib as a drop-in replacement for fread() and fwrite() if
|
You can use zlib as a drop-in replacement for fread() and fwrite() if
|
||||||
you are so inclined.
|
you are so inclined.
|
||||||
|
|
||||||
zlib should be available at the same place that libpng is.
|
zlib should be available at the same place that libpng is, or at
|
||||||
If not, it should be at ftp.uu.net in /graphics/png
|
ftp://ftp.simplesystems.org/pub/png/src/
|
||||||
Eventually, it will be at ftp.uu.net in /pub/archiving/zip/zlib
|
|
||||||
|
|
||||||
You may also want a copy of the PNG specification. It is available
|
You may also want a copy of the PNG specification. It is available
|
||||||
as an RFC and a W3C Recommendation. Failing
|
as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
|
||||||
these resources you can try ftp.uu.net in the /graphics/png directory.
|
these at http://www.libpng.org/pub/png/pngdocs.html
|
||||||
|
|
||||||
This code is currently being archived at ftp.uu.net in the
|
This code is currently being archived at libpng.sf.net in the
|
||||||
/graphics/png directory, and on CompuServe, Lib 20 (PNG SUPPORT)
|
[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT)
|
||||||
at GO GRAPHSUP. If you can't find it in any of those places,
|
at GO GRAPHSUP. If you can't find it in any of those places,
|
||||||
e-mail me, and I'll help you find it.
|
e-mail me, and I'll help you find it.
|
||||||
|
|
||||||
@@ -96,19 +105,23 @@ Finally, if you get any warning messages when compiling libpng
|
|||||||
fix. Please mention "libpng" somewhere in the subject line. Thanks.
|
fix. Please mention "libpng" somewhere in the subject line. Thanks.
|
||||||
|
|
||||||
This release was created and will be supported by myself (of course
|
This release was created and will be supported by myself (of course
|
||||||
based in a large way on Guy's and Andreas' earlier work), and the PNG group.
|
based in a large way on Guy's and Andreas' earlier work), and the PNG
|
||||||
|
development group.
|
||||||
|
|
||||||
randeg@alum.rpi.edu
|
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||||
png-implement@ccrc.wustl.edu
|
(subscription required; visit
|
||||||
|
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||||
|
to subscribe) or to glennrp at users.sourceforge.net
|
||||||
|
|
||||||
You can't reach Guy, the original libpng author, at the addresses
|
You can't reach Guy, the original libpng author, at the addresses
|
||||||
given in previous versions of this document. He and Andreas will read mail
|
given in previous versions of this document. He and Andreas will
|
||||||
addressed to the png-implement list, however.
|
read mail addressed to the png-mng-implement list, however.
|
||||||
|
|
||||||
Please do not send general questions about PNG. Send them to
|
Please do not send general questions about PNG. Send them to
|
||||||
the address in the specification (png-group@w3.org). At the same
|
the (png-mng-misc at lists.sourceforge.net, subscription required, visit
|
||||||
time, please do not send libpng questions to that address, send them to me
|
https://lists.sourceforge.net/lists/listinfo/png-mng-misc to
|
||||||
or to png-implement@ccrc.wustl.edu. I'll
|
subscribe). On the other hand, please do not send libpng questions to
|
||||||
|
that address, send them to me or to the png-mng-implement list. I'll
|
||||||
get them in the end anyway. If you have a question about something
|
get them in the end anyway. If you have a question about something
|
||||||
in the PNG specification that is related to using libpng, send it
|
in the PNG specification that is related to using libpng, send it
|
||||||
to me. Send me any questions that start with "I was using libpng,
|
to me. Send me any questions that start with "I was using libpng,
|
||||||
@@ -116,20 +129,23 @@ and ...". If in doubt, send questions to me. I'll bounce them
|
|||||||
to others, if necessary.
|
to others, if necessary.
|
||||||
|
|
||||||
Please do not send suggestions on how to change PNG. We have
|
Please do not send suggestions on how to change PNG. We have
|
||||||
been discussing PNG for three years now, and it is official and
|
been discussing PNG for twelve years now, and it is official and
|
||||||
finished. If you have suggestions for libpng, however, I'll
|
finished. If you have suggestions for libpng, however, I'll
|
||||||
gladly listen. Even if your suggestion is not used for version
|
gladly listen. Even if your suggestion is not used immediately,
|
||||||
1.0, it may be used later.
|
it may be used later.
|
||||||
|
|
||||||
Files in this distribution:
|
Files in this distribution:
|
||||||
|
|
||||||
|
ANNOUNCE => Announcement of this version, with recent changes
|
||||||
CHANGES => Description of changes between libpng versions
|
CHANGES => Description of changes between libpng versions
|
||||||
|
KNOWNBUG => List of known bugs and deficiencies
|
||||||
|
LICENSE => License to use and redistribute libpng
|
||||||
README => This file
|
README => This file
|
||||||
TODO => Things not implemented in the current library
|
TODO => Things not implemented in the current library
|
||||||
build.bat => MS-DOS batch file for Borland compiler
|
Y2KINFO => Statement of Y2K compliance
|
||||||
descrip.mms => VMS project file
|
|
||||||
example.c => Example code for using libpng functions
|
example.c => Example code for using libpng functions
|
||||||
libpng.3 => manual page for libpng
|
libpng-*-*-diff.txt => Diff from previous release
|
||||||
|
libpng.3 => manual page for libpng (includes libpng.txt)
|
||||||
libpng.txt => Description of libpng and its functions
|
libpng.txt => Description of libpng and its functions
|
||||||
libpngpf.3 => manual page for libpng's private functions
|
libpngpf.3 => manual page for libpng's private functions
|
||||||
png.5 => manual page for the PNG format
|
png.5 => manual page for the PNG format
|
||||||
@@ -139,6 +155,8 @@ Files in this distribution:
|
|||||||
pngerror.c => Error/warning message I/O functions
|
pngerror.c => Error/warning message I/O functions
|
||||||
pngget.c => Functions for retrieving info from struct
|
pngget.c => Functions for retrieving info from struct
|
||||||
pngmem.c => Memory handling functions
|
pngmem.c => Memory handling functions
|
||||||
|
pngbar.png => PNG logo, 88x31
|
||||||
|
pngnow.png => PNG logo, 98x31
|
||||||
pngpread.c => Progressive reading functions
|
pngpread.c => Progressive reading functions
|
||||||
pngread.c => Read data/helper high-level functions
|
pngread.c => Read data/helper high-level functions
|
||||||
pngrio.c => Lowest-level data read I/O functions
|
pngrio.c => Lowest-level data read I/O functions
|
||||||
@@ -152,20 +170,72 @@ Files in this distribution:
|
|||||||
pngwrite.c => High-level write functions
|
pngwrite.c => High-level write functions
|
||||||
pngwtran.c => Write data transformations
|
pngwtran.c => Write data transformations
|
||||||
pngwutil.c => Write utility functions
|
pngwutil.c => Write utility functions
|
||||||
|
contrib => Contributions
|
||||||
|
gregbook => source code for PNG reading and writing, from
|
||||||
|
Greg Roelofs' "PNG: The Definitive Guide",
|
||||||
|
O'Reilly, 1999
|
||||||
|
msvctest => Builds and runs pngtest using a MSVC workspace
|
||||||
|
pngminim => Simple pnm2pngm and png2pnmm programs
|
||||||
|
pngminus => Simple pnm2png and png2pnm programs
|
||||||
|
pngsuite => Test images
|
||||||
|
visupng => Contains a MSVC workspace for VisualPng
|
||||||
|
projects => Contains project files and workspaces for
|
||||||
|
building a DLL
|
||||||
|
beos => Contains a Beos workspace for building libpng
|
||||||
|
c5builder => Contains a Borland workspace for building
|
||||||
|
libpng and zlib
|
||||||
|
netware.txt => Contains instructions for downloading a set
|
||||||
|
of project files for building libpng and
|
||||||
|
zlib on Netware.
|
||||||
|
visualc6 => Contains a Microsoft Visual C++ (MSVC)
|
||||||
|
workspace for building libpng and zlib
|
||||||
|
wince.txt => Contains instructions for downloading a
|
||||||
|
Microsoft Visual C++ (Windows CD Toolkit)
|
||||||
|
workspace for building libpng and zlib on
|
||||||
|
WindowsCE
|
||||||
|
xcode => Contains xcode project files
|
||||||
scripts => Directory containing scripts for building libpng:
|
scripts => Directory containing scripts for building libpng:
|
||||||
descrip.mms => VMS makefile for MMS or MMK
|
descrip.mms => VMS makefile for MMS or MMK
|
||||||
makefile.std => Generic UNIX makefile
|
makefile.std => Generic UNIX makefile (cc, creates static
|
||||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
libpng.a)
|
||||||
ansi2knr (Requires ansi2knr.c from
|
makefile.elf => Linux/ELF gcc makefile symbol versioning,
|
||||||
|
creates libpng10.so.0.1.0.51)
|
||||||
|
makefile.linux => Linux/ELF makefile (gcc, creates
|
||||||
|
libpng10.so.0.1.0.51)
|
||||||
|
makefile.gcmmx => Linux/ELF makefile (gcc, creates
|
||||||
|
libpng10.so.0.1.0.51, previously
|
||||||
|
used assembler code tuned for Intel MMX
|
||||||
|
platform)
|
||||||
|
makefile.gcc => Generic makefile (gcc, creates static
|
||||||
|
libpng.a)
|
||||||
|
makefile.knr => Archaic UNIX Makefile that converts files
|
||||||
|
with ansi2knr (Requires ansi2knr.c from
|
||||||
ftp://ftp.cs.wisc.edu/ghost)
|
ftp://ftp.cs.wisc.edu/ghost)
|
||||||
|
makefile.aix => AIX makefile
|
||||||
|
makefile.cygwin => Cygwin/gcc makefile
|
||||||
|
makefile.darwin => Darwin makefile
|
||||||
makefile.dec => DEC Alpha UNIX makefile
|
makefile.dec => DEC Alpha UNIX makefile
|
||||||
|
makefile.freebsd => FreeBSD makefile
|
||||||
|
makefile.hpgcc => HPUX makefile using gcc
|
||||||
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
||||||
makefile.sgi => Silicon Graphics IRIX makefile
|
makefile.hp64 => HPUX (10.20 and 11.00) makefile, 64 bit
|
||||||
|
makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2
|
||||||
|
(static)
|
||||||
|
makefile.intel => Intel C/C++ version 4.0 and later
|
||||||
|
libpng.icc => Project file, IBM VisualAge/C++ 4.0 or later
|
||||||
|
makefile.netbsd => NetBSD/cc makefile, makes libpng.so.
|
||||||
|
makefile.ne10bsd => NetBSD/cc makefile, makes libpng10.so
|
||||||
|
makefile.openbsd => OpenBSD makefile
|
||||||
|
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
|
||||||
|
makefile.sggcc => Silicon Graphics
|
||||||
|
(gcc, creates libpng10.so.0.1.0.51)
|
||||||
makefile.sunos => Sun makefile
|
makefile.sunos => Sun makefile
|
||||||
makefile.solaris => Solaris 2.X makefile
|
makefile.solaris => Solaris 2.X makefile
|
||||||
(gcc, creates libpng.so.2.1.0.4c)
|
(gcc, creates libpng10.so.0.1.0.51)
|
||||||
makefile.linux => Linux/ELF makefile
|
makefile.so9 => Solaris 9 makefile
|
||||||
(gcc, creates libpng.so.2.1.0.4c)
|
(gcc, creates libpng10.so.0.1.0.51)
|
||||||
|
makefile.32sunu => Sun Ultra 32-bit makefile
|
||||||
|
makefile.64sunu => Sun Ultra 64-bit makefile
|
||||||
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
|
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
|
||||||
makefile.mips => MIPS makefile
|
makefile.mips => MIPS makefile
|
||||||
makefile.acorn => Acorn makefile
|
makefile.acorn => Acorn makefile
|
||||||
@@ -175,33 +245,31 @@ Files in this distribution:
|
|||||||
scripts/SCOPTIONS.ppc)
|
scripts/SCOPTIONS.ppc)
|
||||||
makefile.atari => Atari makefile
|
makefile.atari => Atari makefile
|
||||||
makefile.beos => BEOS makefile for X86
|
makefile.beos => BEOS makefile for X86
|
||||||
makefile.borland => Borland makefile
|
makefile.bor => Borland makefile (uses bcc)
|
||||||
build.bat => MS-DOS batch file for Borland compiler
|
makefile.bc32 => 32-bit Borland C++ (all modules compiled in C mode)
|
||||||
|
makefile.tc3 => Turbo C 3.0 makefile
|
||||||
makefile.dj2 => DJGPP 2 makefile
|
makefile.dj2 => DJGPP 2 makefile
|
||||||
makefile.msc => Microsoft C makefile
|
makefile.msc => Microsoft C makefile
|
||||||
makefile.vcawin32 => makefile for Microsoft Visual C++ 5.0 and
|
makefile.vcawin32=> makefile for Microsoft Visual C++ 5.0 and
|
||||||
later (uses assembler code)
|
later (previously used assembler code tuned
|
||||||
|
for Intel MMX platform)
|
||||||
makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and
|
makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and
|
||||||
later (does not use assembler code)
|
later (does not use assembler code)
|
||||||
makefile.turboc3 => Turbo C 3.0 makefile
|
|
||||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||||
makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
|
makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||||
makevms.com => VMS build script
|
makevms.com => VMS build script
|
||||||
pngdll.mak => To make a png32bd.dll with Borland C++ 4.5
|
|
||||||
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
|
|
||||||
SCOPTIONS.ppc => Used with smakefile.ppc
|
SCOPTIONS.ppc => Used with smakefile.ppc
|
||||||
|
|
||||||
Good luck, and happy coding.
|
Good luck, and happy coding.
|
||||||
|
|
||||||
-Glenn Randers-Pehrson
|
-Glenn Randers-Pehrson (current maintainer)
|
||||||
Internet: randeg@alum.rpi.edu
|
Internet: glennrp at users.sourceforge.net
|
||||||
Web: http://www.rpi.edu/~randeg/index.html
|
|
||||||
|
|
||||||
-Andreas Eric Dilger
|
-Andreas Eric Dilger (former maintainer, 1996-1997)
|
||||||
Internet: adilger@enel.ucalgary.ca
|
Internet: adilger at enel.ucalgary.ca
|
||||||
Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
|
Web: http://members.shaw.ca/adilger/
|
||||||
|
|
||||||
-Guy Eric Schalnat
|
-Guy Eric Schalnat (original author and former maintainer, 1995-1996)
|
||||||
(formerly of Group 42, Inc)
|
(formerly of Group 42, Inc)
|
||||||
Internet: gschal@infinet.com
|
Internet: gschal at infinet.com
|
||||||
|
|||||||
17
TODO
@@ -1,14 +1,12 @@
|
|||||||
TODO - list of things to do for libpng:
|
TODO - list of things to do for libpng:
|
||||||
|
|
||||||
Final bug fixes.
|
Final bug fixes.
|
||||||
Fix problem with C++ and EXTERN "C".
|
Improve API by hiding the png_struct and png_info structs.
|
||||||
|
Finish work on the no-floating-point version (including gamma compensation)
|
||||||
Better C++ wrapper/full C++ implementation?
|
Better C++ wrapper/full C++ implementation?
|
||||||
Keep up with public chunks.
|
Fix problem with C++ and EXTERN "C".
|
||||||
sPLT chunk handling.
|
|
||||||
cHRM transformation.
|
cHRM transformation.
|
||||||
Support for application-defined chunk handlers.
|
|
||||||
Improve setjmp/longjmp usage or remove it in favor of returning error codes.
|
Improve setjmp/longjmp usage or remove it in favor of returning error codes.
|
||||||
High-level API for reading images.
|
|
||||||
Add "grayscale->palette" transformation and "palette->grayscale" detection.
|
Add "grayscale->palette" transformation and "palette->grayscale" detection.
|
||||||
Improved dithering.
|
Improved dithering.
|
||||||
Multi-lingual error and warning message support.
|
Multi-lingual error and warning message support.
|
||||||
@@ -17,8 +15,11 @@ Man pages for function calls.
|
|||||||
Better documentation.
|
Better documentation.
|
||||||
Better filter selection
|
Better filter selection
|
||||||
(counting huffman bits/precompression? filter inertia? filter costs?).
|
(counting huffman bits/precompression? filter inertia? filter costs?).
|
||||||
Optional palette (sPLT) creation.
|
|
||||||
Histogram creation.
|
Histogram creation.
|
||||||
Text conversion between different code pages (Latin-1 -> Mac and DOS).
|
Text conversion between different code pages (Latin-1 -> Mac and DOS).
|
||||||
Improve API by hiding the info_ptr.
|
Should we always malloc 2^bit_depth PLTE/tRNS/hIST entries for safety?
|
||||||
Make a no-floating-point version.
|
Build gamma tables using fixed point (and do away with floating point entirely).
|
||||||
|
Use greater precision when changing to linear gamma for compositing against
|
||||||
|
background and doing rgb-to-gray transformation.
|
||||||
|
Investigate pre-incremented loop counters and other loop constructions.
|
||||||
|
Add interpolated method of handling interlacing.
|
||||||
|
|||||||
4
Y2KINFO
@@ -1,13 +1,13 @@
|
|||||||
Y2K compliance in libpng:
|
Y2K compliance in libpng:
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
October 1, 1999
|
December 3, 2009
|
||||||
|
|
||||||
Since the PNG Development group is an ad-hoc body, we can't make
|
Since the PNG Development group is an ad-hoc body, we can't make
|
||||||
an official declaration.
|
an official declaration.
|
||||||
|
|
||||||
This is your unofficial assurance that libpng from version 0.71 and
|
This is your unofficial assurance that libpng from version 0.71 and
|
||||||
upward through 1.0.4c are Y2K compliant. It is my belief that earlier
|
upward through 1.0.51 are Y2K compliant. It is my belief that earlier
|
||||||
versions were also Y2K compliant.
|
versions were also Y2K compliant.
|
||||||
|
|
||||||
Libpng only has three year fields. One is a 2-byte unsigned integer
|
Libpng only has three year fields. One is a 2-byte unsigned integer
|
||||||
|
|||||||
8949
aclocal.m4
vendored
Normal file
25
autogen.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# a quick hack script to generate necessary files from
|
||||||
|
# auto* tools.
|
||||||
|
#
|
||||||
|
# WARNING: if you run this you will change the versions
|
||||||
|
# of the tools which are used and, maybe, required!
|
||||||
|
touch Makefile.am configure.ac
|
||||||
|
{
|
||||||
|
echo "running libtoolize" >&2
|
||||||
|
libtoolize --force --copy --automake
|
||||||
|
} && {
|
||||||
|
echo "running aclocal" >&2
|
||||||
|
aclocal
|
||||||
|
} && {
|
||||||
|
echo "running autoheader [ignore the warnings]" >&2
|
||||||
|
autoheader
|
||||||
|
} && {
|
||||||
|
echo "running automake" >&2
|
||||||
|
automake --force-missing --foreign -a -c
|
||||||
|
} && {
|
||||||
|
echo "running autoconf" >&2
|
||||||
|
autoconf
|
||||||
|
} &&
|
||||||
|
echo "autogen complete" >&2 ||
|
||||||
|
echo "ERROR: autogen.sh failed, autogen is incomplete" >&2
|
||||||
1561
config.guess
vendored
Executable file
86
config.h.in
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
|
#undef HAVE_DLFCN_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
|
#undef HAVE_INTTYPES_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `m' library (-lm). */
|
||||||
|
#undef HAVE_LIBM
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `z' library (-lz). */
|
||||||
|
#undef HAVE_LIBZ
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <malloc.h> header file. */
|
||||||
|
#undef HAVE_MALLOC_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <memory.h> header file. */
|
||||||
|
#undef HAVE_MEMORY_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `memset' function. */
|
||||||
|
#undef HAVE_MEMSET
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `pow' function. */
|
||||||
|
#undef HAVE_POW
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdint.h> header file. */
|
||||||
|
#undef HAVE_STDINT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||||
|
#undef HAVE_STDLIB_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <strings.h> header file. */
|
||||||
|
#undef HAVE_STRINGS_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <string.h> header file. */
|
||||||
|
#undef HAVE_STRING_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||||
|
#undef HAVE_SYS_STAT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||||
|
#undef HAVE_SYS_TYPES_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
|
#undef HAVE_UNISTD_H
|
||||||
|
|
||||||
|
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||||
|
*/
|
||||||
|
#undef LT_OBJDIR
|
||||||
|
|
||||||
|
/* Name of package */
|
||||||
|
#undef PACKAGE
|
||||||
|
|
||||||
|
/* Define to the address where bug reports for this package should be sent. */
|
||||||
|
#undef PACKAGE_BUGREPORT
|
||||||
|
|
||||||
|
/* Define to the full name of this package. */
|
||||||
|
#undef PACKAGE_NAME
|
||||||
|
|
||||||
|
/* Define to the full name and version of this package. */
|
||||||
|
#undef PACKAGE_STRING
|
||||||
|
|
||||||
|
/* Define to the one symbol short name of this package. */
|
||||||
|
#undef PACKAGE_TARNAME
|
||||||
|
|
||||||
|
/* Define to the home page for this package. */
|
||||||
|
#undef PACKAGE_URL
|
||||||
|
|
||||||
|
/* Define to the version of this package. */
|
||||||
|
#undef PACKAGE_VERSION
|
||||||
|
|
||||||
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
|
#undef STDC_HEADERS
|
||||||
|
|
||||||
|
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
|
||||||
|
#undef TM_IN_SYS_TIME
|
||||||
|
|
||||||
|
/* Version number of package */
|
||||||
|
#undef VERSION
|
||||||
|
|
||||||
|
/* Define to empty if `const' does not conform to ANSI C. */
|
||||||
|
#undef const
|
||||||
|
|
||||||
|
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||||
|
#undef size_t
|
||||||
1686
config.sub
vendored
Executable file
148
configure.ac
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
# configure.ac
|
||||||
|
|
||||||
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
|
dnl
|
||||||
|
dnl Minor upgrades (compatible ABI): increment the package version
|
||||||
|
dnl (third field in two places below) and set the PNGLIB_RELEASE
|
||||||
|
dnl variable.
|
||||||
|
dnl
|
||||||
|
dnl Major upgrades (incompatible ABI): increment the package major
|
||||||
|
dnl version (second field, or first if desired), set the minor
|
||||||
|
dnl to 0, set PNGLIB_MAJOR below *and* follow the instructions in
|
||||||
|
dnl Makefile.am to upgrade the package name.
|
||||||
|
|
||||||
|
dnl This is here to prevent earlier autoconf from being used, it
|
||||||
|
dnl should not be necessary to regenerate configure if the time
|
||||||
|
dnl stamps are correct
|
||||||
|
AC_PREREQ(2.59)
|
||||||
|
|
||||||
|
dnl Version number stuff here:
|
||||||
|
|
||||||
|
AC_INIT([libpng], [1.0.51], [png-mng-implement@lists.sourceforge.net])
|
||||||
|
AM_INIT_AUTOMAKE
|
||||||
|
dnl stop configure from automagically running automake
|
||||||
|
AM_MAINTAINER_MODE
|
||||||
|
|
||||||
|
PNGLIB_VERSION=1.0.51
|
||||||
|
PNGLIB_MAJOR=1
|
||||||
|
PNGLIB_MINOR=0
|
||||||
|
PNGLIB_RELEASE=51
|
||||||
|
|
||||||
|
dnl End of version number stuff
|
||||||
|
|
||||||
|
AC_CONFIG_SRCDIR([pngget.c])
|
||||||
|
AM_CONFIG_HEADER(config.h)
|
||||||
|
|
||||||
|
# Checks for programs.
|
||||||
|
AC_PROG_CC
|
||||||
|
AC_PROG_LD
|
||||||
|
AC_PROG_CPP
|
||||||
|
AC_CHECK_TOOL(SED, sed, :)
|
||||||
|
AC_LIBTOOL_WIN32_DLL
|
||||||
|
AC_PROG_INSTALL
|
||||||
|
AC_PROG_LN_S
|
||||||
|
AC_PROG_MAKE_SET
|
||||||
|
AC_PROG_LIBTOOL
|
||||||
|
|
||||||
|
# Checks for header files.
|
||||||
|
AC_HEADER_STDC
|
||||||
|
AC_CHECK_HEADERS([malloc.h stdlib.h string.h strings.h])
|
||||||
|
|
||||||
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
|
AC_C_CONST
|
||||||
|
AC_TYPE_SIZE_T
|
||||||
|
AC_STRUCT_TM
|
||||||
|
|
||||||
|
# Checks for library functions.
|
||||||
|
AC_FUNC_STRTOD
|
||||||
|
AC_CHECK_FUNCS([memset], , AC_ERROR([memset not found in libc]))
|
||||||
|
AC_CHECK_FUNCS([pow], , AC_CHECK_LIB(m, pow, , AC_ERROR([cannot find pow])) )
|
||||||
|
AC_CHECK_LIB(z, zlibVersion, , AC_ERROR([zlib not installed]))
|
||||||
|
|
||||||
|
LIBPNG_DEFINES=-DPNG_CONFIGURE_LIBPNG
|
||||||
|
AC_MSG_CHECKING(
|
||||||
|
[if assembler code in pnggccrd.c can be compiled without PNG_NO_MMX_CODE])
|
||||||
|
AC_TRY_COMPILE(
|
||||||
|
[#include "$srcdir/pnggccrd.c"],
|
||||||
|
[return 0;],
|
||||||
|
AC_MSG_RESULT(yes)
|
||||||
|
LIBPNG_NO_MMX="",
|
||||||
|
AC_MSG_RESULT(no)
|
||||||
|
LIBPNG_NO_MMX=-DPNG_NO_MMX_CODE)
|
||||||
|
LIBPNG_DEFINES=$LIBPNG_DEFINES\ $LIBPNG_NO_MMX
|
||||||
|
AC_SUBST(LIBPNG_DEFINES)
|
||||||
|
AC_SUBST(LIBPNG_NO_MMX)
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([if libraries can be versioned])
|
||||||
|
GLD=`$LD --help < /dev/null 2>/dev/null | grep version-script`
|
||||||
|
if test "$GLD"; then
|
||||||
|
have_ld_version_script=yes
|
||||||
|
AC_MSG_RESULT(yes)
|
||||||
|
else
|
||||||
|
have_ld_version_script=no
|
||||||
|
AC_MSG_RESULT(no)
|
||||||
|
AC_MSG_WARN(*** You have not enabled versioned symbols.)
|
||||||
|
fi
|
||||||
|
AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
|
||||||
|
|
||||||
|
if test "$have_ld_version_script" = "yes"; then
|
||||||
|
AC_MSG_CHECKING([for symbol prefix])
|
||||||
|
SYMBOL_PREFIX=`echo "PREFIX=__USER_LABEL_PREFIX__" \
|
||||||
|
| ${CPP-${CC-gcc} -E} - 2>&1 \
|
||||||
|
| ${EGREP-grep} "^PREFIX=" \
|
||||||
|
| ${SED-sed} "s:^PREFIX=::"`
|
||||||
|
AC_SUBST(SYMBOL_PREFIX)
|
||||||
|
AC_MSG_RESULT($SYMBOL_PREFIX)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Substitutions for .in files
|
||||||
|
AC_SUBST(PNGLIB_VERSION)
|
||||||
|
AC_SUBST(PNGLIB_MAJOR)
|
||||||
|
AC_SUBST(PNGLIB_MINOR)
|
||||||
|
AC_SUBST(PNGLIB_RELEASE)
|
||||||
|
|
||||||
|
# Additional arguments (and substitutions)
|
||||||
|
# Allow the pkg-config directory to be set
|
||||||
|
AC_ARG_WITH(pkgconfigdir,
|
||||||
|
AC_HELP_STRING([--with-pkgconfigdir],
|
||||||
|
[Use the specified pkgconfig dir (default is libdir/pkgconfig)]),
|
||||||
|
[pkgconfigdir=${withval}],
|
||||||
|
[pkgconfigdir='${libdir}/pkgconfig'])
|
||||||
|
|
||||||
|
AC_SUBST([pkgconfigdir])
|
||||||
|
AC_MSG_NOTICE([pkgconfig directory is ${pkgconfigdir}])
|
||||||
|
|
||||||
|
# Make the *-config binary config scripts optional
|
||||||
|
AC_ARG_WITH(binconfigs,
|
||||||
|
AC_HELP_STRING([--with-binconfigs],
|
||||||
|
[Generate shell libpng-config scripts as well as pkg-config data]
|
||||||
|
[@<:@default=yes@:>@]),
|
||||||
|
[if test "${withval}" = no; then
|
||||||
|
binconfigs=
|
||||||
|
AC_MSG_NOTICE([libpng-config scripts will not be built])
|
||||||
|
else
|
||||||
|
binconfigs='${binconfigs}'
|
||||||
|
fi],
|
||||||
|
[binconfigs='${binconfigs}'])
|
||||||
|
AC_SUBST([binconfigs])
|
||||||
|
|
||||||
|
# Allow the old version number library, libpng.so, to be removed from
|
||||||
|
# the build
|
||||||
|
AC_ARG_WITH(libpng-compat,
|
||||||
|
AC_HELP_STRING([--with-libpng-compat],
|
||||||
|
[Generate the obsolete libpng.so library @<:@default=yes@:>@]),
|
||||||
|
[if test "${withval}" = no; then
|
||||||
|
compatlib=
|
||||||
|
AC_MSG_NOTICE([libpng.so will not be built])
|
||||||
|
else
|
||||||
|
compatlib=libpng.la
|
||||||
|
fi],
|
||||||
|
[compatlib=libpng.la])
|
||||||
|
AC_SUBST([compatlib])
|
||||||
|
|
||||||
|
# Config files, substituting as above
|
||||||
|
AC_CONFIG_FILES([Makefile libpng.pc:scripts/libpng.pc-configure.in])
|
||||||
|
AC_CONFIG_FILES([libpng-config:scripts/libpng-config.in],
|
||||||
|
[chmod +x libpng-config])
|
||||||
|
|
||||||
|
AC_OUTPUT
|
||||||
340
contrib/gregbook/COPYING
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Library General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Library General
|
||||||
|
Public License instead of this License.
|
||||||
50
contrib/gregbook/LICENSE
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
130
contrib/gregbook/Makefile.mingw32
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
# Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make.
|
||||||
|
# Greg Roelofs
|
||||||
|
# Last modified: 2 June 2007
|
||||||
|
#
|
||||||
|
# The programs built by this makefile are described in the book,
|
||||||
|
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
|
||||||
|
# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
|
||||||
|
# generally for sale anymore, but it's the thought that counts,
|
||||||
|
# right? (Hint: http://www.libpng.org/pub/png/book/ )
|
||||||
|
#
|
||||||
|
# Invoke this makefile from a DOS-prompt window via:
|
||||||
|
#
|
||||||
|
# make -f Makefile.mingw32
|
||||||
|
#
|
||||||
|
# This makefile assumes libpng and zlib have already been built or downloaded
|
||||||
|
# and are in subdirectories at the same level as the current subdirectory
|
||||||
|
# (as indicated by the PNGDIR and ZDIR macros below). It makes no assumptions
|
||||||
|
# at all about the mingw32 installation tree (W32DIR). Edit as appropriate.
|
||||||
|
#
|
||||||
|
# Note that the names of the dynamic and static libpng and zlib libraries
|
||||||
|
# used below may change in later releases of the libraries. This makefile
|
||||||
|
# builds both statically and dynamically linked executables by default.
|
||||||
|
# (You need only one set, but for testing it can be handy to have both.)
|
||||||
|
|
||||||
|
|
||||||
|
# macros --------------------------------------------------------------------
|
||||||
|
|
||||||
|
#PNGDIR = ../..# for libpng-x.y.z/contrib/gregbook builds
|
||||||
|
PNGDIR = ../libpng-win32
|
||||||
|
PNGINC = -I$(PNGDIR)
|
||||||
|
PNGLIBd = $(PNGDIR)/libpng.dll.a # dynamically linked
|
||||||
|
PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
|
||||||
|
|
||||||
|
#ZDIR = ../../../zlib-win32# for libpng-x.y.z/contrib/gregbook builds
|
||||||
|
ZDIR = ../zlib-win32
|
||||||
|
ZINC = -I$(ZDIR)
|
||||||
|
ZLIBd = $(ZDIR)/libzdll.a
|
||||||
|
ZLIBs = $(ZDIR)/libz.a
|
||||||
|
|
||||||
|
# change this to be the path where mingw32 installs its stuff:
|
||||||
|
W32DIR =
|
||||||
|
#W32DIR = /usr/local/cross-tools/i386-mingw32msvc
|
||||||
|
W32INC = -I$(W32DIR)/include
|
||||||
|
W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
#CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation
|
||||||
|
LD = $(CC)
|
||||||
|
RM = rm -f
|
||||||
|
CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS)
|
||||||
|
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
|
||||||
|
# [-ansi, -pedantic and -W can also be used]
|
||||||
|
LDFLAGS = $(MINGW_LDFLAGS)
|
||||||
|
O = .o
|
||||||
|
E = .exe
|
||||||
|
|
||||||
|
INCS = $(PNGINC) $(ZINC) $(W32INC)
|
||||||
|
RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm
|
||||||
|
RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm
|
||||||
|
WLIBSd = $(PNGLIBd) $(ZLIBd)
|
||||||
|
WLIBSs = $(PNGLIBs) $(ZLIBs)
|
||||||
|
|
||||||
|
RPNG = rpng-win
|
||||||
|
RPNG2 = rpng2-win
|
||||||
|
WPNG = wpng
|
||||||
|
|
||||||
|
ROBJSd = $(RPNG)$(O) readpng.pic$(O)
|
||||||
|
ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O)
|
||||||
|
WOBJSd = $(WPNG)$(O) writepng.pic$(O)
|
||||||
|
|
||||||
|
RPNGs = $(RPNG)-static
|
||||||
|
RPNG2s = $(RPNG2)-static
|
||||||
|
WPNGs = $(WPNG)-static
|
||||||
|
|
||||||
|
ROBJSs = $(RPNG)$(O) readpng$(O)
|
||||||
|
ROBJS2s = $(RPNG2)$(O) readpng2$(O)
|
||||||
|
WOBJSs = $(WPNG)$(O) writepng$(O)
|
||||||
|
|
||||||
|
STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
|
||||||
|
DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||||
|
|
||||||
|
EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
|
||||||
|
|
||||||
|
|
||||||
|
# implicit make rules -------------------------------------------------------
|
||||||
|
|
||||||
|
.c$(O):
|
||||||
|
$(CC) -c $(CFLAGS) $<
|
||||||
|
|
||||||
|
%.pic$(O): %.c
|
||||||
|
$(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
|
||||||
|
|
||||||
|
|
||||||
|
# dependencies --------------------------------------------------------------
|
||||||
|
|
||||||
|
all: $(EXES)
|
||||||
|
|
||||||
|
$(RPNGs)$(E): $(ROBJSs)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs)
|
||||||
|
|
||||||
|
$(RPNG)$(E): $(ROBJSd)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd)
|
||||||
|
|
||||||
|
$(RPNG2s)$(E): $(ROBJS2s)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs)
|
||||||
|
|
||||||
|
$(RPNG2)$(E): $(ROBJS2d)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd)
|
||||||
|
|
||||||
|
$(WPNGs)$(E): $(WOBJSs)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs)
|
||||||
|
|
||||||
|
$(WPNG)$(E): $(WOBJSd)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd)
|
||||||
|
|
||||||
|
$(RPNG)$(O): $(RPNG).c readpng.h
|
||||||
|
$(RPNG2)$(O): $(RPNG2).c readpng2.h
|
||||||
|
$(WPNG)$(O): $(WPNG).c writepng.h
|
||||||
|
|
||||||
|
readpng$(O) readpng.pic$(O): readpng.c readpng.h
|
||||||
|
readpng2$(O) readpng2.pic$(O): readpng2.c readpng2.h
|
||||||
|
writepng$(O) writepng.pic$(O): writepng.c writepng.h
|
||||||
|
|
||||||
|
|
||||||
|
# maintenance ---------------------------------------------------------------
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(EXES)
|
||||||
|
$(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs)
|
||||||
|
$(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd)
|
||||||
104
contrib/gregbook/Makefile.sgi
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
# Sample makefile for rpng-x / rpng2-x / wpng for SGI using cc and make.
|
||||||
|
# Greg Roelofs
|
||||||
|
# Last modified: 7 March 2002
|
||||||
|
#
|
||||||
|
# The programs built by this makefile are described in the book,
|
||||||
|
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
|
||||||
|
# Associates, 1999). Go buy a copy, eh? Buy some for friends
|
||||||
|
# and family, too. (Not that this is a blatant plug or anything.)
|
||||||
|
#
|
||||||
|
# Invoke this makefile from a shell prompt in the usual way; for example:
|
||||||
|
#
|
||||||
|
# make -f Makefile.sgi
|
||||||
|
#
|
||||||
|
# This makefile assumes libpng and zlib have already been built or downloaded
|
||||||
|
# and are both installed in /usr/local/{include,lib} (as indicated by the
|
||||||
|
# PNG* and Z* macros below). Edit as appropriate--choose only ONE each of
|
||||||
|
# the PNGINC, PNGLIB, ZINC and ZLIB lines.
|
||||||
|
#
|
||||||
|
# This makefile builds dynamically linked executables (against libpng and zlib,
|
||||||
|
# that is), but that can be changed by uncommenting the appropriate PNGLIB and
|
||||||
|
# ZLIB lines.
|
||||||
|
|
||||||
|
|
||||||
|
# macros --------------------------------------------------------------------
|
||||||
|
|
||||||
|
PNGINC = -I/usr/local/include/libpng12
|
||||||
|
PNGLIB = -L/usr/local/lib -lpng12 # dynamically linked against libpng
|
||||||
|
#PNGLIB = /usr/local/lib/libpng12.a # statically linked against libpng
|
||||||
|
# or:
|
||||||
|
#PNGINC = -I../..
|
||||||
|
#PNGLIB = -L../.. -lpng
|
||||||
|
#PNGLIB = ../../libpng.a
|
||||||
|
|
||||||
|
ZINC = -I/usr/local/include
|
||||||
|
ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib
|
||||||
|
#ZLIB = /usr/local/lib/libz.a # statically linked against zlib
|
||||||
|
#ZINC = -I../zlib
|
||||||
|
#ZLIB = -L../zlib -lz
|
||||||
|
#ZLIB = ../../../zlib/libz.a
|
||||||
|
|
||||||
|
XINC = -I/usr/include/X11 # old-style, stock X distributions
|
||||||
|
XLIB = -L/usr/lib/X11 -lX11
|
||||||
|
#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows)
|
||||||
|
#XLIB = -L/usr/openwin/lib -lX11
|
||||||
|
#XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.)
|
||||||
|
#XLIB = -L/usr/X11R6/lib -lX11
|
||||||
|
|
||||||
|
INCS = $(PNGINC) $(ZINC) $(XINC)
|
||||||
|
RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm
|
||||||
|
WLIBS = $(PNGLIB) $(ZLIB)
|
||||||
|
|
||||||
|
CC = cc
|
||||||
|
LD = cc
|
||||||
|
RM = rm -f
|
||||||
|
# ABI must be the same as that used to build libpng.
|
||||||
|
ABI=
|
||||||
|
CFLAGS = $(ABI) -O -fullwarn $(INCS)
|
||||||
|
LDFLAGS = $(ABI)
|
||||||
|
O = .o
|
||||||
|
E =
|
||||||
|
|
||||||
|
RPNG = rpng-x
|
||||||
|
RPNG2 = rpng2-x
|
||||||
|
WPNG = wpng
|
||||||
|
|
||||||
|
ROBJS = $(RPNG)$(O) readpng$(O)
|
||||||
|
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
|
||||||
|
WOBJS = $(WPNG)$(O) writepng$(O)
|
||||||
|
|
||||||
|
EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||||
|
|
||||||
|
|
||||||
|
# implicit make rules -------------------------------------------------------
|
||||||
|
|
||||||
|
.c$(O):
|
||||||
|
$(CC) -c $(CFLAGS) $<
|
||||||
|
|
||||||
|
|
||||||
|
# dependencies --------------------------------------------------------------
|
||||||
|
|
||||||
|
all: $(EXES)
|
||||||
|
|
||||||
|
$(RPNG)$(E): $(ROBJS)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS)
|
||||||
|
|
||||||
|
$(RPNG2)$(E): $(ROBJS2)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS)
|
||||||
|
|
||||||
|
$(WPNG)$(E): $(WOBJS)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS)
|
||||||
|
|
||||||
|
$(RPNG)$(O): $(RPNG).c readpng.h
|
||||||
|
$(RPNG2)$(O): $(RPNG2).c readpng2.h
|
||||||
|
$(WPNG)$(O): $(WPNG).c writepng.h
|
||||||
|
|
||||||
|
readpng$(O): readpng.c readpng.h
|
||||||
|
readpng2$(O): readpng2.c readpng2.h
|
||||||
|
writepng$(O): writepng.c writepng.h
|
||||||
|
|
||||||
|
|
||||||
|
# maintenance ---------------------------------------------------------------
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
|
||||||
132
contrib/gregbook/Makefile.unx
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
|
||||||
|
# Greg Roelofs
|
||||||
|
# Last modified: 2 June 2007
|
||||||
|
#
|
||||||
|
# The programs built by this makefile are described in the book,
|
||||||
|
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
|
||||||
|
# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
|
||||||
|
# generally for sale anymore, but it's the thought that counts,
|
||||||
|
# right? (Hint: http://www.libpng.org/pub/png/book/ )
|
||||||
|
#
|
||||||
|
# Invoke this makefile from a shell prompt in the usual way; for example:
|
||||||
|
#
|
||||||
|
# make -f Makefile.unx
|
||||||
|
#
|
||||||
|
# This makefile assumes libpng and zlib have already been built or downloaded
|
||||||
|
# and are installed in /usr/local/{include,lib} or as otherwise indicated by
|
||||||
|
# the PNG* and Z* macros below. Edit as appropriate--choose only ONE each of
|
||||||
|
# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines.
|
||||||
|
#
|
||||||
|
# This makefile builds both dynamically and statically linked executables
|
||||||
|
# (against libpng and zlib, that is), but that can be changed by modifying
|
||||||
|
# the "EXES =" line. (You need only one set, but for testing it can be handy
|
||||||
|
# to have both.)
|
||||||
|
|
||||||
|
|
||||||
|
# macros --------------------------------------------------------------------
|
||||||
|
|
||||||
|
#PNGDIR = /usr/local/lib
|
||||||
|
#PNGINC = -I/usr/local/include/libpng12
|
||||||
|
#PNGLIBd = -L$(PNGDIR) -lpng12 # dynamically linked, installed libpng
|
||||||
|
#PNGLIBs = $(PNGDIR)/libpng12.a # statically linked, installed libpng
|
||||||
|
# or:
|
||||||
|
PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds
|
||||||
|
#PNGDIR = ../libpng
|
||||||
|
PNGINC = -I$(PNGDIR)
|
||||||
|
PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng12 # dynamically linked
|
||||||
|
PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
|
||||||
|
|
||||||
|
ZDIR = /usr/local/lib
|
||||||
|
#ZDIR = /usr/lib64
|
||||||
|
ZINC = -I/usr/local/include
|
||||||
|
ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib
|
||||||
|
ZLIBs = $(ZDIR)/libz.a # statically linked against zlib
|
||||||
|
# or:
|
||||||
|
#ZDIR = ../zlib
|
||||||
|
#ZINC = -I$(ZDIR)
|
||||||
|
#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing
|
||||||
|
#ZLIBs = $(ZDIR)/libz.a
|
||||||
|
|
||||||
|
#XINC = -I/usr/include # old-style, stock X distributions
|
||||||
|
#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX)
|
||||||
|
#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows)
|
||||||
|
#XLIB = -L/usr/openwin/lib -lX11
|
||||||
|
XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.)
|
||||||
|
XLIB = -L/usr/X11R6/lib -lX11
|
||||||
|
#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64
|
||||||
|
|
||||||
|
INCS = $(PNGINC) $(ZINC) $(XINC)
|
||||||
|
RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm
|
||||||
|
RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm
|
||||||
|
WLIBSd = $(PNGLIBd) $(ZLIBd) -lm
|
||||||
|
WLIBSs = $(PNGLIBs) $(ZLIBs)
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
LD = gcc
|
||||||
|
RM = rm -f
|
||||||
|
CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP
|
||||||
|
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
|
||||||
|
# [-ansi, -pedantic and -W can also be used]
|
||||||
|
LDFLAGS =
|
||||||
|
O = .o
|
||||||
|
E =
|
||||||
|
|
||||||
|
RPNG = rpng-x
|
||||||
|
RPNG2 = rpng2-x
|
||||||
|
WPNG = wpng
|
||||||
|
|
||||||
|
RPNGs = $(RPNG)-static
|
||||||
|
RPNG2s = $(RPNG2)-static
|
||||||
|
WPNGs = $(WPNG)-static
|
||||||
|
|
||||||
|
ROBJS = $(RPNG)$(O) readpng$(O)
|
||||||
|
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
|
||||||
|
WOBJS = $(WPNG)$(O) writepng$(O)
|
||||||
|
|
||||||
|
STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
|
||||||
|
DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||||
|
|
||||||
|
EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
|
||||||
|
|
||||||
|
|
||||||
|
# implicit make rules -------------------------------------------------------
|
||||||
|
|
||||||
|
.c$(O):
|
||||||
|
$(CC) -c $(CFLAGS) $<
|
||||||
|
|
||||||
|
|
||||||
|
# dependencies --------------------------------------------------------------
|
||||||
|
|
||||||
|
all: $(EXES)
|
||||||
|
|
||||||
|
$(RPNGs)$(E): $(ROBJS)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs)
|
||||||
|
|
||||||
|
$(RPNG)$(E): $(ROBJS)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd)
|
||||||
|
|
||||||
|
$(RPNG2s)$(E): $(ROBJS2)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs)
|
||||||
|
|
||||||
|
$(RPNG2)$(E): $(ROBJS2)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd)
|
||||||
|
|
||||||
|
$(WPNGs)$(E): $(WOBJS)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs)
|
||||||
|
|
||||||
|
$(WPNG)$(E): $(WOBJS)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd)
|
||||||
|
|
||||||
|
$(RPNG)$(O): $(RPNG).c readpng.h
|
||||||
|
$(RPNG2)$(O): $(RPNG2).c readpng2.h
|
||||||
|
$(WPNG)$(O): $(WPNG).c writepng.h
|
||||||
|
|
||||||
|
readpng$(O): readpng.c readpng.h
|
||||||
|
readpng2$(O): readpng2.c readpng2.h
|
||||||
|
writepng$(O): writepng.c writepng.h
|
||||||
|
|
||||||
|
|
||||||
|
# maintenance ---------------------------------------------------------------
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
|
||||||
113
contrib/gregbook/Makefile.w32
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE.
|
||||||
|
# Greg Roelofs
|
||||||
|
# Last modified: 2 June 2007
|
||||||
|
#
|
||||||
|
# The programs built by this makefile are described in the book,
|
||||||
|
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
|
||||||
|
# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
|
||||||
|
# generally for sale anymore, but it's the thought that counts,
|
||||||
|
# right? (Hint: http://www.libpng.org/pub/png/book/ )
|
||||||
|
#
|
||||||
|
# Invoke this makefile from a DOS prompt window via:
|
||||||
|
#
|
||||||
|
# %devstudio%\vc\bin\vcvars32.bat
|
||||||
|
# nmake -nologo -f Makefile.w32
|
||||||
|
#
|
||||||
|
# where %devstudio% is the installation directory for MSVC / DevStudio. If
|
||||||
|
# you get "environment out of space" errors, create a desktop shortcut with
|
||||||
|
# "c:\windows\command.com /e:4096" as the program command line and set the
|
||||||
|
# working directory to this directory. Then double-click to open the new
|
||||||
|
# DOS-prompt window with a bigger environment and retry the commands above.
|
||||||
|
#
|
||||||
|
# This makefile assumes libpng and zlib have already been built or downloaded
|
||||||
|
# and are in subdirectories at the same level as the current subdirectory
|
||||||
|
# (as indicated by the PNGPATH and ZPATH macros below). Edit as appropriate.
|
||||||
|
#
|
||||||
|
# Note that the names of the dynamic and static libpng and zlib libraries
|
||||||
|
# used below may change in later releases of the libraries. This makefile
|
||||||
|
# builds statically linked executables, but that can be changed by uncom-
|
||||||
|
# menting the appropriate PNGLIB and ZLIB lines.
|
||||||
|
|
||||||
|
!include <ntwin32.mak>
|
||||||
|
|
||||||
|
|
||||||
|
# macros --------------------------------------------------------------------
|
||||||
|
|
||||||
|
PNGPATH = ../libpng
|
||||||
|
PNGINC = -I$(PNGPATH)
|
||||||
|
#PNGLIB = $(PNGPATH)/pngdll.lib
|
||||||
|
PNGLIB = $(PNGPATH)/libpng.lib
|
||||||
|
|
||||||
|
ZPATH = ../zlib
|
||||||
|
ZINC = -I$(ZPATH)
|
||||||
|
#ZLIB = $(ZPATH)/zlibdll.lib
|
||||||
|
ZLIB = $(ZPATH)/zlibstat.lib
|
||||||
|
|
||||||
|
WINLIBS = -defaultlib:user32.lib gdi32.lib
|
||||||
|
# ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.]
|
||||||
|
|
||||||
|
INCS = $(PNGINC) $(ZINC)
|
||||||
|
RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS)
|
||||||
|
WLIBS = $(PNGLIB) $(ZLIB)
|
||||||
|
|
||||||
|
CC = cl
|
||||||
|
LD = link
|
||||||
|
RM = del
|
||||||
|
CFLAGS = -nologo -O -W3 $(INCS) $(cvars)
|
||||||
|
# [note that -W3 is an MSVC-specific compilation flag ("all warnings on")]
|
||||||
|
# [see %devstudio%\vc\include\win32.mak for cvars macro definition]
|
||||||
|
O = .obj
|
||||||
|
E = .exe
|
||||||
|
|
||||||
|
RLDFLAGS = -nologo -subsystem:windows
|
||||||
|
WLDFLAGS = -nologo
|
||||||
|
|
||||||
|
RPNG = rpng-win
|
||||||
|
RPNG2 = rpng2-win
|
||||||
|
WPNG = wpng
|
||||||
|
|
||||||
|
ROBJS = $(RPNG)$(O) readpng$(O)
|
||||||
|
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
|
||||||
|
WOBJS = $(WPNG)$(O) writepng$(O)
|
||||||
|
|
||||||
|
EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||||
|
|
||||||
|
|
||||||
|
# implicit make rules -------------------------------------------------------
|
||||||
|
|
||||||
|
.c$(O):
|
||||||
|
$(CC) -c $(CFLAGS) $<
|
||||||
|
|
||||||
|
|
||||||
|
# dependencies --------------------------------------------------------------
|
||||||
|
|
||||||
|
all: $(EXES)
|
||||||
|
|
||||||
|
$(RPNG)$(E): $(ROBJS)
|
||||||
|
$(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS)
|
||||||
|
|
||||||
|
$(RPNG2)$(E): $(ROBJS2)
|
||||||
|
$(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS)
|
||||||
|
|
||||||
|
$(WPNG)$(E): $(WOBJS)
|
||||||
|
$(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS)
|
||||||
|
|
||||||
|
$(RPNG)$(O): $(RPNG).c readpng.h
|
||||||
|
$(RPNG2)$(O): $(RPNG2).c readpng2.h
|
||||||
|
$(WPNG)$(O): $(WPNG).c writepng.h
|
||||||
|
|
||||||
|
readpng$(O): readpng.c readpng.h
|
||||||
|
readpng2$(O): readpng2.c readpng2.h
|
||||||
|
writepng$(O): writepng.c writepng.h
|
||||||
|
|
||||||
|
|
||||||
|
# maintenance ---------------------------------------------------------------
|
||||||
|
|
||||||
|
clean:
|
||||||
|
# ideally we could just do this:
|
||||||
|
# $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
|
||||||
|
# ...but the Windows "DEL" command is none too bright, so:
|
||||||
|
$(RM) r*$(E)
|
||||||
|
$(RM) w*$(E)
|
||||||
|
$(RM) r*$(O)
|
||||||
|
$(RM) w*$(O)
|
||||||
186
contrib/gregbook/README
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
===========================
|
||||||
|
PNG: The Definitive Guide
|
||||||
|
===========================
|
||||||
|
|
||||||
|
Source Code
|
||||||
|
|
||||||
|
Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free,
|
||||||
|
cross-platform demo programs that show how to use the libpng reference
|
||||||
|
library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is
|
||||||
|
a very simple example that that shows how a standard file-viewer might use
|
||||||
|
libpng, while the second is designed to process streaming data and shows
|
||||||
|
how a web browser might be written. wpng is a simple command-line program
|
||||||
|
that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets
|
||||||
|
of PBMPLUS/NetPBM) and converts them to PNG.
|
||||||
|
|
||||||
|
The source code for all three demo programs currently compiles under
|
||||||
|
Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser,
|
||||||
|
zinser@decus.de, for making the necessary changes for OpenVMS and for
|
||||||
|
providing an appropriate build script.) Build instructions can be found
|
||||||
|
below.
|
||||||
|
|
||||||
|
Files:
|
||||||
|
|
||||||
|
README this file
|
||||||
|
LICENSE terms of distribution and reuse (BSD-like or GNU GPL)
|
||||||
|
COPYING GNU General Public License (GPL)
|
||||||
|
|
||||||
|
Makefile.unx Unix makefile
|
||||||
|
Makefile.w32 Windows (MSVC) makefile
|
||||||
|
makevms.com OpenVMS build script
|
||||||
|
|
||||||
|
rpng-win.c Windows front end for the basic viewer
|
||||||
|
rpng-x.c X Window System (Unix, OpenVMS) front end
|
||||||
|
readpng.c generic back end for the basic viewer
|
||||||
|
readpng.h header file for the basic viewer
|
||||||
|
|
||||||
|
rpng2-win.c Windows front end for the progressive viewer
|
||||||
|
rpng2-x.c X front end for the progressive viewer
|
||||||
|
readpng2.c generic back end for the progressive viewer
|
||||||
|
readpng2.h header file for the progressive viewer
|
||||||
|
|
||||||
|
wpng.c generic (text) front end for the converter
|
||||||
|
writepng.c generic back end for the converter
|
||||||
|
writepng.h header file for the converter
|
||||||
|
|
||||||
|
toucan.png transparent PNG for testing (by Stefan Schneider)
|
||||||
|
|
||||||
|
Note that, although the programs are designed to be functional, their
|
||||||
|
primary purpose is to illustrate how to use libpng to add PNG support to
|
||||||
|
other programs. As such, their user interfaces are crude and definitely
|
||||||
|
are not intended for everyday use.
|
||||||
|
|
||||||
|
Please see http://www.libpng.org/pub/png/pngbook.html for further infor-
|
||||||
|
mation and links to the latest version of the source code, and Chapters
|
||||||
|
13-15 of the book for detailed discussion of the three programs.
|
||||||
|
|
||||||
|
Greg Roelofs
|
||||||
|
http://pobox.com/~newt/greg_contact.html
|
||||||
|
16 March 2008
|
||||||
|
|
||||||
|
|
||||||
|
BUILD INSTRUCTIONS
|
||||||
|
|
||||||
|
- Prerequisites (in order of compilation):
|
||||||
|
|
||||||
|
- zlib http://zlib.net/
|
||||||
|
- libpng http://www.libpng.org/pub/png/libpng.html
|
||||||
|
- pngbook http://www.libpng.org/pub/png/book/sources.html
|
||||||
|
|
||||||
|
The pngbook demo programs are explicitly designed to demonstrate proper
|
||||||
|
coding techniques for using the libpng reference library. As a result,
|
||||||
|
you need to download and build both zlib (on which libpng depends) and
|
||||||
|
libpng. A common build setup is to place the zlib, libpng and pngbook
|
||||||
|
subdirectory trees ("folders") in the same parent directory. Then the
|
||||||
|
libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]),
|
||||||
|
and similarly for the pngbook build.
|
||||||
|
|
||||||
|
Note that all three packages are designed to be built from a command
|
||||||
|
line by default; those who wish to use a graphical or other integrated
|
||||||
|
development environments are on their own.
|
||||||
|
|
||||||
|
|
||||||
|
- Unix:
|
||||||
|
|
||||||
|
Unpack the latest pngbook sources (which should correspond to this
|
||||||
|
README file) into a directory and change into that directory.
|
||||||
|
|
||||||
|
Copy Makefile.unx to Makefile and edit the PNG* and Z* variables
|
||||||
|
appropriately (possibly also the X* variables if necessary).
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
There is no "install" target, so copy the three executables somewhere
|
||||||
|
in your path or run them from the current directory. All three will
|
||||||
|
print a basic usage screen when run without any command-line arguments;
|
||||||
|
see the book for more details.
|
||||||
|
|
||||||
|
|
||||||
|
- Windows:
|
||||||
|
|
||||||
|
Unpack the latest pngbook sources (which should correspond to this
|
||||||
|
README file) into a folder, open a "DOS shell" or "command prompt"
|
||||||
|
or equivalent command-line window, and cd into the folder where you
|
||||||
|
unpacked the source code.
|
||||||
|
|
||||||
|
For MSVC, set up the necessary environment variables by invoking
|
||||||
|
|
||||||
|
%devstudio%\vc\bin\vcvars32.bat
|
||||||
|
|
||||||
|
where where %devstudio% is the installation directory for MSVC /
|
||||||
|
DevStudio. If you get "environment out of space" errors under 95/98,
|
||||||
|
create a desktop shortcut with "c:\windows\command.com /e:4096" as
|
||||||
|
the program command line and set the working directory to the pngbook
|
||||||
|
directory. Then double-click to open the new DOS-prompt window with
|
||||||
|
a bigger environment and retry the commands above.
|
||||||
|
|
||||||
|
Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables
|
||||||
|
appropriately (possibly also the "INC" and "LIB" variables if needed).
|
||||||
|
Note that the names of the dynamic and static libpng and zlib libraries
|
||||||
|
used in the makefile may change in later releases of the libraries.
|
||||||
|
Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work.
|
||||||
|
This makefile therefore builds statically linked executables, but if
|
||||||
|
the DLL problems ever get fixed, uncommenting the appropriate PNGLIB
|
||||||
|
and ZLIB lines will build dynamically linked executables instead.
|
||||||
|
|
||||||
|
Do the build by typing
|
||||||
|
|
||||||
|
nmake
|
||||||
|
|
||||||
|
The result should be three executables: rpng-win.exe, rpng2-win.exe,
|
||||||
|
and wpng.exe. Copy them somewhere in your PATH or run them from the
|
||||||
|
current folder. Like the Unix versions, the two windowed programs
|
||||||
|
(rpng and rpng2) now display a usage screen in a console window when
|
||||||
|
invoked without command-line arguments; this is new behavior as of
|
||||||
|
the June 2001 release. Note that the programs use the Unix-style "-"
|
||||||
|
character to specify options, instead of the more common DOS/Windows
|
||||||
|
"/" character. (For example: "rpng2-win -bgpat 4 foo.png", not
|
||||||
|
"rpng2-win /bgpat 4 foo.png")
|
||||||
|
|
||||||
|
|
||||||
|
- OpenVMS:
|
||||||
|
|
||||||
|
Unpack the pngbook sources into a subdirectory and change into that
|
||||||
|
subdirectory.
|
||||||
|
|
||||||
|
Edit makevms.com appropriately, specifically the zpath and pngpath
|
||||||
|
variables.
|
||||||
|
|
||||||
|
@makevms
|
||||||
|
|
||||||
|
To run the programs, they probably first need to be set up as "foreign
|
||||||
|
symbols," with "disk" and "dir" set appropriately:
|
||||||
|
|
||||||
|
$ rpng == "$disk:[dir]rpng-x.exe"
|
||||||
|
$ rpng2 == "$disk:[dir]rpng2-x.exe"
|
||||||
|
$ wpng == "$disk:[dir]wpng.exe"
|
||||||
|
|
||||||
|
All three will print a basic usage screen when run without any command-
|
||||||
|
line arguments; see the book for more details. Note that the options
|
||||||
|
style is Unix-like, i.e., preceded by "-" rather than "/".
|
||||||
|
|
||||||
|
|
||||||
|
RUNNING THE PROGRAMS: (VERY) BRIEF INTRO
|
||||||
|
|
||||||
|
rpng is a simple PNG viewer that can display transparent PNGs with a
|
||||||
|
specified background color; for example,
|
||||||
|
|
||||||
|
rpng -bgcolor #ff0000 toucan.png
|
||||||
|
|
||||||
|
would display the image with a red background. rpng2 is a progressive
|
||||||
|
viewer that simulates a web browser in some respects; it can display
|
||||||
|
images against either a background color or a dynamically generated
|
||||||
|
background image. For example:
|
||||||
|
|
||||||
|
rpng2 -bgpat 16 toucan.png
|
||||||
|
|
||||||
|
wpng is a purely command-line image converter from binary PBMPLUS/NetPBM
|
||||||
|
format (.pgm or .ppm) to PNG; for example,
|
||||||
|
|
||||||
|
wpng -time < toucan-notrans.ppm > toucan-notrans.png
|
||||||
|
|
||||||
|
would convert the specified PPM file (using redirection) to PNG, auto-
|
||||||
|
matically setting the PNG modification-time chunk.
|
||||||
|
|
||||||
|
All options can be abbreviated to the shortest unique value; for example,
|
||||||
|
"-bgc" for -bgcolor (versus "-bgp" for -bgpat), or "-g" for -gamma.
|
||||||
132
contrib/gregbook/makevms.com
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
$!------------------------------------------------------------------------------
|
||||||
|
$! make "PNG: The Definitive Guide" demo programs (for X) under OpenVMS
|
||||||
|
$!
|
||||||
|
$! Script created by Martin Zinser for libpng; modified by Greg Roelofs
|
||||||
|
$! for standalone pngbook source distribution.
|
||||||
|
$!
|
||||||
|
$!
|
||||||
|
$! Set locations where zlib and libpng sources live.
|
||||||
|
$!
|
||||||
|
$ zpath = ""
|
||||||
|
$ pngpath = ""
|
||||||
|
$!
|
||||||
|
$ if f$search("[---.zlib]zlib.h").nes."" then zpath = "[---.zlib]"
|
||||||
|
$ if f$search("[--]png.h").nes."" then pngpath = "[--]"
|
||||||
|
$!
|
||||||
|
$ if f$search("[-.zlib]zlib.h").nes."" then zpath = "[-.zlib]"
|
||||||
|
$ if f$search("[-.libpng]png.h").nes."" then pngpath = "[-.libpng]"
|
||||||
|
$!
|
||||||
|
$ if zpath .eqs. ""
|
||||||
|
$ then
|
||||||
|
$ write sys$output "zlib include not found. Exiting..."
|
||||||
|
$ exit 2
|
||||||
|
$ endif
|
||||||
|
$!
|
||||||
|
$ if pngpath .eqs. ""
|
||||||
|
$ then
|
||||||
|
$ write sys$output "libpng include not found. Exiting..."
|
||||||
|
$ exit 2
|
||||||
|
$ endif
|
||||||
|
$!
|
||||||
|
$! Look for the compiler used.
|
||||||
|
$!
|
||||||
|
$ ccopt="/include=(''zpath',''pngpath')"
|
||||||
|
$ if f$getsyi("HW_MODEL").ge.1024
|
||||||
|
$ then
|
||||||
|
$ ccopt = "/prefix=all"+ccopt
|
||||||
|
$ comp = "__decc__=1"
|
||||||
|
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||||
|
$ else
|
||||||
|
$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
|
||||||
|
$ then
|
||||||
|
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||||
|
$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
|
||||||
|
$ then
|
||||||
|
$ comp = "__gcc__=1"
|
||||||
|
$ CC :== GCC
|
||||||
|
$ else
|
||||||
|
$ comp = "__vaxc__=1"
|
||||||
|
$ endif
|
||||||
|
$ else
|
||||||
|
$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
|
||||||
|
$ ccopt = "/decc/prefix=all"+ccopt
|
||||||
|
$ comp = "__decc__=1"
|
||||||
|
$ endif
|
||||||
|
$ endif
|
||||||
|
$ open/write lopt lib.opt
|
||||||
|
$ write lopt "''pngpath'libpng.olb/lib"
|
||||||
|
$ write lopt "''zpath'libz.olb/lib"
|
||||||
|
$ close lopt
|
||||||
|
$ open/write xopt x11.opt
|
||||||
|
$ write xopt "sys$library:decw$xlibshr.exe/share"
|
||||||
|
$ close xopt
|
||||||
|
$!
|
||||||
|
$! Build 'em.
|
||||||
|
$!
|
||||||
|
$ write sys$output "Compiling PNG book programs ..."
|
||||||
|
$ CALL MAKE readpng.OBJ "cc ''CCOPT' readpng" -
|
||||||
|
readpng.c readpng.h
|
||||||
|
$ CALL MAKE readpng2.OBJ "cc ''CCOPT' readpng2" -
|
||||||
|
readpng2.c readpng2.h
|
||||||
|
$ CALL MAKE writepng.OBJ "cc ''CCOPT' writepng" -
|
||||||
|
writepng.c writepng.h
|
||||||
|
$ write sys$output "Building rpng-x..."
|
||||||
|
$ CALL MAKE rpng-x.OBJ "cc ''CCOPT' rpng-x" -
|
||||||
|
rpng-x.c readpng.h
|
||||||
|
$ call make rpng-x.exe -
|
||||||
|
"LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt" -
|
||||||
|
rpng-x.obj readpng.obj
|
||||||
|
$ write sys$output "Building rpng2-x..."
|
||||||
|
$ CALL MAKE rpng2-x.OBJ "cc ''CCOPT' rpng2-x" -
|
||||||
|
rpng2-x.c readpng2.h
|
||||||
|
$ call make rpng2-x.exe -
|
||||||
|
"LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt" -
|
||||||
|
rpng2-x.obj readpng2.obj
|
||||||
|
$ write sys$output "Building wpng..."
|
||||||
|
$ CALL MAKE wpng.OBJ "cc ''CCOPT' wpng" -
|
||||||
|
wpng.c writepng.h
|
||||||
|
$ call make wpng.exe -
|
||||||
|
"LINK wpng,writepng,lib.opt/opt" -
|
||||||
|
wpng.obj writepng.obj
|
||||||
|
$ exit
|
||||||
|
$!
|
||||||
|
$!
|
||||||
|
$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
|
||||||
|
$ V = 'F$Verify(0)
|
||||||
|
$! P1 = What we are trying to make
|
||||||
|
$! P2 = Command to make it
|
||||||
|
$! P3 - P8 What it depends on
|
||||||
|
$
|
||||||
|
$ If F$Search(P1) .Eqs. "" Then Goto Makeit
|
||||||
|
$ Time = F$CvTime(F$File(P1,"RDT"))
|
||||||
|
$arg=3
|
||||||
|
$Loop:
|
||||||
|
$ Argument = P'arg
|
||||||
|
$ If Argument .Eqs. "" Then Goto Exit
|
||||||
|
$ El=0
|
||||||
|
$Loop2:
|
||||||
|
$ File = F$Element(El," ",Argument)
|
||||||
|
$ If File .Eqs. " " Then Goto Endl
|
||||||
|
$ AFile = ""
|
||||||
|
$Loop3:
|
||||||
|
$ OFile = AFile
|
||||||
|
$ AFile = F$Search(File)
|
||||||
|
$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
|
||||||
|
$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
|
||||||
|
$ Goto Loop3
|
||||||
|
$NextEL:
|
||||||
|
$ El = El + 1
|
||||||
|
$ Goto Loop2
|
||||||
|
$EndL:
|
||||||
|
$ arg=arg+1
|
||||||
|
$ If arg .Le. 8 Then Goto Loop
|
||||||
|
$ Goto Exit
|
||||||
|
$
|
||||||
|
$Makeit:
|
||||||
|
$ VV=F$VERIFY(0)
|
||||||
|
$ write sys$output P2
|
||||||
|
$ 'P2
|
||||||
|
$ VV='F$Verify(VV)
|
||||||
|
$Exit:
|
||||||
|
$ If V Then Set Verify
|
||||||
|
$ENDSUBROUTINE
|
||||||
304
contrib/gregbook/readpng.c
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rpng - simple PNG display program readpng.c
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "png.h" /* libpng header; includes zlib.h */
|
||||||
|
#include "readpng.h" /* typedefs, common macros, public prototypes */
|
||||||
|
|
||||||
|
/* future versions of libpng will provide this macro: */
|
||||||
|
#ifndef png_jmpbuf
|
||||||
|
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static png_structp png_ptr = NULL;
|
||||||
|
static png_infop info_ptr = NULL;
|
||||||
|
|
||||||
|
png_uint_32 width, height;
|
||||||
|
int bit_depth, color_type;
|
||||||
|
uch *image_data = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
void readpng_version_info(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
|
||||||
|
PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||||
|
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||||
|
ZLIB_VERSION, zlib_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
|
||||||
|
|
||||||
|
int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
|
||||||
|
{
|
||||||
|
uch sig[8];
|
||||||
|
|
||||||
|
|
||||||
|
/* first do a quick check that the file really is a PNG image; could
|
||||||
|
* have used slightly more general png_sig_cmp() function instead */
|
||||||
|
|
||||||
|
fread(sig, 1, 8, infile);
|
||||||
|
if (png_sig_cmp(sig, 0, 8))
|
||||||
|
return 1; /* bad signature */
|
||||||
|
|
||||||
|
|
||||||
|
/* could pass pointers to user-defined error handlers instead of NULLs: */
|
||||||
|
|
||||||
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
|
if (!png_ptr)
|
||||||
|
return 4; /* out of memory */
|
||||||
|
|
||||||
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
if (!info_ptr) {
|
||||||
|
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||||
|
return 4; /* out of memory */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* we could create a second info struct here (end_info), but it's only
|
||||||
|
* useful if we want to keep pre- and post-IDAT chunk info separated
|
||||||
|
* (mainly for PNG-aware image editors and converters) */
|
||||||
|
|
||||||
|
|
||||||
|
/* setjmp() must be called in every function that calls a PNG-reading
|
||||||
|
* libpng function */
|
||||||
|
|
||||||
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
png_init_io(png_ptr, infile);
|
||||||
|
png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */
|
||||||
|
|
||||||
|
png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */
|
||||||
|
|
||||||
|
|
||||||
|
/* alternatively, could make separate calls to png_get_image_width(),
|
||||||
|
* etc., but want bit_depth and color_type for later [don't care about
|
||||||
|
* compression_type and filter_type => NULLs] */
|
||||||
|
|
||||||
|
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
*pWidth = width;
|
||||||
|
*pHeight = height;
|
||||||
|
|
||||||
|
|
||||||
|
/* OK, that's all we need for now; return happy */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
|
||||||
|
* scales values to 8-bit if necessary */
|
||||||
|
|
||||||
|
int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
|
||||||
|
{
|
||||||
|
png_color_16p pBackground;
|
||||||
|
|
||||||
|
|
||||||
|
/* setjmp() must be called in every function that calls a PNG-reading
|
||||||
|
* libpng function */
|
||||||
|
|
||||||
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* it is not obvious from the libpng documentation, but this function
|
||||||
|
* takes a pointer to a pointer, and it always returns valid red, green
|
||||||
|
* and blue values, regardless of color_type: */
|
||||||
|
|
||||||
|
png_get_bKGD(png_ptr, info_ptr, &pBackground);
|
||||||
|
|
||||||
|
|
||||||
|
/* however, it always returns the raw bKGD data, regardless of any
|
||||||
|
* bit-depth transformations, so check depth and adjust if necessary */
|
||||||
|
|
||||||
|
if (bit_depth == 16) {
|
||||||
|
*red = pBackground->red >> 8;
|
||||||
|
*green = pBackground->green >> 8;
|
||||||
|
*blue = pBackground->blue >> 8;
|
||||||
|
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
|
||||||
|
if (bit_depth == 1)
|
||||||
|
*red = *green = *blue = pBackground->gray? 255 : 0;
|
||||||
|
else if (bit_depth == 2)
|
||||||
|
*red = *green = *blue = (255/3) * pBackground->gray;
|
||||||
|
else /* bit_depth == 4 */
|
||||||
|
*red = *green = *blue = (255/15) * pBackground->gray;
|
||||||
|
} else {
|
||||||
|
*red = (uch)pBackground->red;
|
||||||
|
*green = (uch)pBackground->green;
|
||||||
|
*blue = (uch)pBackground->blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* display_exponent == LUT_exponent * CRT_exponent */
|
||||||
|
|
||||||
|
uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
|
||||||
|
{
|
||||||
|
double gamma;
|
||||||
|
png_uint_32 i, rowbytes;
|
||||||
|
png_bytepp row_pointers = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/* setjmp() must be called in every function that calls a PNG-reading
|
||||||
|
* libpng function */
|
||||||
|
|
||||||
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
|
||||||
|
* transparency chunks to full alpha channel; strip 16-bit-per-sample
|
||||||
|
* images to 8 bits per sample; and convert grayscale to RGB[A] */
|
||||||
|
|
||||||
|
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (bit_depth == 16)
|
||||||
|
png_set_strip_16(png_ptr);
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||||
|
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
png_set_gray_to_rgb(png_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/* unlike the example in the libpng documentation, we have *no* idea where
|
||||||
|
* this file may have come from--so if it doesn't have a file gamma, don't
|
||||||
|
* do any correction ("do no harm") */
|
||||||
|
|
||||||
|
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
|
||||||
|
png_set_gamma(png_ptr, display_exponent, gamma);
|
||||||
|
|
||||||
|
|
||||||
|
/* all transformations have been registered; now update info_ptr data,
|
||||||
|
* get rowbytes and channels, and allocate image memory */
|
||||||
|
|
||||||
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
*pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||||
|
*pChannels = (int)png_get_channels(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
free(image_data);
|
||||||
|
image_data = NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Trace((stderr, "readpng_get_image: channels = %d, rowbytes = %ld, height = %ld\n", *pChannels, rowbytes, height));
|
||||||
|
|
||||||
|
|
||||||
|
/* set the individual row_pointers to point at the correct offsets */
|
||||||
|
|
||||||
|
for (i = 0; i < height; ++i)
|
||||||
|
row_pointers[i] = image_data + i*rowbytes;
|
||||||
|
|
||||||
|
|
||||||
|
/* now we can go ahead and just read the whole image */
|
||||||
|
|
||||||
|
png_read_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
|
|
||||||
|
/* and we're done! (png_read_end() can be omitted if no processing of
|
||||||
|
* post-IDAT text/time/etc. is desired) */
|
||||||
|
|
||||||
|
free(row_pointers);
|
||||||
|
row_pointers = NULL;
|
||||||
|
|
||||||
|
png_read_end(png_ptr, NULL);
|
||||||
|
|
||||||
|
return image_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void readpng_cleanup(int free_image_data)
|
||||||
|
{
|
||||||
|
if (free_image_data && image_data) {
|
||||||
|
free(image_data);
|
||||||
|
image_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (png_ptr && info_ptr) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
png_ptr = NULL;
|
||||||
|
info_ptr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
88
contrib/gregbook/readpng.h
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rpng - simple PNG display program readpng.h
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
# define TRUE 1
|
||||||
|
# define FALSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
# define MAX(a,b) ((a) > (b)? (a) : (b))
|
||||||
|
# define MIN(a,b) ((a) < (b)? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
|
||||||
|
#else
|
||||||
|
# define Trace(x) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef unsigned char uch;
|
||||||
|
typedef unsigned short ush;
|
||||||
|
typedef unsigned long ulg;
|
||||||
|
|
||||||
|
|
||||||
|
/* prototypes for public functions in readpng.c */
|
||||||
|
|
||||||
|
void readpng_version_info(void);
|
||||||
|
|
||||||
|
int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight);
|
||||||
|
|
||||||
|
int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue);
|
||||||
|
|
||||||
|
uch *readpng_get_image(double display_exponent, int *pChannels,
|
||||||
|
ulg *pRowbytes);
|
||||||
|
|
||||||
|
void readpng_cleanup(int free_image_data);
|
||||||
648
contrib/gregbook/readpng2.c
Normal file
@@ -0,0 +1,648 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rpng2 - progressive-model PNG display program readpng2.c
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h> /* for exit() prototype */
|
||||||
|
|
||||||
|
#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
|
||||||
|
#include "readpng2.h" /* typedefs, common macros, public prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
/* local prototypes */
|
||||||
|
|
||||||
|
static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr);
|
||||||
|
static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
|
||||||
|
png_uint_32 row_num, int pass);
|
||||||
|
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
|
||||||
|
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void readpng2_version_info(void)
|
||||||
|
{
|
||||||
|
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \
|
||||||
|
(defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \
|
||||||
|
defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
|
||||||
|
/*
|
||||||
|
* WARNING: This preprocessor approach means that the following code
|
||||||
|
* cannot be used with a libpng DLL older than 1.2.0--the
|
||||||
|
* compiled-in symbols for the new functions will not exist.
|
||||||
|
* (Could use dlopen() and dlsym() on Unix and corresponding
|
||||||
|
* calls for Windows, but not portable...)
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
int mmxsupport = png_mmx_support();
|
||||||
|
if (mmxsupport < 0)
|
||||||
|
fprintf(stderr, " Compiled with libpng %s; using libpng %s "
|
||||||
|
"without MMX support.\n", PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||||
|
else {
|
||||||
|
int compilerID;
|
||||||
|
png_uint_32 mmx_mask = png_get_mmx_flagmask(
|
||||||
|
PNG_SELECT_READ | PNG_SELECT_WRITE, &compilerID);
|
||||||
|
|
||||||
|
fprintf(stderr, " Compiled with libpng %s; using libpng %s "
|
||||||
|
"with MMX support\n (%s version).", PNG_LIBPNG_VER_STRING,
|
||||||
|
png_libpng_ver, compilerID == 1? "MSVC++" :
|
||||||
|
(compilerID == 2? "GNU C" : "unknown"));
|
||||||
|
fprintf(stderr, " Processor (x86%s) %s MMX instructions.\n",
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
"_64",
|
||||||
|
#else
|
||||||
|
"",
|
||||||
|
#endif
|
||||||
|
mmxsupport? "supports" : "does not support");
|
||||||
|
if (mmxsupport > 0) {
|
||||||
|
int num_optims = 0;
|
||||||
|
|
||||||
|
fprintf(stderr,
|
||||||
|
" Potential MMX optimizations supported by libpng:\n");
|
||||||
|
if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)
|
||||||
|
++num_optims;
|
||||||
|
if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_UP)
|
||||||
|
++num_optims;
|
||||||
|
if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)
|
||||||
|
++num_optims;
|
||||||
|
if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)
|
||||||
|
++num_optims;
|
||||||
|
if (num_optims)
|
||||||
|
fprintf(stderr,
|
||||||
|
" decoding %s row filters (reading)\n",
|
||||||
|
(num_optims == 4)? "all non-trivial" : "some");
|
||||||
|
if (mmx_mask & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW) {
|
||||||
|
fprintf(stderr, " combining rows (reading)\n");
|
||||||
|
++num_optims;
|
||||||
|
}
|
||||||
|
if (mmx_mask & PNG_ASM_FLAG_MMX_READ_INTERLACE) {
|
||||||
|
fprintf(stderr,
|
||||||
|
" expanding interlacing (reading)\n");
|
||||||
|
++num_optims;
|
||||||
|
}
|
||||||
|
mmx_mask &= ~( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_INTERLACE \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_UP \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );
|
||||||
|
if (mmx_mask) {
|
||||||
|
fprintf(stderr, " other (unknown)\n");
|
||||||
|
++num_optims;
|
||||||
|
}
|
||||||
|
if (num_optims == 0)
|
||||||
|
fprintf(stderr, " (none)\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
fprintf(stderr, " Compiled with libpng %s; using libpng %s "
|
||||||
|
"without MMX support.\n", PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||||
|
ZLIB_VERSION, zlib_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int readpng2_check_sig(uch *sig, int num)
|
||||||
|
{
|
||||||
|
return !png_sig_cmp(sig, 0, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 for success, 2 for libpng problem, 4 for out of memory */
|
||||||
|
|
||||||
|
int readpng2_init(mainprog_info *mainprog_ptr)
|
||||||
|
{
|
||||||
|
png_structp png_ptr; /* note: temporary variables! */
|
||||||
|
png_infop info_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* could also replace libpng warning-handler (final NULL), but no need: */
|
||||||
|
|
||||||
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
|
||||||
|
readpng2_error_handler, NULL);
|
||||||
|
if (!png_ptr)
|
||||||
|
return 4; /* out of memory */
|
||||||
|
|
||||||
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
if (!info_ptr) {
|
||||||
|
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||||
|
return 4; /* out of memory */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* we could create a second info struct here (end_info), but it's only
|
||||||
|
* useful if we want to keep pre- and post-IDAT chunk info separated
|
||||||
|
* (mainly for PNG-aware image editors and converters) */
|
||||||
|
|
||||||
|
|
||||||
|
/* setjmp() must be called in every function that calls a PNG-reading
|
||||||
|
* libpng function, unless an alternate error handler was installed--
|
||||||
|
* but compatible error handlers must either use longjmp() themselves
|
||||||
|
* (as in this program) or exit immediately, so here we are: */
|
||||||
|
|
||||||
|
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
|
||||||
|
/* prepare the reader to ignore all recognized chunks whose data won't be
|
||||||
|
* used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT,
|
||||||
|
* IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */
|
||||||
|
{
|
||||||
|
/* These byte strings were copied from png.h. If a future libpng
|
||||||
|
* version recognizes more chunks, add them to this list. If a
|
||||||
|
* future version of readpng2.c recognizes more chunks, delete them
|
||||||
|
* from this list. */
|
||||||
|
static const png_byte chunks_to_ignore[] = {
|
||||||
|
99, 72, 82, 77, '\0', /* cHRM */
|
||||||
|
104, 73, 83, 84, '\0', /* hIST */
|
||||||
|
105, 67, 67, 80, '\0', /* iCCP */
|
||||||
|
105, 84, 88, 116, '\0', /* iTXt */
|
||||||
|
111, 70, 70, 115, '\0', /* oFFs */
|
||||||
|
112, 67, 65, 76, '\0', /* pCAL */
|
||||||
|
112, 72, 89, 115, '\0', /* pHYs */
|
||||||
|
115, 66, 73, 84, '\0', /* sBIT */
|
||||||
|
115, 67, 65, 76, '\0', /* sCAL */
|
||||||
|
115, 80, 76, 84, '\0', /* sPLT */
|
||||||
|
115, 84, 69, 82, '\0', /* sTER */
|
||||||
|
116, 69, 88, 116, '\0', /* tEXt */
|
||||||
|
116, 73, 77, 69, '\0', /* tIME */
|
||||||
|
122, 84, 88, 116, '\0' /* zTXt */
|
||||||
|
};
|
||||||
|
|
||||||
|
png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
|
||||||
|
chunks_to_ignore, sizeof(chunks_to_ignore)/5);
|
||||||
|
}
|
||||||
|
#endif /* PNG_UNKNOWN_CHUNKS_SUPPORTED */
|
||||||
|
|
||||||
|
|
||||||
|
/* instead of doing png_init_io() here, now we set up our callback
|
||||||
|
* functions for progressive decoding */
|
||||||
|
|
||||||
|
png_set_progressive_read_fn(png_ptr, mainprog_ptr,
|
||||||
|
readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* may as well enable or disable MMX routines here, if supported;
|
||||||
|
*
|
||||||
|
* to enable all: mask = png_get_mmx_flagmask (
|
||||||
|
* PNG_SELECT_READ | PNG_SELECT_WRITE, &compilerID);
|
||||||
|
* flags = png_get_asm_flags (png_ptr);
|
||||||
|
* flags |= mask;
|
||||||
|
* png_set_asm_flags (png_ptr, flags);
|
||||||
|
*
|
||||||
|
* to disable all: mask = png_get_mmx_flagmask (
|
||||||
|
* PNG_SELECT_READ | PNG_SELECT_WRITE, &compilerID);
|
||||||
|
* flags = png_get_asm_flags (png_ptr);
|
||||||
|
* flags &= ~mask;
|
||||||
|
* png_set_asm_flags (png_ptr, flags);
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \
|
||||||
|
defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
|
||||||
|
/*
|
||||||
|
* WARNING: This preprocessor approach means that the following code
|
||||||
|
* cannot be used with a libpng DLL older than 1.2.0--the
|
||||||
|
* compiled-in symbols for the new functions will not exist.
|
||||||
|
* (Could use dlopen() and dlsym() on Unix and corresponding
|
||||||
|
* calls for Windows, but not portable...)
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
|
||||||
|
png_uint_32 mmx_disable_mask = 0;
|
||||||
|
png_uint_32 asm_flags, mmx_mask;
|
||||||
|
int compilerID;
|
||||||
|
|
||||||
|
if (mainprog_ptr->nommxfilters)
|
||||||
|
mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_UP \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );
|
||||||
|
if (mainprog_ptr->nommxcombine)
|
||||||
|
mmx_disable_mask |= PNG_ASM_FLAG_MMX_READ_COMBINE_ROW;
|
||||||
|
if (mainprog_ptr->nommxinterlace)
|
||||||
|
mmx_disable_mask |= PNG_ASM_FLAG_MMX_READ_INTERLACE;
|
||||||
|
asm_flags = png_get_asm_flags(png_ptr);
|
||||||
|
png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask);
|
||||||
|
|
||||||
|
|
||||||
|
/* Now query libpng's asm settings, just for yuks. Note that this
|
||||||
|
* differs from the querying of its *potential* MMX capabilities
|
||||||
|
* in readpng2_version_info(); this is true runtime verification. */
|
||||||
|
|
||||||
|
asm_flags = png_get_asm_flags(png_ptr);
|
||||||
|
mmx_mask = png_get_mmx_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE,
|
||||||
|
&compilerID);
|
||||||
|
if (asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED)
|
||||||
|
fprintf(stderr,
|
||||||
|
" MMX support (%s version) is compiled into libpng\n",
|
||||||
|
compilerID == 1? "MSVC++" :
|
||||||
|
(compilerID == 2? "GNU C" : "unknown"));
|
||||||
|
else
|
||||||
|
fprintf(stderr, " MMX support is not compiled into libpng\n");
|
||||||
|
fprintf(stderr, " MMX instructions are %ssupported by CPU\n",
|
||||||
|
(asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU)? "" : "not ");
|
||||||
|
fprintf(stderr, " MMX read support for combining rows is %sabled\n",
|
||||||
|
(asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)? "en" : "dis");
|
||||||
|
fprintf(stderr,
|
||||||
|
" MMX read support for expanding interlacing is %sabled\n",
|
||||||
|
(asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)? "en" : "dis");
|
||||||
|
fprintf(stderr, " MMX read support for \"sub\" filter is %sabled\n",
|
||||||
|
(asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "en" : "dis");
|
||||||
|
fprintf(stderr, " MMX read support for \"up\" filter is %sabled\n",
|
||||||
|
(asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "en" : "dis");
|
||||||
|
fprintf(stderr, " MMX read support for \"avg\" filter is %sabled\n",
|
||||||
|
(asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "en" : "dis");
|
||||||
|
fprintf(stderr, " MMX read support for \"Paeth\" filter is %sabled\n",
|
||||||
|
(asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "en" : "dis");
|
||||||
|
asm_flags &= (mmx_mask & ~( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_INTERLACE \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_UP \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
|
||||||
|
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ));
|
||||||
|
if (asm_flags)
|
||||||
|
fprintf(stderr,
|
||||||
|
" additional MMX support is also enabled (0x%02lx)\n",
|
||||||
|
asm_flags);
|
||||||
|
#else /* !PNG_ASSEMBLER_CODE_SUPPORTED */
|
||||||
|
fprintf(stderr, " MMX querying is disabled in libpng.\n");
|
||||||
|
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* make sure we save our pointers for use in readpng2_decode_data() */
|
||||||
|
|
||||||
|
mainprog_ptr->png_ptr = png_ptr;
|
||||||
|
mainprog_ptr->info_ptr = info_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* and that's all there is to initialization */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 for success, 2 for libpng (longjmp) problem */
|
||||||
|
|
||||||
|
int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)
|
||||||
|
{
|
||||||
|
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||||
|
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* setjmp() must be called in every function that calls a PNG-reading
|
||||||
|
* libpng function */
|
||||||
|
|
||||||
|
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
mainprog_ptr->png_ptr = NULL;
|
||||||
|
mainprog_ptr->info_ptr = NULL;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* hand off the next chunk of input data to libpng for decoding */
|
||||||
|
|
||||||
|
png_process_data(png_ptr, info_ptr, rawbuf, length);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
|
||||||
|
{
|
||||||
|
mainprog_info *mainprog_ptr;
|
||||||
|
int color_type, bit_depth;
|
||||||
|
png_uint_32 width, height;
|
||||||
|
double gamma;
|
||||||
|
|
||||||
|
|
||||||
|
/* setjmp() doesn't make sense here, because we'd either have to exit(),
|
||||||
|
* longjmp() ourselves, or return control to libpng, which doesn't want
|
||||||
|
* to see us again. By not doing anything here, libpng will instead jump
|
||||||
|
* to readpng2_decode_data(), which can return an error value to the main
|
||||||
|
* program. */
|
||||||
|
|
||||||
|
|
||||||
|
/* retrieve the pointer to our special-purpose struct, using the png_ptr
|
||||||
|
* that libpng passed back to us (i.e., not a global this time--there's
|
||||||
|
* no real difference for a single image, but for a multithreaded browser
|
||||||
|
* decoding several PNG images at the same time, one needs to avoid mixing
|
||||||
|
* up different images' structs) */
|
||||||
|
|
||||||
|
mainprog_ptr = png_get_progressive_ptr(png_ptr);
|
||||||
|
|
||||||
|
if (mainprog_ptr == NULL) { /* we be hosed */
|
||||||
|
fprintf(stderr,
|
||||||
|
"readpng2 error: main struct not recoverable in info_callback.\n");
|
||||||
|
fflush(stderr);
|
||||||
|
return;
|
||||||
|
/*
|
||||||
|
* Alternatively, we could call our error-handler just like libpng
|
||||||
|
* does, which would effectively terminate the program. Since this
|
||||||
|
* can only happen if png_ptr gets redirected somewhere odd or the
|
||||||
|
* main PNG struct gets wiped, we're probably toast anyway. (If
|
||||||
|
* png_ptr itself is NULL, we would not have been called.)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* this is just like in the non-progressive case */
|
||||||
|
|
||||||
|
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
mainprog_ptr->width = (ulg)width;
|
||||||
|
mainprog_ptr->height = (ulg)height;
|
||||||
|
|
||||||
|
|
||||||
|
/* since we know we've read all of the PNG file's "header" (i.e., up
|
||||||
|
* to IDAT), we can check for a background color here */
|
||||||
|
|
||||||
|
if (mainprog_ptr->need_bgcolor &&
|
||||||
|
png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
|
||||||
|
{
|
||||||
|
png_color_16p pBackground;
|
||||||
|
|
||||||
|
/* it is not obvious from the libpng documentation, but this function
|
||||||
|
* takes a pointer to a pointer, and it always returns valid red,
|
||||||
|
* green and blue values, regardless of color_type: */
|
||||||
|
png_get_bKGD(png_ptr, info_ptr, &pBackground);
|
||||||
|
|
||||||
|
/* however, it always returns the raw bKGD data, regardless of any
|
||||||
|
* bit-depth transformations, so check depth and adjust if necessary */
|
||||||
|
if (bit_depth == 16) {
|
||||||
|
mainprog_ptr->bg_red = pBackground->red >> 8;
|
||||||
|
mainprog_ptr->bg_green = pBackground->green >> 8;
|
||||||
|
mainprog_ptr->bg_blue = pBackground->blue >> 8;
|
||||||
|
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
|
||||||
|
if (bit_depth == 1)
|
||||||
|
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
|
||||||
|
mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
|
||||||
|
else if (bit_depth == 2)
|
||||||
|
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
|
||||||
|
mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
|
||||||
|
else /* bit_depth == 4 */
|
||||||
|
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
|
||||||
|
mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
|
||||||
|
} else {
|
||||||
|
mainprog_ptr->bg_red = (uch)pBackground->red;
|
||||||
|
mainprog_ptr->bg_green = (uch)pBackground->green;
|
||||||
|
mainprog_ptr->bg_blue = (uch)pBackground->blue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* as before, let libpng expand palette images to RGB, low-bit-depth
|
||||||
|
* grayscale images to 8 bits, transparency chunks to full alpha channel;
|
||||||
|
* strip 16-bit-per-sample images to 8 bits per sample; and convert
|
||||||
|
* grayscale to RGB[A] */
|
||||||
|
|
||||||
|
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (bit_depth == 16)
|
||||||
|
png_set_strip_16(png_ptr);
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||||
|
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
png_set_gray_to_rgb(png_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/* Unlike the basic viewer, which was designed to operate on local files,
|
||||||
|
* this program is intended to simulate a web browser--even though we
|
||||||
|
* actually read from a local file, too. But because we are pretending
|
||||||
|
* that most of the images originate on the Internet, we follow the recom-
|
||||||
|
* mendation of the sRGB proposal and treat unlabelled images (no gAMA
|
||||||
|
* chunk) as existing in the sRGB color space. That is, we assume that
|
||||||
|
* such images have a file gamma of 0.45455, which corresponds to a PC-like
|
||||||
|
* display system. This change in assumptions will have no effect on a
|
||||||
|
* PC-like system, but on a Mac, SGI, NeXT or other system with a non-
|
||||||
|
* identity lookup table, it will darken unlabelled images, which effec-
|
||||||
|
* tively favors images from PC-like systems over those originating on
|
||||||
|
* the local platform. Note that mainprog_ptr->display_exponent is the
|
||||||
|
* "gamma" value for the entire display system, i.e., the product of
|
||||||
|
* LUT_exponent and CRT_exponent. */
|
||||||
|
|
||||||
|
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
|
||||||
|
png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma);
|
||||||
|
else
|
||||||
|
png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455);
|
||||||
|
|
||||||
|
|
||||||
|
/* we'll let libpng expand interlaced images, too */
|
||||||
|
|
||||||
|
mainprog_ptr->passes = png_set_interlace_handling(png_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/* all transformations have been registered; now update info_ptr data and
|
||||||
|
* then get rowbytes and channels */
|
||||||
|
|
||||||
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr);
|
||||||
|
mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/* Call the main program to allocate memory for the image buffer and
|
||||||
|
* initialize windows and whatnot. (The old-style function-pointer
|
||||||
|
* invocation is used for compatibility with a few supposedly ANSI
|
||||||
|
* compilers that nevertheless barf on "fn_ptr()"-style syntax.) */
|
||||||
|
|
||||||
|
(*mainprog_ptr->mainprog_init)();
|
||||||
|
|
||||||
|
|
||||||
|
/* and that takes care of initialization */
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
|
||||||
|
png_uint_32 row_num, int pass)
|
||||||
|
{
|
||||||
|
mainprog_info *mainprog_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* first check whether the row differs from the previous pass; if not,
|
||||||
|
* nothing to combine or display */
|
||||||
|
|
||||||
|
if (!new_row)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
/* retrieve the pointer to our special-purpose struct so we can access
|
||||||
|
* the old rows and image-display callback function */
|
||||||
|
|
||||||
|
mainprog_ptr = png_get_progressive_ptr(png_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/* save the pass number for optional use by the front end */
|
||||||
|
|
||||||
|
mainprog_ptr->pass = pass;
|
||||||
|
|
||||||
|
|
||||||
|
/* have libpng either combine the new row data with the existing row data
|
||||||
|
* from previous passes (if interlaced) or else just copy the new row
|
||||||
|
* into the main program's image buffer */
|
||||||
|
|
||||||
|
png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num],
|
||||||
|
new_row);
|
||||||
|
|
||||||
|
|
||||||
|
/* finally, call the display routine in the main program with the number
|
||||||
|
* of the row we just updated */
|
||||||
|
|
||||||
|
(*mainprog_ptr->mainprog_display_row)(row_num);
|
||||||
|
|
||||||
|
|
||||||
|
/* and we're ready for more */
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
|
||||||
|
{
|
||||||
|
mainprog_info *mainprog_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* retrieve the pointer to our special-purpose struct */
|
||||||
|
|
||||||
|
mainprog_ptr = png_get_progressive_ptr(png_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/* let the main program know that it should flush any buffered image
|
||||||
|
* data to the display now and set a "done" flag or whatever, but note
|
||||||
|
* that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do
|
||||||
|
* NOT call readpng2_cleanup() either here or in the finish_display()
|
||||||
|
* routine; wait until control returns to the main program via
|
||||||
|
* readpng2_decode_data() */
|
||||||
|
|
||||||
|
(*mainprog_ptr->mainprog_finish_display)();
|
||||||
|
|
||||||
|
|
||||||
|
/* all done */
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void readpng2_cleanup(mainprog_info *mainprog_ptr)
|
||||||
|
{
|
||||||
|
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||||
|
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||||
|
|
||||||
|
if (png_ptr && info_ptr)
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
|
||||||
|
mainprog_ptr->png_ptr = NULL;
|
||||||
|
mainprog_ptr->info_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
|
||||||
|
{
|
||||||
|
mainprog_info *mainprog_ptr;
|
||||||
|
|
||||||
|
/* This function, aside from the extra step of retrieving the "error
|
||||||
|
* pointer" (below) and the fact that it exists within the application
|
||||||
|
* rather than within libpng, is essentially identical to libpng's
|
||||||
|
* default error handler. The second point is critical: since both
|
||||||
|
* setjmp() and longjmp() are called from the same code, they are
|
||||||
|
* guaranteed to have compatible notions of how big a jmp_buf is,
|
||||||
|
* regardless of whether _BSD_SOURCE or anything else has (or has not)
|
||||||
|
* been defined. */
|
||||||
|
|
||||||
|
fprintf(stderr, "readpng2 libpng error: %s\n", msg);
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
|
mainprog_ptr = png_get_error_ptr(png_ptr);
|
||||||
|
if (mainprog_ptr == NULL) { /* we are completely hosed now */
|
||||||
|
fprintf(stderr,
|
||||||
|
"readpng2 severe error: jmpbuf not recoverable; terminating.\n");
|
||||||
|
fflush(stderr);
|
||||||
|
exit(99);
|
||||||
|
}
|
||||||
|
|
||||||
|
longjmp(mainprog_ptr->jmpbuf, 1);
|
||||||
|
}
|
||||||
121
contrib/gregbook/readpng2.h
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rpng2 - progressive-model PNG display program readpng2.h
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
# define TRUE 1
|
||||||
|
# define FALSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
# define MAX(a,b) ((a) > (b)? (a) : (b))
|
||||||
|
# define MIN(a,b) ((a) < (b)? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
|
||||||
|
#else
|
||||||
|
# define Trace(x) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum rpng2_states {
|
||||||
|
kPreInit = 0,
|
||||||
|
kWindowInit,
|
||||||
|
kDone
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef unsigned char uch;
|
||||||
|
typedef unsigned short ush;
|
||||||
|
typedef unsigned long ulg;
|
||||||
|
|
||||||
|
typedef struct _mainprog_info {
|
||||||
|
double display_exponent;
|
||||||
|
ulg width;
|
||||||
|
ulg height;
|
||||||
|
void *png_ptr;
|
||||||
|
void *info_ptr;
|
||||||
|
void (*mainprog_init)(void);
|
||||||
|
void (*mainprog_display_row)(ulg row_num);
|
||||||
|
void (*mainprog_finish_display)(void);
|
||||||
|
uch *image_data;
|
||||||
|
uch **row_pointers;
|
||||||
|
jmp_buf jmpbuf;
|
||||||
|
int passes; /* not used */
|
||||||
|
int pass;
|
||||||
|
int rowbytes;
|
||||||
|
int channels;
|
||||||
|
int need_bgcolor;
|
||||||
|
#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__))
|
||||||
|
int nommxfilters;
|
||||||
|
int nommxcombine;
|
||||||
|
int nommxinterlace;
|
||||||
|
#endif
|
||||||
|
int state;
|
||||||
|
uch bg_red;
|
||||||
|
uch bg_green;
|
||||||
|
uch bg_blue;
|
||||||
|
} mainprog_info;
|
||||||
|
|
||||||
|
|
||||||
|
/* prototypes for public functions in readpng2.c */
|
||||||
|
|
||||||
|
void readpng2_version_info(void);
|
||||||
|
|
||||||
|
int readpng2_check_sig(uch *sig, int num);
|
||||||
|
|
||||||
|
int readpng2_init(mainprog_info *mainprog_ptr);
|
||||||
|
|
||||||
|
int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length);
|
||||||
|
|
||||||
|
void readpng2_cleanup(mainprog_info *mainprog_ptr);
|
||||||
179
contrib/gregbook/readppm.c
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rpng - simple PNG display program readppm.c
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is a special-purpose replacement for readpng.c that allows binary
|
||||||
|
PPM files to be used in place of PNG images.
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "readpng.h" /* typedefs, common macros, public prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
ulg width, height;
|
||||||
|
int bit_depth, color_type, channels;
|
||||||
|
uch *image_data = NULL;
|
||||||
|
FILE *saved_infile;
|
||||||
|
|
||||||
|
|
||||||
|
void readpng_version_info()
|
||||||
|
{
|
||||||
|
fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
|
||||||
|
|
||||||
|
int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
|
||||||
|
{
|
||||||
|
static uch ppmline[256];
|
||||||
|
int maxval;
|
||||||
|
|
||||||
|
|
||||||
|
saved_infile = infile;
|
||||||
|
|
||||||
|
fgets(ppmline, 256, infile);
|
||||||
|
if (ppmline[0] != 'P' || ppmline[1] != '6') {
|
||||||
|
fprintf(stderr, "ERROR: not a PPM file\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */
|
||||||
|
if (ppmline[1] == '6') {
|
||||||
|
color_type = 2;
|
||||||
|
channels = 3;
|
||||||
|
} else if (ppmline[1] == '8') {
|
||||||
|
color_type = 6;
|
||||||
|
channels = 4;
|
||||||
|
} else /* if (ppmline[1] == '5') */ {
|
||||||
|
color_type = 0;
|
||||||
|
channels = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
fgets(ppmline, 256, infile);
|
||||||
|
} while (ppmline[0] == '#');
|
||||||
|
sscanf(ppmline, "%lu %lu", &width, &height);
|
||||||
|
|
||||||
|
do {
|
||||||
|
fgets(ppmline, 256, infile);
|
||||||
|
} while (ppmline[0] == '#');
|
||||||
|
sscanf(ppmline, "%d", &maxval);
|
||||||
|
if (maxval != 255) {
|
||||||
|
fprintf(stderr, "ERROR: maxval = %d\n", maxval);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
bit_depth = 8;
|
||||||
|
|
||||||
|
*pWidth = width;
|
||||||
|
*pHeight = height;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
|
||||||
|
* scales values to 8-bit if necessary */
|
||||||
|
|
||||||
|
int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* display_exponent == LUT_exponent * CRT_exponent */
|
||||||
|
|
||||||
|
uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
|
||||||
|
{
|
||||||
|
ulg rowbytes;
|
||||||
|
|
||||||
|
|
||||||
|
/* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
|
||||||
|
* transparency chunks to full alpha channel; strip 16-bit-per-sample
|
||||||
|
* images to 8 bits per sample; and convert grayscale to RGB[A] */
|
||||||
|
|
||||||
|
/* GRR WARNING: grayscale needs to be expanded and channels reset! */
|
||||||
|
|
||||||
|
*pRowbytes = rowbytes = channels*width;
|
||||||
|
*pChannels = channels;
|
||||||
|
|
||||||
|
if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
|
||||||
|
|
||||||
|
|
||||||
|
/* now we can go ahead and just read the whole image */
|
||||||
|
|
||||||
|
fread(image_data, 1L, rowbytes*height, saved_infile);
|
||||||
|
|
||||||
|
|
||||||
|
return image_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void readpng_cleanup(int free_image_data)
|
||||||
|
{
|
||||||
|
if (free_image_data && image_data) {
|
||||||
|
free(image_data);
|
||||||
|
image_data = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
684
contrib/gregbook/rpng-win.c
Normal file
@@ -0,0 +1,684 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rpng - simple PNG display program rpng-win.c
|
||||||
|
|
||||||
|
This program decodes and displays PNG images, with gamma correction and
|
||||||
|
optionally with a user-specified background color (in case the image has
|
||||||
|
transparency). It is very nearly the most basic PNG viewer possible.
|
||||||
|
This version is for 32-bit Windows; it may compile under 16-bit Windows
|
||||||
|
with a little tweaking (or maybe not).
|
||||||
|
|
||||||
|
to do:
|
||||||
|
- handle quoted command-line args (especially filenames with spaces)
|
||||||
|
- have minimum window width: oh well
|
||||||
|
- use %.1023s to simplify truncation of title-bar string?
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Changelog:
|
||||||
|
- 1.00: initial public release
|
||||||
|
- 1.01: modified to allow abbreviated options; fixed long/ulong mis-
|
||||||
|
match; switched to png_jmpbuf() macro
|
||||||
|
- 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed
|
||||||
|
command-line parsing bug
|
||||||
|
- 1.10: enabled "message window"/console (thanks to David Geldreich)
|
||||||
|
- 2.00: dual-licensed (added GNU GPL)
|
||||||
|
- 2.01: fixed improper display of usage screen on PNG error(s)
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define PROGNAME "rpng-win"
|
||||||
|
#define LONGNAME "Simple PNG Viewer for Windows"
|
||||||
|
#define VERSION "2.01 of 16 March 2008"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <conio.h> /* only for _getch() */
|
||||||
|
|
||||||
|
/* #define DEBUG : this enables the Trace() macros */
|
||||||
|
|
||||||
|
#include "readpng.h" /* typedefs, common macros, readpng prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
/* could just include png.h, but this macro is the only thing we need
|
||||||
|
* (name and typedefs changed to local versions); note that side effects
|
||||||
|
* only happen with alpha (which could easily be avoided with
|
||||||
|
* "ush acopy = (alpha);") */
|
||||||
|
|
||||||
|
#define alpha_composite(composite, fg, alpha, bg) { \
|
||||||
|
ush temp = ((ush)(fg)*(ush)(alpha) + \
|
||||||
|
(ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
|
||||||
|
(composite) = (uch)((temp + (temp >> 8)) >> 8); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* local prototypes */
|
||||||
|
static int rpng_win_create_window(HINSTANCE hInst, int showmode);
|
||||||
|
static int rpng_win_display_image(void);
|
||||||
|
static void rpng_win_cleanup(void);
|
||||||
|
LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
|
||||||
|
|
||||||
|
static char titlebar[1024];
|
||||||
|
static char *progname = PROGNAME;
|
||||||
|
static char *appname = LONGNAME;
|
||||||
|
static char *filename;
|
||||||
|
static FILE *infile;
|
||||||
|
|
||||||
|
static char *bgstr;
|
||||||
|
static uch bg_red=0, bg_green=0, bg_blue=0;
|
||||||
|
|
||||||
|
static double display_exponent;
|
||||||
|
|
||||||
|
static ulg image_width, image_height, image_rowbytes;
|
||||||
|
static int image_channels;
|
||||||
|
static uch *image_data;
|
||||||
|
|
||||||
|
/* Windows-specific variables */
|
||||||
|
static ulg wimage_rowbytes;
|
||||||
|
static uch *dib;
|
||||||
|
static uch *wimage_data;
|
||||||
|
static BITMAPINFOHEADER *bmih;
|
||||||
|
|
||||||
|
static HWND global_hwnd;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||||
|
{
|
||||||
|
char *args[1024]; /* arbitrary limit, but should suffice */
|
||||||
|
char *p, *q, **argv = args;
|
||||||
|
int argc = 0;
|
||||||
|
int rc, alen, flen;
|
||||||
|
int error = 0;
|
||||||
|
int have_bg = FALSE;
|
||||||
|
double LUT_exponent; /* just the lookup table */
|
||||||
|
double CRT_exponent = 2.2; /* just the monitor */
|
||||||
|
double default_display_exponent; /* whole display system */
|
||||||
|
MSG msg;
|
||||||
|
|
||||||
|
|
||||||
|
filename = (char *)NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/* First reenable console output, which normally goes to the bit bucket
|
||||||
|
* for windowed apps. Closing the console window will terminate the
|
||||||
|
* app. Thanks to David.Geldreich@realviz.com for supplying the magical
|
||||||
|
* incantation. */
|
||||||
|
|
||||||
|
AllocConsole();
|
||||||
|
freopen("CONOUT$", "a", stderr);
|
||||||
|
freopen("CONOUT$", "a", stdout);
|
||||||
|
|
||||||
|
|
||||||
|
/* Next set the default value for our display-system exponent, i.e.,
|
||||||
|
* the product of the CRT exponent and the exponent corresponding to
|
||||||
|
* the frame-buffer's lookup table (LUT), if any. This is not an
|
||||||
|
* exhaustive list of LUT values (e.g., OpenStep has a lot of weird
|
||||||
|
* ones), but it should cover 99% of the current possibilities. And
|
||||||
|
* yes, these ifdefs are completely wasted in a Windows program... */
|
||||||
|
|
||||||
|
#if defined(NeXT)
|
||||||
|
LUT_exponent = 1.0 / 2.2;
|
||||||
|
/*
|
||||||
|
if (some_next_function_that_returns_gamma(&next_gamma))
|
||||||
|
LUT_exponent = 1.0 / next_gamma;
|
||||||
|
*/
|
||||||
|
#elif defined(sgi)
|
||||||
|
LUT_exponent = 1.0 / 1.7;
|
||||||
|
/* there doesn't seem to be any documented function to get the
|
||||||
|
* "gamma" value, so we do it the hard way */
|
||||||
|
infile = fopen("/etc/config/system.glGammaVal", "r");
|
||||||
|
if (infile) {
|
||||||
|
double sgi_gamma;
|
||||||
|
|
||||||
|
fgets(tmpline, 80, infile);
|
||||||
|
fclose(infile);
|
||||||
|
sgi_gamma = atof(tmpline);
|
||||||
|
if (sgi_gamma > 0.0)
|
||||||
|
LUT_exponent = 1.0 / sgi_gamma;
|
||||||
|
}
|
||||||
|
#elif defined(Macintosh)
|
||||||
|
LUT_exponent = 1.8 / 2.61;
|
||||||
|
/*
|
||||||
|
if (some_mac_function_that_returns_gamma(&mac_gamma))
|
||||||
|
LUT_exponent = mac_gamma / 2.61;
|
||||||
|
*/
|
||||||
|
#else
|
||||||
|
LUT_exponent = 1.0; /* assume no LUT: most PCs */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
|
||||||
|
default_display_exponent = LUT_exponent * CRT_exponent;
|
||||||
|
|
||||||
|
|
||||||
|
/* If the user has set the SCREEN_GAMMA environment variable as suggested
|
||||||
|
* (somewhat imprecisely) in the libpng documentation, use that; otherwise
|
||||||
|
* use the default value we just calculated. Either way, the user may
|
||||||
|
* override this via a command-line option. */
|
||||||
|
|
||||||
|
if ((p = getenv("SCREEN_GAMMA")) != NULL)
|
||||||
|
display_exponent = atof(p);
|
||||||
|
else
|
||||||
|
display_exponent = default_display_exponent;
|
||||||
|
|
||||||
|
|
||||||
|
/* Windows really hates command lines, so we have to set up our own argv.
|
||||||
|
* Note that we do NOT bother with quoted arguments here, so don't use
|
||||||
|
* filenames with spaces in 'em! */
|
||||||
|
|
||||||
|
argv[argc++] = PROGNAME;
|
||||||
|
p = cmd;
|
||||||
|
for (;;) {
|
||||||
|
if (*p == ' ')
|
||||||
|
while (*++p == ' ')
|
||||||
|
;
|
||||||
|
/* now p points at the first non-space after some spaces */
|
||||||
|
if (*p == '\0')
|
||||||
|
break; /* nothing after the spaces: done */
|
||||||
|
argv[argc++] = q = p;
|
||||||
|
while (*q && *q != ' ')
|
||||||
|
++q;
|
||||||
|
/* now q points at a space or the end of the string */
|
||||||
|
if (*q == '\0')
|
||||||
|
break; /* last argv already terminated; quit */
|
||||||
|
*q = '\0'; /* change space to terminator */
|
||||||
|
p = q + 1;
|
||||||
|
}
|
||||||
|
argv[argc] = NULL; /* terminate the argv array itself */
|
||||||
|
|
||||||
|
|
||||||
|
/* Now parse the command line for options and the PNG filename. */
|
||||||
|
|
||||||
|
while (*++argv && !error) {
|
||||||
|
if (!strncmp(*argv, "-gamma", 2)) {
|
||||||
|
if (!*++argv)
|
||||||
|
++error;
|
||||||
|
else {
|
||||||
|
display_exponent = atof(*argv);
|
||||||
|
if (display_exponent <= 0.0)
|
||||||
|
++error;
|
||||||
|
}
|
||||||
|
} else if (!strncmp(*argv, "-bgcolor", 2)) {
|
||||||
|
if (!*++argv)
|
||||||
|
++error;
|
||||||
|
else {
|
||||||
|
bgstr = *argv;
|
||||||
|
if (strlen(bgstr) != 7 || bgstr[0] != '#')
|
||||||
|
++error;
|
||||||
|
else
|
||||||
|
have_bg = TRUE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (**argv != '-') {
|
||||||
|
filename = *argv;
|
||||||
|
if (argv[1]) /* shouldn't be any more args after filename */
|
||||||
|
++error;
|
||||||
|
} else
|
||||||
|
++error; /* not expecting any other options */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filename)
|
||||||
|
++error;
|
||||||
|
|
||||||
|
|
||||||
|
/* print usage screen if any errors up to this point */
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
|
||||||
|
readpng_version_info();
|
||||||
|
fprintf(stderr, "\n"
|
||||||
|
"Usage: %s [-gamma exp] [-bgcolor bg] file.png\n"
|
||||||
|
" exp \ttransfer-function exponent (``gamma'') of the display\n"
|
||||||
|
"\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
|
||||||
|
"\t\t to the product of the lookup-table exponent (varies)\n"
|
||||||
|
"\t\t and the CRT exponent (usually 2.2); must be positive\n"
|
||||||
|
" bg \tdesired background color in 7-character hex RGB format\n"
|
||||||
|
"\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
|
||||||
|
"\t\t used with transparent images\n"
|
||||||
|
"\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
|
||||||
|
"Press Q or Esc to quit this usage screen.\n"
|
||||||
|
"\n", PROGNAME, default_display_exponent);
|
||||||
|
do
|
||||||
|
ch = _getch();
|
||||||
|
while (ch != 'q' && ch != 'Q' && ch != 0x1B);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!(infile = fopen(filename, "rb"))) {
|
||||||
|
fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
|
||||||
|
++error;
|
||||||
|
} else {
|
||||||
|
if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
|
||||||
|
switch (rc) {
|
||||||
|
case 1:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": [%s] is not a PNG file: incorrect signature\n",
|
||||||
|
filename);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": [%s] has bad IHDR (libpng longjmp)\n", filename);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
fprintf(stderr, PROGNAME ": insufficient memory\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": unknown readpng_init() error\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++error;
|
||||||
|
}
|
||||||
|
if (error)
|
||||||
|
fclose(infile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
fprintf(stderr, PROGNAME ": aborting.\n");
|
||||||
|
do
|
||||||
|
ch = _getch();
|
||||||
|
while (ch != 'q' && ch != 'Q' && ch != 0x1B);
|
||||||
|
exit(2);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
|
||||||
|
fprintf(stderr,
|
||||||
|
"\n [console window: closing this window will terminate %s]\n\n",
|
||||||
|
PROGNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* set the title-bar string, but make sure buffer doesn't overflow */
|
||||||
|
|
||||||
|
alen = strlen(appname);
|
||||||
|
flen = strlen(filename);
|
||||||
|
if (alen + flen + 3 > 1023)
|
||||||
|
sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
|
||||||
|
else
|
||||||
|
sprintf(titlebar, "%s: %s", appname, filename);
|
||||||
|
|
||||||
|
|
||||||
|
/* if the user didn't specify a background color on the command line,
|
||||||
|
* check for one in the PNG file--if not, the initialized values of 0
|
||||||
|
* (black) will be used */
|
||||||
|
|
||||||
|
if (have_bg) {
|
||||||
|
unsigned r, g, b; /* this approach quiets compiler warnings */
|
||||||
|
|
||||||
|
sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
|
||||||
|
bg_red = (uch)r;
|
||||||
|
bg_green = (uch)g;
|
||||||
|
bg_blue = (uch)b;
|
||||||
|
} else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
|
||||||
|
readpng_cleanup(TRUE);
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": libpng error while checking for background color\n");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* do the basic Windows initialization stuff, make the window and fill it
|
||||||
|
* with the background color */
|
||||||
|
|
||||||
|
if (rpng_win_create_window(hInst, showmode))
|
||||||
|
exit(2);
|
||||||
|
|
||||||
|
|
||||||
|
/* decode the image, all at once */
|
||||||
|
|
||||||
|
Trace((stderr, "calling readpng_get_image()\n"))
|
||||||
|
image_data = readpng_get_image(display_exponent, &image_channels,
|
||||||
|
&image_rowbytes);
|
||||||
|
Trace((stderr, "done with readpng_get_image()\n"))
|
||||||
|
|
||||||
|
|
||||||
|
/* done with PNG file, so clean up to minimize memory usage (but do NOT
|
||||||
|
* nuke image_data!) */
|
||||||
|
|
||||||
|
readpng_cleanup(FALSE);
|
||||||
|
fclose(infile);
|
||||||
|
|
||||||
|
if (!image_data) {
|
||||||
|
fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* display image (composite with background if requested) */
|
||||||
|
|
||||||
|
Trace((stderr, "calling rpng_win_display_image()\n"))
|
||||||
|
if (rpng_win_display_image()) {
|
||||||
|
free(image_data);
|
||||||
|
exit(4);
|
||||||
|
}
|
||||||
|
Trace((stderr, "done with rpng_win_display_image()\n"))
|
||||||
|
|
||||||
|
|
||||||
|
/* wait for the user to tell us when to quit */
|
||||||
|
|
||||||
|
printf(
|
||||||
|
"Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* OK, we're done: clean up all image and Windows resources and go away */
|
||||||
|
|
||||||
|
rpng_win_cleanup();
|
||||||
|
|
||||||
|
return msg.wParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int rpng_win_create_window(HINSTANCE hInst, int showmode)
|
||||||
|
{
|
||||||
|
uch *dest;
|
||||||
|
int extra_width, extra_height;
|
||||||
|
ulg i, j;
|
||||||
|
WNDCLASSEX wndclass;
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Allocate memory for the display-specific version of the image (round up
|
||||||
|
to multiple of 4 for Windows DIB).
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2;
|
||||||
|
|
||||||
|
if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +
|
||||||
|
wimage_rowbytes*image_height)))
|
||||||
|
{
|
||||||
|
return 4; /* fail */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Initialize the DIB. Negative height means to use top-down BMP ordering
|
||||||
|
(must be uncompressed, but that's what we want). Bit count of 1, 4 or 8
|
||||||
|
implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values
|
||||||
|
directly => wimage_data begins immediately after BMP header.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
memset(dib, 0, sizeof(BITMAPINFOHEADER));
|
||||||
|
bmih = (BITMAPINFOHEADER *)dib;
|
||||||
|
bmih->biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
bmih->biWidth = image_width;
|
||||||
|
bmih->biHeight = -((long)image_height);
|
||||||
|
bmih->biPlanes = 1;
|
||||||
|
bmih->biBitCount = 24;
|
||||||
|
bmih->biCompression = 0;
|
||||||
|
wimage_data = dib + sizeof(BITMAPINFOHEADER);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Fill in background color (black by default); data are in BGR order.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
for (j = 0; j < image_height; ++j) {
|
||||||
|
dest = wimage_data + j*wimage_rowbytes;
|
||||||
|
for (i = image_width; i > 0; --i) {
|
||||||
|
*dest++ = bg_blue;
|
||||||
|
*dest++ = bg_green;
|
||||||
|
*dest++ = bg_red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Set the window parameters.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
memset(&wndclass, 0, sizeof(wndclass));
|
||||||
|
|
||||||
|
wndclass.cbSize = sizeof(wndclass);
|
||||||
|
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
|
wndclass.lpfnWndProc = rpng_win_wndproc;
|
||||||
|
wndclass.hInstance = hInst;
|
||||||
|
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||||
|
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||||
|
wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
|
||||||
|
wndclass.lpszMenuName = NULL;
|
||||||
|
wndclass.lpszClassName = progname;
|
||||||
|
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||||
|
|
||||||
|
RegisterClassEx(&wndclass);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Finally, create the window.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
extra_width = 2*(GetSystemMetrics(SM_CXBORDER) +
|
||||||
|
GetSystemMetrics(SM_CXDLGFRAME));
|
||||||
|
extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +
|
||||||
|
GetSystemMetrics(SM_CYDLGFRAME)) +
|
||||||
|
GetSystemMetrics(SM_CYCAPTION);
|
||||||
|
|
||||||
|
global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width,
|
||||||
|
image_height+extra_height, NULL, NULL, hInst, NULL);
|
||||||
|
|
||||||
|
ShowWindow(global_hwnd, showmode);
|
||||||
|
UpdateWindow(global_hwnd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} /* end function rpng_win_create_window() */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int rpng_win_display_image()
|
||||||
|
{
|
||||||
|
uch *src, *dest;
|
||||||
|
uch r, g, b, a;
|
||||||
|
ulg i, row, lastrow;
|
||||||
|
RECT rect;
|
||||||
|
|
||||||
|
|
||||||
|
Trace((stderr, "beginning display loop (image_channels == %d)\n",
|
||||||
|
image_channels))
|
||||||
|
Trace((stderr, "(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n",
|
||||||
|
image_width, image_rowbytes, wimage_rowbytes))
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Blast image data to buffer. This whole routine takes place before the
|
||||||
|
message loop begins, so there's no real point in any pseudo-progressive
|
||||||
|
display...
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
for (lastrow = row = 0; row < image_height; ++row) {
|
||||||
|
src = image_data + row*image_rowbytes;
|
||||||
|
dest = wimage_data + row*wimage_rowbytes;
|
||||||
|
if (image_channels == 3) {
|
||||||
|
for (i = image_width; i > 0; --i) {
|
||||||
|
r = *src++;
|
||||||
|
g = *src++;
|
||||||
|
b = *src++;
|
||||||
|
*dest++ = b;
|
||||||
|
*dest++ = g; /* note reverse order */
|
||||||
|
*dest++ = r;
|
||||||
|
}
|
||||||
|
} else /* if (image_channels == 4) */ {
|
||||||
|
for (i = image_width; i > 0; --i) {
|
||||||
|
r = *src++;
|
||||||
|
g = *src++;
|
||||||
|
b = *src++;
|
||||||
|
a = *src++;
|
||||||
|
if (a == 255) {
|
||||||
|
*dest++ = b;
|
||||||
|
*dest++ = g;
|
||||||
|
*dest++ = r;
|
||||||
|
} else if (a == 0) {
|
||||||
|
*dest++ = bg_blue;
|
||||||
|
*dest++ = bg_green;
|
||||||
|
*dest++ = bg_red;
|
||||||
|
} else {
|
||||||
|
/* this macro (copied from png.h) composites the
|
||||||
|
* foreground and background values and puts the
|
||||||
|
* result into the first argument; there are no
|
||||||
|
* side effects with the first argument */
|
||||||
|
alpha_composite(*dest++, b, a, bg_blue);
|
||||||
|
alpha_composite(*dest++, g, a, bg_green);
|
||||||
|
alpha_composite(*dest++, r, a, bg_red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* display after every 16 lines */
|
||||||
|
if (((row+1) & 0xf) == 0) {
|
||||||
|
rect.left = 0L;
|
||||||
|
rect.top = (LONG)lastrow;
|
||||||
|
rect.right = (LONG)image_width; /* possibly off by one? */
|
||||||
|
rect.bottom = (LONG)lastrow + 16L; /* possibly off by one? */
|
||||||
|
InvalidateRect(global_hwnd, &rect, FALSE);
|
||||||
|
UpdateWindow(global_hwnd); /* similar to XFlush() */
|
||||||
|
lastrow = row + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Trace((stderr, "calling final image-flush routine\n"))
|
||||||
|
if (lastrow < image_height) {
|
||||||
|
rect.left = 0L;
|
||||||
|
rect.top = (LONG)lastrow;
|
||||||
|
rect.right = (LONG)image_width; /* possibly off by one? */
|
||||||
|
rect.bottom = (LONG)image_height; /* possibly off by one? */
|
||||||
|
InvalidateRect(global_hwnd, &rect, FALSE);
|
||||||
|
UpdateWindow(global_hwnd); /* similar to XFlush() */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
last param determines whether or not background is wiped before paint
|
||||||
|
InvalidateRect(global_hwnd, NULL, TRUE);
|
||||||
|
UpdateWindow(global_hwnd);
|
||||||
|
*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void rpng_win_cleanup()
|
||||||
|
{
|
||||||
|
if (image_data) {
|
||||||
|
free(image_data);
|
||||||
|
image_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dib) {
|
||||||
|
free(dib);
|
||||||
|
dib = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)
|
||||||
|
{
|
||||||
|
HDC hdc;
|
||||||
|
PAINTSTRUCT ps;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
switch (iMsg) {
|
||||||
|
case WM_CREATE:
|
||||||
|
/* one-time processing here, if any */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_PAINT:
|
||||||
|
hdc = BeginPaint(hwnd, &ps);
|
||||||
|
/* dest */
|
||||||
|
rc = StretchDIBits(hdc, 0, 0, image_width, image_height,
|
||||||
|
/* source */
|
||||||
|
0, 0, image_width, image_height,
|
||||||
|
wimage_data, (BITMAPINFO *)bmih,
|
||||||
|
/* iUsage: no clue */
|
||||||
|
0, SRCCOPY);
|
||||||
|
EndPaint(hwnd, &ps);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* wait for the user to tell us when to quit */
|
||||||
|
case WM_CHAR:
|
||||||
|
switch (wP) { /* only need one, so ignore repeat count */
|
||||||
|
case 'q':
|
||||||
|
case 'Q':
|
||||||
|
case 0x1B: /* Esc key */
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_LBUTTONDOWN: /* another way of quitting */
|
||||||
|
case WM_DESTROY:
|
||||||
|
PostQuitMessage(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DefWindowProc(hwnd, iMsg, wP, lP);
|
||||||
|
}
|
||||||
904
contrib/gregbook/rpng-x.c
Normal file
@@ -0,0 +1,904 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rpng - simple PNG display program rpng-x.c
|
||||||
|
|
||||||
|
This program decodes and displays PNG images, with gamma correction and
|
||||||
|
optionally with a user-specified background color (in case the image has
|
||||||
|
transparency). It is very nearly the most basic PNG viewer possible.
|
||||||
|
This version is for the X Window System (tested by author under Unix and
|
||||||
|
by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking).
|
||||||
|
|
||||||
|
to do:
|
||||||
|
- 8-bit (colormapped) X support
|
||||||
|
- use %.1023s to simplify truncation of title-bar string?
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Changelog:
|
||||||
|
- 1.01: initial public release
|
||||||
|
- 1.02: modified to allow abbreviated options; fixed long/ulong mis-
|
||||||
|
match; switched to png_jmpbuf() macro
|
||||||
|
- 1.10: added support for non-default visuals; fixed X pixel-conversion
|
||||||
|
- 1.11: added extra set of parentheses to png_jmpbuf() macro; fixed
|
||||||
|
command-line parsing bug
|
||||||
|
- 1.12: fixed some small X memory leaks (thanks to Fran<61>ois Petitjean)
|
||||||
|
- 1.13: fixed XFreeGC() crash bug (thanks to Patrick Welche)
|
||||||
|
- 1.14: added support for X resources (thanks to Gerhard Niklasch)
|
||||||
|
- 2.00: dual-licensed (added GNU GPL)
|
||||||
|
- 2.01: fixed improper display of usage screen on PNG error(s)
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define PROGNAME "rpng-x"
|
||||||
|
#define LONGNAME "Simple PNG Viewer for X"
|
||||||
|
#define VERSION "2.01 of 16 March 2008"
|
||||||
|
#define RESNAME "rpng" /* our X resource application name */
|
||||||
|
#define RESCLASS "Rpng" /* our X resource class name */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <X11/Xos.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
|
/* #define DEBUG : this enables the Trace() macros */
|
||||||
|
|
||||||
|
#include "readpng.h" /* typedefs, common macros, readpng prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
/* could just include png.h, but this macro is the only thing we need
|
||||||
|
* (name and typedefs changed to local versions); note that side effects
|
||||||
|
* only happen with alpha (which could easily be avoided with
|
||||||
|
* "ush acopy = (alpha);") */
|
||||||
|
|
||||||
|
#define alpha_composite(composite, fg, alpha, bg) { \
|
||||||
|
ush temp = ((ush)(fg)*(ush)(alpha) + \
|
||||||
|
(ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
|
||||||
|
(composite) = (uch)((temp + (temp >> 8)) >> 8); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* local prototypes */
|
||||||
|
static int rpng_x_create_window(void);
|
||||||
|
static int rpng_x_display_image(void);
|
||||||
|
static void rpng_x_cleanup(void);
|
||||||
|
static int rpng_x_msb(ulg u32val);
|
||||||
|
|
||||||
|
|
||||||
|
static char titlebar[1024], *window_name = titlebar;
|
||||||
|
static char *appname = LONGNAME;
|
||||||
|
static char *icon_name = PROGNAME;
|
||||||
|
static char *res_name = RESNAME;
|
||||||
|
static char *res_class = RESCLASS;
|
||||||
|
static char *filename;
|
||||||
|
static FILE *infile;
|
||||||
|
|
||||||
|
static char *bgstr;
|
||||||
|
static uch bg_red=0, bg_green=0, bg_blue=0;
|
||||||
|
|
||||||
|
static double display_exponent;
|
||||||
|
|
||||||
|
static ulg image_width, image_height, image_rowbytes;
|
||||||
|
static int image_channels;
|
||||||
|
static uch *image_data;
|
||||||
|
|
||||||
|
/* X-specific variables */
|
||||||
|
static char *displayname;
|
||||||
|
static XImage *ximage;
|
||||||
|
static Display *display;
|
||||||
|
static int depth;
|
||||||
|
static Visual *visual;
|
||||||
|
static XVisualInfo *visual_list;
|
||||||
|
static int RShift, GShift, BShift;
|
||||||
|
static ulg RMask, GMask, BMask;
|
||||||
|
static Window window;
|
||||||
|
static GC gc;
|
||||||
|
static Colormap colormap;
|
||||||
|
|
||||||
|
static int have_nondefault_visual = FALSE;
|
||||||
|
static int have_colormap = FALSE;
|
||||||
|
static int have_window = FALSE;
|
||||||
|
static int have_gc = FALSE;
|
||||||
|
/*
|
||||||
|
ulg numcolors=0, pixels[256];
|
||||||
|
ush reds[256], greens[256], blues[256];
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
#ifdef sgi
|
||||||
|
char tmpline[80];
|
||||||
|
#endif
|
||||||
|
char *p;
|
||||||
|
int rc, alen, flen;
|
||||||
|
int error = 0;
|
||||||
|
int have_bg = FALSE;
|
||||||
|
double LUT_exponent; /* just the lookup table */
|
||||||
|
double CRT_exponent = 2.2; /* just the monitor */
|
||||||
|
double default_display_exponent; /* whole display system */
|
||||||
|
XEvent e;
|
||||||
|
KeySym k;
|
||||||
|
|
||||||
|
|
||||||
|
displayname = (char *)NULL;
|
||||||
|
filename = (char *)NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/* First set the default value for our display-system exponent, i.e.,
|
||||||
|
* the product of the CRT exponent and the exponent corresponding to
|
||||||
|
* the frame-buffer's lookup table (LUT), if any. This is not an
|
||||||
|
* exhaustive list of LUT values (e.g., OpenStep has a lot of weird
|
||||||
|
* ones), but it should cover 99% of the current possibilities. */
|
||||||
|
|
||||||
|
#if defined(NeXT)
|
||||||
|
LUT_exponent = 1.0 / 2.2;
|
||||||
|
/*
|
||||||
|
if (some_next_function_that_returns_gamma(&next_gamma))
|
||||||
|
LUT_exponent = 1.0 / next_gamma;
|
||||||
|
*/
|
||||||
|
#elif defined(sgi)
|
||||||
|
LUT_exponent = 1.0 / 1.7;
|
||||||
|
/* there doesn't seem to be any documented function to get the
|
||||||
|
* "gamma" value, so we do it the hard way */
|
||||||
|
infile = fopen("/etc/config/system.glGammaVal", "r");
|
||||||
|
if (infile) {
|
||||||
|
double sgi_gamma;
|
||||||
|
|
||||||
|
fgets(tmpline, 80, infile);
|
||||||
|
fclose(infile);
|
||||||
|
sgi_gamma = atof(tmpline);
|
||||||
|
if (sgi_gamma > 0.0)
|
||||||
|
LUT_exponent = 1.0 / sgi_gamma;
|
||||||
|
}
|
||||||
|
#elif defined(Macintosh)
|
||||||
|
LUT_exponent = 1.8 / 2.61;
|
||||||
|
/*
|
||||||
|
if (some_mac_function_that_returns_gamma(&mac_gamma))
|
||||||
|
LUT_exponent = mac_gamma / 2.61;
|
||||||
|
*/
|
||||||
|
#else
|
||||||
|
LUT_exponent = 1.0; /* assume no LUT: most PCs */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
|
||||||
|
default_display_exponent = LUT_exponent * CRT_exponent;
|
||||||
|
|
||||||
|
|
||||||
|
/* If the user has set the SCREEN_GAMMA environment variable as suggested
|
||||||
|
* (somewhat imprecisely) in the libpng documentation, use that; otherwise
|
||||||
|
* use the default value we just calculated. Either way, the user may
|
||||||
|
* override this via a command-line option. */
|
||||||
|
|
||||||
|
if ((p = getenv("SCREEN_GAMMA")) != NULL)
|
||||||
|
display_exponent = atof(p);
|
||||||
|
else
|
||||||
|
display_exponent = default_display_exponent;
|
||||||
|
|
||||||
|
|
||||||
|
/* Now parse the command line for options and the PNG filename. */
|
||||||
|
|
||||||
|
while (*++argv && !error) {
|
||||||
|
if (!strncmp(*argv, "-display", 2)) {
|
||||||
|
if (!*++argv)
|
||||||
|
++error;
|
||||||
|
else
|
||||||
|
displayname = *argv;
|
||||||
|
} else if (!strncmp(*argv, "-gamma", 2)) {
|
||||||
|
if (!*++argv)
|
||||||
|
++error;
|
||||||
|
else {
|
||||||
|
display_exponent = atof(*argv);
|
||||||
|
if (display_exponent <= 0.0)
|
||||||
|
++error;
|
||||||
|
}
|
||||||
|
} else if (!strncmp(*argv, "-bgcolor", 2)) {
|
||||||
|
if (!*++argv)
|
||||||
|
++error;
|
||||||
|
else {
|
||||||
|
bgstr = *argv;
|
||||||
|
if (strlen(bgstr) != 7 || bgstr[0] != '#')
|
||||||
|
++error;
|
||||||
|
else
|
||||||
|
have_bg = TRUE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (**argv != '-') {
|
||||||
|
filename = *argv;
|
||||||
|
if (argv[1]) /* shouldn't be any more args after filename */
|
||||||
|
++error;
|
||||||
|
} else
|
||||||
|
++error; /* not expecting any other options */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filename)
|
||||||
|
++error;
|
||||||
|
|
||||||
|
|
||||||
|
/* print usage screen if any errors up to this point */
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
|
||||||
|
readpng_version_info();
|
||||||
|
fprintf(stderr, "\n"
|
||||||
|
"Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n"
|
||||||
|
" xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
|
||||||
|
" exp \ttransfer-function exponent (``gamma'') of the display\n"
|
||||||
|
"\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
|
||||||
|
"\t\t to the product of the lookup-table exponent (varies)\n"
|
||||||
|
"\t\t and the CRT exponent (usually 2.2); must be positive\n"
|
||||||
|
" bg \tdesired background color in 7-character hex RGB format\n"
|
||||||
|
"\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
|
||||||
|
"\t\t used with transparent images\n"
|
||||||
|
"\nPress Q, Esc or mouse button 1 (within image window, after image\n"
|
||||||
|
"is displayed) to quit.\n"
|
||||||
|
"\n", PROGNAME, default_display_exponent);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!(infile = fopen(filename, "rb"))) {
|
||||||
|
fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
|
||||||
|
++error;
|
||||||
|
} else {
|
||||||
|
if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
|
||||||
|
switch (rc) {
|
||||||
|
case 1:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": [%s] is not a PNG file: incorrect signature\n",
|
||||||
|
filename);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": [%s] has bad IHDR (libpng longjmp)\n", filename);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
fprintf(stderr, PROGNAME ": insufficient memory\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": unknown readpng_init() error\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++error;
|
||||||
|
} else {
|
||||||
|
display = XOpenDisplay(displayname);
|
||||||
|
if (!display) {
|
||||||
|
readpng_cleanup(TRUE);
|
||||||
|
fprintf(stderr, PROGNAME ": can't open X display [%s]\n",
|
||||||
|
displayname? displayname : "default");
|
||||||
|
++error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error)
|
||||||
|
fclose(infile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
fprintf(stderr, PROGNAME ": aborting.\n");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* set the title-bar string, but make sure buffer doesn't overflow */
|
||||||
|
|
||||||
|
alen = strlen(appname);
|
||||||
|
flen = strlen(filename);
|
||||||
|
if (alen + flen + 3 > 1023)
|
||||||
|
sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
|
||||||
|
else
|
||||||
|
sprintf(titlebar, "%s: %s", appname, filename);
|
||||||
|
|
||||||
|
|
||||||
|
/* if the user didn't specify a background color on the command line,
|
||||||
|
* check for one in the PNG file--if not, the initialized values of 0
|
||||||
|
* (black) will be used */
|
||||||
|
|
||||||
|
if (have_bg) {
|
||||||
|
unsigned r, g, b; /* this approach quiets compiler warnings */
|
||||||
|
|
||||||
|
sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
|
||||||
|
bg_red = (uch)r;
|
||||||
|
bg_green = (uch)g;
|
||||||
|
bg_blue = (uch)b;
|
||||||
|
} else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
|
||||||
|
readpng_cleanup(TRUE);
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": libpng error while checking for background color\n");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* do the basic X initialization stuff, make the window and fill it
|
||||||
|
* with the background color */
|
||||||
|
|
||||||
|
if (rpng_x_create_window())
|
||||||
|
exit(2);
|
||||||
|
|
||||||
|
|
||||||
|
/* decode the image, all at once */
|
||||||
|
|
||||||
|
Trace((stderr, "calling readpng_get_image()\n"))
|
||||||
|
image_data = readpng_get_image(display_exponent, &image_channels,
|
||||||
|
&image_rowbytes);
|
||||||
|
Trace((stderr, "done with readpng_get_image()\n"))
|
||||||
|
|
||||||
|
|
||||||
|
/* done with PNG file, so clean up to minimize memory usage (but do NOT
|
||||||
|
* nuke image_data!) */
|
||||||
|
|
||||||
|
readpng_cleanup(FALSE);
|
||||||
|
fclose(infile);
|
||||||
|
|
||||||
|
if (!image_data) {
|
||||||
|
fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* display image (composite with background if requested) */
|
||||||
|
|
||||||
|
Trace((stderr, "calling rpng_x_display_image()\n"))
|
||||||
|
if (rpng_x_display_image()) {
|
||||||
|
free(image_data);
|
||||||
|
exit(4);
|
||||||
|
}
|
||||||
|
Trace((stderr, "done with rpng_x_display_image()\n"))
|
||||||
|
|
||||||
|
|
||||||
|
/* wait for the user to tell us when to quit */
|
||||||
|
|
||||||
|
printf(
|
||||||
|
"Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
do
|
||||||
|
XNextEvent(display, &e);
|
||||||
|
while (!(e.type == ButtonPress && e.xbutton.button == Button1) &&
|
||||||
|
!(e.type == KeyPress && /* v--- or 1 for shifted keys */
|
||||||
|
((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) ));
|
||||||
|
|
||||||
|
|
||||||
|
/* OK, we're done: clean up all image and X resources and go away */
|
||||||
|
|
||||||
|
rpng_x_cleanup();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int rpng_x_create_window(void)
|
||||||
|
{
|
||||||
|
uch *xdata;
|
||||||
|
int need_colormap = FALSE;
|
||||||
|
int screen, pad;
|
||||||
|
ulg bg_pixel = 0L;
|
||||||
|
ulg attrmask;
|
||||||
|
Window root;
|
||||||
|
XEvent e;
|
||||||
|
XGCValues gcvalues;
|
||||||
|
XSetWindowAttributes attr;
|
||||||
|
XTextProperty windowName, *pWindowName = &windowName;
|
||||||
|
XTextProperty iconName, *pIconName = &iconName;
|
||||||
|
XVisualInfo visual_info;
|
||||||
|
XSizeHints *size_hints;
|
||||||
|
XWMHints *wm_hints;
|
||||||
|
XClassHint *class_hints;
|
||||||
|
|
||||||
|
|
||||||
|
screen = DefaultScreen(display);
|
||||||
|
depth = DisplayPlanes(display, screen);
|
||||||
|
root = RootWindow(display, screen);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
XSynchronize(display, True);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* GRR: add 8-bit support */
|
||||||
|
if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\n",
|
||||||
|
depth);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
XMatchVisualInfo(display, screen, depth,
|
||||||
|
(depth == 8)? PseudoColor : TrueColor, &visual_info);
|
||||||
|
visual = visual_info.visual;
|
||||||
|
#else
|
||||||
|
if (depth != 16 && depth != 24 && depth != 32) {
|
||||||
|
int visuals_matched = 0;
|
||||||
|
|
||||||
|
Trace((stderr, "default depth is %d: checking other visuals\n",
|
||||||
|
depth))
|
||||||
|
|
||||||
|
/* 24-bit first */
|
||||||
|
visual_info.screen = screen;
|
||||||
|
visual_info.depth = 24;
|
||||||
|
visual_list = XGetVisualInfo(display,
|
||||||
|
VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);
|
||||||
|
if (visuals_matched == 0) {
|
||||||
|
/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */
|
||||||
|
fprintf(stderr, "default screen depth %d not supported, and no"
|
||||||
|
" 24-bit visuals found\n", depth);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n",
|
||||||
|
visuals_matched))
|
||||||
|
visual = visual_list[0].visual;
|
||||||
|
depth = visual_list[0].depth;
|
||||||
|
/*
|
||||||
|
colormap_size = visual_list[0].colormap_size;
|
||||||
|
visual_class = visual->class;
|
||||||
|
visualID = XVisualIDFromVisual(visual);
|
||||||
|
*/
|
||||||
|
have_nondefault_visual = TRUE;
|
||||||
|
need_colormap = TRUE;
|
||||||
|
} else {
|
||||||
|
XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);
|
||||||
|
visual = visual_info.visual;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RMask = visual->red_mask;
|
||||||
|
GMask = visual->green_mask;
|
||||||
|
BMask = visual->blue_mask;
|
||||||
|
|
||||||
|
/* GRR: add/check 8-bit support */
|
||||||
|
if (depth == 8 || need_colormap) {
|
||||||
|
colormap = XCreateColormap(display, root, visual, AllocNone);
|
||||||
|
if (!colormap) {
|
||||||
|
fprintf(stderr, "XCreateColormap() failed\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
have_colormap = TRUE;
|
||||||
|
}
|
||||||
|
if (depth == 15 || depth == 16) {
|
||||||
|
RShift = 15 - rpng_x_msb(RMask); /* these are right-shifts */
|
||||||
|
GShift = 15 - rpng_x_msb(GMask);
|
||||||
|
BShift = 15 - rpng_x_msb(BMask);
|
||||||
|
} else if (depth > 16) {
|
||||||
|
#define NO_24BIT_MASKS
|
||||||
|
#ifdef NO_24BIT_MASKS
|
||||||
|
RShift = rpng_x_msb(RMask) - 7; /* these are left-shifts */
|
||||||
|
GShift = rpng_x_msb(GMask) - 7;
|
||||||
|
BShift = rpng_x_msb(BMask) - 7;
|
||||||
|
#else
|
||||||
|
RShift = 7 - rpng_x_msb(RMask); /* these are right-shifts, too */
|
||||||
|
GShift = 7 - rpng_x_msb(GMask);
|
||||||
|
BShift = 7 - rpng_x_msb(BMask);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {
|
||||||
|
fprintf(stderr, "rpng internal logic error: negative X shift(s)!\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Finally, create the window.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
attr.backing_store = Always;
|
||||||
|
attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
|
||||||
|
attrmask = CWBackingStore | CWEventMask;
|
||||||
|
if (have_nondefault_visual) {
|
||||||
|
attr.colormap = colormap;
|
||||||
|
attr.background_pixel = 0;
|
||||||
|
attr.border_pixel = 1;
|
||||||
|
attrmask |= CWColormap | CWBackPixel | CWBorderPixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0,
|
||||||
|
depth, InputOutput, visual, attrmask, &attr);
|
||||||
|
|
||||||
|
if (window == None) {
|
||||||
|
fprintf(stderr, "XCreateWindow() failed\n");
|
||||||
|
return 2;
|
||||||
|
} else
|
||||||
|
have_window = TRUE;
|
||||||
|
|
||||||
|
if (depth == 8)
|
||||||
|
XSetWindowColormap(display, window, colormap);
|
||||||
|
|
||||||
|
if (!XStringListToTextProperty(&window_name, 1, pWindowName))
|
||||||
|
pWindowName = NULL;
|
||||||
|
if (!XStringListToTextProperty(&icon_name, 1, pIconName))
|
||||||
|
pIconName = NULL;
|
||||||
|
|
||||||
|
/* OK if any hints allocation fails; XSetWMProperties() allows NULLs */
|
||||||
|
|
||||||
|
if ((size_hints = XAllocSizeHints()) != NULL) {
|
||||||
|
/* window will not be resizable */
|
||||||
|
size_hints->flags = PMinSize | PMaxSize;
|
||||||
|
size_hints->min_width = size_hints->max_width = (int)image_width;
|
||||||
|
size_hints->min_height = size_hints->max_height = (int)image_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wm_hints = XAllocWMHints()) != NULL) {
|
||||||
|
wm_hints->initial_state = NormalState;
|
||||||
|
wm_hints->input = True;
|
||||||
|
/* wm_hints->icon_pixmap = icon_pixmap; */
|
||||||
|
wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((class_hints = XAllocClassHint()) != NULL) {
|
||||||
|
class_hints->res_name = res_name;
|
||||||
|
class_hints->res_class = res_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,
|
||||||
|
size_hints, wm_hints, class_hints);
|
||||||
|
|
||||||
|
/* various properties and hints no longer needed; free memory */
|
||||||
|
if (pWindowName)
|
||||||
|
XFree(pWindowName->value);
|
||||||
|
if (pIconName)
|
||||||
|
XFree(pIconName->value);
|
||||||
|
if (size_hints)
|
||||||
|
XFree(size_hints);
|
||||||
|
if (wm_hints)
|
||||||
|
XFree(wm_hints);
|
||||||
|
if (class_hints)
|
||||||
|
XFree(class_hints);
|
||||||
|
|
||||||
|
XMapWindow(display, window);
|
||||||
|
|
||||||
|
gc = XCreateGC(display, window, 0, &gcvalues);
|
||||||
|
have_gc = TRUE;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Fill window with the specified background color.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
if (depth == 24 || depth == 32) {
|
||||||
|
bg_pixel = ((ulg)bg_red << RShift) |
|
||||||
|
((ulg)bg_green << GShift) |
|
||||||
|
((ulg)bg_blue << BShift);
|
||||||
|
} else if (depth == 16) {
|
||||||
|
bg_pixel = ((((ulg)bg_red << 8) >> RShift) & RMask) |
|
||||||
|
((((ulg)bg_green << 8) >> GShift) & GMask) |
|
||||||
|
((((ulg)bg_blue << 8) >> BShift) & BMask);
|
||||||
|
} else /* depth == 8 */ {
|
||||||
|
|
||||||
|
/* GRR: add 8-bit support */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
XSetForeground(display, gc, bg_pixel);
|
||||||
|
XFillRectangle(display, window, gc, 0, 0, image_width, image_height);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Wait for first Expose event to do any drawing, then flush.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
do
|
||||||
|
XNextEvent(display, &e);
|
||||||
|
while (e.type != Expose || e.xexpose.count);
|
||||||
|
|
||||||
|
XFlush(display);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
Allocate memory for the X- and display-specific version of the image.
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
if (depth == 24 || depth == 32) {
|
||||||
|
xdata = (uch *)malloc(4*image_width*image_height);
|
||||||
|
pad = 32;
|
||||||
|
} else if (depth == 16) {
|
||||||
|
xdata = (uch *)malloc(2*image_width*image_height);
|
||||||
|
pad = 16;
|
||||||
|
} else /* depth == 8 */ {
|
||||||
|
xdata = (uch *)malloc(image_width*image_height);
|
||||||
|
pad = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xdata) {
|
||||||
|
fprintf(stderr, PROGNAME ": unable to allocate image memory\n");
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
ximage = XCreateImage(display, visual, depth, ZPixmap, 0,
|
||||||
|
(char *)xdata, image_width, image_height, pad, 0);
|
||||||
|
|
||||||
|
if (!ximage) {
|
||||||
|
fprintf(stderr, PROGNAME ": XCreateImage() failed\n");
|
||||||
|
free(xdata);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* to avoid testing the byte order every pixel (or doubling the size of
|
||||||
|
* the drawing routine with a giant if-test), we arbitrarily set the byte
|
||||||
|
* order to MSBFirst and let Xlib worry about inverting things on little-
|
||||||
|
* endian machines (like Linux/x86, old VAXen, etc.)--this is not the most
|
||||||
|
* efficient approach (the giant if-test would be better), but in the
|
||||||
|
* interest of clarity, we take the easy way out... */
|
||||||
|
|
||||||
|
ximage->byte_order = MSBFirst;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} /* end function rpng_x_create_window() */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int rpng_x_display_image(void)
|
||||||
|
{
|
||||||
|
uch *src;
|
||||||
|
char *dest;
|
||||||
|
uch r, g, b, a;
|
||||||
|
ulg i, row, lastrow = 0;
|
||||||
|
ulg pixel;
|
||||||
|
int ximage_rowbytes = ximage->bytes_per_line;
|
||||||
|
/* int bpp = ximage->bits_per_pixel; */
|
||||||
|
|
||||||
|
|
||||||
|
Trace((stderr, "beginning display loop (image_channels == %d)\n",
|
||||||
|
image_channels))
|
||||||
|
Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n",
|
||||||
|
image_width, image_rowbytes, ximage_rowbytes))
|
||||||
|
Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel))
|
||||||
|
Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst?
|
||||||
|
"MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown")))
|
||||||
|
|
||||||
|
if (depth == 24 || depth == 32) {
|
||||||
|
ulg red, green, blue;
|
||||||
|
|
||||||
|
for (lastrow = row = 0; row < image_height; ++row) {
|
||||||
|
src = image_data + row*image_rowbytes;
|
||||||
|
dest = ximage->data + row*ximage_rowbytes;
|
||||||
|
if (image_channels == 3) {
|
||||||
|
for (i = image_width; i > 0; --i) {
|
||||||
|
red = *src++;
|
||||||
|
green = *src++;
|
||||||
|
blue = *src++;
|
||||||
|
#ifdef NO_24BIT_MASKS
|
||||||
|
pixel = (red << RShift) |
|
||||||
|
(green << GShift) |
|
||||||
|
(blue << BShift);
|
||||||
|
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||||
|
/* GRR BUG: this assumes bpp == 32, but may be 24: */
|
||||||
|
*dest++ = (char)((pixel >> 24) & 0xff);
|
||||||
|
*dest++ = (char)((pixel >> 16) & 0xff);
|
||||||
|
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||||
|
*dest++ = (char)( pixel & 0xff);
|
||||||
|
#else
|
||||||
|
red = (RShift < 0)? red << (-RShift) : red >> RShift;
|
||||||
|
green = (GShift < 0)? green << (-GShift) : green >> GShift;
|
||||||
|
blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
|
||||||
|
pixel = (red & RMask) | (green & GMask) | (blue & BMask);
|
||||||
|
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||||
|
*dest++ = (char)((pixel >> 24) & 0xff);
|
||||||
|
*dest++ = (char)((pixel >> 16) & 0xff);
|
||||||
|
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||||
|
*dest++ = (char)( pixel & 0xff);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else /* if (image_channels == 4) */ {
|
||||||
|
for (i = image_width; i > 0; --i) {
|
||||||
|
r = *src++;
|
||||||
|
g = *src++;
|
||||||
|
b = *src++;
|
||||||
|
a = *src++;
|
||||||
|
if (a == 255) {
|
||||||
|
red = r;
|
||||||
|
green = g;
|
||||||
|
blue = b;
|
||||||
|
} else if (a == 0) {
|
||||||
|
red = bg_red;
|
||||||
|
green = bg_green;
|
||||||
|
blue = bg_blue;
|
||||||
|
} else {
|
||||||
|
/* this macro (from png.h) composites the foreground
|
||||||
|
* and background values and puts the result into the
|
||||||
|
* first argument */
|
||||||
|
alpha_composite(red, r, a, bg_red);
|
||||||
|
alpha_composite(green, g, a, bg_green);
|
||||||
|
alpha_composite(blue, b, a, bg_blue);
|
||||||
|
}
|
||||||
|
pixel = (red << RShift) |
|
||||||
|
(green << GShift) |
|
||||||
|
(blue << BShift);
|
||||||
|
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||||
|
*dest++ = (char)((pixel >> 24) & 0xff);
|
||||||
|
*dest++ = (char)((pixel >> 16) & 0xff);
|
||||||
|
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||||
|
*dest++ = (char)( pixel & 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* display after every 16 lines */
|
||||||
|
if (((row+1) & 0xf) == 0) {
|
||||||
|
XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
|
||||||
|
(int)lastrow, image_width, 16);
|
||||||
|
XFlush(display);
|
||||||
|
lastrow = row + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (depth == 16) {
|
||||||
|
ush red, green, blue;
|
||||||
|
|
||||||
|
for (lastrow = row = 0; row < image_height; ++row) {
|
||||||
|
src = image_data + row*image_rowbytes;
|
||||||
|
dest = ximage->data + row*ximage_rowbytes;
|
||||||
|
if (image_channels == 3) {
|
||||||
|
for (i = image_width; i > 0; --i) {
|
||||||
|
red = ((ush)(*src) << 8);
|
||||||
|
++src;
|
||||||
|
green = ((ush)(*src) << 8);
|
||||||
|
++src;
|
||||||
|
blue = ((ush)(*src) << 8);
|
||||||
|
++src;
|
||||||
|
pixel = ((red >> RShift) & RMask) |
|
||||||
|
((green >> GShift) & GMask) |
|
||||||
|
((blue >> BShift) & BMask);
|
||||||
|
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||||
|
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||||
|
*dest++ = (char)( pixel & 0xff);
|
||||||
|
}
|
||||||
|
} else /* if (image_channels == 4) */ {
|
||||||
|
for (i = image_width; i > 0; --i) {
|
||||||
|
r = *src++;
|
||||||
|
g = *src++;
|
||||||
|
b = *src++;
|
||||||
|
a = *src++;
|
||||||
|
if (a == 255) {
|
||||||
|
red = ((ush)r << 8);
|
||||||
|
green = ((ush)g << 8);
|
||||||
|
blue = ((ush)b << 8);
|
||||||
|
} else if (a == 0) {
|
||||||
|
red = ((ush)bg_red << 8);
|
||||||
|
green = ((ush)bg_green << 8);
|
||||||
|
blue = ((ush)bg_blue << 8);
|
||||||
|
} else {
|
||||||
|
/* this macro (from png.h) composites the foreground
|
||||||
|
* and background values and puts the result back into
|
||||||
|
* the first argument (== fg byte here: safe) */
|
||||||
|
alpha_composite(r, r, a, bg_red);
|
||||||
|
alpha_composite(g, g, a, bg_green);
|
||||||
|
alpha_composite(b, b, a, bg_blue);
|
||||||
|
red = ((ush)r << 8);
|
||||||
|
green = ((ush)g << 8);
|
||||||
|
blue = ((ush)b << 8);
|
||||||
|
}
|
||||||
|
pixel = ((red >> RShift) & RMask) |
|
||||||
|
((green >> GShift) & GMask) |
|
||||||
|
((blue >> BShift) & BMask);
|
||||||
|
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||||
|
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||||
|
*dest++ = (char)( pixel & 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* display after every 16 lines */
|
||||||
|
if (((row+1) & 0xf) == 0) {
|
||||||
|
XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
|
||||||
|
(int)lastrow, image_width, 16);
|
||||||
|
XFlush(display);
|
||||||
|
lastrow = row + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else /* depth == 8 */ {
|
||||||
|
|
||||||
|
/* GRR: add 8-bit support */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Trace((stderr, "calling final XPutImage()\n"))
|
||||||
|
if (lastrow < image_height) {
|
||||||
|
XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
|
||||||
|
(int)lastrow, image_width, image_height-lastrow);
|
||||||
|
XFlush(display);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void rpng_x_cleanup(void)
|
||||||
|
{
|
||||||
|
if (image_data) {
|
||||||
|
free(image_data);
|
||||||
|
image_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ximage) {
|
||||||
|
if (ximage->data) {
|
||||||
|
free(ximage->data); /* we allocated it, so we free it */
|
||||||
|
ximage->data = (char *)NULL; /* instead of XDestroyImage() */
|
||||||
|
}
|
||||||
|
XDestroyImage(ximage);
|
||||||
|
ximage = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (have_gc)
|
||||||
|
XFreeGC(display, gc);
|
||||||
|
|
||||||
|
if (have_window)
|
||||||
|
XDestroyWindow(display, window);
|
||||||
|
|
||||||
|
if (have_colormap)
|
||||||
|
XFreeColormap(display, colormap);
|
||||||
|
|
||||||
|
if (have_nondefault_visual)
|
||||||
|
XFree(visual_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int rpng_x_msb(ulg u32val)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 31; i >= 0; --i) {
|
||||||
|
if (u32val & 0x80000000L)
|
||||||
|
break;
|
||||||
|
u32val <<= 1;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
1225
contrib/gregbook/rpng2-win.c
Normal file
2127
contrib/gregbook/rpng2-x.c
Normal file
BIN
contrib/gregbook/toucan.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
853
contrib/gregbook/wpng.c
Normal file
@@ -0,0 +1,853 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wpng - simple PNG-writing program wpng.c
|
||||||
|
|
||||||
|
This program converts certain NetPBM binary files (grayscale and RGB,
|
||||||
|
maxval = 255) to PNG. Non-interlaced PNGs are written progressively;
|
||||||
|
interlaced PNGs are read and written in one memory-intensive blast.
|
||||||
|
|
||||||
|
Thanks to Jean-loup Gailly for providing the necessary trick to read
|
||||||
|
interactive text from the keyboard while stdin is redirected. Thanks
|
||||||
|
to Cosmin Truta for Cygwin fixes.
|
||||||
|
|
||||||
|
NOTE: includes provisional support for PNM type "8" (portable alphamap)
|
||||||
|
images, presumed to be a 32-bit interleaved RGBA format; no pro-
|
||||||
|
vision for possible interleaved grayscale+alpha (16-bit) format.
|
||||||
|
THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT!
|
||||||
|
|
||||||
|
to do:
|
||||||
|
- delete output file if quit before calling any writepng routines
|
||||||
|
- process backspace with -text option under DOS/Win? (currently get ^H)
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Changelog:
|
||||||
|
- 1.01: initial public release
|
||||||
|
- 1.02: modified to allow abbreviated options
|
||||||
|
- 1.03: removed extraneous character from usage screen; fixed bug in
|
||||||
|
command-line parsing
|
||||||
|
- 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix
|
||||||
|
(see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff)
|
||||||
|
- 2.00: dual-licensed (added GNU GPL)
|
||||||
|
|
||||||
|
[REPORTED BUG (win32 only): "contrib/gregbook/wpng.c - cmd line
|
||||||
|
dose not work! In order to do something useful I needed to redirect
|
||||||
|
both input and output, with cygwin and with bcc32 as well. Under
|
||||||
|
Linux, the same wpng appears to work fine. I don't know what is
|
||||||
|
the problem."]
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define PROGNAME "wpng"
|
||||||
|
#define VERSION "2.00 of 2 June 2007"
|
||||||
|
#define APPNAME "Simple PGM/PPM/PAM to PNG Converter"
|
||||||
|
|
||||||
|
#if defined(__MSDOS__) || defined(__OS2__)
|
||||||
|
# define DOS_OS2_W32
|
||||||
|
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||||
|
# ifndef __GNUC__ /* treat Win32 native ports of gcc as Unix environments */
|
||||||
|
# define DOS_OS2_W32
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <setjmp.h> /* for jmpbuf declaration in writepng.h */
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#ifdef DOS_OS2_W32
|
||||||
|
# include <io.h> /* for isatty(), setmode() prototypes */
|
||||||
|
# include <fcntl.h> /* O_BINARY for fdopen() without text translation */
|
||||||
|
# ifdef __EMX__
|
||||||
|
# ifndef getch
|
||||||
|
# define getch() _read_kbd(0, 1, 0) /* need getche() */
|
||||||
|
# endif
|
||||||
|
# else /* !__EMX__ */
|
||||||
|
# ifdef __GO32__
|
||||||
|
# include <pc.h>
|
||||||
|
# define getch() getkey() /* GRR: need getche() */
|
||||||
|
# else
|
||||||
|
# include <conio.h> /* for getche() console input */
|
||||||
|
# endif
|
||||||
|
# endif /* ?__EMX__ */
|
||||||
|
# define FGETS(buf,len,stream) dos_kbd_gets(buf,len)
|
||||||
|
#else
|
||||||
|
# include <unistd.h> /* for isatty() prototype */
|
||||||
|
# define FGETS fgets
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* #define DEBUG : this enables the Trace() macros */
|
||||||
|
|
||||||
|
/* #define FORBID_LATIN1_CTRL : this requires the user to re-enter any
|
||||||
|
text that includes control characters discouraged by the PNG spec; text
|
||||||
|
that includes an escape character (27) must be re-entered regardless */
|
||||||
|
|
||||||
|
#include "writepng.h" /* typedefs, common macros, writepng prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* local prototypes */
|
||||||
|
|
||||||
|
static int wpng_isvalid_latin1(uch *p, int len);
|
||||||
|
static void wpng_cleanup(void);
|
||||||
|
|
||||||
|
#ifdef DOS_OS2_W32
|
||||||
|
static char *dos_kbd_gets(char *buf, int len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static mainprog_info wpng_info; /* lone global */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
#ifndef DOS_OS2_W32
|
||||||
|
FILE *keybd;
|
||||||
|
#endif
|
||||||
|
#ifdef sgi
|
||||||
|
FILE *tmpfile; /* or we could just use keybd, since no overlap */
|
||||||
|
char tmpline[80];
|
||||||
|
#endif
|
||||||
|
char *inname = NULL, outname[256];
|
||||||
|
char *p, pnmchar, pnmline[256];
|
||||||
|
char *bgstr, *textbuf = NULL;
|
||||||
|
ulg rowbytes;
|
||||||
|
int rc, len = 0;
|
||||||
|
int error = 0;
|
||||||
|
int text = FALSE;
|
||||||
|
int maxval;
|
||||||
|
double LUT_exponent; /* just the lookup table */
|
||||||
|
double CRT_exponent = 2.2; /* just the monitor */
|
||||||
|
double default_display_exponent; /* whole display system */
|
||||||
|
double default_gamma = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
wpng_info.infile = NULL;
|
||||||
|
wpng_info.outfile = NULL;
|
||||||
|
wpng_info.image_data = NULL;
|
||||||
|
wpng_info.row_pointers = NULL;
|
||||||
|
wpng_info.filter = FALSE;
|
||||||
|
wpng_info.interlaced = FALSE;
|
||||||
|
wpng_info.have_bg = FALSE;
|
||||||
|
wpng_info.have_time = FALSE;
|
||||||
|
wpng_info.have_text = 0;
|
||||||
|
wpng_info.gamma = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
/* First get the default value for our display-system exponent, i.e.,
|
||||||
|
* the product of the CRT exponent and the exponent corresponding to
|
||||||
|
* the frame-buffer's lookup table (LUT), if any. If the PNM image
|
||||||
|
* looks correct on the user's display system, its file gamma is the
|
||||||
|
* inverse of this value. (Note that this is not an exhaustive list
|
||||||
|
* of LUT values--e.g., OpenStep has a lot of weird ones--but it should
|
||||||
|
* cover 99% of the current possibilities. This section must ensure
|
||||||
|
* that default_display_exponent is positive.) */
|
||||||
|
|
||||||
|
#if defined(NeXT)
|
||||||
|
/* third-party utilities can modify the default LUT exponent */
|
||||||
|
LUT_exponent = 1.0 / 2.2;
|
||||||
|
/*
|
||||||
|
if (some_next_function_that_returns_gamma(&next_gamma))
|
||||||
|
LUT_exponent = 1.0 / next_gamma;
|
||||||
|
*/
|
||||||
|
#elif defined(sgi)
|
||||||
|
LUT_exponent = 1.0 / 1.7;
|
||||||
|
/* there doesn't seem to be any documented function to
|
||||||
|
* get the "gamma" value, so we do it the hard way */
|
||||||
|
tmpfile = fopen("/etc/config/system.glGammaVal", "r");
|
||||||
|
if (tmpfile) {
|
||||||
|
double sgi_gamma;
|
||||||
|
|
||||||
|
fgets(tmpline, 80, tmpfile);
|
||||||
|
fclose(tmpfile);
|
||||||
|
sgi_gamma = atof(tmpline);
|
||||||
|
if (sgi_gamma > 0.0)
|
||||||
|
LUT_exponent = 1.0 / sgi_gamma;
|
||||||
|
}
|
||||||
|
#elif defined(Macintosh)
|
||||||
|
LUT_exponent = 1.8 / 2.61;
|
||||||
|
/*
|
||||||
|
if (some_mac_function_that_returns_gamma(&mac_gamma))
|
||||||
|
LUT_exponent = mac_gamma / 2.61;
|
||||||
|
*/
|
||||||
|
#else
|
||||||
|
LUT_exponent = 1.0; /* assume no LUT: most PCs */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
|
||||||
|
default_display_exponent = LUT_exponent * CRT_exponent;
|
||||||
|
|
||||||
|
|
||||||
|
/* If the user has set the SCREEN_GAMMA environment variable as suggested
|
||||||
|
* (somewhat imprecisely) in the libpng documentation, use that; otherwise
|
||||||
|
* use the default value we just calculated. Either way, the user may
|
||||||
|
* override this via a command-line option. */
|
||||||
|
|
||||||
|
if ((p = getenv("SCREEN_GAMMA")) != NULL) {
|
||||||
|
double exponent = atof(p);
|
||||||
|
|
||||||
|
if (exponent > 0.0)
|
||||||
|
default_gamma = 1.0 / exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (default_gamma == 0.0)
|
||||||
|
default_gamma = 1.0 / default_display_exponent;
|
||||||
|
|
||||||
|
|
||||||
|
/* Now parse the command line for options and the PNM filename. */
|
||||||
|
|
||||||
|
while (*++argv && !error) {
|
||||||
|
if (!strncmp(*argv, "-i", 2)) {
|
||||||
|
wpng_info.interlaced = TRUE;
|
||||||
|
} else if (!strncmp(*argv, "-time", 3)) {
|
||||||
|
wpng_info.modtime = time(NULL);
|
||||||
|
wpng_info.have_time = TRUE;
|
||||||
|
} else if (!strncmp(*argv, "-text", 3)) {
|
||||||
|
text = TRUE;
|
||||||
|
} else if (!strncmp(*argv, "-gamma", 2)) {
|
||||||
|
if (!*++argv)
|
||||||
|
++error;
|
||||||
|
else {
|
||||||
|
wpng_info.gamma = atof(*argv);
|
||||||
|
if (wpng_info.gamma <= 0.0)
|
||||||
|
++error;
|
||||||
|
else if (wpng_info.gamma > 1.01)
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
" warning: file gammas are usually less than 1.0\n");
|
||||||
|
}
|
||||||
|
} else if (!strncmp(*argv, "-bgcolor", 4)) {
|
||||||
|
if (!*++argv)
|
||||||
|
++error;
|
||||||
|
else {
|
||||||
|
bgstr = *argv;
|
||||||
|
if (strlen(bgstr) != 7 || bgstr[0] != '#')
|
||||||
|
++error;
|
||||||
|
else {
|
||||||
|
unsigned r, g, b; /* this way quiets compiler warnings */
|
||||||
|
|
||||||
|
sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
|
||||||
|
wpng_info.bg_red = (uch)r;
|
||||||
|
wpng_info.bg_green = (uch)g;
|
||||||
|
wpng_info.bg_blue = (uch)b;
|
||||||
|
wpng_info.have_bg = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (**argv != '-') {
|
||||||
|
inname = *argv;
|
||||||
|
if (argv[1]) /* shouldn't be any more args after filename */
|
||||||
|
++error;
|
||||||
|
} else
|
||||||
|
++error; /* not expecting any other options */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* open the input and output files, or register an error and abort */
|
||||||
|
|
||||||
|
if (!inname) {
|
||||||
|
if (isatty(0)) {
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": must give input filename or provide image data via stdin\n");
|
||||||
|
++error;
|
||||||
|
} else {
|
||||||
|
#ifdef DOS_OS2_W32
|
||||||
|
/* some buggy C libraries require BOTH setmode() and fdopen(bin) */
|
||||||
|
setmode(fileno(stdin), O_BINARY);
|
||||||
|
setmode(fileno(stdout), O_BINARY);
|
||||||
|
#endif
|
||||||
|
if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) {
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": unable to reopen stdin in binary mode\n");
|
||||||
|
++error;
|
||||||
|
} else
|
||||||
|
if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) {
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": unable to reopen stdout in binary mode\n");
|
||||||
|
fclose(wpng_info.infile);
|
||||||
|
++error;
|
||||||
|
} else
|
||||||
|
wpng_info.filter = TRUE;
|
||||||
|
}
|
||||||
|
} else if ((len = strlen(inname)) > 250) {
|
||||||
|
fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n",
|
||||||
|
len);
|
||||||
|
++error;
|
||||||
|
} else if (!(wpng_info.infile = fopen(inname, "rb"))) {
|
||||||
|
fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname);
|
||||||
|
++error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
fgets(pnmline, 256, wpng_info.infile);
|
||||||
|
if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' &&
|
||||||
|
pnmchar != '6' && pnmchar != '8'))
|
||||||
|
{
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": input file [%s] is not a binary PGM, PPM or PAM file\n",
|
||||||
|
inname);
|
||||||
|
++error;
|
||||||
|
} else {
|
||||||
|
wpng_info.pnmtype = (int)(pnmchar - '0');
|
||||||
|
if (wpng_info.pnmtype != 8)
|
||||||
|
wpng_info.have_bg = FALSE; /* no need for bg if opaque */
|
||||||
|
do {
|
||||||
|
fgets(pnmline, 256, wpng_info.infile); /* lose any comments */
|
||||||
|
} while (pnmline[0] == '#');
|
||||||
|
sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height);
|
||||||
|
do {
|
||||||
|
fgets(pnmline, 256, wpng_info.infile); /* more comment lines */
|
||||||
|
} while (pnmline[0] == '#');
|
||||||
|
sscanf(pnmline, "%d", &maxval);
|
||||||
|
if (wpng_info.width <= 0L || wpng_info.height <= 0L ||
|
||||||
|
maxval != 255)
|
||||||
|
{
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": only positive width/height, maxval == 255 allowed \n");
|
||||||
|
++error;
|
||||||
|
}
|
||||||
|
wpng_info.sample_depth = 8; /* <==> maxval 255 */
|
||||||
|
|
||||||
|
if (!wpng_info.filter) {
|
||||||
|
/* make outname from inname */
|
||||||
|
if ((p = strrchr(inname, '.')) == NULL ||
|
||||||
|
(p - inname) != (len - 4))
|
||||||
|
{
|
||||||
|
strcpy(outname, inname);
|
||||||
|
strcpy(outname+len, ".png");
|
||||||
|
} else {
|
||||||
|
len -= 4;
|
||||||
|
strncpy(outname, inname, len);
|
||||||
|
strcpy(outname+len, ".png");
|
||||||
|
}
|
||||||
|
/* check if outname already exists; if not, open */
|
||||||
|
if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) {
|
||||||
|
fprintf(stderr, PROGNAME ": output file exists [%s]\n",
|
||||||
|
outname);
|
||||||
|
fclose(wpng_info.outfile);
|
||||||
|
++error;
|
||||||
|
} else if (!(wpng_info.outfile = fopen(outname, "wb"))) {
|
||||||
|
fprintf(stderr, PROGNAME ": can't open output file [%s]\n",
|
||||||
|
outname);
|
||||||
|
++error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
fclose(wpng_info.infile);
|
||||||
|
wpng_info.infile = NULL;
|
||||||
|
if (wpng_info.filter) {
|
||||||
|
fclose(wpng_info.outfile);
|
||||||
|
wpng_info.outfile = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* if we had any errors, print usage and die horrible death...arrr! */
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME);
|
||||||
|
writepng_version_info();
|
||||||
|
fprintf(stderr, "\n"
|
||||||
|
"Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n"
|
||||||
|
"or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n"
|
||||||
|
" exp \ttransfer-function exponent (``gamma'') of the image in\n"
|
||||||
|
"\t\t floating-point format (e.g., ``%.5f''); if image looks\n"
|
||||||
|
"\t\t correct on given display system, image gamma is equal to\n"
|
||||||
|
"\t\t inverse of display-system exponent, i.e., 1 / (LUT * CRT)\n"
|
||||||
|
"\t\t (where LUT = lookup-table exponent and CRT = CRT exponent;\n"
|
||||||
|
"\t\t first varies, second is usually 2.2, all are positive)\n"
|
||||||
|
" bg \tdesired background color for alpha-channel images, in\n"
|
||||||
|
"\t\t 7-character hex RGB format (e.g., ``#ff7700'' for orange:\n"
|
||||||
|
"\t\t same as HTML colors)\n"
|
||||||
|
" -text\tprompt interactively for text info (tEXt chunks)\n"
|
||||||
|
" -time\tinclude a tIME chunk (last modification time)\n"
|
||||||
|
" -interlace\twrite interlaced PNG image\n"
|
||||||
|
"\n"
|
||||||
|
"pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\n"
|
||||||
|
"unofficial and unsupported!) PAM (`P8') file. Currently it is required\n"
|
||||||
|
"to have maxval == 255 (i.e., no scaling). If pnmfile is specified, it\n"
|
||||||
|
"is converted to the corresponding PNG file with the same base name but a\n"
|
||||||
|
"``.png'' extension; files read from stdin are converted and sent to stdout.\n"
|
||||||
|
"The conversion is progressive (low memory usage) unless interlacing is\n"
|
||||||
|
"requested; in that case the whole image will be buffered in memory and\n"
|
||||||
|
"written in one call.\n"
|
||||||
|
"\n", PROGNAME, PROGNAME, default_gamma);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* prepare the text buffers for libpng's use; note that even though
|
||||||
|
* PNG's png_text struct includes a length field, we don't have to fill
|
||||||
|
* it out */
|
||||||
|
|
||||||
|
if (text &&
|
||||||
|
#ifndef DOS_OS2_W32
|
||||||
|
(keybd = fdopen(fileno(stderr), "r")) != NULL &&
|
||||||
|
#endif
|
||||||
|
(textbuf = (char *)malloc((5 + 9)*75)) != NULL)
|
||||||
|
{
|
||||||
|
int i, valid, result;
|
||||||
|
|
||||||
|
fprintf(stderr,
|
||||||
|
"Enter text info (no more than 72 characters per line);\n");
|
||||||
|
fprintf(stderr, "to skip a field, hit the <Enter> key.\n");
|
||||||
|
/* note: just <Enter> leaves len == 1 */
|
||||||
|
|
||||||
|
do {
|
||||||
|
valid = TRUE;
|
||||||
|
p = textbuf + TEXT_TITLE_OFFSET;
|
||||||
|
fprintf(stderr, " Title: ");
|
||||||
|
fflush(stderr);
|
||||||
|
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||||
|
if (p[len-1] == '\n')
|
||||||
|
p[--len] = '\0';
|
||||||
|
wpng_info.title = p;
|
||||||
|
wpng_info.have_text |= TEXT_TITLE;
|
||||||
|
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||||
|
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||||
|
" %u is %sdiscouraged by the PNG\n specification "
|
||||||
|
"[first occurrence was at character position #%d]\n",
|
||||||
|
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||||
|
result+1);
|
||||||
|
fflush(stderr);
|
||||||
|
#ifdef FORBID_LATIN1_CTRL
|
||||||
|
wpng_info.have_text &= ~TEXT_TITLE;
|
||||||
|
valid = FALSE;
|
||||||
|
#else
|
||||||
|
if (p[result] == 27) { /* escape character */
|
||||||
|
wpng_info.have_text &= ~TEXT_TITLE;
|
||||||
|
valid = FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!valid);
|
||||||
|
|
||||||
|
do {
|
||||||
|
valid = TRUE;
|
||||||
|
p = textbuf + TEXT_AUTHOR_OFFSET;
|
||||||
|
fprintf(stderr, " Author: ");
|
||||||
|
fflush(stderr);
|
||||||
|
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||||
|
if (p[len-1] == '\n')
|
||||||
|
p[--len] = '\0';
|
||||||
|
wpng_info.author = p;
|
||||||
|
wpng_info.have_text |= TEXT_AUTHOR;
|
||||||
|
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||||
|
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||||
|
" %u is %sdiscouraged by the PNG\n specification "
|
||||||
|
"[first occurrence was at character position #%d]\n",
|
||||||
|
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||||
|
result+1);
|
||||||
|
fflush(stderr);
|
||||||
|
#ifdef FORBID_LATIN1_CTRL
|
||||||
|
wpng_info.have_text &= ~TEXT_AUTHOR;
|
||||||
|
valid = FALSE;
|
||||||
|
#else
|
||||||
|
if (p[result] == 27) { /* escape character */
|
||||||
|
wpng_info.have_text &= ~TEXT_AUTHOR;
|
||||||
|
valid = FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!valid);
|
||||||
|
|
||||||
|
do {
|
||||||
|
valid = TRUE;
|
||||||
|
p = textbuf + TEXT_DESC_OFFSET;
|
||||||
|
fprintf(stderr, " Description (up to 9 lines):\n");
|
||||||
|
for (i = 1; i < 10; ++i) {
|
||||||
|
fprintf(stderr, " [%d] ", i);
|
||||||
|
fflush(stderr);
|
||||||
|
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1)
|
||||||
|
p += len; /* now points at NULL; char before is newline */
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) {
|
||||||
|
if (p[-1] == '\n') {
|
||||||
|
p[-1] = '\0';
|
||||||
|
--len;
|
||||||
|
}
|
||||||
|
wpng_info.desc = textbuf + TEXT_DESC_OFFSET;
|
||||||
|
wpng_info.have_text |= TEXT_DESC;
|
||||||
|
p = textbuf + TEXT_DESC_OFFSET;
|
||||||
|
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||||
|
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||||
|
" %u is %sdiscouraged by the PNG\n specification "
|
||||||
|
"[first occurrence was at character position #%d]\n",
|
||||||
|
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||||
|
result+1);
|
||||||
|
fflush(stderr);
|
||||||
|
#ifdef FORBID_LATIN1_CTRL
|
||||||
|
wpng_info.have_text &= ~TEXT_DESC;
|
||||||
|
valid = FALSE;
|
||||||
|
#else
|
||||||
|
if (p[result] == 27) { /* escape character */
|
||||||
|
wpng_info.have_text &= ~TEXT_DESC;
|
||||||
|
valid = FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!valid);
|
||||||
|
|
||||||
|
do {
|
||||||
|
valid = TRUE;
|
||||||
|
p = textbuf + TEXT_COPY_OFFSET;
|
||||||
|
fprintf(stderr, " Copyright: ");
|
||||||
|
fflush(stderr);
|
||||||
|
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||||
|
if (p[len-1] == '\n')
|
||||||
|
p[--len] = '\0';
|
||||||
|
wpng_info.copyright = p;
|
||||||
|
wpng_info.have_text |= TEXT_COPY;
|
||||||
|
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||||
|
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||||
|
" %u is %sdiscouraged by the PNG\n specification "
|
||||||
|
"[first occurrence was at character position #%d]\n",
|
||||||
|
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||||
|
result+1);
|
||||||
|
fflush(stderr);
|
||||||
|
#ifdef FORBID_LATIN1_CTRL
|
||||||
|
wpng_info.have_text &= ~TEXT_COPY;
|
||||||
|
valid = FALSE;
|
||||||
|
#else
|
||||||
|
if (p[result] == 27) { /* escape character */
|
||||||
|
wpng_info.have_text &= ~TEXT_COPY;
|
||||||
|
valid = FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!valid);
|
||||||
|
|
||||||
|
do {
|
||||||
|
valid = TRUE;
|
||||||
|
p = textbuf + TEXT_EMAIL_OFFSET;
|
||||||
|
fprintf(stderr, " E-mail: ");
|
||||||
|
fflush(stderr);
|
||||||
|
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||||
|
if (p[len-1] == '\n')
|
||||||
|
p[--len] = '\0';
|
||||||
|
wpng_info.email = p;
|
||||||
|
wpng_info.have_text |= TEXT_EMAIL;
|
||||||
|
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||||
|
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||||
|
" %u is %sdiscouraged by the PNG\n specification "
|
||||||
|
"[first occurrence was at character position #%d]\n",
|
||||||
|
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||||
|
result+1);
|
||||||
|
fflush(stderr);
|
||||||
|
#ifdef FORBID_LATIN1_CTRL
|
||||||
|
wpng_info.have_text &= ~TEXT_EMAIL;
|
||||||
|
valid = FALSE;
|
||||||
|
#else
|
||||||
|
if (p[result] == 27) { /* escape character */
|
||||||
|
wpng_info.have_text &= ~TEXT_EMAIL;
|
||||||
|
valid = FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!valid);
|
||||||
|
|
||||||
|
do {
|
||||||
|
valid = TRUE;
|
||||||
|
p = textbuf + TEXT_URL_OFFSET;
|
||||||
|
fprintf(stderr, " URL: ");
|
||||||
|
fflush(stderr);
|
||||||
|
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||||
|
if (p[len-1] == '\n')
|
||||||
|
p[--len] = '\0';
|
||||||
|
wpng_info.url = p;
|
||||||
|
wpng_info.have_text |= TEXT_URL;
|
||||||
|
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||||
|
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||||
|
" %u is %sdiscouraged by the PNG\n specification "
|
||||||
|
"[first occurrence was at character position #%d]\n",
|
||||||
|
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||||
|
result+1);
|
||||||
|
fflush(stderr);
|
||||||
|
#ifdef FORBID_LATIN1_CTRL
|
||||||
|
wpng_info.have_text &= ~TEXT_URL;
|
||||||
|
valid = FALSE;
|
||||||
|
#else
|
||||||
|
if (p[result] == 27) { /* escape character */
|
||||||
|
wpng_info.have_text &= ~TEXT_URL;
|
||||||
|
valid = FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!valid);
|
||||||
|
|
||||||
|
#ifndef DOS_OS2_W32
|
||||||
|
fclose(keybd);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else if (text) {
|
||||||
|
fprintf(stderr, PROGNAME ": unable to allocate memory for text\n");
|
||||||
|
text = FALSE;
|
||||||
|
wpng_info.have_text = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* allocate libpng stuff, initialize transformations, write pre-IDAT data */
|
||||||
|
|
||||||
|
if ((rc = writepng_init(&wpng_info)) != 0) {
|
||||||
|
switch (rc) {
|
||||||
|
case 2:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": libpng initialization problem (longjmp)\n");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
fprintf(stderr, PROGNAME ": insufficient memory\n");
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": internal logic error (unexpected PNM type)\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": unknown writepng_init() error\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exit(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* free textbuf, since it's a completely local variable and all text info
|
||||||
|
* has just been written to the PNG file */
|
||||||
|
|
||||||
|
if (text && textbuf) {
|
||||||
|
free(textbuf);
|
||||||
|
textbuf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* calculate rowbytes on basis of image type; note that this becomes much
|
||||||
|
* more complicated if we choose to support PBM type, ASCII PNM types, or
|
||||||
|
* 16-bit-per-sample binary data [currently not an official NetPBM type] */
|
||||||
|
|
||||||
|
if (wpng_info.pnmtype == 5)
|
||||||
|
rowbytes = wpng_info.width;
|
||||||
|
else if (wpng_info.pnmtype == 6)
|
||||||
|
rowbytes = wpng_info.width * 3;
|
||||||
|
else /* if (wpng_info.pnmtype == 8) */
|
||||||
|
rowbytes = wpng_info.width * 4;
|
||||||
|
|
||||||
|
|
||||||
|
/* read and write the image, either in its entirety (if writing interlaced
|
||||||
|
* PNG) or row by row (if non-interlaced) */
|
||||||
|
|
||||||
|
fprintf(stderr, "Encoding image data...\n");
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
|
if (wpng_info.interlaced) {
|
||||||
|
long i;
|
||||||
|
ulg bytes;
|
||||||
|
ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */
|
||||||
|
|
||||||
|
wpng_info.image_data = (uch *)malloc(image_bytes);
|
||||||
|
wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *));
|
||||||
|
if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) {
|
||||||
|
fprintf(stderr, PROGNAME ": insufficient memory for image data\n");
|
||||||
|
writepng_cleanup(&wpng_info);
|
||||||
|
wpng_cleanup();
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
|
for (i = 0; i < wpng_info.height; ++i)
|
||||||
|
wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes;
|
||||||
|
bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile);
|
||||||
|
if (bytes != image_bytes) {
|
||||||
|
fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n",
|
||||||
|
image_bytes, bytes);
|
||||||
|
fprintf(stderr, " (continuing anyway)\n");
|
||||||
|
}
|
||||||
|
if (writepng_encode_image(&wpng_info) != 0) {
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": libpng problem (longjmp) while writing image data\n");
|
||||||
|
writepng_cleanup(&wpng_info);
|
||||||
|
wpng_cleanup();
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else /* not interlaced: write progressively (row by row) */ {
|
||||||
|
long j;
|
||||||
|
ulg bytes;
|
||||||
|
|
||||||
|
wpng_info.image_data = (uch *)malloc(rowbytes);
|
||||||
|
if (wpng_info.image_data == NULL) {
|
||||||
|
fprintf(stderr, PROGNAME ": insufficient memory for row data\n");
|
||||||
|
writepng_cleanup(&wpng_info);
|
||||||
|
wpng_cleanup();
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
|
error = 0;
|
||||||
|
for (j = wpng_info.height; j > 0L; --j) {
|
||||||
|
bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile);
|
||||||
|
if (bytes != rowbytes) {
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes,
|
||||||
|
bytes, wpng_info.height-j);
|
||||||
|
++error;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (writepng_encode_row(&wpng_info) != 0) {
|
||||||
|
fprintf(stderr, PROGNAME
|
||||||
|
": libpng problem (longjmp) while writing row %ld\n",
|
||||||
|
wpng_info.height-j);
|
||||||
|
++error;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
writepng_cleanup(&wpng_info);
|
||||||
|
wpng_cleanup();
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
if (writepng_encode_finish(&wpng_info) != 0) {
|
||||||
|
fprintf(stderr, PROGNAME ": error on final libpng call\n");
|
||||||
|
writepng_cleanup(&wpng_info);
|
||||||
|
wpng_cleanup();
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* OK, we're done (successfully): clean up all resources and quit */
|
||||||
|
|
||||||
|
fprintf(stderr, "Done.\n");
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
|
writepng_cleanup(&wpng_info);
|
||||||
|
wpng_cleanup();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int wpng_isvalid_latin1(uch *p, int len)
|
||||||
|
{
|
||||||
|
int i, result = -1;
|
||||||
|
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160)
|
||||||
|
continue; /* character is completely OK */
|
||||||
|
if (result < 0 || (p[result] != 27 && p[i] == 27))
|
||||||
|
result = i; /* mark location of first questionable one */
|
||||||
|
} /* or of first escape character (bad) */
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void wpng_cleanup(void)
|
||||||
|
{
|
||||||
|
if (wpng_info.outfile) {
|
||||||
|
fclose(wpng_info.outfile);
|
||||||
|
wpng_info.outfile = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wpng_info.infile) {
|
||||||
|
fclose(wpng_info.infile);
|
||||||
|
wpng_info.infile = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wpng_info.image_data) {
|
||||||
|
free(wpng_info.image_data);
|
||||||
|
wpng_info.image_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wpng_info.row_pointers) {
|
||||||
|
free(wpng_info.row_pointers);
|
||||||
|
wpng_info.row_pointers = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DOS_OS2_W32
|
||||||
|
|
||||||
|
static char *dos_kbd_gets(char *buf, int len)
|
||||||
|
{
|
||||||
|
int ch, count=0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
buf[count++] = ch = getche();
|
||||||
|
} while (ch != '\r' && count < len-1);
|
||||||
|
|
||||||
|
buf[count--] = '\0'; /* terminate string */
|
||||||
|
if (buf[count] == '\r') /* Enter key makes CR, so change to newline */
|
||||||
|
buf[count] = '\n';
|
||||||
|
|
||||||
|
fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DOS_OS2_W32 */
|
||||||
392
contrib/gregbook/writepng.c
Normal file
@@ -0,0 +1,392 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wpng - simple PNG-writing program writepng.c
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h> /* for exit() prototype */
|
||||||
|
|
||||||
|
#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
|
||||||
|
#include "writepng.h" /* typedefs, common macros, public prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
/* local prototype */
|
||||||
|
|
||||||
|
static void writepng_error_handler(png_structp png_ptr, png_const_charp msg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void writepng_version_info(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
|
||||||
|
PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||||
|
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||||
|
ZLIB_VERSION, zlib_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for
|
||||||
|
* unexpected pnmtype; note that outfile might be stdout */
|
||||||
|
|
||||||
|
int writepng_init(mainprog_info *mainprog_ptr)
|
||||||
|
{
|
||||||
|
png_structp png_ptr; /* note: temporary variables! */
|
||||||
|
png_infop info_ptr;
|
||||||
|
int color_type, interlace_type;
|
||||||
|
|
||||||
|
|
||||||
|
/* could also replace libpng warning-handler (final NULL), but no need: */
|
||||||
|
|
||||||
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
|
||||||
|
writepng_error_handler, NULL);
|
||||||
|
if (!png_ptr)
|
||||||
|
return 4; /* out of memory */
|
||||||
|
|
||||||
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
if (!info_ptr) {
|
||||||
|
png_destroy_write_struct(&png_ptr, NULL);
|
||||||
|
return 4; /* out of memory */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* setjmp() must be called in every function that calls a PNG-writing
|
||||||
|
* libpng function, unless an alternate error handler was installed--
|
||||||
|
* but compatible error handlers must either use longjmp() themselves
|
||||||
|
* (as in this program) or exit immediately, so here we go: */
|
||||||
|
|
||||||
|
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||||
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* make sure outfile is (re)opened in BINARY mode */
|
||||||
|
|
||||||
|
png_init_io(png_ptr, mainprog_ptr->outfile);
|
||||||
|
|
||||||
|
|
||||||
|
/* set the compression levels--in general, always want to leave filtering
|
||||||
|
* turned on (except for palette images) and allow all of the filters,
|
||||||
|
* which is the default; want 32K zlib window, unless entire image buffer
|
||||||
|
* is 16K or smaller (unknown here)--also the default; usually want max
|
||||||
|
* compression (NOT the default); and remaining compression flags should
|
||||||
|
* be left alone */
|
||||||
|
|
||||||
|
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
|
||||||
|
/*
|
||||||
|
>> this is default for no filtering; Z_FILTERED is default otherwise:
|
||||||
|
png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
|
||||||
|
>> these are all defaults:
|
||||||
|
png_set_compression_mem_level(png_ptr, 8);
|
||||||
|
png_set_compression_window_bits(png_ptr, 15);
|
||||||
|
png_set_compression_method(png_ptr, 8);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* set the image parameters appropriately */
|
||||||
|
|
||||||
|
if (mainprog_ptr->pnmtype == 5)
|
||||||
|
color_type = PNG_COLOR_TYPE_GRAY;
|
||||||
|
else if (mainprog_ptr->pnmtype == 6)
|
||||||
|
color_type = PNG_COLOR_TYPE_RGB;
|
||||||
|
else if (mainprog_ptr->pnmtype == 8)
|
||||||
|
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||||
|
else {
|
||||||
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
return 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 :
|
||||||
|
PNG_INTERLACE_NONE;
|
||||||
|
|
||||||
|
png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
|
||||||
|
mainprog_ptr->sample_depth, color_type, interlace_type,
|
||||||
|
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||||
|
|
||||||
|
if (mainprog_ptr->gamma > 0.0)
|
||||||
|
png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma);
|
||||||
|
|
||||||
|
if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */
|
||||||
|
png_color_16 background;
|
||||||
|
|
||||||
|
background.red = mainprog_ptr->bg_red;
|
||||||
|
background.green = mainprog_ptr->bg_green;
|
||||||
|
background.blue = mainprog_ptr->bg_blue;
|
||||||
|
png_set_bKGD(png_ptr, info_ptr, &background);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainprog_ptr->have_time) {
|
||||||
|
png_time modtime;
|
||||||
|
|
||||||
|
png_convert_from_time_t(&modtime, mainprog_ptr->modtime);
|
||||||
|
png_set_tIME(png_ptr, info_ptr, &modtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainprog_ptr->have_text) {
|
||||||
|
png_text text[6];
|
||||||
|
int num_text = 0;
|
||||||
|
|
||||||
|
if (mainprog_ptr->have_text & TEXT_TITLE) {
|
||||||
|
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
|
text[num_text].key = "Title";
|
||||||
|
text[num_text].text = mainprog_ptr->title;
|
||||||
|
++num_text;
|
||||||
|
}
|
||||||
|
if (mainprog_ptr->have_text & TEXT_AUTHOR) {
|
||||||
|
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
|
text[num_text].key = "Author";
|
||||||
|
text[num_text].text = mainprog_ptr->author;
|
||||||
|
++num_text;
|
||||||
|
}
|
||||||
|
if (mainprog_ptr->have_text & TEXT_DESC) {
|
||||||
|
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
|
text[num_text].key = "Description";
|
||||||
|
text[num_text].text = mainprog_ptr->desc;
|
||||||
|
++num_text;
|
||||||
|
}
|
||||||
|
if (mainprog_ptr->have_text & TEXT_COPY) {
|
||||||
|
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
|
text[num_text].key = "Copyright";
|
||||||
|
text[num_text].text = mainprog_ptr->copyright;
|
||||||
|
++num_text;
|
||||||
|
}
|
||||||
|
if (mainprog_ptr->have_text & TEXT_EMAIL) {
|
||||||
|
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
|
text[num_text].key = "E-mail";
|
||||||
|
text[num_text].text = mainprog_ptr->email;
|
||||||
|
++num_text;
|
||||||
|
}
|
||||||
|
if (mainprog_ptr->have_text & TEXT_URL) {
|
||||||
|
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
|
text[num_text].key = "URL";
|
||||||
|
text[num_text].text = mainprog_ptr->url;
|
||||||
|
++num_text;
|
||||||
|
}
|
||||||
|
png_set_text(png_ptr, info_ptr, text, num_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* write all chunks up to (but not including) first IDAT */
|
||||||
|
|
||||||
|
png_write_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/* if we wanted to write any more text info *after* the image data, we
|
||||||
|
* would set up text struct(s) here and call png_set_text() again, with
|
||||||
|
* just the new data; png_set_tIME() could also go here, but it would
|
||||||
|
* have no effect since we already called it above (only one tIME chunk
|
||||||
|
* allowed) */
|
||||||
|
|
||||||
|
|
||||||
|
/* set up the transformations: for now, just pack low-bit-depth pixels
|
||||||
|
* into bytes (one, two or four pixels per byte) */
|
||||||
|
|
||||||
|
png_set_packing(png_ptr);
|
||||||
|
/* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */
|
||||||
|
|
||||||
|
|
||||||
|
/* make sure we save our pointers for use in writepng_encode_image() */
|
||||||
|
|
||||||
|
mainprog_ptr->png_ptr = png_ptr;
|
||||||
|
mainprog_ptr->info_ptr = info_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* OK, that's all we need to do for now; return happy */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 for success, 2 for libpng (longjmp) problem */
|
||||||
|
|
||||||
|
int writepng_encode_image(mainprog_info *mainprog_ptr)
|
||||||
|
{
|
||||||
|
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||||
|
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* as always, setjmp() must be called in every function that calls a
|
||||||
|
* PNG-writing libpng function */
|
||||||
|
|
||||||
|
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||||
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
mainprog_ptr->png_ptr = NULL;
|
||||||
|
mainprog_ptr->info_ptr = NULL;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* and now we just write the whole image; libpng takes care of interlacing
|
||||||
|
* for us */
|
||||||
|
|
||||||
|
png_write_image(png_ptr, mainprog_ptr->row_pointers);
|
||||||
|
|
||||||
|
|
||||||
|
/* since that's it, we also close out the end of the PNG file now--if we
|
||||||
|
* had any text or time info to write after the IDATs, second argument
|
||||||
|
* would be info_ptr, but we optimize slightly by sending NULL pointer: */
|
||||||
|
|
||||||
|
png_write_end(png_ptr, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 if succeeds, 2 if libpng problem */
|
||||||
|
|
||||||
|
int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */
|
||||||
|
{
|
||||||
|
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||||
|
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* as always, setjmp() must be called in every function that calls a
|
||||||
|
* PNG-writing libpng function */
|
||||||
|
|
||||||
|
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||||
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
mainprog_ptr->png_ptr = NULL;
|
||||||
|
mainprog_ptr->info_ptr = NULL;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* image_data points at our one row of image data */
|
||||||
|
|
||||||
|
png_write_row(png_ptr, mainprog_ptr->image_data);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* returns 0 if succeeds, 2 if libpng problem */
|
||||||
|
|
||||||
|
int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */
|
||||||
|
{
|
||||||
|
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||||
|
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* as always, setjmp() must be called in every function that calls a
|
||||||
|
* PNG-writing libpng function */
|
||||||
|
|
||||||
|
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||||
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
mainprog_ptr->png_ptr = NULL;
|
||||||
|
mainprog_ptr->info_ptr = NULL;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* close out PNG file; if we had any text or time info to write after
|
||||||
|
* the IDATs, second argument would be info_ptr: */
|
||||||
|
|
||||||
|
png_write_end(png_ptr, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void writepng_cleanup(mainprog_info *mainprog_ptr)
|
||||||
|
{
|
||||||
|
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||||
|
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||||
|
|
||||||
|
if (png_ptr && info_ptr)
|
||||||
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void writepng_error_handler(png_structp png_ptr, png_const_charp msg)
|
||||||
|
{
|
||||||
|
mainprog_info *mainprog_ptr;
|
||||||
|
|
||||||
|
/* This function, aside from the extra step of retrieving the "error
|
||||||
|
* pointer" (below) and the fact that it exists within the application
|
||||||
|
* rather than within libpng, is essentially identical to libpng's
|
||||||
|
* default error handler. The second point is critical: since both
|
||||||
|
* setjmp() and longjmp() are called from the same code, they are
|
||||||
|
* guaranteed to have compatible notions of how big a jmp_buf is,
|
||||||
|
* regardless of whether _BSD_SOURCE or anything else has (or has not)
|
||||||
|
* been defined. */
|
||||||
|
|
||||||
|
fprintf(stderr, "writepng libpng error: %s\n", msg);
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
|
mainprog_ptr = png_get_error_ptr(png_ptr);
|
||||||
|
if (mainprog_ptr == NULL) { /* we are completely hosed now */
|
||||||
|
fprintf(stderr,
|
||||||
|
"writepng severe error: jmpbuf not recoverable; terminating.\n");
|
||||||
|
fflush(stderr);
|
||||||
|
exit(99);
|
||||||
|
}
|
||||||
|
|
||||||
|
longjmp(mainprog_ptr->jmpbuf, 1);
|
||||||
|
}
|
||||||
133
contrib/gregbook/writepng.h
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wpng - simple PNG-writing program writepng.h
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided "as is," without warranty of any kind,
|
||||||
|
express or implied. In no event shall the author or contributors
|
||||||
|
be held liable for any damages arising in any way from the use of
|
||||||
|
this software.
|
||||||
|
|
||||||
|
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||||
|
redistribute this software according to the terms of one of the
|
||||||
|
following two licenses (at your option):
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 1 ("BSD-like with advertising clause"):
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute
|
||||||
|
it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, disclaimer, and this list of conditions in the documenta-
|
||||||
|
tion and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this
|
||||||
|
software must display the following acknowledgment:
|
||||||
|
|
||||||
|
This product includes software developed by Greg Roelofs
|
||||||
|
and contributors for the book, "PNG: The Definitive Guide,"
|
||||||
|
published by O'Reilly and Associates.
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE 2 (GNU GPL v2 or later):
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
# define TRUE 1
|
||||||
|
# define FALSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
# define MAX(a,b) ((a) > (b)? (a) : (b))
|
||||||
|
# define MIN(a,b) ((a) < (b)? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
|
||||||
|
#else
|
||||||
|
# define Trace(x) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TEXT_TITLE 0x01
|
||||||
|
#define TEXT_AUTHOR 0x02
|
||||||
|
#define TEXT_DESC 0x04
|
||||||
|
#define TEXT_COPY 0x08
|
||||||
|
#define TEXT_EMAIL 0x10
|
||||||
|
#define TEXT_URL 0x20
|
||||||
|
|
||||||
|
#define TEXT_TITLE_OFFSET 0
|
||||||
|
#define TEXT_AUTHOR_OFFSET 72
|
||||||
|
#define TEXT_COPY_OFFSET (2*72)
|
||||||
|
#define TEXT_EMAIL_OFFSET (3*72)
|
||||||
|
#define TEXT_URL_OFFSET (4*72)
|
||||||
|
#define TEXT_DESC_OFFSET (5*72)
|
||||||
|
|
||||||
|
typedef unsigned char uch;
|
||||||
|
typedef unsigned short ush;
|
||||||
|
typedef unsigned long ulg;
|
||||||
|
|
||||||
|
typedef struct _mainprog_info {
|
||||||
|
double gamma;
|
||||||
|
long width;
|
||||||
|
long height;
|
||||||
|
time_t modtime;
|
||||||
|
FILE *infile;
|
||||||
|
FILE *outfile;
|
||||||
|
void *png_ptr;
|
||||||
|
void *info_ptr;
|
||||||
|
uch *image_data;
|
||||||
|
uch **row_pointers;
|
||||||
|
char *title;
|
||||||
|
char *author;
|
||||||
|
char *desc;
|
||||||
|
char *copyright;
|
||||||
|
char *email;
|
||||||
|
char *url;
|
||||||
|
int filter; /* command-line-filter flag, not PNG row filter! */
|
||||||
|
int pnmtype;
|
||||||
|
int sample_depth;
|
||||||
|
int interlaced;
|
||||||
|
int have_bg;
|
||||||
|
int have_time;
|
||||||
|
int have_text;
|
||||||
|
jmp_buf jmpbuf;
|
||||||
|
uch bg_red;
|
||||||
|
uch bg_green;
|
||||||
|
uch bg_blue;
|
||||||
|
} mainprog_info;
|
||||||
|
|
||||||
|
|
||||||
|
/* prototypes for public functions in writepng.c */
|
||||||
|
|
||||||
|
void writepng_version_info(void);
|
||||||
|
|
||||||
|
int writepng_init(mainprog_info *mainprog_ptr);
|
||||||
|
|
||||||
|
int writepng_encode_image(mainprog_info *mainprog_ptr);
|
||||||
|
|
||||||
|
int writepng_encode_row(mainprog_info *mainprog_ptr);
|
||||||
|
|
||||||
|
int writepng_encode_finish(mainprog_info *mainprog_ptr);
|
||||||
|
|
||||||
|
void writepng_cleanup(mainprog_info *mainprog_ptr);
|
||||||
153
contrib/pngminus/README
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
PngMinus
|
||||||
|
--------
|
||||||
|
(copyright Willem van Schaik, 1999)
|
||||||
|
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and
|
||||||
|
its documentation for any purpose and without fee is hereby granted,
|
||||||
|
provided that the above copyright notice appear in all copies and
|
||||||
|
that both that copyright notice and this permission notice appear in
|
||||||
|
supporting documentation. This software is provided "as is" without
|
||||||
|
express or implied warranty.
|
||||||
|
|
||||||
|
|
||||||
|
Some history
|
||||||
|
------------
|
||||||
|
Soon after the creation of PNG in 1995, the need was felt for a set of
|
||||||
|
pnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I
|
||||||
|
(Willem van Schaik) started such a project. Luckily we discovered this
|
||||||
|
and merged the two together into pnmtopng.tar.gz, which is available
|
||||||
|
from a/o ftp://ftp.simplesystems.org/pub/libpng/png/.
|
||||||
|
|
||||||
|
These two utilities have many, many options and make use of most of the
|
||||||
|
features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes
|
||||||
|
the utilities quite complex and by now not anymore very maintainable.
|
||||||
|
When we wrote these programs, libpng was still in an early stage.
|
||||||
|
Therefore, lots of the functionality that we put in our software can now
|
||||||
|
be done using transform-functions in libpng.
|
||||||
|
|
||||||
|
Finally, to compile these programs, you need to have installed and
|
||||||
|
compiled three libraries: libpng, zlib and netpbm. Especially the latter
|
||||||
|
makes the whole setup a bit bulky. But that's unavoidable given the many
|
||||||
|
features of pnmtopng.
|
||||||
|
|
||||||
|
|
||||||
|
What now
|
||||||
|
--------
|
||||||
|
At this moment libpng is in a very stable state and can do much of the
|
||||||
|
work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new
|
||||||
|
interface of libpng. Hence, it is time for a rewrite from the ground up
|
||||||
|
of pnmtopng and pngtopnm. This will happen in the near future (stay
|
||||||
|
tuned). The new package will get a different name to distinguish it from
|
||||||
|
the old one: PngPlus.
|
||||||
|
|
||||||
|
To experiment a bit with the new interface of libpng, I started off with
|
||||||
|
a small prototype that contains only the basic functionality. It doesn't
|
||||||
|
have any of the options to read or write special chunks and it will do
|
||||||
|
no gamma correction. But this makes it also a simple program that is
|
||||||
|
quite easy to understand and can serve well as a template for other
|
||||||
|
software developments. (By now there are of course a couple of programs,
|
||||||
|
like Greg Roelofs' rpng/wpng, that can be used just as good.)
|
||||||
|
|
||||||
|
|
||||||
|
Can and can not
|
||||||
|
---------------
|
||||||
|
As this is the small brother of the future PngPlus, I called this fellow
|
||||||
|
PngMinus. Because I started this development in good-old Turbo-C, I
|
||||||
|
avoided the use the netpbm library, which requires DOS extenders. Again,
|
||||||
|
another reason to call it PngMinus (minus netpbm :-). So, part of the
|
||||||
|
program are some elementary routines to read / write pgm- and ppm-files.
|
||||||
|
It does not read b&w pbm-files.
|
||||||
|
|
||||||
|
The downside of this approach is that you can not use them on images
|
||||||
|
that require blocks of memory bigger than 64k (the DOS version). For
|
||||||
|
larger images you will get an out-of-memory error.
|
||||||
|
|
||||||
|
As said before, PngMinus doesn't correct for gamma. When reading
|
||||||
|
png-files you can do this just as well by piping the output of png2pnm
|
||||||
|
to pnmgamma, one of the standard PbmPlus tools. This same scenario will
|
||||||
|
most probably also be followed in the full-blown future PngPlus, with
|
||||||
|
the addition of course of the possibility to create gamma-chunks when
|
||||||
|
writing png-files.
|
||||||
|
|
||||||
|
On the other hand it supports alpha-channels. When reading a png-image
|
||||||
|
you can write the alpha-channel into a pgm-file. And when creating an
|
||||||
|
RGB+A png-image, you just combine a ppm-file with a corresponding
|
||||||
|
pgm-file containing the alpha-channel. When reading, transparency chunks
|
||||||
|
are converted into an alpha-channel and from there on treated the same
|
||||||
|
way.
|
||||||
|
|
||||||
|
Finally you can opt for writing ascii or binary pgm- and ppm-files. When
|
||||||
|
the bit-depth is 16, the format will always be ascii.
|
||||||
|
|
||||||
|
|
||||||
|
Using it
|
||||||
|
--------
|
||||||
|
To distinguish them from pnmtopng and PngPlus, the utilities are named
|
||||||
|
png2pnm and pnm2png (2 instead of to). The input- and output-files can
|
||||||
|
be given as parameters or through redirection. Therefore the programs
|
||||||
|
can be part of a pipe.
|
||||||
|
|
||||||
|
To list the options type "png2pnm -h" or "pnm2png -h".
|
||||||
|
|
||||||
|
|
||||||
|
Just like Scandinavian furniture
|
||||||
|
--------------------------------
|
||||||
|
You have to put it together yourself. I did test the software under
|
||||||
|
MS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both
|
||||||
|
cases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK,
|
||||||
|
however some older libpng versions have a bug in pngmem.c when using
|
||||||
|
Turbo-C 3.0 (see below).
|
||||||
|
|
||||||
|
You can build it using one of the two makefiles (make -f makefile.###)
|
||||||
|
or use the batch/script files pngminus.bat / pngminus.sh. This assumes
|
||||||
|
that you have built the libraries in ../libpng and ../zlib. Using Linux,
|
||||||
|
make sure that you have built libpng with makefile.std and not
|
||||||
|
makefile.linux (also called .lnx in earlier versions of libpng). The
|
||||||
|
latter creates a .so shared-library, while the PngMinus makefile assumes
|
||||||
|
a normal .a static library.
|
||||||
|
|
||||||
|
If you create a ../pngsuite directory and then store the basn####.png
|
||||||
|
files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can
|
||||||
|
test in one go the proper functioning of PngMinus, see png2pnm.bat and
|
||||||
|
pnm2png.bat (or the .sh versions).
|
||||||
|
|
||||||
|
|
||||||
|
Warranty
|
||||||
|
-------
|
||||||
|
Please, remember that this was just a small experiment to learn a few
|
||||||
|
things. It will have many unforeseen features <vbg>. Who said bugs? Use
|
||||||
|
it when you are in need for something simple or when you want to start
|
||||||
|
developing your own stuff.
|
||||||
|
|
||||||
|
|
||||||
|
The Turbo bug
|
||||||
|
-------------
|
||||||
|
** pngmem.old
|
||||||
|
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
|
||||||
|
hptr += 16L;
|
||||||
|
** pngmem.c
|
||||||
|
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
|
||||||
|
hptr = hptr + 16L;
|
||||||
|
**
|
||||||
|
|
||||||
|
** pngmem.old
|
||||||
|
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||||
|
hptr += (png_uint_32)65536L;
|
||||||
|
** pngmem.c
|
||||||
|
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||||
|
hptr = hptr + 65536L;
|
||||||
|
**
|
||||||
|
|
||||||
|
|
||||||
|
The end
|
||||||
|
-------
|
||||||
|
Willem van Schaik
|
||||||
|
mailto:willem@schaik.com
|
||||||
|
http://www.schaik.com/png/
|
||||||
|
-------
|
||||||
|
Oct 1999
|
||||||
|
|
||||||
65
contrib/pngminus/makefile.std
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# Makefile for PngMinus (png2pnm and pnm2png)
|
||||||
|
# Linux / Unix
|
||||||
|
|
||||||
|
#CC=cc
|
||||||
|
CC=gcc
|
||||||
|
LD=$(CC)
|
||||||
|
|
||||||
|
RM=rm -f
|
||||||
|
|
||||||
|
#PNGPATH = /usr/local
|
||||||
|
#PNGINC = -I$(PNGPATH)/include/libpng12
|
||||||
|
#PNGLIB = -L$(PNGPATH)/lib -lpng12
|
||||||
|
#PNGLIBS = $(PNGPATH)/lib/libpng12.a
|
||||||
|
PNGINC = -I../..
|
||||||
|
PNGLIB = -L../.. -lpng
|
||||||
|
PNGLIBS = ../../libpng.a
|
||||||
|
|
||||||
|
#ZPATH = /usr/local
|
||||||
|
#ZINC = -I$(ZPATH)/include
|
||||||
|
#ZLIB = -L$(ZPATH)/lib -lz
|
||||||
|
#ZLIBS = $(ZPATH)/lib/libz.a
|
||||||
|
ZINC = -I../../../zlib
|
||||||
|
ZLIB = -L../../../zlib -lz
|
||||||
|
ZLIBS = ../../../zlib/libz.a
|
||||||
|
|
||||||
|
CFLAGS=-O3 $(PNGINC) $(ZINC)
|
||||||
|
LDFLAGS=$(PNGLIB) $(ZLIB)
|
||||||
|
LDFLAGSS=$(PNGLIBS) $(ZLIBS)
|
||||||
|
C=.c
|
||||||
|
O=.o
|
||||||
|
L=.a
|
||||||
|
E=
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
|
||||||
|
#all: png2pnm$(E) pnm2png$(E)
|
||||||
|
all: png2pnm$(E) pnm2png$(E) png2pnm-static$(E) pnm2png-static$(E)
|
||||||
|
|
||||||
|
png2pnm$(O): png2pnm$(C)
|
||||||
|
$(CC) -c $(CFLAGS) png2pnm$(C)
|
||||||
|
|
||||||
|
png2pnm$(E): png2pnm$(O)
|
||||||
|
$(LD) -o png2pnm$(E) png2pnm$(O) $(LDFLAGS) -lm
|
||||||
|
|
||||||
|
png2pnm-static$(E): png2pnm$(O)
|
||||||
|
$(LD) -o png2pnm-static$(E) png2pnm$(O) $(LDFLAGSS) -lm
|
||||||
|
|
||||||
|
pnm2png$(O): pnm2png$(C)
|
||||||
|
$(CC) -c $(CFLAGS) pnm2png$(C)
|
||||||
|
|
||||||
|
pnm2png$(E): pnm2png$(O)
|
||||||
|
$(LD) -o pnm2png$(E) pnm2png$(O) $(LDFLAGS) -lm
|
||||||
|
|
||||||
|
pnm2png-static$(E): pnm2png$(O)
|
||||||
|
$(LD) -o pnm2png-static$(E) pnm2png$(O) $(LDFLAGSS) -lm
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) png2pnm$(O)
|
||||||
|
$(RM) pnm2png$(O)
|
||||||
|
$(RM) png2pnm$(E)
|
||||||
|
$(RM) pnm2png$(E)
|
||||||
|
$(RM) png2pnm-static$(E)
|
||||||
|
$(RM) pnm2png-static$(E)
|
||||||
|
|
||||||
|
# End of makefile for png2pnm / pnm2png
|
||||||
38
contrib/pngminus/makefile.tc3
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Makefile for PngMinus (png2pnm and pnm2png)
|
||||||
|
# TurboC++ 3.0
|
||||||
|
|
||||||
|
CC=tcc -Ic:\tc3\inc
|
||||||
|
LD=tcc -Lc:\tc3\lib
|
||||||
|
LB=tlib
|
||||||
|
RM=del
|
||||||
|
CP=copy
|
||||||
|
MODEL=l
|
||||||
|
CCFLAGS=-O -m$(MODEL) -I..\libpng -I..\zlib
|
||||||
|
LDFLAGS=-m$(MODEL) -L..\libpng -L..\zlib
|
||||||
|
C=.c
|
||||||
|
O=.obj
|
||||||
|
L=.lib
|
||||||
|
E=.exe
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
|
||||||
|
all: png2pnm$(E) pnm2png$(E)
|
||||||
|
|
||||||
|
png2pnm$(O): png2pnm$(C)
|
||||||
|
$(CC) -c $(CCFLAGS) png2pnm$(C)
|
||||||
|
|
||||||
|
png2pnm$(E): png2pnm$(O)
|
||||||
|
$(LD) $(LDFLAGS) png2pnm$(O) libpng$(L) zlib$(L)
|
||||||
|
|
||||||
|
pnm2png$(O): pnm2png$(C)
|
||||||
|
$(CC) -c $(CCFLAGS) pnm2png$(C)
|
||||||
|
|
||||||
|
pnm2png$(E): pnm2png$(O)
|
||||||
|
$(LD) $(LDFLAGS) pnm2png$(O) libpng$(L) zlib$(L)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *$(O)
|
||||||
|
$(RM) *$(E)
|
||||||
|
|
||||||
|
# End of makefile for png2pnm / pnm2png
|
||||||
|
|
||||||
92
contrib/pngminus/makevms.com
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
$!------------------------------------------------------------------------------
|
||||||
|
$! make Contrib programs of libpng under OpenVMS
|
||||||
|
$!
|
||||||
|
$!
|
||||||
|
$! Look for the compiler used
|
||||||
|
$!
|
||||||
|
$ zlibsrc = "[---.zlib]"
|
||||||
|
$ ccopt="/include=(''zlibsrc',[--])"
|
||||||
|
$ if f$getsyi("HW_MODEL").ge.1024
|
||||||
|
$ then
|
||||||
|
$ ccopt = "/prefix=all"+ccopt
|
||||||
|
$ comp = "__decc__=1"
|
||||||
|
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||||
|
$ else
|
||||||
|
$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
|
||||||
|
$ then
|
||||||
|
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||||
|
$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
|
||||||
|
$ then
|
||||||
|
$ comp = "__gcc__=1"
|
||||||
|
$ CC :== GCC
|
||||||
|
$ else
|
||||||
|
$ comp = "__vaxc__=1"
|
||||||
|
$ endif
|
||||||
|
$ else
|
||||||
|
$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
|
||||||
|
$ ccopt = "/decc/prefix=all"+ccopt
|
||||||
|
$ comp = "__decc__=1"
|
||||||
|
$ endif
|
||||||
|
$ endif
|
||||||
|
$ open/write lopt lib.opt
|
||||||
|
$ write lopt "[--]libpng.olb/lib"
|
||||||
|
$ write lopt "''zlibsrc'libz.olb/lib"
|
||||||
|
$ close lopt
|
||||||
|
$ open/write xopt x11.opt
|
||||||
|
$ write xopt "sys$library:decw$xlibshr.exe/share"
|
||||||
|
$ close xopt
|
||||||
|
$ write sys$output "Compiling PNG contrib programs ..."
|
||||||
|
$ write sys$output "Building pnm2png..."
|
||||||
|
$ CALL MAKE pnm2png.OBJ "cc ''CCOPT' pnm2png" -
|
||||||
|
pnm2png.c
|
||||||
|
$ call make pnm2png.exe -
|
||||||
|
"LINK pnm2png,lib.opt/opt" -
|
||||||
|
pnm2png.obj
|
||||||
|
$ write sys$output "Building png2pnm..."
|
||||||
|
$ CALL MAKE png2pnm.OBJ "cc ''CCOPT' png2pnm" -
|
||||||
|
png2pnm.c
|
||||||
|
$ call make png2pnm.exe -
|
||||||
|
"LINK png2pnm,lib.opt/opt" -
|
||||||
|
png2pnm.obj
|
||||||
|
$ exit
|
||||||
|
$!
|
||||||
|
$!
|
||||||
|
$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
|
||||||
|
$ V = 'F$Verify(0)
|
||||||
|
$! P1 = What we are trying to make
|
||||||
|
$! P2 = Command to make it
|
||||||
|
$! P3 - P8 What it depends on
|
||||||
|
$
|
||||||
|
$ If F$Search(P1) .Eqs. "" Then Goto Makeit
|
||||||
|
$ Time = F$CvTime(F$File(P1,"RDT"))
|
||||||
|
$arg=3
|
||||||
|
$Loop:
|
||||||
|
$ Argument = P'arg
|
||||||
|
$ If Argument .Eqs. "" Then Goto Exit
|
||||||
|
$ El=0
|
||||||
|
$Loop2:
|
||||||
|
$ File = F$Element(El," ",Argument)
|
||||||
|
$ If File .Eqs. " " Then Goto Endl
|
||||||
|
$ AFile = ""
|
||||||
|
$Loop3:
|
||||||
|
$ OFile = AFile
|
||||||
|
$ AFile = F$Search(File)
|
||||||
|
$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
|
||||||
|
$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
|
||||||
|
$ Goto Loop3
|
||||||
|
$NextEL:
|
||||||
|
$ El = El + 1
|
||||||
|
$ Goto Loop2
|
||||||
|
$EndL:
|
||||||
|
$ arg=arg+1
|
||||||
|
$ If arg .Le. 8 Then Goto Loop
|
||||||
|
$ Goto Exit
|
||||||
|
$
|
||||||
|
$Makeit:
|
||||||
|
$ VV=F$VERIFY(0)
|
||||||
|
$ write sys$output P2
|
||||||
|
$ 'P2
|
||||||
|
$ VV='F$Verify(VV)
|
||||||
|
$Exit:
|
||||||
|
$ If V Then Set Verify
|
||||||
|
$ENDSUBROUTINE
|
||||||
41
contrib/pngminus/png2pnm.bat
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
REM -- grayscale
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn0g01.png basn0g01.pgm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn0g02.png basn0g02.pgm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn0g04.png basn0g04.pgm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn0g08.png basn0g08.pgm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn0g16.png basn0g16.pgm
|
||||||
|
REM -- full-color
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn2c08.png basn2c08.ppm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn2c16.png basn2c16.ppm
|
||||||
|
REM -- palletted
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn3p01.png basn3p01.ppm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn3p02.png basn3p02.ppm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn3p04.png basn3p04.ppm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn3p08.png basn3p08.ppm
|
||||||
|
REM -- gray with alpha-channel
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn4a08.png basn4a08.pgm
|
||||||
|
png2pnm.exe -noraw ..\pngsuite\basn4a16.png basn4a16.pgm
|
||||||
|
REM -- color with alpha-channel
|
||||||
|
png2pnm.exe -noraw -alpha basn6a08.pgm ..\pngsuite\basn6a08.png basn6a08.ppm
|
||||||
|
png2pnm.exe -noraw -alpha basn6a16.pgm ..\pngsuite\basn6a16.png basn6a16.ppm
|
||||||
|
REM -- grayscale
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn0g01.png rawn0g01.pgm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn0g02.png rawn0g02.pgm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn0g04.png rawn0g04.pgm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn0g08.png rawn0g08.pgm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn0g16.png rawn0g16.pgm
|
||||||
|
REM -- full-color
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn2c08.png rawn2c08.ppm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn2c16.png rawn2c16.ppm
|
||||||
|
REM -- palletted
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn3p01.png rawn3p01.ppm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn3p02.png rawn3p02.ppm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn3p04.png rawn3p04.ppm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn3p08.png rawn3p08.ppm
|
||||||
|
REM -- gray with alpha-channel
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn4a08.png rawn4a08.pgm
|
||||||
|
png2pnm.exe -raw ..\pngsuite\basn4a16.png rawn4a16.pgm
|
||||||
|
REM -- color with alpha-channel
|
||||||
|
png2pnm.exe -noraw -alpha rawn6a08.pgm ..\pngsuite\basn6a08.png rawn6a08.ppm
|
||||||
|
png2pnm.exe -noraw -alpha rawn6a16.pgm ..\pngsuite\basn6a16.png rawn6a16.ppm
|
||||||
|
|
||||||
430
contrib/pngminus/png2pnm.c
Normal file
@@ -0,0 +1,430 @@
|
|||||||
|
/*
|
||||||
|
* png2pnm.c --- conversion from PNG-file to PGM/PPM-file
|
||||||
|
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
|
||||||
|
*
|
||||||
|
* version 1.0 - 1999.10.15 - First version.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software and
|
||||||
|
* its documentation for any purpose and without fee is hereby granted,
|
||||||
|
* provided that the above copyright notice appear in all copies and
|
||||||
|
* that both that copyright notice and this permission notice appear in
|
||||||
|
* supporting documentation. This software is provided "as is" without
|
||||||
|
* express or implied warranty.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
#include <mem.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BOOL
|
||||||
|
#define BOOL unsigned char
|
||||||
|
#endif
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE (BOOL) 1
|
||||||
|
#endif
|
||||||
|
#ifndef FALSE
|
||||||
|
#define FALSE (BOOL) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
#define STDIN 0
|
||||||
|
#define STDOUT 1
|
||||||
|
#define STDERR 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* to make png2pnm verbose so we can find problems (needs to be before png.h) */
|
||||||
|
#ifndef PNG_DEBUG
|
||||||
|
#define PNG_DEBUG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "png.h"
|
||||||
|
|
||||||
|
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
||||||
|
#ifndef png_jmpbuf
|
||||||
|
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* function prototypes */
|
||||||
|
|
||||||
|
int main (int argc, char *argv[]);
|
||||||
|
void usage ();
|
||||||
|
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* main
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
FILE *fp_rd = stdin;
|
||||||
|
FILE *fp_wr = stdout;
|
||||||
|
FILE *fp_al = NULL;
|
||||||
|
BOOL raw = TRUE;
|
||||||
|
BOOL alpha = FALSE;
|
||||||
|
int argi;
|
||||||
|
|
||||||
|
for (argi = 1; argi < argc; argi++)
|
||||||
|
{
|
||||||
|
if (argv[argi][0] == '-')
|
||||||
|
{
|
||||||
|
switch (argv[argi][1])
|
||||||
|
{
|
||||||
|
case 'n':
|
||||||
|
raw = FALSE;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
raw = TRUE;
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
alpha = TRUE;
|
||||||
|
argi++;
|
||||||
|
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, "Error: can not create alpha-channel file %s\n", argv[argi]);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
case '?':
|
||||||
|
usage();
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf (stderr, "PNG2PNM\n");
|
||||||
|
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
|
||||||
|
usage();
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
} /* end switch */
|
||||||
|
}
|
||||||
|
else if (fp_rd == stdin)
|
||||||
|
{
|
||||||
|
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNG2PNM\n");
|
||||||
|
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fp_wr == stdout)
|
||||||
|
{
|
||||||
|
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNG2PNM\n");
|
||||||
|
fprintf (stderr, "Error: can not create file %s\n", argv[argi]);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNG2PNM\n");
|
||||||
|
fprintf (stderr, "Error: too many parameters\n");
|
||||||
|
usage();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} /* end for */
|
||||||
|
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
/* set stdin/stdout if required to binary */
|
||||||
|
if (fp_rd == stdin)
|
||||||
|
{
|
||||||
|
setmode (STDIN, O_BINARY);
|
||||||
|
}
|
||||||
|
if ((raw) && (fp_wr == stdout))
|
||||||
|
{
|
||||||
|
setmode (STDOUT, O_BINARY);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* call the conversion program itself */
|
||||||
|
if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNG2PNM\n");
|
||||||
|
fprintf (stderr, "Error: unsuccessful convertion of PNG-image\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close input file */
|
||||||
|
fclose (fp_rd);
|
||||||
|
/* close output file */
|
||||||
|
fclose (fp_wr);
|
||||||
|
/* close alpha file */
|
||||||
|
if (alpha)
|
||||||
|
fclose (fp_al);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* usage
|
||||||
|
*/
|
||||||
|
|
||||||
|
void usage()
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNG2PNM\n");
|
||||||
|
fprintf (stderr, " by Willem van Schaik, 1999\n");
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
|
||||||
|
#else
|
||||||
|
fprintf (stderr, " for Linux (and Unix) compilers\n");
|
||||||
|
#endif
|
||||||
|
fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
|
||||||
|
fprintf (stderr, " or: ... | png2pnm [options]\n");
|
||||||
|
fprintf (stderr, "Options:\n");
|
||||||
|
fprintf (stderr, " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
|
||||||
|
fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
|
||||||
|
fprintf (stderr, " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
|
||||||
|
fprintf (stderr, " -h | -? print this help-information\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* png2pnm
|
||||||
|
*/
|
||||||
|
|
||||||
|
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha)
|
||||||
|
{
|
||||||
|
png_struct *png_ptr = NULL;
|
||||||
|
png_info *info_ptr = NULL;
|
||||||
|
png_byte buf[8];
|
||||||
|
png_byte *png_pixels = NULL;
|
||||||
|
png_byte **row_pointers = NULL;
|
||||||
|
png_byte *pix_ptr = NULL;
|
||||||
|
png_uint_32 row_bytes;
|
||||||
|
|
||||||
|
png_uint_32 width;
|
||||||
|
png_uint_32 height;
|
||||||
|
int bit_depth;
|
||||||
|
int channels;
|
||||||
|
int color_type;
|
||||||
|
int alpha_present;
|
||||||
|
int row, col;
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
long dep_16;
|
||||||
|
|
||||||
|
/* read and check signature in PNG file */
|
||||||
|
ret = fread (buf, 1, 8, png_file);
|
||||||
|
if (ret != 8)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
ret = !png_sig_cmp (buf, 0, 8);
|
||||||
|
if (!ret)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* create png and info structures */
|
||||||
|
|
||||||
|
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
if (!png_ptr)
|
||||||
|
return FALSE; /* out of memory */
|
||||||
|
|
||||||
|
info_ptr = png_create_info_struct (png_ptr);
|
||||||
|
if (!info_ptr)
|
||||||
|
{
|
||||||
|
png_destroy_read_struct (&png_ptr, NULL, NULL);
|
||||||
|
return FALSE; /* out of memory */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setjmp (png_jmpbuf(png_ptr)))
|
||||||
|
{
|
||||||
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set up the input control for C streams */
|
||||||
|
png_init_io (png_ptr, png_file);
|
||||||
|
png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
|
||||||
|
|
||||||
|
/* read the file information */
|
||||||
|
png_read_info (png_ptr, info_ptr);
|
||||||
|
|
||||||
|
/* get size and bit-depth of the PNG-image */
|
||||||
|
png_get_IHDR (png_ptr, info_ptr,
|
||||||
|
&width, &height, &bit_depth, &color_type,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
|
/* set-up the transformations */
|
||||||
|
|
||||||
|
/* transform paletted images into full-color rgb */
|
||||||
|
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_set_expand (png_ptr);
|
||||||
|
/* expand images to bit-depth 8 (only applicable for grayscale images) */
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||||
|
png_set_expand (png_ptr);
|
||||||
|
/* transform transparency maps into full alpha-channel */
|
||||||
|
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||||
|
png_set_expand (png_ptr);
|
||||||
|
|
||||||
|
#ifdef NJET
|
||||||
|
/* downgrade 16-bit images to 8 bit */
|
||||||
|
if (bit_depth == 16)
|
||||||
|
png_set_strip_16 (png_ptr);
|
||||||
|
/* transform grayscale images into full-color */
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||||
|
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
png_set_gray_to_rgb (png_ptr);
|
||||||
|
/* only if file has a file gamma, we do a correction */
|
||||||
|
if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
|
||||||
|
png_set_gamma (png_ptr, (double) 2.2, file_gamma);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* all transformations have been registered; now update info_ptr data,
|
||||||
|
* get rowbytes and channels, and allocate image memory */
|
||||||
|
|
||||||
|
png_read_update_info (png_ptr, info_ptr);
|
||||||
|
|
||||||
|
/* get the new color-type and bit-depth (after expansion/stripping) */
|
||||||
|
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
|
/* check for 16-bit files */
|
||||||
|
if (bit_depth == 16)
|
||||||
|
{
|
||||||
|
raw = FALSE;
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
pnm_file->flags &= ~((unsigned) _F_BIN);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* calculate new number of channels and store alpha-presence */
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||||
|
channels = 1;
|
||||||
|
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
channels = 2;
|
||||||
|
else if (color_type == PNG_COLOR_TYPE_RGB)
|
||||||
|
channels = 3;
|
||||||
|
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||||
|
channels = 4;
|
||||||
|
else
|
||||||
|
channels = 0; /* should never happen */
|
||||||
|
alpha_present = (channels - 1) % 2;
|
||||||
|
|
||||||
|
/* check if alpha is expected to be present in file */
|
||||||
|
if (alpha && !alpha_present)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNG2PNM\n");
|
||||||
|
fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||||
|
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
|
||||||
|
|
||||||
|
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) {
|
||||||
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
|
||||||
|
{
|
||||||
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||||
|
free (png_pixels);
|
||||||
|
png_pixels = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the individual row_pointers to point at the correct offsets */
|
||||||
|
for (i = 0; i < (height); i++)
|
||||||
|
row_pointers[i] = png_pixels + i * row_bytes;
|
||||||
|
|
||||||
|
/* now we can go ahead and just read the whole image */
|
||||||
|
png_read_image (png_ptr, row_pointers);
|
||||||
|
|
||||||
|
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||||
|
png_read_end (png_ptr, info_ptr);
|
||||||
|
|
||||||
|
/* clean up after the read, and free any memory allocated - REQUIRED */
|
||||||
|
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
|
||||||
|
|
||||||
|
/* write header of PNM file */
|
||||||
|
|
||||||
|
if ((color_type == PNG_COLOR_TYPE_GRAY) ||
|
||||||
|
(color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||||
|
{
|
||||||
|
fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2");
|
||||||
|
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
||||||
|
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||||
|
}
|
||||||
|
else if ((color_type == PNG_COLOR_TYPE_RGB) ||
|
||||||
|
(color_type == PNG_COLOR_TYPE_RGB_ALPHA))
|
||||||
|
{
|
||||||
|
fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3");
|
||||||
|
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
||||||
|
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write header of PGM file with alpha channel */
|
||||||
|
|
||||||
|
if ((alpha) &&
|
||||||
|
((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
|
||||||
|
(color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
|
||||||
|
{
|
||||||
|
fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2");
|
||||||
|
fprintf (alpha_file, "%d %d\n", (int) width, (int) height);
|
||||||
|
fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write data to PNM file */
|
||||||
|
pix_ptr = png_pixels;
|
||||||
|
|
||||||
|
for (row = 0; row < height; row++)
|
||||||
|
{
|
||||||
|
for (col = 0; col < width; col++)
|
||||||
|
{
|
||||||
|
for (i = 0; i < (channels - alpha_present); i++)
|
||||||
|
{
|
||||||
|
if (raw)
|
||||||
|
fputc ((int) *pix_ptr++ , pnm_file);
|
||||||
|
else
|
||||||
|
if (bit_depth == 16){
|
||||||
|
dep_16 = (long) *pix_ptr++;
|
||||||
|
fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fprintf (pnm_file, "%ld ", (long) *pix_ptr++);
|
||||||
|
}
|
||||||
|
if (alpha_present)
|
||||||
|
{
|
||||||
|
if (!alpha)
|
||||||
|
{
|
||||||
|
pix_ptr++; /* alpha */
|
||||||
|
if (bit_depth == 16)
|
||||||
|
pix_ptr++;
|
||||||
|
}
|
||||||
|
else /* output alpha-channel as pgm file */
|
||||||
|
{
|
||||||
|
if (raw)
|
||||||
|
fputc ((int) *pix_ptr++ , alpha_file);
|
||||||
|
else
|
||||||
|
if (bit_depth == 16){
|
||||||
|
dep_16 = (long) *pix_ptr++;
|
||||||
|
fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fprintf (alpha_file, "%ld ", (long) *pix_ptr++);
|
||||||
|
}
|
||||||
|
} /* if alpha_present */
|
||||||
|
|
||||||
|
if (!raw)
|
||||||
|
if (col % 4 == 3)
|
||||||
|
fprintf (pnm_file, "\n");
|
||||||
|
} /* end for col */
|
||||||
|
|
||||||
|
if (!raw)
|
||||||
|
if (col % 4 != 0)
|
||||||
|
fprintf (pnm_file, "\n");
|
||||||
|
} /* end for row */
|
||||||
|
|
||||||
|
if (row_pointers != (unsigned char**) NULL)
|
||||||
|
free (row_pointers);
|
||||||
|
if (png_pixels != (unsigned char*) NULL)
|
||||||
|
free (png_pixels);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
} /* end of source */
|
||||||
|
|
||||||
42
contrib/pngminus/png2pnm.sh
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# -- grayscale
|
||||||
|
./png2pnm -noraw ../pngsuite/basn0g01.png basn0g01.pgm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn0g02.png basn0g02.pgm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn0g04.png basn0g04.pgm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn0g08.png basn0g08.pgm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn0g16.png basn0g16.pgm
|
||||||
|
# -- full-color
|
||||||
|
./png2pnm -noraw ../pngsuite/basn2c08.png basn2c08.ppm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn2c16.png basn2c16.ppm
|
||||||
|
# -- palletted
|
||||||
|
./png2pnm -noraw ../pngsuite/basn3p01.png basn3p01.ppm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn3p02.png basn3p02.ppm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn3p04.png basn3p04.ppm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn3p08.png basn3p08.ppm
|
||||||
|
# -- gray with alpha-channel
|
||||||
|
./png2pnm -noraw ../pngsuite/basn4a08.png basn4a08.pgm
|
||||||
|
./png2pnm -noraw ../pngsuite/basn4a16.png basn4a16.pgm
|
||||||
|
# -- color with alpha-channel
|
||||||
|
./png2pnm -noraw -alpha basn6a08.pgm ../pngsuite/basn6a08.png basn6a08.ppm
|
||||||
|
./png2pnm -noraw -alpha basn6a16.pgm ../pngsuite/basn6a16.png basn6a16.ppm
|
||||||
|
# -- grayscale
|
||||||
|
./png2pnm -raw ../pngsuite/basn0g01.png rawn0g01.pgm
|
||||||
|
./png2pnm -raw ../pngsuite/basn0g02.png rawn0g02.pgm
|
||||||
|
./png2pnm -raw ../pngsuite/basn0g04.png rawn0g04.pgm
|
||||||
|
./png2pnm -raw ../pngsuite/basn0g08.png rawn0g08.pgm
|
||||||
|
./png2pnm -raw ../pngsuite/basn0g16.png rawn0g16.pgm
|
||||||
|
# -- full-color
|
||||||
|
./png2pnm -raw ../pngsuite/basn2c08.png rawn2c08.ppm
|
||||||
|
./png2pnm -raw ../pngsuite/basn2c16.png rawn2c16.ppm
|
||||||
|
# -- palletted
|
||||||
|
./png2pnm -raw ../pngsuite/basn3p01.png rawn3p01.ppm
|
||||||
|
./png2pnm -raw ../pngsuite/basn3p02.png rawn3p02.ppm
|
||||||
|
./png2pnm -raw ../pngsuite/basn3p04.png rawn3p04.ppm
|
||||||
|
./png2pnm -raw ../pngsuite/basn3p08.png rawn3p08.ppm
|
||||||
|
# -- gray with alpha-channel
|
||||||
|
./png2pnm -raw ../pngsuite/basn4a08.png rawn4a08.pgm
|
||||||
|
./png2pnm -raw ../pngsuite/basn4a16.png rawn4a16.pgm
|
||||||
|
# -- color with alpha-channel
|
||||||
|
./png2pnm -noraw -alpha rawn6a08.pgm ../pngsuite/basn6a08.png rawn6a08.ppm
|
||||||
|
./png2pnm -noraw -alpha rawn6a16.pgm ../pngsuite/basn6a16.png rawn6a16.ppm
|
||||||
|
|
||||||
4
contrib/pngminus/pngminus.bat
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
make -f makefile.tc3
|
||||||
|
call png2pnm.bat
|
||||||
|
call pnm2png.bat
|
||||||
|
|
||||||
5
contrib/pngminus/pngminus.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
make -f makefile.std
|
||||||
|
sh png2pnm.sh
|
||||||
|
sh pnm2png.sh
|
||||||
|
|
||||||
41
contrib/pngminus/pnm2png.bat
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
REM -- grayscale
|
||||||
|
pnm2png.exe basn0g01.pgm basn0g01.png
|
||||||
|
pnm2png.exe basn0g02.pgm basn0g02.png
|
||||||
|
pnm2png.exe basn0g04.pgm basn0g04.png
|
||||||
|
pnm2png.exe basn0g08.pgm basn0g08.png
|
||||||
|
pnm2png.exe basn0g16.pgm basn0g16.png
|
||||||
|
REM -- full-color
|
||||||
|
pnm2png.exe basn2c08.ppm basn2c08.png
|
||||||
|
pnm2png.exe basn2c16.ppm basn2c16.png
|
||||||
|
REM -- palletted
|
||||||
|
pnm2png.exe basn3p01.ppm basn3p01.png
|
||||||
|
pnm2png.exe basn3p02.ppm basn3p02.png
|
||||||
|
pnm2png.exe basn3p04.ppm basn3p04.png
|
||||||
|
pnm2png.exe basn3p08.ppm basn3p08.png
|
||||||
|
REM -- gray with alpha-channel
|
||||||
|
pnm2png.exe -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
|
||||||
|
pnm2png.exe -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
|
||||||
|
REM -- color with alpha-channel
|
||||||
|
pnm2png.exe -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
|
||||||
|
pnm2png.exe -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
|
||||||
|
REM -- grayscale
|
||||||
|
pnm2png.exe rawn0g01.pgm rawn0g01.png
|
||||||
|
pnm2png.exe rawn0g02.pgm rawn0g02.png
|
||||||
|
pnm2png.exe rawn0g04.pgm rawn0g04.png
|
||||||
|
pnm2png.exe rawn0g08.pgm rawn0g08.png
|
||||||
|
pnm2png.exe rawn0g16.pgm rawn0g16.png
|
||||||
|
REM -- full-color
|
||||||
|
pnm2png.exe rawn2c08.ppm rawn2c08.png
|
||||||
|
pnm2png.exe rawn2c16.ppm rawn2c16.png
|
||||||
|
REM -- palletted
|
||||||
|
pnm2png.exe rawn3p01.ppm rawn3p01.png
|
||||||
|
pnm2png.exe rawn3p02.ppm rawn3p02.png
|
||||||
|
pnm2png.exe rawn3p04.ppm rawn3p04.png
|
||||||
|
pnm2png.exe rawn3p08.ppm rawn3p08.png
|
||||||
|
REM -- gray with alpha-channel
|
||||||
|
pnm2png.exe -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
|
||||||
|
pnm2png.exe -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
|
||||||
|
REM -- color with alpha-channel
|
||||||
|
pnm2png.exe -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
|
||||||
|
pnm2png.exe -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
|
||||||
|
|
||||||
533
contrib/pngminus/pnm2png.c
Normal file
@@ -0,0 +1,533 @@
|
|||||||
|
/*
|
||||||
|
* pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file
|
||||||
|
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
|
||||||
|
*
|
||||||
|
* version 1.0 - 1999.10.15 - First version.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software and
|
||||||
|
* its documentation for any purpose and without fee is hereby granted,
|
||||||
|
* provided that the above copyright notice appear in all copies and
|
||||||
|
* that both that copyright notice and this permission notice appear in
|
||||||
|
* supporting documentation. This software is provided "as is" without
|
||||||
|
* express or implied warranty.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
#include <mem.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BOOL
|
||||||
|
#define BOOL unsigned char
|
||||||
|
#endif
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE (BOOL) 1
|
||||||
|
#endif
|
||||||
|
#ifndef FALSE
|
||||||
|
#define FALSE (BOOL) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define STDIN 0
|
||||||
|
#define STDOUT 1
|
||||||
|
#define STDERR 2
|
||||||
|
|
||||||
|
/* to make pnm2png verbose so we can find problems (needs to be before png.h) */
|
||||||
|
#ifndef PNG_DEBUG
|
||||||
|
#define PNG_DEBUG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "png.h"
|
||||||
|
|
||||||
|
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
||||||
|
#ifndef png_jmpbuf
|
||||||
|
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* function prototypes */
|
||||||
|
|
||||||
|
int main (int argc, char *argv[]);
|
||||||
|
void usage ();
|
||||||
|
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha);
|
||||||
|
void get_token(FILE *pnm_file, char *token);
|
||||||
|
png_uint_32 get_data (FILE *pnm_file, int depth);
|
||||||
|
png_uint_32 get_value (FILE *pnm_file, int depth);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* main
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
FILE *fp_rd = stdin;
|
||||||
|
FILE *fp_al = NULL;
|
||||||
|
FILE *fp_wr = stdout;
|
||||||
|
BOOL interlace = FALSE;
|
||||||
|
BOOL alpha = FALSE;
|
||||||
|
int argi;
|
||||||
|
|
||||||
|
for (argi = 1; argi < argc; argi++)
|
||||||
|
{
|
||||||
|
if (argv[argi][0] == '-')
|
||||||
|
{
|
||||||
|
switch (argv[argi][1])
|
||||||
|
{
|
||||||
|
case 'i':
|
||||||
|
interlace = TRUE;
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
alpha = TRUE;
|
||||||
|
argi++;
|
||||||
|
if ((fp_al = fopen (argv[argi], "rb")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, "Error: alpha-channel file %s does not exist\n",
|
||||||
|
argv[argi]);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
case '?':
|
||||||
|
usage();
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
|
||||||
|
usage();
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
} /* end switch */
|
||||||
|
}
|
||||||
|
else if (fp_rd == stdin)
|
||||||
|
{
|
||||||
|
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fp_wr == stdout)
|
||||||
|
{
|
||||||
|
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, "Error: can not create PNG-file %s\n", argv[argi]);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, "Error: too many parameters\n");
|
||||||
|
usage();
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
} /* end for */
|
||||||
|
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
/* set stdin/stdout to binary, we're reading the PNM always! in binary format */
|
||||||
|
if (fp_rd == stdin)
|
||||||
|
{
|
||||||
|
setmode (STDIN, O_BINARY);
|
||||||
|
}
|
||||||
|
if (fp_wr == stdout)
|
||||||
|
{
|
||||||
|
setmode (STDOUT, O_BINARY);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* call the conversion program itself */
|
||||||
|
if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, "Error: unsuccessful converting to PNG-image\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close input file */
|
||||||
|
fclose (fp_rd);
|
||||||
|
/* close output file */
|
||||||
|
fclose (fp_wr);
|
||||||
|
/* close alpha file */
|
||||||
|
if (alpha)
|
||||||
|
fclose (fp_al);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* usage
|
||||||
|
*/
|
||||||
|
|
||||||
|
void usage()
|
||||||
|
{
|
||||||
|
fprintf (stderr, "PNM2PNG\n");
|
||||||
|
fprintf (stderr, " by Willem van Schaik, 1999\n");
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
|
||||||
|
#else
|
||||||
|
fprintf (stderr, " for Linux (and Unix) compilers\n");
|
||||||
|
#endif
|
||||||
|
fprintf (stderr, "Usage: pnm2png [options] <file>.<pnm> [<file>.png]\n");
|
||||||
|
fprintf (stderr, " or: ... | pnm2png [options]\n");
|
||||||
|
fprintf (stderr, "Options:\n");
|
||||||
|
fprintf (stderr, " -i[nterlace] write png-file with interlacing on\n");
|
||||||
|
fprintf (stderr, " -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\n");
|
||||||
|
fprintf (stderr, " -h | -? print this help-information\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pnm2png
|
||||||
|
*/
|
||||||
|
|
||||||
|
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha)
|
||||||
|
{
|
||||||
|
png_struct *png_ptr = NULL;
|
||||||
|
png_info *info_ptr = NULL;
|
||||||
|
png_byte *png_pixels = NULL;
|
||||||
|
png_byte **row_pointers = NULL;
|
||||||
|
png_byte *pix_ptr = NULL;
|
||||||
|
png_uint_32 row_bytes;
|
||||||
|
|
||||||
|
char type_token[16];
|
||||||
|
char width_token[16];
|
||||||
|
char height_token[16];
|
||||||
|
char maxval_token[16];
|
||||||
|
int color_type;
|
||||||
|
png_uint_32 width, alpha_width;
|
||||||
|
png_uint_32 height, alpha_height;
|
||||||
|
png_uint_32 maxval;
|
||||||
|
int bit_depth = 0;
|
||||||
|
int channels;
|
||||||
|
int alpha_depth = 0;
|
||||||
|
int alpha_present;
|
||||||
|
int row, col;
|
||||||
|
BOOL raw, alpha_raw = FALSE;
|
||||||
|
png_uint_32 tmp16;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* read header of PNM file */
|
||||||
|
|
||||||
|
get_token(pnm_file, type_token);
|
||||||
|
if (type_token[0] != 'P')
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else if ((type_token[1] == '1') || (type_token[1] == '4'))
|
||||||
|
{
|
||||||
|
raw = (type_token[1] == '4');
|
||||||
|
color_type = PNG_COLOR_TYPE_GRAY;
|
||||||
|
bit_depth = 1;
|
||||||
|
}
|
||||||
|
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||||
|
{
|
||||||
|
raw = (type_token[1] == '5');
|
||||||
|
color_type = PNG_COLOR_TYPE_GRAY;
|
||||||
|
get_token(pnm_file, width_token);
|
||||||
|
sscanf (width_token, "%lu", &width);
|
||||||
|
get_token(pnm_file, height_token);
|
||||||
|
sscanf (height_token, "%lu", &height);
|
||||||
|
get_token(pnm_file, maxval_token);
|
||||||
|
sscanf (maxval_token, "%lu", &maxval);
|
||||||
|
if (maxval <= 1)
|
||||||
|
bit_depth = 1;
|
||||||
|
else if (maxval <= 3)
|
||||||
|
bit_depth = 2;
|
||||||
|
else if (maxval <= 15)
|
||||||
|
bit_depth = 4;
|
||||||
|
else if (maxval <= 255)
|
||||||
|
bit_depth = 8;
|
||||||
|
else /* if (maxval <= 65535) */
|
||||||
|
bit_depth = 16;
|
||||||
|
}
|
||||||
|
else if ((type_token[1] == '3') || (type_token[1] == '6'))
|
||||||
|
{
|
||||||
|
raw = (type_token[1] == '6');
|
||||||
|
color_type = PNG_COLOR_TYPE_RGB;
|
||||||
|
get_token(pnm_file, width_token);
|
||||||
|
sscanf (width_token, "%lu", &width);
|
||||||
|
get_token(pnm_file, height_token);
|
||||||
|
sscanf (height_token, "%lu", &height);
|
||||||
|
get_token(pnm_file, maxval_token);
|
||||||
|
sscanf (maxval_token, "%lu", &maxval);
|
||||||
|
if (maxval <= 1)
|
||||||
|
bit_depth = 1;
|
||||||
|
else if (maxval <= 3)
|
||||||
|
bit_depth = 2;
|
||||||
|
else if (maxval <= 15)
|
||||||
|
bit_depth = 4;
|
||||||
|
else if (maxval <= 255)
|
||||||
|
bit_depth = 8;
|
||||||
|
else /* if (maxval <= 65535) */
|
||||||
|
bit_depth = 16;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read header of PGM file with alpha channel */
|
||||||
|
|
||||||
|
if (alpha)
|
||||||
|
{
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||||
|
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
|
||||||
|
if (color_type == PNG_COLOR_TYPE_RGB)
|
||||||
|
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||||
|
|
||||||
|
get_token(alpha_file, type_token);
|
||||||
|
if (type_token[0] != 'P')
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||||
|
{
|
||||||
|
alpha_raw = (type_token[1] == '5');
|
||||||
|
get_token(alpha_file, width_token);
|
||||||
|
sscanf (width_token, "%lu", &alpha_width);
|
||||||
|
if (alpha_width != width)
|
||||||
|
return FALSE;
|
||||||
|
get_token(alpha_file, height_token);
|
||||||
|
sscanf (height_token, "%lu", &alpha_height);
|
||||||
|
if (alpha_height != height)
|
||||||
|
return FALSE;
|
||||||
|
get_token(alpha_file, maxval_token);
|
||||||
|
sscanf (maxval_token, "%lu", &maxval);
|
||||||
|
if (maxval <= 1)
|
||||||
|
alpha_depth = 1;
|
||||||
|
else if (maxval <= 3)
|
||||||
|
alpha_depth = 2;
|
||||||
|
else if (maxval <= 15)
|
||||||
|
alpha_depth = 4;
|
||||||
|
else if (maxval <= 255)
|
||||||
|
alpha_depth = 8;
|
||||||
|
else /* if (maxval <= 65535) */
|
||||||
|
alpha_depth = 16;
|
||||||
|
if (alpha_depth != bit_depth)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
} /* end if alpha */
|
||||||
|
|
||||||
|
/* calculate the number of channels and store alpha-presence */
|
||||||
|
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||||
|
channels = 1;
|
||||||
|
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
channels = 2;
|
||||||
|
else if (color_type == PNG_COLOR_TYPE_RGB)
|
||||||
|
channels = 3;
|
||||||
|
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||||
|
channels = 4;
|
||||||
|
else
|
||||||
|
channels = 0; /* should not happen */
|
||||||
|
|
||||||
|
alpha_present = (channels - 1) % 2;
|
||||||
|
|
||||||
|
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||||
|
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||||
|
|
||||||
|
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* read data from PNM file */
|
||||||
|
pix_ptr = png_pixels;
|
||||||
|
|
||||||
|
for (row = 0; row < height; row++)
|
||||||
|
{
|
||||||
|
for (col = 0; col < width; col++)
|
||||||
|
{
|
||||||
|
for (i = 0; i < (channels - alpha_present); i++)
|
||||||
|
{
|
||||||
|
if (raw)
|
||||||
|
*pix_ptr++ = get_data (pnm_file, bit_depth);
|
||||||
|
else
|
||||||
|
if (bit_depth <= 8)
|
||||||
|
*pix_ptr++ = get_value (pnm_file, bit_depth);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp16 = get_value (pnm_file, bit_depth);
|
||||||
|
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||||
|
pix_ptr++;
|
||||||
|
*pix_ptr = (png_byte) (tmp16 & 0xFF);
|
||||||
|
pix_ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alpha) /* read alpha-channel from pgm file */
|
||||||
|
{
|
||||||
|
if (alpha_raw)
|
||||||
|
*pix_ptr++ = get_data (alpha_file, alpha_depth);
|
||||||
|
else
|
||||||
|
if (alpha_depth <= 8)
|
||||||
|
*pix_ptr++ = get_value (alpha_file, bit_depth);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp16 = get_value (alpha_file, bit_depth);
|
||||||
|
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||||
|
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
|
||||||
|
}
|
||||||
|
} /* if alpha */
|
||||||
|
|
||||||
|
} /* end for col */
|
||||||
|
} /* end for row */
|
||||||
|
|
||||||
|
/* prepare the standard PNG structures */
|
||||||
|
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
|
if (!png_ptr)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
info_ptr = png_create_info_struct (png_ptr);
|
||||||
|
if (!info_ptr)
|
||||||
|
{
|
||||||
|
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* setjmp() must be called in every function that calls a PNG-reading libpng function */
|
||||||
|
if (setjmp (png_jmpbuf(png_ptr)))
|
||||||
|
{
|
||||||
|
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* initialize the png structure */
|
||||||
|
png_init_io (png_ptr, png_file);
|
||||||
|
|
||||||
|
/* we're going to write more or less the same PNG as the input file */
|
||||||
|
png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type,
|
||||||
|
(!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
|
||||||
|
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||||
|
|
||||||
|
/* write the file header information */
|
||||||
|
png_write_info (png_ptr, info_ptr);
|
||||||
|
|
||||||
|
/* if needed we will allocate memory for an new array of row-pointers */
|
||||||
|
if (row_pointers == (unsigned char**) NULL)
|
||||||
|
{
|
||||||
|
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
|
||||||
|
{
|
||||||
|
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the individual row_pointers to point at the correct offsets */
|
||||||
|
for (i = 0; i < (height); i++)
|
||||||
|
row_pointers[i] = png_pixels + i * row_bytes;
|
||||||
|
|
||||||
|
/* write out the entire image data in one call */
|
||||||
|
png_write_image (png_ptr, row_pointers);
|
||||||
|
|
||||||
|
/* write the additional chuncks to the PNG file (not really needed) */
|
||||||
|
png_write_end (png_ptr, info_ptr);
|
||||||
|
|
||||||
|
/* clean up after the write, and free any memory allocated */
|
||||||
|
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||||
|
|
||||||
|
if (row_pointers != (unsigned char**) NULL)
|
||||||
|
free (row_pointers);
|
||||||
|
if (png_pixels != (unsigned char*) NULL)
|
||||||
|
free (png_pixels);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
} /* end of pnm2png */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get_token() - gets the first string after whitespace
|
||||||
|
*/
|
||||||
|
|
||||||
|
void get_token(FILE *pnm_file, char *token)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
/* remove white-space */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
token[i] = (unsigned char) fgetc (pnm_file);
|
||||||
|
}
|
||||||
|
while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
|
||||||
|
|
||||||
|
/* read string */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
token[i] = (unsigned char) fgetc (pnm_file);
|
||||||
|
}
|
||||||
|
while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));
|
||||||
|
|
||||||
|
token[i] = '\0';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get_data() - takes first byte and converts into next pixel value,
|
||||||
|
* taking as much bits as defined by bit-depth and
|
||||||
|
* using the bit-depth to fill up a byte (0Ah -> AAh)
|
||||||
|
*/
|
||||||
|
|
||||||
|
png_uint_32 get_data (FILE *pnm_file, int depth)
|
||||||
|
{
|
||||||
|
static int bits_left = 0;
|
||||||
|
static int old_value = 0;
|
||||||
|
static int mask = 0;
|
||||||
|
int i;
|
||||||
|
png_uint_32 ret_value;
|
||||||
|
|
||||||
|
if (mask == 0)
|
||||||
|
for (i = 0; i < depth; i++)
|
||||||
|
mask = (mask >> 1) | 0x80;
|
||||||
|
|
||||||
|
if (bits_left <= 0)
|
||||||
|
{
|
||||||
|
old_value = fgetc (pnm_file);
|
||||||
|
bits_left = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_value = old_value & mask;
|
||||||
|
for (i = 1; i < (8 / depth); i++)
|
||||||
|
ret_value = ret_value || (ret_value >> depth);
|
||||||
|
|
||||||
|
old_value = (old_value << depth) & 0xFF;
|
||||||
|
bits_left -= depth;
|
||||||
|
|
||||||
|
return ret_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get_value() - takes first (numeric) string and converts into number,
|
||||||
|
* using the bit-depth to fill up a byte (0Ah -> AAh)
|
||||||
|
*/
|
||||||
|
|
||||||
|
png_uint_32 get_value (FILE *pnm_file, int depth)
|
||||||
|
{
|
||||||
|
static png_uint_32 mask = 0;
|
||||||
|
png_byte token[16];
|
||||||
|
png_uint_32 ret_value;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (mask == 0)
|
||||||
|
for (i = 0; i < depth; i++)
|
||||||
|
mask = (mask << 1) | 0x01;
|
||||||
|
|
||||||
|
get_token (pnm_file, (char *) token);
|
||||||
|
sscanf ((const char *) token, "%lu", &ret_value);
|
||||||
|
|
||||||
|
ret_value &= mask;
|
||||||
|
|
||||||
|
if (depth < 8)
|
||||||
|
for (i = 0; i < (8 / depth); i++)
|
||||||
|
ret_value = (ret_value << depth) || ret_value;
|
||||||
|
|
||||||
|
return ret_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of source */
|
||||||
|
|
||||||
42
contrib/pngminus/pnm2png.sh
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# -- grayscale
|
||||||
|
./pnm2png basn0g01.pgm basn0g01.png
|
||||||
|
./pnm2png basn0g02.pgm basn0g02.png
|
||||||
|
./pnm2png basn0g04.pgm basn0g04.png
|
||||||
|
./pnm2png basn0g08.pgm basn0g08.png
|
||||||
|
./pnm2png basn0g16.pgm basn0g16.png
|
||||||
|
# -- full-color
|
||||||
|
./pnm2png basn2c08.ppm basn2c08.png
|
||||||
|
./pnm2png basn2c16.ppm basn2c16.png
|
||||||
|
# -- palletted
|
||||||
|
./pnm2png basn3p01.ppm basn3p01.png
|
||||||
|
./pnm2png basn3p02.ppm basn3p02.png
|
||||||
|
./pnm2png basn3p04.ppm basn3p04.png
|
||||||
|
./pnm2png basn3p08.ppm basn3p08.png
|
||||||
|
# -- gray with alpha-channel
|
||||||
|
./pnm2png -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
|
||||||
|
./pnm2png -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
|
||||||
|
# -- color with alpha-channel
|
||||||
|
./pnm2png -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
|
||||||
|
./pnm2png -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
|
||||||
|
# -- grayscale
|
||||||
|
./pnm2png rawn0g01.pgm rawn0g01.png
|
||||||
|
./pnm2png rawn0g02.pgm rawn0g02.png
|
||||||
|
./pnm2png rawn0g04.pgm rawn0g04.png
|
||||||
|
./pnm2png rawn0g08.pgm rawn0g08.png
|
||||||
|
./pnm2png rawn0g16.pgm rawn0g16.png
|
||||||
|
# -- full-color
|
||||||
|
./pnm2png rawn2c08.ppm rawn2c08.png
|
||||||
|
./pnm2png rawn2c16.ppm rawn2c16.png
|
||||||
|
# -- palletted
|
||||||
|
./pnm2png rawn3p01.ppm rawn3p01.png
|
||||||
|
./pnm2png rawn3p02.ppm rawn3p02.png
|
||||||
|
./pnm2png rawn3p04.ppm rawn3p04.png
|
||||||
|
./pnm2png rawn3p08.ppm rawn3p08.png
|
||||||
|
# -- gray with alpha-channel
|
||||||
|
./pnm2png -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
|
||||||
|
./pnm2png -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
|
||||||
|
# -- color with alpha-channel
|
||||||
|
./pnm2png -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
|
||||||
|
./pnm2png -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
|
||||||
|
|
||||||
85
contrib/pngsuite/README
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
|
||||||
|
pngsuite
|
||||||
|
--------
|
||||||
|
(c) Willem van Schaik, 1999
|
||||||
|
|
||||||
|
Permission to use, copy, and distribute these images for any purpose and
|
||||||
|
without fee is hereby granted.
|
||||||
|
|
||||||
|
These 15 images are part of the much larger PngSuite test-set of
|
||||||
|
images, available for developers of PNG supporting software. The
|
||||||
|
complete set, available at http:/www.schaik.com/pngsuite/, contains
|
||||||
|
a variety of images to test interlacing, gamma settings, ancillary
|
||||||
|
chunks, etc.
|
||||||
|
|
||||||
|
The images in this directory represent the basic PNG color-types:
|
||||||
|
grayscale (1-16 bit deep), full color (8 or 16 bit), paletted
|
||||||
|
(1-8 bit) and grayscale or color images with alpha channel. You
|
||||||
|
can use them to test the proper functioning of PNG software.
|
||||||
|
|
||||||
|
filename depth type
|
||||||
|
------------ ------ --------------
|
||||||
|
basn0g01.png 1-bit grayscale
|
||||||
|
basn0g02.png 2-bit grayscale
|
||||||
|
basn0g04.png 4-bit grayscale
|
||||||
|
basn0g08.png 8-bit grayscale
|
||||||
|
basn0g16.png 16-bit grayscale
|
||||||
|
basn2c08.png 8-bit truecolor
|
||||||
|
basn2c16.png 16-bit truecolor
|
||||||
|
basn3p01.png 1-bit paletted
|
||||||
|
basn3p02.png 2-bit paletted
|
||||||
|
basn3p04.png 4-bit paletted
|
||||||
|
basn3p08.png 8-bit paletted
|
||||||
|
basn4a08.png 8-bit gray with alpha
|
||||||
|
basn4a16.png 16-bit gray with alpha
|
||||||
|
basn6a08.png 8-bit RGBA
|
||||||
|
basn6a16.png 16-bit RGBA
|
||||||
|
|
||||||
|
Here is the correct result of typing "pngtest -m *.png" in
|
||||||
|
this directory:
|
||||||
|
|
||||||
|
Testing basn0g01.png: PASS (524 zero samples)
|
||||||
|
Filter 0 was used 32 times
|
||||||
|
Testing basn0g02.png: PASS (448 zero samples)
|
||||||
|
Filter 0 was used 32 times
|
||||||
|
Testing basn0g04.png: PASS (520 zero samples)
|
||||||
|
Filter 0 was used 32 times
|
||||||
|
Testing basn0g08.png: PASS (3 zero samples)
|
||||||
|
Filter 1 was used 9 times
|
||||||
|
Filter 4 was used 23 times
|
||||||
|
Testing basn0g16.png: PASS (1 zero samples)
|
||||||
|
Filter 1 was used 1 times
|
||||||
|
Filter 2 was used 31 times
|
||||||
|
Testing basn2c08.png: PASS (6 zero samples)
|
||||||
|
Filter 1 was used 5 times
|
||||||
|
Filter 4 was used 27 times
|
||||||
|
Testing basn2c16.png: PASS (592 zero samples)
|
||||||
|
Filter 1 was used 1 times
|
||||||
|
Filter 4 was used 31 times
|
||||||
|
Testing basn3p01.png: PASS (512 zero samples)
|
||||||
|
Filter 0 was used 32 times
|
||||||
|
Testing basn3p02.png: PASS (448 zero samples)
|
||||||
|
Filter 0 was used 32 times
|
||||||
|
Testing basn3p04.png: PASS (544 zero samples)
|
||||||
|
Filter 0 was used 32 times
|
||||||
|
Testing basn3p08.png: PASS (4 zero samples)
|
||||||
|
Filter 0 was used 32 times
|
||||||
|
Testing basn4a08.png: PASS (32 zero samples)
|
||||||
|
Filter 1 was used 1 times
|
||||||
|
Filter 4 was used 31 times
|
||||||
|
Testing basn4a16.png: PASS (64 zero samples)
|
||||||
|
Filter 0 was used 1 times
|
||||||
|
Filter 1 was used 2 times
|
||||||
|
Filter 2 was used 1 times
|
||||||
|
Filter 4 was used 28 times
|
||||||
|
Testing basn6a08.png: PASS (160 zero samples)
|
||||||
|
Filter 1 was used 1 times
|
||||||
|
Filter 4 was used 31 times
|
||||||
|
Testing basn6a16.png: PASS (1072 zero samples)
|
||||||
|
Filter 1 was used 4 times
|
||||||
|
Filter 4 was used 28 times
|
||||||
|
libpng passes test
|
||||||
|
|
||||||
|
Willem van Schaik
|
||||||
|
<willem@schaik.com>
|
||||||
|
October 1999
|
||||||
BIN
contrib/pngsuite/basn0g01.png
Normal file
|
After Width: | Height: | Size: 164 B |
BIN
contrib/pngsuite/basn0g02.png
Normal file
|
After Width: | Height: | Size: 104 B |
BIN
contrib/pngsuite/basn0g04.png
Normal file
|
After Width: | Height: | Size: 145 B |
BIN
contrib/pngsuite/basn0g08.png
Normal file
|
After Width: | Height: | Size: 138 B |
BIN
contrib/pngsuite/basn0g16.png
Normal file
|
After Width: | Height: | Size: 167 B |
BIN
contrib/pngsuite/basn2c08.png
Normal file
|
After Width: | Height: | Size: 145 B |
BIN
contrib/pngsuite/basn2c16.png
Normal file
|
After Width: | Height: | Size: 302 B |
BIN
contrib/pngsuite/basn3p01.png
Normal file
|
After Width: | Height: | Size: 112 B |
BIN
contrib/pngsuite/basn3p02.png
Normal file
|
After Width: | Height: | Size: 146 B |
BIN
contrib/pngsuite/basn3p04.png
Normal file
|
After Width: | Height: | Size: 216 B |
BIN
contrib/pngsuite/basn3p08.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
contrib/pngsuite/basn4a08.png
Normal file
|
After Width: | Height: | Size: 126 B |
BIN
contrib/pngsuite/basn4a16.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
contrib/pngsuite/basn6a08.png
Normal file
|
After Width: | Height: | Size: 184 B |
BIN
contrib/pngsuite/basn6a16.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
442
contrib/visupng/PngFile.c
Normal file
@@ -0,0 +1,442 @@
|
|||||||
|
//-------------------------------------
|
||||||
|
// PNGFILE.C -- Image File Functions
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
// Copyright 2000, Willem van Schaik.
|
||||||
|
//
|
||||||
|
// This code is released under the libpng license.
|
||||||
|
// For conditions of distribution and use, see the disclaimer
|
||||||
|
// and license in png.h
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <commdlg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "png.h"
|
||||||
|
#include "pngfile.h"
|
||||||
|
#include "cexcept.h"
|
||||||
|
|
||||||
|
define_exception_type(const char *);
|
||||||
|
extern struct exception_context the_exception_context[1];
|
||||||
|
struct exception_context the_exception_context[1];
|
||||||
|
png_const_charp msg;
|
||||||
|
|
||||||
|
static OPENFILENAME ofn;
|
||||||
|
|
||||||
|
static png_structp png_ptr = NULL;
|
||||||
|
static png_infop info_ptr = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
// cexcept interface
|
||||||
|
|
||||||
|
static void
|
||||||
|
png_cexcept_error(png_structp png_ptr, png_const_charp msg)
|
||||||
|
{
|
||||||
|
if(png_ptr)
|
||||||
|
;
|
||||||
|
#ifndef PNG_NO_CONSOLE_IO
|
||||||
|
fprintf(stderr, "libpng error: %s\n", msg);
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
Throw msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Windows open-file functions
|
||||||
|
|
||||||
|
void PngFileInitialize (HWND hwnd)
|
||||||
|
{
|
||||||
|
static TCHAR szFilter[] = TEXT ("PNG Files (*.PNG)\0*.png\0")
|
||||||
|
TEXT ("All Files (*.*)\0*.*\0\0");
|
||||||
|
|
||||||
|
ofn.lStructSize = sizeof (OPENFILENAME);
|
||||||
|
ofn.hwndOwner = hwnd;
|
||||||
|
ofn.hInstance = NULL;
|
||||||
|
ofn.lpstrFilter = szFilter;
|
||||||
|
ofn.lpstrCustomFilter = NULL;
|
||||||
|
ofn.nMaxCustFilter = 0;
|
||||||
|
ofn.nFilterIndex = 0;
|
||||||
|
ofn.lpstrFile = NULL; // Set in Open and Close functions
|
||||||
|
ofn.nMaxFile = MAX_PATH;
|
||||||
|
ofn.lpstrFileTitle = NULL; // Set in Open and Close functions
|
||||||
|
ofn.nMaxFileTitle = MAX_PATH;
|
||||||
|
ofn.lpstrInitialDir = NULL;
|
||||||
|
ofn.lpstrTitle = NULL;
|
||||||
|
ofn.Flags = 0; // Set in Open and Close functions
|
||||||
|
ofn.nFileOffset = 0;
|
||||||
|
ofn.nFileExtension = 0;
|
||||||
|
ofn.lpstrDefExt = TEXT ("png");
|
||||||
|
ofn.lCustData = 0;
|
||||||
|
ofn.lpfnHook = NULL;
|
||||||
|
ofn.lpTemplateName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
|
||||||
|
{
|
||||||
|
ofn.hwndOwner = hwnd;
|
||||||
|
ofn.lpstrFile = pstrFileName;
|
||||||
|
ofn.lpstrFileTitle = pstrTitleName;
|
||||||
|
ofn.Flags = OFN_HIDEREADONLY;
|
||||||
|
|
||||||
|
return GetOpenFileName (&ofn);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
|
||||||
|
{
|
||||||
|
ofn.hwndOwner = hwnd;
|
||||||
|
ofn.lpstrFile = pstrFileName;
|
||||||
|
ofn.lpstrFileTitle = pstrTitleName;
|
||||||
|
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
|
||||||
|
|
||||||
|
return GetSaveFileName (&ofn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PNG image handler functions
|
||||||
|
|
||||||
|
BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||||
|
int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor)
|
||||||
|
{
|
||||||
|
static FILE *pfFile;
|
||||||
|
png_byte pbSig[8];
|
||||||
|
int iBitDepth;
|
||||||
|
int iColorType;
|
||||||
|
double dGamma;
|
||||||
|
png_color_16 *pBackground;
|
||||||
|
png_uint_32 ulChannels;
|
||||||
|
png_uint_32 ulRowBytes;
|
||||||
|
png_byte *pbImageData = *ppbImageData;
|
||||||
|
static png_byte **ppbRowPointers = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// open the PNG input file
|
||||||
|
|
||||||
|
if (!pstrFileName)
|
||||||
|
{
|
||||||
|
*ppbImageData = pbImageData = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(pfFile = fopen(pstrFileName, "rb")))
|
||||||
|
{
|
||||||
|
*ppbImageData = pbImageData = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// first check the eight byte PNG signature
|
||||||
|
|
||||||
|
fread(pbSig, 1, 8, pfFile);
|
||||||
|
if (png_sig_cmp(pbSig, 0, 8))
|
||||||
|
{
|
||||||
|
*ppbImageData = pbImageData = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the two png(-info) structures
|
||||||
|
|
||||||
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
|
||||||
|
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
|
||||||
|
if (!png_ptr)
|
||||||
|
{
|
||||||
|
*ppbImageData = pbImageData = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
if (!info_ptr)
|
||||||
|
{
|
||||||
|
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||||
|
*ppbImageData = pbImageData = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Try
|
||||||
|
{
|
||||||
|
|
||||||
|
// initialize the png structure
|
||||||
|
|
||||||
|
#if !defined(PNG_NO_STDIO)
|
||||||
|
png_init_io(png_ptr, pfFile);
|
||||||
|
#else
|
||||||
|
png_set_read_fn(png_ptr, (png_voidp)pfFile, png_read_data);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
png_set_sig_bytes(png_ptr, 8);
|
||||||
|
|
||||||
|
// read all PNG info up to image data
|
||||||
|
|
||||||
|
png_read_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
// get width, height, bit-depth and color-type
|
||||||
|
|
||||||
|
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
|
||||||
|
&iColorType, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
// expand images of all color-type and bit-depth to 3x8 bit RGB images
|
||||||
|
// let the library process things like alpha, transparency, background
|
||||||
|
|
||||||
|
if (iBitDepth == 16)
|
||||||
|
png_set_strip_16(png_ptr);
|
||||||
|
if (iColorType == PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (iBitDepth < 8)
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||||
|
png_set_expand(png_ptr);
|
||||||
|
if (iColorType == PNG_COLOR_TYPE_GRAY ||
|
||||||
|
iColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
png_set_gray_to_rgb(png_ptr);
|
||||||
|
|
||||||
|
// set the background color to draw transparent and alpha images over.
|
||||||
|
if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
|
||||||
|
{
|
||||||
|
png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||||
|
pBkgColor->red = (byte) pBackground->red;
|
||||||
|
pBkgColor->green = (byte) pBackground->green;
|
||||||
|
pBkgColor->blue = (byte) pBackground->blue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pBkgColor = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if required set gamma conversion
|
||||||
|
if (png_get_gAMA(png_ptr, info_ptr, &dGamma))
|
||||||
|
png_set_gamma(png_ptr, (double) 2.2, dGamma);
|
||||||
|
|
||||||
|
// after the transformations have been registered update info_ptr data
|
||||||
|
|
||||||
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
// get again width, height and the new bit-depth and color-type
|
||||||
|
|
||||||
|
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
|
||||||
|
&iColorType, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
// row_bytes is the width x number of channels
|
||||||
|
|
||||||
|
ulRowBytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||||
|
ulChannels = png_get_channels(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
*piChannels = ulChannels;
|
||||||
|
|
||||||
|
// now we can allocate memory to store the image
|
||||||
|
|
||||||
|
if (pbImageData)
|
||||||
|
{
|
||||||
|
free (pbImageData);
|
||||||
|
pbImageData = NULL;
|
||||||
|
}
|
||||||
|
if ((pbImageData = (png_byte *) malloc(ulRowBytes * (*piHeight)
|
||||||
|
* sizeof(png_byte))) == NULL)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "Visual PNG: out of memory");
|
||||||
|
}
|
||||||
|
*ppbImageData = pbImageData;
|
||||||
|
|
||||||
|
// and allocate memory for an array of row-pointers
|
||||||
|
|
||||||
|
if ((ppbRowPointers = (png_bytepp) malloc((*piHeight)
|
||||||
|
* sizeof(png_bytep))) == NULL)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "Visual PNG: out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the individual row-pointers to point at the correct offsets
|
||||||
|
|
||||||
|
for (i = 0; i < (*piHeight); i++)
|
||||||
|
ppbRowPointers[i] = pbImageData + i * ulRowBytes;
|
||||||
|
|
||||||
|
// now we can go ahead and just read the whole image
|
||||||
|
|
||||||
|
png_read_image(png_ptr, ppbRowPointers);
|
||||||
|
|
||||||
|
// read the additional chunks in the PNG file (not really needed)
|
||||||
|
|
||||||
|
png_read_end(png_ptr, NULL);
|
||||||
|
|
||||||
|
// and we're done
|
||||||
|
|
||||||
|
free (ppbRowPointers);
|
||||||
|
ppbRowPointers = NULL;
|
||||||
|
|
||||||
|
// yepp, done
|
||||||
|
}
|
||||||
|
|
||||||
|
Catch (msg)
|
||||||
|
{
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
|
|
||||||
|
*ppbImageData = pbImageData = NULL;
|
||||||
|
|
||||||
|
if(ppbRowPointers)
|
||||||
|
free (ppbRowPointers);
|
||||||
|
|
||||||
|
fclose(pfFile);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (pfFile);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
|
||||||
|
int iWidth, int iHeight, png_color bkgColor)
|
||||||
|
{
|
||||||
|
const int ciBitDepth = 8;
|
||||||
|
const int ciChannels = 3;
|
||||||
|
|
||||||
|
static FILE *pfFile;
|
||||||
|
png_uint_32 ulRowBytes;
|
||||||
|
static png_byte **ppbRowPointers = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// open the PNG output file
|
||||||
|
|
||||||
|
if (!pstrFileName)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!(pfFile = fopen(pstrFileName, "wb")))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
// prepare the standard PNG structures
|
||||||
|
|
||||||
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
|
||||||
|
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
|
||||||
|
if (!png_ptr)
|
||||||
|
{
|
||||||
|
fclose(pfFile);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
if (!info_ptr) {
|
||||||
|
fclose(pfFile);
|
||||||
|
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Try
|
||||||
|
{
|
||||||
|
// initialize the png structure
|
||||||
|
|
||||||
|
#if !defined(PNG_NO_STDIO)
|
||||||
|
png_init_io(png_ptr, pfFile);
|
||||||
|
#else
|
||||||
|
png_set_write_fn(png_ptr, (png_voidp)pfFile, png_write_data, png_flush);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// we're going to write a very simple 3x8 bit RGB image
|
||||||
|
|
||||||
|
png_set_IHDR(png_ptr, info_ptr, iWidth, iHeight, ciBitDepth,
|
||||||
|
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
|
||||||
|
PNG_FILTER_TYPE_BASE);
|
||||||
|
|
||||||
|
// write the file header information
|
||||||
|
|
||||||
|
png_write_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
// swap the BGR pixels in the DiData structure to RGB
|
||||||
|
|
||||||
|
png_set_bgr(png_ptr);
|
||||||
|
|
||||||
|
// row_bytes is the width x number of channels
|
||||||
|
|
||||||
|
ulRowBytes = iWidth * ciChannels;
|
||||||
|
|
||||||
|
// we can allocate memory for an array of row-pointers
|
||||||
|
|
||||||
|
if ((ppbRowPointers = (png_bytepp) malloc(iHeight * sizeof(png_bytep))) == NULL)
|
||||||
|
Throw "Visualpng: Out of memory";
|
||||||
|
|
||||||
|
// set the individual row-pointers to point at the correct offsets
|
||||||
|
|
||||||
|
for (i = 0; i < iHeight; i++)
|
||||||
|
ppbRowPointers[i] = pDiData + i * (((ulRowBytes + 3) >> 2) << 2);
|
||||||
|
|
||||||
|
// write out the entire image data in one call
|
||||||
|
|
||||||
|
png_write_image (png_ptr, ppbRowPointers);
|
||||||
|
|
||||||
|
// write the additional chunks to the PNG file (not really needed)
|
||||||
|
|
||||||
|
png_write_end(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
// and we're done
|
||||||
|
|
||||||
|
free (ppbRowPointers);
|
||||||
|
ppbRowPointers = NULL;
|
||||||
|
|
||||||
|
// clean up after the write, and free any memory allocated
|
||||||
|
|
||||||
|
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||||
|
|
||||||
|
// yepp, done
|
||||||
|
}
|
||||||
|
|
||||||
|
Catch (msg)
|
||||||
|
{
|
||||||
|
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||||
|
|
||||||
|
if(ppbRowPointers)
|
||||||
|
free (ppbRowPointers);
|
||||||
|
|
||||||
|
fclose(pfFile);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (pfFile);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PNG_NO_STDIO
|
||||||
|
|
||||||
|
static void
|
||||||
|
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||||
|
{
|
||||||
|
png_size_t check;
|
||||||
|
|
||||||
|
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||||
|
* instead of an int, which is what fread() actually returns.
|
||||||
|
*/
|
||||||
|
check = (png_size_t)fread(data, (png_size_t)1, length,
|
||||||
|
(FILE *)png_ptr->io_ptr);
|
||||||
|
|
||||||
|
if (check != length)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "Read Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||||
|
{
|
||||||
|
png_uint_32 check;
|
||||||
|
|
||||||
|
check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
|
||||||
|
if (check != length)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "Write Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
png_flush(png_structp png_ptr)
|
||||||
|
{
|
||||||
|
FILE *io_ptr;
|
||||||
|
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
|
||||||
|
if (io_ptr != NULL)
|
||||||
|
fflush(io_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-----------------
|
||||||
|
// end of source
|
||||||
|
//-----------------
|
||||||
30
contrib/visupng/PngFile.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
//------------------------------------------
|
||||||
|
// PNGFILE.H -- Header File for pngfile.c
|
||||||
|
//------------------------------------------
|
||||||
|
|
||||||
|
// Copyright 2000, Willem van Schaik.
|
||||||
|
|
||||||
|
// This code is released under the libpng license.
|
||||||
|
// For conditions of distribution and use, see the disclaimer
|
||||||
|
// and license in png.h
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
void PngFileInitialize (HWND hwnd) ;
|
||||||
|
BOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ;
|
||||||
|
BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ;
|
||||||
|
|
||||||
|
BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||||
|
int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor);
|
||||||
|
BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
|
||||||
|
int iWidth, int iHeight, png_color BkgColor);
|
||||||
|
|
||||||
|
#if defined(PNG_NO_STDIO)
|
||||||
|
static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
|
||||||
|
static void png_write_data(png_structp png_ptr, png_bytep data, png_size_t length);
|
||||||
|
static void png_flush(png_structp png_ptr);
|
||||||
|
#endif
|
||||||
|
|
||||||
61
contrib/visupng/README.txt
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
Microsoft Developer Studio Build File, Format Version 6.00 for VisualPng
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright 2000, Willem van Schaik.
|
||||||
|
|
||||||
|
This code is released under the libpng license.
|
||||||
|
For conditions of distribution and use, see the disclaimer
|
||||||
|
and license in png.h
|
||||||
|
|
||||||
|
As a PNG .dll demo VisualPng is finished. More features would only hinder
|
||||||
|
the program's objective. However, further extensions (like support for other
|
||||||
|
graphics formats) are in development. To get these, or for pre-compiled
|
||||||
|
binaries, go to "http://www.schaik.com/png/visualpng.html".
|
||||||
|
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Assumes that
|
||||||
|
|
||||||
|
libpng DLLs and LIBs are in ..\..\projects\msvc\win32\libpng
|
||||||
|
zlib DLLs and LIBs are in ..\..\projects\msvc\win32\zlib
|
||||||
|
libpng header files are in ..\..\..\libpng
|
||||||
|
zlib header files are in ..\..\..\zlib
|
||||||
|
the pngsuite images are in ..\pngsuite
|
||||||
|
|
||||||
|
To build:
|
||||||
|
|
||||||
|
1) On the main menu Select "Build|Set Active configuration".
|
||||||
|
Choose the configuration that corresponds to the library you want to test.
|
||||||
|
This library must have been built using the libpng MS project located in
|
||||||
|
the "..\..\mscv" subdirectory.
|
||||||
|
|
||||||
|
2) Select "Build|Clean"
|
||||||
|
|
||||||
|
3) Select "Build|Rebuild All"
|
||||||
|
|
||||||
|
4) After compiling and linking VisualPng will be started to view an image
|
||||||
|
from the PngSuite directory. Press Ctrl-N (and Ctrl-V) for other images.
|
||||||
|
|
||||||
|
|
||||||
|
To install:
|
||||||
|
|
||||||
|
When distributing VisualPng (or a further development) the following options
|
||||||
|
are available:
|
||||||
|
|
||||||
|
1) Build the program with the configuration "Win32 LIB" and you only need to
|
||||||
|
include the executable from the ./lib directory in your distribution.
|
||||||
|
|
||||||
|
2) Build the program with the configuration "Win32 DLL" and you need to put
|
||||||
|
in your distribution the executable from the ./dll directory and the dll's
|
||||||
|
libpng1.dll, zlib.dll and msvcrt.dll. These need to be in the user's PATH.
|
||||||
|
|
||||||
|
|
||||||
|
Willem van Schaik
|
||||||
|
Calgary, June 6th 2000
|
||||||
|
|
||||||
|
P.S. VisualPng was written based on preliminary work of:
|
||||||
|
|
||||||
|
- Simon-Pierre Cadieux
|
||||||
|
- Glenn Randers-Pehrson
|
||||||
|
- Greg Roelofs
|
||||||
|
|
||||||
964
contrib/visupng/VisualPng.c
Normal file
@@ -0,0 +1,964 @@
|
|||||||
|
//------------------------------------
|
||||||
|
// VisualPng.C -- Shows a PNG image
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
|
// Copyright 2000, Willem van Schaik.
|
||||||
|
|
||||||
|
// This code is released under the libpng license.
|
||||||
|
// For conditions of distribution and use, see the disclaimer
|
||||||
|
// and license in png.h
|
||||||
|
|
||||||
|
// switches
|
||||||
|
|
||||||
|
// defines
|
||||||
|
|
||||||
|
#define PROGNAME "VisualPng"
|
||||||
|
#define LONGNAME "Win32 Viewer for PNG-files"
|
||||||
|
#define VERSION "1.0 of 2000 June 07"
|
||||||
|
|
||||||
|
// constants
|
||||||
|
|
||||||
|
#define MARGIN 8
|
||||||
|
|
||||||
|
// standard includes
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
// application includes
|
||||||
|
|
||||||
|
#include "png.h"
|
||||||
|
#include "pngfile.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
// macros
|
||||||
|
|
||||||
|
// function prototypes
|
||||||
|
|
||||||
|
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
|
||||||
|
BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
|
||||||
|
|
||||||
|
BOOL CenterAbout (HWND hwndChild, HWND hwndParent);
|
||||||
|
|
||||||
|
BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||||
|
int *pFileIndex);
|
||||||
|
|
||||||
|
BOOL SearchPngList (TCHAR *pFileList, int FileCount, int *pFileIndex,
|
||||||
|
PTSTR pstrPrevName, PTSTR pstrNextName);
|
||||||
|
|
||||||
|
BOOL LoadImageFile(HWND hwnd, PTSTR pstrPathName,
|
||||||
|
png_byte **ppbImage, int *pxImgSize, int *pyImgSize, int *piChannels,
|
||||||
|
png_color *pBkgColor);
|
||||||
|
|
||||||
|
BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
|
||||||
|
BYTE **ppDiData, int cxWinSize, int cyWinSize,
|
||||||
|
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
|
||||||
|
BOOL bStretched);
|
||||||
|
|
||||||
|
BOOL InitBitmap (
|
||||||
|
BYTE *pDiData, int cxWinSize, int cyWinSize);
|
||||||
|
|
||||||
|
BOOL FillBitmap (
|
||||||
|
BYTE *pDiData, int cxWinSize, int cyWinSize,
|
||||||
|
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
|
||||||
|
BOOL bStretched);
|
||||||
|
|
||||||
|
// a few global variables
|
||||||
|
|
||||||
|
static char *szProgName = PROGNAME;
|
||||||
|
static char *szAppName = LONGNAME;
|
||||||
|
static char *szIconName = PROGNAME;
|
||||||
|
static char szCmdFileName [MAX_PATH];
|
||||||
|
|
||||||
|
// MAIN routine
|
||||||
|
|
||||||
|
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
|
PSTR szCmdLine, int iCmdShow)
|
||||||
|
{
|
||||||
|
HACCEL hAccel;
|
||||||
|
HWND hwnd;
|
||||||
|
MSG msg;
|
||||||
|
WNDCLASS wndclass;
|
||||||
|
int ixBorders, iyBorders;
|
||||||
|
|
||||||
|
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
|
wndclass.lpfnWndProc = WndProc;
|
||||||
|
wndclass.cbClsExtra = 0;
|
||||||
|
wndclass.cbWndExtra = 0;
|
||||||
|
wndclass.hInstance = hInstance;
|
||||||
|
wndclass.hIcon = LoadIcon (hInstance, szIconName) ;
|
||||||
|
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
|
||||||
|
wndclass.hbrBackground = NULL; // (HBRUSH) GetStockObject (GRAY_BRUSH);
|
||||||
|
wndclass.lpszMenuName = szProgName;
|
||||||
|
wndclass.lpszClassName = szProgName;
|
||||||
|
|
||||||
|
if (!RegisterClass (&wndclass))
|
||||||
|
{
|
||||||
|
MessageBox (NULL, TEXT ("Error: this program requires Windows NT!"),
|
||||||
|
szProgName, MB_ICONERROR);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if filename given on commandline, store it
|
||||||
|
if ((szCmdLine != NULL) && (*szCmdLine != '\0'))
|
||||||
|
if (szCmdLine[0] == '"')
|
||||||
|
strncpy (szCmdFileName, szCmdLine + 1, strlen(szCmdLine) - 2);
|
||||||
|
else
|
||||||
|
strcpy (szCmdFileName, szCmdLine);
|
||||||
|
else
|
||||||
|
strcpy (szCmdFileName, "");
|
||||||
|
|
||||||
|
// calculate size of window-borders
|
||||||
|
ixBorders = 2 * (GetSystemMetrics (SM_CXBORDER) +
|
||||||
|
GetSystemMetrics (SM_CXDLGFRAME));
|
||||||
|
iyBorders = 2 * (GetSystemMetrics (SM_CYBORDER) +
|
||||||
|
GetSystemMetrics (SM_CYDLGFRAME)) +
|
||||||
|
GetSystemMetrics (SM_CYCAPTION) +
|
||||||
|
GetSystemMetrics (SM_CYMENUSIZE) +
|
||||||
|
1; /* WvS: don't ask me why? */
|
||||||
|
|
||||||
|
hwnd = CreateWindow (szProgName, szAppName,
|
||||||
|
WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
|
512 + 2 * MARGIN + ixBorders, 384 + 2 * MARGIN + iyBorders,
|
||||||
|
// CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
|
NULL, NULL, hInstance, NULL);
|
||||||
|
|
||||||
|
ShowWindow (hwnd, iCmdShow);
|
||||||
|
UpdateWindow (hwnd);
|
||||||
|
|
||||||
|
hAccel = LoadAccelerators (hInstance, szProgName);
|
||||||
|
|
||||||
|
while (GetMessage (&msg, NULL, 0, 0))
|
||||||
|
{
|
||||||
|
if (!TranslateAccelerator (hwnd, hAccel, &msg))
|
||||||
|
{
|
||||||
|
TranslateMessage (&msg);
|
||||||
|
DispatchMessage (&msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg.wParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
|
{
|
||||||
|
static HINSTANCE hInstance ;
|
||||||
|
static HDC hdc;
|
||||||
|
static PAINTSTRUCT ps;
|
||||||
|
static HMENU hMenu;
|
||||||
|
|
||||||
|
static BITMAPFILEHEADER *pbmfh;
|
||||||
|
static BITMAPINFOHEADER *pbmih;
|
||||||
|
static BYTE *pbImage;
|
||||||
|
static int cxWinSize, cyWinSize;
|
||||||
|
static int cxImgSize, cyImgSize;
|
||||||
|
static int cImgChannels;
|
||||||
|
static png_color bkgColor = {127, 127, 127};
|
||||||
|
|
||||||
|
static BOOL bStretched = TRUE;
|
||||||
|
|
||||||
|
static BYTE *pDib = NULL;
|
||||||
|
static BYTE *pDiData = NULL;
|
||||||
|
|
||||||
|
static TCHAR szImgPathName [MAX_PATH];
|
||||||
|
static TCHAR szTitleName [MAX_PATH];
|
||||||
|
|
||||||
|
static TCHAR *pPngFileList = NULL;
|
||||||
|
static int iPngFileCount;
|
||||||
|
static int iPngFileIndex;
|
||||||
|
|
||||||
|
BOOL bOk;
|
||||||
|
|
||||||
|
switch (message)
|
||||||
|
{
|
||||||
|
case WM_CREATE:
|
||||||
|
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
|
||||||
|
PngFileInitialize (hwnd);
|
||||||
|
|
||||||
|
strcpy (szImgPathName, "");
|
||||||
|
|
||||||
|
// in case we process file given on command-line
|
||||||
|
|
||||||
|
if (szCmdFileName[0] != '\0')
|
||||||
|
{
|
||||||
|
strcpy (szImgPathName, szCmdFileName);
|
||||||
|
|
||||||
|
// read the other png-files in the directory for later
|
||||||
|
// next/previous commands
|
||||||
|
|
||||||
|
BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
|
||||||
|
&iPngFileIndex);
|
||||||
|
|
||||||
|
// load the image from file
|
||||||
|
|
||||||
|
if (!LoadImageFile (hwnd, szImgPathName,
|
||||||
|
&pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// invalidate the client area for later update
|
||||||
|
|
||||||
|
InvalidateRect (hwnd, NULL, TRUE);
|
||||||
|
|
||||||
|
// display the PNG into the DIBitmap
|
||||||
|
|
||||||
|
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||||
|
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_SIZE:
|
||||||
|
cxWinSize = LOWORD (lParam);
|
||||||
|
cyWinSize = HIWORD (lParam);
|
||||||
|
|
||||||
|
// invalidate the client area for later update
|
||||||
|
|
||||||
|
InvalidateRect (hwnd, NULL, TRUE);
|
||||||
|
|
||||||
|
// display the PNG into the DIBitmap
|
||||||
|
|
||||||
|
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||||
|
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_INITMENUPOPUP:
|
||||||
|
hMenu = GetMenu (hwnd);
|
||||||
|
|
||||||
|
if (pbImage)
|
||||||
|
EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_ENABLED);
|
||||||
|
else
|
||||||
|
EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_GRAYED);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_COMMAND:
|
||||||
|
hMenu = GetMenu (hwnd);
|
||||||
|
|
||||||
|
switch (LOWORD (wParam))
|
||||||
|
{
|
||||||
|
case IDM_FILE_OPEN:
|
||||||
|
|
||||||
|
// show the File Open dialog box
|
||||||
|
|
||||||
|
if (!PngFileOpenDlg (hwnd, szImgPathName, szTitleName))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// read the other png-files in the directory for later
|
||||||
|
// next/previous commands
|
||||||
|
|
||||||
|
BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
|
||||||
|
&iPngFileIndex);
|
||||||
|
|
||||||
|
// load the image from file
|
||||||
|
|
||||||
|
if (!LoadImageFile (hwnd, szImgPathName,
|
||||||
|
&pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// invalidate the client area for later update
|
||||||
|
|
||||||
|
InvalidateRect (hwnd, NULL, TRUE);
|
||||||
|
|
||||||
|
// display the PNG into the DIBitmap
|
||||||
|
|
||||||
|
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||||
|
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case IDM_FILE_SAVE:
|
||||||
|
|
||||||
|
// show the File Save dialog box
|
||||||
|
|
||||||
|
if (!PngFileSaveDlg (hwnd, szImgPathName, szTitleName))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// save the PNG to a disk file
|
||||||
|
|
||||||
|
SetCursor (LoadCursor (NULL, IDC_WAIT));
|
||||||
|
ShowCursor (TRUE);
|
||||||
|
|
||||||
|
bOk = PngSaveImage (szImgPathName, pDiData, cxWinSize, cyWinSize,
|
||||||
|
bkgColor);
|
||||||
|
|
||||||
|
ShowCursor (FALSE);
|
||||||
|
SetCursor (LoadCursor (NULL, IDC_ARROW));
|
||||||
|
|
||||||
|
if (!bOk)
|
||||||
|
MessageBox (hwnd, TEXT ("Error in saving the PNG image"),
|
||||||
|
szProgName, MB_ICONEXCLAMATION | MB_OK);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case IDM_FILE_NEXT:
|
||||||
|
|
||||||
|
// read next entry in the directory
|
||||||
|
|
||||||
|
if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
|
||||||
|
NULL, szImgPathName))
|
||||||
|
{
|
||||||
|
if (strcmp (szImgPathName, "") == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// load the image from file
|
||||||
|
|
||||||
|
if (!LoadImageFile (hwnd, szImgPathName, &pbImage,
|
||||||
|
&cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// invalidate the client area for later update
|
||||||
|
|
||||||
|
InvalidateRect (hwnd, NULL, TRUE);
|
||||||
|
|
||||||
|
// display the PNG into the DIBitmap
|
||||||
|
|
||||||
|
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||||
|
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case IDM_FILE_PREVIOUS:
|
||||||
|
|
||||||
|
// read previous entry in the directory
|
||||||
|
|
||||||
|
if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
|
||||||
|
szImgPathName, NULL))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (strcmp (szImgPathName, "") == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// load the image from file
|
||||||
|
|
||||||
|
if (!LoadImageFile (hwnd, szImgPathName, &pbImage, &cxImgSize,
|
||||||
|
&cyImgSize, &cImgChannels, &bkgColor))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// invalidate the client area for later update
|
||||||
|
|
||||||
|
InvalidateRect (hwnd, NULL, TRUE);
|
||||||
|
|
||||||
|
// display the PNG into the DIBitmap
|
||||||
|
|
||||||
|
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||||
|
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case IDM_FILE_EXIT:
|
||||||
|
|
||||||
|
// more cleanup needed...
|
||||||
|
|
||||||
|
// free image buffer
|
||||||
|
|
||||||
|
if (pDib != NULL)
|
||||||
|
{
|
||||||
|
free (pDib);
|
||||||
|
pDib = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// free file-list
|
||||||
|
|
||||||
|
if (pPngFileList != NULL)
|
||||||
|
{
|
||||||
|
free (pPngFileList);
|
||||||
|
pPngFileList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// let's go ...
|
||||||
|
|
||||||
|
exit (0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case IDM_OPTIONS_STRETCH:
|
||||||
|
bStretched = !bStretched;
|
||||||
|
if (bStretched)
|
||||||
|
CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_CHECKED);
|
||||||
|
else
|
||||||
|
CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_UNCHECKED);
|
||||||
|
|
||||||
|
// invalidate the client area for later update
|
||||||
|
|
||||||
|
InvalidateRect (hwnd, NULL, TRUE);
|
||||||
|
|
||||||
|
// display the PNG into the DIBitmap
|
||||||
|
|
||||||
|
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||||
|
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case IDM_HELP_ABOUT:
|
||||||
|
DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} // end switch
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_PAINT:
|
||||||
|
hdc = BeginPaint (hwnd, &ps);
|
||||||
|
|
||||||
|
if (pDib)
|
||||||
|
SetDIBitsToDevice (hdc, 0, 0, cxWinSize, cyWinSize, 0, 0,
|
||||||
|
0, cyWinSize, pDiData, (BITMAPINFO *) pDib, DIB_RGB_COLORS);
|
||||||
|
|
||||||
|
EndPaint (hwnd, &ps);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_DESTROY:
|
||||||
|
if (pbmfh)
|
||||||
|
{
|
||||||
|
free (pbmfh);
|
||||||
|
pbmfh = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PostQuitMessage (0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DefWindowProc (hwnd, message, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,
|
||||||
|
WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
switch (message)
|
||||||
|
{
|
||||||
|
case WM_INITDIALOG :
|
||||||
|
ShowWindow (hDlg, SW_HIDE);
|
||||||
|
CenterAbout (hDlg, GetWindow (hDlg, GW_OWNER));
|
||||||
|
ShowWindow (hDlg, SW_SHOW);
|
||||||
|
return TRUE ;
|
||||||
|
|
||||||
|
case WM_COMMAND :
|
||||||
|
switch (LOWORD (wParam))
|
||||||
|
{
|
||||||
|
case IDOK :
|
||||||
|
case IDCANCEL :
|
||||||
|
EndDialog (hDlg, 0) ;
|
||||||
|
return TRUE ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
return FALSE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------
|
||||||
|
// CenterAbout
|
||||||
|
//---------------
|
||||||
|
|
||||||
|
BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
|
||||||
|
{
|
||||||
|
RECT rChild, rParent, rWorkArea;
|
||||||
|
int wChild, hChild, wParent, hParent;
|
||||||
|
int xNew, yNew;
|
||||||
|
BOOL bResult;
|
||||||
|
|
||||||
|
// Get the Height and Width of the child window
|
||||||
|
GetWindowRect (hwndChild, &rChild);
|
||||||
|
wChild = rChild.right - rChild.left;
|
||||||
|
hChild = rChild.bottom - rChild.top;
|
||||||
|
|
||||||
|
// Get the Height and Width of the parent window
|
||||||
|
GetWindowRect (hwndParent, &rParent);
|
||||||
|
wParent = rParent.right - rParent.left;
|
||||||
|
hParent = rParent.bottom - rParent.top;
|
||||||
|
|
||||||
|
// Get the limits of the 'workarea'
|
||||||
|
bResult = SystemParametersInfo(
|
||||||
|
SPI_GETWORKAREA, // system parameter to query or set
|
||||||
|
sizeof(RECT),
|
||||||
|
&rWorkArea,
|
||||||
|
0);
|
||||||
|
if (!bResult) {
|
||||||
|
rWorkArea.left = rWorkArea.top = 0;
|
||||||
|
rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
|
||||||
|
rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate new X position, then adjust for workarea
|
||||||
|
xNew = rParent.left + ((wParent - wChild) /2);
|
||||||
|
if (xNew < rWorkArea.left) {
|
||||||
|
xNew = rWorkArea.left;
|
||||||
|
} else if ((xNew+wChild) > rWorkArea.right) {
|
||||||
|
xNew = rWorkArea.right - wChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate new Y position, then adjust for workarea
|
||||||
|
yNew = rParent.top + ((hParent - hChild) /2);
|
||||||
|
if (yNew < rWorkArea.top) {
|
||||||
|
yNew = rWorkArea.top;
|
||||||
|
} else if ((yNew+hChild) > rWorkArea.bottom) {
|
||||||
|
yNew = rWorkArea.bottom - hChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set it, and return
|
||||||
|
return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE |
|
||||||
|
SWP_NOZORDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------
|
||||||
|
// BuildPngList
|
||||||
|
//----------------
|
||||||
|
|
||||||
|
BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||||
|
int *pFileIndex)
|
||||||
|
{
|
||||||
|
static TCHAR szImgPathName [MAX_PATH];
|
||||||
|
static TCHAR szImgFileName [MAX_PATH];
|
||||||
|
static TCHAR szImgFindName [MAX_PATH];
|
||||||
|
|
||||||
|
WIN32_FIND_DATA finddata;
|
||||||
|
HANDLE hFind;
|
||||||
|
|
||||||
|
static TCHAR szTmp [MAX_PATH];
|
||||||
|
BOOL bOk;
|
||||||
|
int i, ii;
|
||||||
|
int j, jj;
|
||||||
|
|
||||||
|
// free previous file-list
|
||||||
|
|
||||||
|
if (*ppFileList != NULL)
|
||||||
|
{
|
||||||
|
free (*ppFileList);
|
||||||
|
*ppFileList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract foldername, filename and search-name
|
||||||
|
|
||||||
|
strcpy (szImgPathName, pstrPathName);
|
||||||
|
strcpy (szImgFileName, strrchr (pstrPathName, '\\') + 1);
|
||||||
|
|
||||||
|
strcpy (szImgFindName, szImgPathName);
|
||||||
|
*(strrchr (szImgFindName, '\\') + 1) = '\0';
|
||||||
|
strcat (szImgFindName, "*.png");
|
||||||
|
|
||||||
|
// first cycle: count number of files in directory for memory allocation
|
||||||
|
|
||||||
|
*pFileCount = 0;
|
||||||
|
|
||||||
|
hFind = FindFirstFile(szImgFindName, &finddata);
|
||||||
|
bOk = (hFind != (HANDLE) -1);
|
||||||
|
|
||||||
|
while (bOk)
|
||||||
|
{
|
||||||
|
*pFileCount += 1;
|
||||||
|
bOk = FindNextFile(hFind, &finddata);
|
||||||
|
}
|
||||||
|
FindClose(hFind);
|
||||||
|
|
||||||
|
// allocation memory for file-list
|
||||||
|
|
||||||
|
*ppFileList = (TCHAR *) malloc (*pFileCount * MAX_PATH);
|
||||||
|
|
||||||
|
// second cycle: read directory and store filenames in file-list
|
||||||
|
|
||||||
|
hFind = FindFirstFile(szImgFindName, &finddata);
|
||||||
|
bOk = (hFind != (HANDLE) -1);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
ii = 0;
|
||||||
|
while (bOk)
|
||||||
|
{
|
||||||
|
strcpy (*ppFileList + ii, szImgPathName);
|
||||||
|
strcpy (strrchr(*ppFileList + ii, '\\') + 1, finddata.cFileName);
|
||||||
|
|
||||||
|
if (strcmp(pstrPathName, *ppFileList + ii) == 0)
|
||||||
|
*pFileIndex = i;
|
||||||
|
|
||||||
|
ii += MAX_PATH;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
bOk = FindNextFile(hFind, &finddata);
|
||||||
|
}
|
||||||
|
FindClose(hFind);
|
||||||
|
|
||||||
|
// finally we must sort the file-list
|
||||||
|
|
||||||
|
for (i = 0; i < *pFileCount - 1; i++)
|
||||||
|
{
|
||||||
|
ii = i * MAX_PATH;
|
||||||
|
for (j = i+1; j < *pFileCount; j++)
|
||||||
|
{
|
||||||
|
jj = j * MAX_PATH;
|
||||||
|
if (strcmp (*ppFileList + ii, *ppFileList + jj) > 0)
|
||||||
|
{
|
||||||
|
strcpy (szTmp, *ppFileList + jj);
|
||||||
|
strcpy (*ppFileList + jj, *ppFileList + ii);
|
||||||
|
strcpy (*ppFileList + ii, szTmp);
|
||||||
|
|
||||||
|
// check if this was the current image that we moved
|
||||||
|
|
||||||
|
if (*pFileIndex == i)
|
||||||
|
*pFileIndex = j;
|
||||||
|
else
|
||||||
|
if (*pFileIndex == j)
|
||||||
|
*pFileIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------
|
||||||
|
// SearchPngList
|
||||||
|
//----------------
|
||||||
|
|
||||||
|
BOOL SearchPngList (
|
||||||
|
TCHAR *pFileList, int FileCount, int *pFileIndex,
|
||||||
|
PTSTR pstrPrevName, PTSTR pstrNextName)
|
||||||
|
{
|
||||||
|
if (FileCount > 0)
|
||||||
|
{
|
||||||
|
// get previous entry
|
||||||
|
|
||||||
|
if (pstrPrevName != NULL)
|
||||||
|
{
|
||||||
|
if (*pFileIndex > 0)
|
||||||
|
*pFileIndex -= 1;
|
||||||
|
else
|
||||||
|
*pFileIndex = FileCount - 1;
|
||||||
|
|
||||||
|
strcpy (pstrPrevName, pFileList + (*pFileIndex * MAX_PATH));
|
||||||
|
}
|
||||||
|
|
||||||
|
// get next entry
|
||||||
|
|
||||||
|
if (pstrNextName != NULL)
|
||||||
|
{
|
||||||
|
if (*pFileIndex < FileCount - 1)
|
||||||
|
*pFileIndex += 1;
|
||||||
|
else
|
||||||
|
*pFileIndex = 0;
|
||||||
|
|
||||||
|
strcpy (pstrNextName, pFileList + (*pFileIndex * MAX_PATH));
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------
|
||||||
|
// LoadImageFile
|
||||||
|
//-----------------
|
||||||
|
|
||||||
|
BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
|
||||||
|
png_byte **ppbImage, int *pxImgSize, int *pyImgSize,
|
||||||
|
int *piChannels, png_color *pBkgColor)
|
||||||
|
{
|
||||||
|
static TCHAR szTmp [MAX_PATH];
|
||||||
|
|
||||||
|
// if there's an existing PNG, free the memory
|
||||||
|
|
||||||
|
if (*ppbImage)
|
||||||
|
{
|
||||||
|
free (*ppbImage);
|
||||||
|
*ppbImage = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the entire PNG into memory
|
||||||
|
|
||||||
|
SetCursor (LoadCursor (NULL, IDC_WAIT));
|
||||||
|
ShowCursor (TRUE);
|
||||||
|
|
||||||
|
PngLoadImage (pstrPathName, ppbImage, pxImgSize, pyImgSize, piChannels,
|
||||||
|
pBkgColor);
|
||||||
|
|
||||||
|
ShowCursor (FALSE);
|
||||||
|
SetCursor (LoadCursor (NULL, IDC_ARROW));
|
||||||
|
|
||||||
|
if (*ppbImage != NULL)
|
||||||
|
{
|
||||||
|
sprintf (szTmp, "VisualPng - %s", strrchr(pstrPathName, '\\') + 1);
|
||||||
|
SetWindowText (hwnd, szTmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox (hwnd, TEXT ("Error in loading the PNG image"),
|
||||||
|
szProgName, MB_ICONEXCLAMATION | MB_OK);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------
|
||||||
|
// DisplayImage
|
||||||
|
//----------------
|
||||||
|
|
||||||
|
BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
|
||||||
|
BYTE **ppDiData, int cxWinSize, int cyWinSize,
|
||||||
|
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
|
||||||
|
BOOL bStretched)
|
||||||
|
{
|
||||||
|
BYTE *pDib = *ppDib;
|
||||||
|
BYTE *pDiData = *ppDiData;
|
||||||
|
// BITMAPFILEHEADER *pbmfh;
|
||||||
|
BITMAPINFOHEADER *pbmih;
|
||||||
|
WORD wDIRowBytes;
|
||||||
|
png_color bkgBlack = {0, 0, 0};
|
||||||
|
png_color bkgGray = {127, 127, 127};
|
||||||
|
png_color bkgWhite = {255, 255, 255};
|
||||||
|
|
||||||
|
// allocate memory for the Device Independant bitmap
|
||||||
|
|
||||||
|
wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2;
|
||||||
|
|
||||||
|
if (pDib)
|
||||||
|
{
|
||||||
|
free (pDib);
|
||||||
|
pDib = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(pDib = (BYTE *) malloc (sizeof(BITMAPINFOHEADER) +
|
||||||
|
wDIRowBytes * cyWinSize)))
|
||||||
|
{
|
||||||
|
MessageBox (hwnd, TEXT ("Error in displaying the PNG image"),
|
||||||
|
szProgName, MB_ICONEXCLAMATION | MB_OK);
|
||||||
|
*ppDib = pDib = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
*ppDib = pDib;
|
||||||
|
memset (pDib, 0, sizeof(BITMAPINFOHEADER));
|
||||||
|
|
||||||
|
// initialize the dib-structure
|
||||||
|
|
||||||
|
pbmih = (BITMAPINFOHEADER *) pDib;
|
||||||
|
pbmih->biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
pbmih->biWidth = cxWinSize;
|
||||||
|
pbmih->biHeight = -((long) cyWinSize);
|
||||||
|
pbmih->biPlanes = 1;
|
||||||
|
pbmih->biBitCount = 24;
|
||||||
|
pbmih->biCompression = 0;
|
||||||
|
pDiData = pDib + sizeof(BITMAPINFOHEADER);
|
||||||
|
*ppDiData = pDiData;
|
||||||
|
|
||||||
|
// first fill bitmap with gray and image border
|
||||||
|
|
||||||
|
InitBitmap (pDiData, cxWinSize, cyWinSize);
|
||||||
|
|
||||||
|
// then fill bitmap with image
|
||||||
|
|
||||||
|
if (pbImage)
|
||||||
|
{
|
||||||
|
FillBitmap (
|
||||||
|
pDiData, cxWinSize, cyWinSize,
|
||||||
|
pbImage, cxImgSize, cyImgSize, cImgChannels,
|
||||||
|
bStretched);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------
|
||||||
|
// InitBitmap
|
||||||
|
//--------------
|
||||||
|
|
||||||
|
BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)
|
||||||
|
{
|
||||||
|
BYTE *dst;
|
||||||
|
int x, y, col;
|
||||||
|
|
||||||
|
// initialize the background with gray
|
||||||
|
|
||||||
|
dst = pDiData;
|
||||||
|
for (y = 0; y < cyWinSize; y++)
|
||||||
|
{
|
||||||
|
col = 0;
|
||||||
|
for (x = 0; x < cxWinSize; x++)
|
||||||
|
{
|
||||||
|
// fill with GRAY
|
||||||
|
*dst++ = 127;
|
||||||
|
*dst++ = 127;
|
||||||
|
*dst++ = 127;
|
||||||
|
col += 3;
|
||||||
|
}
|
||||||
|
// rows start on 4 byte boundaries
|
||||||
|
while ((col % 4) != 0)
|
||||||
|
{
|
||||||
|
dst++;
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------
|
||||||
|
// FillBitmap
|
||||||
|
//--------------
|
||||||
|
|
||||||
|
BOOL FillBitmap (
|
||||||
|
BYTE *pDiData, int cxWinSize, int cyWinSize,
|
||||||
|
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
|
||||||
|
BOOL bStretched)
|
||||||
|
{
|
||||||
|
BYTE *pStretchedImage;
|
||||||
|
BYTE *pImg;
|
||||||
|
BYTE *src, *dst;
|
||||||
|
BYTE r, g, b, a;
|
||||||
|
const int cDIChannels = 3;
|
||||||
|
WORD wImgRowBytes;
|
||||||
|
WORD wDIRowBytes;
|
||||||
|
int cxNewSize, cyNewSize;
|
||||||
|
int cxImgPos, cyImgPos;
|
||||||
|
int xImg, yImg;
|
||||||
|
int xWin, yWin;
|
||||||
|
int xOld, yOld;
|
||||||
|
int xNew, yNew;
|
||||||
|
|
||||||
|
if (bStretched)
|
||||||
|
{
|
||||||
|
cxNewSize = cxWinSize - 2 * MARGIN;
|
||||||
|
cyNewSize = cyWinSize - 2 * MARGIN;
|
||||||
|
|
||||||
|
// stretch the image to it's window determined size
|
||||||
|
|
||||||
|
// the following two are the same, but the first has side-effects
|
||||||
|
// because of rounding
|
||||||
|
// if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize))
|
||||||
|
if ((cyNewSize * cxImgSize) > (cyImgSize * cxNewSize))
|
||||||
|
{
|
||||||
|
cyNewSize = cxNewSize * cyImgSize / cxImgSize;
|
||||||
|
cxImgPos = MARGIN;
|
||||||
|
cyImgPos = (cyWinSize - cyNewSize) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cxNewSize = cyNewSize * cxImgSize / cyImgSize;
|
||||||
|
cyImgPos = MARGIN;
|
||||||
|
cxImgPos = (cxWinSize - cxNewSize) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
pStretchedImage = malloc (cImgChannels * cxNewSize * cyNewSize);
|
||||||
|
pImg = pStretchedImage;
|
||||||
|
|
||||||
|
for (yNew = 0; yNew < cyNewSize; yNew++)
|
||||||
|
{
|
||||||
|
yOld = yNew * cyImgSize / cyNewSize;
|
||||||
|
for (xNew = 0; xNew < cxNewSize; xNew++)
|
||||||
|
{
|
||||||
|
xOld = xNew * cxImgSize / cxNewSize;
|
||||||
|
|
||||||
|
r = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 0);
|
||||||
|
g = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 1);
|
||||||
|
b = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 2);
|
||||||
|
*pImg++ = r;
|
||||||
|
*pImg++ = g;
|
||||||
|
*pImg++ = b;
|
||||||
|
if (cImgChannels == 4)
|
||||||
|
{
|
||||||
|
a = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld)
|
||||||
|
+ 3);
|
||||||
|
*pImg++ = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate row-bytes
|
||||||
|
|
||||||
|
wImgRowBytes = cImgChannels * cxNewSize;
|
||||||
|
wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
|
||||||
|
|
||||||
|
// copy image to screen
|
||||||
|
|
||||||
|
for (yImg = 0, yWin = cyImgPos; yImg < cyNewSize; yImg++, yWin++)
|
||||||
|
{
|
||||||
|
if (yWin >= cyWinSize - cyImgPos)
|
||||||
|
break;
|
||||||
|
src = pStretchedImage + yImg * wImgRowBytes;
|
||||||
|
dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;
|
||||||
|
|
||||||
|
for (xImg = 0, xWin = cxImgPos; xImg < cxNewSize; xImg++, xWin++)
|
||||||
|
{
|
||||||
|
if (xWin >= cxWinSize - cxImgPos)
|
||||||
|
break;
|
||||||
|
r = *src++;
|
||||||
|
g = *src++;
|
||||||
|
b = *src++;
|
||||||
|
*dst++ = b; /* note the reverse order */
|
||||||
|
*dst++ = g;
|
||||||
|
*dst++ = r;
|
||||||
|
if (cImgChannels == 4)
|
||||||
|
{
|
||||||
|
a = *src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// free memory
|
||||||
|
|
||||||
|
if (pStretchedImage != NULL)
|
||||||
|
{
|
||||||
|
free (pStretchedImage);
|
||||||
|
pStretchedImage = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// process the image not-stretched
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// calculate the central position
|
||||||
|
|
||||||
|
cxImgPos = (cxWinSize - cxImgSize) / 2;
|
||||||
|
cyImgPos = (cyWinSize - cyImgSize) / 2;
|
||||||
|
|
||||||
|
// check for image larger than window
|
||||||
|
|
||||||
|
if (cxImgPos < MARGIN)
|
||||||
|
cxImgPos = MARGIN;
|
||||||
|
if (cyImgPos < MARGIN)
|
||||||
|
cyImgPos = MARGIN;
|
||||||
|
|
||||||
|
// calculate both row-bytes
|
||||||
|
|
||||||
|
wImgRowBytes = cImgChannels * cxImgSize;
|
||||||
|
wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
|
||||||
|
|
||||||
|
// copy image to screen
|
||||||
|
|
||||||
|
for (yImg = 0, yWin = cyImgPos; yImg < cyImgSize; yImg++, yWin++)
|
||||||
|
{
|
||||||
|
if (yWin >= cyWinSize - MARGIN)
|
||||||
|
break;
|
||||||
|
src = pbImage + yImg * wImgRowBytes;
|
||||||
|
dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;
|
||||||
|
|
||||||
|
for (xImg = 0, xWin = cxImgPos; xImg < cxImgSize; xImg++, xWin++)
|
||||||
|
{
|
||||||
|
if (xWin >= cxWinSize - MARGIN)
|
||||||
|
break;
|
||||||
|
r = *src++;
|
||||||
|
g = *src++;
|
||||||
|
b = *src++;
|
||||||
|
*dst++ = b; /* note the reverse order */
|
||||||
|
*dst++ = g;
|
||||||
|
*dst++ = r;
|
||||||
|
if (cImgChannels == 4)
|
||||||
|
{
|
||||||
|
a = *src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------
|
||||||
|
// end of source
|
||||||
|
//-----------------
|
||||||
147
contrib/visupng/VisualPng.dsp
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
# Microsoft Developer Studio Project File - Name="VisualPng" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||||
|
|
||||||
|
CFG=VisualPng - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "VisualPng.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "VisualPng.mak" CFG="VisualPng - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "VisualPng - Win32 Release" (based on "Win32 (x86) Application")
|
||||||
|
!MESSAGE "VisualPng - Win32 Debug" (based on "Win32 (x86) Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
MTL=midl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "VisualPng - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Ignore_Export_Lib 0
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /O2 /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /c
|
||||||
|
# SUBTRACT BASE CPP /YX
|
||||||
|
# ADD CPP /nologo /MD /W3 /O2 /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /c
|
||||||
|
# SUBTRACT CPP /YX
|
||||||
|
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||||
|
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||||
|
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
|
||||||
|
# ADD LINK32 ..\..\projects\visualc6\Win32_LIB_Release\libpng.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_Release\zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
|
||||||
|
# Begin Special Build Tool
|
||||||
|
OutDir=.\Release
|
||||||
|
SOURCE="$(InputPath)"
|
||||||
|
PostBuild_Cmds=$(outdir)\VisualPng.exe ..\..\contrib\pngsuite\basn6a16.png
|
||||||
|
# End Special Build Tool
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "VisualPng - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Ignore_Export_Lib 0
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /GZ /c
|
||||||
|
# SUBTRACT BASE CPP /YX
|
||||||
|
# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /GZ /c
|
||||||
|
# SUBTRACT CPP /YX
|
||||||
|
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||||
|
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||||
|
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 ..\..\projects\visualc6\Win32_LIB_Release\libpng.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_Release\zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept
|
||||||
|
# Begin Special Build Tool
|
||||||
|
OutDir=.\Debug
|
||||||
|
SOURCE="$(InputPath)"
|
||||||
|
PostBuild_Cmds=$(outdir)\VisualPng.exe ..\..\contrib\pngsuite\basn6a16.png
|
||||||
|
# End Special Build Tool
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "VisualPng - Win32 Release"
|
||||||
|
# Name "VisualPng - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\PngFile.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\VisualPng.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\cexcept.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\PngFile.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\resource.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\VisualPng.ico
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\VisualPng.rc
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
||||||
29
contrib/visupng/VisualPng.dsw
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "VisualPng"=.\VisualPng.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
BIN
contrib/visupng/VisualPng.ico
Normal file
|
After Width: | Height: | Size: 766 B |
BIN
contrib/visupng/VisualPng.png
Normal file
|
After Width: | Height: | Size: 208 B |
152
contrib/visupng/VisualPng.rc
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
//Microsoft Developer Studio generated resource script.
|
||||||
|
//
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
#define APSTUDIO_READONLY_SYMBOLS
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 2 resource.
|
||||||
|
//
|
||||||
|
#include "afxres.h"
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// English (U.S.) resources
|
||||||
|
|
||||||
|
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||||
|
#ifdef _WIN32
|
||||||
|
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||||
|
#pragma code_page(1252)
|
||||||
|
#endif //_WIN32
|
||||||
|
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// TEXTINCLUDE
|
||||||
|
//
|
||||||
|
|
||||||
|
1 TEXTINCLUDE DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
"resource.h\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
2 TEXTINCLUDE DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
"#include ""afxres.h""\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
3 TEXTINCLUDE DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
"\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Menu
|
||||||
|
//
|
||||||
|
|
||||||
|
VISUALPNG MENU DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
POPUP "&File"
|
||||||
|
BEGIN
|
||||||
|
MENUITEM "&Open Image...\tCtrl+O", IDM_FILE_OPEN
|
||||||
|
MENUITEM "Save &As...", IDM_FILE_SAVE
|
||||||
|
MENUITEM SEPARATOR
|
||||||
|
MENUITEM "&Next Image\tCtrl+N", IDM_FILE_NEXT
|
||||||
|
MENUITEM "Pre&vious Image\tCtrl+V", IDM_FILE_PREVIOUS
|
||||||
|
MENUITEM SEPARATOR
|
||||||
|
MENUITEM "E&xit\tAlt+X", IDM_FILE_EXIT
|
||||||
|
END
|
||||||
|
POPUP "&Options"
|
||||||
|
BEGIN
|
||||||
|
MENUITEM "&Stretch", IDM_OPTIONS_STRETCH, CHECKED
|
||||||
|
END
|
||||||
|
POPUP "&Help"
|
||||||
|
BEGIN
|
||||||
|
MENUITEM "&About", IDM_HELP_ABOUT
|
||||||
|
END
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Accelerator
|
||||||
|
//
|
||||||
|
|
||||||
|
VISUALPNG ACCELERATORS DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
"N", IDM_FILE_NEXT, VIRTKEY, CONTROL, NOINVERT
|
||||||
|
"O", IDM_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
|
||||||
|
"P", IDM_FILE_PREVIOUS, VIRTKEY, CONTROL, NOINVERT
|
||||||
|
"V", IDM_FILE_PREVIOUS, VIRTKEY, CONTROL, NOINVERT
|
||||||
|
"X", IDM_FILE_EXIT, VIRTKEY, ALT, NOINVERT
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Icon
|
||||||
|
//
|
||||||
|
|
||||||
|
// Icon with lowest ID value placed first to ensure application icon
|
||||||
|
// remains consistent on all systems.
|
||||||
|
VISUALPNG ICON DISCARDABLE "VisualPng.ico"
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Dialog
|
||||||
|
//
|
||||||
|
|
||||||
|
ABOUTBOX DIALOG DISCARDABLE 0, 0, 186, 94
|
||||||
|
STYLE DS_MODALFRAME | WS_POPUP
|
||||||
|
FONT 8, "MS Sans Serif"
|
||||||
|
BEGIN
|
||||||
|
DEFPUSHBUTTON "OK",IDOK,68,67,50,14
|
||||||
|
CTEXT "VisualPng 1.0 - June 2000",IDC_STATIC,49,14,88,8
|
||||||
|
LTEXT "a PNG image viewer",IDC_STATIC,60,30,66,8
|
||||||
|
LTEXT "(c) Willem van Schaik, 2000",IDC_STATIC,48,52,90,8
|
||||||
|
LTEXT "to demonstrate the use of libpng in Visual C",
|
||||||
|
IDC_STATIC,25,38,136,8
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// DESIGNINFO
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
GUIDELINES DESIGNINFO DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
"ABOUTBOX", DIALOG
|
||||||
|
BEGIN
|
||||||
|
LEFTMARGIN, 7
|
||||||
|
RIGHTMARGIN, 179
|
||||||
|
TOPMARGIN, 7
|
||||||
|
BOTTOMMARGIN, 87
|
||||||
|
END
|
||||||
|
END
|
||||||
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
#endif // English (U.S.) resources
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 3 resource.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif // not APSTUDIO_INVOKED
|
||||||
|
|
||||||
248
contrib/visupng/cexcept.h
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
/*===
|
||||||
|
cexcept.h 2.0.1 (2008-Jul-19-Sat)
|
||||||
|
http://www.nicemice.net/cexcept/
|
||||||
|
Adam M. Costello
|
||||||
|
http://www.nicemice.net/amc/
|
||||||
|
|
||||||
|
An interface for exception-handling in ANSI C (C89 and subsequent ISO
|
||||||
|
standards), developed jointly with Cosmin Truta.
|
||||||
|
|
||||||
|
Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.
|
||||||
|
This software may be modified only if its author and version
|
||||||
|
information is updated accurately, and may be redistributed
|
||||||
|
only if accompanied by this unaltered notice. Subject to those
|
||||||
|
restrictions, permission is granted to anyone to do anything
|
||||||
|
with this software. The copyright holders make no guarantees
|
||||||
|
regarding this software, and are not responsible for any damage
|
||||||
|
resulting from its use.
|
||||||
|
|
||||||
|
The cexcept interface is not compatible with and cannot interact
|
||||||
|
with system exceptions (like division by zero or memory segmentation
|
||||||
|
violation), compiler-generated exceptions (like C++ exceptions), or
|
||||||
|
other exception-handling interfaces.
|
||||||
|
|
||||||
|
When using this interface across multiple .c files, do not include
|
||||||
|
this header file directly. Instead, create a wrapper header file that
|
||||||
|
includes this header file and then invokes the define_exception_type
|
||||||
|
macro (see below). The .c files should then include that header file.
|
||||||
|
|
||||||
|
The interface consists of one type, one well-known name, and six macros.
|
||||||
|
|
||||||
|
|
||||||
|
define_exception_type(type_name);
|
||||||
|
|
||||||
|
This macro is used like an external declaration. It specifies
|
||||||
|
the type of object that gets copied from the exception thrower to
|
||||||
|
the exception catcher. The type_name can be any type that can be
|
||||||
|
assigned to, that is, a non-constant arithmetic type, struct, union,
|
||||||
|
or pointer. Examples:
|
||||||
|
|
||||||
|
define_exception_type(int);
|
||||||
|
|
||||||
|
enum exception { out_of_memory, bad_arguments, disk_full };
|
||||||
|
define_exception_type(enum exception);
|
||||||
|
|
||||||
|
struct exception { int code; const char *msg; };
|
||||||
|
define_exception_type(struct exception);
|
||||||
|
|
||||||
|
Because throwing an exception causes the object to be copied (not
|
||||||
|
just once, but twice), programmers may wish to consider size when
|
||||||
|
choosing the exception type.
|
||||||
|
|
||||||
|
|
||||||
|
struct exception_context;
|
||||||
|
|
||||||
|
This type may be used after the define_exception_type() macro has
|
||||||
|
been invoked. A struct exception_context must be known to both
|
||||||
|
the thrower and the catcher. It is expected that there be one
|
||||||
|
context for each thread that uses exceptions. It would certainly
|
||||||
|
be dangerous for multiple threads to access the same context.
|
||||||
|
One thread can use multiple contexts, but that is likely to be
|
||||||
|
confusing and not typically useful. The application can allocate
|
||||||
|
this structure in any way it pleases--automatic, static, or dynamic.
|
||||||
|
The application programmer should pretend not to know the structure
|
||||||
|
members, which are subject to change.
|
||||||
|
|
||||||
|
|
||||||
|
struct exception_context *the_exception_context;
|
||||||
|
|
||||||
|
The Try/Catch and Throw statements (described below) implicitly
|
||||||
|
refer to a context, using the name the_exception_context. It is
|
||||||
|
the application's responsibility to make sure that this name yields
|
||||||
|
the address of a mutable (non-constant) struct exception_context
|
||||||
|
wherever those statements are used. Subject to that constraint, the
|
||||||
|
application may declare a variable of this name anywhere it likes
|
||||||
|
(inside a function, in a parameter list, or externally), and may
|
||||||
|
use whatever storage class specifiers (static, extern, etc) or type
|
||||||
|
qualifiers (const, volatile, etc) it likes. Examples:
|
||||||
|
|
||||||
|
static struct exception_context
|
||||||
|
* const the_exception_context = &foo;
|
||||||
|
|
||||||
|
{ struct exception_context *the_exception_context = bar; ... }
|
||||||
|
|
||||||
|
int blah(struct exception_context *the_exception_context, ...);
|
||||||
|
|
||||||
|
extern struct exception_context the_exception_context[1];
|
||||||
|
|
||||||
|
The last example illustrates a trick that avoids creating a pointer
|
||||||
|
object separate from the structure object.
|
||||||
|
|
||||||
|
The name could even be a macro, for example:
|
||||||
|
|
||||||
|
struct exception_context ec_array[numthreads];
|
||||||
|
#define the_exception_context (ec_array + thread_id)
|
||||||
|
|
||||||
|
Be aware that the_exception_context is used several times by the
|
||||||
|
Try/Catch/Throw macros, so it shouldn't be expensive or have side
|
||||||
|
effects. The expansion must be a drop-in replacement for an
|
||||||
|
identifier, so it's safest to put parentheses around it.
|
||||||
|
|
||||||
|
|
||||||
|
void init_exception_context(struct exception_context *ec);
|
||||||
|
|
||||||
|
For context structures allocated statically (by an external
|
||||||
|
definition or using the "static" keyword), the implicit
|
||||||
|
initialization to all zeros is sufficient, but contexts allocated
|
||||||
|
by other means must be initialized using this macro before they
|
||||||
|
are used by a Try/Catch statement. It does no harm to initialize
|
||||||
|
a context more than once (by using this macro on a statically
|
||||||
|
allocated context, or using this macro twice on the same context),
|
||||||
|
but a context must not be re-initialized after it has been used by a
|
||||||
|
Try/Catch statement.
|
||||||
|
|
||||||
|
|
||||||
|
Try statement
|
||||||
|
Catch (expression) statement
|
||||||
|
|
||||||
|
The Try/Catch/Throw macros are capitalized in order to avoid
|
||||||
|
confusion with the C++ keywords, which have subtly different
|
||||||
|
semantics.
|
||||||
|
|
||||||
|
A Try/Catch statement has a syntax similar to an if/else statement,
|
||||||
|
except that the parenthesized expression goes after the second
|
||||||
|
keyword rather than the first. As with if/else, there are two
|
||||||
|
clauses, each of which may be a simple statement ending with a
|
||||||
|
semicolon or a brace-enclosed compound statement. But whereas
|
||||||
|
the else clause is optional, the Catch clause is required. The
|
||||||
|
expression must be a modifiable lvalue (something capable of being
|
||||||
|
assigned to) of the same type (disregarding type qualifiers) that
|
||||||
|
was passed to define_exception_type().
|
||||||
|
|
||||||
|
If a Throw that uses the same exception context as the Try/Catch is
|
||||||
|
executed within the Try clause (typically within a function called
|
||||||
|
by the Try clause), and the exception is not caught by a nested
|
||||||
|
Try/Catch statement, then a copy of the exception will be assigned
|
||||||
|
to the expression, and control will jump to the Catch clause. If no
|
||||||
|
such Throw is executed, then the assignment is not performed, and
|
||||||
|
the Catch clause is not executed.
|
||||||
|
|
||||||
|
The expression is not evaluated unless and until the exception is
|
||||||
|
caught, which is significant if it has side effects, for example:
|
||||||
|
|
||||||
|
Try foo();
|
||||||
|
Catch (p[++i].e) { ... }
|
||||||
|
|
||||||
|
IMPORTANT: Jumping into or out of a Try clause (for example via
|
||||||
|
return, break, continue, goto, longjmp) is forbidden--the compiler
|
||||||
|
will not complain, but bad things will happen at run-time. Jumping
|
||||||
|
into or out of a Catch clause is okay, and so is jumping around
|
||||||
|
inside a Try clause. In many cases where one is tempted to return
|
||||||
|
from a Try clause, it will suffice to use Throw, and then return
|
||||||
|
from the Catch clause. Another option is to set a flag variable and
|
||||||
|
use goto to jump to the end of the Try clause, then check the flag
|
||||||
|
after the Try/Catch statement.
|
||||||
|
|
||||||
|
IMPORTANT: The values of any non-volatile automatic variables
|
||||||
|
changed within the Try clause are undefined after an exception is
|
||||||
|
caught. Therefore, variables modified inside the Try block whose
|
||||||
|
values are needed later outside the Try block must either use static
|
||||||
|
storage or be declared with the "volatile" type qualifier.
|
||||||
|
|
||||||
|
|
||||||
|
Throw expression;
|
||||||
|
|
||||||
|
A Throw statement is very much like a return statement, except that
|
||||||
|
the expression is required. Whereas return jumps back to the place
|
||||||
|
where the current function was called, Throw jumps back to the Catch
|
||||||
|
clause of the innermost enclosing Try clause. The expression must
|
||||||
|
be compatible with the type passed to define_exception_type(). The
|
||||||
|
exception must be caught, otherwise the program may crash.
|
||||||
|
|
||||||
|
Slight limitation: If the expression is a comma-expression, it must
|
||||||
|
be enclosed in parentheses.
|
||||||
|
|
||||||
|
|
||||||
|
Try statement
|
||||||
|
Catch_anonymous statement
|
||||||
|
|
||||||
|
When the value of the exception is not needed, a Try/Catch statement
|
||||||
|
can use Catch_anonymous instead of Catch (expression).
|
||||||
|
|
||||||
|
|
||||||
|
Everything below this point is for the benefit of the compiler. The
|
||||||
|
application programmer should pretend not to know any of it, because it
|
||||||
|
is subject to change.
|
||||||
|
|
||||||
|
===*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CEXCEPT_H
|
||||||
|
#define CEXCEPT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#define define_exception_type(etype) \
|
||||||
|
struct exception_context { \
|
||||||
|
jmp_buf *penv; \
|
||||||
|
int caught; \
|
||||||
|
volatile struct { etype etmp; } v; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* etmp must be volatile because the application might use automatic */
|
||||||
|
/* storage for the_exception_context, and etmp is modified between */
|
||||||
|
/* the calls to setjmp() and longjmp(). A wrapper struct is used to */
|
||||||
|
/* avoid warnings about a duplicate volatile qualifier in case etype */
|
||||||
|
/* already includes it. */
|
||||||
|
|
||||||
|
#define init_exception_context(ec) ((void)((ec)->penv = 0))
|
||||||
|
|
||||||
|
#define Try \
|
||||||
|
{ \
|
||||||
|
jmp_buf *exception__prev, exception__env; \
|
||||||
|
exception__prev = the_exception_context->penv; \
|
||||||
|
the_exception_context->penv = &exception__env; \
|
||||||
|
if (setjmp(exception__env) == 0) { \
|
||||||
|
do
|
||||||
|
|
||||||
|
#define exception__catch(action) \
|
||||||
|
while (the_exception_context->caught = 0, \
|
||||||
|
the_exception_context->caught); \
|
||||||
|
} \
|
||||||
|
else { \
|
||||||
|
the_exception_context->caught = 1; \
|
||||||
|
} \
|
||||||
|
the_exception_context->penv = exception__prev; \
|
||||||
|
} \
|
||||||
|
if (!the_exception_context->caught || action) { } \
|
||||||
|
else
|
||||||
|
|
||||||
|
#define Catch(e) exception__catch(((e) = the_exception_context->v.etmp, 0))
|
||||||
|
#define Catch_anonymous exception__catch(0)
|
||||||
|
|
||||||
|
/* Try ends with do, and Catch begins with while(0) and ends with */
|
||||||
|
/* else, to ensure that Try/Catch syntax is similar to if/else */
|
||||||
|
/* syntax. */
|
||||||
|
/* */
|
||||||
|
/* The 0 in while(0) is expressed as x=0,x in order to appease */
|
||||||
|
/* compilers that warn about constant expressions inside while(). */
|
||||||
|
/* Most compilers should still recognize that the condition is always */
|
||||||
|
/* false and avoid generating code for it. */
|
||||||
|
|
||||||
|
#define Throw \
|
||||||
|
for (;; longjmp(*the_exception_context->penv, 1)) \
|
||||||
|
the_exception_context->v.etmp =
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CEXCEPT_H */
|
||||||
23
contrib/visupng/resource.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//{{NO_DEPENDENCIES}}
|
||||||
|
// Microsoft Developer Studio generated include file.
|
||||||
|
// Used by VisualPng.rc
|
||||||
|
//
|
||||||
|
#define IDM_FILE_OPEN 40001
|
||||||
|
#define IDM_FILE_SAVE 40002
|
||||||
|
#define IDM_FILE_NEXT 40003
|
||||||
|
#define IDM_FILE_PREVIOUS 40004
|
||||||
|
#define IDM_FILE_EXIT 40005
|
||||||
|
#define IDM_OPTIONS_BACKGROUND 40006
|
||||||
|
#define IDM_OPTIONS_STRETCH 40007
|
||||||
|
#define IDM_HELP_ABOUT 40008
|
||||||
|
|
||||||
|
// Next default values for new objects
|
||||||
|
//
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
#define _APS_NEXT_RESOURCE_VALUE 113
|
||||||
|
#define _APS_NEXT_COMMAND_VALUE 40009
|
||||||
|
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||||
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
630
depcomp
Executable file
@@ -0,0 +1,630 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# depcomp - compile a program generating dependencies as side-effects
|
||||||
|
|
||||||
|
scriptversion=2009-04-28.21; # UTC
|
||||||
|
|
||||||
|
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
|
||||||
|
# Software Foundation, Inc.
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# As a special exception to the GNU General Public License, if you
|
||||||
|
# distribute this file as part of a program that contains a
|
||||||
|
# configuration script generated by Autoconf, you may include it under
|
||||||
|
# the same distribution terms that you use for the rest of that program.
|
||||||
|
|
||||||
|
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
'')
|
||||||
|
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
|
||||||
|
exit 1;
|
||||||
|
;;
|
||||||
|
-h | --h*)
|
||||||
|
cat <<\EOF
|
||||||
|
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
|
||||||
|
|
||||||
|
Run PROGRAMS ARGS to compile a file, generating dependencies
|
||||||
|
as side-effects.
|
||||||
|
|
||||||
|
Environment variables:
|
||||||
|
depmode Dependency tracking mode.
|
||||||
|
source Source file read by `PROGRAMS ARGS'.
|
||||||
|
object Object file output by `PROGRAMS ARGS'.
|
||||||
|
DEPDIR directory where to store dependencies.
|
||||||
|
depfile Dependency file to output.
|
||||||
|
tmpdepfile Temporary file to use when outputing dependencies.
|
||||||
|
libtool Whether libtool is used (yes/no).
|
||||||
|
|
||||||
|
Report bugs to <bug-automake@gnu.org>.
|
||||||
|
EOF
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
-v | --v*)
|
||||||
|
echo "depcomp $scriptversion"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
|
||||||
|
echo "depcomp: Variables source, object and depmode must be set" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
|
||||||
|
depfile=${depfile-`echo "$object" |
|
||||||
|
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
|
||||||
|
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
|
||||||
|
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
|
||||||
|
# Some modes work just like other modes, but use different flags. We
|
||||||
|
# parameterize here, but still list the modes in the big case below,
|
||||||
|
# to make depend.m4 easier to write. Note that we *cannot* use a case
|
||||||
|
# here, because this file can only contain one case statement.
|
||||||
|
if test "$depmode" = hp; then
|
||||||
|
# HP compiler uses -M and no extra arg.
|
||||||
|
gccflag=-M
|
||||||
|
depmode=gcc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$depmode" = dashXmstdout; then
|
||||||
|
# This is just like dashmstdout with a different argument.
|
||||||
|
dashmflag=-xM
|
||||||
|
depmode=dashmstdout
|
||||||
|
fi
|
||||||
|
|
||||||
|
cygpath_u="cygpath -u -f -"
|
||||||
|
if test "$depmode" = msvcmsys; then
|
||||||
|
# This is just like msvisualcpp but w/o cygpath translation.
|
||||||
|
# Just convert the backslash-escaped backslashes to single forward
|
||||||
|
# slashes to satisfy depend.m4
|
||||||
|
cygpath_u="sed s,\\\\\\\\,/,g"
|
||||||
|
depmode=msvisualcpp
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$depmode" in
|
||||||
|
gcc3)
|
||||||
|
## gcc 3 implements dependency tracking that does exactly what
|
||||||
|
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
|
||||||
|
## it if -MD -MP comes after the -MF stuff. Hmm.
|
||||||
|
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
|
||||||
|
## the command line argument order; so add the flags where they
|
||||||
|
## appear in depend2.am. Note that the slowdown incurred here
|
||||||
|
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
|
||||||
|
*) set fnord "$@" "$arg" ;;
|
||||||
|
esac
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
done
|
||||||
|
"$@"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
mv "$tmpdepfile" "$depfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
gcc)
|
||||||
|
## There are various ways to get dependency output from gcc. Here's
|
||||||
|
## why we pick this rather obscure method:
|
||||||
|
## - Don't want to use -MD because we'd like the dependencies to end
|
||||||
|
## up in a subdir. Having to rename by hand is ugly.
|
||||||
|
## (We might end up doing this anyway to support other compilers.)
|
||||||
|
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
|
||||||
|
## -MM, not -M (despite what the docs say).
|
||||||
|
## - Using -M directly means running the compiler twice (even worse
|
||||||
|
## than renaming).
|
||||||
|
if test -z "$gccflag"; then
|
||||||
|
gccflag=-MD,
|
||||||
|
fi
|
||||||
|
"$@" -Wp,"$gccflag$tmpdepfile"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||||
|
## The second -e expression handles DOS-style file names with drive letters.
|
||||||
|
sed -e 's/^[^:]*: / /' \
|
||||||
|
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
|
||||||
|
## This next piece of magic avoids the `deleted header file' problem.
|
||||||
|
## The problem is that when a header file which appears in a .P file
|
||||||
|
## is deleted, the dependency causes make to die (because there is
|
||||||
|
## typically no way to rebuild the header). We avoid this by adding
|
||||||
|
## dummy dependencies for each header file. Too bad gcc doesn't do
|
||||||
|
## this for us directly.
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" |
|
||||||
|
## Some versions of gcc put a space before the `:'. On the theory
|
||||||
|
## that the space means something, we add a space to the output as
|
||||||
|
## well.
|
||||||
|
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
## correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
hp)
|
||||||
|
# This case exists only to let depend.m4 do its work. It works by
|
||||||
|
# looking at the text of this script. This case will never be run,
|
||||||
|
# since it is checked for above.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
sgi)
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
"$@" "-Wp,-MDupdate,$tmpdepfile"
|
||||||
|
else
|
||||||
|
"$@" -MDupdate "$tmpdepfile"
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
|
||||||
|
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
|
||||||
|
# Clip off the initial element (the dependent). Don't try to be
|
||||||
|
# clever and replace this with sed code, as IRIX sed won't handle
|
||||||
|
# lines with more than a fixed number of characters (4096 in
|
||||||
|
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
|
||||||
|
# the IRIX cc adds comments like `#:fec' to the end of the
|
||||||
|
# dependency line.
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
|
||||||
|
tr '
|
||||||
|
' ' ' >> "$depfile"
|
||||||
|
echo >> "$depfile"
|
||||||
|
|
||||||
|
# The second pass generates a dummy entry for each header file.
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
|
||||||
|
>> "$depfile"
|
||||||
|
else
|
||||||
|
# The sourcefile does not contain any dependencies, so just
|
||||||
|
# store a dummy comment line, to avoid errors with the Makefile
|
||||||
|
# "include basename.Plo" scheme.
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
aix)
|
||||||
|
# The C for AIX Compiler uses -M and outputs the dependencies
|
||||||
|
# in a .u file. In older versions, this file always lives in the
|
||||||
|
# current directory. Also, the AIX compiler puts `$object:' at the
|
||||||
|
# start of each line; $object doesn't have directory information.
|
||||||
|
# Version 6 uses the directory in both cases.
|
||||||
|
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||||
|
test "x$dir" = "x$object" && dir=
|
||||||
|
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
tmpdepfile1=$dir$base.u
|
||||||
|
tmpdepfile2=$base.u
|
||||||
|
tmpdepfile3=$dir.libs/$base.u
|
||||||
|
"$@" -Wc,-M
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.u
|
||||||
|
tmpdepfile2=$dir$base.u
|
||||||
|
tmpdepfile3=$dir$base.u
|
||||||
|
"$@" -M
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
# Each line is of the form `foo.o: dependent.h'.
|
||||||
|
# Do two passes, one to just change these to
|
||||||
|
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||||
|
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
|
||||||
|
# That's a tab and a space in the [].
|
||||||
|
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
|
||||||
|
else
|
||||||
|
# The sourcefile does not contain any dependencies, so just
|
||||||
|
# store a dummy comment line, to avoid errors with the Makefile
|
||||||
|
# "include basename.Plo" scheme.
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
icc)
|
||||||
|
# Intel's C compiler understands `-MD -MF file'. However on
|
||||||
|
# icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
|
||||||
|
# ICC 7.0 will fill foo.d with something like
|
||||||
|
# foo.o: sub/foo.c
|
||||||
|
# foo.o: sub/foo.h
|
||||||
|
# which is wrong. We want:
|
||||||
|
# sub/foo.o: sub/foo.c
|
||||||
|
# sub/foo.o: sub/foo.h
|
||||||
|
# sub/foo.c:
|
||||||
|
# sub/foo.h:
|
||||||
|
# ICC 7.1 will output
|
||||||
|
# foo.o: sub/foo.c sub/foo.h
|
||||||
|
# and will wrap long lines using \ :
|
||||||
|
# foo.o: sub/foo.c ... \
|
||||||
|
# sub/foo.h ... \
|
||||||
|
# ...
|
||||||
|
|
||||||
|
"$@" -MD -MF "$tmpdepfile"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
# Each line is of the form `foo.o: dependent.h',
|
||||||
|
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
|
||||||
|
# Do two passes, one to just change these to
|
||||||
|
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||||
|
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
|
||||||
|
# Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
# correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
|
||||||
|
sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
hp2)
|
||||||
|
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
|
||||||
|
# compilers, which have integrated preprocessors. The correct option
|
||||||
|
# to use with these is +Maked; it writes dependencies to a file named
|
||||||
|
# 'foo.d', which lands next to the object file, wherever that
|
||||||
|
# happens to be.
|
||||||
|
# Much of this is similar to the tru64 case; see comments there.
|
||||||
|
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||||
|
test "x$dir" = "x$object" && dir=
|
||||||
|
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
tmpdepfile1=$dir$base.d
|
||||||
|
tmpdepfile2=$dir.libs/$base.d
|
||||||
|
"$@" -Wc,+Maked
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.d
|
||||||
|
tmpdepfile2=$dir$base.d
|
||||||
|
"$@" +Maked
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
|
||||||
|
# Add `dependent.h:' lines.
|
||||||
|
sed -ne '2,${
|
||||||
|
s/^ *//
|
||||||
|
s/ \\*$//
|
||||||
|
s/$/:/
|
||||||
|
p
|
||||||
|
}' "$tmpdepfile" >> "$depfile"
|
||||||
|
else
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile" "$tmpdepfile2"
|
||||||
|
;;
|
||||||
|
|
||||||
|
tru64)
|
||||||
|
# The Tru64 compiler uses -MD to generate dependencies as a side
|
||||||
|
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
|
||||||
|
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
|
||||||
|
# dependencies in `foo.d' instead, so we check for that too.
|
||||||
|
# Subdirectories are respected.
|
||||||
|
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||||
|
test "x$dir" = "x$object" && dir=
|
||||||
|
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||||
|
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
# With Tru64 cc, shared objects can also be used to make a
|
||||||
|
# static library. This mechanism is used in libtool 1.4 series to
|
||||||
|
# handle both shared and static libraries in a single compilation.
|
||||||
|
# With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
|
||||||
|
#
|
||||||
|
# With libtool 1.5 this exception was removed, and libtool now
|
||||||
|
# generates 2 separate objects for the 2 libraries. These two
|
||||||
|
# compilations output dependencies in $dir.libs/$base.o.d and
|
||||||
|
# in $dir$base.o.d. We have to check for both files, because
|
||||||
|
# one of the two compilations can be disabled. We should prefer
|
||||||
|
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
|
||||||
|
# automatically cleaned when .libs/ is deleted, while ignoring
|
||||||
|
# the former would cause a distcleancheck panic.
|
||||||
|
tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
|
||||||
|
tmpdepfile2=$dir$base.o.d # libtool 1.5
|
||||||
|
tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
|
||||||
|
tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
|
||||||
|
"$@" -Wc,-MD
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.o.d
|
||||||
|
tmpdepfile2=$dir$base.d
|
||||||
|
tmpdepfile3=$dir$base.d
|
||||||
|
tmpdepfile4=$dir$base.d
|
||||||
|
"$@" -MD
|
||||||
|
fi
|
||||||
|
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
|
||||||
|
# That's a tab and a space in the [].
|
||||||
|
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
|
||||||
|
else
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
#nosideeffect)
|
||||||
|
# This comment above is used by automake to tell side-effect
|
||||||
|
# dependency tracking mechanisms from slower ones.
|
||||||
|
|
||||||
|
dashmstdout)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout, regardless of -o.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove `-o $object'.
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
test -z "$dashmflag" && dashmflag=-M
|
||||||
|
# Require at least two characters before searching for `:'
|
||||||
|
# in the target name. This is to cope with DOS-style filenames:
|
||||||
|
# a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
|
||||||
|
"$@" $dashmflag |
|
||||||
|
sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
cat < "$tmpdepfile" > "$depfile"
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" | \
|
||||||
|
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
## correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
dashXmstdout)
|
||||||
|
# This case only exists to satisfy depend.m4. It is never actually
|
||||||
|
# run, as this mode is specially recognized in the preamble.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
makedepend)
|
||||||
|
"$@" || exit $?
|
||||||
|
# Remove any Libtool call
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
# X makedepend
|
||||||
|
shift
|
||||||
|
cleared=no eat=no
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $cleared in
|
||||||
|
no)
|
||||||
|
set ""; shift
|
||||||
|
cleared=yes ;;
|
||||||
|
esac
|
||||||
|
if test $eat = yes; then
|
||||||
|
eat=no
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
case "$arg" in
|
||||||
|
-D*|-I*)
|
||||||
|
set fnord "$@" "$arg"; shift ;;
|
||||||
|
# Strip any option that makedepend may not understand. Remove
|
||||||
|
# the object too, otherwise makedepend will parse it as a source file.
|
||||||
|
-arch)
|
||||||
|
eat=yes ;;
|
||||||
|
-*|$object)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"; shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
obj_suffix=`echo "$object" | sed 's/^.*\././'`
|
||||||
|
touch "$tmpdepfile"
|
||||||
|
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
|
||||||
|
rm -f "$depfile"
|
||||||
|
cat < "$tmpdepfile" > "$depfile"
|
||||||
|
sed '1,2d' "$tmpdepfile" | tr ' ' '
|
||||||
|
' | \
|
||||||
|
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
## correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile" "$tmpdepfile".bak
|
||||||
|
;;
|
||||||
|
|
||||||
|
cpp)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove `-o $object'.
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
"$@" -E |
|
||||||
|
sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||||
|
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
|
||||||
|
sed '$ s: \\$::' > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
cat < "$tmpdepfile" >> "$depfile"
|
||||||
|
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
msvisualcpp)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case "$arg" in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
|
||||||
|
set fnord "$@"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
"$@" -E 2>/dev/null |
|
||||||
|
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
|
||||||
|
echo " " >> "$depfile"
|
||||||
|
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
msvcmsys)
|
||||||
|
# This case exists only to let depend.m4 do its work. It works by
|
||||||
|
# looking at the text of this script. This case will never be run,
|
||||||
|
# since it is checked for above.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
none)
|
||||||
|
exec "$@"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unknown depmode $depmode" 1>&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: shell-script
|
||||||
|
# sh-indentation: 2
|
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-time-zone: "UTC"
|
||||||
|
# time-stamp-end: "; # UTC"
|
||||||
|
# End:
|
||||||
464
example.c
@@ -1,20 +1,39 @@
|
|||||||
|
|
||||||
/* example.c - an example of using libpng */
|
#if 0 /* in case someone actually tries to compile this */
|
||||||
|
|
||||||
|
/* example.c - an example of using libpng
|
||||||
|
* Last changed in libpng 1.2.37 [June 4, 2009]
|
||||||
|
* This file has been placed in the public domain by the authors.
|
||||||
|
* Maintained 1998-2009 Glenn Randers-Pehrson
|
||||||
|
* Maintained 1996, 1997 Andreas Dilger)
|
||||||
|
* Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||||
|
*/
|
||||||
|
|
||||||
/* This is an example of how to use libpng to read and write PNG files.
|
/* This is an example of how to use libpng to read and write PNG files.
|
||||||
* The file libpng.txt is much more verbose then this. If you have not
|
* The file libpng.txt is much more verbose then this. If you have not
|
||||||
* read it, do so first. This was designed to be a starting point of an
|
* read it, do so first. This was designed to be a starting point of an
|
||||||
* implementation. This is not officially part of libpng, and therefore
|
* implementation. This is not officially part of libpng, is hereby placed
|
||||||
* does not require a copyright notice.
|
* in the public domain, and therefore does not require a copyright notice.
|
||||||
*
|
*
|
||||||
* This file does not currently compile, because it is missing certain
|
* This file does not currently compile, because it is missing certain
|
||||||
* parts, like allocating memory to hold an image. You will have to
|
* parts, like allocating memory to hold an image. You will have to
|
||||||
* supply these parts to get it to compile. For an example of a minimal
|
* supply these parts to get it to compile. For an example of a minimal
|
||||||
* working PNG reader/writer, see pngtest.c, included in this distribution.
|
* working PNG reader/writer, see pngtest.c, included in this distribution;
|
||||||
|
* see also the programs in the contrib directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
|
||||||
|
/* The png_jmpbuf() macro, used in error handling, became available in
|
||||||
|
* libpng version 1.0.6. If you want to be able to run your code with older
|
||||||
|
* versions of libpng, you must define the macro yourself (but only if it
|
||||||
|
* is not already defined by libpng!).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef png_jmpbuf
|
||||||
|
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
|
/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
|
||||||
* returns zero if the image is a PNG and nonzero if it isn't a PNG.
|
* returns zero if the image is a PNG and nonzero if it isn't a PNG.
|
||||||
*
|
*
|
||||||
@@ -41,7 +60,7 @@ int check_if_png(char *file_name, FILE **fp)
|
|||||||
char buf[PNG_BYTES_TO_CHECK];
|
char buf[PNG_BYTES_TO_CHECK];
|
||||||
|
|
||||||
/* Open the prospective PNG file. */
|
/* Open the prospective PNG file. */
|
||||||
if ((*fp = fopen(file_name, "rb")) != NULL);
|
if ((*fp = fopen(file_name, "rb")) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Read in some of the signature bytes */
|
/* Read in some of the signature bytes */
|
||||||
@@ -71,15 +90,16 @@ void read_png(char *file_name) /* We need to open the file */
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if ((fp = fopen(file_name, "rb")) == NULL)
|
if ((fp = fopen(file_name, "rb")) == NULL)
|
||||||
return;
|
return (ERROR);
|
||||||
|
|
||||||
#else no_open_file /* prototype 2 */
|
#else no_open_file /* prototype 2 */
|
||||||
void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||||
{
|
{
|
||||||
png_structp png_ptr;
|
png_structp png_ptr;
|
||||||
png_infop info_ptr;
|
png_infop info_ptr;
|
||||||
png_uint_32 width, height;
|
png_uint_32 width, height;
|
||||||
int bit_depth, color_type, interlace_type;
|
int bit_depth, color_type, interlace_type;
|
||||||
#endif no_open_file /* only use one prototype! */
|
#endif no_open_file /* Only use one prototype! */
|
||||||
|
|
||||||
/* Create and initialize the png_struct with the desired error handler
|
/* Create and initialize the png_struct with the desired error handler
|
||||||
* functions. If you want to use the default stderr and longjump method,
|
* functions. If you want to use the default stderr and longjump method,
|
||||||
@@ -93,7 +113,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
if (png_ptr == NULL)
|
if (png_ptr == NULL)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate/initialize the memory for image information. REQUIRED. */
|
/* Allocate/initialize the memory for image information. REQUIRED. */
|
||||||
@@ -101,21 +121,22 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
if (info_ptr == NULL)
|
if (info_ptr == NULL)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
|
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
|
||||||
return;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set error handling if you are using the setjmp/longjmp method (this is
|
/* Set error handling if you are using the setjmp/longjmp method (this is
|
||||||
* the normal method of doing things with libpng). REQUIRED unless you
|
* the normal method of doing things with libpng). REQUIRED unless you
|
||||||
* set up your own error handlers in the png_create_read_struct() earlier.
|
* set up your own error handlers in the png_create_read_struct() earlier.
|
||||||
*/
|
*/
|
||||||
if (setjmp(png_ptr->jmpbuf))
|
|
||||||
|
if (setjmp(png_jmpbuf(png_ptr)))
|
||||||
{
|
{
|
||||||
/* Free all of the memory associated with the png_ptr and info_ptr */
|
/* Free all of the memory associated with the png_ptr and info_ptr */
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
/* If we get here, we had a problem reading the file */
|
/* If we get here, we had a problem reading the file */
|
||||||
return;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* One of the following I/O initialization methods is REQUIRED */
|
/* One of the following I/O initialization methods is REQUIRED */
|
||||||
@@ -134,21 +155,35 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
/* If we have already read some of the signature */
|
/* If we have already read some of the signature */
|
||||||
png_set_sig_bytes(png_ptr, sig_read);
|
png_set_sig_bytes(png_ptr, sig_read);
|
||||||
|
|
||||||
|
#ifdef hilevel
|
||||||
|
/*
|
||||||
|
* If you have enough memory to read in the entire image at once,
|
||||||
|
* and you need to specify only transforms that can be controlled
|
||||||
|
* with one of the PNG_TRANSFORM_* bits (this presently excludes
|
||||||
|
* dithering, filling, setting background, and doing gamma
|
||||||
|
* adjustment), then you can read the entire image (including
|
||||||
|
* pixels) into the info structure with this call:
|
||||||
|
*/
|
||||||
|
png_read_png(png_ptr, info_ptr, png_transforms, png_voidp_NULL);
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* OK, you're doing it the hard way, with the lower-level functions */
|
||||||
|
|
||||||
/* The call to png_read_info() gives us all of the information from the
|
/* The call to png_read_info() gives us all of the information from the
|
||||||
* PNG file before the first IDAT (image data chunk). REQUIRED
|
* PNG file before the first IDAT (image data chunk). REQUIRED
|
||||||
*/
|
*/
|
||||||
png_read_info(png_ptr, info_ptr);
|
png_read_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||||
&interlace_type, NULL, NULL);
|
&interlace_type, int_p_NULL, int_p_NULL);
|
||||||
|
|
||||||
/**** Set up the data transformations you want. Note that these are all
|
/* Set up the data transformations you want. Note that these are all
|
||||||
**** optional. Only call them if you want/need them. Many of the
|
* optional. Only call them if you want/need them. Many of the
|
||||||
**** transformations only work on specific types of images, and many
|
* transformations only work on specific types of images, and many
|
||||||
**** are mutually exclusive.
|
* are mutually exclusive.
|
||||||
****/
|
*/
|
||||||
|
|
||||||
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
|
/* Tell libpng to strip 16 bit/color files down to 8 bits/color */
|
||||||
png_set_strip_16(png_ptr);
|
png_set_strip_16(png_ptr);
|
||||||
|
|
||||||
/* Strip alpha bytes from the input data without combining with the
|
/* Strip alpha bytes from the input data without combining with the
|
||||||
@@ -167,17 +202,17 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
|
|
||||||
/* Expand paletted colors into true RGB triplets */
|
/* Expand paletted colors into true RGB triplets */
|
||||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
png_set_expand(png_ptr);
|
png_set_palette_to_rgb(png_ptr);
|
||||||
|
|
||||||
/* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
|
/* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
|
||||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||||
png_set_expand(png_ptr);
|
png_set_expand_gray_1_2_4_to_8(png_ptr);
|
||||||
|
|
||||||
/* Expand paletted or RGB images with transparency to full alpha channels
|
/* Expand paletted or RGB images with transparency to full alpha channels
|
||||||
* so the data will be available as RGBA quartets.
|
* so the data will be available as RGBA quartets.
|
||||||
*/
|
*/
|
||||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||||
png_set_expand(png_ptr);
|
png_set_tRNS_to_alpha(png_ptr);
|
||||||
|
|
||||||
/* Set the background color to draw transparent and alpha images over.
|
/* Set the background color to draw transparent and alpha images over.
|
||||||
* It is possible to set the red, green, and blue components directly
|
* It is possible to set the red, green, and blue components directly
|
||||||
@@ -195,10 +230,11 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
png_set_background(png_ptr, &my_background,
|
png_set_background(png_ptr, &my_background,
|
||||||
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
||||||
|
|
||||||
/* Some suggestions as to how to get a screen gamma value */
|
/* Some suggestions as to how to get a screen gamma value
|
||||||
|
*
|
||||||
/* Note that screen gamma is the display_exponent, which includes
|
* Note that screen gamma is the display_exponent, which includes
|
||||||
* the CRT_exponent and any correction for viewing conditions */
|
* the CRT_exponent and any correction for viewing conditions
|
||||||
|
*/
|
||||||
if (/* We have a user-defined screen gamma value */)
|
if (/* We have a user-defined screen gamma value */)
|
||||||
{
|
{
|
||||||
screen_gamma = user-defined screen_gamma;
|
screen_gamma = user-defined screen_gamma;
|
||||||
@@ -211,12 +247,12 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
/* If we don't have another value */
|
/* If we don't have another value */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
screen_gamma = 2.2; /* A good guess for a PC monitors in a dimly
|
screen_gamma = 2.2; /* A good guess for a PC monitor in a dimly
|
||||||
lit room */
|
lit room */
|
||||||
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tell libpng to handle the gamma conversion for you. The second call
|
/* Tell libpng to handle the gamma conversion for you. The final call
|
||||||
* is a good guess for PC generated images, but it should be configurable
|
* is a good guess for PC generated images, but it should be configurable
|
||||||
* by the user at run time by the user. It is strongly suggested that
|
* by the user at run time by the user. It is strongly suggested that
|
||||||
* your application support gamma correction.
|
* your application support gamma correction.
|
||||||
@@ -225,7 +261,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
int intent;
|
int intent;
|
||||||
|
|
||||||
if (png_get_sRGB(png_ptr, info_ptr, &intent))
|
if (png_get_sRGB(png_ptr, info_ptr, &intent))
|
||||||
png_set_sRGB(png_ptr, intent, 0);
|
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double image_gamma;
|
double image_gamma;
|
||||||
@@ -240,22 +276,22 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
*/
|
*/
|
||||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||||
{
|
{
|
||||||
png_uint_32 num_palette;
|
int num_palette;
|
||||||
png_colorp palette;
|
png_colorp palette;
|
||||||
|
|
||||||
/* This reduces the image to the application supplied palette */
|
/* This reduces the image to the application supplied palette */
|
||||||
if (/* we have our own palette */)
|
if (/* We have our own palette */)
|
||||||
{
|
{
|
||||||
/* An array of colors to which the image should be dithered */
|
/* An array of colors to which the image should be dithered */
|
||||||
png_color std_color_cube[MAX_SCREEN_COLORS];
|
png_color std_color_cube[MAX_SCREEN_COLORS];
|
||||||
|
|
||||||
png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
|
png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
|
||||||
MAX_SCREEN_COLORS, NULL, 0);
|
MAX_SCREEN_COLORS, png_uint_16p_NULL, 0);
|
||||||
}
|
}
|
||||||
/* This reduces the image to the palette supplied in the file */
|
/* This reduces the image to the palette supplied in the file */
|
||||||
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
|
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
|
||||||
{
|
{
|
||||||
png_color16p histogram;
|
png_uint_16p histogram = NULL;
|
||||||
|
|
||||||
png_get_hIST(png_ptr, info_ptr, &histogram);
|
png_get_hIST(png_ptr, info_ptr, &histogram);
|
||||||
|
|
||||||
@@ -264,7 +300,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* invert monocrome files to have 0 as white and 1 as black */
|
/* Invert monochrome files to have 0 as white and 1 as black */
|
||||||
png_set_invert_mono(png_ptr);
|
png_set_invert_mono(png_ptr);
|
||||||
|
|
||||||
/* If you want to shift the pixel values from the range [0,255] or
|
/* If you want to shift the pixel values from the range [0,255] or
|
||||||
@@ -273,19 +309,20 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
*/
|
*/
|
||||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
||||||
{
|
{
|
||||||
png_color8p sig_bit;
|
png_color_8p sig_bit_p;
|
||||||
|
|
||||||
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
png_get_sBIT(png_ptr, info_ptr, &sig_bit_p);
|
||||||
png_set_shift(png_ptr, sig_bit);
|
png_set_shift(png_ptr, sig_bit_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
|
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
|
||||||
png_set_bgr(png_ptr);
|
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||||
|
png_set_bgr(png_ptr);
|
||||||
|
|
||||||
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
||||||
png_set_swap_alpha(png_ptr);
|
png_set_swap_alpha(png_ptr);
|
||||||
|
|
||||||
/* swap bytes of 16 bit files to least significant byte first */
|
/* Swap bytes of 16 bit files to least significant byte first */
|
||||||
png_set_swap(png_ptr);
|
png_set_swap(png_ptr);
|
||||||
|
|
||||||
/* Add filler (or alpha) byte (before/after each RGB triplet) */
|
/* Add filler (or alpha) byte (before/after each RGB triplet) */
|
||||||
@@ -308,10 +345,13 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
/* The easiest way to read the image: */
|
/* The easiest way to read the image: */
|
||||||
png_bytep row_pointers[height];
|
png_bytep row_pointers[height];
|
||||||
|
|
||||||
|
/* Clear the pointer array */
|
||||||
for (row = 0; row < height; row++)
|
for (row = 0; row < height; row++)
|
||||||
{
|
row_pointers[row] = NULL;
|
||||||
row_pointers[row] = malloc(png_get_rowbytes(png_ptr, info_ptr));
|
|
||||||
}
|
for (row = 0; row < height; row++)
|
||||||
|
row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr,
|
||||||
|
info_ptr));
|
||||||
|
|
||||||
/* Now it's time to read the image. One of these methods is REQUIRED */
|
/* Now it's time to read the image. One of these methods is REQUIRED */
|
||||||
#ifdef entire /* Read the entire image in one go */
|
#ifdef entire /* Read the entire image in one go */
|
||||||
@@ -325,41 +365,43 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
|||||||
#ifdef single /* Read the image a single row at a time */
|
#ifdef single /* Read the image a single row at a time */
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
png_read_rows(png_ptr, &row_pointers[y], NULL, 1);
|
png_read_rows(png_ptr, &row_pointers[y], png_bytepp_NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else no_single /* Read the image several rows at a time */
|
#else no_single /* Read the image several rows at a time */
|
||||||
for (y = 0; y < height; y += number_of_rows)
|
for (y = 0; y < height; y += number_of_rows)
|
||||||
{
|
{
|
||||||
#ifdef sparkle /* Read the image using the "sparkle" effect. */
|
#ifdef sparkle /* Read the image using the "sparkle" effect. */
|
||||||
png_read_rows(png_ptr, &row_pointers[y], NULL, number_of_rows);
|
png_read_rows(png_ptr, &row_pointers[y], png_bytepp_NULL,
|
||||||
|
number_of_rows);
|
||||||
png_read_rows(png_ptr, NULL, row_pointers[y], number_of_rows);
|
|
||||||
#else no_sparkle /* Read the image using the "rectangle" effect */
|
#else no_sparkle /* Read the image using the "rectangle" effect */
|
||||||
png_read_rows(png_ptr, NULL, &row_pointers[y], number_of_rows);
|
png_read_rows(png_ptr, png_bytepp_NULL, &row_pointers[y],
|
||||||
#endif no_sparkle /* use only one of these two methods */
|
number_of_rows);
|
||||||
|
#endif no_sparkle /* Use only one of these two methods */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if you want to display the image after every pass, do
|
/* If you want to display the image after every pass, do so here */
|
||||||
so here */
|
#endif no_single /* Use only one of these two methods */
|
||||||
#endif no_single /* use only one of these two methods */
|
|
||||||
}
|
}
|
||||||
#endif no_entire /* use only one of these two methods */
|
#endif no_entire /* Use only one of these two methods */
|
||||||
|
|
||||||
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
/* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||||
png_read_end(png_ptr, info_ptr);
|
png_read_end(png_ptr, info_ptr);
|
||||||
|
#endif hilevel
|
||||||
|
|
||||||
/* clean up after the read, and free any memory allocated - REQUIRED */
|
/* At this point you have read the entire image */
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
|
||||||
|
|
||||||
/* close the file */
|
/* Clean up after the read, and free any memory allocated - REQUIRED */
|
||||||
|
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
|
||||||
|
|
||||||
|
/* Close the file */
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/* that's it */
|
/* That's it */
|
||||||
return;
|
return (OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* progressively read a file */
|
/* Progressively read a file */
|
||||||
|
|
||||||
int
|
int
|
||||||
initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||||
@@ -376,21 +418,21 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
|||||||
if (*png_ptr == NULL)
|
if (*png_ptr == NULL)
|
||||||
{
|
{
|
||||||
*info_ptr = NULL;
|
*info_ptr = NULL;
|
||||||
return ERROR;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
*info_ptr = png_create_info_struct(png_ptr);
|
*info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
|
||||||
if (*info_ptr == NULL)
|
if (*info_ptr == NULL)
|
||||||
{
|
{
|
||||||
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
|
png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL);
|
||||||
return ERROR;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setjmp((*png_ptr)->jmpbuf))
|
if (setjmp(png_jmpbuf((*png_ptr))))
|
||||||
{
|
{
|
||||||
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
|
png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL);
|
||||||
return ERROR;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This one's new. You will need to provide all three
|
/* This one's new. You will need to provide all three
|
||||||
@@ -408,23 +450,23 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
|||||||
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
|
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
|
||||||
info_callback, row_callback, end_callback);
|
info_callback, row_callback, end_callback);
|
||||||
|
|
||||||
return OK;
|
return (OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
process_data(png_structp *png_ptr, png_infop *info_ptr,
|
process_data(png_structp *png_ptr, png_infop *info_ptr,
|
||||||
png_bytep buffer, png_uint_32 length)
|
png_bytep buffer, png_uint_32 length)
|
||||||
{
|
{
|
||||||
if (setjmp((*png_ptr)->jmpbuf))
|
if (setjmp(png_jmpbuf((*png_ptr))))
|
||||||
{
|
{
|
||||||
/* Free the png_ptr and info_ptr memory on error */
|
/* Free the png_ptr and info_ptr memory on error */
|
||||||
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
|
png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL);
|
||||||
return ERROR;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This one's new also. Simply give it chunks of data as
|
/* This one's new also. Simply give it chunks of data as
|
||||||
* they arrive from the data stream (in order, of course).
|
* they arrive from the data stream (in order, of course).
|
||||||
* On Segmented machines, don't give it any more than 64K.
|
* On segmented machines, don't give it any more than 64K.
|
||||||
* The library seems to run fine with sizes of 4K, although
|
* The library seems to run fine with sizes of 4K, although
|
||||||
* you can give it much less if necessary (I assume you can
|
* you can give it much less if necessary (I assume you can
|
||||||
* give it chunks of 1 byte, but I haven't tried with less
|
* give it chunks of 1 byte, but I haven't tried with less
|
||||||
@@ -433,75 +475,103 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
|
|||||||
* callback, if you aren't already displaying them there.
|
* callback, if you aren't already displaying them there.
|
||||||
*/
|
*/
|
||||||
png_process_data(*png_ptr, *info_ptr, buffer, length);
|
png_process_data(*png_ptr, *info_ptr, buffer, length);
|
||||||
return OK;
|
return (OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
info_callback(png_structp png_ptr, png_infop info)
|
info_callback(png_structp png_ptr, png_infop info)
|
||||||
{
|
{
|
||||||
/* do any setup here, including setting any of the transformations
|
/* Do any setup here, including setting any of the transformations
|
||||||
* mentioned in the Reading PNG files section. For now, you _must_
|
* mentioned in the Reading PNG files section. For now, you _must_
|
||||||
* call either png_start_read_image() or png_read_update_info()
|
* call either png_start_read_image() or png_read_update_info()
|
||||||
* after all the transformations are set (even if you don't set
|
* after all the transformations are set (even if you don't set
|
||||||
* any). You may start getting rows before png_process_data()
|
* any). You may start getting rows before png_process_data()
|
||||||
* returns, so this is your last chance to prepare for that.
|
* returns, so this is your last chance to prepare for that.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
row_callback(png_structp png_ptr, png_bytep new_row,
|
row_callback(png_structp png_ptr, png_bytep new_row,
|
||||||
png_uint_32 row_num, int pass)
|
png_uint_32 row_num, int pass)
|
||||||
{
|
{
|
||||||
/* this function is called for every row in the image. If the
|
/*
|
||||||
* image is interlacing, and you turned on the interlace handler,
|
* This function is called for every row in the image. If the
|
||||||
* this function will be called for every row in every pass.
|
* image is interlaced, and you turned on the interlace handler,
|
||||||
* Some of these rows will not be changed from the previous pass.
|
* this function will be called for every row in every pass.
|
||||||
* When the row is not changed, the new_row variable will be NULL.
|
*
|
||||||
* The rows and passes are called in order, so you don't really
|
* In this function you will receive a pointer to new row data from
|
||||||
* need the row_num and pass, but I'm supplying them because it
|
* libpng called new_row that is to replace a corresponding row (of
|
||||||
* may make your life easier.
|
* the same data format) in a buffer allocated by your application.
|
||||||
*
|
*
|
||||||
* For the non-NULL rows of interlaced images, you must call
|
* The new row data pointer "new_row" may be NULL, indicating there is
|
||||||
* png_progressive_combine_row() passing in the row and the
|
* no new data to be replaced (in cases of interlace loading).
|
||||||
* old row. You can call this function for NULL rows (it will
|
*
|
||||||
* just return) and for non-interlaced images (it just does the
|
* If new_row is not NULL then you need to call
|
||||||
* memcpy for you) if it will make the code easier. Thus, you
|
* png_progressive_combine_row() to replace the corresponding row as
|
||||||
* can just do this for all cases:
|
* shown below:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Check if row_num is in bounds. */
|
||||||
|
if ((row_num >= 0) && (row_num < height))
|
||||||
|
{
|
||||||
|
/* Get pointer to corresponding row in our
|
||||||
|
* PNG read buffer.
|
||||||
|
*/
|
||||||
|
png_bytep old_row = ((png_bytep *)our_data)[row_num];
|
||||||
|
|
||||||
|
/* If both rows are allocated then copy the new row
|
||||||
|
* data to the corresponding row data.
|
||||||
|
*/
|
||||||
|
if ((old_row != NULL) && (new_row != NULL))
|
||||||
|
png_progressive_combine_row(png_ptr, old_row, new_row);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* The rows and passes are called in order, so you don't really
|
||||||
|
* need the row_num and pass, but I'm supplying them because it
|
||||||
|
* may make your life easier.
|
||||||
|
*
|
||||||
|
* For the non-NULL rows of interlaced images, you must call
|
||||||
|
* png_progressive_combine_row() passing in the new row and the
|
||||||
|
* old row, as demonstrated above. You can call this function for
|
||||||
|
* NULL rows (it will just return) and for non-interlaced images
|
||||||
|
* (it just does the png_memcpy for you) if it will make the code
|
||||||
|
* easier. Thus, you can just do this for all cases:
|
||||||
|
*/
|
||||||
|
|
||||||
png_progressive_combine_row(png_ptr, old_row, new_row);
|
png_progressive_combine_row(png_ptr, old_row, new_row);
|
||||||
|
|
||||||
/* where old_row is what was displayed for previous rows. Note
|
/* where old_row is what was displayed for previous rows. Note
|
||||||
* that the first pass (pass == 0 really) will completely cover
|
* that the first pass (pass == 0 really) will completely cover
|
||||||
* the old row, so the rows do not have to be initialized. After
|
* the old row, so the rows do not have to be initialized. After
|
||||||
* the first pass (and only for interlaced images), you will have
|
* the first pass (and only for interlaced images), you will have
|
||||||
* to pass the current row, and the function will combine the
|
* to pass the current row as new_row, and the function will combine
|
||||||
* old row and the new row.
|
* the old row and the new row.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
end_callback(png_structp png_ptr, png_infop info)
|
end_callback(png_structp png_ptr, png_infop info)
|
||||||
{
|
{
|
||||||
/* this function is called when the whole image has been read,
|
/* This function is called when the whole image has been read,
|
||||||
* including any chunks after the image (up to and including
|
* including any chunks after the image (up to and including
|
||||||
* the IEND). You will usually have the same info chunk as you
|
* the IEND). You will usually have the same info chunk as you
|
||||||
* had in the header, although some data may have been added
|
* had in the header, although some data may have been added
|
||||||
* to the comments and time fields.
|
* to the comments and time fields.
|
||||||
*
|
*
|
||||||
* Most people won't do much here, perhaps setting a flag that
|
* Most people won't do much here, perhaps setting a flag that
|
||||||
* marks the image as finished.
|
* marks the image as finished.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write a png file */
|
/* Write a png file */
|
||||||
void write_png(char *file_name /* , ... other image information ... */)
|
void write_png(char *file_name /* , ... other image information ... */)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
png_structp png_ptr;
|
png_structp png_ptr;
|
||||||
png_infop info_ptr;
|
png_infop info_ptr;
|
||||||
|
png_colorp palette;
|
||||||
|
|
||||||
/* open the file */
|
/* Open the file */
|
||||||
fp = fopen(file_name, "wb");
|
fp = fopen(file_name, "wb");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return;
|
return (ERROR);
|
||||||
|
|
||||||
/* Create and initialize the png_struct with the desired error handler
|
/* Create and initialize the png_struct with the desired error handler
|
||||||
* functions. If you want to use the default stderr and longjump method,
|
* functions. If you want to use the default stderr and longjump method,
|
||||||
@@ -515,7 +585,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
if (png_ptr == NULL)
|
if (png_ptr == NULL)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate/initialize the image information data. REQUIRED */
|
/* Allocate/initialize the image information data. REQUIRED */
|
||||||
@@ -523,32 +593,45 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
if (info_ptr == NULL)
|
if (info_ptr == NULL)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
png_destroy_write_struct(&png_ptr, png_infopp_NULL);
|
||||||
return;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set error handling. REQUIRED if you aren't supplying your own
|
/* Set error handling. REQUIRED if you aren't supplying your own
|
||||||
* error hadnling functions in the png_create_write_struct() call.
|
* error handling functions in the png_create_write_struct() call.
|
||||||
*/
|
*/
|
||||||
if (setjmp(png_ptr->jmpbuf))
|
if (setjmp(png_jmpbuf(png_ptr)))
|
||||||
{
|
{
|
||||||
/* If we get here, we had a problem reading the file */
|
/* If we get here, we had a problem writing the file */
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
return;
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* One of the following I/O initialization functions is REQUIRED */
|
/* One of the following I/O initialization functions is REQUIRED */
|
||||||
|
|
||||||
#ifdef streams /* I/O initialization method 1 */
|
#ifdef streams /* I/O initialization method 1 */
|
||||||
/* set up the output control if you are using standard C streams */
|
/* Set up the output control if you are using standard C streams */
|
||||||
png_init_io(png_ptr, fp);
|
png_init_io(png_ptr, fp);
|
||||||
|
|
||||||
#else no_streams /* I/O initialization method 2 */
|
#else no_streams /* I/O initialization method 2 */
|
||||||
/* If you are using replacement read functions, instead of calling
|
/* If you are using replacement write functions, instead of calling
|
||||||
* png_init_io() here you would call */
|
* png_init_io() here you would call
|
||||||
|
*/
|
||||||
png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
|
png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
|
||||||
user_IO_flush_function);
|
user_IO_flush_function);
|
||||||
/* where user_io_ptr is a structure you want available to the callbacks */
|
/* where user_io_ptr is a structure you want available to the callbacks */
|
||||||
#endif no_streams /* only use one initialization method */
|
#endif no_streams /* Only use one initialization method */
|
||||||
|
|
||||||
|
#ifdef hilevel
|
||||||
|
/* This is the easy way. Use it if you already have all the
|
||||||
|
* image info living in the structure. You could "|" many
|
||||||
|
* PNG_TRANSFORM flags into the png_transforms integer here.
|
||||||
|
*/
|
||||||
|
png_write_png(png_ptr, info_ptr, png_transforms, png_voidp_NULL);
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* This is the hard way */
|
||||||
|
|
||||||
/* Set the image information here. Width and height are up to 2^31,
|
/* Set the image information here. Width and height are up to 2^31,
|
||||||
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
|
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
|
||||||
@@ -561,21 +644,27 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,
|
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,
|
||||||
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||||
|
|
||||||
/* set the palette if there is one. REQUIRED for indexed-color images */
|
/* Set the palette if there is one. REQUIRED for indexed-color images */
|
||||||
palette = (png_colorp)png_malloc(png_ptr, 256 * sizeof (png_color));
|
palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH
|
||||||
/* ... set palette colors ... */
|
* png_sizeof(png_color));
|
||||||
png_set_PLTE(png_ptr, info_ptr, palette, 256);
|
/* ... Set palette colors ... */
|
||||||
|
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
|
||||||
|
/* You must not free palette here, because png_set_PLTE only makes a link to
|
||||||
|
* the palette that you malloced. Wait until you are about to destroy
|
||||||
|
* the png structure.
|
||||||
|
*/
|
||||||
|
|
||||||
/* optional significant bit chunk */
|
/* Optional significant bit (sBIT) chunk */
|
||||||
/* if we are dealing with a grayscale image then */
|
png_color_8 sig_bit;
|
||||||
|
/* If we are dealing with a grayscale image then */
|
||||||
sig_bit.gray = true_bit_depth;
|
sig_bit.gray = true_bit_depth;
|
||||||
/* otherwise, if we are dealing with a color image then */
|
/* Otherwise, if we are dealing with a color image then */
|
||||||
sig_bit.red = true_red_bit_depth;
|
sig_bit.red = true_red_bit_depth;
|
||||||
sig_bit.green = true_green_bit_depth;
|
sig_bit.green = true_green_bit_depth;
|
||||||
sig_bit.blue = true_blue_bit_depth;
|
sig_bit.blue = true_blue_bit_depth;
|
||||||
/* if the image has an alpha channel then */
|
/* If the image has an alpha channel then */
|
||||||
sig_bit.alpha = true_alpha_bit_depth;
|
sig_bit.alpha = true_alpha_bit_depth;
|
||||||
png_set_sBIT(png_ptr, info_ptr, sig_bit);
|
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||||
|
|
||||||
|
|
||||||
/* Optional gamma chunk is strongly suggested if you have any guess
|
/* Optional gamma chunk is strongly suggested if you have any guess
|
||||||
@@ -593,26 +682,45 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
text_ptr[2].key = "Description";
|
text_ptr[2].key = "Description";
|
||||||
text_ptr[2].text = "<long text>";
|
text_ptr[2].text = "<long text>";
|
||||||
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
|
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
|
||||||
|
#ifdef PNG_iTXt_SUPPORTED
|
||||||
|
text_ptr[0].lang = NULL;
|
||||||
|
text_ptr[1].lang = NULL;
|
||||||
|
text_ptr[2].lang = NULL;
|
||||||
|
#endif
|
||||||
png_set_text(png_ptr, info_ptr, text_ptr, 3);
|
png_set_text(png_ptr, info_ptr, text_ptr, 3);
|
||||||
|
|
||||||
/* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
|
/* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */
|
||||||
/* note that if sRGB is present the cHRM chunk must be ignored
|
|
||||||
* on read and must be written in accordance with the sRGB profile */
|
/* Note that if sRGB is present the gAMA and cHRM chunks must be ignored
|
||||||
|
* on read and, if your application chooses to write them, they must
|
||||||
|
* be written in accordance with the sRGB profile
|
||||||
|
*/
|
||||||
|
|
||||||
/* Write the file header information. REQUIRED */
|
/* Write the file header information. REQUIRED */
|
||||||
png_write_info(png_ptr, info_ptr);
|
png_write_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
/* If you want, you can write the info in two steps, in case you need to
|
||||||
|
* write your private chunk ahead of PLTE:
|
||||||
|
*
|
||||||
|
* png_write_info_before_PLTE(write_ptr, write_info_ptr);
|
||||||
|
* write_my_chunk();
|
||||||
|
* png_write_info(png_ptr, info_ptr);
|
||||||
|
*
|
||||||
|
* However, given the level of known- and unknown-chunk support in 1.2.0
|
||||||
|
* and up, this should no longer be necessary.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Once we write out the header, the compression type on the text
|
/* Once we write out the header, the compression type on the text
|
||||||
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||||
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
|
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
|
||||||
* at the end.
|
* at the end.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* set up the transformations you want. Note that these are
|
/* Set up the transformations you want. Note that these are
|
||||||
* all optional. Only call them if you want them.
|
* all optional. Only call them if you want them.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* invert monocrome pixels */
|
/* Invert monochrome pixels */
|
||||||
png_set_invert_mono(png_ptr);
|
png_set_invert_mono(png_ptr);
|
||||||
|
|
||||||
/* Shift the pixels up to a legal bit depth and fill in
|
/* Shift the pixels up to a legal bit depth and fill in
|
||||||
@@ -620,10 +728,10 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
*/
|
*/
|
||||||
png_set_shift(png_ptr, &sig_bit);
|
png_set_shift(png_ptr, &sig_bit);
|
||||||
|
|
||||||
/* pack pixels into bytes */
|
/* Pack pixels into bytes */
|
||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
|
||||||
/* swap location of alpha bytes from ARGB to RGBA */
|
/* Swap location of alpha bytes from ARGB to RGBA */
|
||||||
png_set_swap_alpha(png_ptr);
|
png_set_swap_alpha(png_ptr);
|
||||||
|
|
||||||
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
|
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
|
||||||
@@ -631,16 +739,16 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
*/
|
*/
|
||||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||||
|
|
||||||
/* flip BGR pixels to RGB */
|
/* Flip BGR pixels to RGB */
|
||||||
png_set_bgr(png_ptr);
|
png_set_bgr(png_ptr);
|
||||||
|
|
||||||
/* swap bytes of 16-bit files to most significant byte first */
|
/* Swap bytes of 16-bit files to most significant byte first */
|
||||||
png_set_swap(png_ptr);
|
png_set_swap(png_ptr);
|
||||||
|
|
||||||
/* swap bits of 1, 2, 4 bit packed pixel formats */
|
/* Swap bits of 1, 2, 4 bit packed pixel formats */
|
||||||
png_set_packswap(png_ptr);
|
png_set_packswap(png_ptr);
|
||||||
|
|
||||||
/* turn on interlace handling if you are not using png_write_image() */
|
/* Turn on interlace handling if you are not using png_write_image() */
|
||||||
if (interlacing)
|
if (interlacing)
|
||||||
number_passes = png_set_interlace_handling(png_ptr);
|
number_passes = png_set_interlace_handling(png_ptr);
|
||||||
else
|
else
|
||||||
@@ -651,18 +759,24 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
* use the first method if you aren't handling interlacing yourself.
|
* use the first method if you aren't handling interlacing yourself.
|
||||||
*/
|
*/
|
||||||
png_uint_32 k, height, width;
|
png_uint_32 k, height, width;
|
||||||
png_byte image[height][width];
|
png_byte image[height][width*bytes_per_pixel];
|
||||||
png_bytep row_pointers[height];
|
png_bytep row_pointers[height];
|
||||||
|
|
||||||
|
if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
|
||||||
|
png_error (png_ptr, "Image is too tall to process in memory");
|
||||||
|
|
||||||
for (k = 0; k < height; k++)
|
for (k = 0; k < height; k++)
|
||||||
row_pointers[k] = image + k*width;
|
row_pointers[k] = image + k*width*bytes_per_pixel;
|
||||||
|
|
||||||
/* One of the following output methods is REQUIRED */
|
/* One of the following output methods is REQUIRED */
|
||||||
#ifdef entire /* write out the entire image data in one call */
|
|
||||||
|
#ifdef entire /* Write out the entire image data in one call */
|
||||||
png_write_image(png_ptr, row_pointers);
|
png_write_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
/* the other way to write the image - deal with interlacing */
|
/* The other way to write the image - deal with interlacing */
|
||||||
|
|
||||||
|
#else no_entire /* Write out the image data by one or more scanlines */
|
||||||
|
|
||||||
#else no_entire /* write out the image data by one or more scanlines */
|
|
||||||
/* The number of passes is either 1 for non-interlaced images,
|
/* The number of passes is either 1 for non-interlaced images,
|
||||||
* or 7 for interlaced images.
|
* or 7 for interlaced images.
|
||||||
*/
|
*/
|
||||||
@@ -673,31 +787,49 @@ void write_png(char *file_name /* , ... other image information ... */)
|
|||||||
|
|
||||||
/* If you are only writing one row at a time, this works */
|
/* If you are only writing one row at a time, this works */
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
|
||||||
png_write_rows(png_ptr, &row_pointers[y], 1);
|
png_write_rows(png_ptr, &row_pointers[y], 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif no_entire /* use only one output method */
|
#endif no_entire /* Use only one output method */
|
||||||
|
|
||||||
/* You can write optional chunks like tEXt, zTXt, and tIME at the end
|
/* You can write optional chunks like tEXt, zTXt, and tIME at the end
|
||||||
* as well.
|
* as well. Shouldn't be necessary in 1.2.0 and up as all the public
|
||||||
|
* chunks are supported and you can use png_set_unknown_chunks() to
|
||||||
|
* register unknown chunks into the info structure to be written out.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* It is REQUIRED to call this to finish writing the rest of the file */
|
/* It is REQUIRED to call this to finish writing the rest of the file */
|
||||||
png_write_end(png_ptr, info_ptr);
|
png_write_end(png_ptr, info_ptr);
|
||||||
|
#endif hilevel
|
||||||
|
|
||||||
/* if you malloced the palette, free it here */
|
/* If you png_malloced a palette, free it here (don't free info_ptr->palette,
|
||||||
free(info_ptr->palette);
|
* as recommended in versions 1.0.5m and earlier of this example; if
|
||||||
|
* libpng mallocs info_ptr->palette, libpng will free it). If you
|
||||||
|
* allocated it with malloc() instead of png_malloc(), use free() instead
|
||||||
|
* of png_free().
|
||||||
|
*/
|
||||||
|
png_free(png_ptr, palette);
|
||||||
|
palette = NULL;
|
||||||
|
|
||||||
/* if you allocated any text comments, free them here */
|
/* Similarly, if you png_malloced any data that you passed in with
|
||||||
|
* png_set_something(), such as a hist or trans array, free it here,
|
||||||
|
* when you can be sure that libpng is through with it.
|
||||||
|
*/
|
||||||
|
png_free(png_ptr, trans);
|
||||||
|
trans = NULL;
|
||||||
|
/* Whenever you use png_free() it is a good idea to set the pointer to
|
||||||
|
* NULL in case your application inadvertently tries to png_free() it
|
||||||
|
* again. When png_free() sees a NULL it returns without action, thus
|
||||||
|
* avoiding the double-free security problem.
|
||||||
|
*/
|
||||||
|
|
||||||
/* clean up after the write, and free any memory allocated */
|
/* Clean up after the write, and free any memory allocated */
|
||||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
|
||||||
/* close the file */
|
/* Close the file */
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/* that's it */
|
/* That's it */
|
||||||
return;
|
return (OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* if 0 */
|
||||||
|
|||||||
520
install-sh
Executable file
@@ -0,0 +1,520 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# install - install a program, script, or datafile
|
||||||
|
|
||||||
|
scriptversion=2009-04-28.21; # UTC
|
||||||
|
|
||||||
|
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||||
|
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||||
|
# following copyright and license.
|
||||||
|
#
|
||||||
|
# Copyright (C) 1994 X Consortium
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to
|
||||||
|
# deal in the Software without restriction, including without limitation the
|
||||||
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
# sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||||
|
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
#
|
||||||
|
# Except as contained in this notice, the name of the X Consortium shall not
|
||||||
|
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||||
|
# ings in this Software without prior written authorization from the X Consor-
|
||||||
|
# tium.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# FSF changes to this file are in the public domain.
|
||||||
|
#
|
||||||
|
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||||
|
# `make' implicit rules from creating a file called install from it
|
||||||
|
# when there is no Makefile.
|
||||||
|
#
|
||||||
|
# This script is compatible with the BSD install script, but was written
|
||||||
|
# from scratch.
|
||||||
|
|
||||||
|
nl='
|
||||||
|
'
|
||||||
|
IFS=" "" $nl"
|
||||||
|
|
||||||
|
# set DOITPROG to echo to test this script
|
||||||
|
|
||||||
|
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||||
|
doit=${DOITPROG-}
|
||||||
|
if test -z "$doit"; then
|
||||||
|
doit_exec=exec
|
||||||
|
else
|
||||||
|
doit_exec=$doit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Put in absolute file names if you don't have them in your path;
|
||||||
|
# or use environment vars.
|
||||||
|
|
||||||
|
chgrpprog=${CHGRPPROG-chgrp}
|
||||||
|
chmodprog=${CHMODPROG-chmod}
|
||||||
|
chownprog=${CHOWNPROG-chown}
|
||||||
|
cmpprog=${CMPPROG-cmp}
|
||||||
|
cpprog=${CPPROG-cp}
|
||||||
|
mkdirprog=${MKDIRPROG-mkdir}
|
||||||
|
mvprog=${MVPROG-mv}
|
||||||
|
rmprog=${RMPROG-rm}
|
||||||
|
stripprog=${STRIPPROG-strip}
|
||||||
|
|
||||||
|
posix_glob='?'
|
||||||
|
initialize_posix_glob='
|
||||||
|
test "$posix_glob" != "?" || {
|
||||||
|
if (set -f) 2>/dev/null; then
|
||||||
|
posix_glob=
|
||||||
|
else
|
||||||
|
posix_glob=:
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
'
|
||||||
|
|
||||||
|
posix_mkdir=
|
||||||
|
|
||||||
|
# Desired mode of installed file.
|
||||||
|
mode=0755
|
||||||
|
|
||||||
|
chgrpcmd=
|
||||||
|
chmodcmd=$chmodprog
|
||||||
|
chowncmd=
|
||||||
|
mvcmd=$mvprog
|
||||||
|
rmcmd="$rmprog -f"
|
||||||
|
stripcmd=
|
||||||
|
|
||||||
|
src=
|
||||||
|
dst=
|
||||||
|
dir_arg=
|
||||||
|
dst_arg=
|
||||||
|
|
||||||
|
copy_on_change=false
|
||||||
|
no_target_directory=
|
||||||
|
|
||||||
|
usage="\
|
||||||
|
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
||||||
|
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
||||||
|
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
||||||
|
or: $0 [OPTION]... -d DIRECTORIES...
|
||||||
|
|
||||||
|
In the 1st form, copy SRCFILE to DSTFILE.
|
||||||
|
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
||||||
|
In the 4th, create DIRECTORIES.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--help display this help and exit.
|
||||||
|
--version display version info and exit.
|
||||||
|
|
||||||
|
-c (ignored)
|
||||||
|
-C install only if different (preserve the last data modification time)
|
||||||
|
-d create directories instead of installing files.
|
||||||
|
-g GROUP $chgrpprog installed files to GROUP.
|
||||||
|
-m MODE $chmodprog installed files to MODE.
|
||||||
|
-o USER $chownprog installed files to USER.
|
||||||
|
-s $stripprog installed files.
|
||||||
|
-t DIRECTORY install into DIRECTORY.
|
||||||
|
-T report an error if DSTFILE is a directory.
|
||||||
|
|
||||||
|
Environment variables override the default commands:
|
||||||
|
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
||||||
|
RMPROG STRIPPROG
|
||||||
|
"
|
||||||
|
|
||||||
|
while test $# -ne 0; do
|
||||||
|
case $1 in
|
||||||
|
-c) ;;
|
||||||
|
|
||||||
|
-C) copy_on_change=true;;
|
||||||
|
|
||||||
|
-d) dir_arg=true;;
|
||||||
|
|
||||||
|
-g) chgrpcmd="$chgrpprog $2"
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
--help) echo "$usage"; exit $?;;
|
||||||
|
|
||||||
|
-m) mode=$2
|
||||||
|
case $mode in
|
||||||
|
*' '* | *' '* | *'
|
||||||
|
'* | *'*'* | *'?'* | *'['*)
|
||||||
|
echo "$0: invalid mode: $mode" >&2
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
-o) chowncmd="$chownprog $2"
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
-s) stripcmd=$stripprog;;
|
||||||
|
|
||||||
|
-t) dst_arg=$2
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
-T) no_target_directory=true;;
|
||||||
|
|
||||||
|
--version) echo "$0 $scriptversion"; exit $?;;
|
||||||
|
|
||||||
|
--) shift
|
||||||
|
break;;
|
||||||
|
|
||||||
|
-*) echo "$0: invalid option: $1" >&2
|
||||||
|
exit 1;;
|
||||||
|
|
||||||
|
*) break;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
||||||
|
# When -d is used, all remaining arguments are directories to create.
|
||||||
|
# When -t is used, the destination is already specified.
|
||||||
|
# Otherwise, the last argument is the destination. Remove it from $@.
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
if test -n "$dst_arg"; then
|
||||||
|
# $@ is not empty: it contains at least $arg.
|
||||||
|
set fnord "$@" "$dst_arg"
|
||||||
|
shift # fnord
|
||||||
|
fi
|
||||||
|
shift # arg
|
||||||
|
dst_arg=$arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $# -eq 0; then
|
||||||
|
if test -z "$dir_arg"; then
|
||||||
|
echo "$0: no input file specified." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# It's OK to call `install-sh -d' without argument.
|
||||||
|
# This can happen when creating conditional directories.
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$dir_arg"; then
|
||||||
|
trap '(exit $?); exit' 1 2 13 15
|
||||||
|
|
||||||
|
# Set umask so as not to create temps with too-generous modes.
|
||||||
|
# However, 'strip' requires both read and write access to temps.
|
||||||
|
case $mode in
|
||||||
|
# Optimize common cases.
|
||||||
|
*644) cp_umask=133;;
|
||||||
|
*755) cp_umask=22;;
|
||||||
|
|
||||||
|
*[0-7])
|
||||||
|
if test -z "$stripcmd"; then
|
||||||
|
u_plus_rw=
|
||||||
|
else
|
||||||
|
u_plus_rw='% 200'
|
||||||
|
fi
|
||||||
|
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
||||||
|
*)
|
||||||
|
if test -z "$stripcmd"; then
|
||||||
|
u_plus_rw=
|
||||||
|
else
|
||||||
|
u_plus_rw=,u+rw
|
||||||
|
fi
|
||||||
|
cp_umask=$mode$u_plus_rw;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
for src
|
||||||
|
do
|
||||||
|
# Protect names starting with `-'.
|
||||||
|
case $src in
|
||||||
|
-*) src=./$src;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
dst=$src
|
||||||
|
dstdir=$dst
|
||||||
|
test -d "$dstdir"
|
||||||
|
dstdir_status=$?
|
||||||
|
else
|
||||||
|
|
||||||
|
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||||
|
# might cause directories to be created, which would be especially bad
|
||||||
|
# if $src (and thus $dsttmp) contains '*'.
|
||||||
|
if test ! -f "$src" && test ! -d "$src"; then
|
||||||
|
echo "$0: $src does not exist." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$dst_arg"; then
|
||||||
|
echo "$0: no destination specified." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
dst=$dst_arg
|
||||||
|
# Protect names starting with `-'.
|
||||||
|
case $dst in
|
||||||
|
-*) dst=./$dst;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# If destination is a directory, append the input filename; won't work
|
||||||
|
# if double slashes aren't ignored.
|
||||||
|
if test -d "$dst"; then
|
||||||
|
if test -n "$no_target_directory"; then
|
||||||
|
echo "$0: $dst_arg: Is a directory" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
dstdir=$dst
|
||||||
|
dst=$dstdir/`basename "$src"`
|
||||||
|
dstdir_status=0
|
||||||
|
else
|
||||||
|
# Prefer dirname, but fall back on a substitute if dirname fails.
|
||||||
|
dstdir=`
|
||||||
|
(dirname "$dst") 2>/dev/null ||
|
||||||
|
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
|
||||||
|
X"$dst" : 'X\(//\)[^/]' \| \
|
||||||
|
X"$dst" : 'X\(//\)$' \| \
|
||||||
|
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
|
||||||
|
echo X"$dst" |
|
||||||
|
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
/^X\(\/\/\)[^/].*/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
/^X\(\/\/\)$/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
/^X\(\/\).*/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
s/.*/./; q'
|
||||||
|
`
|
||||||
|
|
||||||
|
test -d "$dstdir"
|
||||||
|
dstdir_status=$?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
obsolete_mkdir_used=false
|
||||||
|
|
||||||
|
if test $dstdir_status != 0; then
|
||||||
|
case $posix_mkdir in
|
||||||
|
'')
|
||||||
|
# Create intermediate dirs using mode 755 as modified by the umask.
|
||||||
|
# This is like FreeBSD 'install' as of 1997-10-28.
|
||||||
|
umask=`umask`
|
||||||
|
case $stripcmd.$umask in
|
||||||
|
# Optimize common cases.
|
||||||
|
*[2367][2367]) mkdir_umask=$umask;;
|
||||||
|
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
|
||||||
|
|
||||||
|
*[0-7])
|
||||||
|
mkdir_umask=`expr $umask + 22 \
|
||||||
|
- $umask % 100 % 40 + $umask % 20 \
|
||||||
|
- $umask % 10 % 4 + $umask % 2
|
||||||
|
`;;
|
||||||
|
*) mkdir_umask=$umask,go-w;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# With -d, create the new directory with the user-specified mode.
|
||||||
|
# Otherwise, rely on $mkdir_umask.
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
mkdir_mode=-m$mode
|
||||||
|
else
|
||||||
|
mkdir_mode=
|
||||||
|
fi
|
||||||
|
|
||||||
|
posix_mkdir=false
|
||||||
|
case $umask in
|
||||||
|
*[123567][0-7][0-7])
|
||||||
|
# POSIX mkdir -p sets u+wx bits regardless of umask, which
|
||||||
|
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||||
|
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
|
||||||
|
|
||||||
|
if (umask $mkdir_umask &&
|
||||||
|
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
if test -z "$dir_arg" || {
|
||||||
|
# Check for POSIX incompatibilities with -m.
|
||||||
|
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||||
|
# other-writeable bit of parent directory when it shouldn't.
|
||||||
|
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||||
|
ls_ld_tmpdir=`ls -ld "$tmpdir"`
|
||||||
|
case $ls_ld_tmpdir in
|
||||||
|
d????-?r-*) different_mode=700;;
|
||||||
|
d????-?--*) different_mode=755;;
|
||||||
|
*) false;;
|
||||||
|
esac &&
|
||||||
|
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
|
||||||
|
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
|
||||||
|
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
then posix_mkdir=:
|
||||||
|
fi
|
||||||
|
rmdir "$tmpdir/d" "$tmpdir"
|
||||||
|
else
|
||||||
|
# Remove any dirs left behind by ancient mkdir implementations.
|
||||||
|
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
|
||||||
|
fi
|
||||||
|
trap '' 0;;
|
||||||
|
esac;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if
|
||||||
|
$posix_mkdir && (
|
||||||
|
umask $mkdir_umask &&
|
||||||
|
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
||||||
|
)
|
||||||
|
then :
|
||||||
|
else
|
||||||
|
|
||||||
|
# The umask is ridiculous, or mkdir does not conform to POSIX,
|
||||||
|
# or it failed possibly due to a race condition. Create the
|
||||||
|
# directory the slow way, step by step, checking for races as we go.
|
||||||
|
|
||||||
|
case $dstdir in
|
||||||
|
/*) prefix='/';;
|
||||||
|
-*) prefix='./';;
|
||||||
|
*) prefix='';;
|
||||||
|
esac
|
||||||
|
|
||||||
|
eval "$initialize_posix_glob"
|
||||||
|
|
||||||
|
oIFS=$IFS
|
||||||
|
IFS=/
|
||||||
|
$posix_glob set -f
|
||||||
|
set fnord $dstdir
|
||||||
|
shift
|
||||||
|
$posix_glob set +f
|
||||||
|
IFS=$oIFS
|
||||||
|
|
||||||
|
prefixes=
|
||||||
|
|
||||||
|
for d
|
||||||
|
do
|
||||||
|
test -z "$d" && continue
|
||||||
|
|
||||||
|
prefix=$prefix$d
|
||||||
|
if test -d "$prefix"; then
|
||||||
|
prefixes=
|
||||||
|
else
|
||||||
|
if $posix_mkdir; then
|
||||||
|
(umask=$mkdir_umask &&
|
||||||
|
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||||
|
# Don't fail if two instances are running concurrently.
|
||||||
|
test -d "$prefix" || exit 1
|
||||||
|
else
|
||||||
|
case $prefix in
|
||||||
|
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
||||||
|
*) qprefix=$prefix;;
|
||||||
|
esac
|
||||||
|
prefixes="$prefixes '$qprefix'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
prefix=$prefix/
|
||||||
|
done
|
||||||
|
|
||||||
|
if test -n "$prefixes"; then
|
||||||
|
# Don't fail if two instances are running concurrently.
|
||||||
|
(umask $mkdir_umask &&
|
||||||
|
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
||||||
|
test -d "$dstdir" || exit 1
|
||||||
|
obsolete_mkdir_used=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
||||||
|
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
||||||
|
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
||||||
|
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
||||||
|
else
|
||||||
|
|
||||||
|
# Make a couple of temp file names in the proper directory.
|
||||||
|
dsttmp=$dstdir/_inst.$$_
|
||||||
|
rmtmp=$dstdir/_rm.$$_
|
||||||
|
|
||||||
|
# Trap to clean up those temp files at exit.
|
||||||
|
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||||
|
|
||||||
|
# Copy the file name to the temp name.
|
||||||
|
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
|
||||||
|
|
||||||
|
# and set any options; do chmod last to preserve setuid bits.
|
||||||
|
#
|
||||||
|
# If any of these fail, we abort the whole thing. If we want to
|
||||||
|
# ignore errors from any of these, just make sure not to ignore
|
||||||
|
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
||||||
|
#
|
||||||
|
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
|
||||||
|
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
|
||||||
|
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
|
||||||
|
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
||||||
|
|
||||||
|
# If -C, don't bother to copy if it wouldn't change the file.
|
||||||
|
if $copy_on_change &&
|
||||||
|
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
|
||||||
|
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
|
||||||
|
|
||||||
|
eval "$initialize_posix_glob" &&
|
||||||
|
$posix_glob set -f &&
|
||||||
|
set X $old && old=:$2:$4:$5:$6 &&
|
||||||
|
set X $new && new=:$2:$4:$5:$6 &&
|
||||||
|
$posix_glob set +f &&
|
||||||
|
|
||||||
|
test "$old" = "$new" &&
|
||||||
|
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
rm -f "$dsttmp"
|
||||||
|
else
|
||||||
|
# Rename the file to the real destination.
|
||||||
|
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
||||||
|
|
||||||
|
# The rename failed, perhaps because mv can't rename something else
|
||||||
|
# to itself, or perhaps because mv is so ancient that it does not
|
||||||
|
# support -f.
|
||||||
|
{
|
||||||
|
# Now remove or move aside any old file at destination location.
|
||||||
|
# We try this two ways since rm can't unlink itself on some
|
||||||
|
# systems and the destination file might be busy for other
|
||||||
|
# reasons. In this case, the final cleanup might fail but the new
|
||||||
|
# file should still install successfully.
|
||||||
|
{
|
||||||
|
test ! -f "$dst" ||
|
||||||
|
$doit $rmcmd -f "$dst" 2>/dev/null ||
|
||||||
|
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
||||||
|
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
|
||||||
|
} ||
|
||||||
|
{ echo "$0: cannot unlink or rename $dst" >&2
|
||||||
|
(exit 1); exit 1
|
||||||
|
}
|
||||||
|
} &&
|
||||||
|
|
||||||
|
# Now rename the file to the real destination.
|
||||||
|
$doit $mvcmd "$dsttmp" "$dst"
|
||||||
|
}
|
||||||
|
fi || exit 1
|
||||||
|
|
||||||
|
trap '' 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Local variables:
|
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-time-zone: "UTC"
|
||||||
|
# time-stamp-end: "; # UTC"
|
||||||
|
# End:
|
||||||
359
libpngpf.3
@@ -1,57 +1,105 @@
|
|||||||
.TH LIBPNGPF 3 October 1, 1999
|
.TH LIBPNGPF 3 "December 3, 2009"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4c - October 1, 1999
|
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.51
|
||||||
(private functions)
|
(private functions)
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
\fB#include <png.h>\fP
|
\fB#include <png.h>\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_64bit_product (long \fP\fIv1\fP\fB, long \fP\fIv2\fP\fB, unsigned long \fI*hi_product,
|
||||||
|
|
||||||
|
\fBunsigned long \fI*lo_product\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_build_gamma_table (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_build_gamma_table (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
|
\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_calculate_crc (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIptr\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
\fBvoid png_calculate_crc (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIptr\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBint png_check_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_fixed_point \fP\fIint_white_x\fP\fB, png_fixed_point \fP\fIint_white_y\fP\fB, png_fixed_point \fP\fIint_red_x\fP\fB, png_fixed_point \fP\fIint_red_y\fP\fB, png_fixed_point \fP\fIint_green_x\fP\fB, png_fixed_point \fP\fIint_green_y\fP\fB, png_fixed_point \fP\fIint_blue_x\fP\fB, png_fixed_point \fIint_blue_y\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_check_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_check_chunk_name (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
|
\fBvoid png_check_chunk_name (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBpng_size_t png_check_keyword (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charpp \fInew_key\fP\fB);\fP
|
\fBpng_size_t png_check_keyword (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charpp \fInew_key\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fImask\fP\fB);\fP
|
\fBvoid png_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fImask\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_correct_palette (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
|
\fBvoid png_correct_palette (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBint png_crc_error (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBint png_crc_error (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBint png_crc_finish (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIskip\fP\fB);\fP
|
\fBint png_crc_finish (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIskip\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_crc_read (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuf\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
\fBvoid png_crc_read (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuf\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBpng_voidp png_create_struct (int \fP\fItype\fP\fB, png_malloc_ptr \fImalloc_fn\fP\fB);\fP
|
\fI\fB
|
||||||
|
|
||||||
|
\fBpng_voidp png_create_struct (int \fItype\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBpng_voidp png_create_struct_2 (int \fItype\fP\fB);\fP
|
\fI\fB
|
||||||
|
|
||||||
|
\fBpng_voidp png_create_struct_2 (int \fP\fItype\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_voidp \fImem_ptr\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_decompress_chunk (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcomp_type\fP\fB, png_charp \fP\fIchunkdata\fP\fB, png_size_t \fP\fIchunklength\fP\fB, png_size_t \fP\fIprefix_length\fP\fB, png_size_t \fI*data_length\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
@@ -59,7 +107,11 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4c - October 1,
|
|||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_destroy_struct_2 (png_voidp \fP\fIstruct_ptr\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_destroy_struct_2 (png_voidp \fP\fIstruct_ptr\fP\fB, png_free_ptr \fP\fIfree_fn\fP\fB, png_voidp \fImem_ptr\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
@@ -67,361 +119,551 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4c - October 1,
|
|||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_bgr (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_bgr (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_chop (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_chop (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_dither (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIpalette_lookup\fP\fB, png_bytep \fIdither_lookup\fP\fB);\fP
|
\fBvoid png_do_dither (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIpalette_lookup\fP\fB, png_bytep \fIdither_lookup\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_expand (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fItrans_value\fP\fB);\fP
|
\fBvoid png_do_expand (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fItrans_value\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_expand_palette (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fInum_trans\fP\fB);\fP
|
\fBvoid png_do_expand_palette (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fInum_trans\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_gamma (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_uint_16pp \fP\fIgamma_16_table\fP\fB, int \fIgamma_shift\fP\fB);\fP
|
\fBvoid png_do_gamma (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_uint_16pp \fP\fIgamma_16_table\fP\fB, int \fIgamma_shift\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_gray_to_rgb (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_gray_to_rgb (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_invert (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_invert (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_pack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIbit_depth\fP\fB);\fP
|
\fBvoid png_do_pack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIbit_depth\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_packswap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_packswap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_read_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
|
\fBvoid png_do_read_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_read_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fP\fIpass\fP\fB, png_uint_32 \fItransformations\fP\fB);\fP
|
\fBvoid png_do_read_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fP\fIpass\fP\fB, png_uint_32 \fItransformations\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_read_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_read_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_read_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_read_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_do_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBint png_do_rgb_to_gray (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBint png_do_rgb_to_gray (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_shift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIbit_depth\fP\fB);\fP
|
\fBvoid png_do_shift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIbit_depth\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_strip_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
|
\fBvoid png_do_strip_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_swap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_swap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_unpack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_unpack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_unshift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIsig_bits\fP\fB);\fP
|
\fBvoid png_do_unshift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIsig_bits\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_write_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fIpass\fP\fB);\fP
|
\fBvoid png_do_write_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fIpass\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_write_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_write_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_write_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_do_write_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_do_write_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_do_write_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid *png_far_to_near (png_structp png_ptr,png_voidp \fP\fIptr\fP\fB, int \fIcheck\fP\fB);\fP
|
\fBvoid *png_far_to_near (png_structp png_ptr,png_voidp \fP\fIptr\fP\fB, int \fIcheck\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_flush (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_flush (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
|
|
||||||
|
|
||||||
\fI\fB
|
|
||||||
|
|
||||||
\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
|
|
||||||
|
|
||||||
\fI\fB
|
|
||||||
|
|
||||||
\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
|
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_IEND (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_IEND (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_handle_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_handle_iTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_handle_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_handle_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_info_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_info_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_init_mmx_flags (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_init_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_init_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_process_IDAT_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
|
\fBvoid png_process_IDAT_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_process_some_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_process_some_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_check_crc (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_push_check_crc (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_crc_finish (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_push_crc_finish (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_crc_skip (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_push_crc_skip (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_fill_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
\fBvoid png_push_fill_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_push_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_push_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
\fBvoid png_push_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_have_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_push_have_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_have_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_push_have_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_have_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
\fBvoid png_push_have_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_process_row (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_push_process_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_read_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_push_read_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_push_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_read_IDAT (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_push_read_IDAT (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_read_sig (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_push_read_sig (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_read_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_push_read_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_read_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_push_read_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_restore_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
|
\fBvoid png_push_restore_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_push_save_buffer (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_push_save_buffer (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBpng_uint_32 png_read_chunk_header (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_read_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
\fBvoid png_read_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_read_filter_row (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIprev_row\fP\fB, int \fIfilter\fP\fB);\fP
|
\fBvoid png_read_filter_row (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIprev_row\fP\fB, int \fIfilter\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_read_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_read_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_read_init (png_structp \fIpng_ptr\fP\fB);\fP
|
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_read_push_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_read_push_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_read_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_read_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_read_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
\fBvoid png_read_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_reset_crc (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_reset_crc (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
|
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
|
\fBint png_set_text_2 (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
|
|
||||||
|
|
||||||
\fI\fB
|
|
||||||
|
|
||||||
\fBvoid png_write_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIvalues\fP\fB, int \fIcolor_type\fP\fB);\fP
|
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_cHRM (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
|
\fBvoid png_write_cHRM (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_write_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
\fBvoid png_write_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_filtered_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIfiltered_row\fP\fB);\fP
|
\fBvoid png_write_filtered_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIfiltered_row\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_find_filter (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fIrow_info\fP\fB);\fP
|
\fBvoid png_write_find_filter (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fIrow_info\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_write_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_gAMA (png_structp \fP\fIpng_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
|
\fBvoid png_write_gAMA (png_structp \fP\fIpng_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_write_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIint_file_gamma\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_uint_16p \fP\fIhist\fP\fB, int \fInum_hist\fP\fB);\fP
|
\fBvoid png_write_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_uint_16p \fP\fIhist\fP\fB, int \fInum_hist\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_write_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, int \fIproflen\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
@@ -429,77 +671,136 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4c - October 1,
|
|||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_IEND (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_write_IEND (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fP\fIfilter_type\fP\fB, int \fIinterlace_type\fP\fB);\fP
|
\fBvoid png_write_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fP\fIfilter_type\fP\fB, int \fIinterlace_type\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_write_iTXt (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcompression\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fIlang\fP\fB, png_charp \fP\fItranslated_key\fP\fB, png_charp \fItext\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_offset\fP\fB, png_uint_32 \fP\fIy_offset\fP\fB, int \fIunit_type\fP\fB);\fP
|
\fBvoid png_write_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_offset\fP\fB, png_uint_32 \fP\fIy_offset\fP\fB, int \fIunit_type\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
|
\fBvoid png_write_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_pixels_per_unit\fP\fB, png_uint_32 \fP\fIy_pixels_per_unit\fP\fB, int \fIunit_type\fP\fB);\fP
|
\fBvoid png_write_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_pixels_per_unit\fP\fB, png_uint_32 \fP\fIy_pixels_per_unit\fP\fB, int \fIunit_type\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_uint_32 \fInum_pal\fP\fB);\fP
|
\fBvoid png_write_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_uint_32 \fInum_pal\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fP\fIsbit\fP\fB, int \fIcolor_type\fP\fB);\fP
|
\fBvoid png_write_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fP\fIsbit\fP\fB, int \fIcolor_type\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_write_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_write_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_sRGB (png_structp \fP\fIpng_ptr\fP\fB, int \fIintent\fP\fB);\fP
|
\fBvoid png_write_sRGB (png_structp \fP\fIpng_ptr\fP\fB, int \fIintent\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fBvoid png_write_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_spalette_p \fIpalette\fP\fB);\fP
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
\fBvoid png_write_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fItext_len\fP\fB);\fP
|
\fBvoid png_write_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fItext_len\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
|
\fBvoid png_write_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, png_color_16p \fP\fIvalues\fP\fB, int \fP\fInumber\fP\fB, int \fIcolor_type\fP\fB);\fP
|
\fBvoid png_write_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, png_color_16p \fP\fIvalues\fP\fB, int \fP\fInumber\fP\fB, int \fIcolor_type\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_write_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fP\fItext_len\fP\fB, int \fIcompression\fP\fB);\fP
|
\fBvoid png_write_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fP\fItext_len\fP\fB, int \fIcompression\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
|
\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
|
\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
|
||||||
|
|
||||||
\fI\fB
|
\fI\fB
|
||||||
|
|
||||||
|
\fI\fB
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
The functions listed above are used privately by libpng
|
The functions listed above are used privately by libpng
|
||||||
and are not recommended for use by applications. They
|
and are not recommended for use by applications. They are
|
||||||
|
not "exported" to applications using shared libraries. They
|
||||||
are listed alphabetically here as an aid to libpng maintainers.
|
are listed alphabetically here as an aid to libpng maintainers.
|
||||||
See png.h for more information on these functions.
|
See png.h for more information on these functions.
|
||||||
|
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
libpng(3), png(5)
|
.IR libpng(3) ", " png(5)
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Glenn Randers-Pehrson
|
Glenn Randers-Pehrson
|
||||||
|
|||||||
376
missing
Executable file
@@ -0,0 +1,376 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Common stub for a few missing GNU programs while installing.
|
||||||
|
|
||||||
|
scriptversion=2009-04-28.21; # UTC
|
||||||
|
|
||||||
|
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
|
||||||
|
# 2008, 2009 Free Software Foundation, Inc.
|
||||||
|
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# As a special exception to the GNU General Public License, if you
|
||||||
|
# distribute this file as part of a program that contains a
|
||||||
|
# configuration script generated by Autoconf, you may include it under
|
||||||
|
# the same distribution terms that you use for the rest of that program.
|
||||||
|
|
||||||
|
if test $# -eq 0; then
|
||||||
|
echo 1>&2 "Try \`$0 --help' for more information"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
run=:
|
||||||
|
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
|
||||||
|
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
|
||||||
|
|
||||||
|
# In the cases where this matters, `missing' is being run in the
|
||||||
|
# srcdir already.
|
||||||
|
if test -f configure.ac; then
|
||||||
|
configure_ac=configure.ac
|
||||||
|
else
|
||||||
|
configure_ac=configure.in
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg="missing on your system"
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
--run)
|
||||||
|
# Try to run requested program, and just exit if it succeeds.
|
||||||
|
run=
|
||||||
|
shift
|
||||||
|
"$@" && exit 0
|
||||||
|
# Exit code 63 means version mismatch. This often happens
|
||||||
|
# when the user try to use an ancient version of a tool on
|
||||||
|
# a file that requires a minimum version. In this case we
|
||||||
|
# we should proceed has if the program had been absent, or
|
||||||
|
# if --run hadn't been passed.
|
||||||
|
if test $? = 63; then
|
||||||
|
run=:
|
||||||
|
msg="probably too old"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
-h|--h|--he|--hel|--help)
|
||||||
|
echo "\
|
||||||
|
$0 [OPTION]... PROGRAM [ARGUMENT]...
|
||||||
|
|
||||||
|
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
|
||||||
|
error status if there is no known handling for PROGRAM.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help display this help and exit
|
||||||
|
-v, --version output version information and exit
|
||||||
|
--run try to run the given command, and emulate it if it fails
|
||||||
|
|
||||||
|
Supported PROGRAM values:
|
||||||
|
aclocal touch file \`aclocal.m4'
|
||||||
|
autoconf touch file \`configure'
|
||||||
|
autoheader touch file \`config.h.in'
|
||||||
|
autom4te touch the output file, or create a stub one
|
||||||
|
automake touch all \`Makefile.in' files
|
||||||
|
bison create \`y.tab.[ch]', if possible, from existing .[ch]
|
||||||
|
flex create \`lex.yy.c', if possible, from existing .c
|
||||||
|
help2man touch the output file
|
||||||
|
lex create \`lex.yy.c', if possible, from existing .c
|
||||||
|
makeinfo touch the output file
|
||||||
|
tar try tar, gnutar, gtar, then tar without non-portable flags
|
||||||
|
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
|
||||||
|
|
||||||
|
Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
|
||||||
|
\`g' are ignored when checking the name.
|
||||||
|
|
||||||
|
Send bug reports to <bug-automake@gnu.org>."
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
|
||||||
|
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
|
||||||
|
echo "missing $scriptversion (GNU Automake)"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
|
||||||
|
-*)
|
||||||
|
echo 1>&2 "$0: Unknown \`$1' option"
|
||||||
|
echo 1>&2 "Try \`$0 --help' for more information"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
|
# normalize program name to check for.
|
||||||
|
program=`echo "$1" | sed '
|
||||||
|
s/^gnu-//; t
|
||||||
|
s/^gnu//; t
|
||||||
|
s/^g//; t'`
|
||||||
|
|
||||||
|
# Now exit if we have it, but it failed. Also exit now if we
|
||||||
|
# don't have it and --version was passed (most likely to detect
|
||||||
|
# the program). This is about non-GNU programs, so use $1 not
|
||||||
|
# $program.
|
||||||
|
case $1 in
|
||||||
|
lex*|yacc*)
|
||||||
|
# Not GNU programs, they don't have --version.
|
||||||
|
;;
|
||||||
|
|
||||||
|
tar*)
|
||||||
|
if test -n "$run"; then
|
||||||
|
echo 1>&2 "ERROR: \`tar' requires --run"
|
||||||
|
exit 1
|
||||||
|
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
|
||||||
|
# We have it, but it failed.
|
||||||
|
exit 1
|
||||||
|
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
|
||||||
|
# Could not run --version or --help. This is probably someone
|
||||||
|
# running `$TOOL --version' or `$TOOL --help' to check whether
|
||||||
|
# $TOOL exists and not knowing $TOOL uses missing.
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# If it does not exist, or fails to run (possibly an outdated version),
|
||||||
|
# try to emulate it.
|
||||||
|
case $program in
|
||||||
|
aclocal*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
|
||||||
|
to install the \`Automake' and \`Perl' packages. Grab them from
|
||||||
|
any GNU archive site."
|
||||||
|
touch aclocal.m4
|
||||||
|
;;
|
||||||
|
|
||||||
|
autoconf*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`${configure_ac}'. You might want to install the
|
||||||
|
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
|
||||||
|
archive site."
|
||||||
|
touch configure
|
||||||
|
;;
|
||||||
|
|
||||||
|
autoheader*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`acconfig.h' or \`${configure_ac}'. You might want
|
||||||
|
to install the \`Autoconf' and \`GNU m4' packages. Grab them
|
||||||
|
from any GNU archive site."
|
||||||
|
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
|
||||||
|
test -z "$files" && files="config.h"
|
||||||
|
touch_files=
|
||||||
|
for f in $files; do
|
||||||
|
case $f in
|
||||||
|
*:*) touch_files="$touch_files "`echo "$f" |
|
||||||
|
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
|
||||||
|
*) touch_files="$touch_files $f.in";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
touch $touch_files
|
||||||
|
;;
|
||||||
|
|
||||||
|
automake*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
|
||||||
|
You might want to install the \`Automake' and \`Perl' packages.
|
||||||
|
Grab them from any GNU archive site."
|
||||||
|
find . -type f -name Makefile.am -print |
|
||||||
|
sed 's/\.am$/.in/' |
|
||||||
|
while read f; do touch "$f"; done
|
||||||
|
;;
|
||||||
|
|
||||||
|
autom4te*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is needed, but is $msg.
|
||||||
|
You might have modified some files without having the
|
||||||
|
proper tools for further handling them.
|
||||||
|
You can get \`$1' as part of \`Autoconf' from any GNU
|
||||||
|
archive site."
|
||||||
|
|
||||||
|
file=`echo "$*" | sed -n "$sed_output"`
|
||||||
|
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||||
|
if test -f "$file"; then
|
||||||
|
touch $file
|
||||||
|
else
|
||||||
|
test -z "$file" || exec >$file
|
||||||
|
echo "#! /bin/sh"
|
||||||
|
echo "# Created by GNU Automake missing as a replacement of"
|
||||||
|
echo "# $ $@"
|
||||||
|
echo "exit 0"
|
||||||
|
chmod +x $file
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
bison*|yacc*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' $msg. You should only need it if
|
||||||
|
you modified a \`.y' file. You may need the \`Bison' package
|
||||||
|
in order for those modifications to take effect. You can get
|
||||||
|
\`Bison' from any GNU archive site."
|
||||||
|
rm -f y.tab.c y.tab.h
|
||||||
|
if test $# -ne 1; then
|
||||||
|
eval LASTARG="\${$#}"
|
||||||
|
case $LASTARG in
|
||||||
|
*.y)
|
||||||
|
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
|
||||||
|
if test -f "$SRCFILE"; then
|
||||||
|
cp "$SRCFILE" y.tab.c
|
||||||
|
fi
|
||||||
|
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
|
||||||
|
if test -f "$SRCFILE"; then
|
||||||
|
cp "$SRCFILE" y.tab.h
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
if test ! -f y.tab.h; then
|
||||||
|
echo >y.tab.h
|
||||||
|
fi
|
||||||
|
if test ! -f y.tab.c; then
|
||||||
|
echo 'main() { return 0; }' >y.tab.c
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
lex*|flex*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified a \`.l' file. You may need the \`Flex' package
|
||||||
|
in order for those modifications to take effect. You can get
|
||||||
|
\`Flex' from any GNU archive site."
|
||||||
|
rm -f lex.yy.c
|
||||||
|
if test $# -ne 1; then
|
||||||
|
eval LASTARG="\${$#}"
|
||||||
|
case $LASTARG in
|
||||||
|
*.l)
|
||||||
|
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
|
||||||
|
if test -f "$SRCFILE"; then
|
||||||
|
cp "$SRCFILE" lex.yy.c
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
if test ! -f lex.yy.c; then
|
||||||
|
echo 'main() { return 0; }' >lex.yy.c
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
help2man*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified a dependency of a manual page. You may need the
|
||||||
|
\`Help2man' package in order for those modifications to take
|
||||||
|
effect. You can get \`Help2man' from any GNU archive site."
|
||||||
|
|
||||||
|
file=`echo "$*" | sed -n "$sed_output"`
|
||||||
|
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||||
|
if test -f "$file"; then
|
||||||
|
touch $file
|
||||||
|
else
|
||||||
|
test -z "$file" || exec >$file
|
||||||
|
echo ".ab help2man is required to generate this page"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
makeinfo*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified a \`.texi' or \`.texinfo' file, or any other file
|
||||||
|
indirectly affecting the aspect of the manual. The spurious
|
||||||
|
call might also be the consequence of using a buggy \`make' (AIX,
|
||||||
|
DU, IRIX). You might want to install the \`Texinfo' package or
|
||||||
|
the \`GNU make' package. Grab either from any GNU archive site."
|
||||||
|
# The file to touch is that specified with -o ...
|
||||||
|
file=`echo "$*" | sed -n "$sed_output"`
|
||||||
|
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||||
|
if test -z "$file"; then
|
||||||
|
# ... or it is the one specified with @setfilename ...
|
||||||
|
infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
|
||||||
|
file=`sed -n '
|
||||||
|
/^@setfilename/{
|
||||||
|
s/.* \([^ ]*\) *$/\1/
|
||||||
|
p
|
||||||
|
q
|
||||||
|
}' $infile`
|
||||||
|
# ... or it is derived from the source name (dir/f.texi becomes f.info)
|
||||||
|
test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
|
||||||
|
fi
|
||||||
|
# If the file does not exist, the user really needs makeinfo;
|
||||||
|
# let's fail without touching anything.
|
||||||
|
test -f $file || exit 1
|
||||||
|
touch $file
|
||||||
|
;;
|
||||||
|
|
||||||
|
tar*)
|
||||||
|
shift
|
||||||
|
|
||||||
|
# We have already tried tar in the generic part.
|
||||||
|
# Look for gnutar/gtar before invocation to avoid ugly error
|
||||||
|
# messages.
|
||||||
|
if (gnutar --version > /dev/null 2>&1); then
|
||||||
|
gnutar "$@" && exit 0
|
||||||
|
fi
|
||||||
|
if (gtar --version > /dev/null 2>&1); then
|
||||||
|
gtar "$@" && exit 0
|
||||||
|
fi
|
||||||
|
firstarg="$1"
|
||||||
|
if shift; then
|
||||||
|
case $firstarg in
|
||||||
|
*o*)
|
||||||
|
firstarg=`echo "$firstarg" | sed s/o//`
|
||||||
|
tar "$firstarg" "$@" && exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
case $firstarg in
|
||||||
|
*h*)
|
||||||
|
firstarg=`echo "$firstarg" | sed s/h//`
|
||||||
|
tar "$firstarg" "$@" && exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: I can't seem to be able to run \`tar' with the given arguments.
|
||||||
|
You may want to install GNU tar or Free paxutils, or check the
|
||||||
|
command line arguments."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is needed, and is $msg.
|
||||||
|
You might have modified some files without having the
|
||||||
|
proper tools for further handling them. Check the \`README' file,
|
||||||
|
it often tells you about the needed prerequisites for installing
|
||||||
|
this package. You may also peek at any GNU archive site, in case
|
||||||
|
some other package would contain this missing \`$1' program."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
# Local variables:
|
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-time-zone: "UTC"
|
||||||
|
# time-stamp-end: "; # UTC"
|
||||||
|
# End:
|
||||||
162
mkinstalldirs
Executable file
@@ -0,0 +1,162 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# mkinstalldirs --- make directory hierarchy
|
||||||
|
|
||||||
|
scriptversion=2009-04-28.21; # UTC
|
||||||
|
|
||||||
|
# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
|
||||||
|
# Created: 1993-05-16
|
||||||
|
# Public domain.
|
||||||
|
#
|
||||||
|
# This file is maintained in Automake, please report
|
||||||
|
# bugs to <bug-automake@gnu.org> or send patches to
|
||||||
|
# <automake-patches@gnu.org>.
|
||||||
|
|
||||||
|
nl='
|
||||||
|
'
|
||||||
|
IFS=" "" $nl"
|
||||||
|
errstatus=0
|
||||||
|
dirmode=
|
||||||
|
|
||||||
|
usage="\
|
||||||
|
Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
|
||||||
|
|
||||||
|
Create each directory DIR (with mode MODE, if specified), including all
|
||||||
|
leading file name components.
|
||||||
|
|
||||||
|
Report bugs to <bug-automake@gnu.org>."
|
||||||
|
|
||||||
|
# process command line arguments
|
||||||
|
while test $# -gt 0 ; do
|
||||||
|
case $1 in
|
||||||
|
-h | --help | --h*) # -h for help
|
||||||
|
echo "$usage"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
-m) # -m PERM arg
|
||||||
|
shift
|
||||||
|
test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
|
||||||
|
dirmode=$1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--version)
|
||||||
|
echo "$0 $scriptversion"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
--) # stop option processing
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-*) # unknown option
|
||||||
|
echo "$usage" 1>&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*) # first non-opt arg
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
for file
|
||||||
|
do
|
||||||
|
if test -d "$file"; then
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
case $# in
|
||||||
|
0) exit 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
|
||||||
|
# mkdir -p a/c at the same time, both will detect that a is missing,
|
||||||
|
# one will create a, then the other will try to create a and die with
|
||||||
|
# a "File exists" error. This is a problem when calling mkinstalldirs
|
||||||
|
# from a parallel make. We use --version in the probe to restrict
|
||||||
|
# ourselves to GNU mkdir, which is thread-safe.
|
||||||
|
case $dirmode in
|
||||||
|
'')
|
||||||
|
if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
|
||||||
|
echo "mkdir -p -- $*"
|
||||||
|
exec mkdir -p -- "$@"
|
||||||
|
else
|
||||||
|
# On NextStep and OpenStep, the `mkdir' command does not
|
||||||
|
# recognize any option. It will interpret all options as
|
||||||
|
# directories to create, and then abort because `.' already
|
||||||
|
# exists.
|
||||||
|
test -d ./-p && rmdir ./-p
|
||||||
|
test -d ./--version && rmdir ./--version
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
|
||||||
|
test ! -d ./--version; then
|
||||||
|
echo "mkdir -m $dirmode -p -- $*"
|
||||||
|
exec mkdir -m "$dirmode" -p -- "$@"
|
||||||
|
else
|
||||||
|
# Clean up after NextStep and OpenStep mkdir.
|
||||||
|
for d in ./-m ./-p ./--version "./$dirmode";
|
||||||
|
do
|
||||||
|
test -d $d && rmdir $d
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
for file
|
||||||
|
do
|
||||||
|
case $file in
|
||||||
|
/*) pathcomp=/ ;;
|
||||||
|
*) pathcomp= ;;
|
||||||
|
esac
|
||||||
|
oIFS=$IFS
|
||||||
|
IFS=/
|
||||||
|
set fnord $file
|
||||||
|
shift
|
||||||
|
IFS=$oIFS
|
||||||
|
|
||||||
|
for d
|
||||||
|
do
|
||||||
|
test "x$d" = x && continue
|
||||||
|
|
||||||
|
pathcomp=$pathcomp$d
|
||||||
|
case $pathcomp in
|
||||||
|
-*) pathcomp=./$pathcomp ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test ! -d "$pathcomp"; then
|
||||||
|
echo "mkdir $pathcomp"
|
||||||
|
|
||||||
|
mkdir "$pathcomp" || lasterr=$?
|
||||||
|
|
||||||
|
if test ! -d "$pathcomp"; then
|
||||||
|
errstatus=$lasterr
|
||||||
|
else
|
||||||
|
if test ! -z "$dirmode"; then
|
||||||
|
echo "chmod $dirmode $pathcomp"
|
||||||
|
lasterr=
|
||||||
|
chmod "$dirmode" "$pathcomp" || lasterr=$?
|
||||||
|
|
||||||
|
if test ! -z "$lasterr"; then
|
||||||
|
errstatus=$lasterr
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
pathcomp=$pathcomp/
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $errstatus
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: shell-script
|
||||||
|
# sh-indentation: 2
|
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-time-zone: "UTC"
|
||||||
|
# time-stamp-end: "; # UTC"
|
||||||
|
# End:
|
||||||
32
png.5
@@ -1,4 +1,4 @@
|
|||||||
.TH PNG 5 "October 1, 1999"
|
.TH PNG 5 "December 3, 2009"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
png \- Portable Network Graphics (PNG) format
|
png \- Portable Network Graphics (PNG) format
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
@@ -18,12 +18,16 @@ gamma and chromaticity data for improved color matching on heterogeneous
|
|||||||
platforms.
|
platforms.
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
.IR libpng(3), zlib(3), deflate(5), and zlib(5)
|
.IR libpng(3) ", " zlib(3) ", " deflate(5) ", and " zlib(5)
|
||||||
.LP
|
.LP
|
||||||
PNG 1.1 specification, January 1999:
|
PNG specification (second edition), November 2003:
|
||||||
.IP
|
.IP
|
||||||
.br
|
.br
|
||||||
http://www.cdrom.com/pub/png
|
<http://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||||
|
PNG 1.2 specification, July 1999:
|
||||||
|
.IP
|
||||||
|
.br
|
||||||
|
http://www.libpng.org/pub/png
|
||||||
.LP
|
.LP
|
||||||
PNG 1.0 specification, October 1996:
|
PNG 1.0 specification, October 1996:
|
||||||
.IP
|
.IP
|
||||||
@@ -31,7 +35,7 @@ PNG 1.0 specification, October 1996:
|
|||||||
RFC 2083
|
RFC 2083
|
||||||
.IP
|
.IP
|
||||||
.br
|
.br
|
||||||
ftp://ds.internic.net/rfc/rfc2083.txt
|
ftp://ftp.rfc-editor.org:/in-notes/rfc2083.txt
|
||||||
.br
|
.br
|
||||||
or (as a W3C Recommendation) at
|
or (as a W3C Recommendation) at
|
||||||
.br
|
.br
|
||||||
@@ -39,19 +43,31 @@ http://www.w3.org/TR/REC-png.html
|
|||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
This man page: Glenn Randers-Pehrson
|
This man page: Glenn Randers-Pehrson
|
||||||
.LP
|
.LP
|
||||||
|
Portable Network Graphics (PNG) Specification (Second Edition)
|
||||||
|
Information technology - Computer graphics and image processing -
|
||||||
|
Portable Network Graphics (PNG): Functional specification.
|
||||||
|
ISO/IEC 15948:2003 (E) (November 10, 2003): David Duce and others.
|
||||||
|
.LP
|
||||||
Portable Network Graphics (PNG) Specification Version 1.2 (July 8, 1999):
|
Portable Network Graphics (PNG) Specification Version 1.2 (July 8, 1999):
|
||||||
Glenn Randers-Pehrson and others (png-list@ccrc.wustl.edu).
|
Glenn Randers-Pehrson and others (png-list).
|
||||||
.LP
|
.LP
|
||||||
Portable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):
|
Portable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):
|
||||||
Thomas Boutell and others (png-list@ccrc.wustl.edu).
|
Thomas Boutell and others (png-list).
|
||||||
.LP
|
.LP
|
||||||
|
|
||||||
|
|
||||||
.SH COPYRIGHT NOTICE
|
.SH COPYRIGHT NOTICE
|
||||||
|
.LP
|
||||||
|
This man page is Copyright (c) 1998-2006 Glenn Randers-Pehrson. See png.h
|
||||||
|
for conditions of use and distribution.
|
||||||
|
.LP
|
||||||
|
The PNG Specification (Second Edition) is
|
||||||
|
Copyright (c) 2003 W3C. (MIT, ERCIM, Keio), All Rights Reserved.
|
||||||
|
.LP
|
||||||
The PNG-1.2 specification is copyright (c) 1999 Glenn Randers-Pehrson.
|
The PNG-1.2 specification is copyright (c) 1999 Glenn Randers-Pehrson.
|
||||||
See the specification for conditions of use and distribution.
|
See the specification for conditions of use and distribution.
|
||||||
.LP
|
.LP
|
||||||
The PNG-1.0 specification is copyright (c) 1996 Massachussets Institute of
|
The PNG-1.0 specification is copyright (c) 1996 Massachusetts Institute of
|
||||||
Technology. See the specification for conditions of use and distribution.
|
Technology. See the specification for conditions of use and distribution.
|
||||||
.LP
|
.LP
|
||||||
.\" end of man page
|
.\" end of man page
|
||||||
|
|||||||
32
pngasmrd.h
@@ -1,32 +0,0 @@
|
|||||||
/* pngasmrd.h - assembler version of utilities to read a PNG file
|
|
||||||
*
|
|
||||||
* libpng 1.0.4c - October 1, 1999
|
|
||||||
* For conditions of distribution and use, see copyright notice in png.h
|
|
||||||
* Copyright (c) 1999 Glenn Randers-Pehrson
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
|
|
||||||
|
|
||||||
/* Set this in the makefile for VC++ on Pentium, not in pngconf.h */
|
|
||||||
#ifdef PNG_USE_PNGVCRD
|
|
||||||
/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c .
|
|
||||||
* MMX will be detected at run time and used if present.
|
|
||||||
*/
|
|
||||||
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
|
||||||
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
|
||||||
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set this in the makefile for gcc on Pentium, not in pngconf.h */
|
|
||||||
#ifdef PNG_USE_PNGGCCRD
|
|
||||||
/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c
|
|
||||||
* (not available in libpng 1.0.4c).
|
|
||||||
* MMX will be detected at run time and used if present.
|
|
||||||
*/
|
|
||||||
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
|
||||||
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
|
||||||
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
BIN
pngbar.jpg
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
pngbar.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
340
pngerror.c
@@ -1,11 +1,14 @@
|
|||||||
|
|
||||||
/* pngerror.c - stub functions for i/o and memory allocation
|
/* pngerror.c - stub functions for i/o and memory allocation
|
||||||
*
|
*
|
||||||
* libpng 1.0.4c - October 1, 1999
|
* Last changed in libpng 1.2.41 [December 3, 2009]
|
||||||
* For conditions of distribution and use, see copyright notice in png.h
|
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
*
|
||||||
|
* This code is released under the libpng license.
|
||||||
|
* For conditions of distribution and use, see the disclaimer
|
||||||
|
* and license in png.h
|
||||||
*
|
*
|
||||||
* This file provides a location for all error handling. Users who
|
* This file provides a location for all error handling. Users who
|
||||||
* need special error handling are expected to write replacement functions
|
* need special error handling are expected to write replacement functions
|
||||||
@@ -14,42 +17,127 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
|
#define PNG_NO_PEDANTIC_WARNINGS
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||||
|
|
||||||
static void png_default_error PNGARG((png_structp png_ptr,
|
static void /* PRIVATE */
|
||||||
png_const_charp message));
|
png_default_error PNGARG((png_structp png_ptr,
|
||||||
static void png_default_warning PNGARG((png_structp png_ptr,
|
png_const_charp error_message)) PNG_NORETURN;
|
||||||
png_const_charp message));
|
#ifdef PNG_WARNINGS_SUPPORTED
|
||||||
|
static void /* PRIVATE */
|
||||||
|
png_default_warning PNGARG((png_structp png_ptr,
|
||||||
|
png_const_charp warning_message));
|
||||||
|
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||||
|
|
||||||
/* This function is called whenever there is a fatal error. This function
|
/* This function is called whenever there is a fatal error. This function
|
||||||
* should not be changed. If there is a need to handle errors differently,
|
* should not be changed. If there is a need to handle errors differently,
|
||||||
* you should supply a replacement error function and use png_set_error_fn()
|
* you should supply a replacement error function and use png_set_error_fn()
|
||||||
* to replace the error function at run-time.
|
* to replace the error function at run-time.
|
||||||
*/
|
*/
|
||||||
void
|
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||||
png_error(png_structp png_ptr, png_const_charp message)
|
void PNGAPI
|
||||||
|
png_error(png_structp png_ptr, png_const_charp error_message)
|
||||||
{
|
{
|
||||||
if (png_ptr->error_fn != NULL)
|
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||||
(*(png_ptr->error_fn))(png_ptr, message);
|
char msg[16];
|
||||||
|
if (png_ptr != NULL)
|
||||||
|
{
|
||||||
|
if (png_ptr->flags&
|
||||||
|
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||||
|
{
|
||||||
|
if (*error_message == PNG_LITERAL_SHARP)
|
||||||
|
{
|
||||||
|
/* Strip "#nnnn " from beginning of error message. */
|
||||||
|
int offset;
|
||||||
|
for (offset = 1; offset<15; offset++)
|
||||||
|
if (error_message[offset] == ' ')
|
||||||
|
break;
|
||||||
|
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < offset - 1; i++)
|
||||||
|
msg[i] = error_message[i + 1];
|
||||||
|
msg[i - 1] = '\0';
|
||||||
|
error_message = msg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error_message += offset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||||
|
{
|
||||||
|
msg[0] = '0';
|
||||||
|
msg[1] = '\0';
|
||||||
|
error_message = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (png_ptr != NULL && png_ptr->error_fn != NULL)
|
||||||
|
(*(png_ptr->error_fn))(png_ptr, error_message);
|
||||||
|
|
||||||
/* if the following returns or doesn't exist, use the default function,
|
/* If the custom handler doesn't exist, or if it returns,
|
||||||
which will not return */
|
use the default handler, which will not return. */
|
||||||
png_default_error(png_ptr, message);
|
png_default_error(png_ptr, error_message);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void PNGAPI
|
||||||
|
png_err(png_structp png_ptr)
|
||||||
|
{
|
||||||
|
if (png_ptr != NULL && png_ptr->error_fn != NULL)
|
||||||
|
(*(png_ptr->error_fn))(png_ptr, '\0');
|
||||||
|
|
||||||
|
/* If the custom handler doesn't exist, or if it returns,
|
||||||
|
use the default handler, which will not return. */
|
||||||
|
png_default_error(png_ptr, '\0');
|
||||||
|
}
|
||||||
|
#endif /* PNG_ERROR_TEXT_SUPPORTED */
|
||||||
|
|
||||||
|
#ifdef PNG_WARNINGS_SUPPORTED
|
||||||
/* This function is called whenever there is a non-fatal error. This function
|
/* This function is called whenever there is a non-fatal error. This function
|
||||||
* should not be changed. If there is a need to handle warnings differently,
|
* should not be changed. If there is a need to handle warnings differently,
|
||||||
* you should supply a replacement warning function and use
|
* you should supply a replacement warning function and use
|
||||||
* png_set_error_fn() to replace the warning function at run-time.
|
* png_set_error_fn() to replace the warning function at run-time.
|
||||||
*/
|
*/
|
||||||
void
|
void PNGAPI
|
||||||
png_warning(png_structp png_ptr, png_const_charp message)
|
png_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||||
{
|
{
|
||||||
if (png_ptr->warning_fn != NULL)
|
int offset = 0;
|
||||||
(*(png_ptr->warning_fn))(png_ptr, message);
|
if (png_ptr != NULL)
|
||||||
|
{
|
||||||
|
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||||
|
if (png_ptr->flags&
|
||||||
|
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if (*warning_message == PNG_LITERAL_SHARP)
|
||||||
|
{
|
||||||
|
for (offset = 1; offset < 15; offset++)
|
||||||
|
if (warning_message[offset] == ' ')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
|
||||||
|
(*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
|
||||||
else
|
else
|
||||||
png_default_warning(png_ptr, message);
|
png_default_warning(png_ptr, warning_message + offset);
|
||||||
}
|
}
|
||||||
|
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||||
|
|
||||||
|
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||||
|
void PNGAPI
|
||||||
|
png_benign_error(png_structp png_ptr, png_const_charp error_message)
|
||||||
|
{
|
||||||
|
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||||
|
png_warning(png_ptr, error_message);
|
||||||
|
else
|
||||||
|
png_error(png_ptr, error_message);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* These utilities are used internally to build an error message that relates
|
/* These utilities are used internally to build an error message that relates
|
||||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
||||||
@@ -57,101 +145,214 @@ png_warning(png_structp png_ptr, png_const_charp message)
|
|||||||
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
||||||
* if the character is invalid.
|
* if the character is invalid.
|
||||||
*/
|
*/
|
||||||
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
|
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||||
static PNG_CONST char png_digit[16] = {
|
static PNG_CONST char png_digit[16] = {
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||||
|
'A', 'B', 'C', 'D', 'E', 'F'
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
#define PNG_MAX_ERROR_TEXT 64
|
||||||
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message)
|
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||||
|
static void /* PRIVATE */
|
||||||
|
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
|
||||||
|
error_message)
|
||||||
{
|
{
|
||||||
int iout = 0, iin = 0;
|
int iout = 0, iin = 0;
|
||||||
|
|
||||||
while (iin < 4) {
|
while (iin < 4)
|
||||||
|
{
|
||||||
int c = png_ptr->chunk_name[iin++];
|
int c = png_ptr->chunk_name[iin++];
|
||||||
if (isnonalpha(c)) {
|
if (isnonalpha(c))
|
||||||
buffer[iout++] = '[';
|
{
|
||||||
|
buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
|
||||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||||
buffer[iout++] = png_digit[c & 0xf];
|
buffer[iout++] = png_digit[c & 0x0f];
|
||||||
buffer[iout++] = ']';
|
buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
|
||||||
} else {
|
}
|
||||||
buffer[iout++] = c;
|
else
|
||||||
|
{
|
||||||
|
buffer[iout++] = (png_byte)c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message == NULL)
|
if (error_message == NULL)
|
||||||
buffer[iout] = 0;
|
buffer[iout] = '\0';
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
buffer[iout++] = ':';
|
buffer[iout++] = ':';
|
||||||
buffer[iout++] = ' ';
|
buffer[iout++] = ' ';
|
||||||
png_memcpy(buffer+iout, message, 64);
|
png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);
|
||||||
buffer[iout+63] = 0;
|
buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
#ifdef PNG_READ_SUPPORTED
|
||||||
png_chunk_error(png_structp png_ptr, png_const_charp message)
|
void PNGAPI
|
||||||
|
png_chunk_error(png_structp png_ptr, png_const_charp error_message)
|
||||||
{
|
{
|
||||||
char msg[16+64];
|
char msg[18+PNG_MAX_ERROR_TEXT];
|
||||||
png_format_buffer(png_ptr, msg, message);
|
if (png_ptr == NULL)
|
||||||
png_error(png_ptr, msg);
|
png_error(png_ptr, error_message);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
png_format_buffer(png_ptr, msg, error_message);
|
||||||
|
png_error(png_ptr, msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* PNG_READ_SUPPORTED */
|
||||||
|
#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
|
||||||
|
|
||||||
void
|
#ifdef PNG_WARNINGS_SUPPORTED
|
||||||
png_chunk_warning(png_structp png_ptr, png_const_charp message)
|
void PNGAPI
|
||||||
|
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||||
{
|
{
|
||||||
char msg[16+64];
|
char msg[18+PNG_MAX_ERROR_TEXT];
|
||||||
png_format_buffer(png_ptr, msg, message);
|
if (png_ptr == NULL)
|
||||||
png_warning(png_ptr, msg);
|
png_warning(png_ptr, warning_message);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
png_format_buffer(png_ptr, msg, warning_message);
|
||||||
|
png_warning(png_ptr, msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||||
|
|
||||||
|
#ifdef PNG_READ_SUPPORTED
|
||||||
|
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||||
|
void PNGAPI
|
||||||
|
png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
|
||||||
|
{
|
||||||
|
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||||
|
png_chunk_warning(png_ptr, error_message);
|
||||||
|
else
|
||||||
|
png_chunk_error(png_ptr, error_message);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* PNG_READ_SUPPORTED */
|
||||||
|
|
||||||
/* This is the default error handling function. Note that replacements for
|
/* This is the default error handling function. Note that replacements for
|
||||||
* this function MUST NOT RETURN, or the program will likely crash. This
|
* this function MUST NOT RETURN, or the program will likely crash. This
|
||||||
* function is used by default, or if the program supplies NULL for the
|
* function is used by default, or if the program supplies NULL for the
|
||||||
* error function pointer in png_set_error_fn().
|
* error function pointer in png_set_error_fn().
|
||||||
*/
|
*/
|
||||||
static void
|
static void /* PRIVATE */
|
||||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
png_default_error(png_structp png_ptr, png_const_charp error_message)
|
||||||
{
|
{
|
||||||
#ifndef PNG_NO_CONSOLE_IO
|
#ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||||
fprintf(stderr, "libpng error: %s\n", message);
|
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||||
|
if (*error_message == PNG_LITERAL_SHARP)
|
||||||
|
{
|
||||||
|
/* Strip "#nnnn " from beginning of error message. */
|
||||||
|
int offset;
|
||||||
|
char error_number[16];
|
||||||
|
for (offset = 0; offset<15; offset++)
|
||||||
|
{
|
||||||
|
error_number[offset] = error_message[offset + 1];
|
||||||
|
if (error_message[offset] == ' ')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((offset > 1) && (offset < 15))
|
||||||
|
{
|
||||||
|
error_number[offset - 1] = '\0';
|
||||||
|
fprintf(stderr, "libpng error no. %s: %s",
|
||||||
|
error_number, error_message + offset + 1);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "libpng error: %s, offset=%d",
|
||||||
|
error_message, offset);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
fprintf(stderr, "libpng error: %s", error_message);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FAR_KEYWORD
|
#ifdef PNG_SETJMP_SUPPORTED
|
||||||
|
if (png_ptr)
|
||||||
|
{
|
||||||
|
# ifdef USE_FAR_KEYWORD
|
||||||
{
|
{
|
||||||
jmp_buf jmpbuf;
|
jmp_buf jmpbuf;
|
||||||
png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
|
png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
|
||||||
longjmp(jmpbuf, 1);
|
longjmp(jmpbuf, 1);
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
longjmp(png_ptr->jmpbuf, 1);
|
longjmp(png_ptr->jmpbuf, 1);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* Here if not setjmp support or if png_ptr is null. */
|
||||||
|
PNG_ABORT();
|
||||||
|
#ifndef PNG_CONSOLE_IO_SUPPORTED
|
||||||
|
error_message = error_message; /* Make compiler happy */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PNG_WARNINGS_SUPPORTED
|
||||||
/* This function is called when there is a warning, but the library thinks
|
/* This function is called when there is a warning, but the library thinks
|
||||||
* it can continue anyway. Replacement functions don't have to do anything
|
* it can continue anyway. Replacement functions don't have to do anything
|
||||||
* here if you don't want them to. In the default configuration, png_ptr is
|
* here if you don't want them to. In the default configuration, png_ptr is
|
||||||
* not used, but it is passed in case it may be useful.
|
* not used, but it is passed in case it may be useful.
|
||||||
*/
|
*/
|
||||||
static void
|
static void /* PRIVATE */
|
||||||
png_default_warning(png_structp png_ptr, png_const_charp message)
|
png_default_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||||
{
|
{
|
||||||
#ifndef PNG_NO_CONSOLE_IO
|
#ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||||
fprintf(stderr, "libpng warning: %s\n", message);
|
# ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||||
|
if (*warning_message == PNG_LITERAL_SHARP)
|
||||||
|
{
|
||||||
|
int offset;
|
||||||
|
char warning_number[16];
|
||||||
|
for (offset = 0; offset < 15; offset++)
|
||||||
|
{
|
||||||
|
warning_number[offset] = warning_message[offset + 1];
|
||||||
|
if (warning_message[offset] == ' ')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((offset > 1) && (offset < 15))
|
||||||
|
{
|
||||||
|
warning_number[offset + 1] = '\0';
|
||||||
|
fprintf(stderr, "libpng warning no. %s: %s",
|
||||||
|
warning_number, warning_message + offset);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "libpng warning: %s",
|
||||||
|
warning_message);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
{
|
||||||
|
fprintf(stderr, "libpng warning: %s", warning_message);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
warning_message = warning_message; /* Make compiler happy */
|
||||||
#endif
|
#endif
|
||||||
if (png_ptr == NULL)
|
png_ptr = png_ptr; /* Make compiler happy */
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||||
|
|
||||||
/* This function is called when the application wants to use another method
|
/* This function is called when the application wants to use another method
|
||||||
* of handling errors and warnings. Note that the error function MUST NOT
|
* of handling errors and warnings. Note that the error function MUST NOT
|
||||||
* return to the calling routine or serious problems will occur. The return
|
* return to the calling routine or serious problems will occur. The return
|
||||||
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
|
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
|
||||||
*/
|
*/
|
||||||
void
|
void PNGAPI
|
||||||
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
||||||
png_error_ptr error_fn, png_error_ptr warning_fn)
|
png_error_ptr error_fn, png_error_ptr warning_fn)
|
||||||
{
|
{
|
||||||
|
if (png_ptr == NULL)
|
||||||
|
return;
|
||||||
png_ptr->error_ptr = error_ptr;
|
png_ptr->error_ptr = error_ptr;
|
||||||
png_ptr->error_fn = error_fn;
|
png_ptr->error_fn = error_fn;
|
||||||
png_ptr->warning_fn = warning_fn;
|
png_ptr->warning_fn = warning_fn;
|
||||||
@@ -162,11 +363,24 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
|||||||
* functions. The application should free any memory associated with this
|
* functions. The application should free any memory associated with this
|
||||||
* pointer before png_write_destroy and png_read_destroy are called.
|
* pointer before png_write_destroy and png_read_destroy are called.
|
||||||
*/
|
*/
|
||||||
png_voidp
|
png_voidp PNGAPI
|
||||||
png_get_error_ptr(png_structp png_ptr)
|
png_get_error_ptr(png_structp png_ptr)
|
||||||
{
|
{
|
||||||
|
if (png_ptr == NULL)
|
||||||
|
return NULL;
|
||||||
return ((png_voidp)png_ptr->error_ptr);
|
return ((png_voidp)png_ptr->error_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||||
|
void PNGAPI
|
||||||
|
png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
|
||||||
|
{
|
||||||
|
if (png_ptr != NULL)
|
||||||
|
{
|
||||||
|
png_ptr->flags &=
|
||||||
|
((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||||
|
|||||||
103
pnggccrd.c
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/* pnggccrd.c was removed from libpng-1.2.20. */
|
||||||
|
|
||||||
|
/* This code snippet is for use by configure's compilation test. */
|
||||||
|
|
||||||
|
#if (!defined _MSC_VER) && \
|
||||||
|
defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \
|
||||||
|
defined(PNG_MMX_CODE_SUPPORTED)
|
||||||
|
|
||||||
|
int PNGAPI png_dummy_mmx_support(void);
|
||||||
|
|
||||||
|
static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested
|
||||||
|
|
||||||
|
int PNGAPI
|
||||||
|
png_dummy_mmx_support(void) __attribute__((noinline));
|
||||||
|
|
||||||
|
int PNGAPI
|
||||||
|
png_dummy_mmx_support(void)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
#ifdef PNG_MMX_CODE_SUPPORTED // superfluous, but what the heck
|
||||||
|
__asm__ __volatile__ (
|
||||||
|
#ifdef __x86_64__
|
||||||
|
"pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction
|
||||||
|
"pushq %%rcx \n\t" // so does rcx...
|
||||||
|
"pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux)
|
||||||
|
"pushfq \n\t" // save Eflag to stack
|
||||||
|
"popq %%rax \n\t" // get Eflag from stack into rax
|
||||||
|
"movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx
|
||||||
|
"xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21)
|
||||||
|
"pushq %%rax \n\t" // save modified Eflag back to stack
|
||||||
|
"popfq \n\t" // restore modified value to Eflag reg
|
||||||
|
"pushfq \n\t" // save Eflag to stack
|
||||||
|
"popq %%rax \n\t" // get Eflag from stack
|
||||||
|
"pushq %%rcx \n\t" // save original Eflag to stack
|
||||||
|
"popfq \n\t" // restore original Eflag
|
||||||
|
#else
|
||||||
|
"pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction
|
||||||
|
"pushl %%ecx \n\t" // so does ecx...
|
||||||
|
"pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux)
|
||||||
|
"pushfl \n\t" // save Eflag to stack
|
||||||
|
"popl %%eax \n\t" // get Eflag from stack into eax
|
||||||
|
"movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx
|
||||||
|
"xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21)
|
||||||
|
"pushl %%eax \n\t" // save modified Eflag back to stack
|
||||||
|
"popfl \n\t" // restore modified value to Eflag reg
|
||||||
|
"pushfl \n\t" // save Eflag to stack
|
||||||
|
"popl %%eax \n\t" // get Eflag from stack
|
||||||
|
"pushl %%ecx \n\t" // save original Eflag to stack
|
||||||
|
"popfl \n\t" // restore original Eflag
|
||||||
|
#endif
|
||||||
|
"xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag
|
||||||
|
"jz 0f \n\t" // if same, CPUID instr. is not supported
|
||||||
|
|
||||||
|
"xorl %%eax, %%eax \n\t" // set eax to zero
|
||||||
|
// ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode)
|
||||||
|
"cpuid \n\t" // get the CPU identification info
|
||||||
|
"cmpl $1, %%eax \n\t" // make sure eax return non-zero value
|
||||||
|
"jl 0f \n\t" // if eax is zero, MMX is not supported
|
||||||
|
|
||||||
|
"xorl %%eax, %%eax \n\t" // set eax to zero and...
|
||||||
|
"incl %%eax \n\t" // ...increment eax to 1. This pair is
|
||||||
|
// faster than the instruction "mov eax, 1"
|
||||||
|
"cpuid \n\t" // get the CPU identification info again
|
||||||
|
"andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23)
|
||||||
|
"cmpl $0, %%edx \n\t" // 0 = MMX not supported
|
||||||
|
"jz 0f \n\t" // non-zero = yes, MMX IS supported
|
||||||
|
|
||||||
|
"movl $1, %%eax \n\t" // set return value to 1
|
||||||
|
"jmp 1f \n\t" // DONE: have MMX support
|
||||||
|
|
||||||
|
"0: \n\t" // .NOT_SUPPORTED: target label for jump instructions
|
||||||
|
"movl $0, %%eax \n\t" // set return value to 0
|
||||||
|
"1: \n\t" // .RETURN: target label for jump instructions
|
||||||
|
#ifdef __x86_64__
|
||||||
|
"popq %%rdx \n\t" // restore rdx
|
||||||
|
"popq %%rcx \n\t" // restore rcx
|
||||||
|
"popq %%rbx \n\t" // restore rbx
|
||||||
|
#else
|
||||||
|
"popl %%edx \n\t" // restore edx
|
||||||
|
"popl %%ecx \n\t" // restore ecx
|
||||||
|
"popl %%ebx \n\t" // restore ebx
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// "ret \n\t" // DONE: no MMX support
|
||||||
|
// (fall through to standard C "ret")
|
||||||
|
|
||||||
|
: "=a" (result) // output list
|
||||||
|
|
||||||
|
: // any variables used on input (none)
|
||||||
|
|
||||||
|
// no clobber list
|
||||||
|
// , "%ebx", "%ecx", "%edx" // GRR: we handle these manually
|
||||||
|
// , "memory" // if write to a variable gcc thought was in a reg
|
||||||
|
// , "cc" // "condition codes" (flag bits)
|
||||||
|
);
|
||||||
|
_mmx_supported = result;
|
||||||
|
#else
|
||||||
|
_mmx_supported = 0;
|
||||||
|
#endif /* PNG_MMX_CODE_SUPPORTED */
|
||||||
|
|
||||||
|
return _mmx_supported;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
371
pngmem.c
@@ -1,11 +1,14 @@
|
|||||||
|
|
||||||
/* pngmem.c - stub functions for memory allocation
|
/* pngmem.c - stub functions for memory allocation
|
||||||
*
|
*
|
||||||
* libpng 1.0.4c - October 1, 1999
|
* Last changed in libpng 1.2.41 [December 3, 2009]
|
||||||
* For conditions of distribution and use, see copyright notice in png.h
|
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
*
|
||||||
|
* This code is released under the libpng license.
|
||||||
|
* For conditions of distribution and use, see the disclaimer
|
||||||
|
* and license in png.h
|
||||||
*
|
*
|
||||||
* This file provides a location for all memory allocation. Users who
|
* This file provides a location for all memory allocation. Users who
|
||||||
* need special memory handling are expected to supply replacement
|
* need special memory handling are expected to supply replacement
|
||||||
@@ -15,79 +18,81 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
|
#define PNG_NO_PEDANTIC_WARNINGS
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||||
|
|
||||||
/* Borland DOS special memory handler */
|
/* Borland DOS special memory handler */
|
||||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||||
/* if you change this, be sure to change the one in png.h also */
|
/* If you change this, be sure to change the one in png.h also */
|
||||||
|
|
||||||
/* Allocate memory for a png_struct. The malloc and memset can be replaced
|
/* Allocate memory for a png_struct. The malloc and memset can be replaced
|
||||||
by a single call to calloc() if this is thought to improve performance. */
|
by a single call to calloc() if this is thought to improve performance. */
|
||||||
png_voidp
|
png_voidp /* PRIVATE */
|
||||||
png_create_struct(int type)
|
png_create_struct(int type)
|
||||||
{
|
{
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
return (png_create_struct_2(type, NULL));
|
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Alternate version of png_create_struct, for use with user-defined malloc. */
|
/* Alternate version of png_create_struct, for use with user-defined malloc. */
|
||||||
png_voidp
|
png_voidp /* PRIVATE */
|
||||||
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
|
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
|
||||||
{
|
{
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
png_size_t size;
|
png_size_t size;
|
||||||
png_voidp struct_ptr;
|
png_voidp struct_ptr;
|
||||||
|
|
||||||
if (type == PNG_STRUCT_INFO)
|
if (type == PNG_STRUCT_INFO)
|
||||||
size = sizeof(png_info);
|
size = png_sizeof(png_info);
|
||||||
else if (type == PNG_STRUCT_PNG)
|
else if (type == PNG_STRUCT_PNG)
|
||||||
size = sizeof(png_struct);
|
size = png_sizeof(png_struct);
|
||||||
else
|
else
|
||||||
return ((png_voidp)NULL);
|
return (png_get_copyright(NULL));
|
||||||
|
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
if(malloc_fn != NULL)
|
if (malloc_fn != NULL)
|
||||||
{
|
{
|
||||||
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
|
png_struct dummy_struct;
|
||||||
png_memset(struct_ptr, 0, size);
|
png_structp png_ptr = &dummy_struct;
|
||||||
return (struct_ptr);
|
png_ptr->mem_ptr=mem_ptr;
|
||||||
|
struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
|
struct_ptr = (png_voidp)farmalloc(size);
|
||||||
{
|
if (struct_ptr != NULL)
|
||||||
png_memset(struct_ptr, 0, size);
|
png_memset(struct_ptr, 0, size);
|
||||||
}
|
|
||||||
return (struct_ptr);
|
return (struct_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Free memory allocated by a png_create_struct() call */
|
/* Free memory allocated by a png_create_struct() call */
|
||||||
void
|
void /* PRIVATE */
|
||||||
png_destroy_struct(png_voidp struct_ptr)
|
png_destroy_struct(png_voidp struct_ptr)
|
||||||
{
|
{
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
|
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free memory allocated by a png_create_struct() call */
|
/* Free memory allocated by a png_create_struct() call */
|
||||||
void
|
void /* PRIVATE */
|
||||||
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
|
||||||
|
png_voidp mem_ptr)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
if (struct_ptr != NULL)
|
if (struct_ptr != NULL)
|
||||||
{
|
{
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
if(free_fn != NULL)
|
if (free_fn != NULL)
|
||||||
{
|
{
|
||||||
png_struct dummy_struct;
|
png_struct dummy_struct;
|
||||||
png_structp png_ptr = &dummy_struct;
|
png_structp png_ptr = &dummy_struct;
|
||||||
|
png_ptr->mem_ptr=mem_ptr;
|
||||||
(*(free_fn))(png_ptr, struct_ptr);
|
(*(free_fn))(png_ptr, struct_ptr);
|
||||||
struct_ptr = NULL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
farfree (struct_ptr);
|
farfree (struct_ptr);
|
||||||
struct_ptr = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,38 +115,60 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
|||||||
* result, we would be truncating potentially larger memory requests
|
* result, we would be truncating potentially larger memory requests
|
||||||
* (which should cause a fatal error) and introducing major problems.
|
* (which should cause a fatal error) and introducing major problems.
|
||||||
*/
|
*/
|
||||||
png_voidp
|
png_voidp PNGAPI
|
||||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
png_calloc(png_structp png_ptr, png_uint_32 size)
|
||||||
{
|
{
|
||||||
#ifndef PNG_USER_MEM_SUPPORTED
|
|
||||||
png_voidp ret;
|
png_voidp ret;
|
||||||
#endif
|
|
||||||
if (png_ptr == NULL || size == 0)
|
|
||||||
return ((png_voidp)NULL);
|
|
||||||
|
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
ret = (png_malloc(png_ptr, size));
|
||||||
if(png_ptr->malloc_fn != NULL)
|
if (ret != NULL)
|
||||||
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
|
png_memset(ret,0,(png_size_t)size);
|
||||||
else
|
return (ret);
|
||||||
return png_malloc_default(png_ptr, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
png_voidp
|
png_voidp PNGAPI
|
||||||
|
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||||
|
{
|
||||||
|
png_voidp ret;
|
||||||
|
|
||||||
|
if (png_ptr == NULL || size == 0)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
|
if (png_ptr->malloc_fn != NULL)
|
||||||
|
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
|
||||||
|
else
|
||||||
|
ret = (png_malloc_default(png_ptr, size));
|
||||||
|
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr, "Out of memory!");
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
png_voidp PNGAPI
|
||||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||||
{
|
{
|
||||||
png_voidp ret;
|
png_voidp ret;
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
|
|
||||||
|
if (png_ptr == NULL || size == 0)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
#ifdef PNG_MAX_MALLOC_64K
|
#ifdef PNG_MAX_MALLOC_64K
|
||||||
if (size > (png_uint_32)65536L)
|
if (size > (png_uint_32)65536L)
|
||||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
{
|
||||||
|
png_warning(png_ptr, "Cannot Allocate > 64K");
|
||||||
|
ret = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (size == (png_uint_32)65536L)
|
if (size != (size_t)size)
|
||||||
|
ret = NULL;
|
||||||
|
else if (size == (png_uint_32)65536L)
|
||||||
{
|
{
|
||||||
if (png_ptr->offset_table == NULL)
|
if (png_ptr->offset_table == NULL)
|
||||||
{
|
{
|
||||||
/* try to see if we need to do any of this fancy stuff */
|
/* Try to see if we need to do any of this fancy stuff */
|
||||||
ret = farmalloc(size);
|
ret = farmalloc(size);
|
||||||
if (ret == NULL || ((png_size_t)ret & 0xffff))
|
if (ret == NULL || ((png_size_t)ret & 0xffff))
|
||||||
{
|
{
|
||||||
@@ -157,7 +184,7 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
|||||||
ret = NULL;
|
ret = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(png_ptr->zlib_window_bits > 14)
|
if (png_ptr->zlib_window_bits > 14)
|
||||||
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
|
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
|
||||||
else
|
else
|
||||||
num_blocks = 1;
|
num_blocks = 1;
|
||||||
@@ -172,21 +199,41 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
|||||||
|
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
|
#ifndef PNG_USER_MEM_SUPPORTED
|
||||||
|
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
|
||||||
|
else
|
||||||
|
png_warning(png_ptr, "Out Of Memory.");
|
||||||
|
#endif
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((png_size_t)table & 0xfff0)
|
if ((png_size_t)table & 0xfff0)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Farmalloc didn't return normalized pointer");
|
#ifndef PNG_USER_MEM_SUPPORTED
|
||||||
|
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr,
|
||||||
|
"Farmalloc didn't return normalized pointer");
|
||||||
|
else
|
||||||
|
png_warning(png_ptr,
|
||||||
|
"Farmalloc didn't return normalized pointer");
|
||||||
|
#endif
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_ptr->offset_table = table;
|
png_ptr->offset_table = table;
|
||||||
png_ptr->offset_table_ptr = farmalloc(num_blocks *
|
png_ptr->offset_table_ptr = farmalloc(num_blocks *
|
||||||
sizeof (png_bytep));
|
png_sizeof(png_bytep));
|
||||||
|
|
||||||
if (png_ptr->offset_table_ptr == NULL)
|
if (png_ptr->offset_table_ptr == NULL)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Out Of memory.");
|
#ifndef PNG_USER_MEM_SUPPORTED
|
||||||
|
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
|
||||||
|
else
|
||||||
|
png_warning(png_ptr, "Out Of memory.");
|
||||||
|
#endif
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
hptr = (png_byte huge *)table;
|
hptr = (png_byte huge *)table;
|
||||||
@@ -208,25 +255,39 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
|
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
|
||||||
png_error(png_ptr, "Out of Memory.");
|
{
|
||||||
|
#ifndef PNG_USER_MEM_SUPPORTED
|
||||||
|
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
|
||||||
|
else
|
||||||
|
png_warning(png_ptr, "Out of Memory.");
|
||||||
|
#endif
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
|
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = farmalloc(size);
|
ret = farmalloc(size);
|
||||||
|
|
||||||
|
#ifndef PNG_USER_MEM_SUPPORTED
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
|
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
|
||||||
|
else
|
||||||
|
png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free a pointer allocated by png_malloc(). In the default
|
/* Free a pointer allocated by png_malloc(). In the default
|
||||||
configuration, png_ptr is not used, but is passed in case it
|
* configuration, png_ptr is not used, but is passed in case it
|
||||||
is needed. If ptr is NULL, return without taking any action. */
|
* is needed. If ptr is NULL, return without taking any action.
|
||||||
void
|
*/
|
||||||
|
void PNGAPI
|
||||||
png_free(png_structp png_ptr, png_voidp ptr)
|
png_free(png_structp png_ptr, png_voidp ptr)
|
||||||
{
|
{
|
||||||
if (png_ptr == NULL || ptr == NULL)
|
if (png_ptr == NULL || ptr == NULL)
|
||||||
@@ -236,17 +297,20 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
|||||||
if (png_ptr->free_fn != NULL)
|
if (png_ptr->free_fn != NULL)
|
||||||
{
|
{
|
||||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||||
ptr = NULL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else png_free_default(png_ptr, ptr);
|
else
|
||||||
|
png_free_default(png_ptr, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PNGAPI
|
||||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||||
{
|
{
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
|
|
||||||
|
if (png_ptr == NULL || ptr == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (png_ptr->offset_table != NULL)
|
if (png_ptr->offset_table != NULL)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -272,7 +336,6 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
|
|||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
{
|
{
|
||||||
farfree(ptr);
|
farfree(ptr);
|
||||||
ptr = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,151 +343,187 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
|
|||||||
|
|
||||||
/* Allocate memory for a png_struct or a png_info. The malloc and
|
/* Allocate memory for a png_struct or a png_info. The malloc and
|
||||||
memset can be replaced by a single call to calloc() if this is thought
|
memset can be replaced by a single call to calloc() if this is thought
|
||||||
to improve performance noticably.*/
|
to improve performance noticably. */
|
||||||
png_voidp
|
png_voidp /* PRIVATE */
|
||||||
png_create_struct(int type)
|
png_create_struct(int type)
|
||||||
{
|
{
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
return (png_create_struct_2(type, NULL));
|
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory for a png_struct or a png_info. The malloc and
|
/* Allocate memory for a png_struct or a png_info. The malloc and
|
||||||
memset can be replaced by a single call to calloc() if this is thought
|
memset can be replaced by a single call to calloc() if this is thought
|
||||||
to improve performance noticably.*/
|
to improve performance noticably. */
|
||||||
png_voidp
|
png_voidp /* PRIVATE */
|
||||||
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
|
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
|
||||||
{
|
{
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
png_size_t size;
|
png_size_t size;
|
||||||
png_voidp struct_ptr;
|
png_voidp struct_ptr;
|
||||||
|
|
||||||
if (type == PNG_STRUCT_INFO)
|
if (type == PNG_STRUCT_INFO)
|
||||||
size = sizeof(png_info);
|
size = png_sizeof(png_info);
|
||||||
else if (type == PNG_STRUCT_PNG)
|
else if (type == PNG_STRUCT_PNG)
|
||||||
size = sizeof(png_struct);
|
size = png_sizeof(png_struct);
|
||||||
else
|
else
|
||||||
return ((png_voidp)NULL);
|
return (NULL);
|
||||||
|
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
if(malloc_fn != NULL)
|
if (malloc_fn != NULL)
|
||||||
{
|
{
|
||||||
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
|
png_struct dummy_struct;
|
||||||
|
png_structp png_ptr = &dummy_struct;
|
||||||
|
png_ptr->mem_ptr=mem_ptr;
|
||||||
|
struct_ptr = (*(malloc_fn))(png_ptr, size);
|
||||||
|
if (struct_ptr != NULL)
|
||||||
png_memset(struct_ptr, 0, size);
|
png_memset(struct_ptr, 0, size);
|
||||||
return (struct_ptr);
|
return (struct_ptr);
|
||||||
}
|
}
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
|
|
||||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||||
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
|
struct_ptr = (png_voidp)farmalloc(size);
|
||||||
#else
|
#else
|
||||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||||
if ((struct_ptr = (png_voidp)halloc(size,1)) != NULL)
|
struct_ptr = (png_voidp)halloc(size, 1);
|
||||||
# else
|
# else
|
||||||
if ((struct_ptr = (png_voidp)malloc(size)) != NULL)
|
struct_ptr = (png_voidp)malloc(size);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
{
|
if (struct_ptr != NULL)
|
||||||
png_memset(struct_ptr, 0, size);
|
png_memset(struct_ptr, 0, size);
|
||||||
}
|
|
||||||
|
|
||||||
return (struct_ptr);
|
return (struct_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Free memory allocated by a png_create_struct() call */
|
/* Free memory allocated by a png_create_struct() call */
|
||||||
void
|
void /* PRIVATE */
|
||||||
png_destroy_struct(png_voidp struct_ptr)
|
png_destroy_struct(png_voidp struct_ptr)
|
||||||
{
|
{
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
|
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free memory allocated by a png_create_struct() call */
|
/* Free memory allocated by a png_create_struct() call */
|
||||||
void
|
void /* PRIVATE */
|
||||||
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
|
||||||
|
png_voidp mem_ptr)
|
||||||
{
|
{
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
if (struct_ptr != NULL)
|
if (struct_ptr != NULL)
|
||||||
{
|
{
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
if(free_fn != NULL)
|
if (free_fn != NULL)
|
||||||
{
|
{
|
||||||
png_struct dummy_struct;
|
png_struct dummy_struct;
|
||||||
png_structp png_ptr = &dummy_struct;
|
png_structp png_ptr = &dummy_struct;
|
||||||
|
png_ptr->mem_ptr=mem_ptr;
|
||||||
(*(free_fn))(png_ptr, struct_ptr);
|
(*(free_fn))(png_ptr, struct_ptr);
|
||||||
struct_ptr = NULL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||||
farfree(struct_ptr);
|
farfree(struct_ptr);
|
||||||
struct_ptr = NULL;
|
|
||||||
#else
|
#else
|
||||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||||
hfree(struct_ptr);
|
hfree(struct_ptr);
|
||||||
struct_ptr = NULL;
|
|
||||||
# else
|
# else
|
||||||
free(struct_ptr);
|
free(struct_ptr);
|
||||||
struct_ptr = NULL;
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Allocate memory. For reasonable files, size should never exceed
|
/* Allocate memory. For reasonable files, size should never exceed
|
||||||
64K. However, zlib may allocate more then 64K if you don't tell
|
* 64K. However, zlib may allocate more then 64K if you don't tell
|
||||||
it not to. See zconf.h and png.h for more information. zlib does
|
* it not to. See zconf.h and png.h for more information. zlib does
|
||||||
need to allocate exactly 64K, so whatever you call here must
|
* need to allocate exactly 64K, so whatever you call here must
|
||||||
have the ability to do that. */
|
* have the ability to do that.
|
||||||
|
*/
|
||||||
|
|
||||||
png_voidp
|
png_voidp PNGAPI
|
||||||
|
png_calloc(png_structp png_ptr, png_uint_32 size)
|
||||||
|
{
|
||||||
|
png_voidp ret;
|
||||||
|
|
||||||
|
ret = (png_malloc(png_ptr, size));
|
||||||
|
if (ret != NULL)
|
||||||
|
png_memset(ret,0,(png_size_t)size);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
png_voidp PNGAPI
|
||||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||||
{
|
{
|
||||||
#ifndef PNG_USER_MEM_SUPPORTED
|
|
||||||
png_voidp ret;
|
png_voidp ret;
|
||||||
#endif
|
|
||||||
if (png_ptr == NULL || size == 0)
|
|
||||||
return ((png_voidp)NULL);
|
|
||||||
|
|
||||||
#ifdef PNG_USER_MEM_SUPPORTED
|
#ifdef PNG_USER_MEM_SUPPORTED
|
||||||
if(png_ptr->malloc_fn != NULL)
|
if (png_ptr == NULL || size == 0)
|
||||||
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
|
return (NULL);
|
||||||
|
|
||||||
|
if (png_ptr->malloc_fn != NULL)
|
||||||
|
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
|
||||||
else
|
else
|
||||||
return (png_malloc_default(png_ptr, size));
|
ret = (png_malloc_default(png_ptr, size));
|
||||||
|
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr, "Out of Memory!");
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
png_voidp
|
|
||||||
|
png_voidp PNGAPI
|
||||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||||
{
|
{
|
||||||
png_voidp ret;
|
png_voidp ret;
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
|
|
||||||
|
if (png_ptr == NULL || size == 0)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
#ifdef PNG_MAX_MALLOC_64K
|
#ifdef PNG_MAX_MALLOC_64K
|
||||||
if (size > (png_uint_32)65536L)
|
if (size > (png_uint_32)65536L)
|
||||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
{
|
||||||
|
#ifndef PNG_USER_MEM_SUPPORTED
|
||||||
|
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
|
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Check for overflow */
|
||||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||||
ret = farmalloc(size);
|
if (size != (unsigned long)size)
|
||||||
|
ret = NULL;
|
||||||
|
else
|
||||||
|
ret = farmalloc(size);
|
||||||
#else
|
#else
|
||||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||||
ret = halloc(size, 1);
|
if (size != (unsigned long)size)
|
||||||
|
ret = NULL;
|
||||||
|
else
|
||||||
|
ret = halloc(size, 1);
|
||||||
# else
|
# else
|
||||||
ret = malloc((size_t)size);
|
if (size != (size_t)size)
|
||||||
|
ret = NULL;
|
||||||
|
else
|
||||||
|
ret = malloc((size_t)size);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ret == NULL)
|
#ifndef PNG_USER_MEM_SUPPORTED
|
||||||
{
|
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory");
|
||||||
}
|
#endif
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
|
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
|
||||||
without taking any action. */
|
* without taking any action.
|
||||||
void
|
*/
|
||||||
|
void PNGAPI
|
||||||
png_free(png_structp png_ptr, png_voidp ptr)
|
png_free(png_structp png_ptr, png_voidp ptr)
|
||||||
{
|
{
|
||||||
if (png_ptr == NULL || ptr == NULL)
|
if (png_ptr == NULL || ptr == NULL)
|
||||||
@@ -434,33 +533,57 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
|||||||
if (png_ptr->free_fn != NULL)
|
if (png_ptr->free_fn != NULL)
|
||||||
{
|
{
|
||||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||||
ptr = NULL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else png_free_default(png_ptr, ptr);
|
else
|
||||||
|
png_free_default(png_ptr, ptr);
|
||||||
}
|
}
|
||||||
void
|
void PNGAPI
|
||||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||||
{
|
{
|
||||||
|
if (png_ptr == NULL || ptr == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
|
|
||||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||||
farfree(ptr);
|
farfree(ptr);
|
||||||
ptr = NULL;
|
|
||||||
#else
|
#else
|
||||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||||
hfree(ptr);
|
hfree(ptr);
|
||||||
ptr = NULL;
|
|
||||||
# else
|
# else
|
||||||
free(ptr);
|
free(ptr);
|
||||||
ptr = NULL;
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* Not Borland DOS special memory handler */
|
#endif /* Not Borland DOS special memory handler */
|
||||||
|
|
||||||
png_voidp
|
#ifdef PNG_1_0_X
|
||||||
|
# define png_malloc_warn png_malloc
|
||||||
|
#else
|
||||||
|
/* This function was added at libpng version 1.2.3. The png_malloc_warn()
|
||||||
|
* function will set up png_malloc() to issue a png_warning and return NULL
|
||||||
|
* instead of issuing a png_error, if it fails to allocate the requested
|
||||||
|
* memory.
|
||||||
|
*/
|
||||||
|
png_voidp PNGAPI
|
||||||
|
png_malloc_warn(png_structp png_ptr, png_uint_32 size)
|
||||||
|
{
|
||||||
|
png_voidp ptr;
|
||||||
|
png_uint_32 save_flags;
|
||||||
|
if (png_ptr == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
save_flags = png_ptr->flags;
|
||||||
|
png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
|
||||||
|
ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
|
||||||
|
png_ptr->flags=save_flags;
|
||||||
|
return(ptr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
png_voidp PNGAPI
|
||||||
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
|
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
|
||||||
png_uint_32 length)
|
png_uint_32 length)
|
||||||
{
|
{
|
||||||
@@ -468,12 +591,12 @@ png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
|
|||||||
|
|
||||||
size = (png_size_t)length;
|
size = (png_size_t)length;
|
||||||
if ((png_uint_32)size != length)
|
if ((png_uint_32)size != length)
|
||||||
png_error(png_ptr,"Overflow in png_memcpy_check.");
|
png_error(png_ptr, "Overflow in png_memcpy_check.");
|
||||||
|
|
||||||
return(png_memcpy (s1, s2, size));
|
return(png_memcpy (s1, s2, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
png_voidp
|
png_voidp PNGAPI
|
||||||
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
|
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
|
||||||
png_uint_32 length)
|
png_uint_32 length)
|
||||||
{
|
{
|
||||||
@@ -481,7 +604,7 @@ png_memset_check (png_structp png_ptr, png_voidp s1, int value,
|
|||||||
|
|
||||||
size = (png_size_t)length;
|
size = (png_size_t)length;
|
||||||
if ((png_uint_32)size != length)
|
if ((png_uint_32)size != length)
|
||||||
png_error(png_ptr,"Overflow in png_memset_check.");
|
png_error(png_ptr, "Overflow in png_memset_check.");
|
||||||
|
|
||||||
return (png_memset (s1, value, size));
|
return (png_memset (s1, value, size));
|
||||||
|
|
||||||
@@ -491,22 +614,28 @@ png_memset_check (png_structp png_ptr, png_voidp s1, int value,
|
|||||||
/* This function is called when the application wants to use another method
|
/* This function is called when the application wants to use another method
|
||||||
* of allocating and freeing memory.
|
* of allocating and freeing memory.
|
||||||
*/
|
*/
|
||||||
void
|
void PNGAPI
|
||||||
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
|
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
|
||||||
malloc_fn, png_free_ptr free_fn)
|
malloc_fn, png_free_ptr free_fn)
|
||||||
{
|
{
|
||||||
png_ptr->mem_ptr = mem_ptr;
|
if (png_ptr != NULL)
|
||||||
png_ptr->malloc_fn = malloc_fn;
|
{
|
||||||
png_ptr->free_fn = free_fn;
|
png_ptr->mem_ptr = mem_ptr;
|
||||||
|
png_ptr->malloc_fn = malloc_fn;
|
||||||
|
png_ptr->free_fn = free_fn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function returns a pointer to the mem_ptr associated with the user
|
/* This function returns a pointer to the mem_ptr associated with the user
|
||||||
* functions. The application should free any memory associated with this
|
* functions. The application should free any memory associated with this
|
||||||
* pointer before png_write_destroy and png_read_destroy are called.
|
* pointer before png_write_destroy and png_read_destroy are called.
|
||||||
*/
|
*/
|
||||||
png_voidp
|
png_voidp PNGAPI
|
||||||
png_get_mem_ptr(png_structp png_ptr)
|
png_get_mem_ptr(png_structp png_ptr)
|
||||||
{
|
{
|
||||||
|
if (png_ptr == NULL)
|
||||||
|
return (NULL);
|
||||||
return ((png_voidp)png_ptr->mem_ptr);
|
return ((png_voidp)png_ptr->mem_ptr);
|
||||||
}
|
}
|
||||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||||
|
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||||
|
|||||||
BIN
pngnow.png
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.0 KiB |