Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
074af5e9ca | ||
|
|
5379b24536 | ||
|
|
6d8f3b080a | ||
|
|
860ab2b1c0 | ||
|
|
ad5dd1f0fb | ||
|
|
33b25bf1a8 | ||
|
|
18c415f5b5 | ||
|
|
310faa8ec9 | ||
|
|
ab1e583c44 | ||
|
|
bcfd15d9f2 | ||
|
|
54a066a8a9 | ||
|
|
352ca6bee0 | ||
|
|
f8b008cd43 | ||
|
|
4393a9ad6b | ||
|
|
87544ac62b | ||
|
|
c944229859 | ||
|
|
5c6aeb25c1 |
101
ANNOUNCE
@@ -1,67 +1,48 @@
|
||||
|
||||
Libpng 1.0.2 - June 14, 1998
|
||||
Libpng 1.0.5d - November 29, 1999
|
||||
|
||||
This is a public release of libpng, intended for use in production codes.
|
||||
This is not intended to be a public release. It will be replaced
|
||||
within a few weeks by a public version or by another test version.
|
||||
|
||||
Changes since the previous public release (1.0.1):
|
||||
Changes since the last public release (1.0.5):
|
||||
|
||||
Optimized Paeth calculations by replacing abs() function calls with intrinsics
|
||||
plus other loop optimizations. Improves avg decoding speed by about 20%.
|
||||
Commented out i386istic "align" compiler flags in makefile.lnx.
|
||||
Reduced the default warning level in some makefiles, to make them consistent.
|
||||
Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
|
||||
Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
|
||||
Added grayscale and 16-bit capability to png_do_read_filler().
|
||||
Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
|
||||
too large when writing an image with bit_depth < 8 (Bob Dellaca).
|
||||
Corrected some bugs in the experimental weighted filtering heuristics.
|
||||
Moved a misplaced pngrutil code block that truncates tRNS if it has more
|
||||
than num_palette entries -- test was done before num_palette was defined.
|
||||
Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
|
||||
Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen).
|
||||
Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
|
||||
Relocated the png_composite macros from pngrtran.c to png.h (Greg).
|
||||
Added makefile.sco (contributed by Mike Hopkirk).
|
||||
Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
|
||||
Added warnings when people try to use transforms they've defined out.
|
||||
Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran.
|
||||
Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)
|
||||
Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
|
||||
Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
|
||||
out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
|
||||
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
|
||||
for consistency, in pngconf.h
|
||||
Added individual "ifndef PNG_NO_CAPABILITY" for the capabilities in pngconf.h
|
||||
to make it easier to remove unwanted capabilities via the compile line
|
||||
Made some corrections to grammar (which, it's) in documentation (Greg).
|
||||
Corrected example.c, use of row_pointers in png_write_image().
|
||||
Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
|
||||
More corrections to example.c, use of row_pointers in png_write_image()
|
||||
and png_read_rows().
|
||||
Added pngdll.mak and pngdef.pas to scripts directory, contributed by
|
||||
Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
|
||||
Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
|
||||
Changed several loops from count-down to count-up, for consistency.
|
||||
Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
|
||||
added warnings when people try to set png_read_fn and png_write_fn in
|
||||
the same structure.
|
||||
Added a test such that png_do_gamma will be done when num_trans==0
|
||||
for truecolor images that have defined a background. This corrects an
|
||||
error that was introduced in libpng-0.90 that can cause gamma processing
|
||||
to be skipped.
|
||||
Added tests in png.h to include "trans" and "trans_values" in structures
|
||||
when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined.
|
||||
Add png_free(png_ptr->time_buffer) in png_destroy_read_struct()
|
||||
Moved png_convert_to_rfc_1123() from pngwrite.c to png.c
|
||||
Added capability for user-provided malloc_fn() and free_fn() functions,
|
||||
and revised pngtest.c to demonstrate their use, replacing the
|
||||
PNGTEST_DEBUG_MEM feature.
|
||||
Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner).
|
||||
Fixed two bugs in makefile.bor
|
||||
version libpng-1.0.5a October 23, 1999
|
||||
Added contrib/pngsuite and contrib/pngminus (Willem van Schaik)
|
||||
Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans)
|
||||
Further optimization and bugfix of pngvcrd.c
|
||||
Revised pngset.c so that it does not allocate or free memory in the user's
|
||||
text_ptr structure. Instead, it makes its own copy.
|
||||
Created separate write_end_info_struct in pngtest.c for a more severe test.
|
||||
Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak.
|
||||
version libpng-1.0.5b November 23, 1999
|
||||
Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and
|
||||
PNG_FLAG_WROTE_tIME from flags to mode.
|
||||
Added png_write_info_before_PLTE() function.
|
||||
Fixed some typecasting in contrib/gregbook/*.c
|
||||
Updated scripts/makevms.com and added makevms.com to contrib/gregbook
|
||||
and contrib/pngminus (Martin Zinser)
|
||||
version libpng-1.0.5c November 26, 1999
|
||||
Moved png_get_header_version from png.h to png.c, to accomodate ansi2knr.
|
||||
Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to
|
||||
accomodate making DLL's: Moved usr_png_ver from global variable to function
|
||||
png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and
|
||||
eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays
|
||||
into pngtypes.h. Eliminated use of global png_pass arrays. Declared the
|
||||
png_CHNK and png_pass arrays to be "const". Made the global arrays
|
||||
available to applications (although none are used in libpng itself) when
|
||||
PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined.
|
||||
Removed some extraneous "-I" from contrib/pngminus/makefile.std
|
||||
Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2.
|
||||
Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3
|
||||
version 1.0.5d [November 29, 1999]
|
||||
Add type cast (png_const_charp) two places in png.c
|
||||
Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays.
|
||||
Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available
|
||||
to applications a macro "PNG_USE_LOCAL_ARRAYS".
|
||||
#ifdef out all the new declarations when PNG_USE_GLOBAL_ARRAYS is defined.
|
||||
Added PNG_EXPORT_VAR macro to accommodate making DLL's.
|
||||
|
||||
Send comments/corrections/commendations to
|
||||
png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu
|
||||
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
libpng maintainer
|
||||
PNG Development Group
|
||||
Glenn R-P
|
||||
|
||||
168
CHANGES
@@ -89,7 +89,7 @@ version 0.89 [July, 1996]
|
||||
so that people are aware that they need to change their code
|
||||
changed filter selection API to allow selection of multiple filters
|
||||
since it didn't work in previous versions of libpng anyways
|
||||
optimized filter selection code
|
||||
optimized filter selection code
|
||||
fixed png_set_background() to allow using an arbitrary RGB color for
|
||||
paletted images
|
||||
fixed gamma and background correction for paletted images, so
|
||||
@@ -256,7 +256,7 @@ version 0.99g [March 6, 1998, morning]
|
||||
Minor changes to pngtest.c to suppress compiler warnings.
|
||||
Removed "beta" language from documentation.
|
||||
version 0.99h [March 6, 1998, evening]
|
||||
Minor changes to previous minor changes to pngtest.c
|
||||
Minor changes to previous minor changes to pngtest.c
|
||||
Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED
|
||||
and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro
|
||||
version 1.00 [March 7, 1998]
|
||||
@@ -334,7 +334,7 @@ version 1.0.1d [May 24, 1998]
|
||||
Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
|
||||
Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
|
||||
Changed several loops from count-down to count-up, for consistency.
|
||||
version 1.0.2 [June 14, 1998]
|
||||
version 1.0.1e [June 6, 1998]
|
||||
Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
|
||||
added warnings when people try to set png_read_fn and png_write_fn in
|
||||
the same structure.
|
||||
@@ -350,4 +350,164 @@ version 1.0.2 [June 14, 1998]
|
||||
and revised pngtest.c to demonstrate their use, replacing the
|
||||
PNGTEST_DEBUG_MEM feature.
|
||||
Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner).
|
||||
Fixed two bugs in makefile.bor
|
||||
version 1.0.2 [June 14, 1998]
|
||||
Fixed two bugs in makefile.bor .
|
||||
version 1.0.2a [December 30, 1998]
|
||||
Replaced and extended code that was removed from png_set_filler() in 1.0.1a.
|
||||
Fixed a bug in png_do_filler() that made it fail to write filler bytes in
|
||||
the left-most pixel of each row (Kevin Bracey).
|
||||
Changed "static pngcharp tIME_string" to "static char tIME_string[30]"
|
||||
in pngtest.c (Duncan Simpson).
|
||||
Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk
|
||||
even when no tIME chunk was present in the source file.
|
||||
Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit.
|
||||
Fixed a problem in png_read_push_finish_row(), which would not skip some
|
||||
passes that it should skip, for images that are less than 3 pixels high.
|
||||
Interchanged the order of calls to png_do_swap() and png_do_shift()
|
||||
in pngwtran.c (John Cromer).
|
||||
Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h .
|
||||
Changed "bad adaptive filter type" from error to warning in pngrutil.c .
|
||||
Fixed a documentation error about default filtering with 8-bit indexed-color.
|
||||
Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO
|
||||
(L. Peter Deutsch).
|
||||
Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions.
|
||||
Added png_get_copyright() and png_get_header_version() functions.
|
||||
Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c
|
||||
Added information about debugging in libpng.txt and libpng.3 .
|
||||
Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and makefile.sco.
|
||||
Removed lines after Dynamic Dependencies" in makefile.aco .
|
||||
Revised makefile.dec to make a shared library (Jeremie Petit).
|
||||
Removed trailing blanks from all files.
|
||||
version 1.0.2a [January 6, 1999]
|
||||
Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h
|
||||
Added "if" tests to silence complaints about unused png_ptr in png.h and png.c
|
||||
Changed "check_if_png" function in example.c to return true (nonzero) if PNG.
|
||||
Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig()
|
||||
which is obsolete.
|
||||
version 1.0.3 [January 14, 1999]
|
||||
Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice)
|
||||
Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO.
|
||||
version 1.0.3a [August 12, 1999]
|
||||
Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
|
||||
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
|
||||
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)
|
||||
Added a copy of pngnow.png to the distribution.
|
||||
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.
|
||||
Changed type of png_user_transform_depth|channels from int to png_byte.
|
||||
version 1.0.4d [October 6, 1999]
|
||||
Changed 0.45 to 0.45455 in png_set_sRGB()
|
||||
Removed unused PLTE entries from pngnow.png
|
||||
Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly.
|
||||
version 1.0.4e [October 10, 1999]
|
||||
Fixed sign error in pngvcrd.c (Greg Roelofs)
|
||||
Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)
|
||||
version 1.0.4f [October 15, 1999]
|
||||
Surrounded example.c code with #if 0 .. #endif to prevent people from
|
||||
inadvertently trying to compile it.
|
||||
Changed png_get_header_version() from a function to a macro in png.h
|
||||
Added type casting mostly in pngrtran.c and pngwtran.c
|
||||
Removed some pointless "ptr = NULL" in pngmem.c
|
||||
Added a "contrib" directory containing the source code from Greg's book.
|
||||
version 1.0.5 [October 15, 1999]
|
||||
Minor editing of the INSTALL and README files.
|
||||
version 1.0.5a [October 23, 1999]
|
||||
Added contrib/pngsuite and contrib/pngminus (Willem van Schaik)
|
||||
Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans)
|
||||
Further optimization and bugfix of pngvcrd.c
|
||||
Revised pngset.c so that it does not allocate or free memory in the user's
|
||||
text_ptr structure. Instead, it makes its own copy.
|
||||
Created separate write_end_info_struct in pngtest.c for a more severe test.
|
||||
Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak.
|
||||
version 1.0.5b [November 23, 1999]
|
||||
Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and
|
||||
PNG_FLAG_WROTE_tIME from flags to mode.
|
||||
Added png_write_info_before_PLTE() function.
|
||||
Fixed some typecasting in contrib/gregbook/*.c
|
||||
Updated scripts/makevms.com and added makevms.com to contrib/gregbook
|
||||
and contrib/pngminus (Martin Zinser)
|
||||
version 1.0.5c [November 26, 1999]
|
||||
Moved png_get_header_version from png.h to png.c, to accomodate ansi2knr.
|
||||
Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to
|
||||
accomodate making DLL's: Moved usr_png_ver from global variable to function
|
||||
png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and
|
||||
eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays
|
||||
into pngtypes.h. Eliminated use of global png_pass arrays. Declared the
|
||||
png_CHNK and png_pass arrays to be "const". Made the global arrays
|
||||
available to applications (although none are used in libpng itself) when
|
||||
PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined.
|
||||
Removed some extraneous "-I" from contrib/pngminus/makefile.std
|
||||
Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2.
|
||||
Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3
|
||||
version 1.0.5d [November 29, 1999]
|
||||
Add type cast (png_const_charp) two places in png.c
|
||||
Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays.
|
||||
Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available
|
||||
to applications a macro "PNG_USE_LOCAL_ARRAYS".
|
||||
#ifdef out all the new declarations when PNG_USE_GLOBAL_ARRAYS is defined.
|
||||
Added PNG_EXPORT_VAR macro to accommodate making DLL's.
|
||||
|
||||
84
INSTALL
@@ -1,17 +1,17 @@
|
||||
|
||||
Installing libpng version 1.0.2 - June 14, 1998
|
||||
Installing libpng version 1.0.5d - November 29, 1999
|
||||
|
||||
Before installing libpng, you must first install zlib. zlib
|
||||
can usually be found wherever you got libpng. zlib can be
|
||||
placed in another directory, at the same level as libpng.
|
||||
Note that your system might already have a preinstalled
|
||||
zlib, but you will still need to have access to the
|
||||
zlib, but 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
|
||||
might be called "libpng-1.0.2" or "lpng102" and "zlib-1.1.2"
|
||||
or "zlib112") so that you have directories called "zlib" and "libpng".
|
||||
might be called "libpng-1.0.5d" or "lpng103" and "zlib-1.1.3"
|
||||
or "zlib113") so that you have directories called "zlib" and "libpng".
|
||||
|
||||
Your directory structure should look like this:
|
||||
|
||||
@@ -21,6 +21,10 @@ Your directory structure should look like this:
|
||||
README
|
||||
*.h
|
||||
*.c
|
||||
contrib
|
||||
gregbook
|
||||
pngminus
|
||||
pngsuite
|
||||
scripts
|
||||
makefile.*
|
||||
pngtest.png
|
||||
@@ -38,37 +42,46 @@ appropriate makefile.sys in the scripts directory.
|
||||
The files that are presently available in the scripts directory
|
||||
include
|
||||
|
||||
descrip.mms => VMS makefile for MMS or MMK
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with ansi2knr
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.sun => Sun makefile
|
||||
makefile.s2x => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0)
|
||||
makefile.lnx => Linux/ELF makefile (gcc, creates libpng.so.2.1.0)
|
||||
makefile.mip => MIPS makefile
|
||||
makefile.aco => Acorn makefile
|
||||
makefile.ama => Amiga makefile
|
||||
smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
|
||||
(Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
|
||||
makefile.atr => Atari makefile
|
||||
makefile.bor => Borland makefile
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.w32 => makefile for Microsoft Visual C++ 4.0 and later
|
||||
makefile.tc3 => 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.wat => 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
|
||||
descrip.mms => VMS makefile for MMS or MMK
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
||||
ansi2knr (Requires ansi2knr.c from
|
||||
ftp://ftp.cs.wisc.edu/ghost)
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.sunos => Sun makefile
|
||||
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.5d)
|
||||
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.5d)
|
||||
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
|
||||
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
|
||||
|
||||
Read the makefile to see if you need to change any source or
|
||||
@@ -80,11 +93,16 @@ changes.
|
||||
Then just run "make test" which will create the libpng library in
|
||||
this directory and run a quick test that reads 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 *.png" in the "contrib/pngsuite" directory and compare
|
||||
your output with the result shown in contrib/pngsuite/README.
|
||||
|
||||
Most of the makefiles will allow you to run "make install" 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).
|
||||
|
||||
Further information can be found in the README and libpng.txt
|
||||
files, in the individual makefiles, and in png.h, and the manual
|
||||
pages libpng.3 and png.5.
|
||||
files, in the individual makefiles, in png.h, and the manual pages
|
||||
libpng.3 and png.5.
|
||||
|
||||
48
KNOWNBUG
@@ -1,5 +1,5 @@
|
||||
|
||||
Known bugs and suggested enhancements in libpng-1.0.2
|
||||
Known bugs and suggested enhancements in libpng-1.0.5
|
||||
|
||||
|
||||
1. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
|
||||
@@ -7,13 +7,53 @@ Known bugs and suggested enhancements in libpng-1.0.2
|
||||
Loops need to be optimized everywhere
|
||||
|
||||
Make them count down instead of up -- Kevin Bracey
|
||||
|
||||
|
||||
Optimizing compilers don't need this, and making
|
||||
the change would be error prone -- Tom Lane, Glenn R-P
|
||||
|
||||
Question whether i-- or --i is better.
|
||||
|
||||
STATUS: Under investigation, postponed until after
|
||||
libpng-1.0.2. About 160 loops turned around
|
||||
in libpng-1.0.2a, for testing.
|
||||
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.
|
||||
|
||||
4. October 1999 -- BUG
|
||||
|
||||
pngvcrd.c is failing for interlaced PNGs that have empty passes.
|
||||
|
||||
STATUS: A check for "width != 0" is required in several places.
|
||||
Fixed in libpng-1.0.5a/1.0.6
|
||||
|
||||
5. October 1999 -- BUG
|
||||
|
||||
Under MSVC++6.0 with debugging enabled, heap corruption was detected
|
||||
while destroying the png_write_ptr.
|
||||
|
||||
STATUS: This was fixed by modifying png_set_text (in pngset.c) to
|
||||
refrain from writing into the user's text_ptr. With this fix, however,
|
||||
pngwrite.c, while destroying the info_ptr, was failing to free the
|
||||
text->key strings. Fix for the latter problem is to duplicate code
|
||||
from png.c.
|
||||
|
||||
Fixed in libpng-1.0.5a/1.0.6
|
||||
|
||||
70
LICENSE
Normal file
@@ -0,0 +1,70 @@
|
||||
COPYRIGHT NOTICE:
|
||||
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
(libpng versions 0.5, May 1995, through 0.89c, May 1996)
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
(libpng versions 0.90, December 1996, through 0.96, May 1997)
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
(libpng versions 0.97, January 1998, through 1.0.5d, November 29, 1999)
|
||||
|
||||
For the purposes of this copyright and license, "Contributing Authors"
|
||||
is defined as the following set of individuals:
|
||||
|
||||
John Bowler
|
||||
Kevin Bracey
|
||||
Sam Bushell
|
||||
Andreas Dilger
|
||||
Magnus Holmgren
|
||||
Tom Lane
|
||||
Dave Martindale
|
||||
Glenn Randers-Pehrson
|
||||
Greg Roelofs
|
||||
Guy Eric Schalnat
|
||||
Paul Schmidt
|
||||
Tom Tanner
|
||||
Willem van Schaik
|
||||
Tim Wegner
|
||||
|
||||
The PNG Reference Library is supplied "AS IS". The Contributing Authors
|
||||
and Group 42, Inc. disclaim all warranties, expressed or implied,
|
||||
including, without limitation, the warranties of merchantability and of
|
||||
fitness for any purpose. The Contributing Authors and Group 42, Inc.
|
||||
assume no liability for direct, indirect, incidental, special, exemplary,
|
||||
or consequential damages, which may result from the use of the PNG
|
||||
Reference Library, even if advised of the possibility of such damage.
|
||||
|
||||
Permission is hereby granted to use, copy, modify, and distribute this
|
||||
source code, or portions hereof, for any purpose, without fee, subject
|
||||
to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be
|
||||
misrepresented.
|
||||
|
||||
2. Altered versions must be plainly marked as such
|
||||
and must not be misrepresented as being the
|
||||
original source.
|
||||
|
||||
3. This Copyright notice may not be removed or
|
||||
altered from any source or altered source
|
||||
distribution.
|
||||
|
||||
The Contributing Authors and Group 42, Inc. specifically permit, without
|
||||
fee, and encourage the use of this source code as a component to
|
||||
supporting the PNG file format in commercial products. If you use this
|
||||
source code in a product, acknowledgment is not required but would be
|
||||
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
|
||||
file "pngnow.png".
|
||||
|
||||
Libpng is OSI Certified Open Source Software. OSI Certified is a
|
||||
certification mark of the Open Source Initiative.
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
randeg@alum.rpi.edu
|
||||
November 29, 1999
|
||||
102
README
@@ -1,14 +1,15 @@
|
||||
README for libpng 1.0.2 - June 14, 1998 (shared library 2.1)
|
||||
README for libpng 1.0.5d - November 29, 1999 (shared library 2.1)
|
||||
See the note about version numbers near the top of png.h
|
||||
|
||||
See INSTALL for instructions on how to install libpng.
|
||||
|
||||
This is 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 for about two and a half years. However, it's
|
||||
finally gotten to the stage where there haven't been significant
|
||||
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
|
||||
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
|
||||
@@ -28,8 +29,8 @@ directly, to avoid such problems in the future.
|
||||
It is important to note that the APIs do not make current programs
|
||||
that access the info struct directly incompatible with the new
|
||||
library. However, it is strongly suggested that new programs use
|
||||
the new APIs (as shown in example.c), and older programs be converted
|
||||
to the new format, to facilitate upgrades in the future.
|
||||
the new APIs (as shown in example.c and pngtest.c), and older programs
|
||||
be converted to the new format, to facilitate upgrades in the future.
|
||||
****
|
||||
|
||||
Additions since 0.90 include the ability to compile libpng as a
|
||||
@@ -49,8 +50,9 @@ to set different actions based on whether the CRC error occurred in a
|
||||
critical or an ancillary chunk.
|
||||
|
||||
The changes made to the library, and bugs fixed are based on discussions
|
||||
on the PNG implementation mailing list <png-implement@dworking.wustl.edu>
|
||||
and not on material submitted to Guy.
|
||||
on the PNG implementation mailing list <png-implement@ccrc.wustl.edu>
|
||||
and not on material submitted 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
|
||||
examples of libpng in a program, see example.c and pngtest.c. For usage
|
||||
@@ -98,8 +100,8 @@ fix. Please mention "libpng" somewhere in the subject line. Thanks.
|
||||
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.
|
||||
|
||||
randeg@alumni.rpi.edu
|
||||
png-implement@dworkin.wustl.edu
|
||||
randeg@alum.rpi.edu
|
||||
png-implement@ccrc.wustl.edu
|
||||
|
||||
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
|
||||
@@ -108,7 +110,7 @@ addressed to the png-implement list, however.
|
||||
Please do not send general questions about PNG. Send them to
|
||||
the address in the specification (png-group@w3.org). At the same
|
||||
time, please do not send libpng questions to that address, send them to me
|
||||
or to png-implement@dworkin.wustl.edu. I'll
|
||||
or to png-implement@ccrc.wustl.edu. I'll
|
||||
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
|
||||
to me. Send me any questions that start with "I was using libpng,
|
||||
@@ -126,8 +128,6 @@ Files in this distribution:
|
||||
CHANGES => Description of changes between libpng versions
|
||||
README => This file
|
||||
TODO => Things not implemented in the current library
|
||||
ansi2knr.1 => Manual page for ansi2knr
|
||||
ansi2knr.c => Converts files to K&R style function declarations
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
descrip.mms => VMS project file
|
||||
example.c => Example code for using libpng functions
|
||||
@@ -154,38 +154,56 @@ Files in this distribution:
|
||||
pngwrite.c => High-level write functions
|
||||
pngwtran.c => Write data transformations
|
||||
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
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
scripts => Directory containing scripts for building libpng:
|
||||
descrip.mms => VMS makefile for MMS or MMK
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with ansi2knr
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.sun => Sun makefile
|
||||
makefile.s2x => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0)
|
||||
makefile.lnx => Linux/ELF makefile (gcc, creates libpng.so.2.1.0)
|
||||
makefile.mip => MIPS makefile
|
||||
makefile.aco => Acorn makefile
|
||||
makefile.ama => Amiga makefile
|
||||
smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
|
||||
(Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
|
||||
makefile.atr => Atari makefile
|
||||
makefile.bor => Borland makefile
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.w32 => makefile for Microsoft Visual C++ 4.0 and later
|
||||
makefile.tc3 => Turbo C 3.0 makefile
|
||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||
makefile.wat => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||
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
|
||||
descrip.mms => VMS makefile for MMS or MMK
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
||||
ansi2knr (Requires ansi2knr.c from
|
||||
ftp://ftp.cs.wisc.edu/ghost)
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.sunos => Sun makefile
|
||||
makefile.solaris => Solaris 2.X makefile
|
||||
(gcc, creates libpng.so.2.1.0.5d)
|
||||
makefile.linux => Linux/ELF makefile
|
||||
(gcc, creates libpng.so.2.1.0.5d)
|
||||
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
|
||||
|
||||
Good luck, and happy coding.
|
||||
|
||||
-Glenn Randers-Pehrson
|
||||
Internet: randeg@alumni.rpi.edu
|
||||
Internet: randeg@alum.rpi.edu
|
||||
Web: http://www.rpi.edu/~randeg/index.html
|
||||
|
||||
-Andreas Eric Dilger
|
||||
|
||||
45
TODO
@@ -1,23 +1,24 @@
|
||||
TODO - list of things to do for libpng
|
||||
TODO - list of things to do for libpng:
|
||||
|
||||
fix problem with C++ and EXTERN "C"
|
||||
add "grayscale->palette" transformation and "palette->grayscale" detection
|
||||
color to gray transformation
|
||||
improved dithering
|
||||
multi-lingual error and warning message support
|
||||
sPLT chunk handling
|
||||
cHRM transformation
|
||||
complete sRGB transformation (presently it simply uses gamma=0.45)
|
||||
man pages for function calls
|
||||
high-level API for reading images
|
||||
final bug fixes
|
||||
better documentation
|
||||
better filter selection
|
||||
(counting huffman bits/precompression? filter inertia? filter costs?)
|
||||
optional palette creation
|
||||
histogram creation
|
||||
support for application-defined chunk handlers
|
||||
keep up with public chunks
|
||||
better C++ wrapper/full C++ implementation?
|
||||
text conversion between different code pages (Latin-1 -> Mac and DOS)
|
||||
improve API by hiding the info_ptr
|
||||
Final bug fixes.
|
||||
Fix problem with C++ and EXTERN "C".
|
||||
Better C++ wrapper/full C++ implementation?
|
||||
Keep up with public chunks.
|
||||
sPLT chunk handling.
|
||||
cHRM transformation.
|
||||
Support for application-defined chunk handlers.
|
||||
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.
|
||||
Improved dithering.
|
||||
Multi-lingual error and warning message support.
|
||||
Complete sRGB transformation (presently it simply uses gamma=0.45455).
|
||||
Man pages for function calls.
|
||||
Better documentation.
|
||||
Better filter selection
|
||||
(counting huffman bits/precompression? filter inertia? filter costs?).
|
||||
Optional palette (sPLT) creation.
|
||||
Histogram creation.
|
||||
Text conversion between different code pages (Latin-1 -> Mac and DOS).
|
||||
Improve API by hiding the info_ptr.
|
||||
Make a no-floating-point version.
|
||||
|
||||
55
Y2KINFO
Normal file
@@ -0,0 +1,55 @@
|
||||
Y2K compliance in libpng:
|
||||
=========================
|
||||
|
||||
November 29, 1999
|
||||
|
||||
Since the PNG Development group is an ad-hoc body, we can't make
|
||||
an official declaration.
|
||||
|
||||
This is your unofficial assurance that libpng from version 0.71 and
|
||||
upward through 1.0.5d are Y2K compliant. It is my belief that earlier
|
||||
versions were also Y2K compliant.
|
||||
|
||||
Libpng only has three year fields. One is a 2-byte unsigned integer
|
||||
that will hold years up to 65535. The other two hold the date in text
|
||||
format, and will hold years up to 9999.
|
||||
|
||||
The integer is
|
||||
"png_uint_16 year" in png_time_struct.
|
||||
|
||||
The strings are
|
||||
"png_charp time_buffer" in png_struct and
|
||||
"near_time_buffer", which is a local character string in png.c.
|
||||
|
||||
There are seven time-related functions:
|
||||
|
||||
png_convert_to_rfc_1123() in png.c
|
||||
(formerly png_convert_to_rfc_1152() in error)
|
||||
png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
|
||||
png_convert_from_time_t() in pngwrite.c
|
||||
png_get_tIME() in pngget.c
|
||||
png_handle_tIME() in pngrutil.c, called in pngread.c
|
||||
png_set_tIME() in pngset.c
|
||||
png_write_tIME() in pngwutil.c, called in pngwrite.c
|
||||
|
||||
All appear to handle dates properly in a Y2K environment. The
|
||||
png_convert_from_time_t() function calls gmtime() to convert from system
|
||||
clock time, which returns (year - 1900), which we properly convert to
|
||||
the full 4-digit year. There is a possibility that applications using
|
||||
libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
|
||||
function, or that they are incorrectly passing only a 2-digit year
|
||||
instead of "year - 1900" into the png_convert_from_struct_tm() function,
|
||||
but this is not under our control. The libpng documentation has always
|
||||
stated that it works with 4-digit years, and the APIs have been
|
||||
documented as such.
|
||||
|
||||
The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
|
||||
integer to hold the year, and can hold years as large as 65535.
|
||||
|
||||
zlib, upon which libpng depends, is also Y2K compliant. It contains
|
||||
no date-related code.
|
||||
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
libpng maintainer
|
||||
PNG Development Group
|
||||
36
ansi2knr.1
@@ -1,36 +0,0 @@
|
||||
.TH ANSI2KNR 1 "19 Jan 1996"
|
||||
.SH NAME
|
||||
ansi2knr \- convert ANSI C to Kernighan & Ritchie C
|
||||
.SH SYNOPSIS
|
||||
.I ansi2knr
|
||||
[--varargs] input_file [output_file]
|
||||
.SH DESCRIPTION
|
||||
If no output_file is supplied, output goes to stdout.
|
||||
.br
|
||||
There are no error messages.
|
||||
.sp
|
||||
.I ansi2knr
|
||||
recognizes function definitions by seeing a non-keyword identifier at the left
|
||||
margin, followed by a left parenthesis, with a right parenthesis as the last
|
||||
character on the line, and with a left brace as the first token on the
|
||||
following line (ignoring possible intervening comments). It will recognize a
|
||||
multi-line header provided that no intervening line ends with a left or right
|
||||
brace or a semicolon. These algorithms ignore whitespace and comments, except
|
||||
that the function name must be the first thing on the line.
|
||||
.sp
|
||||
The following constructs will confuse it:
|
||||
.br
|
||||
- Any other construct that starts at the left margin and follows the
|
||||
above syntax (such as a macro or function call).
|
||||
.br
|
||||
- Some macros that tinker with the syntax of the function header.
|
||||
.sp
|
||||
The --varargs switch is obsolete, and is recognized only for
|
||||
backwards compatibility. The present version of
|
||||
.I ansi2knr
|
||||
will always attempt to convert a ... argument to va_alist and va_dcl.
|
||||
.SH AUTHOR
|
||||
L. Peter Deutsch <ghost@aladdin.com> wrote the original ansi2knr and
|
||||
continues to maintain the current version; most of the code in the current
|
||||
version is his work. ansi2knr also includes contributions by Francois
|
||||
Pinard <pinard@iro.umontreal.ca> and Jim Avera <jima@netcom.com>.
|
||||
695
ansi2knr.c
@@ -1,695 +0,0 @@
|
||||
/* ansi2knr.c */
|
||||
|
||||
/* Convert ANSI C function definitions to K&R ("traditional C") syntax
|
||||
Copyright (C) 1989 Aladdin Enterprises. All rights reserved.
|
||||
Copyright (C) 1988 Richard M. Stallman
|
||||
|
||||
ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY. No author or distributor accepts responsibility to anyone for the
|
||||
consequences of using it or for whether it serves any particular purpose or
|
||||
works at all, unless he says so in writing. Refer to the GNU General Public
|
||||
License (the "GPL") for full details.
|
||||
|
||||
Everyone is granted permission to copy, modify and redistribute ansi2knr,
|
||||
but only under the conditions described in the GPL. A copy of this license
|
||||
is supposed to have been given to you along with ansi2knr so you can know
|
||||
your rights and responsibilities. It should be in a file named COPYLEFT.
|
||||
[In the LIBPNG distribution, the GPL appears below, not in a separate file.]
|
||||
Among other things, the copyright notice and this notice must be preserved
|
||||
on all copies.
|
||||
|
||||
We explicitly state here what we believe is already implied by the GPL: if
|
||||
the ansi2knr program is distributed as a separate source file and a
|
||||
separate executable file which are aggregated on a storage medium together
|
||||
with another program, this in itself does not bring the other program under
|
||||
the GPL, nor does the mere fact that such a program or the procedures for
|
||||
constructing it invoke the ansi2knr executable bring any other part of the
|
||||
program under the GPL.
|
||||
*/
|
||||
|
||||
/*
|
||||
---------- Here is the GNU GPL file COPYLEFT, referred to above ----------
|
||||
----- These terms do NOT apply to the LIBPNG software itself; see README ------
|
||||
|
||||
GHOSTSCRIPT GENERAL PUBLIC LICENSE
|
||||
(Clarified 11 Feb 1988)
|
||||
|
||||
Copyright (C) 1988 Richard M. Stallman
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license, but changing it is not allowed. You can also use this wording
|
||||
to make the terms for other programs.
|
||||
|
||||
The license agreements of most software companies keep you at the
|
||||
mercy of those companies. By contrast, our general public license is
|
||||
intended to give everyone the right to share Ghostscript. To make sure
|
||||
that you get the rights we want you to have, we need to make
|
||||
restrictions that forbid anyone to deny you these rights or to ask you
|
||||
to surrender the rights. Hence this license agreement.
|
||||
|
||||
Specifically, we want to make sure that you have the right to give
|
||||
away copies of Ghostscript, that you receive source code or else can get
|
||||
it if you want it, that you can change Ghostscript or use pieces of it
|
||||
in new free programs, and that you know you can do these things.
|
||||
|
||||
To make sure that everyone has such rights, we have to forbid you to
|
||||
deprive anyone else of these rights. For example, if you distribute
|
||||
copies of Ghostscript, 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 tell them their rights.
|
||||
|
||||
Also, for our own protection, we must make certain that everyone finds
|
||||
out that there is no warranty for Ghostscript. If Ghostscript is
|
||||
modified by someone else and passed on, we want its recipients to know
|
||||
that what they have is not what we distributed, so that any problems
|
||||
introduced by others will not reflect on our reputation.
|
||||
|
||||
Therefore we (Richard M. Stallman and the Free Software Foundation,
|
||||
Inc.) make the following terms which say what you must do to be allowed
|
||||
to distribute or change Ghostscript.
|
||||
|
||||
|
||||
COPYING POLICIES
|
||||
|
||||
1. You may copy and distribute verbatim copies of Ghostscript source
|
||||
code as you receive it, in any medium, provided that you conspicuously
|
||||
and appropriately publish on each copy a valid copyright and license
|
||||
notice "Copyright (C) 1989 Aladdin Enterprises. All rights reserved.
|
||||
Distributed by Free Software Foundation, Inc." (or with whatever year is
|
||||
appropriate); keep intact the notices on all files that refer to this
|
||||
License Agreement and to the absence of any warranty; and give any other
|
||||
recipients of the Ghostscript program a copy of this License Agreement
|
||||
along with the program. You may charge a distribution fee for the
|
||||
physical act of transferring a copy.
|
||||
|
||||
2. You may modify your copy or copies of Ghostscript or any portion of
|
||||
it, and copy and distribute such modifications under the terms of
|
||||
Paragraph 1 above, provided that you also do the following:
|
||||
|
||||
a) cause the modified files to carry prominent notices stating
|
||||
that you changed the files and the date of any change; and
|
||||
|
||||
b) cause the whole of any work that you distribute or publish,
|
||||
that in whole or in part contains or is a derivative of Ghostscript
|
||||
or any part thereof, to be licensed at no charge to all third
|
||||
parties on terms identical to those contained in this License
|
||||
Agreement (except that you may choose to grant more extensive
|
||||
warranty protection to some or all third parties, at your option).
|
||||
|
||||
c) You may charge a distribution fee for the physical act of
|
||||
transferring a copy, and you may at your option offer warranty
|
||||
protection in exchange for a fee.
|
||||
|
||||
Mere aggregation of another unrelated program with this program (or its
|
||||
derivative) on a volume of a storage or distribution medium does not bring
|
||||
the other program under the scope of these terms.
|
||||
|
||||
3. You may copy and distribute Ghostscript (or a portion or derivative
|
||||
of it, under Paragraph 2) in object code or executable form under the
|
||||
terms of Paragraphs 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
|
||||
Paragraphs 1 and 2 above; or,
|
||||
|
||||
b) accompany it with a written offer, valid for at least three
|
||||
years, to give any third party free (except for a nominal
|
||||
shipping charge) a complete machine-readable copy of the
|
||||
corresponding source code, to be distributed under the terms of
|
||||
Paragraphs 1 and 2 above; or,
|
||||
|
||||
c) accompany it with the information you received as to where the
|
||||
corresponding source code may be obtained. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form alone.)
|
||||
|
||||
For an executable file, complete source code means all the source code for
|
||||
all modules it contains; but, as a special exception, it need not include
|
||||
source code for modules which are standard libraries that accompany the
|
||||
operating system on which the executable file runs.
|
||||
|
||||
4. You may not copy, sublicense, distribute or transfer Ghostscript
|
||||
except as expressly provided under this License Agreement. Any attempt
|
||||
otherwise to copy, sublicense, distribute or transfer Ghostscript is
|
||||
void and your rights to use the program under this License agreement
|
||||
shall be automatically terminated. However, parties who have received
|
||||
computer software programs from you with this License Agreement will not
|
||||
have their licenses terminated so long as such parties remain in full
|
||||
compliance.
|
||||
|
||||
5. If you wish to incorporate parts of Ghostscript into other free
|
||||
programs whose distribution conditions are different, write to the Free
|
||||
Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not
|
||||
yet worked out a simple rule that can be stated here, but we will often
|
||||
permit this. We 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.
|
||||
|
||||
Your comments and suggestions about our licensing policies and our
|
||||
software are welcome! Please contact the Free Software Foundation,
|
||||
Inc., 675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
BECAUSE GHOSTSCRIPT IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
|
||||
NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
|
||||
WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD
|
||||
M. STALLMAN, ALADDIN ENTERPRISES, L. PETER DEUTSCH, AND/OR OTHER PARTIES
|
||||
PROVIDE GHOSTSCRIPT "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 GHOSTSCRIPT IS WITH
|
||||
YOU. SHOULD GHOSTSCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
|
||||
NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
|
||||
STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., L. PETER DEUTSCH, ALADDIN
|
||||
ENTERPRISES, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE
|
||||
GHOSTSCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING
|
||||
ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
|
||||
(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
|
||||
INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE
|
||||
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GHOSTSCRIPT, EVEN IF YOU
|
||||
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
|
||||
BY ANY OTHER PARTY.
|
||||
|
||||
-------------------- End of file COPYLEFT ------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
ansi2knr input_file [output_file]
|
||||
* If no output_file is supplied, output goes to stdout.
|
||||
* There are no error messages.
|
||||
*
|
||||
* ansi2knr recognizes function definitions by seeing a non-keyword
|
||||
* identifier at the left margin, followed by a left parenthesis,
|
||||
* with a right parenthesis as the last character on the line,
|
||||
* and with a left brace as the first token on the following line
|
||||
* (ignoring possible intervening comments).
|
||||
* It will recognize a multi-line header provided that no intervening
|
||||
* line ends with a left or right brace or a semicolon.
|
||||
* These algorithms ignore whitespace and comments, except that
|
||||
* the function name must be the first thing on the line.
|
||||
* The following constructs will confuse it:
|
||||
* - Any other construct that starts at the left margin and
|
||||
* follows the above syntax (such as a macro or function call).
|
||||
* - Some macros that tinker with the syntax of the function header.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The original and principal author of ansi2knr is L. Peter Deutsch
|
||||
* <ghost@aladdin.com>. Other authors are noted in the change history
|
||||
* that follows (in reverse chronological order):
|
||||
lpd 96-01-21 added code to cope with not HAVE_CONFIG_H and with
|
||||
compilers that don't understand void, as suggested by
|
||||
Tom Lane
|
||||
lpd 96-01-15 changed to require that the first non-comment token
|
||||
on the line following a function header be a left brace,
|
||||
to reduce sensitivity to macros, as suggested by Tom Lane
|
||||
<tgl@sss.pgh.pa.us>
|
||||
lpd 95-06-22 removed #ifndefs whose sole purpose was to define
|
||||
undefined preprocessor symbols as 0; changed all #ifdefs
|
||||
for configuration symbols to #ifs
|
||||
lpd 95-04-05 changed copyright notice to make it clear that
|
||||
including ansi2knr in a program does not bring the entire
|
||||
program under the GPL
|
||||
lpd 94-12-18 added conditionals for systems where ctype macros
|
||||
don't handle 8-bit characters properly, suggested by
|
||||
Francois Pinard <pinard@iro.umontreal.ca>;
|
||||
removed --varargs switch (this is now the default)
|
||||
lpd 94-10-10 removed CONFIG_BROKETS conditional
|
||||
lpd 94-07-16 added some conditionals to help GNU `configure',
|
||||
suggested by Francois Pinard <pinard@iro.umontreal.ca>;
|
||||
properly erase prototype args in function parameters,
|
||||
contributed by Jim Avera <jima@netcom.com>;
|
||||
correct error in writeblanks (it shouldn't erase EOLs)
|
||||
lpd 89-xx-xx original version
|
||||
*/
|
||||
|
||||
/* Most of the conditionals here are to make ansi2knr work with */
|
||||
/* or without the GNU configure machinery. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
|
||||
/*
|
||||
For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h).
|
||||
This will define HAVE_CONFIG_H and so, activate the following lines.
|
||||
*/
|
||||
|
||||
# if STDC_HEADERS || HAVE_STRING_H
|
||||
# include <string.h>
|
||||
# else
|
||||
# include <strings.h>
|
||||
# endif
|
||||
|
||||
#else /* not HAVE_CONFIG_H */
|
||||
|
||||
/* Otherwise do it the hard way */
|
||||
|
||||
# ifdef BSD
|
||||
# include <strings.h>
|
||||
# else
|
||||
# ifdef VMS
|
||||
extern int strlen(), strncmp();
|
||||
# else
|
||||
# include <string.h>
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif /* not HAVE_CONFIG_H */
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
/*
|
||||
malloc and free should be declared in stdlib.h,
|
||||
but if you've got a K&R compiler, they probably aren't.
|
||||
*/
|
||||
# ifdef MSDOS
|
||||
# include <malloc.h>
|
||||
# else
|
||||
# ifdef VMS
|
||||
extern char *malloc();
|
||||
extern void free();
|
||||
# else
|
||||
extern char *malloc();
|
||||
extern int free();
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The ctype macros don't always handle 8-bit characters correctly.
|
||||
* Compensate for this here.
|
||||
*/
|
||||
#ifdef isascii
|
||||
# undef HAVE_ISASCII /* just in case */
|
||||
# define HAVE_ISASCII 1
|
||||
#else
|
||||
#endif
|
||||
#if STDC_HEADERS || !HAVE_ISASCII
|
||||
# define is_ascii(c) 1
|
||||
#else
|
||||
# define is_ascii(c) isascii(c)
|
||||
#endif
|
||||
|
||||
#define is_space(c) (is_ascii(c) && isspace(c))
|
||||
#define is_alpha(c) (is_ascii(c) && isalpha(c))
|
||||
#define is_alnum(c) (is_ascii(c) && isalnum(c))
|
||||
|
||||
/* Scanning macros */
|
||||
#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
|
||||
#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
|
||||
|
||||
/* Forward references */
|
||||
char *skipspace();
|
||||
int writeblanks();
|
||||
int test1();
|
||||
int convert1();
|
||||
|
||||
/* The main program */
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{ FILE *in, *out;
|
||||
#define bufsize 5000 /* arbitrary size */
|
||||
char *buf;
|
||||
char *line;
|
||||
char *more;
|
||||
/*
|
||||
* In previous versions, ansi2knr recognized a --varargs switch.
|
||||
* If this switch was supplied, ansi2knr would attempt to convert
|
||||
* a ... argument to va_alist and va_dcl; if this switch was not
|
||||
* supplied, ansi2knr would simply drop any such arguments.
|
||||
* Now, ansi2knr always does this conversion, and we only
|
||||
* check for this switch for backward compatibility.
|
||||
*/
|
||||
int convert_varargs = 1;
|
||||
|
||||
if ( argc > 1 && argv[1][0] == '-' )
|
||||
{ if ( !strcmp(argv[1], "--varargs") )
|
||||
{ convert_varargs = 1;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else
|
||||
{ fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
switch ( argc )
|
||||
{
|
||||
default:
|
||||
printf("Usage: ansi2knr input_file [output_file]\n");
|
||||
exit(0);
|
||||
case 2:
|
||||
out = stdout;
|
||||
break;
|
||||
case 3:
|
||||
out = fopen(argv[2], "w");
|
||||
if ( out == NULL )
|
||||
{ fprintf(stderr, "Cannot open output file %s\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
in = fopen(argv[1], "r");
|
||||
if ( in == NULL )
|
||||
{ fprintf(stderr, "Cannot open input file %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(out, "#line 1 \"%s\"\n", argv[1]);
|
||||
buf = malloc(bufsize);
|
||||
line = buf;
|
||||
while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
|
||||
{
|
||||
test: line += strlen(line);
|
||||
switch ( test1(buf) )
|
||||
{
|
||||
case 2: /* a function header */
|
||||
convert1(buf, out, 1, convert_varargs);
|
||||
break;
|
||||
case 1: /* a function */
|
||||
/* Check for a { at the start of the next line. */
|
||||
more = ++line;
|
||||
f: if ( line >= buf + (bufsize - 1) ) /* overflow check */
|
||||
goto wl;
|
||||
if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
|
||||
goto wl;
|
||||
switch ( *skipspace(more, 1) )
|
||||
{
|
||||
case '{':
|
||||
/* Definitely a function header. */
|
||||
convert1(buf, out, 0, convert_varargs);
|
||||
fputs(more, out);
|
||||
break;
|
||||
case 0:
|
||||
/* The next line was blank or a comment: */
|
||||
/* keep scanning for a non-comment. */
|
||||
line += strlen(line);
|
||||
goto f;
|
||||
default:
|
||||
/* buf isn't a function header, but */
|
||||
/* more might be. */
|
||||
fputs(buf, out);
|
||||
strcpy(buf, more);
|
||||
line = buf;
|
||||
goto test;
|
||||
}
|
||||
break;
|
||||
case -1: /* maybe the start of a function */
|
||||
if ( line != buf + (bufsize - 1) ) /* overflow check */
|
||||
continue;
|
||||
/* falls through */
|
||||
default: /* not a function */
|
||||
wl: fputs(buf, out);
|
||||
break;
|
||||
}
|
||||
line = buf;
|
||||
}
|
||||
if ( line != buf )
|
||||
fputs(buf, out);
|
||||
free(buf);
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Skip over space and comments, in either direction. */
|
||||
char *
|
||||
skipspace(p, dir)
|
||||
register char *p;
|
||||
register int dir; /* 1 for forward, -1 for backward */
|
||||
{ for ( ; ; )
|
||||
{ while ( is_space(*p) )
|
||||
p += dir;
|
||||
if ( !(*p == '/' && p[dir] == '*') )
|
||||
break;
|
||||
p += dir; p += dir;
|
||||
while ( !(*p == '*' && p[dir] == '/') )
|
||||
{ if ( *p == 0 )
|
||||
return p; /* multi-line comment?? */
|
||||
p += dir;
|
||||
}
|
||||
p += dir; p += dir;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write blanks over part of a string.
|
||||
* Don't overwrite end-of-line characters.
|
||||
*/
|
||||
int
|
||||
writeblanks(start, end)
|
||||
char *start;
|
||||
char *end;
|
||||
{ char *p;
|
||||
for ( p = start; p < end; p++ )
|
||||
if ( *p != '\r' && *p != '\n' )
|
||||
*p = ' ';
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test whether the string in buf is a function definition.
|
||||
* The string may contain and/or end with a newline.
|
||||
* Return as follows:
|
||||
* 0 - definitely not a function definition;
|
||||
* 1 - definitely a function definition;
|
||||
* 2 - definitely a function prototype (NOT USED);
|
||||
* -1 - may be the beginning of a function definition,
|
||||
* append another line and look again.
|
||||
* The reason we don't attempt to convert function prototypes is that
|
||||
* Ghostscript's declaration-generating macros look too much like
|
||||
* prototypes, and confuse the algorithms.
|
||||
*/
|
||||
int
|
||||
test1(buf)
|
||||
char *buf;
|
||||
{ register char *p = buf;
|
||||
char *bend;
|
||||
char *endfn;
|
||||
int contin;
|
||||
|
||||
if ( !isidfirstchar(*p) )
|
||||
return 0; /* no name at left margin */
|
||||
bend = skipspace(buf + strlen(buf) - 1, -1);
|
||||
switch ( *bend )
|
||||
{
|
||||
case ';': contin = 0 /*2*/; break;
|
||||
case ')': contin = 1; break;
|
||||
case '{': return 0; /* not a function */
|
||||
case '}': return 0; /* not a function */
|
||||
default: contin = -1;
|
||||
}
|
||||
while ( isidchar(*p) )
|
||||
p++;
|
||||
endfn = p;
|
||||
p = skipspace(p, 1);
|
||||
if ( *p++ != '(' )
|
||||
return 0; /* not a function */
|
||||
p = skipspace(p, 1);
|
||||
if ( *p == ')' )
|
||||
return 0; /* no parameters */
|
||||
/* Check that the apparent function name isn't a keyword. */
|
||||
/* We only need to check for keywords that could be followed */
|
||||
/* by a left parenthesis (which, unfortunately, is most of them). */
|
||||
{ static char *words[] =
|
||||
{ "asm", "auto", "case", "char", "const", "double",
|
||||
"extern", "float", "for", "if", "int", "long",
|
||||
"register", "return", "short", "signed", "sizeof",
|
||||
"static", "switch", "typedef", "unsigned",
|
||||
"void", "volatile", "while", 0
|
||||
};
|
||||
char **key = words;
|
||||
char *kp;
|
||||
int len = endfn - buf;
|
||||
|
||||
while ( (kp = *key) != 0 )
|
||||
{ if ( strlen(kp) == len && !strncmp(kp, buf, len) )
|
||||
return 0; /* name is a keyword */
|
||||
key++;
|
||||
}
|
||||
}
|
||||
return contin;
|
||||
}
|
||||
|
||||
/* Convert a recognized function definition or header to K&R syntax. */
|
||||
int
|
||||
convert1(buf, out, header, convert_varargs)
|
||||
char *buf;
|
||||
FILE *out;
|
||||
int header; /* Boolean */
|
||||
int convert_varargs; /* Boolean */
|
||||
{ char *endfn;
|
||||
register char *p;
|
||||
char **breaks;
|
||||
unsigned num_breaks = 2; /* for testing */
|
||||
char **btop;
|
||||
char **bp;
|
||||
char **ap;
|
||||
char *vararg = 0;
|
||||
|
||||
/* Pre-ANSI implementations don't agree on whether strchr */
|
||||
/* is called strchr or index, so we open-code it here. */
|
||||
for ( endfn = buf; *(endfn++) != '('; )
|
||||
;
|
||||
top: p = endfn;
|
||||
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
|
||||
if ( breaks == 0 )
|
||||
{ /* Couldn't allocate break table, give up */
|
||||
fprintf(stderr, "Unable to allocate break table!\n");
|
||||
fputs(buf, out);
|
||||
return -1;
|
||||
}
|
||||
btop = breaks + num_breaks * 2 - 2;
|
||||
bp = breaks;
|
||||
/* Parse the argument list */
|
||||
do
|
||||
{ int level = 0;
|
||||
char *lp = NULL;
|
||||
char *rp;
|
||||
char *end = NULL;
|
||||
|
||||
if ( bp >= btop )
|
||||
{ /* Filled up break table. */
|
||||
/* Allocate a bigger one and start over. */
|
||||
free((char *)breaks);
|
||||
num_breaks <<= 1;
|
||||
goto top;
|
||||
}
|
||||
*bp++ = p;
|
||||
/* Find the end of the argument */
|
||||
for ( ; end == NULL; p++ )
|
||||
{ switch(*p)
|
||||
{
|
||||
case ',':
|
||||
if ( !level ) end = p;
|
||||
break;
|
||||
case '(':
|
||||
if ( !level ) lp = p;
|
||||
level++;
|
||||
break;
|
||||
case ')':
|
||||
if ( --level < 0 ) end = p;
|
||||
else rp = p;
|
||||
break;
|
||||
case '/':
|
||||
p = skipspace(p, 1) - 1;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
/* Erase any embedded prototype parameters. */
|
||||
if ( lp )
|
||||
writeblanks(lp + 1, rp);
|
||||
p--; /* back up over terminator */
|
||||
/* Find the name being declared. */
|
||||
/* This is complicated because of procedure and */
|
||||
/* array modifiers. */
|
||||
for ( ; ; )
|
||||
{ p = skipspace(p - 1, -1);
|
||||
switch ( *p )
|
||||
{
|
||||
case ']': /* skip array dimension(s) */
|
||||
case ')': /* skip procedure args OR name */
|
||||
{ int level = 1;
|
||||
while ( level )
|
||||
switch ( *--p )
|
||||
{
|
||||
case ']': case ')': level++; break;
|
||||
case '[': case '(': level--; break;
|
||||
case '/': p = skipspace(p, -1) + 1; break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
|
||||
{ /* We found the name being declared */
|
||||
while ( !isidfirstchar(*p) )
|
||||
p = skipspace(p, 1) + 1;
|
||||
goto found;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
||||
{ if ( convert_varargs )
|
||||
{ *bp++ = "va_alist";
|
||||
vararg = p-2;
|
||||
}
|
||||
else
|
||||
{ p++;
|
||||
if ( bp == breaks + 1 ) /* sole argument */
|
||||
writeblanks(breaks[0], p);
|
||||
else
|
||||
writeblanks(bp[-1] - 1, p);
|
||||
bp--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ while ( isidchar(*p) ) p--;
|
||||
*bp++ = p+1;
|
||||
}
|
||||
p = end;
|
||||
}
|
||||
while ( *p++ == ',' );
|
||||
*bp = p;
|
||||
/* Make a special check for 'void' arglist */
|
||||
if ( bp == breaks+2 )
|
||||
{ p = skipspace(breaks[0], 1);
|
||||
if ( !strncmp(p, "void", 4) )
|
||||
{ p = skipspace(p+4, 1);
|
||||
if ( p == breaks[2] - 1 )
|
||||
{ bp = breaks; /* yup, pretend arglist is empty */
|
||||
writeblanks(breaks[0], p + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Put out the function name and left parenthesis. */
|
||||
p = buf;
|
||||
while ( p != endfn ) putc(*p, out), p++;
|
||||
/* Put out the declaration. */
|
||||
if ( header )
|
||||
{ fputs(");", out);
|
||||
for ( p = breaks[0]; *p; p++ )
|
||||
if ( *p == '\r' || *p == '\n' )
|
||||
putc(*p, out);
|
||||
}
|
||||
else
|
||||
{ for ( ap = breaks+1; ap < bp; ap += 2 )
|
||||
{ p = *ap;
|
||||
while ( isidchar(*p) )
|
||||
putc(*p, out), p++;
|
||||
if ( ap < bp - 1 )
|
||||
fputs(", ", out);
|
||||
}
|
||||
fputs(") ", out);
|
||||
/* Put out the argument declarations */
|
||||
for ( ap = breaks+2; ap <= bp; ap += 2 )
|
||||
(*ap)[-1] = ';';
|
||||
if ( vararg != 0 )
|
||||
{ *vararg = 0;
|
||||
fputs(breaks[0], out); /* any prior args */
|
||||
fputs("va_dcl", out); /* the final arg */
|
||||
fputs(bp[0], out);
|
||||
}
|
||||
else
|
||||
fputs(breaks[0], out);
|
||||
}
|
||||
free((char *)breaks);
|
||||
return 0;
|
||||
}
|
||||
52
contrib/gregbook/README
Normal file
@@ -0,0 +1,52 @@
|
||||
PNG: The Definitive Guide: Source Code
|
||||
|
||||
Chapters 13, 14 and 15 of PNG: The Definitive Guide discuss three
|
||||
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 PPM files (the ``raw'' RGB subset of NetPBM) and converts them
|
||||
to PNG.
|
||||
|
||||
The source code for all three demo programs currently compiles only under
|
||||
Unix and 32-bit Windows. It has been tested with gcc 2.7.2.3 under Linux and
|
||||
Solaris and with Microsoft Visual C++ 5.0 under Windows 95. Brief
|
||||
instructions for compiling the programs are included at the top of the
|
||||
makefiles; makefile.unx is the Unix version, and makefile.w32 is (you
|
||||
guessed it!) the version for 32-bit Windows. libpng and zlib are required.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
License
|
||||
|
||||
The source code to the demo programs may be used and distributed freely
|
||||
(even if you didn't buy the book--but feel free to do so at any time),
|
||||
subject to the terms of the following BSD-like license:
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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 documentation 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.
|
||||
|
||||
----------------------------------------------------------
|
||||
http://www.cdrom.com/pub/png/book/sources.html
|
||||
95
contrib/gregbook/makefile.unx
Normal file
@@ -0,0 +1,95 @@
|
||||
# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
|
||||
# Greg Roelofs
|
||||
# Last modified: 16 February 1999
|
||||
#
|
||||
# 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.unx
|
||||
#
|
||||
# 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
|
||||
# PNGPATH and ZPATH macros below). Edit as appropriate.
|
||||
#
|
||||
# This makefile builds statically linked executables (against libpng and zlib,
|
||||
# that is), but that can be changed by uncommenting the appropriate PNGLIB and
|
||||
# ZLIB lines.
|
||||
|
||||
|
||||
# macros --------------------------------------------------------------------
|
||||
|
||||
PNGPATH = /usr/local
|
||||
PNGINC = -I$(PNGPATH)/include
|
||||
#PNGLIB = -L$(PNGPATH)/lib -lpng
|
||||
PNGLIB = $(PNGPATH)/lib/libpng.a
|
||||
|
||||
ZPATH = /usr/local
|
||||
ZINC = -I$(ZPATH)/include
|
||||
#ZLIB = -L$(ZPATH)/lib -lz
|
||||
ZLIB = $(ZPATH)/lib/libz.a
|
||||
|
||||
#XPATH = /usr/X11
|
||||
XPATH = /usr/X11R6
|
||||
XINC = -I$(XPATH)/include
|
||||
XLIB = -L$(XPATH)/lib -lX11
|
||||
|
||||
INCS = $(PNGINC) $(ZINC) $(XINC)
|
||||
RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm
|
||||
WLIBS = $(PNGLIB) $(ZLIB) -lm
|
||||
|
||||
CC = gcc
|
||||
LD = gcc
|
||||
RM = rm -f
|
||||
CFLAGS = -O -Wall $(INCS)
|
||||
# [note that -Wall is a gcc-specific compilation flag ("all warnings on")]
|
||||
LDFLAGS =
|
||||
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)
|
||||
112
contrib/gregbook/makefile.w32
Normal file
@@ -0,0 +1,112 @@
|
||||
# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE.
|
||||
# Greg Roelofs
|
||||
# Last modified: 16 February 1999
|
||||
#
|
||||
# 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 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 -Wall 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)
|
||||
104
contrib/gregbook/makevms.com
Normal file
@@ -0,0 +1,104 @@
|
||||
$!------------------------------------------------------------------------------
|
||||
$! 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 ..."
|
||||
$ 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
|
||||
275
contrib/gregbook/readpng.c
Normal file
@@ -0,0 +1,275 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng - simple PNG display program readpng.c
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "png.h" /* libpng header; includes zlib.h */
|
||||
#include "readpng.h" /* typedefs, common macros, public prototypes */
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
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, long *pWidth, long *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_check_sig(sig, 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_ptr->jmpbuf)) {
|
||||
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_ptr->jmpbuf)) {
|
||||
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_ptr->jmpbuf)) {
|
||||
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: rowbytes = %ld, height = %ld\n", 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;
|
||||
}
|
||||
}
|
||||
64
contrib/gregbook/readpng.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng - simple PNG display program readpng.h
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#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, long *pWidth, long *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);
|
||||
419
contrib/gregbook/readpng2.c
Normal file
@@ -0,0 +1,419 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng2 - progressive-model PNG display program readpng2.c
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int readpng2_check_sig(uch *sig, int num)
|
||||
{
|
||||
return png_check_sig(sig, 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;
|
||||
}
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* 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;
|
||||
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, &mainprog_ptr->width,
|
||||
&mainprog_ptr->height, &bit_depth, &color_type, NULL, NULL, NULL);
|
||||
|
||||
|
||||
/* 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 = 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);
|
||||
|
||||
|
||||
/* 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);
|
||||
}
|
||||
85
contrib/gregbook/readpng2.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng2 - progressive-model PNG display program readpng2.h
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#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;
|
||||
|
||||
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 rowbytes;
|
||||
int channels;
|
||||
int need_bgcolor;
|
||||
int done;
|
||||
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);
|
||||
600
contrib/gregbook/rpng-win.c
Normal file
@@ -0,0 +1,600 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
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:
|
||||
- stdout/stderr don't work! need message window (maybe scrollable?)
|
||||
- handle quoted command-line args (especially filenames with spaces)
|
||||
- have minimum window width: oh well
|
||||
- use %.1023s to simplify truncation of title-bar string?
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define PROGNAME "rpng-win"
|
||||
#define LONGNAME "Simple PNG Viewer for Windows"
|
||||
#define VERSION "1.0 of 20 February 1999"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <windows.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_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], *window_name = titlebar;
|
||||
static char *progname = PROGNAME;
|
||||
static char *appname = LONGNAME;
|
||||
static char *icon_name = PROGNAME; /* GRR: not (yet) used */
|
||||
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 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 (!strcmp(*argv, "-gamma")) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
display_exponent = atof(*argv);
|
||||
if (display_exponent <= 0.0)
|
||||
++error;
|
||||
} else if (!strcmp(*argv, "-bgcolor")) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
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;
|
||||
} else 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) {
|
||||
fprintf(stderr, "\n%s %s: %s\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., ``#ff7f00'' 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"
|
||||
"\n", PROGNAME, default_display_exponent);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* 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)
|
||||
sscanf(bgstr+1, "%2x%2x%2x", &bg_red, &bg_green, &bg_blue);
|
||||
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 */
|
||||
|
||||
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);
|
||||
}
|
||||
741
contrib/gregbook/rpng-x.c
Normal file
@@ -0,0 +1,741 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
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 under Unix, but may work
|
||||
under VMS or OS/2 with a little tweaking).
|
||||
|
||||
to do:
|
||||
- 8-bit support
|
||||
- use %.1023s to simplify truncation of title-bar string?
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define PROGNAME "rpng-x"
|
||||
#define LONGNAME "Simple PNG Viewer for X"
|
||||
#define VERSION "1.01 of 31 March 1999"
|
||||
|
||||
#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 *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 bitmap_order;
|
||||
static int depth;
|
||||
static Visual *visual;
|
||||
static int RPixelShift, GPixelShift, BPixelShift;
|
||||
static ulg RedMask, GreenMask, BlueMask;
|
||||
static Window window;
|
||||
static GC gc;
|
||||
static Colormap colormap;
|
||||
|
||||
static int have_colormap = FALSE;
|
||||
static int have_window = 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 (!strcmp(*argv, "-display")) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
displayname = *argv;
|
||||
} else if (!strcmp(*argv, "-gamma")) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
display_exponent = atof(*argv);
|
||||
if (display_exponent <= 0.0)
|
||||
++error;
|
||||
} else if (!strcmp(*argv, "-bgcolor")) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
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;
|
||||
} else if (!(infile = fopen(filename, "rb"))) {
|
||||
fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
|
||||
++error;
|
||||
} else {
|
||||
if ((rc = readpng_init(infile, (long *)(&image_width),
|
||||
(long *)(&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, "\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., ``#ff7f00'' 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"
|
||||
"\n", PROGNAME, default_display_exponent);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* 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 */
|
||||
|
||||
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()
|
||||
{
|
||||
uch *xdata;
|
||||
int screen, pad;
|
||||
ulg bg_pixel = 0L;
|
||||
Window root;
|
||||
XEvent e;
|
||||
XGCValues gcvalues;
|
||||
XSetWindowAttributes attr;
|
||||
XSizeHints *size_hints;
|
||||
XTextProperty windowName, *pWindowName = &windowName;
|
||||
XTextProperty iconName, *pIconName = &iconName;
|
||||
XVisualInfo visual_info;
|
||||
XWMHints *wm_hints;
|
||||
|
||||
|
||||
bitmap_order = BitmapBitOrder(display);
|
||||
screen = DefaultScreen(display);
|
||||
depth = DisplayPlanes(display, screen);
|
||||
root = RootWindow(display, screen);
|
||||
|
||||
/* 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;
|
||||
|
||||
RedMask = visual->red_mask;
|
||||
GreenMask = visual->green_mask;
|
||||
BlueMask = visual->blue_mask;
|
||||
|
||||
/* GRR: add/check 8-bit support */
|
||||
if (depth == 8) {
|
||||
colormap = XCreateColormap(display, root, visual, AllocNone);
|
||||
if (!colormap) {
|
||||
fprintf(stderr, "XCreateColormap() failed\n");
|
||||
return 2;
|
||||
}
|
||||
have_colormap = TRUE;
|
||||
} else if (depth == 16) {
|
||||
RPixelShift = 15 - rpng_x_msb(RedMask); /* these are right-shifts */
|
||||
GPixelShift = 15 - rpng_x_msb(GreenMask);
|
||||
BPixelShift = 15 - rpng_x_msb(BlueMask);
|
||||
} else /* if (depth > 16) */ {
|
||||
RPixelShift = rpng_x_msb(RedMask) - 7; /* these are left-shifts */
|
||||
GPixelShift = rpng_x_msb(GreenMask) - 7;
|
||||
BPixelShift = rpng_x_msb(BlueMask) - 7;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Finally, create the window.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
attr.backing_store = Always;
|
||||
attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
|
||||
|
||||
window = XCreateWindow(display, root, 0, 0, image_width, image_height,
|
||||
0, depth, InputOutput, visual, CWBackingStore | CWEventMask, &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 either 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 = image_width;
|
||||
size_hints->min_height = size_hints->max_height = 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 */ ;
|
||||
}
|
||||
|
||||
XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,
|
||||
size_hints, wm_hints, NULL);
|
||||
|
||||
XMapWindow(display, window);
|
||||
|
||||
gc = XCreateGC(display, window, 0, &gcvalues);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Fill window with the specified background color.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
if (depth == 24 || depth == 32) {
|
||||
bg_pixel = ((ulg)bg_red << RPixelShift) |
|
||||
((ulg)bg_green << GPixelShift) |
|
||||
((ulg)bg_blue << BPixelShift);
|
||||
} else if (depth == 16) {
|
||||
bg_pixel = ((((ulg)bg_red << 8) >> RPixelShift) & RedMask) |
|
||||
((((ulg)bg_green << 8) >> GPixelShift) & GreenMask) |
|
||||
((((ulg)bg_blue << 8) >> BPixelShift) & BlueMask);
|
||||
} 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 bitmap_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()
|
||||
{
|
||||
uch *src;
|
||||
char *dest;
|
||||
uch r, g, b, a;
|
||||
int ximage_rowbytes = ximage->bytes_per_line;
|
||||
ulg i, row, lastrow = 0;
|
||||
ulg 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))
|
||||
|
||||
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++;
|
||||
pixel = (red << RPixelShift) |
|
||||
(green << GPixelShift) |
|
||||
(blue << BPixelShift);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = ((uch *)&pixel)[3];
|
||||
*dest++ = ((uch *)&pixel)[2];
|
||||
*dest++ = ((uch *)&pixel)[1];
|
||||
*dest++ = ((uch *)&pixel)[0];
|
||||
}
|
||||
} 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 << RPixelShift) |
|
||||
(green << GPixelShift) |
|
||||
(blue << BPixelShift);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = ((uch *)&pixel)[3];
|
||||
*dest++ = ((uch *)&pixel)[2];
|
||||
*dest++ = ((uch *)&pixel)[1];
|
||||
*dest++ = ((uch *)&pixel)[0];
|
||||
}
|
||||
}
|
||||
/* display after every 16 lines */
|
||||
if (((row+1) & 0xf) == 0) {
|
||||
XPutImage(display, window, gc, ximage, 0, lastrow, 0, 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 >> RPixelShift) & RedMask) |
|
||||
((green >> GPixelShift) & GreenMask) |
|
||||
((blue >> BPixelShift) & BlueMask);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = ((uch *)&pixel)[1];
|
||||
*dest++ = ((uch *)&pixel)[0];
|
||||
}
|
||||
} 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 >> RPixelShift) & RedMask) |
|
||||
((green >> GPixelShift) & GreenMask) |
|
||||
((blue >> BPixelShift) & BlueMask);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = ((uch *)&pixel)[1];
|
||||
*dest++ = ((uch *)&pixel)[0];
|
||||
}
|
||||
}
|
||||
/* display after every 16 lines */
|
||||
if (((row+1) & 0xf) == 0) {
|
||||
XPutImage(display, window, gc, ximage, 0, lastrow, 0, 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, lastrow, 0, lastrow,
|
||||
image_width, image_height-lastrow);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void rpng_x_cleanup()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
XFreeGC(display, gc);
|
||||
|
||||
if (have_window)
|
||||
XDestroyWindow(display, window);
|
||||
|
||||
if (have_colormap)
|
||||
XFreeColormap(display, colormap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int rpng_x_msb(ulg u32val)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 31; i >= 0; --i) {
|
||||
if (u32val & 0x80000000L)
|
||||
break;
|
||||
u32val <<= 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
1102
contrib/gregbook/rpng2-win.c
Normal file
1247
contrib/gregbook/rpng2-x.c
Normal file
804
contrib/gregbook/wpng.c
Normal file
@@ -0,0 +1,804 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define PROGNAME "wpng"
|
||||
#define VERSION "1.01 of 31 March 1999"
|
||||
#define APPNAME "Simple PGM/PPM/PAM to PNG Converter"
|
||||
|
||||
#if defined(__MSDOS__) || defined(__OS2__)
|
||||
# define DOS_OS2_W32
|
||||
#elif defined(_WIN32) || defined(__WIN32__)
|
||||
# define DOS_OS2_W32
|
||||
#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 (!strcmp(*argv, "-interlaced")) {
|
||||
wpng_info.interlaced = TRUE;
|
||||
} else if (!strcmp(*argv, "-time")) {
|
||||
wpng_info.modtime = time(NULL);
|
||||
wpng_info.have_time = TRUE;
|
||||
} else if (!strcmp(*argv, "-text")) {
|
||||
text = TRUE;
|
||||
} else if (!strcmp(*argv, "-gamma")) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
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 (!strcmp(*argv, "-bgcolor")) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
bgstr = *argv;
|
||||
if (strlen(bgstr) != 7 || bgstr[0] != '#')
|
||||
++error;
|
||||
else {
|
||||
unsigned r, g, b; /* this approach 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., ``#ff7f00'' 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()
|
||||
{
|
||||
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 */
|
||||
368
contrib/gregbook/writepng.c
Normal file
@@ -0,0 +1,368 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
wpng - simple PNG-writing program writepng.c
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
109
contrib/gregbook/writepng.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
wpng - simple PNG-writing program writepng.h
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-1999 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.
|
||||
|
||||
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.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#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://swrinde.nde.swri.edu/pub/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
|
||||
|
||||
52
contrib/pngminus/makefile.std
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile for PngMinus (png2pnm and pnm2png)
|
||||
# Linux / Unix
|
||||
|
||||
CC=cc -O
|
||||
LD=cc -O
|
||||
#CC=gcc -O
|
||||
#LD=gcc -O
|
||||
LB=ar
|
||||
RM=rm
|
||||
CP=cp
|
||||
|
||||
PNGPATH = /usr/local
|
||||
PNGINC = $(PNGPATH)/include
|
||||
#PNGLIB = $(PNGPATH)/lib -lpng
|
||||
PNGLIB = $(PNGPATH)/lib/libpng.a
|
||||
|
||||
ZPATH = /usr/local
|
||||
ZINC = $(ZPATH)/include
|
||||
#ZLIB = $(ZPATH)/lib -lz
|
||||
ZLIB = $(ZPATH)/lib/libz.a
|
||||
|
||||
CCFLAGS=-I$(PNGINC) -I$(ZINC)
|
||||
LDFLAGS=-L$(PNGLIB) -L$(ZLIB)
|
||||
C=.c
|
||||
O=.o
|
||||
L=.a
|
||||
E=
|
||||
|
||||
# dependencies
|
||||
|
||||
all: png2pnm$(E) pnm2png$(E)
|
||||
|
||||
png2pnm$(O): png2pnm$(C)
|
||||
$(CC) -c $(CCFLAGS) png2pnm$(C)
|
||||
|
||||
png2pnm$(E): png2pnm$(O)
|
||||
$(LD) -o png2pnm$(E) png2pnm$(O) $(LDFLAGS) -lpng -lz -lm
|
||||
|
||||
pnm2png$(O): pnm2png$(C)
|
||||
$(CC) -c $(CCFLAGS) pnm2png$(C)
|
||||
|
||||
pnm2png$(E): pnm2png$(O)
|
||||
$(LD) -o pnm2png$(E) pnm2png$(O) $(LDFLAGS) -lpng -lz -lm
|
||||
|
||||
clean:
|
||||
$(RM) png2pnm$(O)
|
||||
$(RM) pnm2png$(O)
|
||||
$(RM) png2pnm$(E)
|
||||
$(RM) pnm2png$(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 pnm2png.exe -
|
||||
"LINK pnm2png,lib.opt/opt" -
|
||||
pnm2png.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
|
||||
|
||||
420
contrib/pngminus/png2pnm.c
Normal file
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/* 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;
|
||||
|
||||
/* read and check signature in PNG file */
|
||||
ret = fread (buf, 1, 8, png_file);
|
||||
if (ret != 8)
|
||||
return FALSE;
|
||||
|
||||
ret = png_check_sig (buf, 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_ptr->jmpbuf))
|
||||
{
|
||||
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)
|
||||
fprintf (pnm_file, "%ld ", ((long) *pix_ptr++ << 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)
|
||||
fprintf (alpha_file, "%ld ", ((long) *pix_ptr++ << 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 */
|
||||
|
||||
41
contrib/pngminus/png2pnm.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
# -- 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
|
||||
|
||||
4
contrib/pngminus/pngminus.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
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
|
||||
|
||||
527
contrib/pngminus/pnm2png.c
Normal file
@@ -0,0 +1,527 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/* 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_ptr->jmpbuf))
|
||||
{
|
||||
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, token);
|
||||
sscanf (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 */
|
||||
|
||||
41
contrib/pngminus/pnm2png.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
# -- 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 |
51
example.c
@@ -1,4 +1,6 @@
|
||||
|
||||
#if 0 /* in case someone actually tries to compile this */
|
||||
|
||||
/* example.c - an example of using libpng */
|
||||
|
||||
/* This is an example of how to use libpng to read and write PNG files.
|
||||
@@ -15,8 +17,11 @@
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* Check to see if a file is a PNG file using png_sig_cmp(). Returns
|
||||
* non-zero if the image is a PNG, and 0 if it isn't a PNG.
|
||||
/* 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.
|
||||
*
|
||||
* The function check_if_png() shown here, but not used, returns nonzero (true)
|
||||
* if the file can be opened and is a PNG, 0 (false) otherwise.
|
||||
*
|
||||
* If this call is successful, and you are going to keep the file open,
|
||||
* you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once
|
||||
@@ -41,12 +46,14 @@ int check_if_png(char *file_name, FILE **fp)
|
||||
if ((*fp = fopen(file_name, "rb")) != NULL);
|
||||
return 0;
|
||||
|
||||
/* Read in the signature bytes */
|
||||
/* Read in some of the signature bytes */
|
||||
if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)
|
||||
return 0;
|
||||
|
||||
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. */
|
||||
return(png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
|
||||
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
|
||||
Return nonzero (true) if they match */
|
||||
|
||||
return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
|
||||
}
|
||||
|
||||
/* Read a PNG file. You may want to return an error code if the read
|
||||
@@ -146,7 +153,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
/* Strip alpha bytes from the input data without combining with th
|
||||
/* Strip alpha bytes from the input data without combining with the
|
||||
* background (not recommended).
|
||||
*/
|
||||
png_set_strip_alpha(png_ptr);
|
||||
@@ -192,7 +199,8 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
|
||||
/* Some suggestions as to how to get a screen gamma value */
|
||||
|
||||
/* Note that screen gamma is (display_gamma/viewing_gamma) */
|
||||
/* Note that screen gamma is the display_exponent, which includes
|
||||
* the CRT_exponent and any correction for viewing conditions */
|
||||
if (/* We have a user-defined screen gamma value */)
|
||||
{
|
||||
screen_gamma = user-defined screen_gamma;
|
||||
@@ -219,12 +227,15 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent))
|
||||
png_set_sRGB(png_ptr, intent, 0);
|
||||
else
|
||||
png_set_sRGB(png_ptr, info_ptr, intent);
|
||||
else
|
||||
{
|
||||
double image_gamma;
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
|
||||
png_set_gamma(png_ptr, screen_gamma, image_gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.50);
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
}
|
||||
|
||||
/* Dither RGB files down to 8 bit palette or reduce palettes
|
||||
* to the number of colors available on your screen.
|
||||
@@ -324,13 +335,13 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
{
|
||||
#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, NULL, row_pointers[y], number_of_rows);
|
||||
#else no_sparkle /* Read the image using the "rectangle" effect */
|
||||
png_read_rows(png_ptr, NULL, &row_pointers[y], number_of_rows);
|
||||
#endif no_sparkle /* use only one of these two methods */
|
||||
}
|
||||
|
||||
|
||||
/* if you want to display the image after every pass, do
|
||||
so here */
|
||||
#endif no_single /* use only one of these two methods */
|
||||
@@ -384,8 +395,11 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* this one's new. You will need to provide all three
|
||||
/* This one's new. You will need to provide all three
|
||||
* function callbacks, even if you aren't using them all.
|
||||
* If you aren't using all functions, you can specify NULL
|
||||
* parameters. Even when all three functions are NULL,
|
||||
* you need to call png_set_progressive_read_fn().
|
||||
* These functions shouldn't be dependent on global or
|
||||
* static variables if you are decoding several images
|
||||
* simultaneously. You should store stream specific data
|
||||
@@ -565,7 +579,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
sig_bit.alpha = true_alpha_bit_depth;
|
||||
png_set_sBIT(png_ptr, info_ptr, sig_bit);
|
||||
|
||||
|
||||
|
||||
/* Optional gamma chunk is strongly suggested if you have any guess
|
||||
* as to the correct gamma of the image.
|
||||
*/
|
||||
@@ -590,6 +604,14 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
/* Write the file header information. REQUIRED */
|
||||
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);
|
||||
*/
|
||||
|
||||
/* Once we write out the header, the compression type on the text
|
||||
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
|
||||
@@ -689,3 +711,4 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* if 0 */
|
||||
|
||||
349
libpng.txt
@@ -1,16 +1,16 @@
|
||||
libpng.txt - A description on how to use and modify libpng
|
||||
|
||||
libpng version 1.0.2 - June 14, 1998
|
||||
libpng version 1.0.5d - November 29, 1999
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
<randeg@alumni.rpi.edu>
|
||||
Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
<randeg@alum.rpi.edu>
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
For conditions of distribution and use, see copyright
|
||||
notice in png.h.
|
||||
|
||||
based on:
|
||||
|
||||
libpng 1.0 beta 6 version 0.96 May 28, 1997
|
||||
Updated and distributed by Andreas Dilger
|
||||
Updated and distributed by Andreas Dilger
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
|
||||
libpng 1.0 beta 2 - version 0.88 January 26, 1996
|
||||
@@ -22,6 +22,7 @@ libpng.txt - A description on how to use and modify libpng
|
||||
Copyright (c) 1995 Frank J. T. Wojcik
|
||||
December 18, 1995 && January 20, 1996
|
||||
|
||||
*
|
||||
I. Introduction
|
||||
|
||||
This file describes how to use and modify the PNG reference library
|
||||
@@ -35,12 +36,19 @@ INSTALL file for instructions on how to install libpng.
|
||||
|
||||
Libpng was written as a companion to the PNG specification, as a way
|
||||
of reducing the amount of time and effort it takes to support the PNG
|
||||
file format in application programs. The PNG specification is available
|
||||
file format in application programs.
|
||||
|
||||
The PNG-1.2 specification is available at <http://www.cdrom.com/png>.
|
||||
|
||||
The PNG-1.0 specification is available
|
||||
as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> and as a
|
||||
W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
|
||||
additional chunks are described in the special-purpose public chunks
|
||||
documents at <ftp://ftp.uu.net/graphics/png/documents/>. Other information
|
||||
about PNG can be found at the PNG home page, <http://www.cdrom.com/pub/png/>.
|
||||
documents at <ftp://ftp.uu.net/graphics/png/documents/>.
|
||||
|
||||
Other information
|
||||
about PNG, and the latest version of libpng, can be found at the PNG home
|
||||
page, <http://www.cdrom.com/pub/png/>.
|
||||
|
||||
Most users will not have to modify the library significantly; advanced
|
||||
users may want to modify it more. All attempts were made to make it as
|
||||
@@ -57,6 +65,8 @@ work to be done (see the TODO file), libpng should cover the
|
||||
majority of the needs of its users.
|
||||
|
||||
Libpng uses zlib for its compression and decompression of PNG files.
|
||||
Further information about zlib, and the latest version of zlib, can
|
||||
be found at the zlib home page, <http://www.cdrom.com/pub/infozip/zlib/>.
|
||||
The zlib compression utility is a general purpose utility that is
|
||||
useful for more than PNG files, and can be used without libpng.
|
||||
See the documentation delivered with zlib for more details.
|
||||
@@ -126,7 +136,7 @@ Customizing libpng.
|
||||
return;
|
||||
}
|
||||
fread(header, 1, number, fp);
|
||||
is_png = png_check_sig(header, 0, number);
|
||||
is_png = !png_sig_cmp(header, 0, number);
|
||||
if (!is_png)
|
||||
{
|
||||
return;
|
||||
@@ -179,8 +189,8 @@ are only necessary if you are not using the libpng supplied error
|
||||
handling and memory alloc/free functions.
|
||||
|
||||
When libpng encounters an error, it expects to longjmp back
|
||||
to your routine. Therefore, you will need to call setjmp and pass the
|
||||
jmpbuf field of your png_struct. If you read the file from different
|
||||
to your routine. Therefore, you will need to call setjmp and pass
|
||||
your png_ptr->jmpbuf. If you read the file from different
|
||||
routines, you will need to update the jmpbuf field every time you enter
|
||||
a new routine that will call a png_ function.
|
||||
|
||||
@@ -219,7 +229,7 @@ called after each row has been read, which you can use to control
|
||||
a progress meter or the like. It's demonstrated in pngtest.c.
|
||||
You must supply a function
|
||||
|
||||
void read_row_callback(png_ptr, png_uint_32 row, int pass);
|
||||
void read_row_callback(png_ptr ptr, png_uint_32 row, int pass);
|
||||
{
|
||||
/* put your code here */
|
||||
}
|
||||
@@ -253,11 +263,26 @@ with
|
||||
You must supply the function
|
||||
|
||||
void read_transform_fn(png_ptr ptr, row_info_ptr
|
||||
row_info, png_bytep data)
|
||||
row_info, png_bytep data)
|
||||
|
||||
See pngtest.c for a working example. Your function will be called
|
||||
after all of the other transformations have been processed.
|
||||
|
||||
You can also set up a pointer to a user structure for use by your
|
||||
callback function, and you can inform libpng that your transform
|
||||
function will change the number of channels or bit depth with the
|
||||
function
|
||||
|
||||
png_set_user_transform_info(png_ptr, user_ptr,
|
||||
user_depth, user_channels);
|
||||
|
||||
|
||||
You can retrieve the pointer via the function
|
||||
png_get_user_transform_ptr(). For example:
|
||||
|
||||
voidp read_user_transform_ptr =
|
||||
png_get_user_transform_ptr(png_ptr);
|
||||
|
||||
You are now ready to read all the file information up to the actual
|
||||
image data. You do this with a call to png_read_info().
|
||||
|
||||
@@ -282,7 +307,7 @@ Functions are used to get the information from the info_ptr:
|
||||
are present.
|
||||
PNG_COLOR_TYPE_GRAY
|
||||
(bit depths 1, 2, 4, 8, 16)
|
||||
PNG_COLOR_TYPE_GRAY_ALPHA
|
||||
PNG_COLOR_TYPE_GRAY_ALPHA
|
||||
(bit depths 8, 16)
|
||||
PNG_COLOR_TYPE_PALETTE
|
||||
(bit depths 1, 2, 4, 8)
|
||||
@@ -503,13 +528,18 @@ grayscale images with bit depths of 2 or 4 or if there is a multiple-image
|
||||
viewing application that wishes to treat all images in the same way.
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE &&
|
||||
bit_depth <= 8) png_set_expand(png_ptr);
|
||||
bit_depth <= 8) png_set_palette_to_rgb(png_ptr);
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY &&
|
||||
bit_depth < 8) png_set_expand(png_ptr);
|
||||
bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
|
||||
|
||||
if (png_get_valid(png_ptr, info_ptr,
|
||||
PNG_INFO_tRNS)) png_set_expand(png_ptr);
|
||||
PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
|
||||
|
||||
These three functions are actually aliases for png_set_expand(), added
|
||||
in libpng version 1.0.4, with the function names expanded to improve code
|
||||
readability. In some future version they may actually do different
|
||||
things.
|
||||
|
||||
PNG can have files with 16 bits per channel. If you only can handle
|
||||
8 bits per channel, this will strip the pixels down to 8 bit.
|
||||
@@ -588,7 +618,65 @@ RGB. This code will do that conversion:
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
|
||||
If you have a grayscale and you are using png_set_expand() to change to
|
||||
Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
|
||||
with alpha. This is intended for conversion of images that really are
|
||||
gray (red == green == blue), so the function simply strips out the red
|
||||
and blue channels, leaving the green channel in the gray position.
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_RGB ||
|
||||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
png_set_rgb_to_gray(png_ptr, error_action,
|
||||
double red_weight, double green_weight);
|
||||
|
||||
error_action = 1: silently do the conversion
|
||||
error_action = 2: issue a warning if the original
|
||||
image has any pixel where
|
||||
red != green or red != blue
|
||||
error_action = 3: issue an error and abort the
|
||||
conversion if the original
|
||||
image has any pixel where
|
||||
red != green or red != blue
|
||||
|
||||
red_weight: weight of red component
|
||||
(NULL -> default 54/256)
|
||||
green_weight: weight of green component
|
||||
(NULL -> default 183/256)
|
||||
|
||||
If you have set error_action = 1 or 2, you can
|
||||
later check whether the image really was gray, after processing
|
||||
the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
|
||||
It will return a png_byte that is zero if the image was gray or
|
||||
1 if there were any non-gray pixels. bKGD and sBIT data
|
||||
will be silently converted to grayscale, using the green channel
|
||||
data, regardless of the error_action setting.
|
||||
|
||||
With 0.0<=red_weight+green_weight<=1.0,
|
||||
the normalized graylevel is computed:
|
||||
|
||||
int rw = red_weight * 256;
|
||||
int gw = green_weight * 256;
|
||||
int bw = 256 - (rw + gw);
|
||||
gray = (rw*red + gw*green + bw*blue)/256;
|
||||
|
||||
The default values approximate those recommended in the Charles
|
||||
Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
|
||||
Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net
|
||||
|
||||
Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
|
||||
|
||||
Libpng approximates this with
|
||||
|
||||
Y = 0.211 * R + 0.715 * G + 0.074 * B
|
||||
|
||||
which can be expressed with integers as
|
||||
|
||||
Y = (54 * R + 183 * G + 19 * B)/256
|
||||
|
||||
The calculation is done in a linear colorspace, if the image gamma
|
||||
is known.
|
||||
|
||||
If you have a grayscale and you are using png_set_expand_depth() or
|
||||
png_set_expand() to change to
|
||||
a higher bit-depth, you must either supply the background color as a gray
|
||||
value at the original file bit-depth (need_expand = 1) or else supply the
|
||||
background color as an RGB triplet at the final, expanded bit depth
|
||||
@@ -609,17 +697,17 @@ or as an RGB triplet that may or may not be in the palette (need_expand = 0).
|
||||
To properly display PNG images on any kind of system, the application needs
|
||||
to know what the display gamma is. Ideally, the user will know this, and
|
||||
the application will allow them to set it. One method of allowing the user
|
||||
to set the display gamma separately for each system is to check for the
|
||||
DISPLAY_GAMMA and VIEWING_GAMMA environment variables or for a SCREEN_GAMMA
|
||||
environment variable, which will hopefully be correctly set.
|
||||
to set the display gamma separately for each system is to check for a
|
||||
SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
|
||||
correctly set.
|
||||
|
||||
Note that display_gamma is the gamma of your display, while screen_gamma is
|
||||
the overall gamma correction required to produce pleasing results,
|
||||
which depends on the lighting conditions in the surrounding environment.
|
||||
Screen_gamma is display_gamma/viewing_gamma, where viewing_gamma is
|
||||
the amount of additional gamma correction needed to compensate for
|
||||
a (viewing_gamma=1.25) environment. In a dim or brightly lit room, no
|
||||
compensation other than the display_gamma is needed (viewing_gamma=1.0).
|
||||
Note that display_gamma is the overall gamma correction required to produce
|
||||
pleasing results, which depends on the lighting conditions in the surrounding
|
||||
environment. In a dim or brightly lit room, no compensation other than
|
||||
the physical gamma exponent of the monitor is needed, while in a dark room
|
||||
a slightly smaller exponent is better.
|
||||
|
||||
double gamma, screen_gamma;
|
||||
|
||||
if (/* We have a user-defined screen
|
||||
gamma value */)
|
||||
@@ -631,7 +719,7 @@ compensation other than the display_gamma is needed (viewing_gamma=1.0).
|
||||
else if ((gamma_str = getenv("SCREEN_GAMMA"))
|
||||
!= NULL)
|
||||
{
|
||||
screen_gamma = atof(gamma_str);
|
||||
screen_gamma = (double)atof(gamma_str);
|
||||
}
|
||||
/* If we don't have another value */
|
||||
else
|
||||
@@ -647,7 +735,7 @@ compensation other than the display_gamma is needed (viewing_gamma=1.0).
|
||||
The png_set_gamma() function handles gamma transformations of the data.
|
||||
Pass both the file gamma and the current screen_gamma. If the file does
|
||||
not have a gamma value, you can pass one anyway if you have an idea what
|
||||
it is (usually 0.50 is a good guess for GIF images on PCs). Note
|
||||
it is (usually 0.45455 is a good guess for GIF images on PCs). Note
|
||||
that file gammas are inverted from screen gammas. See the discussions
|
||||
on gamma in the PNG specification for an excellent description of what
|
||||
gamma is, and why all applications should support it. It is strongly
|
||||
@@ -656,7 +744,7 @@ recommended that PNG viewers support gamma correction.
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
|
||||
png_set_gamma(png_ptr, screen_gamma, gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.50);
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
|
||||
If you need to reduce an RGB file to a paletted file, or if a paletted
|
||||
file has more entries then will fit on your screen, png_set_dither()
|
||||
@@ -771,7 +859,7 @@ row_pointers:
|
||||
png_read_row(png_ptr, &row_pointers, NULL);
|
||||
|
||||
If the file is interlaced (info_ptr->interlace_type != 0), things get
|
||||
somewhat harder. The only current (PNG Specification version 1.0)
|
||||
somewhat harder. The only current (PNG Specification version 1.2)
|
||||
interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
|
||||
is a somewhat complicated 2D interlace scheme, known as Adam7, that
|
||||
breaks down an image into seven smaller images of varying size, based
|
||||
@@ -907,7 +995,9 @@ png_infop info_ptr;
|
||||
to be called when the header info is valid,
|
||||
when each row is completed, and when the image
|
||||
is finished. If you aren't using all functions,
|
||||
you can specify a NULL parameter. You can use
|
||||
you can specify NULL parameters. Even when all
|
||||
three functions are NULL, you need to call
|
||||
png_set_progressive_read_fn(). You can use
|
||||
any struct as the user_ptr (cast to a void pointer
|
||||
for the function call), and retrieve the pointer
|
||||
from inside the callbacks using the function
|
||||
@@ -939,21 +1029,21 @@ png_infop info_ptr;
|
||||
of data from the file stream (in order, of
|
||||
course). On machines with segmented memory
|
||||
models machines, don't give it any more than
|
||||
64K. The library seems to run fine with sizes
|
||||
64K. The library seems to run fine with sizes
|
||||
of 4K. Although you can give it much less if
|
||||
necessary (I assume you can give it chunks of
|
||||
1 byte, I haven't tried less then 256 bytes
|
||||
yet). When this function returns, you may
|
||||
want to display any rows that were generated
|
||||
in the row callback if you don't already do
|
||||
so there.
|
||||
so there.
|
||||
*/
|
||||
png_process_data(png_ptr, info_ptr, buffer, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function is called (as set by
|
||||
png_set_progressive_fn() above) when enough data
|
||||
png_set_progressive_read_fn() above) when enough data
|
||||
has been supplied so all of the header has been
|
||||
read.
|
||||
*/
|
||||
@@ -1010,7 +1100,7 @@ png_infop info_ptr;
|
||||
for interlaced images), you will have to pass
|
||||
the current row, and the function will combine
|
||||
the old row and the new row.
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1040,7 +1130,7 @@ You will want to do the I/O initialization before you get into libpng,
|
||||
so if it doesn't work, you don't have anything to undo. If you are not
|
||||
using the standard I/O functions, you will need to replace them with
|
||||
custom writing functions. See the discussion under Customizing libpng.
|
||||
|
||||
|
||||
FILE *fp = fopen(file_name, "wb");
|
||||
if (!fp)
|
||||
{
|
||||
@@ -1081,20 +1171,22 @@ png_create_write_struct_2() instead of png_create_read_struct():
|
||||
After you have these structures, you will need to set up the
|
||||
error handling. When libpng encounters an error, it expects to
|
||||
longjmp() back to your routine. Therefore, you will need to call
|
||||
setjmp and pass the jmpbuf field of your png_struct. If you
|
||||
setjmp() and pass the png_ptr->jmpbuf. If you
|
||||
write the file from different routines, you will need to update
|
||||
the jmpbuf field every time you enter a new routine that will
|
||||
call a png_ function. See your documentation of setjmp/longjmp
|
||||
for your compiler for more information on setjmp/longjmp. See
|
||||
the discussion on libpng error handling in the Customizing Libpng
|
||||
section below for more information on the libpng error handling.
|
||||
|
||||
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
{
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
...
|
||||
return;
|
||||
|
||||
Now you need to set up the output code. The default for libpng is to
|
||||
use the C function fwrite(). If you use this, you will need to pass a
|
||||
@@ -1130,12 +1222,12 @@ have no special needs in this area, let the library do what it wants by
|
||||
not calling this function at all, as it has been tuned to deliver a good
|
||||
speed/compression ratio. The second parameter to png_set_filter() is
|
||||
the filter method, for which the only valid value is '0' (as of the
|
||||
October 1996 PNG specification, version 1.0). The third parameter is a
|
||||
July 1999 PNG specification, version 1.2). The third parameter is a
|
||||
flag that indicates which filter type(s) are to be tested for each
|
||||
scanline. See the Compression Library for details on the specific filter
|
||||
types.
|
||||
|
||||
|
||||
|
||||
/* turn on or off filtering, and/or choose
|
||||
specific filters */
|
||||
png_set_filter(png_ptr, 0,
|
||||
@@ -1162,7 +1254,7 @@ data. See the Compression Library for details on the compression levels.
|
||||
You now need to fill in the png_info structure with all the data you
|
||||
wish to write before the actual image. Note that the only thing you
|
||||
are allowed to write after the image is the text chunks and the time
|
||||
chunk (as of PNG Specification 1.0, anyway). See png_write_end() and
|
||||
chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
|
||||
the latest PNG specification for more information on that. If you
|
||||
wish to write them before the image, fill them in now, and flag that
|
||||
data as being valid. If you want to wait until after the data, don't
|
||||
@@ -1230,11 +1322,11 @@ Some of the more important parts of the png_info are:
|
||||
Color Consortium
|
||||
(http://www.color.org).
|
||||
It can be one of
|
||||
PNG_SRGB_INTENT_SATURATION,
|
||||
PNG_SRGB_INTENT_PERCEPTUAL,
|
||||
PNG_SRGB_INTENT_ABSOLUTE, or
|
||||
PNG_SRGB_INTENT_RELATIVE.
|
||||
|
||||
PNG_sRGB_INTENT_SATURATION,
|
||||
PNG_sRGB_INTENT_PERCEPTUAL,
|
||||
PNG_sRGB_INTENT_ABSOLUTE, or
|
||||
PNG_sRGB_INTENT_RELATIVE.
|
||||
|
||||
|
||||
png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
|
||||
srgb_intent);
|
||||
@@ -1325,7 +1417,7 @@ png_text structure holds a keyword-text value, and a compression type.
|
||||
The compression types have the same valid numbers as the compression
|
||||
types of the image data. Currently, the only valid number is zero.
|
||||
However, you can store text either compressed or uncompressed, unlike
|
||||
images which always have to be compressed. So if you don't want the
|
||||
images, which always have to be compressed. So if you don't want the
|
||||
text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
|
||||
Until text gets around 1000 bytes, it is not worth compressing it.
|
||||
After the text has been written out to the file, the compression type
|
||||
@@ -1385,7 +1477,7 @@ depending on whether you mean the PNG file, the time the image was
|
||||
created in a non-PNG format, a still photo from which the image was
|
||||
scanned, or possibly the subject matter itself. In order to facilitate
|
||||
machine-readable dates, it is recommended that the "Creation Time"
|
||||
tEXt chunk use RFC 1123 format dates (e.g. 22 May 1997 18:07:10 GMT"),
|
||||
tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
|
||||
although this isn't a requirement. Unlike the tIME chunk, the
|
||||
"Creation Time" tEXt chunk is not expected to be automatically changed
|
||||
by the software. To facilitate the use of RFC 1123 dates, a function
|
||||
@@ -1397,6 +1489,14 @@ image data. You do this with a call to png_write_info().
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
If you need to write a private chunk that you want to appear before
|
||||
the PLTE chunk when PLTE is present, you can write the PNG info in
|
||||
two steps, and insert code to write your own chunk between them:
|
||||
|
||||
png_write_info_before_PLTE(png_ptr, info_ptr);
|
||||
write_my_private_chunks();
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
After you've written the file information, you can set up the library
|
||||
to handle any special transformations of the image data. The various
|
||||
ways to transform the data will be described in the order that they
|
||||
@@ -1427,7 +1527,7 @@ correctly pack the pixels into a single byte:
|
||||
PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
|
||||
data is of another bit depth, you can write an sBIT chunk into the
|
||||
file so that decoders can get the original data if desired.
|
||||
|
||||
|
||||
/* Set the true bit depth of the image data */
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
@@ -1488,10 +1588,24 @@ with
|
||||
You must supply the function
|
||||
|
||||
void write_transform_fn(png_ptr ptr, row_info_ptr
|
||||
row_info, png_bytep data)
|
||||
row_info, png_bytep data)
|
||||
|
||||
See pngtest.c for a working example. Your function will be called
|
||||
before any of the other transformations have been processed.
|
||||
before any of the other transformations are processed.
|
||||
|
||||
You can also set up a pointer to a user structure for use by your
|
||||
callback function.
|
||||
|
||||
png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
|
||||
|
||||
The user_channels and user_depth parameters of this function are ignored
|
||||
when writing; you can set them to zero as shown.
|
||||
|
||||
You can retrieve the pointer via the function
|
||||
png_get_user_transform_ptr(). For example:
|
||||
|
||||
voidp write_user_transform_ptr =
|
||||
png_get_user_transform_ptr(png_ptr);
|
||||
|
||||
It is possible to have libpng flush any pending output, either manually,
|
||||
or automatically after a certain number of lines have been written. To
|
||||
@@ -1548,8 +1662,8 @@ row_pointers:
|
||||
png_write_row(png_ptr, &row_pointer);
|
||||
|
||||
When the file is interlaced, things can get a good deal more
|
||||
complicated. The only currently (as of February 1998 -- PNG Specification
|
||||
version 1.0, dated October 1996) defined interlacing scheme for PNG files
|
||||
complicated. The only currently (as of August 1999 -- PNG Specification
|
||||
version 1.2, dated July 1999) defined interlacing scheme for PNG files
|
||||
is the "Adam7" interlace scheme, that breaks down an
|
||||
image into seven smaller images of varying size. libpng will build
|
||||
these images for you, or you can do them yourself. If you want to
|
||||
@@ -1594,7 +1708,6 @@ palette, or histogram, before the call to png_destroy_write_struct();
|
||||
|
||||
For a more compact example of writing a PNG image, see the file example.c.
|
||||
|
||||
|
||||
V. Modifying/Customizing libpng:
|
||||
|
||||
There are two issues here. The first is changing how libpng does
|
||||
@@ -1603,7 +1716,7 @@ The second deals with more complicated things like adding new chunks,
|
||||
adding new transformations, and generally changing how libpng works.
|
||||
|
||||
All of the memory allocation, input/output, and error handling in libpng
|
||||
goes through callbacks which are user settable. The default routines are
|
||||
goes through callbacks that are user settable. The default routines are
|
||||
in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively. To change
|
||||
these functions, call the appropriate png_set_???_fn() function.
|
||||
|
||||
@@ -1621,7 +1734,8 @@ which currently just call fread() and fwrite(). The FILE * is stored in
|
||||
png_struct and is initialized via png_init_io(). If you wish to change
|
||||
the method of I/O, the library supplies callbacks that you can set
|
||||
through the function png_set_read_fn() and png_set_write_fn() at run
|
||||
time, instead of calling the png_init_io() function. These functions
|
||||
time, instead of calling the png_init_io() function.
|
||||
These functions
|
||||
also provide a void pointer that can be retrieved via the function
|
||||
png_get_io_ptr(). For example:
|
||||
|
||||
@@ -1645,7 +1759,7 @@ The replacement I/O functions should have prototypes as follows:
|
||||
|
||||
Supplying NULL for the read, write, or flush functions sets them back
|
||||
to using the default C stream functions. It is an error to read from
|
||||
a write stream, and vice versa.
|
||||
a write stream, and vice versa.
|
||||
|
||||
Error handling in libpng is done through png_error() and png_warning().
|
||||
Errors handled through png_error() are fatal, meaning that png_error()
|
||||
@@ -1691,7 +1805,7 @@ a first level of understanding of how it works. Pay particular attention
|
||||
to the sections that describe chunk names, and look at how other chunks
|
||||
were designed, so you can do things similarly. Second, check out the
|
||||
sections of libpng that read and write chunks. Try to find a chunk that
|
||||
is similar to yours and copy off of it. More details can be found in the
|
||||
is similar to yours and use it as a template. More details can be found in the
|
||||
comments inside the code. A way of handling unknown chunks in a generic
|
||||
method, potentially via callback functions, would be best.
|
||||
|
||||
@@ -1712,7 +1826,7 @@ won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
|
||||
|
||||
Configuring for DOS:
|
||||
|
||||
For DOS users which only have access to the lower 640K, you will
|
||||
For DOS users who only have access to the lower 640K, you will
|
||||
have to limit zlib's memory usage via a png_set_compression_mem_level()
|
||||
call. See zlib.h or zconf.h in the zlib library for more information.
|
||||
|
||||
@@ -1724,7 +1838,7 @@ defined, and FAR gets defined to far in pngconf.h, and you should be
|
||||
all set. Everything in the library (except for zlib's structure) is
|
||||
expecting far data. You must use the typedefs with the p or pp on
|
||||
the end for pointers (or at least look at them and be careful). Make
|
||||
note that the row's of data are defined as png_bytepp which is a
|
||||
note that the row's of data are defined as png_bytepp, which is an
|
||||
unsigned char far * far *.
|
||||
|
||||
Configuring for gui/windowing platforms:
|
||||
@@ -1784,11 +1898,11 @@ can call one of these functions. The selection and configuration
|
||||
of row filters can have a significant impact on the size and
|
||||
encoding speed and a somewhat lesser impact on the decoding speed
|
||||
of an image. Filtering is enabled by default for RGB and grayscale
|
||||
images (with and without alpha), and for 8-bit paletted images, but
|
||||
not for paletted images with bit depths less than 8 bits/pixel.
|
||||
images (with and without alpha), but not for paletted images nor
|
||||
for any images with bit depths less than 8 bits/pixel.
|
||||
|
||||
The 'method' parameter sets the main filtering method, which is
|
||||
currently only '0' in the PNG 1.0 specification. The 'filters'
|
||||
currently only '0' in the PNG 1.2 specification. The 'filters'
|
||||
parameter sets which filter(s), if any, should be used for each
|
||||
scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
|
||||
to turn filtering on and off, respectively.
|
||||
@@ -1820,10 +1934,10 @@ by telling it the relative computational costs of the filters.
|
||||
PNG_FILTER_SELECTION_WEIGHTED, 3,
|
||||
weights, costs);
|
||||
|
||||
The weights are multiplying factors which indicate to libpng that row
|
||||
should be the same for successive rows unless another row filter is that
|
||||
many times better than the previous filter. In the above example, if
|
||||
the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
|
||||
The weights are multiplying factors that indicate to libpng that the
|
||||
row filter should be the same for successive rows unless another row filter
|
||||
is that many times better than the previous filter. In the above example,
|
||||
if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
|
||||
"sum of absolute differences" 1.5 x 1.3 times higher than other filters
|
||||
and still be chosen, while the NONE filter could have a sum 1.1 times
|
||||
higher than other filters and still be chosen. Unspecified weights are
|
||||
@@ -1878,10 +1992,46 @@ or DLL file), you should not remove or disable any parts of the library,
|
||||
as this will cause applications linked with different versions of the
|
||||
library to fail if they call functions not available in your library.
|
||||
The size of the library itself should not be an issue, because only
|
||||
those sections which are actually used will be loaded into memory.
|
||||
those sections that are actually used will be loaded into memory.
|
||||
|
||||
Requesting debug printout:
|
||||
|
||||
Changes to Libpng from version 0.88
|
||||
The macro definition PNG_DEBUG can be used to request debugging
|
||||
printout. Set it to an integer value in the range 0 to 3. Higher
|
||||
numbers result in increasing amounts of debugging information. The
|
||||
information is printed to the "stderr" file, unless another file
|
||||
name is specified in the PNG_DEBUG_FILE macro definition.
|
||||
|
||||
When PNG_DEBUG > 0, the following functions (macros) become available:
|
||||
|
||||
png_debug(level, message)
|
||||
png_debug1(level, message, p1)
|
||||
png_debug2(level, message, p1, p2)
|
||||
|
||||
in which "level" is compared to PNG_DEBUG to decide whether to print
|
||||
the message, "message" is the formatted string to be printed,
|
||||
and p1 and p2 are parameters that are to be embedded in the string
|
||||
according to printf-style formatting directives. For example,
|
||||
|
||||
png_debug1(2, "foo=%d\n", foo);
|
||||
|
||||
is expanded to
|
||||
|
||||
if(PNG_DEBUG > 2)
|
||||
fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
|
||||
|
||||
When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
|
||||
can still use PNG_DEBUG to control your own debugging:
|
||||
|
||||
#ifdef PNG_DEBUG
|
||||
fprintf(stderr, ...
|
||||
#endif
|
||||
|
||||
When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
|
||||
having level = 0 will be printed. There aren't any such statements in
|
||||
this version of libpng, but if you insert some they will be printed.
|
||||
|
||||
VI. Changes to Libpng from version 0.88
|
||||
|
||||
It should be noted that versions of libpng later than 0.96 are not
|
||||
distributed by the original libpng author, Guy Schalnat, nor by
|
||||
@@ -1907,9 +2057,64 @@ allocating and freeing the png_struct for each image read.
|
||||
|
||||
Setting the error callbacks via png_set_message_fn() before
|
||||
png_read_init() as was suggested in libpng-0.88 is no longer supported
|
||||
because this caused applications which do not use custom error functions
|
||||
because this caused applications that do not use custom error functions
|
||||
to fail if the png_ptr was not initialized to zero. It is still possible
|
||||
to set the error callbacks AFTER png_read_init(), or to change them with
|
||||
png_set_error_fn(), which is essentially the same function, but with a
|
||||
new name to force compilation errors with applications that try to use
|
||||
the old method.
|
||||
|
||||
VII. Y2K Compliance in libpng
|
||||
|
||||
November 29, 1999
|
||||
|
||||
Since the PNG Development group is an ad-hoc body, we can't make
|
||||
an official declaration.
|
||||
|
||||
This is your unofficial assurance that libpng from version 0.71 and
|
||||
upward through 1.0.5d are Y2K compliant. It is my belief that earlier
|
||||
versions were also Y2K compliant.
|
||||
|
||||
Libpng only has three year fields. One is a 2-byte unsigned integer that
|
||||
will hold years up to 65535. The other two hold the date in text
|
||||
format, and will hold years up to 9999.
|
||||
|
||||
The integer is
|
||||
"png_uint_16 year" in png_time_struct.
|
||||
|
||||
The strings are
|
||||
"png_charp time_buffer" in png_struct and
|
||||
"near_time_buffer", which is a local character string in png.c.
|
||||
|
||||
There are seven time-related functions:
|
||||
|
||||
png_convert_to_rfc_1123() in png.c
|
||||
(formerly png_convert_to_rfc_1152() in error)
|
||||
png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
|
||||
png_convert_from_time_t() in pngwrite.c
|
||||
png_get_tIME() in pngget.c
|
||||
png_handle_tIME() in pngrutil.c, called in pngread.c
|
||||
png_set_tIME() in pngset.c
|
||||
png_write_tIME() in pngwutil.c, called in pngwrite.c
|
||||
|
||||
All appear to handle dates properly in a Y2K environment. The
|
||||
png_convert_from_time_t() function calls gmtime() to convert from system
|
||||
clock time, which returns (year - 1900), which we properly convert to
|
||||
the full 4-digit year. There is a possibility that applications using
|
||||
libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
|
||||
function, or that they are incorrectly passing only a 2-digit year
|
||||
instead of "year - 1900" into the png_convert_from_struct_tm() function,
|
||||
but this is not under our control. The libpng documentation has always
|
||||
stated that it works with 4-digit years, and the APIs have been
|
||||
documented as such.
|
||||
|
||||
The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
|
||||
integer to hold the year, and can hold years as large as 65535.
|
||||
|
||||
zlib, upon which libpng depends, is also Y2K compliant. It contains
|
||||
no date-related code.
|
||||
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
libpng maintainer
|
||||
PNG Development Group
|
||||
|
||||
584
libpngpf.3
@@ -1,339 +1,497 @@
|
||||
.TH LIBPNGPF 3 "June 14, 1998"
|
||||
.TH LIBPNGPF 3 November 29, 1999
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.2 - June 14, 1998
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.5d - November 29, 1999
|
||||
(private functions)
|
||||
.SH SYNOPSIS
|
||||
#include <png.h>
|
||||
\fB#include <png.h>\fP
|
||||
|
||||
void png_build_gamma_table (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_build_grayscale_palette (int bit_depth, png_colorp
|
||||
palette);
|
||||
\fBvoid png_build_gamma_table (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
void png_calculate_crc (png_structp png_ptr, png_bytep ptr,
|
||||
png_size_t length);
|
||||
void png_check_chunk_name (png_structp png_ptr, png_bytep
|
||||
chunk_name);
|
||||
\fI\fB
|
||||
|
||||
png_size_t png_check_keyword (png_structp png_ptr, png_charp
|
||||
key, png_charpp new_key);
|
||||
\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
|
||||
|
||||
void png_combine_row (png_structp png_ptr, png_bytep row, int
|
||||
mask);
|
||||
\fI\fB
|
||||
|
||||
void png_correct_palette (png_structp png_ptr, png_colorp
|
||||
palette, int num_palette);
|
||||
\fBvoid png_calculate_crc (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIptr\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||
|
||||
int png_crc_error (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
int png_crc_finish (png_structp png_ptr, png_uint_32 skip);
|
||||
\fBvoid png_check_chunk_name (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
|
||||
|
||||
void png_crc_read (png_structp png_ptr, png_bytep buf,
|
||||
png_size_t length);
|
||||
\fI\fB
|
||||
|
||||
png_voidp png_create_struct (int type, png_malloc_ptr malloc_fn);
|
||||
\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
|
||||
|
||||
png_voidp png_create_struct_2 (int type);
|
||||
\fI\fB
|
||||
|
||||
void png_destroy_struct (png_voidp struct_ptr);
|
||||
\fBvoid png_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fImask\fP\fB);\fP
|
||||
|
||||
void png_destroy_struct_2 (png_voidp struct_ptr, png_free_ptr
|
||||
free_fn);
|
||||
\fI\fB
|
||||
|
||||
void png_do_background (png_row_infop row_info, png_bytep row,
|
||||
png_color_16p trans_values, png_color_16p background,
|
||||
png_color_16p background_1, png_bytep gamma_table, png_bytep
|
||||
gamma_from_1, png_bytep gamma_to_1, png_uint_16pp gamma_16,
|
||||
png_uint_16pp gamma_16_from_1, png_uint_16pp gamma_16_to_1, int
|
||||
gamma_shift);
|
||||
\fBvoid png_correct_palette (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
|
||||
|
||||
void png_do_bgr (png_row_infop row_info, png_bytep row);
|
||||
\fI\fB
|
||||
|
||||
void png_do_chop (png_row_infop row_info, png_bytep row);
|
||||
\fBint png_crc_error (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
void png_do_dither (png_row_infop row_info, png_bytep row,
|
||||
png_bytep palette_lookup, png_bytep dither_lookup);
|
||||
\fI\fB
|
||||
|
||||
void png_do_expand (png_row_infop row_info, png_bytep row,
|
||||
png_color_16p trans_value);
|
||||
\fBint png_crc_finish (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIskip\fP\fB);\fP
|
||||
|
||||
void png_do_expand_palette (png_row_infop row_info, png_bytep
|
||||
row, png_colorp palette, png_bytep trans, int num_trans);
|
||||
\fI\fB
|
||||
|
||||
void png_do_gamma (png_row_infop row_info, png_bytep row,
|
||||
png_bytep gamma_table, png_uint_16pp gamma_16_table, int
|
||||
gamma_shift);
|
||||
\fBvoid png_crc_read (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuf\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||
|
||||
void png_do_gray_to_rgb (png_row_infop row_info, png_bytep
|
||||
row);
|
||||
\fI\fB
|
||||
|
||||
void png_do_invert (png_row_infop row_info, png_bytep row);
|
||||
\fBpng_voidp png_create_struct (int \fP\fItype\fP\fB, png_malloc_ptr \fImalloc_fn\fP\fB);\fP
|
||||
|
||||
void png_do_pack (png_row_infop row_info, png_bytep row,
|
||||
png_uint_32 bit_depth);
|
||||
\fI\fB
|
||||
|
||||
void png_do_packswap (png_row_infop row_info, png_bytep row);
|
||||
\fBpng_voidp png_create_struct_2 (int \fItype\fP\fB);\fP
|
||||
|
||||
void png_do_read_filler (png_row_infop row_info, png_bytep row,
|
||||
png_uint_32 filler, png_uint_32 flags);
|
||||
\fI\fB
|
||||
|
||||
void png_do_read_interlace (png_row_infop row_info, png_bytep
|
||||
row, int pass, png_uint_32 transformations);
|
||||
\fBvoid png_destroy_struct (png_voidp \fIstruct_ptr\fP\fB);\fP
|
||||
|
||||
void png_do_read_invert_alpha (png_row_infop row_info,
|
||||
png_bytep row);
|
||||
\fI\fB
|
||||
|
||||
void png_do_read_swap_alpha (png_row_infop row_info, png_bytep
|
||||
row);
|
||||
\fBvoid png_destroy_struct_2 (png_voidp \fP\fIstruct_ptr\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
|
||||
|
||||
void png_do_read_transformations (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_do_rgb_to_gray (png_row_infop row_info, png_bytep
|
||||
row);
|
||||
\fBvoid png_do_background (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fP\fItrans_values\fP\fB, png_color_16p \fP\fIbackground\fP\fB, png_color_16p \fP\fIbackground_1\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_bytep \fP\fIgamma_from_1\fP\fB, png_bytep \fP\fIgamma_to_1\fP\fB, png_uint_16pp \fP\fIgamma_16\fP\fB, png_uint_16pp \fP\fIgamma_16_from_1\fP\fB, png_uint_16pp \fP\fIgamma_16_to_1\fP\fB, int \fIgamma_shift\fP\fB);\fP
|
||||
|
||||
void png_do_shift (png_row_infop row_info, png_bytep row,
|
||||
png_color_8p bit_depth);
|
||||
\fI\fB
|
||||
|
||||
void png_do_strip_filler (png_row_infop row_info, png_bytep
|
||||
row, png_uint_32 flags);
|
||||
\fBvoid png_do_bgr (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_do_swap (png_row_infop row_info, png_bytep row);
|
||||
\fI\fB
|
||||
|
||||
void png_do_unpack (png_row_infop row_info, png_bytep row);
|
||||
\fBvoid png_do_chop (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_do_unshift (png_row_infop row_info, png_bytep row,
|
||||
png_color_8p sig_bits);
|
||||
\fI\fB
|
||||
|
||||
void png_do_write_interlace (png_row_infop row_info, png_bytep
|
||||
row, int pass);
|
||||
\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
|
||||
|
||||
void png_do_write_invert_alpha (png_row_infop row_info,
|
||||
png_bytep row);
|
||||
\fI\fB
|
||||
|
||||
void png_do_write_swap_alpha (png_row_infop row_info, png_bytep
|
||||
row);
|
||||
\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
|
||||
|
||||
void png_do_write_transformations (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void *png_far_to_near (png_structp png_ptr,png_voidp ptr,
|
||||
int check);
|
||||
\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
|
||||
|
||||
void png_flush (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
png_int_32 png_get_int_32 (png_bytep buf);
|
||||
\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
|
||||
|
||||
png_uint_16 png_get_uint_16 (png_bytep buf);
|
||||
\fI\fB
|
||||
|
||||
png_uint_32 png_get_uint_32 (png_bytep buf);
|
||||
\fBvoid png_do_gray_to_rgb (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_handle_bKGD (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_cHRM (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fBvoid png_do_invert (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_handle_gAMA (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_hIST (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\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
|
||||
|
||||
void png_handle_IEND (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_IHDR (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fBvoid png_do_packswap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_handle_oFFs (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_pCAL (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\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
|
||||
|
||||
void png_handle_pHYs (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_PLTE (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\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
|
||||
|
||||
void png_handle_sBIT (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_sRGB (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fBvoid png_do_read_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_handle_tEXt (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_tIME (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fBvoid png_do_read_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_handle_tRNS (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_handle_unknown (png_structp png_ptr, png_infop
|
||||
info_ptr, png_uint_32 length);
|
||||
\fBvoid png_do_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
void png_handle_zTXt (png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_info_destroy (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fBint png_do_rgb_to_gray (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_init_read_transformations (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_process_IDAT_data (png_structp png_ptr, png_bytep
|
||||
buffer, png_size_t buffer_length);
|
||||
\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
|
||||
|
||||
void png_process_some_data (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_push_check_crc (png_structp png_ptr);
|
||||
\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
|
||||
|
||||
void png_push_crc_finish (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_push_crc_skip (png_structp png_ptr, png_uint_32
|
||||
length);
|
||||
\fBvoid png_do_swap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_push_fill_buffer (png_structp png_ptr, png_bytep
|
||||
buffer, png_size_t length);
|
||||
\fI\fB
|
||||
|
||||
void png_push_handle_tEXt (png_structp png_ptr, png_infop
|
||||
info_ptr, png_uint_32 length);
|
||||
\fBvoid png_do_unpack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_push_handle_unknown (png_structp png_ptr, png_infop
|
||||
info_ptr, png_uint_32 length);
|
||||
\fI\fB
|
||||
|
||||
void png_push_handle_zTXt (png_structp png_ptr, png_infop
|
||||
info_ptr, png_uint_32 length);
|
||||
\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
|
||||
|
||||
void png_push_have_end (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_push_have_info (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fBvoid png_do_write_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fIpass\fP\fB);\fP
|
||||
|
||||
void png_push_have_row (png_structp png_ptr, png_bytep row);
|
||||
\fI\fB
|
||||
|
||||
void png_push_process_row (png_structp png_ptr);
|
||||
\fBvoid png_do_write_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_push_read_chunk (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_push_read_end (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fBvoid png_do_write_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
void png_push_read_IDAT (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_push_read_sig (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fBvoid png_do_write_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
void png_push_read_tEXt (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_push_read_zTXt (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fBvoid *png_far_to_near (png_structp png_ptr,png_voidp \fP\fIptr\fP\fB, int \fIcheck\fP\fB);\fP
|
||||
|
||||
void png_push_restore_buffer (png_structp png_ptr, png_bytep
|
||||
buffer, png_size_t buffer_length);
|
||||
\fI\fB
|
||||
|
||||
void png_push_save_buffer (png_structp png_ptr);
|
||||
\fBvoid png_flush (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
void png_read_data (png_structp png_ptr, png_bytep data,
|
||||
png_size_t length);
|
||||
\fI\fB
|
||||
|
||||
void png_read_filter_row (png_structp png_ptr, png_row_infop
|
||||
row_info, png_bytep row, png_bytep prev_row, int filter);
|
||||
\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
|
||||
|
||||
void png_read_finish_row (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_read_init (png_structp png_ptr);
|
||||
\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
|
||||
|
||||
void png_read_push_finish_row (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_read_start_row (png_structp png_ptr);
|
||||
\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
|
||||
|
||||
void png_read_transform_info (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_reset_crc (png_structp png_ptr);
|
||||
\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
|
||||
|
||||
void png_save_int_32 (png_bytep buf, png_int_32 i);
|
||||
\fI\fB
|
||||
|
||||
void png_save_uint_16 (png_bytep buf, unsigned int i);
|
||||
\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
|
||||
|
||||
void png_save_uint_32 (png_bytep buf, png_uint_32 i);
|
||||
\fI\fB
|
||||
|
||||
void png_write_bKGD (png_structp png_ptr, png_color_16p values,
|
||||
int color_type);
|
||||
\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
|
||||
|
||||
void png_write_cHRM (png_structp png_ptr, double white_x,
|
||||
double white_y, double red_x, double red_y, double green_x,
|
||||
double green_y, double blue_x, double blue_y);
|
||||
\fI\fB
|
||||
|
||||
void png_write_data (png_structp png_ptr, png_bytep data,
|
||||
png_size_t length);
|
||||
void png_write_filtered_row (png_structp png_ptr, png_bytep
|
||||
filtered_row);
|
||||
\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
|
||||
|
||||
void png_write_find_filter (png_structp png_ptr, png_row_infop
|
||||
row_info);
|
||||
\fI\fB
|
||||
|
||||
void png_write_finish_row (png_structp png_ptr);
|
||||
\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
|
||||
|
||||
void png_write_gAMA (png_structp png_ptr, double file_gamma);
|
||||
\fI\fB
|
||||
|
||||
void png_write_hIST (png_structp png_ptr, png_uint_16p hist,
|
||||
int num_hist);
|
||||
\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
|
||||
|
||||
void png_write_init (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_write_IDAT (png_structp png_ptr, png_bytep data,
|
||||
png_size_t length);
|
||||
\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
|
||||
|
||||
void png_write_IEND (png_structp png_ptr);
|
||||
\fI\fB
|
||||
|
||||
void png_write_IHDR (png_structp png_ptr, png_uint_32 width,
|
||||
png_uint_32 height, int bit_depth, int color_type, int
|
||||
compression_type, int filter_type, int interlace_type);
|
||||
\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
|
||||
|
||||
void png_write_oFFs (png_structp png_ptr, png_uint_32 x_offset,
|
||||
png_uint_32 y_offset, int unit_type);
|
||||
\fI\fB
|
||||
|
||||
void png_write_pCAL (png_structp png_ptr, png_charp purpose,
|
||||
png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp
|
||||
units, png_charpp params);
|
||||
\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
|
||||
|
||||
void png_write_pHYs (png_structp png_ptr, png_uint_32
|
||||
x_pixels_per_unit, png_uint_32 y_pixels_per_unit, int
|
||||
unit_type);
|
||||
\fI\fB
|
||||
|
||||
void png_write_PLTE (png_structp png_ptr, png_colorp palette,
|
||||
png_uint_32 num_pal);
|
||||
\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
|
||||
|
||||
void png_write_sBIT (png_structp png_ptr, png_color_8p sbit,
|
||||
int color_type);
|
||||
\fI\fB
|
||||
|
||||
void png_write_sig (png_structp png_ptr);
|
||||
\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
|
||||
|
||||
void png_write_sRGB (png_structp png_ptr, int intent);
|
||||
\fI\fB
|
||||
|
||||
void png_write_start_row (png_structp png_ptr);
|
||||
\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
|
||||
|
||||
void png_write_tEXt (png_structp png_ptr, png_charp key,
|
||||
png_charp text, png_size_t text_len);
|
||||
\fI\fB
|
||||
|
||||
void png_write_tIME (png_structp png_ptr, png_timep mod_time);
|
||||
\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
|
||||
|
||||
void png_write_tRNS (png_structp png_ptr, png_bytep trans,
|
||||
png_color_16p values, int number, int color_type);
|
||||
\fI\fB
|
||||
|
||||
void png_write_zTXt (png_structp png_ptr, png_charp key,
|
||||
png_charp text, png_size_t text_len, int compression);
|
||||
\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
|
||||
|
||||
voidpf png_zalloc (voidpf png_ptr, uInt items, uInt size);
|
||||
\fI\fB
|
||||
|
||||
void png_zfree (voidpf png_ptr, voidpf ptr);
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\fBvoid png_info_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_init_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_process_some_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_check_crc (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_crc_finish (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_crc_skip (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_have_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_have_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_have_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_process_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_read_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_read_IDAT (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_read_sig (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_read_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_read_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_push_save_buffer (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_init (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_push_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_read_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_reset_crc (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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_filtered_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIfiltered_row\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_find_filter (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fIrow_info\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_gAMA (png_structp \fP\fIpng_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_IDAT (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_IEND (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_sRGB (png_structp \fP\fIpng_ptr\fP\fB, int \fIintent\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
|
||||
|
||||
\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
|
||||
|
||||
\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
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
.SH DESCRIPTION
|
||||
The functions listed above are used privately by libpng
|
||||
|
||||
26
png.5
@@ -1,4 +1,4 @@
|
||||
.TH PNG 5 "June 14, 1998"
|
||||
.TH PNG 5 "November 29, 1999"
|
||||
.SH NAME
|
||||
png \- Portable Network Graphics (PNG) format
|
||||
.SH DESCRIPTION
|
||||
@@ -7,7 +7,7 @@ lossless, portable, well-compressed storage of raster images. PNG provides
|
||||
a patent-free replacement for GIF and can also replace many
|
||||
common uses of TIFF. Indexed-color, grayscale, and truecolor images are
|
||||
supported, plus an optional alpha channel. Sample depths range from
|
||||
1 to 16 bits.
|
||||
1 to 16 bits.
|
||||
.br
|
||||
|
||||
PNG is designed to work well in online viewing applications, such as the
|
||||
@@ -15,12 +15,19 @@ World Wide Web, so it is fully streamable with a progressive display
|
||||
option. PNG is robust, providing both full file integrity checking and
|
||||
fast, simple detection of common transmission errors. Also, PNG can store
|
||||
gamma and chromaticity data for improved color matching on heterogeneous
|
||||
platforms.
|
||||
platforms.
|
||||
|
||||
.SH "SEE ALSO"
|
||||
.IR libpng(3), zlib(3), deflate(5), and zlib(5)
|
||||
.LP
|
||||
PNG specification:
|
||||
PNG 1.1 specification, January 1999:
|
||||
.IP
|
||||
.br
|
||||
http://www.cdrom.com/pub/png
|
||||
.LP
|
||||
PNG 1.0 specification, October 1996:
|
||||
.IP
|
||||
.br
|
||||
RFC 2083
|
||||
.IP
|
||||
.br
|
||||
@@ -32,12 +39,19 @@ http://www.w3.org/TR/REC-png.html
|
||||
.SH AUTHORS
|
||||
This man page: Glenn Randers-Pehrson
|
||||
.LP
|
||||
Portable Network Graphics (PNG) Specification Version 1.2 (July 8, 1999):
|
||||
Glenn Randers-Pehrson and others (png-list@ccrc.wustl.edu).
|
||||
.LP
|
||||
Portable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):
|
||||
Thomas Boutell and others (png-list@dworkin.wustl.edu).
|
||||
Thomas Boutell and others (png-list@ccrc.wustl.edu).
|
||||
.LP
|
||||
|
||||
|
||||
.SH COPYRIGHT NOTICE
|
||||
The PNG specification is copyright (c) 1996 Massachussets Institute of
|
||||
The PNG-1.2 specification is copyright (c) 1999 Glenn Randers-Pehrson.
|
||||
See the specification for conditions of use and distribution.
|
||||
.LP
|
||||
The PNG-1.0 specification is copyright (c) 1996 Massachussets Institute of
|
||||
Technology. See the specification for conditions of use and distribution.
|
||||
.LP
|
||||
.\" end of man page
|
||||
|
||||
140
png.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* libpng version 1.0.5d - November 29, 1999
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -15,32 +15,33 @@
|
||||
/* Version information for C files. This had better match the version
|
||||
* string defined in png.h.
|
||||
*/
|
||||
char png_libpng_ver[12] = "1.0.2";
|
||||
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
/* png_libpng_ver was changed to a function in version 1.0.5c */
|
||||
char png_libpng_ver[12] = "1.0.5d";
|
||||
|
||||
/* png_sig was changed to a function in version 1.0.5c */
|
||||
/* Place to hold the signature string for a PNG file. */
|
||||
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
|
||||
/* Constant strings for known chunk types. If you need to add a chunk,
|
||||
* add a string holding the name here. If you want to make the code
|
||||
* portable to EBCDIC machines, use ASCII numbers, not characters.
|
||||
*/
|
||||
png_byte FARDATA png_IHDR[5] = { 73, 72, 68, 82, '\0'};
|
||||
png_byte FARDATA png_IDAT[5] = { 73, 68, 65, 84, '\0'};
|
||||
png_byte FARDATA png_IEND[5] = { 73, 69, 78, 68, '\0'};
|
||||
png_byte FARDATA png_PLTE[5] = { 80, 76, 84, 69, '\0'};
|
||||
png_byte FARDATA png_bKGD[5] = { 98, 75, 71, 68, '\0'};
|
||||
png_byte FARDATA png_cHRM[5] = { 99, 72, 82, 77, '\0'};
|
||||
png_byte FARDATA png_gAMA[5] = {103, 65, 77, 65, '\0'};
|
||||
png_byte FARDATA png_hIST[5] = {104, 73, 83, 84, '\0'};
|
||||
png_byte FARDATA png_oFFs[5] = {111, 70, 70, 115, '\0'};
|
||||
png_byte FARDATA png_pCAL[5] = {112, 67, 65, 76, '\0'};
|
||||
png_byte FARDATA png_pHYs[5] = {112, 72, 89, 115, '\0'};
|
||||
png_byte FARDATA png_sBIT[5] = {115, 66, 73, 84, '\0'};
|
||||
png_byte FARDATA png_sRGB[5] = {115, 82, 71, 66, '\0'};
|
||||
png_byte FARDATA png_tEXt[5] = {116, 69, 88, 116, '\0'};
|
||||
png_byte FARDATA png_tIME[5] = {116, 73, 77, 69, '\0'};
|
||||
png_byte FARDATA png_tRNS[5] = {116, 82, 78, 83, '\0'};
|
||||
png_byte FARDATA png_zTXt[5] = {122, 84, 88, 116, '\0'};
|
||||
|
||||
/* Invoke global declarations for constant strings for known chunk types */
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
PNG_bKGD;
|
||||
PNG_cHRM;
|
||||
PNG_gAMA;
|
||||
PNG_hIST;
|
||||
PNG_oFFs;
|
||||
PNG_pCAL;
|
||||
PNG_pHYs;
|
||||
PNG_sBIT;
|
||||
PNG_sRGB;
|
||||
PNG_tEXt;
|
||||
PNG_tIME;
|
||||
PNG_tRNS;
|
||||
PNG_zTXt;
|
||||
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
@@ -72,12 +73,14 @@ int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
/* Mask to determine which pixels to overwrite while displaying */
|
||||
int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
|
||||
#endif
|
||||
|
||||
/* Tells libpng that we have already handled the first "num_bytes" bytes
|
||||
* of the PNG file signature. If the PNG data is embedded into another
|
||||
* stream we can set num_bytes = 8 so that libpng will not attempt to read
|
||||
* or write any of the magic bytes before it starts on the IHDR.
|
||||
*/
|
||||
|
||||
void
|
||||
png_set_sig_bytes(png_structp png_ptr, int num_bytes)
|
||||
{
|
||||
@@ -85,7 +88,7 @@ png_set_sig_bytes(png_structp png_ptr, int num_bytes)
|
||||
if (num_bytes > 8)
|
||||
png_error(png_ptr, "Too many bytes for PNG signature.");
|
||||
|
||||
png_ptr->sig_bytes = num_bytes < 0 ? 0 : num_bytes;
|
||||
png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
|
||||
}
|
||||
|
||||
/* Checks whether the supplied bytes match the PNG signature. We allow
|
||||
@@ -99,6 +102,7 @@ png_set_sig_bytes(png_structp png_ptr, int num_bytes)
|
||||
int
|
||||
png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
|
||||
{
|
||||
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
if (num_to_check > 8)
|
||||
num_to_check = 8;
|
||||
else if (num_to_check < 1)
|
||||
@@ -110,12 +114,12 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
|
||||
if (start + num_to_check > 8)
|
||||
num_to_check = 8 - start;
|
||||
|
||||
return ((int)(png_memcmp(&sig[start], &png_sig[start], num_to_check)));
|
||||
return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
|
||||
}
|
||||
|
||||
/* (Obsolete) function to check signature bytes. It does not allow one
|
||||
* to check a partial signature. This function will be removed in the
|
||||
* future - use png_sig_cmp().
|
||||
* to check a partial signature. This function might be removed in the
|
||||
* future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
|
||||
*/
|
||||
int
|
||||
png_check_sig(png_bytep sig, int num)
|
||||
@@ -264,9 +268,14 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
|
||||
int i;
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->text[i].key);
|
||||
if(info_ptr->text[i].key != NULL)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->text[i].key);
|
||||
info_ptr->text[i].key = NULL;
|
||||
}
|
||||
}
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
info_ptr->text = NULL;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
@@ -278,8 +287,10 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
|
||||
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_params[i]);
|
||||
info_ptr->pcal_params[i]=NULL;
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
info_ptr->pcal_params = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -317,8 +328,8 @@ png_charp
|
||||
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
{
|
||||
static PNG_CONST char short_months[12][4] =
|
||||
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
if (png_ptr->time_buffer == NULL)
|
||||
{
|
||||
@@ -345,3 +356,66 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
return ((png_charp)png_ptr->time_buffer);
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
/* Signature string for a PNG file. */
|
||||
png_bytep
|
||||
png_sig_bytes(png_structp png_ptr)
|
||||
{
|
||||
const png_byte png_sig_numbers[9] = {137, 80, 78, 71, 13, 10, 26, 10, 0};
|
||||
if (png_ptr == NULL) /* silence compiler warning */
|
||||
return ((png_bytep) strdup((png_const_charp)png_sig_numbers));
|
||||
return ((png_bytep) strdup((png_const_charp)png_sig_numbers));
|
||||
}
|
||||
|
||||
png_charp
|
||||
png_get_copyright(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
|
||||
return ("\n libpng version 1.0.5d - November 29, 1999\n\
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
|
||||
Copyright (c) 1996, 1997 Andreas Dilger\n\
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson\n");
|
||||
return ("");
|
||||
}
|
||||
|
||||
/* The following return the library version as a short string in the
|
||||
* format 1.0.0 through 99.99.99zz. To get the version of *.h files used
|
||||
* with your application, print out PNG_LIBPNG_VER_STRING, which is defined
|
||||
* in png.h.
|
||||
*/
|
||||
|
||||
png_charp
|
||||
png_get_libpng_ver(png_structp png_ptr)
|
||||
{
|
||||
/* Version of *.c files used when building libpng */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return("1.0.5d");
|
||||
return("1.0.5d");
|
||||
}
|
||||
|
||||
png_charp
|
||||
png_get_header_ver(png_structp png_ptr)
|
||||
{
|
||||
/* Version of *.h files used when building libpng */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return(PNG_LIBPNG_VER_STRING);
|
||||
return(PNG_LIBPNG_VER_STRING);
|
||||
}
|
||||
|
||||
png_charp
|
||||
png_get_header_version(png_structp png_ptr)
|
||||
{
|
||||
/* Returns longer string containing both version and date */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return(PNG_HEADER_VERSION_STRING);
|
||||
return(PNG_HEADER_VERSION_STRING);
|
||||
}
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
void
|
||||
png_check_version
|
||||
(version_1_0_5d png_h_is_not_version_1_0_5d)
|
||||
{
|
||||
if(png_h_is_not_version_1_0_5d == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
487
png.h
@@ -1,49 +1,132 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* For conditions of distribution and use, see the COPYRIGHT NOTICE below.
|
||||
* libpng version 1.0.5d - November 29, 1999
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* Authors and maintainers:
|
||||
* libpng versions 0.71, May 1995, through 0.89c, May 1996: Guy Schalnat
|
||||
* libpng versions 0.90, December 1996, through 0.96, May 1997: Andreas Dilger
|
||||
* libpng versions 0.97, January 1998, through 1.0.5d - November 29, 1999: Glenn
|
||||
* See also "Contributing Authors", below.
|
||||
*
|
||||
* Y2K compliance in libpng:
|
||||
* =========================
|
||||
*
|
||||
* November 29, 1999
|
||||
*
|
||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||
* an official declaration.
|
||||
*
|
||||
* This is your unofficial assurance that libpng from version 0.71 and
|
||||
* upward through 1.0.5d are Y2K compliant. It is my belief that earlier
|
||||
* versions were also Y2K compliant.
|
||||
*
|
||||
* Libpng only has three year fields. One is a 2-byte unsigned integer
|
||||
* that will hold years up to 65535. The other two hold the date in text
|
||||
* format, and will hold years up to 9999.
|
||||
*
|
||||
* The integer is
|
||||
* "png_uint_16 year" in png_time_struct.
|
||||
*
|
||||
* The strings are
|
||||
* "png_charp time_buffer" in png_struct and
|
||||
* "near_time_buffer", which is a local character string in png.c.
|
||||
*
|
||||
* There are seven time-related functions:
|
||||
* png.c: png_convert_to_rfc_1123() in png.c
|
||||
* (formerly png_convert_to_rfc_1152() in error)
|
||||
* png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
|
||||
* png_convert_from_time_t() in pngwrite.c
|
||||
* png_get_tIME() in pngget.c
|
||||
* png_handle_tIME() in pngrutil.c, called in pngread.c
|
||||
* png_set_tIME() in pngset.c
|
||||
* png_write_tIME() in pngwutil.c, called in pngwrite.c
|
||||
*
|
||||
* All handle dates properly in a Y2K environment. The
|
||||
* png_convert_from_time_t() function calls gmtime() to convert from system
|
||||
* clock time, which returns (year - 1900), which we properly convert to
|
||||
* the full 4-digit year. There is a possibility that applications using
|
||||
* libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
|
||||
* function, or that they are incorrectly passing only a 2-digit year
|
||||
* instead of "year - 1900" into the png_convert_from_struct_tm() function,
|
||||
* but this is not under our control. The libpng documentation has always
|
||||
* stated that it works with 4-digit years, and the APIs have been
|
||||
* documented as such.
|
||||
*
|
||||
* The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
|
||||
* integer to hold the year, and can hold years as large as 65535.
|
||||
*
|
||||
* zlib, upon which libpng depends, is also Y2K compliant. It contains
|
||||
* no date-related code.
|
||||
*
|
||||
* Glenn Randers-Pehrson
|
||||
* libpng maintainer
|
||||
* PNG Development Group
|
||||
*
|
||||
* Note about libpng version numbers:
|
||||
*
|
||||
*
|
||||
* Due to various miscommunications, unforeseen code incompatibilities
|
||||
* and occasional factors outside the authors' control, version numbering
|
||||
* on the library has not always been consistent and straightforward.
|
||||
* The following table summarizes matters since version 0.89c, which was
|
||||
* the first widely used release:
|
||||
*
|
||||
* source png.h png.h shared-lib
|
||||
* version string int version
|
||||
* ------- ------ ----- ----------
|
||||
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
|
||||
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
|
||||
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
|
||||
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
|
||||
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
|
||||
* 0.97c 0.97 97 2.0.97
|
||||
* 0.98 0.98 98 2.0.98
|
||||
* 0.99 0.99 98 2.0.99
|
||||
* 0.99a-m 0.99 99 2.0.99
|
||||
* 1.00 1.00 100 2.1.0 [int should be 10000]
|
||||
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
|
||||
* 1.0.1 1.0.1 10001 2.1.0
|
||||
* 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
|
||||
* source png.h png.h shared-lib
|
||||
* version string int version
|
||||
* ------- ------ ----- ----------
|
||||
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
|
||||
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
|
||||
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
|
||||
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
|
||||
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
|
||||
* 0.97c 0.97 97 2.0.97
|
||||
* 0.98 0.98 98 2.0.98
|
||||
* 0.99 0.99 98 2.0.99
|
||||
* 0.99a-m 0.99 99 2.0.99
|
||||
* 1.00 1.00 100 2.1.0 [100 should be 10000]
|
||||
* 1.0.0 1.0.0 100 2.1.0 [100 should be 10000]
|
||||
* 1.0.1 1.0.1 10001 2.1.0
|
||||
* 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
|
||||
* 1.0.2 1.0.2 10002 2.1.0.2
|
||||
* 1.0.2a-b 1.0.2a-b 10003 2.1.0.2a-b
|
||||
* 1.0.3 1.0.3 10003 2.1.0.3
|
||||
* 1.0.3a-d 1.0.3a-d 10004 2.1.0.3a-d
|
||||
* 1.0.4 1.0.4 10004 2.1.0.4
|
||||
* 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
|
||||
* 1.0.5 1.0.5 10005 2.1.0.5
|
||||
* 1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d
|
||||
* 1.0.6 1.0.6 10006 2.1.0.6
|
||||
*
|
||||
* Henceforth the source version will match the shared-library minor
|
||||
* and patch numbers; the shared-library major version number will be
|
||||
* used for changes in backward compatibility, as it is intended. The
|
||||
* PNG_PNGLIB_VER macro, which is not used within libpng but is available
|
||||
* for applications, is an unsigned integer of the form xyyzz corresponding
|
||||
* to the source version x.y.z (leading zeros in y and z).
|
||||
* to the source version x.y.z (leading zeros in y and z). Internal
|
||||
* png-group beta versions (x.y.z[a-z]) will be given the next higher
|
||||
* number.
|
||||
*
|
||||
* See libpng.txt or libpng.3 for more information. The PNG specification
|
||||
* is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
|
||||
* and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT NOTICE:
|
||||
*
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* (libpng versions 0.5, May 1995, through 0.89c, May 1996)
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* (libpng versions 0.90, December 1996, through 0.96, May 1997)
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* (libpng versions 0.97, January 1998, through 1.0.5d, November 29, 1999)
|
||||
*
|
||||
* For the purposes of this copyright and license, "Contributing Authors"
|
||||
* is defined as the following set of individuals:
|
||||
*
|
||||
* Contributing Authors:
|
||||
* John Bowler
|
||||
* Kevin Bracey
|
||||
* Sam Bushell
|
||||
@@ -59,14 +142,6 @@
|
||||
* Willem van Schaik
|
||||
* Tim Wegner
|
||||
*
|
||||
* The contributing authors would like to thank all those who helped
|
||||
* with testing, bug fixes, and patience. This wouldn't have been
|
||||
* possible without all of you.
|
||||
*
|
||||
* Thanks to Frank J. T. Wojcik for helping with the documentation.
|
||||
*
|
||||
* COPYRIGHT NOTICE:
|
||||
*
|
||||
* The PNG Reference Library is supplied "AS IS". The Contributing Authors
|
||||
* and Group 42, Inc. disclaim all warranties, expressed or implied,
|
||||
* including, without limitation, the warranties of merchantability and of
|
||||
@@ -78,11 +153,17 @@
|
||||
* Permission is hereby granted to use, copy, modify, and distribute this
|
||||
* source code, or portions hereof, for any purpose, without fee, subject
|
||||
* to the following restrictions:
|
||||
* 1. The origin of this source code must not be misrepresented.
|
||||
* 2. Altered versions must be plainly marked as such and must not be
|
||||
* misrepresented as being the original source.
|
||||
* 3. This Copyright notice may not be removed or altered from any source or
|
||||
* altered source distribution.
|
||||
*
|
||||
* 1. The origin of this source code must not be
|
||||
* misrepresented.
|
||||
*
|
||||
* 2. Altered versions must be plainly marked as such
|
||||
* and must not be misrepresented as being the
|
||||
* original source.
|
||||
*
|
||||
* 3. This Copyright notice may not be removed or
|
||||
* altered from any source or altered source
|
||||
* distribution.
|
||||
*
|
||||
* The Contributing Authors and Group 42, Inc. specifically permit, without
|
||||
* fee, and encourage the use of this source code as a component to
|
||||
@@ -91,13 +172,32 @@
|
||||
* 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
|
||||
* file "pngnow.png".
|
||||
*/
|
||||
|
||||
/*
|
||||
* Libpng is OSI Certified Open Source Software. OSI Certified is a
|
||||
* certification mark of the Open Source Initiative.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The contributing authors would like to thank all those who helped
|
||||
* with testing, bug fixes, and patience. This wouldn't have been
|
||||
* possible without all of you.
|
||||
*
|
||||
* Thanks to Frank J. T. Wojcik for helping with the documentation.
|
||||
*/
|
||||
|
||||
#ifndef _PNG_H
|
||||
#define _PNG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* This is not the place to learn how to use libpng. The file libpng.txt
|
||||
* describes how to use libpng, and the file example.c summarizes it
|
||||
* with some code on which to build. This file is useful for looking
|
||||
@@ -110,6 +210,11 @@ extern "C" {
|
||||
/* include all user configurable info */
|
||||
#include "pngconf.h"
|
||||
|
||||
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* This file is arranged in several sections. The first section contains
|
||||
* structure and type definitions. The second section contains the external
|
||||
* library functions, while the third has the internal library functions,
|
||||
@@ -117,33 +222,43 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "1.0.2"
|
||||
#define PNG_LIBPNG_VER_STRING "1.0.5d"
|
||||
|
||||
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
|
||||
* We must not include leading zeros.
|
||||
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
|
||||
* version 1.0.0 was mis-numbered 100 instead of 10000). From
|
||||
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=bugfix */
|
||||
#define PNG_LIBPNG_VER 10002 /* 1.0.2 */
|
||||
#define PNG_LIBPNG_VER 10006 /* 1.0.6 */
|
||||
|
||||
/* Note to maintainer: update this number in scripts/pngdef.pas as well */
|
||||
|
||||
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
|
||||
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
|
||||
/* Version information for C files, stored in png.c. This had better match
|
||||
* the version above.
|
||||
*/
|
||||
extern char png_libpng_ver[12]; /* need room for 99.99.99aa */
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
PNG_EXPORT_VAR (char) png_libpng_ver[12]; /* need room for 99.99.99aa */
|
||||
#else
|
||||
#define png_libpng_ver png_get_header_ver(NULL)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
/* This was removed in version 1.0.5c */
|
||||
/* Structures to facilitate easy interlacing. See png.c for more details */
|
||||
extern int FARDATA png_pass_start[7];
|
||||
extern int FARDATA png_pass_inc[7];
|
||||
extern int FARDATA png_pass_ystart[7];
|
||||
extern int FARDATA png_pass_yinc[7];
|
||||
extern int FARDATA png_pass_mask[7];
|
||||
extern int FARDATA png_pass_dsp_mask[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_start[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_inc[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_ystart[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_yinc[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_mask[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_dsp_mask[7];
|
||||
/* These aren't currently used. If you need them, see png.c for more details
|
||||
extern int FARDATA png_pass_width[7];
|
||||
extern int FARDATA png_pass_height[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_width[7];
|
||||
PNG_EXPORT_VAR (int FARDATA) png_pass_height[7];
|
||||
*/
|
||||
#endif
|
||||
|
||||
#endif /* PNG_NO_EXTERN */
|
||||
|
||||
/* Three color definitions. The order of the red, green, and blue, (and the
|
||||
@@ -404,6 +519,9 @@ typedef struct png_info_struct
|
||||
typedef png_info FAR * png_infop;
|
||||
typedef png_info FAR * FAR * png_infopp;
|
||||
|
||||
/* Maximum positive integer used in PNG is (2^31)-1 */
|
||||
#define PNG_MAX_UINT ((png_uint_32)0x7fffffffL)
|
||||
|
||||
/* These describe the color_type field in png_info. */
|
||||
/* color type masks */
|
||||
#define PNG_COLOR_MASK_PALETTE 1
|
||||
@@ -417,11 +535,11 @@ typedef png_info FAR * FAR * png_infopp;
|
||||
#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
|
||||
#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
|
||||
|
||||
/* This is for compression type. PNG 1.0 only defines the single type. */
|
||||
/* This is for compression type. PNG 1.0-1.2 only define the single type. */
|
||||
#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
|
||||
#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
|
||||
|
||||
/* This is for filter type. PNG 1.0 only defines the single type. */
|
||||
/* This is for filter type. PNG 1.0-1.2 only define the single type. */
|
||||
#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
|
||||
#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
|
||||
|
||||
@@ -448,12 +566,12 @@ typedef png_info FAR * FAR * png_infopp;
|
||||
#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
|
||||
|
||||
/* These are for the sRGB chunk. These values should NOT be changed. */
|
||||
#define PNG_sRGB_INTENT_SATURATION 0
|
||||
#define PNG_sRGB_INTENT_PERCEPTUAL 1
|
||||
#define PNG_sRGB_INTENT_ABSOLUTE 2
|
||||
#define PNG_sRGB_INTENT_RELATIVE 3
|
||||
#define PNG_sRGB_INTENT_PERCEPTUAL 0
|
||||
#define PNG_sRGB_INTENT_RELATIVE 1
|
||||
#define PNG_sRGB_INTENT_SATURATION 2
|
||||
#define PNG_sRGB_INTENT_ABSOLUTE 3
|
||||
#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
|
||||
|
||||
|
||||
|
||||
|
||||
/* These determine if an ancillary chunk's data has been successfully read
|
||||
@@ -519,7 +637,7 @@ typedef void (*png_user_transform_ptr) PNGARG((png_structp,
|
||||
#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
|
||||
|
||||
typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
|
||||
typedef void (*png_free_ptr) PNGARG((png_structp, png_structp));
|
||||
typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
|
||||
|
||||
/* The structure that holds the information to read and write PNG files.
|
||||
* The only people who need to care about what is inside of this are the
|
||||
@@ -537,12 +655,19 @@ struct png_struct_def
|
||||
png_voidp error_ptr; /* user supplied struct for error functions */
|
||||
png_rw_ptr write_data_fn; /* function for writing output data */
|
||||
png_rw_ptr read_data_fn; /* function for reading input data */
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
png_voidp io_ptr; /* ptr to application struct for I/O functions*/
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
png_user_transform_ptr read_user_transform_fn; /* user read transform */
|
||||
#endif
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
png_user_transform_ptr write_user_transform_fn; /* user write transform */
|
||||
#endif
|
||||
png_voidp io_ptr; /* ptr to application struct for I/O functions*/
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
png_voidp user_transform_ptr; /* user supplied struct for user transform */
|
||||
png_byte user_transform_depth; /* bit depth of user transformed pixels */
|
||||
png_byte user_transform_channels; /* channels in user transformed pixels */
|
||||
#endif
|
||||
|
||||
png_uint_32 mode; /* tells us where we are in the PNG file */
|
||||
png_uint_32 flags; /* flags indicating various things to libpng */
|
||||
@@ -611,13 +736,13 @@ struct png_struct_def
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
|
||||
float gamma; /* file gamma value */
|
||||
float screen_gamma; /* screen gamma value (display_gamma/viewing_gamma */
|
||||
float screen_gamma; /* screen gamma value (display_exponent) */
|
||||
#endif /* PNG_READ_GAMMA_SUPPORTED */
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_bytep gamma_table; /* gamma table for 8 bit depth files */
|
||||
png_bytep gamma_table; /* gamma table for 8-bit depth files */
|
||||
png_bytep gamma_from_1; /* converts from 1.0 to screen */
|
||||
png_bytep gamma_to_1; /* converts from file to 1.0 */
|
||||
png_uint_16pp gamma_16_table; /* gamma table for 16 bit depth files */
|
||||
png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
|
||||
png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
|
||||
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
|
||||
#endif /* PNG_READ_GAMMA_SUPPORTED || PNG_WRITE_GAMMA_SUPPORTED */
|
||||
@@ -689,8 +814,23 @@ struct png_struct_def
|
||||
png_malloc_ptr malloc_fn; /* function for allocating memory */
|
||||
png_free_ptr free_fn; /* function for freeing memory */
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_byte rgb_to_gray_status;
|
||||
png_byte rgb_to_gray_red_coeff;
|
||||
png_byte rgb_to_gray_green_coeff;
|
||||
png_byte rgb_to_gray_blue_coeff;
|
||||
#endif
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
|
||||
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
|
||||
png_byte empty_plte_permitted;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This prevents a compiler error in png_get_copyright() in png.c if png.c
|
||||
and png.h are both at * version 1.0.5d
|
||||
*/
|
||||
typedef png_structp version_1_0_5d;
|
||||
|
||||
typedef png_struct FAR * FAR * png_structpp;
|
||||
|
||||
/* Here are the function definitions most commonly used. This is not
|
||||
@@ -734,7 +874,7 @@ extern PNG_EXPORT(png_structp,png_create_read_struct_2)
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn));
|
||||
extern PNG_EXPORT(png_structp,png_create_write_struct_2)
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn));
|
||||
#endif
|
||||
@@ -762,6 +902,8 @@ extern PNG_EXPORT(png_infop,png_create_info_struct)
|
||||
extern void png_info_init PNGARG((png_infop info_ptr));
|
||||
|
||||
/* Writes all the PNG information before the image. */
|
||||
extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr));
|
||||
extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr));
|
||||
|
||||
@@ -785,8 +927,11 @@ extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
|
||||
#endif /* PNG_WRITE_tIME_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
/* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha if available. */
|
||||
/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
|
||||
extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_EXPAND_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
@@ -795,13 +940,16 @@ extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_BGR_SUPPORTED || PNG_WRITE_BGR_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
/* Expand the grayscale to 24 bit RGB if necessary. */
|
||||
/* Expand the grayscale to 24-bit RGB if necessary. */
|
||||
extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
/* Reduce RGB to grayscale. (Not yet implemented) */
|
||||
extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr));
|
||||
/* Reduce RGB to grayscale. */
|
||||
extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
|
||||
int error_action, double red, double green ));
|
||||
extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
|
||||
png_ptr));
|
||||
#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */
|
||||
|
||||
extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
|
||||
@@ -832,19 +980,19 @@ extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
|
||||
#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
/* Swap bytes in 16 bit depth files. */
|
||||
/* Swap bytes in 16-bit depth files. */
|
||||
extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_SWAP_SUPPORTED || PNG_WRITE_SWAP_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
/* Use 1 byte per pixel in 1, 2, or 4 bit depth files. */
|
||||
/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
|
||||
extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_PACK_SUPPORTED || PNG_WRITE_PACK_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
/* Swap packing order of pixels in bytes. */
|
||||
extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_PACKSWAP_SUPPORTED || PNG_WRITE_PACKSWAP_SUPPOR */
|
||||
#endif /* PNG_READ_PACKSWAP_SUPPORTED || PNG_WRITE_PACKSWAP_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
/* Converts files to legal bit depths. */
|
||||
@@ -875,7 +1023,7 @@ extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
|
||||
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_16_TO_8_SUPPORTED)
|
||||
/* strip the second byte of information from a 16 bit depth file. */
|
||||
/* strip the second byte of information from a 16-bit depth file. */
|
||||
extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_16_TO_8_SUPPORTED */
|
||||
|
||||
@@ -887,11 +1035,18 @@ extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
|
||||
#endif /* PNG_READ_DITHER_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
/* Handle gamma correction. Screen_gamma=(display_gamma/viewing_gamma) */
|
||||
/* Handle gamma correction. Screen_gamma=(display_exponent) */
|
||||
extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
|
||||
double screen_gamma, double default_file_gamma));
|
||||
#endif /* PNG_READ_GAMMA_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
|
||||
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
|
||||
/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */
|
||||
extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
|
||||
int empty_plte_permitted));
|
||||
#endif /* PNG_READ_EMPTY_PLTE_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
/* Set how many lines between output flushes - 0 for no flushing */
|
||||
extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
|
||||
@@ -1105,6 +1260,7 @@ extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, FILE *fp));
|
||||
* method of error handling. If error_fn or warning_fn is NULL, the
|
||||
* default function will be used.
|
||||
*/
|
||||
|
||||
extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
|
||||
png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
|
||||
|
||||
@@ -1151,6 +1307,16 @@ extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
|
||||
png_ptr, png_user_transform_ptr write_user_transform_fn));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
|
||||
png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
|
||||
int user_transform_channels));
|
||||
/* Return the user pointer associated with the user transform functions */
|
||||
extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
|
||||
PNGARG((png_structp png_ptr));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
/* Sets the function callbacks for the push reader, and a pointer to a
|
||||
* user-defined structure available to the callback functions.
|
||||
@@ -1343,7 +1509,7 @@ extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
|
||||
int *bit_depth, int *color_type, int *interlace_type,
|
||||
int *compression_type, int *filter_type));
|
||||
|
||||
|
||||
extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
|
||||
int color_type, int interlace_type, int compression_type, int filter_type));
|
||||
@@ -1449,28 +1615,41 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
* only been added since version 0.95 so it is not implemented throughout
|
||||
* libpng yet, but more support will be added as needed.
|
||||
*/
|
||||
#ifdef PNG_DEBUG
|
||||
#if (PNG_DEBUG > 0)
|
||||
#ifdef PNG_NO_STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifndef PNG_DEBUG_FILE
|
||||
#define PNG_DEBUG_FILE stderr
|
||||
#endif /* PNG_DEBUG_FILE */
|
||||
|
||||
#define png_debug(l,m) if (PNG_DEBUG > l) \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
|
||||
(l==2 ? "\t\t":(l==3 ? "\t\t\t":""))))
|
||||
(l==2 ? "\t\t":(l>2 ? "\t\t\t":""))))
|
||||
#define png_debug1(l,m,p1) if (PNG_DEBUG > l) \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
|
||||
(l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1)
|
||||
(l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1)
|
||||
#define png_debug2(l,m,p1,p2) if (PNG_DEBUG > l) \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
|
||||
(l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1,p2)
|
||||
#else
|
||||
#define png_debug(l, m)
|
||||
#define png_debug1(l, m, p1)
|
||||
#define png_debug2(l, m, p1, p2)
|
||||
(l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1,p2)
|
||||
#endif /* (PNG_DEBUG > 0) */
|
||||
#endif /* PNG_DEBUG */
|
||||
#ifndef png_debug
|
||||
#define png_debug(l, m)
|
||||
#endif
|
||||
#ifndef png_debug1
|
||||
#define png_debug1(l, m, p1)
|
||||
#endif
|
||||
#ifndef png_debug2
|
||||
#define png_debug2(l, m, p1, p2)
|
||||
#endif
|
||||
|
||||
extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((png_structp png_ptr));
|
||||
|
||||
extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
|
||||
|
||||
#define PNG_HEADER_VERSION_STRING " libpng version 1.0.5d - November 29, 1999 (header)\n"
|
||||
|
||||
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
|
||||
/* With these routines we avoid an integer divide, which will be slower on
|
||||
@@ -1485,28 +1664,30 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
|
||||
*/
|
||||
|
||||
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
{ png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
|
||||
(png_uint_16)(bg)*(png_uint_16)(255 - \
|
||||
(png_uint_16)(alpha)) + (png_uint_16)128); \
|
||||
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
|
||||
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
{ png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
|
||||
+ (png_uint_16)(bg)*(png_uint_16)(255 - \
|
||||
(png_uint_16)(alpha)) + (png_uint_16)128); \
|
||||
(composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
{ png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
|
||||
(png_uint_32)(bg)*(png_uint_32)(65535L - \
|
||||
(png_uint_32)(alpha)) + (png_uint_32)32768L); \
|
||||
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
{ png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
|
||||
+ (png_uint_32)(bg)*(png_uint_32)(65535L - \
|
||||
(png_uint_32)(alpha)) + (png_uint_32)32768L); \
|
||||
(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
|
||||
|
||||
#else /* standard method using integer division */
|
||||
|
||||
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
|
||||
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
|
||||
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
|
||||
(png_uint_16)127) / 255)
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
(composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
|
||||
(png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
|
||||
(png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
|
||||
(png_uint_32)32767) / (png_uint_32)65535L)
|
||||
|
||||
#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
|
||||
@@ -1522,15 +1703,19 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
/* Various modes of operation. Note that after an init, mode is set to
|
||||
* zero automatically when the structure is created.
|
||||
*/
|
||||
#define PNG_BEFORE_IHDR 0x00
|
||||
#define PNG_HAVE_IHDR 0x01
|
||||
#define PNG_HAVE_PLTE 0x02
|
||||
#define PNG_HAVE_IDAT 0x04
|
||||
#define PNG_AFTER_IDAT 0x08
|
||||
#define PNG_HAVE_IEND 0x10
|
||||
#define PNG_HAVE_gAMA 0x20
|
||||
#define PNG_HAVE_cHRM 0x40
|
||||
#define PNG_HAVE_sRGB 0x80
|
||||
#define PNG_BEFORE_IHDR 0x00
|
||||
#define PNG_HAVE_IHDR 0x01
|
||||
#define PNG_HAVE_PLTE 0x02
|
||||
#define PNG_HAVE_IDAT 0x04
|
||||
#define PNG_AFTER_IDAT 0x08
|
||||
#define PNG_HAVE_IEND 0x10
|
||||
#define PNG_HAVE_gAMA 0x20
|
||||
#define PNG_HAVE_cHRM 0x40
|
||||
#define PNG_HAVE_sRGB 0x80
|
||||
#define PNG_HAVE_CHUNK_HEADER 0x100
|
||||
#define PNG_WROTE_tIME 0x200
|
||||
#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
|
||||
#define PNG_BACKGROUND_IS_GRAY 0x800
|
||||
|
||||
/* push model modes */
|
||||
#define PNG_READ_SIG_MODE 0
|
||||
@@ -1552,7 +1737,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_DITHER 0x0040
|
||||
#define PNG_BACKGROUND 0x0080
|
||||
#define PNG_BACKGROUND_EXPAND 0x0100
|
||||
#define PNG_RGB_TO_GRAY 0x0200 /* Not currently implemented */
|
||||
/* 0x0200 unused */
|
||||
#define PNG_16_TO_8 0x0400
|
||||
#define PNG_RGBA 0x0800
|
||||
#define PNG_EXPAND 0x1000
|
||||
@@ -1564,6 +1749,9 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_STRIP_ALPHA 0x40000L
|
||||
#define PNG_INVERT_ALPHA 0x80000L
|
||||
#define PNG_USER_TRANSFORM 0x100000L
|
||||
#define PNG_RGB_TO_GRAY_ERR 0x200000L
|
||||
#define PNG_RGB_TO_GRAY_WARN 0x400000L
|
||||
#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
|
||||
|
||||
/* flags for png_create_struct */
|
||||
#define PNG_STRUCT_PNG 0x0001
|
||||
@@ -1591,9 +1779,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_FLAG_FREE_PALETTE 0x1000
|
||||
#define PNG_FLAG_FREE_TRANS 0x2000
|
||||
#define PNG_FLAG_FREE_HIST 0x4000
|
||||
#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
|
||||
#define PNG_FLAG_WROTE_tIME 0x10000L
|
||||
#define PNG_FLAG_BACKGROUND_IS_GRAY 0x20000L
|
||||
|
||||
|
||||
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
|
||||
PNG_FLAG_CRC_ANCILLARY_NOWARN)
|
||||
@@ -1612,30 +1798,53 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
|
||||
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
|
||||
/* place to hold the signature string for a PNG file. */
|
||||
extern png_byte FARDATA png_sig[8];
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
PNG_EXPORT_VAR (png_byte FARDATA) png_sig[8];
|
||||
#else
|
||||
#define png_sig png_sig_bytes(NULL)
|
||||
#endif
|
||||
|
||||
/* Constant strings for known chunk types. If you need to add a chunk,
|
||||
* add a string holding the name here. See png.c for more details. We
|
||||
* can't selectively include these, since we still check for chunk in the
|
||||
* wrong locations with these labels.
|
||||
* define the name here, and add an invocation of the macro in png.c and
|
||||
* wherever it's needed.
|
||||
*/
|
||||
extern png_byte FARDATA png_IHDR[5];
|
||||
extern png_byte FARDATA png_IDAT[5];
|
||||
extern png_byte FARDATA png_IEND[5];
|
||||
extern png_byte FARDATA png_PLTE[5];
|
||||
extern png_byte FARDATA png_bKGD[5];
|
||||
extern png_byte FARDATA png_cHRM[5];
|
||||
extern png_byte FARDATA png_gAMA[5];
|
||||
extern png_byte FARDATA png_hIST[5];
|
||||
extern png_byte FARDATA png_oFFs[5];
|
||||
extern png_byte FARDATA png_pCAL[5];
|
||||
extern png_byte FARDATA png_pHYs[5];
|
||||
extern png_byte FARDATA png_sBIT[5];
|
||||
extern png_byte FARDATA png_sRGB[5];
|
||||
extern png_byte FARDATA png_tEXt[5];
|
||||
extern png_byte FARDATA png_tIME[5];
|
||||
extern png_byte FARDATA png_tRNS[5];
|
||||
extern png_byte FARDATA png_zTXt[5];
|
||||
#define PNG_IHDR const png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
|
||||
#define PNG_IDAT const png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
|
||||
#define PNG_IEND const png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
|
||||
#define PNG_PLTE const png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
|
||||
#define PNG_bKGD const png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
|
||||
#define PNG_cHRM const png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
|
||||
#define PNG_gAMA const png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
|
||||
#define PNG_hIST const png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
|
||||
#define PNG_oFFs const png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
|
||||
#define PNG_pCAL const png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
|
||||
#define PNG_pHYs const png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
|
||||
#define PNG_sBIT const png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
|
||||
#define PNG_sRGB const png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
|
||||
#define PNG_tEXt const png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
|
||||
#define PNG_tIME const png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
|
||||
#define PNG_tRNS const png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
|
||||
#define PNG_zTXt const png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
|
||||
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_IHDR[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_IDAT[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_IEND[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_PLTE[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_bKGD[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_cHRM[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_gAMA[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_hIST[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_oFFs[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_pCAL[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_pHYs[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_sBIT[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_sRGB[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_tEXt[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_tIME[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_tRNS[5];
|
||||
PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
|
||||
#endif /* PNG_USE_GLOBAL_ARRAYS */
|
||||
|
||||
#endif /* PNG_NO_EXTERN */
|
||||
|
||||
@@ -1725,8 +1934,8 @@ PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
|
||||
#endif
|
||||
|
||||
/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
|
||||
* The only currently known PNG chunk that uses signed numbers is
|
||||
* the ancillary extension chunk, pCAL.
|
||||
* The only currently known PNG chunks that use signed numbers are
|
||||
* the ancillary extension chunks, oFFs and pCAL.
|
||||
*/
|
||||
PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
|
||||
|
||||
@@ -1734,7 +1943,7 @@ PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
|
||||
PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
|
||||
#endif
|
||||
|
||||
/* Place a 16 bit number into a buffer in PNG byte order.
|
||||
/* Place a 16-bit number into a buffer in PNG byte order.
|
||||
* The parameter is declared unsigned int, not png_uint_16,
|
||||
* just to avoid potential problems on pre-ANSI C compilers.
|
||||
*/
|
||||
@@ -1922,8 +2131,8 @@ PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
PNG_EXTERN void png_do_rgb_to_gray PNGARG((png_row_infop row_info,
|
||||
png_bytep row));
|
||||
PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
|
||||
row_info, png_bytep row));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
|
||||
32
pngasmrd.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* pngasmrd.h - assembler version of utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.0.5d - November 29, 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.5d).
|
||||
* 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
|
||||
112
pngconf.h
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
@@ -49,14 +49,28 @@
|
||||
/* This protects us against compilers that run on a windowing system
|
||||
* and thus don't have or would rather us not use the stdio types:
|
||||
* stdin, stdout, and stderr. The only one currently used is stderr
|
||||
* in png_error() and png_warning(). #defining PNG_NO_STDIO will
|
||||
* prevent these from being compiled and used.
|
||||
* in png_error() and png_warning(). #defining PNG_NO_CONSOLE_IO will
|
||||
* prevent these from being compiled and used. #defining PNG_NO_STDIO
|
||||
* will also prevent these, plus will prevent the entire set of stdio
|
||||
* macros and functions (FILE *, printf, etc.) from being compiled and used,
|
||||
* unless (PNG_DEBUG > 0) has been #defined.
|
||||
*
|
||||
* #define PNG_NO_CONSOLE_IO
|
||||
* #define PNG_NO_STDIO
|
||||
*/
|
||||
|
||||
#ifndef PNG_NO_STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
# ifdef PNG_NO_STDIO
|
||||
# ifndef PNG_NO_CONSOLE_IO
|
||||
# define PNG_NO_CONSOLE_IO
|
||||
# endif
|
||||
# ifdef PNG_DEBUG
|
||||
# if (PNG_DEBUG > 0)
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
# endif
|
||||
# else
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
|
||||
/* This macro protects us against machines that don't have function
|
||||
* prototypes (ie K&R style headers). If your compiler does not handle
|
||||
@@ -157,7 +171,7 @@ __dont__ include it again
|
||||
#endif
|
||||
|
||||
/* Codewarrior on NT has linking problems without this. */
|
||||
#if defined(__MWERKS__) && defined(WIN32)
|
||||
#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
|
||||
#define PNG_ALWAYS_EXTERN
|
||||
#endif
|
||||
|
||||
@@ -307,11 +321,9 @@ __dont__ include it again
|
||||
#ifndef PNG_NO_READ_USER_TRANSFORM
|
||||
#define PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
#endif
|
||||
/* the following aren't implemented yet
|
||||
#ifndef PNG_NO_READ_RGB_TO_GRAY
|
||||
#define PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
#endif
|
||||
*/
|
||||
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
|
||||
|
||||
#if !defined(PNG_NO_PROGRESSIVE_READ) && \
|
||||
@@ -325,6 +337,10 @@ __dont__ include it again
|
||||
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel and SGI */
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_READ_EMPTY_PLTE
|
||||
#define PNG_READ_EMPTY_PLTE_SUPPORTED /* useful for MNG applications */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
#ifndef PNG_NO_WRITE_SHIFT
|
||||
#define PNG_WRITE_SHIFT_SUPPORTED
|
||||
@@ -370,6 +386,10 @@ __dont__ include it again
|
||||
#define PNG_WRITE_FLUSH_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_WRITE_EMPTY_PLTE
|
||||
#define PNG_WRITE_EMPTY_PLTE_SUPPORTED /* useful for MNG applications */
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_STDIO
|
||||
#define PNG_TIME_RFC1123_SUPPORTED
|
||||
#endif
|
||||
@@ -394,6 +414,20 @@ __dont__ include it again
|
||||
#define PNG_EASY_ACCESS_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_ASSEMBLER_CODE
|
||||
#define PNG_ASSEMBLER_CODE_SUPPORTED
|
||||
#endif
|
||||
|
||||
/* Do not use global arrays (helps with building DLL's)
|
||||
* They are no longer used in libpng itself, since version 1.0.5c,
|
||||
* but might be required for some pre-1.0.5c applications.
|
||||
*/
|
||||
#ifdef PNG_NO_GLOBAL_ARRAYS
|
||||
#define PNG_USE_LOCAL_ARRAYS
|
||||
#else
|
||||
#define PNG_USE_GLOBAL_ARRAYS
|
||||
#endif
|
||||
|
||||
/* These are currently experimental features, define them if you want */
|
||||
|
||||
/* very little testing */
|
||||
@@ -631,27 +665,57 @@ typedef char FAR * FAR * FAR * png_charppp;
|
||||
*/
|
||||
typedef charf * png_zcharp;
|
||||
typedef charf * FAR * png_zcharpp;
|
||||
typedef z_stream FAR * png_zstreamp;
|
||||
typedef z_stream FAR * png_zstreamp;
|
||||
|
||||
/* allow for compilation as dll under MS Windows */
|
||||
#ifdef __WIN32DLL__
|
||||
#define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
|
||||
#endif
|
||||
|
||||
/* allow for compilation as dll with BORLAND C++ 5.0 */
|
||||
#if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
|
||||
# define PNG_EXPORT(type,symbol) type _export symbol
|
||||
#endif
|
||||
#ifndef PNG_EXPORT
|
||||
/* allow for compilation as dll under MS Windows */
|
||||
# ifdef __WIN32DLL__
|
||||
# define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
|
||||
# endif
|
||||
|
||||
/* allow for compilation as shared lib under BeOS */
|
||||
#ifdef __BEOSDLL__
|
||||
#define PNG_EXPORT(type,symbol) __declspec(export) type symbol
|
||||
/* this variant is used in Mozilla; may correspond to MSVC++ 6.0 changes */
|
||||
# ifdef ALT_WIN32_DLL
|
||||
# define PNG_EXPORT(type,symbol) type __attribute__((dllexport)) symbol
|
||||
# endif
|
||||
|
||||
/* allow for compilation as dll with Borland C++ 5.0 */
|
||||
# if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
|
||||
# define PNG_EXPORT(type,symbol) type _export symbol
|
||||
# endif
|
||||
|
||||
/* allow for compilation as shared lib under BeOS */
|
||||
# ifdef __BEOSDLL__
|
||||
# define PNG_EXPORT(type,symbol) __declspec(export) type symbol
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PNG_EXPORT
|
||||
#define PNG_EXPORT(type,symbol) type symbol
|
||||
# define PNG_EXPORT(type,symbol) type symbol
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN32__)
|
||||
# define PNG_ATTR_DLLIMP
|
||||
#endif
|
||||
|
||||
#ifndef PNG_EXPORT_VAR
|
||||
# ifdef PNG_DECL_DLLEXP
|
||||
# define PNG_EXPORT_VAR(type) extern __declspec(dllexport) type
|
||||
# endif
|
||||
# ifdef PNG_ATTR_DLLEXP
|
||||
# define PNG_EXPORT_VAR(type) extern type __attribute__((dllexport))
|
||||
# endif
|
||||
# ifdef PNG_DECL_DLLIMP
|
||||
# define PNG_EXPORT_VAR(type) extern __declspec(dllimport) type
|
||||
# endif
|
||||
# ifdef PNG_ATTR_DLLIMP
|
||||
# define PNG_EXPORT_VAR(type) extern type __attribute__((dllimport))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PNG_EXPORT_VAR
|
||||
# define PNG_EXPORT_VAR(type) extern type
|
||||
#endif
|
||||
|
||||
/* User may want to use these so not in PNG_INTERNAL. Any library functions
|
||||
* that are passed far data must be model independent.
|
||||
@@ -680,7 +744,7 @@ typedef z_stream FAR * png_zstreamp;
|
||||
/* End of memory model independent support */
|
||||
|
||||
/* Just a double check that someone hasn't tried to define something
|
||||
* contradictory.
|
||||
* contradictory.
|
||||
*/
|
||||
#if (PNG_ZBUF_SIZE > 65536) && defined(PNG_MAX_MALLOC_64K)
|
||||
#undef PNG_ZBUF_SIZE
|
||||
|
||||
15
pngerror.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all error handling. Users who
|
||||
* need special error handling are expected to write replacement functions
|
||||
@@ -75,7 +75,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message
|
||||
buffer[iout++] = png_digit[c & 0xf];
|
||||
buffer[iout++] = ']';
|
||||
} else {
|
||||
buffer[iout++] = c;
|
||||
buffer[iout++] = (png_byte)c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ png_chunk_warning(png_structp png_ptr, png_const_charp message)
|
||||
static void
|
||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr, "libpng error: %s\n", message);
|
||||
#endif
|
||||
|
||||
@@ -136,12 +136,11 @@ png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
static void
|
||||
png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr, "libpng warning: %s\n", message);
|
||||
#endif
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
|
||||
15
pngget.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -423,7 +423,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *width, png_uint_32 *height, int *bit_depth,
|
||||
int *color_type, int *interlace_type, int *compression_type,
|
||||
int *filter_type)
|
||||
|
||||
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
|
||||
bit_depth != NULL && color_type != NULL)
|
||||
@@ -454,7 +454,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
channels++;
|
||||
pixel_depth = *bit_depth * channels;
|
||||
rowbytes_per_pixel = (pixel_depth + 7) >> 3;
|
||||
if ((*width > (png_uint_32)2147483647L/rowbytes_per_pixel))
|
||||
if ((*width > PNG_MAX_UINT/rowbytes_per_pixel))
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Width too large for libpng to process image data.");
|
||||
@@ -641,3 +641,10 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_byte
|
||||
png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
{
|
||||
return png_ptr->rgb_to_gray_status;
|
||||
}
|
||||
#endif
|
||||
|
||||
34
pngmem.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all memory allocation. Users who
|
||||
* need special memory handling are expected to supply replacement
|
||||
@@ -82,12 +82,10 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
farfree (struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +128,7 @@ png_voidp
|
||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
#endif PNG_USER_MEM_SUPPORTED
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
@@ -157,8 +155,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
ret = NULL;
|
||||
}
|
||||
|
||||
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
|
||||
if (num_blocks < 1)
|
||||
if(png_ptr->zlib_window_bits > 14)
|
||||
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
|
||||
else
|
||||
num_blocks = 1;
|
||||
if (png_ptr->zlib_mem_level >= 7)
|
||||
num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
|
||||
@@ -192,12 +191,12 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
if ((png_size_t)hptr & 0xf)
|
||||
{
|
||||
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
|
||||
hptr += 16L;
|
||||
hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
|
||||
}
|
||||
for (i = 0; i < num_blocks; i++)
|
||||
{
|
||||
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||
hptr += (png_uint_32)65536L;
|
||||
hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
|
||||
}
|
||||
|
||||
png_ptr->offset_table_number = num_blocks;
|
||||
@@ -235,7 +234,6 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
ptr = NULL;
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
@@ -245,7 +243,7 @@ void
|
||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
|
||||
if (png_ptr->offset_table != NULL)
|
||||
{
|
||||
int i;
|
||||
@@ -271,7 +269,6 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
if (ptr != NULL)
|
||||
{
|
||||
farfree(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,20 +348,16 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# else
|
||||
free(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -433,7 +426,6 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
ptr = NULL;
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
@@ -441,18 +433,18 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
void
|
||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(ptr);
|
||||
ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(ptr);
|
||||
ptr = NULL;
|
||||
# else
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -468,7 +460,7 @@ png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
|
||||
size = (png_size_t)length;
|
||||
if ((png_uint_32)size != length)
|
||||
png_error(png_ptr,"Overflow in png_memcpy_check.");
|
||||
|
||||
|
||||
return(png_memcpy (s1, s2, size));
|
||||
}
|
||||
|
||||
|
||||
BIN
pngnow.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
125
pngpread.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -92,9 +92,9 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
num_to_check = png_ptr->buffer_size;
|
||||
}
|
||||
|
||||
png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
|
||||
png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
|
||||
num_to_check);
|
||||
png_ptr->sig_bytes += num_to_check;
|
||||
png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
|
||||
|
||||
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
||||
{
|
||||
@@ -116,13 +116,58 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
void
|
||||
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
PNG_hIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
PNG_tIME;
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
#endif /* PNG_USE_LOCAL_ARRAYS */
|
||||
/* First we make sure we have enough data for the 4 byte chunk name
|
||||
* and the 4 byte chunk length before proceeding with decoding the
|
||||
* chunk data. To fully decode each of these chunks, we also make
|
||||
* sure we have enough data in the buffer for the 4 byte CRC at the
|
||||
* end of every chunk (except IDAT, which is handled separately).
|
||||
*/
|
||||
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
|
||||
@@ -136,7 +181,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_ptr->push_length = png_get_uint_32(chunk_length);
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
|
||||
@@ -159,7 +204,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
|
||||
{
|
||||
/* If we reach an IDAT chunk, this means we have read all of the
|
||||
* header chunks, and we can start reading the image (or if this
|
||||
@@ -343,7 +388,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -466,7 +511,7 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
|
||||
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
|
||||
old_buffer = png_ptr->save_buffer;
|
||||
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
|
||||
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)new_max);
|
||||
png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
png_free(png_ptr, old_buffer);
|
||||
@@ -496,7 +541,10 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
void
|
||||
png_push_read_IDAT(png_structp png_ptr)
|
||||
{
|
||||
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
#endif
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
|
||||
@@ -511,9 +559,9 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
|
||||
|
||||
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
|
||||
@@ -576,7 +624,7 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
}
|
||||
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,7 +678,7 @@ png_push_process_row(png_structp png_ptr)
|
||||
png_ptr->row_info.channels = png_ptr->channels;
|
||||
png_ptr->row_info.bit_depth = png_ptr->bit_depth;
|
||||
png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
|
||||
|
||||
|
||||
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||
|
||||
@@ -767,6 +815,32 @@ png_push_process_row(png_structp png_ptr)
|
||||
void
|
||||
png_read_push_finish_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
/* Width of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
const int png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
|
||||
*/
|
||||
|
||||
/* Height of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
const int png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
#endif
|
||||
|
||||
png_ptr->row_number++;
|
||||
if (png_ptr->row_number < png_ptr->num_rows)
|
||||
return;
|
||||
@@ -781,6 +855,7 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
png_ptr->pass++;
|
||||
if (png_ptr->pass >= 7)
|
||||
break;
|
||||
|
||||
png_ptr->iwidth = (png_ptr->width +
|
||||
png_pass_inc[png_ptr->pass] - 1 -
|
||||
png_pass_start[png_ptr->pass]) /
|
||||
@@ -789,18 +864,15 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
png_ptr->irowbytes = ((png_ptr->iwidth *
|
||||
png_ptr->pixel_depth + 7) >> 3) + 1;
|
||||
|
||||
if (!(png_ptr->transformations & PNG_INTERLACE))
|
||||
{
|
||||
png_ptr->num_rows = (png_ptr->height +
|
||||
png_pass_yinc[png_ptr->pass] - 1 -
|
||||
png_pass_ystart[png_ptr->pass]) /
|
||||
png_pass_yinc[png_ptr->pass];
|
||||
if (!(png_ptr->num_rows))
|
||||
continue;
|
||||
}
|
||||
if (png_ptr->transformations & PNG_INTERLACE)
|
||||
break;
|
||||
} while (png_ptr->iwidth == 0);
|
||||
|
||||
png_ptr->num_rows = (png_ptr->height +
|
||||
png_pass_yinc[png_ptr->pass] - 1 -
|
||||
png_pass_ystart[png_ptr->pass]) /
|
||||
png_pass_yinc[png_ptr->pass];
|
||||
|
||||
} while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -826,7 +898,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
|
||||
}
|
||||
#endif
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)(length+1));
|
||||
png_ptr->current_text[length] = '\0';
|
||||
png_ptr->current_text_ptr = png_ptr->current_text;
|
||||
@@ -1117,6 +1189,9 @@ void
|
||||
png_progressive_combine_row (png_structp png_ptr,
|
||||
png_bytep old_row, png_bytep new_row)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
#endif
|
||||
if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
|
||||
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
|
||||
}
|
||||
|
||||
135
pngread.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngread.c - read a PNG file
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file contains routines that an application calls directly to
|
||||
* read a PNG file or stream.
|
||||
@@ -179,6 +179,51 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
for(;;)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
PNG_hIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
PNG_tIME;
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
#endif /* PNG_GLOBAL_ARRAYS */
|
||||
png_byte chunk_length[4];
|
||||
png_uint_32 length;
|
||||
|
||||
@@ -188,7 +233,8 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
|
||||
png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
|
||||
png_debug2(0, "Reading %s chunk, length=%d.\n", png_ptr->chunk_name,
|
||||
length);
|
||||
|
||||
/* This should be a binary subdivision search or a hash for
|
||||
* matching the chunk name rather than a linear search.
|
||||
@@ -296,6 +342,11 @@ png_start_read_image(png_structp png_ptr)
|
||||
void
|
||||
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
#endif
|
||||
int ret;
|
||||
png_debug2(1, "in png_read_row (row %d, pass %d)\n",
|
||||
png_ptr->row_number, png_ptr->pass);
|
||||
@@ -464,10 +515,8 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
png_ptr->row_info.channels = png_ptr->channels;
|
||||
png_ptr->row_info.bit_depth = png_ptr->bit_depth;
|
||||
png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
|
||||
{
|
||||
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||
}
|
||||
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||
|
||||
png_read_filter_row(png_ptr, &(png_ptr->row_info),
|
||||
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
||||
@@ -515,7 +564,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
* image has alpha or transparency, and png_handle_alpha()[*] has been
|
||||
* called, the rows contents must be initialized to the contents of the
|
||||
* screen.
|
||||
*
|
||||
*
|
||||
* "row" holds the actual image, and pixels are placed in it
|
||||
* as they arrive. If the image is displayed after each pass, it will
|
||||
* appear to "sparkle" in. "display_row" can be used to display a
|
||||
@@ -530,7 +579,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
* not called png_set_interlace_handling(), the display_row buffer will
|
||||
* be ignored, so pass NULL to it.
|
||||
*
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.2.
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5d.
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -550,7 +599,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
{
|
||||
png_bytep rptr = *rp++;
|
||||
png_bytep dptr = *dp++;
|
||||
|
||||
|
||||
png_read_row(png_ptr, rptr, dptr);
|
||||
}
|
||||
else if(rp != NULL)
|
||||
@@ -579,7 +628,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
* only call this function once. If you desire to have an image for
|
||||
* each pass of a interlaced image, use png_read_rows() instead.
|
||||
*
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.2.
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5d.
|
||||
*/
|
||||
void
|
||||
png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
@@ -590,7 +639,16 @@ png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
|
||||
png_debug(1, "in png_read_image\n");
|
||||
/* save jump buffer and error functions */
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
pass = png_set_interlace_handling(png_ptr);
|
||||
#else
|
||||
if (png_ptr->interlaced)
|
||||
png_error(png_ptr,
|
||||
"Cannot read interlaced image -- interlace handler disabled.");
|
||||
pass = 1;
|
||||
#endif
|
||||
|
||||
|
||||
image_height=png_ptr->height;
|
||||
png_ptr->num_rows = image_height; /* Make sure this is set correctly */
|
||||
@@ -622,6 +680,52 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
do
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
PNG_hIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
PNG_tIME;
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
#endif /* PNG_GLOBAL_ARRAYS */
|
||||
|
||||
png_read_data(png_ptr, chunk_length, 4);
|
||||
length = png_get_uint_32(chunk_length);
|
||||
|
||||
@@ -805,8 +909,11 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
#endif
|
||||
if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
|
||||
png_zfree(png_ptr, png_ptr->palette);
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) || \
|
||||
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
|
||||
png_free(png_ptr, png_ptr->trans);
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
if (png_ptr->flags & PNG_FLAG_FREE_HIST)
|
||||
png_free(png_ptr, png_ptr->hist);
|
||||
@@ -820,9 +927,9 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_table[i]);
|
||||
}
|
||||
png_free(png_ptr, png_ptr->gamma_16_table);
|
||||
}
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->gamma_16_table);
|
||||
if (png_ptr->gamma_16_from_1 != NULL)
|
||||
{
|
||||
int i;
|
||||
@@ -831,8 +938,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
|
||||
}
|
||||
}
|
||||
png_free(png_ptr, png_ptr->gamma_16_from_1);
|
||||
}
|
||||
if (png_ptr->gamma_16_to_1 != NULL)
|
||||
{
|
||||
int i;
|
||||
@@ -841,8 +948,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
|
||||
}
|
||||
}
|
||||
png_free(png_ptr, png_ptr->gamma_16_to_1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
|
||||
8
pngrio.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all input. Users who need
|
||||
* special handling are expected to write a function that has the same
|
||||
@@ -60,10 +60,10 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
|
||||
static void
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
|
||||
644
pngrtran.c
267
pngrutil.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file contains routines that are only called from within
|
||||
* libpng itself during the course of reading an image.
|
||||
@@ -14,6 +14,10 @@
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
|
||||
#include "pngasmrd.h"
|
||||
#endif
|
||||
|
||||
#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
|
||||
/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
|
||||
png_uint_32
|
||||
@@ -165,8 +169,8 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
interlace_type = buf[12];
|
||||
|
||||
/* check for width and height valid values */
|
||||
if (width == 0 || width > (png_uint_32)2147483647L || height == 0 ||
|
||||
height > (png_uint_32)2147483647L)
|
||||
if (width == 0 || width > PNG_MAX_UINT || height == 0 ||
|
||||
height > PNG_MAX_UINT)
|
||||
png_error(png_ptr, "Invalid image size in IHDR");
|
||||
|
||||
/* check other values */
|
||||
@@ -178,7 +182,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
color_type == 5 || color_type > 6)
|
||||
png_error(png_ptr, "Invalid color type in IHDR");
|
||||
|
||||
if ((color_type == PNG_COLOR_TYPE_PALETTE && bit_depth) > 8 ||
|
||||
if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
|
||||
((color_type == PNG_COLOR_TYPE_RGB ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
|
||||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
|
||||
@@ -420,11 +424,11 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
if(igamma != (png_uint_32)45000L)
|
||||
if(fabs((float)igamma - 45455.)>500.)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr, "igamma = %lu\n", igamma);
|
||||
#endif
|
||||
return;
|
||||
@@ -496,6 +500,9 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
else
|
||||
{
|
||||
png_ptr->sig_bit.gray = buf[0];
|
||||
png_ptr->sig_bit.red = buf[0];
|
||||
png_ptr->sig_bit.green = buf[0];
|
||||
png_ptr->sig_bit.blue = buf[0];
|
||||
png_ptr->sig_bit.alpha = buf[1];
|
||||
}
|
||||
png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
|
||||
@@ -624,7 +631,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect cHRM value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
|
||||
white_x, white_y, red_x, red_y);
|
||||
fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
|
||||
@@ -689,11 +696,11 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
if ((info_ptr->valid & PNG_INFO_gAMA))
|
||||
if((png_uint_32)(png_ptr->gamma*(float)100000.+.5) != (png_uint_32)45000L)
|
||||
if(fabs((png_ptr->gamma*(float)100000.+.5)-45455.) > 500.)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr,"gamma=%f\n",png_ptr->gamma);
|
||||
#endif
|
||||
}
|
||||
@@ -868,9 +875,21 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
png_ptr->background.index = buf[0];
|
||||
png_ptr->background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
|
||||
png_ptr->background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
|
||||
png_ptr->background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
|
||||
if(info_ptr->num_palette)
|
||||
{
|
||||
if(buf[0] > info_ptr->num_palette)
|
||||
{
|
||||
png_warning(png_ptr, "Incorrect bKGD chunk index value");
|
||||
png_crc_finish(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
png_ptr->background.red =
|
||||
(png_uint_16)png_ptr->palette[buf[0]].red;
|
||||
png_ptr->background.green =
|
||||
(png_uint_16)png_ptr->palette[buf[0]].green;
|
||||
png_ptr->background.blue =
|
||||
(png_uint_16)png_ptr->palette[buf[0]].blue;
|
||||
}
|
||||
}
|
||||
else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
|
||||
{
|
||||
@@ -926,7 +945,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
return;
|
||||
}
|
||||
|
||||
num = (int)length / 2;
|
||||
num = (int)length / 2 ;
|
||||
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
|
||||
(png_uint_32)(num * sizeof (png_uint_16)));
|
||||
png_ptr->flags |= PNG_FLAG_FREE_HIST;
|
||||
@@ -1244,6 +1263,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
png_free(png_ptr, key);
|
||||
png_free(png_ptr, text_ptr);
|
||||
}
|
||||
#endif
|
||||
@@ -1261,7 +1281,6 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
png_size_t slength;
|
||||
|
||||
png_debug(1, "in png_handle_zTXt\n");
|
||||
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
||||
png_error(png_ptr, "Missing IHDR before zTXt");
|
||||
|
||||
@@ -1413,6 +1432,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
png_free(png_ptr, text_ptr->key);
|
||||
png_free(png_ptr, text_ptr);
|
||||
}
|
||||
#endif
|
||||
@@ -1477,8 +1497,12 @@ png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
|
||||
to any alpha or transparency value associated with the pixel. If
|
||||
you want all pixels to be combined, pass 0xff (255) in mask. */
|
||||
void
|
||||
png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
int mask)
|
||||
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
png_combine_row_c
|
||||
#else
|
||||
png_combine_row
|
||||
#endif /* PNG_HAVE_ASSEMBLER_COMBINE_ROW */
|
||||
(png_structp png_ptr, png_bytep row, int mask)
|
||||
{
|
||||
png_debug(1,"in png_combine_row\n");
|
||||
if (mask == 0xff)
|
||||
@@ -1681,9 +1705,21 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
void
|
||||
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
#ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
||||
png_do_read_interlace_c
|
||||
#else
|
||||
png_do_read_interlace
|
||||
#endif /* PNG_HAVE_ASSEMBLER_READ_INTERLACE */
|
||||
(png_row_infop row_info, png_bytep row, int pass,
|
||||
png_uint_32 transformations)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
#endif
|
||||
|
||||
png_debug(1,"in png_do_read_interlace\n");
|
||||
if (row != NULL && row_info != NULL)
|
||||
{
|
||||
@@ -1864,6 +1900,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
|
||||
png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
|
||||
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
|
||||
|
||||
int jstop = png_pass_inc[pass];
|
||||
png_uint_32 i;
|
||||
|
||||
@@ -1890,15 +1927,17 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PNG_READ_SLOW_FILTERING
|
||||
void
|
||||
png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
#ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
||||
png_read_filter_row_c
|
||||
#else
|
||||
png_read_filter_row
|
||||
#endif /* PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */
|
||||
(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
png_bytep prev_row, int filter)
|
||||
{
|
||||
png_debug(1, "in png_read_filter_row\n");
|
||||
png_debug2(2,"row = %d, filter = %d\n", png_ptr->row_number, filter);
|
||||
|
||||
|
||||
switch (filter)
|
||||
{
|
||||
case PNG_FILTER_VALUE_NONE:
|
||||
@@ -1907,7 +1946,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
|
||||
png_bytep rp = row + bpp;
|
||||
png_bytep lp = row;
|
||||
|
||||
@@ -1938,20 +1977,20 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
png_bytep rp = row;
|
||||
png_bytep pp = prev_row;
|
||||
png_bytep lp = row;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
|
||||
png_uint_32 istop = row_info->rowbytes - bpp;
|
||||
|
||||
for (i = 0; i < bpp; i++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) +
|
||||
((int)(*pp++) / 2)) & 0xff);
|
||||
((int)(*pp++) / 2 )) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) +
|
||||
(int)(*pp++ + *lp++) / 2) & 0xff);
|
||||
(int)(*pp++ + *lp++) / 2 ) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
break;
|
||||
@@ -1963,7 +2002,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
png_bytep pp = prev_row;
|
||||
png_bytep lp = row;
|
||||
png_bytep cp = prev_row;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
|
||||
png_uint_32 istop=row_info->rowbytes - bpp;
|
||||
|
||||
for (i = 0; i < bpp; i++)
|
||||
@@ -2010,122 +2049,31 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
break;
|
||||
}
|
||||
default:
|
||||
png_error(png_ptr, "Bad adaptive filter type");
|
||||
png_warning(png_ptr, "Ignoring bad adaptive filter type");
|
||||
*row=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else /* PNG_READ_SLOW_FILTERING */
|
||||
void
|
||||
png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
png_bytep prev_row, int filter)
|
||||
{
|
||||
png_debug(1, "in png_read_filter_row\n");
|
||||
png_debug2(2,"row = %d, filter = %d\n", png_ptr->row_number, filter);
|
||||
|
||||
|
||||
switch (filter)
|
||||
{
|
||||
case PNG_FILTER_VALUE_NONE:
|
||||
break;
|
||||
case PNG_FILTER_VALUE_SUB:
|
||||
{
|
||||
png_uint_32 i;
|
||||
int bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_bytep rp;
|
||||
png_bytep lp;
|
||||
|
||||
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
|
||||
i < row_info->rowbytes; i++, rp++, lp++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PNG_FILTER_VALUE_UP:
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_bytep rp;
|
||||
png_bytep pp;
|
||||
|
||||
for (i = 0, rp = row, pp = prev_row;
|
||||
i < row_info->rowbytes; i++, rp++, pp++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PNG_FILTER_VALUE_AVG:
|
||||
{
|
||||
png_uint_32 i;
|
||||
int bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_bytep rp;
|
||||
png_bytep pp;
|
||||
png_bytep lp;
|
||||
|
||||
for (i = 0, rp = row, pp = prev_row;
|
||||
i < (png_uint_32)bpp; i++, rp++, pp++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) +
|
||||
((int)(*pp) / 2)) & 0xff);
|
||||
}
|
||||
for (lp = row; i < row_info->rowbytes; i++, rp++, lp++, pp++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) +
|
||||
(int)(*pp + *lp) / 2) & 0xff);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PNG_FILTER_VALUE_PAETH:
|
||||
{
|
||||
int bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_uint_32 i;
|
||||
png_bytep rp;
|
||||
png_bytep pp;
|
||||
png_bytep lp;
|
||||
png_bytep cp;
|
||||
|
||||
for (i = 0, rp = row, pp = prev_row,
|
||||
lp = row - bpp, cp = prev_row - bpp;
|
||||
i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++)
|
||||
{
|
||||
int a, b, c, pa, pb, pc, p;
|
||||
|
||||
b = *pp;
|
||||
if (i >= (png_uint_32)bpp)
|
||||
{
|
||||
c = *cp;
|
||||
a = *lp;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = c = 0;
|
||||
}
|
||||
p = a + b - c;
|
||||
pa = abs(p - a);
|
||||
pb = abs(p - b);
|
||||
pc = abs(p - c);
|
||||
|
||||
if (pa <= pb && pa <= pc)
|
||||
p = a;
|
||||
else if (pb <= pc)
|
||||
p = b;
|
||||
else
|
||||
p = c;
|
||||
|
||||
*rp = (png_byte)(((int)(*rp) + p) & 0xff);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
png_error(png_ptr, "Bad adaptive filter type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_SLOW_FILTERING */
|
||||
|
||||
void
|
||||
png_read_finish_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_read_finish_row\n");
|
||||
png_ptr->row_number++;
|
||||
if (png_ptr->row_number < png_ptr->num_rows)
|
||||
@@ -2166,6 +2114,9 @@ png_read_finish_row(png_structp png_ptr)
|
||||
|
||||
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
#endif
|
||||
char extra;
|
||||
int ret;
|
||||
|
||||
@@ -2186,7 +2137,7 @@ png_read_finish_row(png_structp png_ptr)
|
||||
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
|
||||
png_error(png_ptr, "Not enough image data");
|
||||
|
||||
}
|
||||
@@ -2229,6 +2180,22 @@ png_read_finish_row(png_structp png_ptr)
|
||||
void
|
||||
png_read_start_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
|
||||
int max_pixel_depth;
|
||||
png_uint_32 row_bytes;
|
||||
|
||||
@@ -2320,24 +2287,40 @@ png_read_start_row(png_structp png_ptr)
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
|
||||
{
|
||||
if ((png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
|
||||
png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
if (
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
(png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
|
||||
#endif
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED)
|
||||
(png_ptr->transformations & (PNG_FILLER)) ||
|
||||
#endif
|
||||
png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
if (max_pixel_depth <= 16)
|
||||
max_pixel_depth = 32;
|
||||
else if (max_pixel_depth <= 32)
|
||||
else
|
||||
max_pixel_depth = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (max_pixel_depth <= 8)
|
||||
max_pixel_depth = 24;
|
||||
else if (max_pixel_depth <= 16)
|
||||
else
|
||||
max_pixel_depth = 48;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
if(png_ptr->transformations & PNG_USER_TRANSFORM)
|
||||
{
|
||||
int user_pixel_depth=png_ptr->user_transform_depth*
|
||||
png_ptr->user_transform_channels;
|
||||
if(user_pixel_depth > max_pixel_depth)
|
||||
max_pixel_depth=user_pixel_depth;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* align the width on the next larger 8 pixels. Mainly used
|
||||
for interlacing */
|
||||
row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
|
||||
|
||||
52
pngset.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* The functions here are used during reads to store data from the file
|
||||
* into the info struct, and during writes to store application data
|
||||
@@ -107,7 +107,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
|
||||
/* check for overflow */
|
||||
rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;
|
||||
if (( width > (png_uint_32)2147483647L/rowbytes_per_pixel))
|
||||
if (( width > PNG_MAX_UINT/rowbytes_per_pixel))
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Width too large to process image data; rowbytes will overflow.");
|
||||
@@ -249,7 +249,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
png_set_sRGB(png_ptr, info_ptr, intent);
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
file_gamma = (float).45;
|
||||
file_gamma = (float).45455;
|
||||
png_set_gAMA(png_ptr, info_ptr, file_gamma);
|
||||
#endif
|
||||
|
||||
@@ -317,9 +317,10 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
for (i = 0; i < num_text; i++)
|
||||
{
|
||||
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
|
||||
png_charp key,text;
|
||||
|
||||
if (text_ptr[i].text == NULL)
|
||||
text_ptr[i].text = (png_charp)"";
|
||||
if (text_ptr[i].key == (png_charp)NULL)
|
||||
continue;
|
||||
|
||||
if (text_ptr[i].text[0] == '\0')
|
||||
{
|
||||
@@ -331,8 +332,30 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
textp->text_length = png_strlen(text_ptr[i].text);
|
||||
textp->compression = text_ptr[i].compression;
|
||||
}
|
||||
textp->text = text_ptr[i].text;
|
||||
textp->key = text_ptr[i].key;
|
||||
key=text_ptr[i].key;
|
||||
for (text = key; *text++;)
|
||||
/* empty loop to find the byte after the zero byte after the
|
||||
end of key */ ;
|
||||
|
||||
textp->key = (png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)(text+textp->text_length - key)+1);
|
||||
/* Caution: the calling program, not libpng, is responsible for
|
||||
freeing this, if libpng wasn't the caller. */
|
||||
png_debug2(2, "Allocated %d bytes at %x in png_set_text\n",
|
||||
text+textp->text_length-key+1, textp->key);
|
||||
|
||||
png_memcpy(textp->key, text_ptr[i].key,
|
||||
(png_size_t)(text - key)); /* includes the zero-byte separator */
|
||||
textp->text = textp->key + (text-key);
|
||||
if(textp->text_length)
|
||||
{
|
||||
png_memcpy(textp->text, text_ptr[i].text,
|
||||
(png_size_t)(textp->text_length));
|
||||
*(textp->text+textp->text_length) = '\0';
|
||||
}
|
||||
else
|
||||
textp->text--;
|
||||
info_ptr->text[info_ptr->num_text]= *textp;
|
||||
info_ptr->num_text++;
|
||||
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
|
||||
}
|
||||
@@ -344,7 +367,8 @@ void
|
||||
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "tIME");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
if (png_ptr == NULL || info_ptr == NULL ||
|
||||
(png_ptr->mode & PNG_WROTE_tIME))
|
||||
return;
|
||||
|
||||
png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time));
|
||||
@@ -378,3 +402,13 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED)
|
||||
void
|
||||
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
|
||||
{
|
||||
png_debug1(1, "in png_permit_empty_plte\n", "");
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->empty_plte_permitted=(png_byte)empty_plte_permitted;
|
||||
}
|
||||
#endif
|
||||
|
||||
221
pngtest.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* libpng 1.0.2 -June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This program reads in a PNG image, writes it out again, and then
|
||||
* compares the two files. If the files are identical, this shows that
|
||||
@@ -35,13 +35,31 @@
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
/* Turn on CPU timing
|
||||
#define PNGTEST_TIMING
|
||||
*/
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include "png.h"
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
#if !defined(PNG_READ_tIME_SUPPORTED) && !defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
static int tIME_chunk_present=0;
|
||||
static char tIME_string[30] = "no tIME chunk present in file";
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
static int verbose = 0;
|
||||
|
||||
int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
|
||||
|
||||
#ifdef __TURBOC__
|
||||
@@ -60,12 +78,12 @@ static int status_dots=1;
|
||||
void
|
||||
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
||||
{
|
||||
if(png_ptr == NULL || row_number > 0x3fffffffL) return;
|
||||
if(png_ptr == NULL || row_number > PNG_MAX_UINT) return;
|
||||
if(status_pass != pass)
|
||||
{
|
||||
fprintf(stdout,"\n Pass %d: ",pass);
|
||||
status_pass = pass;
|
||||
status_dots = 30;
|
||||
status_dots = 31;
|
||||
}
|
||||
status_dots--;
|
||||
if(status_dots == 0)
|
||||
@@ -79,11 +97,24 @@ read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
||||
void
|
||||
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
||||
{
|
||||
if(png_ptr == NULL || row_number > 0x3fffffffL || pass > 7) return;
|
||||
if(png_ptr == NULL || row_number > PNG_MAX_UINT || pass > 7) return;
|
||||
fprintf(stdout, "w");
|
||||
}
|
||||
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
/* Example of using user transform callback (we don't transform anything,
|
||||
but merely examine the row filters. We set this to 256 rather than
|
||||
5 in case illegal filter values are present.) */
|
||||
static png_uint_32 filters_used[256];
|
||||
void
|
||||
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
{
|
||||
if(png_ptr != NULL && row_info != NULL)
|
||||
++filters_used[*(data-1)];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
/* example of using user transform callback (we don't transform anything,
|
||||
but merely count the zero samples) */
|
||||
@@ -94,7 +125,7 @@ void
|
||||
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
{
|
||||
png_bytep dp = data;
|
||||
if(png_ptr == NULL)return;
|
||||
if(png_ptr == NULL)return;
|
||||
|
||||
/* contents of row_info:
|
||||
* png_uint_32 width width of row
|
||||
@@ -105,6 +136,7 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
* png_byte pixel_depth bits per pixel (depth*channels)
|
||||
*/
|
||||
|
||||
|
||||
/* counts the number of zero samples (or zero pixels if color_type is 3 */
|
||||
|
||||
if(row_info->color_type == 0 || row_info->color_type == 3)
|
||||
@@ -178,7 +210,6 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
}
|
||||
#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
|
||||
|
||||
static int verbose = 0;
|
||||
static int wrote_question = 0;
|
||||
|
||||
#if defined(PNG_NO_STDIO)
|
||||
@@ -211,10 +242,10 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
|
||||
static void
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
@@ -412,6 +443,10 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size) {
|
||||
pinformation = pinfo;
|
||||
/* Make sure the caller isn't assuming zeroed memory. */
|
||||
png_memset(pinfo->pointer, 0xdd, pinfo->size);
|
||||
#if PNG_DEBUG
|
||||
if(verbose)
|
||||
printf("png_malloc %d bytes at %x\n",size,pinfo->pointer);
|
||||
#endif
|
||||
return (png_voidp)(pinfo->pointer);
|
||||
}
|
||||
}
|
||||
@@ -454,6 +489,10 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
}
|
||||
|
||||
/* Finally free the data. */
|
||||
#if PNG_DEBUG
|
||||
if(verbose)
|
||||
printf("Freeing %x\n",ptr);
|
||||
#endif
|
||||
png_free_default(png_ptr, ptr);
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
@@ -465,7 +504,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
|
||||
png_structp read_ptr, write_ptr;
|
||||
png_infop read_info_ptr, write_info_ptr, end_info_ptr;
|
||||
png_infop read_info_ptr, write_info_ptr, end_info_ptr, write_end_info_ptr;
|
||||
png_bytep row_buf;
|
||||
png_uint_32 y;
|
||||
png_uint_32 width, height;
|
||||
@@ -474,7 +513,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
|
||||
|
||||
char inbuf[256], outbuf[256];
|
||||
|
||||
row_buf = (png_bytep)NULL;
|
||||
@@ -521,6 +560,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
read_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_info_ptr = png_create_info_struct(write_ptr);
|
||||
end_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_end_info_ptr = png_create_info_struct(write_ptr);
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
#endif
|
||||
|
||||
@@ -533,15 +573,18 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return (1);
|
||||
}
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
|
||||
png_debug(0, "Setting jmpbuf for write struct\n");
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
if (setjmp(jmpbuf))
|
||||
#else
|
||||
if (setjmp(write_ptr->jmpbuf))
|
||||
@@ -549,15 +592,16 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
|
||||
png_debug(0, "Initializing input and output streams\n");
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
png_init_io(read_ptr, fpin);
|
||||
@@ -582,10 +626,18 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_read_status_fn(read_ptr, NULL);
|
||||
}
|
||||
|
||||
# if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
zero_samples=0;
|
||||
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
|
||||
# endif
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<256; i++)
|
||||
filters_used[i]=0;
|
||||
png_set_read_user_transform_fn(read_ptr, count_filters);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
zero_samples=0;
|
||||
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
|
||||
#endif
|
||||
|
||||
png_debug(0, "Reading info struct\n");
|
||||
png_read_info(read_ptr, read_info_ptr);
|
||||
@@ -733,16 +785,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
|
||||
{
|
||||
png_set_tIME(write_ptr, write_info_ptr, mod_time);
|
||||
}
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
{
|
||||
/* we have to use png_strcpy instead of "=" because the string
|
||||
pointed to by png_convert_to_rfc1123() gets free'ed before
|
||||
we use it */
|
||||
png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
|
||||
tIME_chunk_present++;
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
@@ -761,15 +811,20 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif
|
||||
|
||||
png_debug(0, "\nWriting info struct\n");
|
||||
|
||||
/* If we wanted, we could write info in two steps:
|
||||
png_write_info_before_PLTE(write_ptr, write_info_ptr);
|
||||
*/
|
||||
png_write_info(write_ptr, write_info_ptr);
|
||||
|
||||
png_debug(0, "\nAllocating row buffer \n");
|
||||
row_buf = (png_bytep)png_malloc(read_ptr,
|
||||
row_buf = (png_bytep)png_malloc(read_ptr,
|
||||
png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
if (row_buf == NULL)
|
||||
{
|
||||
fprintf(STDERR, "No memory to allocate row buffer\n");
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
@@ -777,23 +832,73 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
png_debug(0, "Writing row data\n");
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
|
||||
defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
num_pass = png_set_interlace_handling(read_ptr);
|
||||
png_set_interlace_handling(write_ptr);
|
||||
#else
|
||||
num_pass=1;
|
||||
#endif
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
t_stop = (float)clock();
|
||||
t_misc += (t_stop - t_start);
|
||||
t_start = t_stop;
|
||||
#endif
|
||||
for (pass = 0; pass < num_pass; pass++)
|
||||
{
|
||||
png_debug1(0, "Writing row data for pass %d\n",pass);
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1);
|
||||
#ifdef PNGTEST_TIMING
|
||||
t_stop = (float)clock();
|
||||
t_decode += (t_stop - t_start);
|
||||
t_start = t_stop;
|
||||
#endif
|
||||
png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
|
||||
#ifdef PNGTEST_TIMING
|
||||
t_stop = (float)clock();
|
||||
t_encode += (t_stop - t_start);
|
||||
t_start = t_stop;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
png_debug(0, "Reading and writing end_info data\n");
|
||||
png_read_end(read_ptr, end_info_ptr);
|
||||
png_write_end(write_ptr, end_info_ptr);
|
||||
|
||||
#if (defined(PNG_READ_tEXt_SUPPORTED) && defined(PNG_WRITE_tEXt_SUPPORTED)) || \
|
||||
(defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED))
|
||||
{
|
||||
png_textp text_ptr;
|
||||
int num_text;
|
||||
|
||||
if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
|
||||
{
|
||||
png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text);
|
||||
png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) && defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
{
|
||||
png_timep mod_time;
|
||||
|
||||
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
|
||||
{
|
||||
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
/* we have to use png_strcpy instead of "=" because the string
|
||||
pointed to by png_convert_to_rfc1123() gets free'ed before
|
||||
we use it */
|
||||
png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
|
||||
tIME_chunk_present++;
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
png_write_end(write_ptr, write_end_info_ptr);
|
||||
|
||||
#ifdef PNG_EASY_ACCESS_SUPPORTED
|
||||
if(verbose)
|
||||
{
|
||||
@@ -808,6 +913,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_debug(0, "Destroying data structs\n");
|
||||
png_free(read_ptr, row_buf);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
|
||||
fclose(fpin);
|
||||
@@ -859,7 +965,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
|
||||
if (png_memcmp(inbuf, outbuf, num_in))
|
||||
{
|
||||
fprintf(STDERR, "Files %s and %s are different\n", inname, outname);
|
||||
fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
|
||||
if(wrote_question == 0)
|
||||
{
|
||||
fprintf(STDERR,
|
||||
@@ -885,8 +991,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
|
||||
/* input and output filenames */
|
||||
#ifdef RISCOS
|
||||
PNG_CONST char *inname = "pngtest/png";
|
||||
PNG_CONST char *outname = "pngout/png";
|
||||
static PNG_CONST char *inname = "pngtest/png";
|
||||
static PNG_CONST char *outname = "pngout/png";
|
||||
#else
|
||||
static PNG_CONST char *inname = "pngtest.png";
|
||||
static PNG_CONST char *outname = "pngout.png";
|
||||
@@ -900,6 +1006,11 @@ main(int argc, char *argv[])
|
||||
|
||||
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
|
||||
fprintf(STDERR,"%s",png_get_copyright(NULL));
|
||||
/* Show the version of libpng used in building the library */
|
||||
fprintf(STDERR," library:%s",png_get_header_version(NULL));
|
||||
/* Show the version of libpng used in building the application */
|
||||
fprintf(STDERR," pngtest:%s",PNG_HEADER_VERSION_STRING);
|
||||
|
||||
/* Do some consistency checking on the memory allocation settings, I'm
|
||||
not sure this matters, but it is nice to know, the first of these
|
||||
@@ -972,16 +1083,22 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
for (i=2; i<argc; ++i)
|
||||
{
|
||||
int kerror;
|
||||
int k, kerror;
|
||||
fprintf(STDERR, "Testing %s:",argv[i]);
|
||||
kerror = test_one_file(argv[i], outname);
|
||||
if (kerror == 0)
|
||||
if (kerror == 0)
|
||||
{
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
for (k=0; k<256; k++)
|
||||
if(filters_used[k])
|
||||
fprintf(STDERR, " Filter %d was used %lu times\n",
|
||||
k,filters_used[k]);
|
||||
#endif
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
if(tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n",tIME_string);
|
||||
@@ -1010,7 +1127,9 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
}
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
|
||||
fprintf(STDERR, " Current memory allocation: %d bytes\n",
|
||||
current_allocation);
|
||||
fprintf(STDERR, " Maximum memory allocation: %d bytes\n",
|
||||
maximum_allocation);
|
||||
#endif
|
||||
}
|
||||
@@ -1031,14 +1150,21 @@ main(int argc, char *argv[])
|
||||
{
|
||||
if(verbose == 1 || i == 2)
|
||||
{
|
||||
int k;
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
for (k=0; k<256; k++)
|
||||
if(filters_used[k])
|
||||
fprintf(STDERR, " Filter %d was used %lu times\n",
|
||||
k,filters_used[k]);
|
||||
#endif
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
if(tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n",tIME_string);
|
||||
if(tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n",tIME_string);
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
}
|
||||
}
|
||||
@@ -1055,7 +1181,7 @@ main(int argc, char *argv[])
|
||||
current_allocation-allocation_now);
|
||||
if (current_allocation != 0) {
|
||||
memory_infop pinfo = pinformation;
|
||||
|
||||
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
|
||||
current_allocation);
|
||||
while (pinfo != NULL) {
|
||||
@@ -1066,11 +1192,27 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
}
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
|
||||
fprintf(STDERR, " Current memory allocation: %d bytes\n",
|
||||
current_allocation);
|
||||
fprintf(STDERR, " Maximum memory allocation: %d bytes\n",
|
||||
maximum_allocation);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
t_stop = (float)clock();
|
||||
t_misc += (t_stop - t_start);
|
||||
t_start = t_stop;
|
||||
fprintf(STDERR," CPU time used = %.3f seconds",
|
||||
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
|
||||
fprintf(STDERR," (decoding %.3f,\n",
|
||||
t_decode/(float)CLOCKS_PER_SEC);
|
||||
fprintf(STDERR," encoding %.3f ,",
|
||||
t_encode/(float)CLOCKS_PER_SEC);
|
||||
fprintf(STDERR," other %.3f seconds)\n\n",
|
||||
t_misc/(float)CLOCKS_PER_SEC);
|
||||
#endif
|
||||
|
||||
if (ierror == 0)
|
||||
fprintf(STDERR, "libpng passes test\n");
|
||||
else
|
||||
@@ -1078,3 +1220,10 @@ main(int argc, char *argv[])
|
||||
return (int)(ierror != 0);
|
||||
}
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
void
|
||||
png_check_pngtest_version
|
||||
(version_1_0_5d png_h_is_not_version_1_0_5d)
|
||||
{
|
||||
if(png_h_is_not_version_1_0_5d == NULL) return;
|
||||
}
|
||||
|
||||
47
pngtrans.c
@@ -1,18 +1,18 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* turn on bgr to rgb mapping */
|
||||
/* turn on BGR-to-RGB mapping */
|
||||
void
|
||||
png_set_bgr(png_structp png_ptr)
|
||||
{
|
||||
@@ -99,6 +99,24 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
|
||||
else
|
||||
png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
|
||||
|
||||
/* This should probably go in the "do_filler" routine.
|
||||
* I attempted to do that in libpng-1.0.1a but that caused problems
|
||||
* so I restored it in libpng-1.0.2a
|
||||
*/
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
png_ptr->usr_channels = 4;
|
||||
}
|
||||
|
||||
/* Also I added this in libpng-1.0.2a (what happens when we expand
|
||||
* a less-than-8-bit grayscale to GA? */
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
|
||||
{
|
||||
png_ptr->usr_channels = 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -552,3 +570,26 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
}
|
||||
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
void
|
||||
png_set_user_transform_info(png_structp png_ptr, png_voidp
|
||||
user_transform_ptr, int user_transform_depth, int user_transform_channels)
|
||||
{
|
||||
png_debug(1, "in png_set_user_transform_info\n");
|
||||
png_ptr->user_transform_ptr = user_transform_ptr;
|
||||
png_ptr->user_transform_depth = (png_byte)user_transform_depth;
|
||||
png_ptr->user_transform_channels = (png_byte)user_transform_channels;
|
||||
}
|
||||
|
||||
/* This function returns a pointer to the user_transform_ptr associated with
|
||||
* the user transform functions. The application should free any memory
|
||||
* associated with this pointer before png_write_destroy and png_read_destroy
|
||||
* are called.
|
||||
*/
|
||||
png_voidp
|
||||
png_get_user_transform_ptr(png_structp png_ptr)
|
||||
{
|
||||
return ((png_voidp)png_ptr->user_transform_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
31
pngtypes.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/* pngtypes.h - array of chunk-types for libpng
|
||||
*
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
/* Constant strings for known chunk types. If you need to add a chunk,
|
||||
* define the string in png.h and invoke it here.
|
||||
*/
|
||||
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
PNG_bKGD;
|
||||
PNG_cHRM;
|
||||
PNG_gAMA;
|
||||
PNG_hIST;
|
||||
PNG_oFFs;
|
||||
PNG_pCAL;
|
||||
PNG_pHYs;
|
||||
PNG_sBIT;
|
||||
PNG_sRGB;
|
||||
PNG_tEXt;
|
||||
PNG_tIME;
|
||||
PNG_tRNS;
|
||||
PNG_zTXt;
|
||||
|
||||
12
pngwio.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all output. Users who need
|
||||
* special handling are expected to write functions that have the same
|
||||
@@ -184,11 +184,11 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(USE_FAR_KEYWORD)
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(USE_FAR_KEYWORD)
|
||||
#if defined(_MSC_VER)
|
||||
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
|
||||
{
|
||||
void *near_ptr;
|
||||
void *near_ptr;
|
||||
void FAR *far_ptr;
|
||||
FP_OFF(near_ptr) = FP_OFF(ptr);
|
||||
far_ptr = (void FAR *)near_ptr;
|
||||
@@ -200,7 +200,7 @@ void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
|
||||
# else
|
||||
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
|
||||
{
|
||||
void *near_ptr;
|
||||
void *near_ptr;
|
||||
void FAR *far_ptr;
|
||||
near_ptr = (void FAR *)ptr;
|
||||
far_ptr = (void FAR *)near_ptr;
|
||||
|
||||
62
pngwrite.c
@@ -1,11 +1,11 @@
|
||||
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
/* get internal access to png.h */
|
||||
@@ -22,13 +22,11 @@
|
||||
* them in png_write_end(), and compressing them.
|
||||
*/
|
||||
void
|
||||
png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_info\n");
|
||||
png_debug(1, "in png_write_info_before_PLTE\n");
|
||||
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
|
||||
{
|
||||
png_write_sig(png_ptr); /* write PNG signature */
|
||||
/* write IHDR information. */
|
||||
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
|
||||
@@ -61,6 +59,21 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
info_ptr->x_green, info_ptr->y_green,
|
||||
info_ptr->x_blue, info_ptr->y_blue);
|
||||
#endif
|
||||
png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_info\n");
|
||||
|
||||
png_write_info_before_PLTE(png_ptr, info_ptr);
|
||||
|
||||
if (info_ptr->valid & PNG_INFO_PLTE)
|
||||
png_write_PLTE(png_ptr, info_ptr->palette,
|
||||
(png_uint_32)info_ptr->num_palette);
|
||||
@@ -77,7 +90,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
int j;
|
||||
for (j=0; j<(int)info_ptr->num_trans; j++)
|
||||
info_ptr->trans[j] = 255 - info_ptr->trans[j];
|
||||
info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
|
||||
}
|
||||
#endif
|
||||
png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
|
||||
@@ -112,7 +125,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
if (info_ptr->valid & PNG_INFO_tIME)
|
||||
{
|
||||
png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
||||
png_ptr->flags |= PNG_FLAG_WROTE_tIME;
|
||||
png_ptr->mode |= PNG_WROTE_tIME;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
@@ -172,7 +185,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* check to see if user has supplied a time chunk */
|
||||
if (info_ptr->valid & PNG_INFO_tIME &&
|
||||
!(png_ptr->flags & PNG_FLAG_WROTE_tIME))
|
||||
!(png_ptr->mode & PNG_WROTE_tIME))
|
||||
png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
@@ -630,8 +643,22 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_WRITE_tEXt_SUPPORTED
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
png_debug(1, "in png_info_destroy\n");
|
||||
if (info_ptr->text != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
if(info_ptr->text[i].key != NULL)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->text[i].key);
|
||||
info_ptr->text[i].key = NULL;
|
||||
}
|
||||
}
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
info_ptr->text = NULL;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
@@ -799,7 +826,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
if (png_ptr->prev_row == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Can't add Paeth filter after starting");
|
||||
png_ptr->do_filter &= ~PNG_FILTER_PAETH;
|
||||
png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -850,8 +877,8 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
|
||||
num_weights = 0;
|
||||
}
|
||||
|
||||
png_ptr->num_prev_filters = num_weights;
|
||||
png_ptr->heuristic_method = heuristic_method;
|
||||
png_ptr->num_prev_filters = (png_byte)num_weights;
|
||||
png_ptr->heuristic_method = (png_byte)heuristic_method;
|
||||
|
||||
if (num_weights > 0)
|
||||
{
|
||||
@@ -971,6 +998,8 @@ png_set_compression_window_bits(png_structp png_ptr, int window_bits)
|
||||
{
|
||||
if (window_bits > 15)
|
||||
png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
|
||||
else if (window_bits < 8)
|
||||
png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
|
||||
png_ptr->zlib_window_bits = window_bits;
|
||||
}
|
||||
@@ -1001,4 +1030,3 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
|
||||
png_ptr->write_user_transform_fn = write_user_transform_fn;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
28
pngwtran.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -47,15 +47,15 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
@@ -102,7 +102,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
dp = row;
|
||||
mask = 0x80;
|
||||
v = 0;
|
||||
|
||||
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if (*sp != 0)
|
||||
@@ -311,7 +311,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
png_uint_16 value, v;
|
||||
int j;
|
||||
|
||||
v = ((png_uint_16)(*bp) << 8) + *(bp + 1);
|
||||
v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
|
||||
value = 0;
|
||||
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
|
||||
{
|
||||
@@ -438,7 +438,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in RRGGBBAA */
|
||||
@@ -456,8 +456,8 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -473,7 +473,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in GGAA */
|
||||
@@ -487,8 +487,8 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
195
pngwutil.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
*
|
||||
* libpng 1.0.2 - June 14, 1998
|
||||
* libpng 1.0.5d - November 29, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -127,8 +127,9 @@ png_write_chunk_end(png_structp png_ptr)
|
||||
void
|
||||
png_write_sig(png_structp png_ptr)
|
||||
{
|
||||
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
/* write the rest of the 8 byte signature */
|
||||
png_write_data(png_ptr, &png_sig[png_ptr->sig_bytes],
|
||||
png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
|
||||
(png_size_t)8 - png_ptr->sig_bytes);
|
||||
}
|
||||
|
||||
@@ -141,6 +142,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
int bit_depth, int color_type, int compression_type, int filter_type,
|
||||
int interlace_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
#endif
|
||||
png_byte buf[13]; /* buffer to store the IHDR info */
|
||||
|
||||
png_debug(1, "in png_write_IHDR\n");
|
||||
@@ -234,7 +238,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
buf[12] = (png_byte)interlace_type;
|
||||
|
||||
/* write the chunk */
|
||||
png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
|
||||
|
||||
/* initialize zlib with PNG info */
|
||||
png_ptr->zstream.zalloc = png_zalloc;
|
||||
@@ -279,28 +283,35 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
void
|
||||
png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_PLTE;
|
||||
#endif
|
||||
png_uint_32 i;
|
||||
png_colorp pal_ptr;
|
||||
png_byte buf[3];
|
||||
|
||||
png_debug(1, "in png_write_PLTE\n");
|
||||
if (num_pal == 0 || num_pal > 256)
|
||||
{
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
png_error(png_ptr, "Invalid number of colors in palette");
|
||||
}
|
||||
else
|
||||
{
|
||||
png_warning(png_ptr, "Invalid number of colors in palette");
|
||||
return;
|
||||
}
|
||||
if ((
|
||||
#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED
|
||||
!png_ptr->empty_plte_permitted &&
|
||||
#endif
|
||||
num_pal == 0) || num_pal > 256)
|
||||
{
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
png_error(png_ptr, "Invalid number of colors in palette");
|
||||
}
|
||||
else
|
||||
{
|
||||
png_warning(png_ptr, "Invalid number of colors in palette");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
png_ptr->num_palette = (png_uint_16)num_pal;
|
||||
png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
|
||||
|
||||
png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
|
||||
png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, num_pal * 3);
|
||||
for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
|
||||
{
|
||||
buf[0] = pal_ptr->red;
|
||||
@@ -316,8 +327,11 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
|
||||
void
|
||||
png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
#endif
|
||||
png_debug(1, "in png_write_IDAT\n");
|
||||
png_write_chunk(png_ptr, png_IDAT, data, length);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
|
||||
png_ptr->mode |= PNG_HAVE_IDAT;
|
||||
}
|
||||
|
||||
@@ -325,8 +339,11 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
void
|
||||
png_write_IEND(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IEND;
|
||||
#endif
|
||||
png_debug(1, "in png_write_IEND\n");
|
||||
png_write_chunk(png_ptr, png_IEND, NULL, (png_size_t)0);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL, (png_size_t)0);
|
||||
png_ptr->mode |= PNG_HAVE_IEND;
|
||||
}
|
||||
|
||||
@@ -335,6 +352,9 @@ png_write_IEND(png_structp png_ptr)
|
||||
void
|
||||
png_write_gAMA(png_structp png_ptr, double file_gamma)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
png_uint_32 igamma;
|
||||
png_byte buf[4];
|
||||
|
||||
@@ -342,7 +362,7 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
|
||||
/* file_gamma is saved in 1/1000000ths */
|
||||
igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
|
||||
png_save_uint_32(buf, igamma);
|
||||
png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -351,6 +371,9 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
|
||||
void
|
||||
png_write_sRGB(png_structp png_ptr, int srgb_intent)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
png_byte buf[1];
|
||||
|
||||
png_debug(1, "in png_write_sRGB\n");
|
||||
@@ -358,7 +381,7 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
|
||||
png_warning(png_ptr,
|
||||
"Invalid sRGB rendering intent specified");
|
||||
buf[0]=(png_byte)srgb_intent;
|
||||
png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -367,6 +390,9 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
|
||||
void
|
||||
png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
png_byte buf[4];
|
||||
png_size_t size;
|
||||
|
||||
@@ -376,9 +402,10 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
|
||||
{
|
||||
png_byte maxbits;
|
||||
|
||||
maxbits = color_type==PNG_COLOR_TYPE_PALETTE ? 8:png_ptr->usr_bit_depth;
|
||||
if (sbit->red == 0 || sbit->red > maxbits ||
|
||||
sbit->green == 0 || sbit->green > maxbits ||
|
||||
maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
|
||||
png_ptr->usr_bit_depth);
|
||||
if (sbit->red == 0 || sbit->red > maxbits ||
|
||||
sbit->green == 0 || sbit->green > maxbits ||
|
||||
sbit->blue == 0 || sbit->blue > maxbits)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid sBIT depth specified");
|
||||
@@ -410,7 +437,7 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
|
||||
buf[size++] = sbit->alpha;
|
||||
}
|
||||
|
||||
png_write_chunk(png_ptr, png_sBIT, buf, size);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -421,6 +448,9 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
|
||||
double red_x, double red_y, double green_x, double green_y,
|
||||
double blue_x, double blue_y)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
png_uint_32 itemp;
|
||||
png_byte buf[32];
|
||||
|
||||
@@ -470,7 +500,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
|
||||
itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
|
||||
png_save_uint_32(buf + 28, itemp);
|
||||
|
||||
png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -480,6 +510,9 @@ void
|
||||
png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
int num_trans, int color_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
png_byte buf[6];
|
||||
|
||||
png_debug(1, "in png_write_tRNS\n");
|
||||
@@ -491,13 +524,13 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
return;
|
||||
}
|
||||
/* write the chunk out as it is */
|
||||
png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, (png_size_t)num_trans);
|
||||
}
|
||||
else if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
/* one 16 bit value */
|
||||
png_save_uint_16(buf, tran->gray);
|
||||
png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
|
||||
}
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
@@ -505,7 +538,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
png_save_uint_16(buf, tran->red);
|
||||
png_save_uint_16(buf + 2, tran->green);
|
||||
png_save_uint_16(buf + 4, tran->blue);
|
||||
png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -519,30 +552,38 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
void
|
||||
png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
png_byte buf[6];
|
||||
|
||||
png_debug(1, "in png_write_bKGD\n");
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
if (back->index > png_ptr->num_palette)
|
||||
if (
|
||||
#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED
|
||||
(!png_ptr->empty_plte_permitted ||
|
||||
(png_ptr->empty_plte_permitted && png_ptr->num_palette)) &&
|
||||
#endif
|
||||
back->index > png_ptr->num_palette)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid background palette index");
|
||||
return;
|
||||
}
|
||||
buf[0] = back->index;
|
||||
png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);
|
||||
}
|
||||
else if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
png_save_uint_16(buf, back->red);
|
||||
png_save_uint_16(buf + 2, back->green);
|
||||
png_save_uint_16(buf + 4, back->blue);
|
||||
png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_save_uint_16(buf, back->gray);
|
||||
png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -552,6 +593,9 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
|
||||
void
|
||||
png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_hIST;
|
||||
#endif
|
||||
int i;
|
||||
png_byte buf[3];
|
||||
|
||||
@@ -564,7 +608,7 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
|
||||
return;
|
||||
}
|
||||
|
||||
png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
|
||||
png_write_chunk_start(png_ptr, (png_bytep)png_hIST, (png_uint_32)(num_hist * 2));
|
||||
for (i = 0; i < num_hist; i++)
|
||||
{
|
||||
png_save_uint_16(buf, hist[i]);
|
||||
@@ -678,6 +722,8 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
|
||||
|
||||
if (key_len == 0)
|
||||
{
|
||||
png_free(png_ptr, *new_key);
|
||||
*new_key=NULL;
|
||||
png_chunk_warning(png_ptr, "zero length keyword");
|
||||
}
|
||||
|
||||
@@ -698,6 +744,9 @@ void
|
||||
png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
png_size_t text_len)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
png_size_t key_len;
|
||||
png_charp new_key;
|
||||
|
||||
@@ -712,7 +761,12 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
text_len = 0;
|
||||
|
||||
/* make sure we include the 0 after the key */
|
||||
png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
|
||||
png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, (png_uint_32)key_len+text_len+1);
|
||||
/*
|
||||
* We leave it to the application to meet PNG-1.0 requirements on the
|
||||
* contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
|
||||
* any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
|
||||
*/
|
||||
png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
|
||||
if (text_len)
|
||||
png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
|
||||
@@ -728,6 +782,9 @@ void
|
||||
png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
png_size_t text_len, int compression)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
png_size_t key_len;
|
||||
char buf[1];
|
||||
png_charp new_key;
|
||||
@@ -897,7 +954,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
|
||||
|
||||
/* write start of chunk */
|
||||
png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)(key_len+text_len+2));
|
||||
png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, (png_uint_32)(key_len+text_len+2));
|
||||
/* write key */
|
||||
png_write_chunk_data(png_ptr, (png_bytep)key, key_len + 1);
|
||||
buf[0] = (png_byte)compression;
|
||||
@@ -932,6 +989,9 @@ png_write_oFFs(png_structp png_ptr, png_uint_32 x_offset,
|
||||
png_uint_32 y_offset,
|
||||
int unit_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
png_byte buf[9];
|
||||
|
||||
png_debug(1, "in png_write_oFFs\n");
|
||||
@@ -942,7 +1002,7 @@ png_write_oFFs(png_structp png_ptr, png_uint_32 x_offset,
|
||||
png_save_uint_32(buf + 4, y_offset);
|
||||
buf[8] = (png_byte)unit_type;
|
||||
|
||||
png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -952,7 +1012,10 @@ void
|
||||
png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
|
||||
png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
|
||||
{
|
||||
png_size_t purpose_len, units_len, total_len;
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
png_size_t purpose_len, units_len, total_len;
|
||||
png_uint_32p params_len;
|
||||
png_byte buf[10];
|
||||
png_charp new_purpose;
|
||||
@@ -981,7 +1044,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
|
||||
}
|
||||
|
||||
png_debug1(3, "pCAL total length = %d\n", total_len);
|
||||
png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
|
||||
png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
|
||||
png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
|
||||
png_save_int_32(buf, X0);
|
||||
png_save_int_32(buf + 4, X1);
|
||||
@@ -1010,6 +1073,9 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
|
||||
png_uint_32 y_pixels_per_unit,
|
||||
int unit_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
png_byte buf[9];
|
||||
|
||||
png_debug(1, "in png_write_pHYs\n");
|
||||
@@ -1020,7 +1086,7 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
|
||||
png_save_uint_32(buf + 4, y_pixels_per_unit);
|
||||
buf[8] = (png_byte)unit_type;
|
||||
|
||||
png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1031,6 +1097,9 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
|
||||
void
|
||||
png_write_tIME(png_structp png_ptr, png_timep mod_time)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_tIME;
|
||||
#endif
|
||||
png_byte buf[7];
|
||||
|
||||
png_debug(1, "in png_write_tIME\n");
|
||||
@@ -1049,7 +1118,7 @@ png_write_tIME(png_structp png_ptr, png_timep mod_time)
|
||||
buf[5] = mod_time->minute;
|
||||
buf[6] = mod_time->second;
|
||||
|
||||
png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1057,6 +1126,22 @@ png_write_tIME(png_structp png_ptr, png_timep mod_time)
|
||||
void
|
||||
png_write_start_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
|
||||
png_size_t buf_size;
|
||||
|
||||
png_debug(1, "in png_write_start_row\n");
|
||||
@@ -1135,6 +1220,22 @@ png_write_start_row(png_structp png_ptr)
|
||||
void
|
||||
png_write_finish_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
|
||||
int ret;
|
||||
|
||||
png_debug(1, "in png_write_finish_row\n");
|
||||
@@ -1180,7 +1281,7 @@ png_write_finish_row(png_structp png_ptr)
|
||||
if (png_ptr->pass < 7)
|
||||
{
|
||||
if (png_ptr->prev_row != NULL)
|
||||
png_memset(png_ptr->prev_row, 0,
|
||||
png_memset(png_ptr->prev_row, 0,
|
||||
(png_size_t) (((png_uint_32)png_ptr->usr_channels *
|
||||
(png_uint_32)png_ptr->usr_bit_depth *
|
||||
png_ptr->width + 7) >> 3) + 1);
|
||||
@@ -1233,6 +1334,16 @@ png_write_finish_row(png_structp png_ptr)
|
||||
void
|
||||
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_do_write_interlace\n");
|
||||
/* we don't have to do anything on the last pass (6) */
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
@@ -1772,7 +1883,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
for (lp = row_buf + 1; i < row_bytes; i++)
|
||||
{
|
||||
v = *dp++ =
|
||||
v = *dp++ =
|
||||
(png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
|
||||
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
# Project: libpng
|
||||
|
||||
|
||||
# Toolflags:
|
||||
CCflags = -c -depend !Depend -IC:,Zlib: -g -throwback -DRISCOS -fnah
|
||||
C++flags = -c -depend !Depend -IC: -throwback
|
||||
Linkflags = -aif -c++ -o $@
|
||||
ObjAsmflags = -throwback -NoCache -depend !Depend
|
||||
CMHGflags =
|
||||
LibFileflags = -c -l -o $@
|
||||
Squeezeflags = -o $@
|
||||
|
||||
|
||||
# Final targets:
|
||||
@.libpng-lib: @.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \
|
||||
@.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngrtran \
|
||||
@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
|
||||
LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngrtran \
|
||||
@.o.pngmem @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngwio \
|
||||
@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
|
||||
@.mm-libpng-lib: @.mm.png @.mm.pngerror @.mm.pngrio @.mm.pngwio @.mm.pngmem \
|
||||
@.mm.pngpread @.mm.pngset @.mm.pngget @.mm.pngread @.mm.pngrtran \
|
||||
@.mm.pngrutil @.mm.pngtrans @.mm.pngwrite @.mm.pngwtran @.mm.pngwutil
|
||||
LibFile $(LibFileflags) @.mm.png @.mm.pngerror @.mm.pngrio \
|
||||
@.mm.pngwio @.mm.pngmem @.mm.pngpread @.mm.pngset @.mm.pngget \
|
||||
@.mm.pngread @.mm.pngrtran @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite \
|
||||
@.mm.pngwtran @.mm.pngwutil
|
||||
|
||||
|
||||
# User-editable dependencies:
|
||||
# (C) Copyright 1997 Tom Tanner
|
||||
Test: @.pngtest
|
||||
<Prefix$Dir>.pngtest
|
||||
@remove <Prefix$Dir>.pngtest
|
||||
|
||||
#It would be nice if you could stop "make" listing from here on!
|
||||
@.pngtest: @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
|
||||
Link $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
|
||||
|
||||
.SUFFIXES: .o .mm .c
|
||||
|
||||
.c.mm:
|
||||
MemCheck.CC cc $(ccflags) -o $@ LibPng:$<
|
||||
.c.o:
|
||||
cc $(ccflags) -o $@ $<
|
||||
|
||||
|
||||
# Static dependencies:
|
||||
|
||||
|
||||
# Dynamic dependencies:
|
||||
o.pngtest: c.pngtest
|
||||
o.pngtest: h.png
|
||||
o.pngtest: Zlib:h.zlib
|
||||
o.pngtest: Zlib:h.zconf
|
||||
o.pngtest: h.pngconf
|
||||
mm.png: LibPng:c.png
|
||||
mm.png: LibPng:h.png
|
||||
mm.png: Zlib:h.zlib
|
||||
mm.png: Zlib:h.zconf
|
||||
mm.png: LibPng:h.pngconf
|
||||
mm.png: MemCheck:ANSI.h.stdio
|
||||
mm.pngerror: LibPng:c.pngerror
|
||||
mm.pngerror: LibPng:h.png
|
||||
mm.pngerror: Zlib:h.zlib
|
||||
mm.pngerror: Zlib:h.zconf
|
||||
mm.pngerror: LibPng:h.pngconf
|
||||
mm.pngerror: MemCheck:ANSI.h.stdio
|
||||
mm.pngrio: LibPng:c.pngrio
|
||||
mm.pngrio: LibPng:h.png
|
||||
mm.pngrio: Zlib:h.zlib
|
||||
mm.pngrio: Zlib:h.zconf
|
||||
mm.pngrio: LibPng:h.pngconf
|
||||
mm.pngrio: MemCheck:ANSI.h.stdio
|
||||
mm.pngwio: LibPng:c.pngwio
|
||||
mm.pngwio: LibPng:h.png
|
||||
mm.pngwio: Zlib:h.zlib
|
||||
mm.pngwio: Zlib:h.zconf
|
||||
mm.pngwio: LibPng:h.pngconf
|
||||
mm.pngwio: MemCheck:ANSI.h.stdio
|
||||
mm.pngmem: LibPng:c.pngmem
|
||||
mm.pngmem: LibPng:h.png
|
||||
mm.pngmem: Zlib:h.zlib
|
||||
mm.pngmem: Zlib:h.zconf
|
||||
mm.pngmem: LibPng:h.pngconf
|
||||
mm.pngmem: MemCheck:ANSI.h.stdio
|
||||
mm.pngpread: LibPng:c.pngpread
|
||||
mm.pngpread: LibPng:h.png
|
||||
mm.pngpread: Zlib:h.zlib
|
||||
mm.pngpread: Zlib:h.zconf
|
||||
mm.pngpread: LibPng:h.pngconf
|
||||
mm.pngpread: MemCheck:ANSI.h.stdio
|
||||
mm.pngset: LibPng:c.pngset
|
||||
mm.pngset: LibPng:h.png
|
||||
mm.pngset: Zlib:h.zlib
|
||||
mm.pngset: Zlib:h.zconf
|
||||
mm.pngset: LibPng:h.pngconf
|
||||
mm.pngset: MemCheck:ANSI.h.stdio
|
||||
mm.pngget: LibPng:c.pngget
|
||||
mm.pngget: LibPng:h.png
|
||||
mm.pngget: Zlib:h.zlib
|
||||
mm.pngget: Zlib:h.zconf
|
||||
mm.pngget: LibPng:h.pngconf
|
||||
mm.pngget: MemCheck:ANSI.h.stdio
|
||||
mm.pngread: LibPng:c.pngread
|
||||
mm.pngread: LibPng:h.png
|
||||
mm.pngread: Zlib:h.zlib
|
||||
mm.pngread: Zlib:h.zconf
|
||||
mm.pngread: LibPng:h.pngconf
|
||||
mm.pngread: MemCheck:ANSI.h.stdio
|
||||
mm.pngrtran: LibPng:c.pngrtran
|
||||
mm.pngrtran: LibPng:h.png
|
||||
mm.pngrtran: Zlib:h.zlib
|
||||
mm.pngrtran: Zlib:h.zconf
|
||||
mm.pngrtran: LibPng:h.pngconf
|
||||
mm.pngrtran: MemCheck:ANSI.h.stdio
|
||||
mm.pngrutil: LibPng:c.pngrutil
|
||||
mm.pngrutil: LibPng:h.png
|
||||
mm.pngrutil: Zlib:h.zlib
|
||||
mm.pngrutil: Zlib:h.zconf
|
||||
mm.pngrutil: LibPng:h.pngconf
|
||||
mm.pngrutil: MemCheck:ANSI.h.stdio
|
||||
mm.pngtrans: LibPng:c.pngtrans
|
||||
mm.pngtrans: LibPng:h.png
|
||||
mm.pngtrans: Zlib:h.zlib
|
||||
mm.pngtrans: Zlib:h.zconf
|
||||
mm.pngtrans: LibPng:h.pngconf
|
||||
mm.pngtrans: MemCheck:ANSI.h.stdio
|
||||
mm.pngwrite: LibPng:c.pngwrite
|
||||
mm.pngwrite: LibPng:h.png
|
||||
mm.pngwrite: Zlib:h.zlib
|
||||
mm.pngwrite: Zlib:h.zconf
|
||||
mm.pngwrite: LibPng:h.pngconf
|
||||
mm.pngwrite: MemCheck:ANSI.h.stdio
|
||||
mm.pngwtran: LibPng:c.pngwtran
|
||||
mm.pngwtran: LibPng:h.png
|
||||
mm.pngwtran: Zlib:h.zlib
|
||||
mm.pngwtran: Zlib:h.zconf
|
||||
mm.pngwtran: LibPng:h.pngconf
|
||||
mm.pngwtran: MemCheck:ANSI.h.stdio
|
||||
mm.pngwutil: LibPng:c.pngwutil
|
||||
mm.pngwutil: LibPng:h.png
|
||||
mm.pngwutil: Zlib:h.zlib
|
||||
mm.pngwutil: Zlib:h.zconf
|
||||
mm.pngwutil: LibPng:h.pngconf
|
||||
mm.pngwutil: MemCheck:ANSI.h.stdio
|
||||
o.png: c.png
|
||||
o.png: h.png
|
||||
o.png: Zlib:h.zlib
|
||||
o.png: Zlib:h.zconf
|
||||
o.png: h.pngconf
|
||||
o.pngerror: c.pngerror
|
||||
o.pngerror: h.png
|
||||
o.pngerror: Zlib:h.zlib
|
||||
o.pngerror: Zlib:h.zconf
|
||||
o.pngerror: h.pngconf
|
||||
o.pngrio: c.pngrio
|
||||
o.pngrio: h.png
|
||||
o.pngrio: Zlib:h.zlib
|
||||
o.pngrio: Zlib:h.zconf
|
||||
o.pngrio: h.pngconf
|
||||
o.pngwio: c.pngwio
|
||||
o.pngwio: h.png
|
||||
o.pngwio: Zlib:h.zlib
|
||||
o.pngwio: Zlib:h.zconf
|
||||
o.pngwio: h.pngconf
|
||||
o.pngmem: c.pngmem
|
||||
o.pngmem: h.png
|
||||
o.pngmem: Zlib:h.zlib
|
||||
o.pngmem: Zlib:h.zconf
|
||||
o.pngmem: h.pngconf
|
||||
o.pngpread: c.pngpread
|
||||
o.pngpread: h.png
|
||||
o.pngpread: Zlib:h.zlib
|
||||
o.pngpread: Zlib:h.zconf
|
||||
o.pngpread: h.pngconf
|
||||
o.pngset: c.pngset
|
||||
o.pngset: h.png
|
||||
o.pngset: Zlib:h.zlib
|
||||
o.pngset: Zlib:h.zconf
|
||||
o.pngset: h.pngconf
|
||||
o.pngget: c.pngget
|
||||
o.pngget: h.png
|
||||
o.pngget: Zlib:h.zlib
|
||||
o.pngget: Zlib:h.zconf
|
||||
o.pngget: h.pngconf
|
||||
o.pngread: c.pngread
|
||||
o.pngread: h.png
|
||||
o.pngread: Zlib:h.zlib
|
||||
o.pngread: Zlib:h.zconf
|
||||
o.pngread: h.pngconf
|
||||
o.pngrtran: c.pngrtran
|
||||
o.pngrtran: h.png
|
||||
o.pngrtran: Zlib:h.zlib
|
||||
o.pngrtran: Zlib:h.zconf
|
||||
o.pngrtran: h.pngconf
|
||||
o.pngrutil: c.pngrutil
|
||||
o.pngrutil: h.png
|
||||
o.pngrutil: Zlib:h.zlib
|
||||
o.pngrutil: Zlib:h.zconf
|
||||
o.pngrutil: h.pngconf
|
||||
o.pngtrans: c.pngtrans
|
||||
o.pngtrans: h.png
|
||||
o.pngtrans: Zlib:h.zlib
|
||||
o.pngtrans: Zlib:h.zconf
|
||||
o.pngtrans: h.pngconf
|
||||
o.pngwrite: c.pngwrite
|
||||
o.pngwrite: h.png
|
||||
o.pngwrite: Zlib:h.zlib
|
||||
o.pngwrite: Zlib:h.zconf
|
||||
o.pngwrite: h.pngconf
|
||||
o.pngwtran: c.pngwtran
|
||||
o.pngwtran: h.png
|
||||
o.pngwtran: Zlib:h.zlib
|
||||
o.pngwtran: Zlib:h.zconf
|
||||
o.pngwtran: h.pngconf
|
||||
o.pngwutil: c.pngwutil
|
||||
o.pngwutil: h.png
|
||||
o.pngwutil: Zlib:h.zlib
|
||||
o.pngwutil: Zlib:h.zconf
|
||||
o.pngwutil: h.pngconf
|
||||
51
scripts/makefile.acorn
Normal file
@@ -0,0 +1,51 @@
|
||||
# Project: libpng
|
||||
|
||||
|
||||
# Toolflags:
|
||||
CCflags = -c -depend !Depend -IC:,Zlib: -g -throwback -DRISCOS -fnah
|
||||
C++flags = -c -depend !Depend -IC: -throwback
|
||||
Linkflags = -aif -c++ -o $@
|
||||
ObjAsmflags = -throwback -NoCache -depend !Depend
|
||||
CMHGflags =
|
||||
LibFileflags = -c -l -o $@
|
||||
Squeezeflags = -o $@
|
||||
|
||||
|
||||
# Final targets:
|
||||
@.libpng-lib: @.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \
|
||||
@.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngrtran \
|
||||
@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
|
||||
LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngrtran \
|
||||
@.o.pngmem @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngwio \
|
||||
@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
|
||||
@.mm-libpng-lib: @.mm.png @.mm.pngerror @.mm.pngrio @.mm.pngwio @.mm.pngmem \
|
||||
@.mm.pngpread @.mm.pngset @.mm.pngget @.mm.pngread @.mm.pngrtran \
|
||||
@.mm.pngrutil @.mm.pngtrans @.mm.pngwrite @.mm.pngwtran @.mm.pngwutil
|
||||
LibFile $(LibFileflags) @.mm.png @.mm.pngerror @.mm.pngrio \
|
||||
@.mm.pngwio @.mm.pngmem @.mm.pngpread @.mm.pngset @.mm.pngget \
|
||||
@.mm.pngread @.mm.pngrtran @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite \
|
||||
@.mm.pngwtran @.mm.pngwutil
|
||||
|
||||
|
||||
# User-editable dependencies:
|
||||
# (C) Copyright 1997 Tom Tanner
|
||||
Test: @.pngtest
|
||||
<Prefix$Dir>.pngtest
|
||||
@remove <Prefix$Dir>.pngtest
|
||||
|
||||
#It would be nice if you could stop "make" listing from here on!
|
||||
@.pngtest: @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
|
||||
Link $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
|
||||
|
||||
.SUFFIXES: .o .mm .c
|
||||
|
||||
.c.mm:
|
||||
MemCheck.CC cc $(ccflags) -o $@ LibPng:$<
|
||||
.c.o:
|
||||
cc $(ccflags) -o $@ $<
|
||||
|
||||
|
||||
# Static dependencies:
|
||||
|
||||
|
||||
# Dynamic dependencies:
|
||||
@@ -8,7 +8,7 @@ CC=sc
|
||||
# WARNING: a bug in V6.51 causes bad code with OPTGO
|
||||
# So use V6.55 or set NOOPTGO!!!!!!!!!
|
||||
CFLAGS= NOSTKCHK PARMS=REG OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL\
|
||||
OPTLOOP OPTRDEP=4 OPTDEP=4 OPTCOMP=4 DEFINE=PNG_INTERNAL
|
||||
OPTLOOP OPTRDEP=4 OPTDEP=4 OPTCOMP=4 DEFINE=PNG_INTERNAL
|
||||
#linker flags
|
||||
LDFLAGS= SD ND BATCH
|
||||
#link libs
|
||||
@@ -9,6 +9,7 @@ LBR = png.lib
|
||||
LDFLAGS=-lpng -lz -lm
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = $(LBR)(png.o) $(LBR)(pngset.o) $(LBR)(pngget.o) $(LBR)(pngrutil.o)\
|
||||
$(LBR)(pngtrans.o) $(LBR)(pngwutil.o)\
|
||||
@@ -28,4 +29,5 @@ install: libpng.a
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
cp pngconf.h $(prefix)/include
|
||||
chmod 644 $(prefix)/include/p
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
104
scripts/makefile.beos
Normal file
@@ -0,0 +1,104 @@
|
||||
# makefile for libpng on BeOS x86 ELF with gcc
|
||||
# modified from makefile.linux by Sander Stoks
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
# Copyright (C) 1999 Greg Roelofs
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
ZLIBLIB=/usr/local/lib
|
||||
ZLIBINC=/usr/local/include
|
||||
|
||||
ALIGN=
|
||||
# For i386:
|
||||
# ALIGN=-malign-loops=2 -malign-functions=2
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
|
||||
# On BeOS, -O1 is actually better than -O3. This is a known bug but it's
|
||||
# still here in R4.5
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O1 -funroll-loops \
|
||||
$(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
|
||||
# LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
|
||||
LDFLAGS=-L. -Wl,-soname=libpng.so.$(PNGMAJ) -L$(ZLIBLIB) -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.5d
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
INCPATH=$(prefix)/include
|
||||
LIBPATH=$(prefix)/lib
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
OBJSDLL = $(OBJS)
|
||||
|
||||
.SUFFIXES: .c .o
|
||||
|
||||
all: libpng.a libpng.so pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.so: libpng.so.$(PNGMAJ)
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so
|
||||
cp libpng.so* /boot/home/config/lib
|
||||
|
||||
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
|
||||
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
|
||||
libpng.so.$(PNGVER): $(OBJSDLL)
|
||||
$(CC) -L$(ZLIBLIB) -lz -nostart -Wl,-soname,libpng.so.$(PNGMAJ) -o
|
||||
libpng.so.$(PNGVER) \
|
||||
$(OBJSDLL)
|
||||
|
||||
pngtest: pngtest.o libpng.so
|
||||
$(CC) -L$(ZLIBLIB) -lz -lpng -o pngtest pngtest.o
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.a libpng.so.$(PNGVER)
|
||||
-@mkdir $(INCPATH) $(LIBPATH)
|
||||
cp png.h pngconf.h $(INCPATH)
|
||||
chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
|
||||
cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
|
||||
chmod 755 $(LIBPATH)/libpng.so.$(PNGVER)
|
||||
-@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
(cd $(LIBPATH); ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so)
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o png.pic.o: png.h pngconf.h
|
||||
pngerror.o pngerror.pic.o: png.h pngconf.h
|
||||
pngrio.o pngrio.pic.o: png.h pngconf.h
|
||||
pngwio.o pngwio.pic.o: png.h pngconf.h
|
||||
pngmem.o pngmem.pic.o: png.h pngconf.h
|
||||
pngset.o pngset.pic.o: png.h pngconf.h
|
||||
pngget.o pngget.pic.o: png.h pngconf.h
|
||||
pngread.o pngread.pic.o: png.h pngconf.h
|
||||
pngrtran.o pngrtran.pic.o: png.h pngconf.h
|
||||
pngrutil.o pngrutil.pic.o: png.h pngconf.h
|
||||
pngtrans.o pngtrans.pic.o: png.h pngconf.h
|
||||
pngwrite.o pngwrite.pic.o: png.h pngconf.h
|
||||
pngwtran.o pngwtran.pic.o: png.h pngconf.h
|
||||
pngwutil.o pngwutil.pic.o: png.h pngconf.h
|
||||
pngpread.o pngpread.pic.o: png.h pngconf.h
|
||||
pngtest.o: png.h pngconf.h
|
||||
@@ -2,8 +2,8 @@
|
||||
# Borland C++ 4.5 (Note: All modules are compiled in C mode)
|
||||
# Will work with C++ 4.02 also
|
||||
# To build the library, do:
|
||||
# "make -fmakefile.bor -DMODEL=m"
|
||||
# or: "make -fmakefile.bor -DMODEL=l"
|
||||
# "make -fmakefile.borland -DMODEL=m"
|
||||
# or: "make -fmakefile.borland -DMODEL=l"
|
||||
#
|
||||
# ------------- Borland C++ 4.5 -------------
|
||||
|
||||
@@ -70,38 +70,38 @@ O=obj
|
||||
|
||||
## variables
|
||||
OBJS = \
|
||||
png.$(O) \
|
||||
pngerror.$(O) \
|
||||
pngmem.$(O) \
|
||||
pngpread.$(O) \
|
||||
pngset.$(O) \
|
||||
pngget.$(O) \
|
||||
pngread.$(O) \
|
||||
pngrio.$(O) \
|
||||
pngrtran.$(O) \
|
||||
pngrutil.$(O) \
|
||||
pngtrans.$(O) \
|
||||
pngwrite.$(O) \
|
||||
pngwtran.$(O) \
|
||||
pngwio.$(O) \
|
||||
pngwutil.$(O)
|
||||
png.$(O) \
|
||||
pngerror.$(O) \
|
||||
pngmem.$(O) \
|
||||
pngpread.$(O) \
|
||||
pngset.$(O) \
|
||||
pngget.$(O) \
|
||||
pngread.$(O) \
|
||||
pngrio.$(O) \
|
||||
pngrtran.$(O) \
|
||||
pngrutil.$(O) \
|
||||
pngtrans.$(O) \
|
||||
pngwrite.$(O) \
|
||||
pngwtran.$(O) \
|
||||
pngwio.$(O) \
|
||||
pngwutil.$(O)
|
||||
|
||||
LIBOBJS = \
|
||||
+png.$(O) \
|
||||
+pngerror.$(O) \
|
||||
+pngmem.$(O) \
|
||||
+pngpread.$(O) \
|
||||
+pngread.$(O) \
|
||||
+pngset.$(O) \
|
||||
+pngget.$(O) \
|
||||
+pngrio.$(O) \
|
||||
+pngrtran.$(O) \
|
||||
+pngrutil.$(O) \
|
||||
+pngtrans.$(O) \
|
||||
+pngwrite.$(O) \
|
||||
+pngwtran.$(O) \
|
||||
+pngwio.$(O)
|
||||
+pngwutil.$(O)
|
||||
+png.$(O) \
|
||||
+pngerror.$(O) \
|
||||
+pngmem.$(O) \
|
||||
+pngpread.$(O) \
|
||||
+pngread.$(O) \
|
||||
+pngset.$(O) \
|
||||
+pngget.$(O) \
|
||||
+pngrio.$(O) \
|
||||
+pngrtran.$(O) \
|
||||
+pngrutil.$(O) \
|
||||
+pngtrans.$(O) \
|
||||
+pngwrite.$(O) \
|
||||
+pngwtran.$(O) \
|
||||
+pngwio.$(O) \
|
||||
+pngwutil.$(O)
|
||||
|
||||
LIBNAME=libpng$(MODEL).lib
|
||||
|
||||
@@ -121,7 +121,7 @@ libpng: $(LIBNAME)
|
||||
|
||||
pngtest: pngtest$(MODEL).exe
|
||||
|
||||
test:
|
||||
test: pngtest$(MODEL).exe
|
||||
pngtest$(MODEL)
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ pngwutil.obj: pngwutil.c
|
||||
|
||||
$(LIBNAME): $(OBJS)
|
||||
-del $(LIBNAME)
|
||||
$(LIB) $(LIBNAME) @&&|
|
||||
$(LIB) $(LIBNAME) @&&|
|
||||
$(LIBOBJS), libpng$(MODEL)
|
||||
|
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.5d
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-std -w1 -I$(ZLIBINC) -O # -g -DPNG_DEBUG=1
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
@@ -15,26 +24,33 @@ LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
#RANLIB=echo
|
||||
RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
all: libpng.a pngtest
|
||||
all: libpng.so libpng.a pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.so: libpng.so.$(PNGMAJ)
|
||||
ln -f -s libpng.so.$(PNGMAJ) libpng.so
|
||||
|
||||
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
|
||||
ln -f -s libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
|
||||
libpng.so.$(PNGVER): $(OBJS)
|
||||
$(CC) -shared -o $@ $(OBJS) -L$(ZLIBLIB) -lz -lm
|
||||
|
||||
pngtest: pngtest.o libpng.a
|
||||
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.a
|
||||
install: libpng.a libpng.so.$(PNGVER)
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
@@ -42,10 +58,15 @@ install: libpng.a
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
cp libpng.a $(prefix)/lib
|
||||
cp libpng.so.$(PNGVER) $(prefix)/lib
|
||||
chmod 644 $(prefix)/lib/libpng.a
|
||||
chmod 644 $(prefix)/lib/libpng.so.$(PNGVER)
|
||||
-@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
(cd $(LIBPATH); ln -f -s libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -f -s libpng.so.$(PNGMAJ) libpng.so)
|
||||
|
||||
clean:
|
||||
rm -f *.o libpng.a pngtest pngout.png
|
||||
rm -f *.o libpng.a pngtest pngout.png libpng.so*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
#prefix=/usr/local
|
||||
prefix=.
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-I../zlib -O
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
#prefix=/usr/local
|
||||
prefix=.
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o pngwtran.o \
|
||||
pngmem.o pngerror.o pngpread.o
|
||||
|
||||
67
scripts/makefile.hpux
Normal file
@@ -0,0 +1,67 @@
|
||||
# makefile for libpng, HPUX (10.20 and 11.00)
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42
|
||||
# Copyright (C) 1999 Glenn Randers-Pehrson
|
||||
# contributed by Jim Rice, Hewlett Packard
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
ZLIBLIB=/opt/zlib/lib
|
||||
ZLIBINC=/opt/zlib/include
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-I$(ZLIBINC) -O -Ae +DA1.1 +DS2.0
|
||||
CCFLAGS=-I$(ZLIBINC) -O -Ae +DA1.1 +DS2.0
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/opt/libpng
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
all: libpng.a pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
pngtest: pngtest.o libpng.a
|
||||
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.a
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
cp pngconf.h $(prefix)/include
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
cp libpng.a $(prefix)/lib
|
||||
chmod 644 $(prefix)/lib/libpng.a
|
||||
|
||||
clean:
|
||||
rm -f *.o libpng.a pngtest pngout.png
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o: png.h pngconf.h
|
||||
pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
pngrutil.o: png.h pngconf.h
|
||||
pngtest.o: png.h pngconf.h
|
||||
pngtrans.o: png.h pngconf.h
|
||||
pngwrite.o: png.h pngconf.h
|
||||
pngwtran.o: png.h pngconf.h
|
||||
pngwutil.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
||||
@@ -2,6 +2,14 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# This makefile requires the file ansi2knr.c, which you can get
|
||||
# from the Ghostscript ftp site at ftp://ftp.cs.wisc.edu/ghost/
|
||||
# If you have libjpeg, you probably already have ansi2knr.c in the jpeg
|
||||
# source distribution.
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-I../zlib -O
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
@@ -11,9 +19,6 @@ ANSI2KNRFLAGS=
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
# makefile for libpng on Linux ELF with gcc
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
# Copyright (C) 1998 Greg Roelofs
|
||||
# Copyright (C) 1998, 1999 Greg Roelofs
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
|
||||
# where "make install" puts libpng.a, libpng.so*, png.h and pngconf.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
@@ -12,15 +15,17 @@ ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
ALIGN=
|
||||
# For I-386:
|
||||
# for i386:
|
||||
#ALIGN=-malign-loops=2 -malign-functions=2
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
|
||||
# for pgcc version 2.95.1, -O3 is buggy; don't use it.
|
||||
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops \
|
||||
$(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
|
||||
$(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
@@ -29,17 +34,15 @@ RANLIB=ranlib
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.2
|
||||
PNGMIN = 1.0.5d
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
INCPATH=$(prefix)/include
|
||||
LIBPATH=$(prefix)/lib
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
|
||||
@@ -62,7 +65,7 @@ libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
|
||||
|
||||
libpng.so.$(PNGVER): $(OBJSDLL)
|
||||
$(CC) -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
|
||||
$(OBJSDLL)
|
||||
$(OBJSDLL) -L$(ZLIBLIB) -lz -lm -lc
|
||||
|
||||
pngtest: pngtest.o libpng.so
|
||||
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
|
||||
@@ -2,6 +2,9 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-I../zlib -O -systype sysv -DSYSV -w -Dmips
|
||||
#CFLAGS=-O
|
||||
@@ -10,9 +13,6 @@ LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
#RANLIB=ranlib
|
||||
RANLIB=echo
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
@@ -3,7 +3,7 @@
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\zlib
|
||||
|
||||
# ------------- Microsoft C 5.1 and later -------------
|
||||
# -------- Microsoft C 5.1 and later, does not use assembler code -----
|
||||
MODEL=-AL
|
||||
CFLAGS=-Oait -Gs -nologo -W3 $(MODEL) -I..\zlib
|
||||
#-Ox generates bad code with MSC 5.1
|
||||
@@ -26,52 +26,52 @@ png$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngset$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngget$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngread$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngpread$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngrtran$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngrutil$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngerror$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngmem$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngrio$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngwio$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngtest$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngtrans$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngwrite$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngwtran$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngwutil$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
|
||||
del libpng.lib
|
||||
del libpng.lib
|
||||
lib libpng $(OBJS1);
|
||||
lib libpng $(OBJS2);
|
||||
lib libpng $(OBJS3);
|
||||
|
||||
@@ -10,10 +10,10 @@ ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O6 -funroll-loops -malign-loops=2 \
|
||||
-malign-functions=2 #$(WARNMORE) -g -DPNG_DEBUG=5
|
||||
-malign-functions=2 #$(WARNMORE) -g -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lzdll -Zcrtdll
|
||||
AR=emxomfar
|
||||
|
||||
@@ -23,8 +23,8 @@ SHAREDLIB=png.dll
|
||||
SHAREDLIBIMP=pngdll.lib
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
.SUFFIXES: .c .o
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
CC=cc
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
@@ -22,17 +25,15 @@ RANLIB=echo
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.2
|
||||
PNGMIN = 1.0.5d
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
INCPATH=$(prefix)/include
|
||||
LIBPATH=$(prefix)/lib
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
|
||||
@@ -48,10 +49,10 @@ libpng.a: $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.so: libpng.so.$(PNGMAJ)
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so
|
||||
ln -f -s libpng.so.$(PNGMAJ) libpng.so
|
||||
|
||||
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
|
||||
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
ln -f -s libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
|
||||
libpng.so.$(PNGVER): $(OBJSDLL)
|
||||
$(CC) -G -Wl,-h,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
|
||||
@@ -70,8 +71,8 @@ install: libpng.a libpng.so.$(PNGVER)
|
||||
cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
|
||||
chmod 755 $(LIBPATH)/libpng.so.$(PNGVER)
|
||||
-@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
(cd $(LIBPATH); ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so)
|
||||
(cd $(LIBPATH); ln -f -s libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -f -s libpng.so.$(PNGMAJ) libpng.so)
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
@@ -11,15 +14,13 @@ ZLIBINC=../zlib
|
||||
CC=cc
|
||||
|
||||
WARNMORE=-fullwarn
|
||||
# You can add the -n32 option; then zlib must also be compiled with -n32
|
||||
CFLAGS=-I$(ZLIBINC) -O $(WARNMORE) # -g -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
RANLIB=echo
|
||||
#RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
# makefile for libpng on Solaris 2.x with gcc
|
||||
# Contributed by William L. Sebok, based on makefile.lnx
|
||||
# Contributed by William L. Sebok, based on makefile.linux
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
# Copyright (C) 1998 Greg Roelofs
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
|
||||
# The commands "CC" and "LD" must NOT refer to /usr/ucb/cc and /usr/ucb/ld.
|
||||
# If they do, you need to adjust your PATH environment variable to put
|
||||
# /usr/ccs/bin ahead of /usr/ucb. The environment variable LD_LIBRARY_PATH
|
||||
# should not be set at all. If it is, things are likely to break because
|
||||
# of the libucb dependency that is created.
|
||||
|
||||
# Where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
# Changing these to ../zlib poses a security risk. If you want
|
||||
# to have zlib in an adjacent directory, specify the full path instead of "..".
|
||||
@@ -15,12 +24,11 @@ CC=gcc
|
||||
ZLIBLIB=/usr/local/lib
|
||||
ZLIBINC=/usr/local/include
|
||||
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O3 \
|
||||
# $(WARNMORE) -g -DPNG_DEBUG=5
|
||||
# $(WARNMORE) -g -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
#RANLIB=ranlib
|
||||
@@ -29,17 +37,15 @@ RANLIB=echo
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.2
|
||||
PNGMIN = 1.0.5d
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
INCPATH=$(prefix)/include
|
||||
LIBPATH=$(prefix)/lib
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
|
||||
@@ -55,10 +61,10 @@ libpng.a: $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.so: libpng.so.$(PNGMAJ)
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so
|
||||
ln -f -s libpng.so.$(PNGMAJ) libpng.so
|
||||
|
||||
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
|
||||
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
ln -f -s libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
|
||||
libpng.so.$(PNGVER): $(OBJSDLL)
|
||||
$(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h libpng.so.$(PNGMAJ) \
|
||||
@@ -77,8 +83,8 @@ install: libpng.a libpng.so.$(PNGVER)
|
||||
cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
|
||||
chmod 755 $(LIBPATH)/libpng.so.$(PNGVER)
|
||||
-@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
(cd $(LIBPATH); ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so)
|
||||
(cd $(LIBPATH); ln -f -s libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -f -s libpng.so.$(PNGMAJ) libpng.so)
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png
|
||||
@@ -2,6 +2,9 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
@@ -15,9 +18,6 @@ LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
#RANLIB=echo
|
||||
RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
@@ -10,8 +13,8 @@ ZLIBINC=../zlib
|
||||
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow -Wconversion \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes
|
||||
CC=gcc
|
||||
CFLAGS=-I$(ZLIBINC) -O # $(WARNMORE) -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
@@ -19,9 +22,6 @@ LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
@@ -1,7 +1,7 @@
|
||||
# Makefile for libpng
|
||||
# TurboC++ 3.0 (Note: All modules are compiled in C mode)
|
||||
|
||||
# To use, do "make -fmakefile.tc3"
|
||||
# To use, do "make -fmakefile.turboc3"
|
||||
|
||||
# ------------- Turbo C++ 3.0 -------------
|
||||
MODEL=-ml
|
||||
@@ -45,38 +45,38 @@ pngrutil$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngerror$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngmem$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngrio$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngwio$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngtest$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngtrans$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngwrite$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngwtran$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngwutil$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
|
||||
$(LIB) libpng +$(OBJSL1)
|
||||
$(LIB) libpng +$(OBJSL2)
|
||||
$(LIB) libpng +$(OBJSL3)
|
||||
$(LIB) libpng +$(OBJSL1)
|
||||
$(LIB) libpng +$(OBJSL2)
|
||||
$(LIB) libpng +$(OBJSL3)
|
||||
|
||||
pngtest$(E): pngtest$(O) libpng.lib
|
||||
$(CC) $(LDFLAGS) pngtest.obj libpng.lib zlib.lib
|
||||
$(CC) $(LDFLAGS) pngtest.obj libpng.lib zlib.lib
|
||||
|
||||
# End of makefile for libpng
|
||||