Compare commits

...

10 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
7cd899c707 Imported from libpng-0.99m.tar 2009-04-06 16:04:17 -05:00
Glenn Randers-Pehrson
ea3bcd7087 Imported from libpng-0.99k.tar 2009-04-06 16:04:17 -05:00
Glenn Randers-Pehrson
983ec160b4 Imported from libpng-0.99j.tar 2009-04-06 16:04:16 -05:00
Glenn Randers-Pehrson
08a3343e05 Imported from libpng-0.99i.tar 2009-04-06 16:04:16 -05:00
Glenn Randers-Pehrson
cbe52d8720 Imported from libpng-0.99e.tar 2009-04-06 16:04:15 -05:00
Glenn Randers-Pehrson
a357b99113 Imported from libpng-0.99d.tar 2009-04-06 16:04:14 -05:00
Glenn Randers-Pehrson
0f881d62b3 Imported from libpng-0.99c.tar 2009-04-06 16:04:13 -05:00
Glenn Randers-Pehrson
b212002101 Imported from libpng-0.99a.tar 2009-04-06 16:04:12 -05:00
Glenn Randers-Pehrson
46f61e2398 Imported from libpng-0.99.tar 2009-04-06 16:04:12 -05:00
Glenn Randers-Pehrson
c4a2ae6cac Imported from libpng-0.98.tar 2009-04-06 16:04:11 -05:00
51 changed files with 6738 additions and 1179 deletions

103
CHANGES
View File

@@ -1,4 +1,4 @@
pngchange.txt - changes for libpng
CHANGES - changes for libpng
version 0.2
added reader into png.h
@@ -170,20 +170,101 @@ version 0.96 [May, 1997]
version 0.97 [January, 1998]
removed PNG_USE_OWN_CRC capability
relocated png_set_crc_action from pngrutil.c to pngrtran.c
fixed typecasts of "new_key", etc.
added RFC 1152 date support
fixed typecasts of "new_key", etc. (Andreas Dilger)
added RFC 1152 [sic] date support
fixed bug in gamma handling of 4-bit grayscale
added more typecasts. 65536L becomes (png_uint_32)65536L, etc.
added 2-bit grayscale gamma handling (Glenn R-P)
added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
minor corrections in libpng.txt
added simple sRGB support
make it simpler to do conditional compiling: PNG_READ_NOT_FULLY_SUPPORTED
fixed memory leak in pngwrite.c (free info_ptr->text)
added simple sRGB support (Glenn R-P)
easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
all configurable options can be selected from command-line instead
of having to edit pngconf.h (Glenn R-P)
fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
added more conditions for png_do_background, to avoid changing
black pixels to background when a background is supplied and
no pixels are transparent
repaired PNG_NO_STDIO behaviour
tested NODIV support and made it default behaviour
added "-m" option to pngtest
[anything else? 2-bit grayscale gamma bug?]
tested NODIV support and made it default behaviour (Greg Roelofs)
added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
regularized version numbering scheme and bumped shared-library major
version number to 2 to avoid potential problems with libpng 0.89 apps
version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs)
version 0.98 [January, 1998]
cleaned up some typos in libpng.txt and in code documentation
fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
changed recommendation about file_gamma for PC images to .51 from .45,
in example.c and libpng.txt, added comments to distinguish between
screen_gamma, viewing_gamma, and display_gamma.
changed all references to RFC1152 to read RFC1123 and changed the
PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
changed srgb_intent from png_byte to int to avoid compiler bugs
version 0.99 [January 30, 1998]
free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
fixed a longstanding "packswap" bug in pngtrans.c
fixed some inconsistencies in pngconf.h that prevented compiling with
PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
changed recommendation about file_gamma for PC images to .50 from .51 in
example.c and libpng.txt, and changed file_gamma for sRGB images to .45
added a number of functions to access information from the png structure
png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
added TARGET_MACOS similar to zlib-1.0.8
define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
added type casting to all png_malloc() function calls
version 0.99a [January 31, 1998]
Added type casts and parentheses to all returns that return a value.(Tim W.)
version 0.99b [February 4, 1998]
Added type cast png_uint_32 on malloc function calls where needed.
Changed type of num_hist from png_uint_32 to int (same as num_palette).
Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
Renamed makefile.elf to makefile.lnx.
version 0.99c [February 7, 1998]
More type casting. Removed erroneous overflow test in pngmem.c.
Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.
Added UNIX manual pages libpng.3 (incorporating libpng.txt) and png.5.
version 0.99d [February 11, 1998]
Renamed "far_to_near()" "png_far_to_near()"
Revised libpng.3
Version 99c "buffered" operations didn't work as intended. Replaced them
with png_memcpy_check() and png_memset_check().
Added many "if (png_ptr == NULL) return" to quell compiler warnings about
unused png_ptr, mostly in pngget.c and pngset.c.
Check for overlength tRNS chunk present when indexed-color PLTE is read.
Cleaned up spelling errors in libpng.3/libpng.txt
Corrected a problem with png_get_tRNS() which returned undefined trans array
version 0.99e [February 28, 1998]
Corrected png_get_tRNS() again.
Add parentheses for easier reading of pngget.c, fixed "||" should be "&&".
Touched up example.c to make more of it compileable, although the entire
file still can't be compiled (Willem van Schaik)
Fixed a bug in png_do_shift() (Bryan Tsai)
Added a space in png.h prototype for png_write_chunk_start()
Replaced pngtest.png with one created with zlib 1.1.1
Changed pngtest to report PASS even when file size is different (Jean-loup G.)
Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)
version 0.99f [March 5, 1998]
Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)
Moved makefiles into a "scripts" directory, and added INSTALL instruction file
Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok)
Added pointers to "note on libpng versions" in makefile.lnx and README
Added row callback feature when reading and writing nonprogressive rows
and added a test of this feature in pngtest.c
Added user transform callbacks, with test of the feature in pngtest.c
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
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]
Changed several typedefs in pngrutil.c
Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)
replaced "while(1)" with "for(;;)"
added PNGARG() to prototypes in pngtest.c and removed some prototypes
updated some of the makefiles (Tom Lane)
changed some typedefs (s_start, etc.) in pngrutil.c
fixed dimensions of "short_months" array in pngwrite.c
Replaced ansi2knr.c with the one from jpeg-v6

85
INSTALL Normal file
View File

@@ -0,0 +1,85 @@
Installing libpng version 1.00 March 7, 1998
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.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.00 or "lpng100" and "zlib-1.1.1"
or "zlib111") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this:
.. (the parent directory)
libpng (this directory)
INSTALL (this file)
README
*.h
*.c
scripts
makefile.*
pngtest.png
etc.
zlib
README
*.h
*.c
contrib
etc.
First enter the zlib directory and follow the instructions
in zlib/README. Then come back here and choose the
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.00)
makefile.lnx => Linux/ELF makefile (gcc, creates libpng.so.2.1.00)
makefile.mip => MIPS makefile
makefile.aco => Acorn makefile
makefile.ama => Amiga makefile
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.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
Copy the file (or files) that you need from the
scripts directory into this directory, for example
MSDOS example: copy scripts\makefile.msd makefile
UNIX example: cp scripts/makefile.std makefile
Read the makefile to see if you need to change any source or
target directories to match your preferences.
Then read pngconf.h to see if you want to make any configuration
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.
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.

80
README
View File

@@ -1,12 +1,11 @@
[NOTE: this is still beta version 0.97c; the text below has already
been updated in anticipation of the imminent 1.0 release.]
README for libpng 1.00 (shared library 2.1)
See the note about version numbers near the top of png.h
README for libpng 1.0
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 years. However, it's
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
changes to the API in some time, and people have a bad feeling about
libraries with versions < 1.0.
@@ -77,7 +76,7 @@ If not, it should be at ftp.uu.net in /graphics/png
Eventually, it will be at ftp.uu.net in /pub/archiving/zip/zlib
You may also want a copy of the PNG specification. It is available
as an Internet Draft, and RFC, and a W3C Recommendation. Failing
as an RFC and a W3C Recommendation. Failing
these resources you can try ftp.uu.net in the /graphics/png directory.
This code is currently being archived at ftp.uu.net in the
@@ -97,19 +96,19 @@ Finally, if you get any warning messages when compiling libpng
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 earlier work), and the PNG group.
based in a large way on Guy's and Andreas' earlier work), and the PNG group.
adilger@enel.ucalgary.ca
randeg@alumni.rpi.edu
png-implement@dworkin.wustl.edu
You can reach Guy, the original libpng author, at (internet preferred):
internet: schalnat@group42.com
CompuServe: 75501,1625
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
addressed to the png-implement list, however.
Please do not send general questions about PNG. Send them to
the address in the specification. At the same time, please do
not send libpng questions to that address, send them to me. I'll
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
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,
@@ -117,7 +116,7 @@ and ...". If in doubt, send questions to me. I'll bounce them
to others, if necessary.
Please do not send suggestions on how to change PNG. We have
been discussing PNG for a couple years now, and it is official and
been discussing PNG for three years now, and it is official and
finished. If you have suggestions for libpng, however, I'll
gladly listen. Even if your suggestion is not used for version
1.0, it may be used later.
@@ -127,28 +126,20 @@ 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
libpng.3 => manual page for libpng
libpng.txt => Description of libpng and its functions
makefile => Default Unixish makefile
makefile.aco => ACORN makefile
makefile.ama => Amiga makefile
makefile.atr => Atari makefile
makefile.bor => Borland makefile
makefile.dj2 => DJGPP 2 makefile
makefile.elf => Unix ELF makefile
makefile.knr => Makefile which calls ansi2knr to convert files
makefile.mip => MIPS makefile
makefile.msc => Microsoft C makefile
makefile.std => Standard Unix makefile
makefile.tc => Turbo C makefile
makevms.com => VMS make program
libpngpf.3 => manual page for libpng's private functions
png.5 => manual page for the PNG format
png.c => Basic interface functions common to library
png.h => Library function and interface declarations
pngconf.h => System specific library configuration
pngerror.c => Error/warning message I/O functions
pngget.c => Functions for retrieving info from struct
pngmem.c => Memory handling functions
pngpread.c => Progressive reading functions
pngread.c => Read data/helper high-level functions
@@ -163,16 +154,39 @@ Files in this distribution:
pngwrite.c => High-level write functions
pngwtran.c => Write data transformations
pngwutil.c => Write utility functions
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.00)
makefile.lnx => Linux/ELF makefile (gcc, creates libpng.so.2.1.00)
makefile.mip => MIPS makefile
makefile.aco => Acorn makefile
makefile.ama => Amiga makefile
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.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
Good luck, and happy coding.
-Glenn Randers-Pehrson
Internet: randeg@alumni.rpi.edu
Web: http://www.rpi.edu/~randeg/index.html
-Andreas Eric Dilger
Internet: adilger@enel.ucalgary.ca
Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
-Guy Eric Schalnat
Group 42, Inc.
Internet: schalnat@group42.com
CompuServe: 75501,1625
Web: http://www.group42.com/
(formerly of Group 42, Inc)
Internet: gschal@infinet.com

5
TODO
View File

@@ -1,11 +1,12 @@
pngtodo.txt - 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
improved dithering
multi-lingual error and warning message support
sPLT chunk handling
cHRM transformation
complete sRGB transformation (presently it simply uses gamma=0.5)
complete sRGB transformation (presently it simply uses gamma=0.45)
man pages for function calls
high-level API for reading images
final bug fixes

36
ansi2knr.1 Normal file
View File

@@ -0,0 +1,36 @@
.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>.

View File

@@ -1,26 +1,32 @@
/* Copyright (C) 1989, 1991, 1993 Aladdin Enterprises. All rights reserved. */
/* ansi2knr.c */
/* Convert ANSI function declarations to K&R syntax */
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
/*
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 for full details.
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 GNU
General Public License. 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 COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies.
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 IJG 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 set of sources 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 COPYING, referred to above ----------
---------- Here is the GNU GPL file COPYLEFT, referred to above ----------
----- These terms do NOT apply to the JPEG software itself; see README ------
GHOSTSCRIPT GENERAL PUBLIC LICENSE
@@ -166,59 +172,142 @@ 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 COPYING ------------------------------
-------------------- End of file COPYLEFT ------------------------------
*/
#include <stdio.h>
#include <ctype.h>
#ifdef BSD
#include <strings.h>
#else
#ifdef VMS
extern int strlen(), strncmp();
#else
#include <string.h>
#endif
#endif
/* 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
/* Usage:
/*
* Usage:
ansi2knr input_file [output_file]
* If no output_file is supplied, output goes to stdout.
* There are no error messages.
*
* ansi2knr recognizes functions 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.
* It will recognize a multi-line header provided that the last character
* of the last line of the header is a right parenthesis,
* and no intervening line ends with a left brace or a semicolon.
* 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).
* - Macros that tinker with the syntax of the function header.
* - 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) (isalnum(ch) || (ch) == '_')
#define isidfirstchar(ch) (isalpha(ch) || (ch) == '_')
#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
/* Forward references */
char *skipspace();
@@ -227,6 +316,7 @@ int test1();
int convert1();
/* The main program */
int
main(argc, argv)
int argc;
char *argv[];
@@ -234,46 +324,99 @@ main(argc, argv)
#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;
out = stdout;
break;
case 3:
out = fopen(argv[2], "w");
if ( out == NULL )
{ fprintf(stderr, "Cannot open %s\n", argv[2]);
{ fprintf(stderr, "Cannot open output file %s\n", argv[2]);
exit(1);
}
}
in = fopen(argv[1], "r");
if ( in == NULL )
{ fprintf(stderr, "Cannot open %s\n", argv[1]);
{ 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 )
{ switch ( test1(buf) )
{
test: line += strlen(line);
switch ( test1(buf) )
{
case 2: /* a function header */
convert1(buf, out, 1, convert_varargs);
break;
case 1: /* a function */
convert1(buf, out);
/* 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 */
line = buf + strlen(buf);
if ( line != buf + (bufsize - 1) ) /* overflow check */
continue;
continue;
/* falls through */
default: /* not a function */
fputs(buf, out);
wl: fputs(buf, out);
break;
}
line = buf;
}
if ( line != buf ) fputs(buf, out);
if ( line != buf )
fputs(buf, out);
free(buf);
fclose(out);
fclose(in);
@@ -286,11 +429,14 @@ skipspace(p, dir)
register char *p;
register int dir; /* 1 for forward, -1 for backward */
{ for ( ; ; )
{ while ( isspace(*p) ) p += dir;
if ( !(*p == '/' && p[dir] == '*') ) break;
{ 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?? */
{ if ( *p == 0 )
return p; /* multi-line comment?? */
p += dir;
}
p += dir; p += dir;
@@ -300,13 +446,16 @@ skipspace(p, dir)
/*
* 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++ ) *p = ' ';
for ( p = start; p < end; p++ )
if ( *p != '\r' && *p != '\n' )
*p = ' ';
return 0;
}
@@ -316,8 +465,12 @@ writeblanks(start, end)
* 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)
@@ -326,24 +479,27 @@ test1(buf)
char *bend;
char *endfn;
int contin;
if ( !isidfirstchar(*p) )
return 0; /* no name at left margin */
return 0; /* no name at left margin */
bend = skipspace(buf + strlen(buf) - 1, -1);
switch ( *bend )
{
case ')': contin = 1; break;
case '{':
case ';': return 0; /* not a function */
default: contin = -1;
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++;
while ( isidchar(*p) )
p++;
endfn = p;
p = skipspace(p, 1);
if ( *p++ != '(' )
return 0; /* not a function */
return 0; /* not a function */
p = skipspace(p, 1);
if ( *p == ')' )
return 0; /* no parameters */
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). */
@@ -357,19 +513,23 @@ test1(buf)
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 */
return 0; /* name is a keyword */
key++;
}
}
return contin;
}
/* Convert a recognized function definition or header to K&R syntax. */
int
convert1(buf, out)
convert1(buf, out, header, convert_varargs)
char *buf;
FILE *out;
int header; /* Boolean */
int convert_varargs; /* Boolean */
{ char *endfn;
register char *p;
char **breaks;
@@ -377,9 +537,12 @@ convert1(buf, out)
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++) != '('; ) ;
for ( endfn = buf; *(endfn++) != '('; )
;
top: p = endfn;
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
if ( breaks == 0 )
@@ -393,7 +556,10 @@ top: p = endfn;
/* 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. */
@@ -406,13 +572,27 @@ top: p = endfn;
for ( ; end == NULL; p++ )
{ switch(*p)
{
case ',': if ( !level ) end = p; break;
case '(': level++; break;
case ')': if ( --level < 0 ) end = p; break;
case '/': p = skipspace(p, 1) - 1; break;
default: ;
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 */
@@ -421,35 +601,42 @@ top: p = endfn;
{ p = skipspace(p - 1, -1);
switch ( *p )
{
case ']': /* skip array dimension(s) */
case ')': /* skip procedure args OR name */
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: ;
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;
p = skipspace(p, 1) + 1;
goto found;
}
break;
default: goto found;
default:
goto found;
}
}
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
{ p++;
if ( bp == breaks + 1 ) /* sole argument */
writeblanks(breaks[0], p);
{ if ( convert_varargs )
{ *bp++ = "va_alist";
vararg = p-2;
}
else
writeblanks(bp[-1] - 1, p);
bp--;
{ p++;
if ( bp == breaks + 1 ) /* sole argument */
writeblanks(breaks[0], p);
else
writeblanks(bp[-1] - 1, p);
bp--;
}
}
else
{ while ( isidchar(*p) ) p--;
@@ -470,19 +657,37 @@ found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
}
}
}
/* Put out the function name */
/* Put out the function name and left parenthesis. */
p = buf;
while ( p != endfn ) putc(*p, out), p++;
/* Put out the declaration */
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] = ';';
fputs(breaks[0], out);
/* 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;
}

View File

@@ -1,3 +1,4 @@
/* example.c - an example of using libpng */
/* This is an example of how to use libpng to read and write PNG files.
@@ -12,7 +13,7 @@
* working PNG reader/writer, see pngtest.c, included in this distribution.
*/
#include <png.h>
#include "png.h"
/* Check to see if a file is a PNG file using png_check_sig(). Returns
* non-zero if the image is a PNG, and 0 if it isn't a PNG.
@@ -54,7 +55,7 @@ int check_if_png(char *file_name, FILE **fp)
* file, and the other where we are given an open file (possibly with
* some or all of the magic bytes read - see comments above).
*/
**** prototype 1 ****
#ifdef open_file /* prototype 1 */
void read_png(char *file_name) /* We need to open the file */
{
png_structp png_ptr;
@@ -66,14 +67,14 @@ void read_png(char *file_name) /* We need to open the file */
if ((fp = fopen(file_name, "rb")) == NULL)
return;
**** prototype 2 ****
#else no_open_file /* prototype 2 */
void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
{
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
**** only use one prototype! ****
#endif no_open_file /* only use one prototype! */
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
@@ -113,17 +114,17 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
}
/* One of the following I/O initialization methods is REQUIRED */
**** PNG file I/O method 1 ****
#ifdef streams /* PNG file I/O method 1 */
/* Set up the input control if you are using standard C streams */
png_init_io(png_ptr, fp);
**** PNG file I/O method 2 ****
#else no_streams /* PNG file I/O method 2 */
/* If you are using replacement read functions, instead of calling
* png_init_io() here you would call:
*/
png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
/* where user_io_ptr is a structure you want available to the callbacks */
**** Use only one I/O method! ****
#endif no_streams /* Use only one I/O method! */
/* If we have already read some of the signature */
png_set_sig_bytes_read(png_ptr, sig_read);
@@ -180,29 +181,32 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
* use it - you should use the (solid) application background if it has one.
*/
png_color_16 my_background, *image_background);
png_color_16 my_background, *image_background;
if (png_get_bKGD(png_ptr, info_ptr, &image_background);
png_set_background(png_ptr, image_background),
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
png_set_background(png_ptr, image_background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
/* Some suggestions as to how to get a screen gamma value */
/* Note that screen gamma is (display_gamma/viewing_gamma) */
if (/* We have a user-defined screen gamma value */)
{
screen_gamma = user-defined screen_gamma;
}
/* This is one way that applications share the same screen gamma value */
else if ((gamma_str = getenv("DISPLAY_GAMMA")) != NULL)
else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
{
screen_gamma = atof(gamma_str);
}
/* If we don't have another value */
else
{
screen_gamma = 2.2; /* A good guess for PC monitors */
screen_gamma = 2.2; /* A good guess for a PC monitors in a dimly
lit room */
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
}
@@ -211,13 +215,16 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
* by the user at run time by the user. It is strongly suggested that
* your application support gamma correction.
*/
if (png_get_sRGB(png_ptr, info_ptr, &srgb_intent)
png_set_sRGB(png_ptr, srgb_intent, 0);
int intent;
if (png_get_sRGB(png_ptr, info_ptr, &intent))
png_set_sRGB(png_ptr, intent, 0);
else
if (png_get_gAMA(png_ptr, info_ptr, &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.45);
png_set_gamma(png_ptr, screen_gamma, 0.50);
/* Dither RGB files down to 8 bit palette or reduce palettes
* to the number of colors available on your screen.
@@ -228,7 +235,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
png_colorp palette;
/* This reduces the image to the application supplied palette */
if (we have our own palette)
if (/* we have our own palette */)
{
/* An array of colors to which the image should be dithered */
png_color std_color_cube[MAX_SCREEN_COLORS];
@@ -237,7 +244,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
MAX_SCREEN_COLORS, NULL, 0);
}
/* This reduces the image to the palette supplied in the file */
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)))
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
{
png_color16p histogram;
@@ -249,7 +256,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
}
/* invert monocrome files to have 0 as white and 1 as black */
png_set_invert(png_ptr);
png_set_invert_mono(png_ptr);
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
@@ -298,37 +305,37 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
}
/* Now it's time to read the image. One of these methods is REQUIRED */
**** Read the entire image in one go ****
#ifdef entire /* Read the entire image in one go */
png_read_image(png_ptr, row_pointers);
**** Read the image one or more scanlines at a time ****
#else no_entire /* Read the image one or more scanlines at a time */
/* The other way to read images - deal with interlacing: */
for (pass = 0; pass < number_passes; pass++)
{
[[[[[[[ Read the image a single row at a time ]]]]]]]
#ifdef single /* Read the image a single row at a time */
for (y = 0; y < height; y++)
{
png_bytep row_pointers = row[y];
png_read_rows(png_ptr, &row_pointers, NULL, 1);
}
[[[[[[[ Read the image several rows at a time ]]]]]]]
#else no_single /* Read the image several rows at a time */
for (y = 0; y < height; y += number_of_rows)
{
<<<<<<<<<< Read the image using the "sparkle" effect. >>>>>>>>>>
#ifdef sparkle /* Read the image using the "sparkle" effect. */
png_read_rows(png_ptr, row_pointers, NULL, number_of_rows);
<<<<<<<<<< Read the image using the "rectangle" effect >>>>>>>>>>
#else no_sparkle /* Read the image using the "rectangle" effect */
png_read_rows(png_ptr, NULL, row_pointers, number_of_rows);
<<<<<<<<<< use only one of these two methods >>>>>>>>>>
#endif no_sparkle /* use only one of these two methods */
}
/* if you want to display the image after every pass, do
so here */
[[[[[[[ use only one of these two methods ]]]]]]]
#endif no_single /* use only one of these two methods */
}
**** use only one of these two methods ****
#endif no_entire /* use only one of these two methods */
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
@@ -473,7 +480,7 @@ end_callback(png_structp png_ptr, png_infop info)
}
/* write a png file */
void write_png(char *file_name, ... other image information ...)
void write_png(char *file_name /* , ... other image information ... */)
{
FILE *fp;
png_structp png_ptr;
@@ -520,16 +527,16 @@ void write_png(char *file_name, ... other image information ...)
}
/* One of the following I/O initialization functions is REQUIRED */
**** I/O initialization method 1 ****
#ifdef streams /* I/O initialization method 1 */
/* set up the output control if you are using standard C streams */
png_init_io(png_ptr, fp);
**** I/O initialization method 2 ****
#else no_streams /* I/O initialization method 2 */
/* If you are using replacement read functions, instead of calling
* png_init_io() here you would call */
png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
user_IO_flush_function);
/* where user_io_ptr is a structure you want available to the callbacks */
**** only use 1 initialization method ****
#endif no_streams /* only use one initialization method */
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
@@ -543,8 +550,8 @@ void write_png(char *file_name, ... other image information ...)
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* set the palette if there is one. REQUIRED for indexed-color images */
palette = png_malloc(png_ptr, 256 * sizeof (png_color));
... set palette colors ...
palette = (png_colorp)png_malloc(png_ptr, 256 * sizeof (png_color));
/* ... set palette colors ... */
png_set_PLTE(png_ptr, info_ptr, palette, 256);
/* optional significant bit chunk */
@@ -594,7 +601,7 @@ void write_png(char *file_name, ... other image information ...)
*/
/* invert monocrome pixels */
png_set_invert(png_ptr);
png_set_invert_mono(png_ptr);
/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.
@@ -634,12 +641,12 @@ void write_png(char *file_name, ... other image information ...)
png_byte row_pointers[height][width];
/* One of the following output methods is REQUIRED */
**** write out the entire image data in one call ***
#ifdef entire /* write out the entire image data in one call */
png_write_image(png_ptr, row_pointers);
/* the other way to write the image - deal with interlacing */
**** write out the image data by one or more scanlines ****
#else no_entire /* write out the image data by one or more scanlines */
/* The number of passes is either 1 for non-interlaced images,
* or 7 for interlaced images.
*/
@@ -655,7 +662,7 @@ void write_png(char *file_name, ... other image information ...)
png_write_rows(png_ptr, &row_pointers, 1);
}
}
**** use only one output method ****
#endif no_entire /* use only one output method */
/* You can write optional chunks like tEXt, zTXt, and tIME at the end
* as well.

2408
libpng.3 Normal file

File diff suppressed because it is too large Load Diff

1067
libpng.txt

File diff suppressed because it is too large Load Diff

342
libpngpf.3 Normal file
View File

@@ -0,0 +1,342 @@
.TH LIBPNGPF 3 "March 7, 1998"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library
(private functions)
.SH SYNOPSIS
#include <png.h>
void png_build_gamma_table (png_structp png_ptr);
void png_build_grayscale_palette (int bit_depth, png_colorp
palette);
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);
png_size_t png_check_keyword (png_structp png_ptr, png_charp
key, png_charpp new_key);
void png_combine_row (png_structp png_ptr, png_bytep row, int
mask);
void png_correct_palette (png_structp png_ptr, png_colorp
palette, int num_palette);
int png_crc_error (png_structp png_ptr);
int png_crc_finish (png_structp png_ptr, png_uint_32 skip);
void png_crc_read (png_structp png_ptr, png_bytep buf,
png_size_t length);
png_voidp png_create_struct (int type);
void png_destroy_struct (png_voidp struct_ptr);
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);
void png_do_bgr (png_row_infop row_info, png_bytep row);
void png_do_chop (png_row_infop row_info, png_bytep row);
void png_do_dither (png_row_infop row_info, png_bytep row,
png_bytep palette_lookup, png_bytep dither_lookup);
void png_do_expand (png_row_infop row_info, png_bytep row,
png_color_16p trans_value);
void png_do_expand_palette (png_row_infop row_info, png_bytep
row, png_colorp palette, png_bytep trans, int num_trans);
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);
void png_do_gray_to_rgb (png_row_infop row_info, png_bytep
row);
void png_do_invert (png_row_infop row_info, png_bytep row);
void png_do_pack (png_row_infop row_info, png_bytep row,
png_uint_32 bit_depth);
void png_do_packswap (png_row_infop row_info, png_bytep row);
void png_do_read_filler (png_row_infop row_info, png_bytep row,
png_uint_32 filler, png_uint_32 flags);
void png_do_read_interlace (png_row_infop row_info, png_bytep
row, int pass, png_uint_32 transformations);
void png_do_read_invert_alpha (png_row_infop row_info,
png_bytep row);
void png_do_read_swap_alpha (png_row_infop row_info, png_bytep
row);
void png_do_read_transformations (png_structp png_ptr);
void png_do_rgb_to_gray (png_row_infop row_info, png_bytep
row);
void png_do_shift (png_row_infop row_info, png_bytep row,
png_color_8p bit_depth);
void png_do_strip_filler (png_row_infop row_info, png_bytep
row, png_uint_32 flags);
void png_do_swap (png_row_infop row_info, png_bytep row);
void png_do_unpack (png_row_infop row_info, png_bytep row);
void png_do_unshift (png_row_infop row_info, png_bytep row,
png_color_8p sig_bits);
void png_do_write_interlace (png_row_infop row_info, png_bytep
row, int pass);
void png_do_write_invert_alpha (png_row_infop row_info,
png_bytep row);
void png_do_write_swap_alpha (png_row_infop row_info, png_bytep
row);
void png_do_write_transformations (png_structp png_ptr);
void *png_far_to_near (png_structp png_ptr,png_voidp ptr,
int check);
void png_flush (png_structp png_ptr);
png_int_32 png_get_int_32 (png_bytep buf);
png_uint_16 png_get_uint_16 (png_bytep buf);
png_uint_32 png_get_uint_32 (png_bytep buf);
void png_handle_bKGD (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_cHRM (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_gAMA (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_hIST (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_IEND (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_IHDR (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_oFFs (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_pCAL (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_pHYs (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_PLTE (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_sBIT (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_sRGB (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_tEXt (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_tIME (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_tRNS (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_unknown (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_handle_zTXt (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_info_destroy (png_structp png_ptr, png_infop
info_ptr);
void png_init_read_transformations (png_structp png_ptr);
void png_process_IDAT_data (png_structp png_ptr, png_bytep
buffer, png_size_t buffer_length);
void png_process_some_data (png_structp png_ptr, png_infop
info_ptr);
void png_push_check_crc (png_structp png_ptr);
void png_push_crc_finish (png_structp png_ptr);
void png_push_crc_skip (png_structp png_ptr, png_uint_32
length);
void png_push_fill_buffer (png_structp png_ptr, png_bytep
buffer, png_size_t length);
void png_push_handle_tEXt (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_push_handle_unknown (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_push_handle_zTXt (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_push_have_end (png_structp png_ptr, png_infop
info_ptr);
void png_push_have_info (png_structp png_ptr, png_infop
info_ptr);
void png_push_have_row (png_structp png_ptr, png_bytep row);
void png_push_process_row (png_structp png_ptr);
void png_push_read_chunk (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_end (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_IDAT (png_structp png_ptr);
void png_push_read_sig (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_tEXt (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_zTXt (png_structp png_ptr, png_infop
info_ptr);
void png_push_restore_buffer (png_structp png_ptr, png_bytep
buffer, png_size_t buffer_length);
void png_push_save_buffer (png_structp png_ptr);
void png_read_data (png_structp png_ptr, png_bytep data,
png_size_t length);
void png_read_filter_row (png_structp png_ptr, png_row_infop
row_info, png_bytep row, png_bytep prev_row, int filter);
void png_read_finish_row (png_structp png_ptr);
void png_read_init (png_structp png_ptr);
void png_read_push_finish_row (png_structp png_ptr);
void png_read_start_row (png_structp png_ptr);
void png_read_transform_info (png_structp png_ptr, png_infop
info_ptr);
void png_reset_crc (png_structp png_ptr);
void png_save_int_32 (png_bytep buf, png_int_32 i);
void png_save_uint_16 (png_bytep buf, unsigned int i);
void png_save_uint_32 (png_bytep buf, png_uint_32 i);
void png_write_bKGD (png_structp png_ptr, png_color_16p values,
int color_type);
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);
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);
void png_write_find_filter (png_structp png_ptr, png_row_infop
row_info);
void png_write_finish_row (png_structp png_ptr);
void png_write_gAMA (png_structp png_ptr, double file_gamma);
void png_write_hIST (png_structp png_ptr, png_uint_16p hist,
int num_hist);
void png_write_init (png_structp png_ptr);
void png_write_IDAT (png_structp png_ptr, png_bytep data,
png_size_t length);
void png_write_IEND (png_structp png_ptr);
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);
void png_write_oFFs (png_structp png_ptr, png_uint_32 x_offset,
png_uint_32 y_offset, int unit_type);
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);
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);
void png_write_PLTE (png_structp png_ptr, png_colorp palette,
png_uint_32 num_pal);
void png_write_sBIT (png_structp png_ptr, png_color_8p sbit,
int color_type);
void png_write_sig (png_structp png_ptr);
void png_write_sRGB (png_structp png_ptr, int intent);
void png_write_start_row (png_structp png_ptr);
void png_write_tEXt (png_structp png_ptr, png_charp key,
png_charp text, png_size_t text_len);
void png_write_tIME (png_structp png_ptr, png_timep mod_time);
void png_write_tRNS (png_structp png_ptr, png_bytep trans,
png_color_16p values, int number, int color_type);
void png_write_zTXt (png_structp png_ptr, png_charp key,
png_charp text, png_size_t text_len, int compression);
voidpf png_zalloc (voidpf png_ptr, uInt items, uInt size);
void png_zfree (voidpf png_ptr, voidpf ptr);
.SH DESCRIPTION
The functions listed above are used privately by libpng
and are not recommended for use by applications. They
are listed alphabetically here as an aid to libpng maintainers.
See png.h for more information on these functions.
.SH SEE ALSO
libpng(3), png(5)
.SH AUTHOR
Glenn Randers-Pehrson

44
png.5 Normal file
View File

@@ -0,0 +1,44 @@
.TH PNG 5 "March 7, 1998"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION
PNG (Portable Network Graphics) is an extensible file format for the
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.
.br
PNG is designed to work well in online viewing applications, such as the
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.
.SH "SEE ALSO"
.IR libpng(3), zlib(3), deflate(5), and zlib(5)
.LP
PNG specification:
RFC 2083
.IP
.br
ftp://ds.internic.net/rfc/rfc2083.txt
.br
or (as a W3C Recommendation) at
.br
http://www.w3.org/TR/REC-png.html
.SH AUTHORS
This man page: Glenn Randers-Pehrson
.LP
Portable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):
Thomas Boutell and others (png-list@dworkin.wustl.edu).
.LP
.SH COPYRIGHT NOTICE
The PNG specification is copyright (c) 1996 Massachussets Institute of
Technology. See the specification for conditions of use and distribution.
.LP
.\" end of man page

29
png.c
View File

@@ -1,12 +1,12 @@
/* png.c - location for general purpose libpng functions
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
#define PNG_INTERNAL
@@ -16,9 +16,9 @@
/* Version information for C files. This had better match the version
* string defined in png.h.
*/
char png_libpng_ver[] = "0.97";
char png_libpng_ver[5] = "1.00";
/* Place to hold the signiture string for a PNG file. */
/* 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,
@@ -103,15 +103,15 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
if (num_to_check > 8)
num_to_check = 8;
else if (num_to_check < 1)
return 0;
return (0);
if (start > 7)
return 0;
return (0);
if (start + num_to_check > 8)
num_to_check = 8 - start;
return (png_memcmp(&sig[start], &png_sig[start], num_to_check));
return ((int)(png_memcmp(&sig[start], &png_sig[start], num_to_check)));
}
/* (Obsolete) function to check signature bytes. It does not allow one
@@ -121,7 +121,7 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
int
png_check_sig(png_bytep sig, int num)
{
return !png_sig_cmp(sig, (png_size_t)0, (png_size_t)num);
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
}
/* Function to allocate memory for zlib. */
@@ -132,7 +132,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
png_uint_32 num_bytes;
num_bytes = (png_uint_32)items * size;
ptr = png_malloc((png_structp)png_ptr, num_bytes);
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
if (num_bytes > (png_uint_32)0x8000)
{
png_memset(ptr, 0, (png_size_t)0x8000L);
@@ -143,7 +143,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
png_memset(ptr, 0, (png_size_t)num_bytes);
}
return (voidpf)(ptr);
return ((voidpf)ptr);
}
/* function to free memory for zlib */
@@ -185,7 +185,7 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
}
if (need_crc)
png_ptr->crc = crc32(png_ptr->crc, ptr, length);
png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
}
/* Allocate the memory for an info_struct for the application. We don't
@@ -200,12 +200,13 @@ png_create_info_struct(png_structp png_ptr)
png_infop info_ptr;
png_debug(1, "in png_create_info_struct\n");
if(png_ptr == NULL) return (NULL);
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
{
png_info_init(info_ptr);
}
return info_ptr;
return (info_ptr);
}
/* This function frees the memory associated with a single info struct.
@@ -268,7 +269,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_free(png_ptr, info_ptr->pcal_units);
if (info_ptr->pcal_params != NULL)
{
for (i = 0; i < info_ptr->pcal_nparams; i++)
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
}
@@ -286,7 +287,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_voidp
png_get_io_ptr(png_structp png_ptr)
{
return png_ptr->io_ptr;
return (png_ptr->io_ptr);
}
#if !defined(PNG_NO_STDIO)

372
png.h
View File

@@ -1,32 +1,47 @@
/* png.h - header file for PNG reference library
*
* libpng 0.97 beta
* For conditions of distribution and use, see copyright notice in png.h
* libpng 1.00
* For conditions of distribution and use, see the COPYRIGHT NOTICE below.
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998 Glenn Randers-Pehrson
* January 7, 1998
* March 7, 1998
*
* BETA NOTICE:
* This is a beta version. It reads and writes valid files on the
* platforms I have, and has had a wide testing program. You may
* have to modify the includes below to get it to work on your
* system, and you may have to supply the correct compiler flags in
* the makefile if you can't find a makefile suitable for your
* operating system/compiler combination. Read libpng.txt for more
* information, including how to contact the authors if you have any
* problems, or if you want your compiler/platform to be supported in
* the next official libpng release.
* 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 shared-lib
* version string version
* ------- ------ ----------
* 0.89c ("1.0 beta 3") 0.89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 1.0.0 [should have been 2.0.97]
* 0.97c 0.97 2.0.97
* 0.98 0.98 2.0.98
* 0.99 0.99 2.0.99
* 0.99a-i 0.99 2.0.99
* 1.00 1.00 2.1.0
*
* 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.
*
* See libpng.txt 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/pub/WWW/TR/REC.png.html>
* and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
*
* Contributing Authors:
* John Bowler
* Sam Bushell
* Kevin Bracey
* Sam Bushell
* Andreas Dilger
* Magnus Holmgren
* Tom Lane
@@ -36,6 +51,7 @@
* Guy Eric Schalnat
* Paul Schmidt
* Tom Tanner
* Willem van Schaik
* Tim Wegner
*
* The contributing authors would like to thank all those who helped
@@ -44,6 +60,8 @@
*
* 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
@@ -94,57 +112,30 @@ extern "C" {
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "0.97"
#define PNG_LIBPNG_VER_STRING "1.00"
/* careful here. At one time, I wanted to use 082, but that would be octal.
* Version 1.0 will be 100 here, etc.
*/
#define PNG_LIBPNG_VER 97
#define PNG_LIBPNG_VER 100
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
#ifndef 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[];
extern char png_libpng_ver[5];
/*
* 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 shared-lib
* version string version
* ------- ------ ----------
* 0.89c ("1.0 beta 3") 0.89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 1.0.0 [should have been 2.0.97]
* 0.97c 0.97 2.0.97
* 0.98 0.98 2.0.98
* 0.99 0.99 2.0.99
* 1.0 1.00 2.1.0
*
* 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.
*/
/* Structures to facilitate easy interlacing. See png.c for more details */
extern int FARDATA png_pass_start[];
extern int FARDATA png_pass_inc[];
extern int FARDATA png_pass_ystart[];
extern int FARDATA png_pass_yinc[];
extern int FARDATA png_pass_mask[];
extern int FARDATA png_pass_dsp_mask[];
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];
/* These aren't currently used. If you need them, see png.c for more details
extern int FARDATA png_pass_width[];
extern int FARDATA png_pass_height[];
extern int FARDATA png_pass_width[7];
extern int FARDATA png_pass_height[7];
*/
#endif /* PNG_NO_EXTERN */
@@ -248,7 +239,7 @@ typedef struct png_info_struct
png_uint_32 width; /* width of image in pixels (from IHDR) */
png_uint_32 height; /* height of image in pixels (from IHDR) */
png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
png_size_t rowbytes; /* bytes needed to hold an untransformed row */
png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
@@ -270,7 +261,8 @@ typedef struct png_info_struct
* and initialize the appropriate fields below.
*/
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) || \
defined(PNG_READ_GAMMA_SUPPORTED)
/* The gAMA chunk describes the gamma characteristics of the system
* on which the image was created, normally in the range [1.0, 2.5].
* Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
@@ -325,7 +317,8 @@ typedef struct png_info_struct
png_bytep trans; /* transparent values for paletted image */
png_color_16 trans_values; /* transparent color for non-palette image */
#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED) || \
defined(PNG_READ_BACKGROUND_SUPPORTED)
/* The bKGD chunk gives the suggested image background color if the
* display program does not have its own background color and the image
* is needs to composited onto a background before display. The colors
@@ -446,6 +439,15 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_RESOLUTION_METER 1 /* pixels/meter */
#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_LAST 4 /* Not a valid value */
/* These determine if an ancillary chunk's data has been successfully read
* from the PNG header, or if the application has filled in the corresponding
* data in the info_struct to be written into the output file. The values
@@ -471,7 +473,7 @@ typedef png_info FAR * FAR * png_infopp;
typedef struct png_row_info_struct
{
png_uint_32 width; /* width of row */
png_size_t rowbytes; /* number of bytes in row */
png_uint_32 rowbytes; /* number of bytes in row */
png_byte color_type; /* color type of row */
png_byte bit_depth; /* bit depth of row */
png_byte channels; /* number of channels (1, 2, 3, or 4) */
@@ -492,6 +494,8 @@ typedef png_struct FAR * png_structp;
typedef void (*png_error_ptr) PNGARG((png_structp, png_const_charp));
typedef void (*png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
typedef void (*png_flush_ptr) PNGARG((png_structp));
typedef void (*png_read_status_ptr) PNGARG((png_structp, png_uint_32, int));
typedef void (*png_write_status_ptr) PNGARG((png_structp, png_uint_32, int));
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
typedef void (*png_progressive_info_ptr) PNGARG((png_structp, png_infop));
typedef void (*png_progressive_end_ptr) PNGARG((png_structp, png_infop));
@@ -499,6 +503,12 @@ typedef void (*png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
png_uint_32, int));
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
typedef void (*png_user_transform_ptr) PNGARG((png_structp,
png_row_infop, png_bytep));
#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
/* 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
* people who will be modifying the library for their own special needs.
@@ -515,9 +525,14 @@ 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_user_transform_ptr read_user_transform_fn; /* user read transform */
png_user_transform_ptr write_user_transform_fn; /* user write transform */
#endif
png_voidp io_ptr; /* ptr to application struct for I/O functions*/
png_uint_32 mode; /* tells us whre we are in the PNG file */
png_uint_32 mode; /* tells us where we are in the PNG file */
png_uint_32 flags; /* flags indicating various things to libpng */
png_uint_32 transformations; /* which transformations to perform */
@@ -534,8 +549,8 @@ struct png_struct_def
png_uint_32 height; /* height of image in pixels */
png_uint_32 num_rows; /* number of rows in current pass */
png_uint_32 usr_width; /* width of row at start of write */
png_size_t rowbytes; /* size of row in bytes */
png_size_t irowbytes; /* size of current interlaced row in bytes */
png_uint_32 rowbytes; /* size of row in bytes */
png_uint_32 irowbytes; /* size of current interlaced row in bytes */
png_uint_32 iwidth; /* width of current interlaced row in pixels */
png_uint_32 row_number; /* current row in interlace pass */
png_bytep prev_row; /* buffer to save previous (unfiltered) row */
@@ -582,9 +597,9 @@ struct png_struct_def
png_uint_32 flush_rows; /* number of rows written since last flush */
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
#if defined(PNG_READ_GAMMA_SUPPORTED)
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
float gamma; /* file gamma value */
float display_gamma; /* display gamma value */
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 */
#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 */
@@ -604,9 +619,11 @@ struct png_struct_def
png_bytep trans; /* transparency values for paletted files */
png_color_16 trans_values; /* transparency values for non-paletted files */
#endif /* PNG_READ_tRNS_SUPPORTED || PNG_READ_BACKGROUND_SUPPORTED */
png_read_status_ptr read_row_fn; /* called after each row is decoded */
png_write_status_ptr write_row_fn; /* called after each row is encoded */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
png_progressive_info_ptr info_fn; /* called after header data fully read */
png_progressive_row_ptr row_fn; /* called after each row is decoded */
png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
png_progressive_end_ptr end_fn; /* called after image is complete */
png_bytep save_buffer_ptr; /* current location in save_buffer */
png_bytep save_buffer; /* buffer for previously read data */
@@ -626,6 +643,7 @@ struct png_struct_def
png_charp current_text; /* current text chunk buffer */
png_charp current_text_ptr; /* current location in current_text */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_tEXt/zTXt_SUPPORTED */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* for the Borland special 64K segment handler */
png_bytepp offset_table_ptr;
@@ -633,13 +651,14 @@ struct png_struct_def
png_uint_16 offset_table_number;
png_uint_16 offset_table_count;
png_uint_16 offset_table_count_free;
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED&&__TURBOC__&&!_Windows&&!__FLAT__ */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#endif /* __TURBOC__&&!_Windows&&!__FLAT__ */
#if defined(PNG_READ_DITHER_SUPPORTED)
png_bytep palette_lookup; /* lookup table for dithering */
png_bytep dither_index; /* index translation for palette files */
png_uint_16p hist; /* histogram */
#endif /* PNG_READ_DITHER_SUPPORTED */
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED)
png_uint_16p hist; /* histogram */
#endif
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_byte heuristic_method; /* heuristic for row filter selection */
png_byte num_prev_filters; /* number of weights for previous rows */
@@ -649,9 +668,9 @@ struct png_struct_def
png_uint_16p filter_costs; /* relative filter calculation cost */
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
#if defined(PNG_TIME_RFC1152_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1152 time text */
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
};
typedef png_struct FAR * FAR * png_structpp;
@@ -691,6 +710,21 @@ extern PNG_EXPORT(png_structp,png_create_write_struct)
PNGARG((png_const_charp user_png_ver, voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn));
/* Write a PNG chunk - size, type, (optional) data, CRC. */
extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
png_bytep chunk_name, png_bytep data, png_size_t length));
/* Write the start of a PNG chunk - length and chunk name. */
extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
png_bytep chunk_name, png_uint_32 length));
/* Write the data of a PNG chunk started with png_write_chunk_start(). */
extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
png_bytep data, png_size_t length));
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
/* Allocate and initialize the info structure */
extern PNG_EXPORT(png_infop,png_create_info_struct)
PNGARG((png_structp png_ptr));
@@ -706,10 +740,10 @@ extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#if defined(PNG_TIME_RFC1152_SUPPORTED)
extern PNG_EXPORT(png_charp,png_convert_to_rfc1152)
#if defined(PNG_TIME_RFC1123_SUPPORTED)
extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
PNGARG((png_structp png_ptr, png_timep ptime));
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if defined(PNG_WRITE_tIME_SUPPORTED)
/* convert from a struct tm to png_time */
@@ -753,6 +787,11 @@ extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED || PNG_WRITE_SWAP_ALPHA_SUPPORTED */
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED || PNG_WRITE_INVERT_ALPHA_SUPPORTED */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
/* Add a filler byte to 24-bit RGB images. */
extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
@@ -819,7 +858,7 @@ 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. */
/* Handle gamma correction. Screen_gamma=(display_gamma/viewing_gamma) */
extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
double screen_gamma, double default_file_gamma));
#endif /* PNG_READ_GAMMA_SUPPORTED */
@@ -1058,6 +1097,22 @@ extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
/* Return the user pointer associated with the I/O functions */
extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
png_read_status_ptr read_row_fn));
extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
png_write_status_ptr write_row_fn));
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
png_ptr, png_user_transform_ptr read_user_transform_fn));
#endif
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
png_ptr, png_user_transform_ptr write_user_transform_fn));
#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.
@@ -1088,8 +1143,22 @@ extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
/* frees a pointer allocated by png_malloc() */
extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
png_voidp s1, png_voidp s2, png_uint_32 size));
extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
png_voidp s1, int value, png_uint_32 size));
#ifdef PNGTEST_MEMORY_DEBUG
/* debugging versions of png_malloc() and png_free() */
extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
png_uint_32 size));
extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
png_voidp ptr));
#endif
#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
extern void *far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,int check));
extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
int check));
#endif /* USE_FAR_KEYWORD */
/* Fatal error in PNG image of libpng - can't continue */
@@ -1120,18 +1189,71 @@ extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
* to avoid problems with future changes in the size and internal layout of
* png_info_struct.
*/
/* Returns "flag" if chunk data is valid in info_ptr */
/* Returns "flag" if chunk data is valid in info_ptr. */
extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 flag));
/* Returns number of bytes needed to hold a transformed row */
/* Returns number of bytes needed to hold a transformed row. */
extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
png_infop info_ptr));
/* Returns number of color channels in image */
/* Returns number of color channels in image. */
extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* Returns image width in pixels. */
extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image height in pixels. */
extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image bit_depth. */
extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image color_type. */
extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image filter_type. */
extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image interlace_type. */
extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image compression_type. */
extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image resolution in pixels per meter, from pHYs chunk data. */
extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns pixel aspect ratio, computed from pHYs chunk data. */
extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
extern PNG_EXPORT(png_uint_32, png_get_x_offset_pixels) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_y_offset_pixels) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_x_offset_microns) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_y_offset_microns) PNGARG((png_structp
png_ptr, png_infop info_ptr));
#endif /* PNG_EASY_ACCESS_SUPPORTED */
/* Returns pointer to signature string read from PNG header */
extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
png_infop info_ptr));
@@ -1240,14 +1362,14 @@ extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
#if defined(PNG_READ_sRGB_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_bytep srgb_intent));
png_infop info_ptr, int *intent));
#endif /* PNG_READ_sRGB_SUPPORTED */
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_byte srgb_intent));
png_infop info_ptr, int intent));
extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_byte srgb_intent));
png_infop info_ptr, int intent));
#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
@@ -1291,6 +1413,9 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
* libpng yet, but more support will be added as needed.
*/
#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 */
@@ -1358,9 +1483,11 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#define PNG_GAMMA 0x2000
#define PNG_GRAY_TO_RGB 0x4000
#define PNG_FILLER 0x8000
#define PNG_PACKSWAP 0x10000
#define PNG_SWAP_ALPHA 0x20000
#define PNG_STRIP_ALPHA 0x40000
#define PNG_PACKSWAP 0x10000L
#define PNG_SWAP_ALPHA 0x20000L
#define PNG_STRIP_ALPHA 0x40000L
#define PNG_INVERT_ALPHA 0x80000L
#define PNG_USER_TRANSFORM 0x100000L
/* flags for png_create_struct */
#define PNG_STRUCT_PNG 0x0001
@@ -1388,8 +1515,8 @@ 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 0x8000
#define PNG_FLAG_WROTE_tIME 0x10000
#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
#define PNG_FLAG_WROTE_tIME 0x10000L
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)
@@ -1406,32 +1533,32 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
abs((int)((c1).blue) - (int)((c2).blue)))
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
#ifndef PNG_NO_EXTERN
/* place to hold the signiture string for a PNG file. */
extern png_byte FARDATA png_sig[];
#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];
/* 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.
*/
extern png_byte FARDATA png_IHDR[];
extern png_byte FARDATA png_IDAT[];
extern png_byte FARDATA png_IEND[];
extern png_byte FARDATA png_PLTE[];
extern png_byte FARDATA png_bKGD[];
extern png_byte FARDATA png_cHRM[];
extern png_byte FARDATA png_gAMA[];
extern png_byte FARDATA png_hIST[];
extern png_byte FARDATA png_oFFs[];
extern png_byte FARDATA png_pCAL[];
extern png_byte FARDATA png_pHYs[];
extern png_byte FARDATA png_sBIT[];
extern png_byte FARDATA png_sRGB[];
extern png_byte FARDATA png_tEXt[];
extern png_byte FARDATA png_tIME[];
extern png_byte FARDATA png_tRNS[];
extern png_byte FARDATA png_zTXt[];
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];
#endif /* PNG_NO_EXTERN */
@@ -1531,22 +1658,7 @@ PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
*/
PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
/* Write a PNG chunk - size, type, (optional) data, CRC. */
PNG_EXTERN void png_write_chunk PNGARG((png_structp png_ptr,
png_bytep chunk_name, png_bytep data, png_size_t length));
/* Write the start of a PNG chunk - length and chunk name. */
PNG_EXTERN void png_write_chunk_start PNGARG((png_structp png_ptr,
png_bytep chunk_name, png_uint_32 length));
/* Write the data of a PNG chunk started with png_write_chunk_start(). */
PNG_EXTERN void png_write_chunk_data PNGARG((png_structp png_ptr,
png_bytep data, png_size_t length));
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
PNG_EXTERN void png_write_chunk_end PNGARG((png_structp png_ptr));
/* simple function to write the signiture */
/* simple function to write the signature */
PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
/* write various chunks */
@@ -1585,7 +1697,7 @@ PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
#if defined(PNG_WRITE_sRGB_SUPPORTED)
PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
png_byte srgb_intent));
int intent));
#endif
#if defined(PNG_WRITE_tRNS_SUPPORTED)
@@ -1600,7 +1712,7 @@ PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
#if defined(PNG_WRITE_hIST_SUPPORTED)
PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
png_uint_32 num_hist));
int num_hist));
#endif
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
@@ -1702,6 +1814,16 @@ PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
png_bytep row));
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
png_bytep row));
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
png_bytep row));
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,

149
pngconf.h
View File

@@ -1,12 +1,12 @@
/* pngconf.c - machine configurable file for libpng
/* pngconf.h - machine configurable file for libpng
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
/* Any machine specific code is near the front of this file, so if you
@@ -27,7 +27,7 @@
* where it becomes significant, if you are concerned with memory
* usage. Note that zlib allocates at least 32Kb also. For readers,
* this describes the size of the buffer available to read the data in.
* Unless this gets smaller then the size of a row (compressed),
* Unless this gets smaller than the size of a row (compressed),
* it should not make much difference how big this is.
*/
@@ -55,8 +55,6 @@
* #define PNG_NO_STDIO
*/
/* We still need stdio.h for FILE even when PNG_NO_STDIO is defined.
*/
#ifndef PNG_NO_STDIO
#include <stdio.h>
#endif
@@ -88,10 +86,12 @@
* just __MWERKS__ is not good enough, because the Codewarrior is now used
* on non-Mac platforms.
*/
#ifndef MACOS
#if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
defined(THINK_C) || defined(__SC__)
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
#define MACOS
#endif
#endif
/* enough people need this for various reasons to include it here */
#if !defined(MACOS) && !defined(RISCOS)
@@ -157,6 +157,11 @@ __dont__ include it again
#include <math.h>
#endif
/* Codewarrior on NT has linking problems without this. */
#if defined(__MWERKS__) && defined(WIN32)
#define PNG_ALWAYS_EXTERN
#endif
/* For some reason, Borland C++ defines memcmp, etc. in mem.h, not
* stdlib.h like it should (I think). Or perhaps this is a C++
* "feature"?
@@ -191,24 +196,25 @@ __dont__ include it again
* less then 8, and even that may not work (I haven't tested it).
*/
#ifndef PNG_MAX_GAMMA_8
#define PNG_MAX_GAMMA_8 11
#endif
/* This controls how much a difference in gamma we can tolerate before
* we actually start doing gamma conversion.
*/
#ifndef PNG_GAMMA_THRESHOLD
#define PNG_GAMMA_THRESHOLD 0.05
#endif
#endif /* PNG_INTERNAL */
/* The following uses const char * instead of char * for error
* and warning message functions, so some compilers won't complain.
* If you want to use const, define PNG_USE_CONST here. It is not
* normally defined to make configuration easier, as it is not a
* critical part of the code.
* If you do not want to use const, define PNG_NO_CONST here.
*/
#define PNG_USE_CONST
#ifdef PNG_USE_CONST
#ifndef PNG_NO_CONST
# define PNG_CONST const
#else
# define PNG_CONST
@@ -230,21 +236,24 @@ __dont__ include it again
/* Any transformations you will not be using can be undef'ed here */
/* GR-P, 0.96a: Set "*FULLY_SUPPORTED as default but allow user
to turn it off with "*NOT_FULLY_SUPPORTED" on the compile line,
/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user
to turn it off with "*TRANSFORMS_NOT_SUPPORTED" on the compile line,
then pick and choose which ones to define without having to edit
this file */
this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED if you
only want to have a png-compliant reader/writer but don't need
any of the extra transformations. This saves about 80 kbytes in a
typical installation of the library.
*/
#ifndef PNG_READ_NOT_FULLY_SUPPORTED
#define PNG_READ_FULLY_SUPPORTED
#ifndef PNG_READ_TRANSFORMS_NOT_SUPPORTED
#define PNG_READ_TRANSFORMS_SUPPORTED
#endif
#ifndef PNG_WRITE_NOT_FULLY_SUPPORTED
#define PNG_WRITE_FULLY_SUPPORTED
#ifndef PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
#define PNG_WRITE_TRANSFORMS_SUPPORTED
#endif
#ifdef PNG_READ_FULLY_SUPPORTED
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_OPT_PLTE_SUPPORTED
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_SHIFT_SUPPORTED
#define PNG_READ_PACK_SUPPORTED
@@ -259,13 +268,22 @@ __dont__ include it again
#define PNG_READ_GAMMA_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#define PNG_READ_SWAP_ALPHA_SUPPORTED
#define PNG_READ_INVERT_ALPHA_SUPPORTED
#define PNG_READ_STRIP_ALPHA_SUPPORTED
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel */
#endif /* PNG_READ_FULLY_SUPPORTED */
#define PNG_READ_INTERLACING_SUPPORTED
#define PNG_READ_USER_TRANSFORM_SUPPORTED
/* the following aren't implemented yet
#define PNG_READ_RGB_TO_GRAY_SUPPORTED
*/
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
#ifdef PNG_WRITE_FULLY_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#ifndef PNG_PROGRESSIVE_READ_NOT_SUPPORTED /* if you don't do progressive */
#define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
#endif /* about interlacing capability! You'll */
/* still have interlacing unless you change the following line: */
#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel and SGI */
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
#define PNG_WRITE_BGR_SUPPORTED
@@ -275,31 +293,72 @@ __dont__ include it again
#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
#define PNG_WRITE_FLUSH_SUPPORTED
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif /* PNG_WRITE_FULLY_SUPPORTED */
#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
encoders, but can cause trouble
if left undefined */
#if !defined(PNG_NO_STDIO)
#define PNG_TIME_RFC1152_SUPPORTED
#define PNG_TIME_RFC1123_SUPPORTED
#endif
/* These are currently experimental features */
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
/* This adds extra functions in pngget.c for accessing data from the
* info pointer (added in version 0.99)
* png_get_image_width()
* png_get_image_height()
* png_get_bit_depth()
* png_get_color_type()
* png_get_compression_type()
* png_get_filter_type()
* png_get_interlace_type()
* png_get_pixel_aspect_ratio()
* png_get_pixels_per_meter()
* png_get_x_offset_pixels()
* png_get_y_offset_pixels()
* png_get_x_offset_microns()
* png_get_y_offset_microns()
*/
#if !defined(PNG_NO_EASY_ACCESS)
#define PNG_EASY_ACCESS_SUPPORTED
#endif
/* These are currently experimental features, define them if you want */
/* very little testing */
/*
#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
*/
/* This is only for PowerPC big-endian and 680x0 systems */
#undef PNG_READ_BIG_ENDIAN_SUPPORTED /* some testing */
/* some testing */
/*
#define PNG_READ_BIG_ENDIAN_SUPPORTED
*/
/* These functions are turned off by default, as they will be phased out. */
#undef PNG_USELESS_TESTS_SUPPORTED
#undef PNG_CORRECT_PALETTE_SUPPORTED
/*
#define PNG_USELESS_TESTS_SUPPORTED
#define PNG_CORRECT_PALETTE_SUPPORTED
*/
/* Any chunks you are not interested in, you can undef here. The
* ones that allocate memory may be expecially important (hIST,
* tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info
* a bit smaller. OPT_PLTE only disables the optional palette in RGB
* and RGBA images.
* a bit smaller.
*/
#ifdef PNG_READ_FULLY_SUPPORTED
#ifndef PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#endif
#ifndef PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#endif
#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_READ_bKGD_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
@@ -313,9 +372,11 @@ __dont__ include it again
#define PNG_READ_tIME_SUPPORTED
#define PNG_READ_tRNS_SUPPORTED
#define PNG_READ_zTXt_SUPPORTED
#endif /* PNG_READ_FULLY_SUPPORTED */
#define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the optional */
/* PLTE chunk in RGB and RGBA images */
#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
#ifdef PNG_WRITE_FULLY_SUPPORTED
#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED
#define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED
@@ -329,7 +390,7 @@ __dont__ include it again
#define PNG_WRITE_tIME_SUPPORTED
#define PNG_WRITE_tRNS_SUPPORTED
#define PNG_WRITE_zTXt_SUPPORTED
#endif /* PNG_WRITE_FULLY_SUPPORTED */
#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
/* need the time information for reading tIME chunks */
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
@@ -455,7 +516,7 @@ typedef z_stream FAR * png_zstreamp;
/* allow for compilation as dll with BORLAND C++ 5.0 */
#if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
# define PNG_EXPORT(t,s) t _export s
# define PNG_EXPORT(type,symbol) type _export symbol
#endif
/* allow for compilation as shared lib under BeOS */
@@ -464,7 +525,7 @@ typedef z_stream FAR * png_zstreamp;
#endif
#ifndef PNG_EXPORT
#define PNG_EXPORT(t,s) t s
#define PNG_EXPORT(type,symbol) type symbol
#endif
@@ -476,8 +537,8 @@ typedef z_stream FAR * png_zstreamp;
/* use this to make far-to-near assignments */
# define CHECK 1
# define NOCHECK 0
# define CVT_PTR(ptr) (far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (far_to_near(png_ptr,ptr,NOCHECK))
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
# define png_strlen _fstrlen
# define png_memcmp _fmemcmp /* SJT: added */
# define png_memcpy _fmemcpy

View File

@@ -1,12 +1,12 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* This file provides a location for all error handling. Users which
* need special error handling are expected to write replacement functions
@@ -59,7 +59,7 @@ png_warning(png_structp png_ptr, png_const_charp message)
* if the character is invalid.
*/
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
static const char png_digit[16] = {
static PNG_CONST char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
@@ -81,7 +81,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message
}
if (message == NULL)
buffer[iout++] = 0;
buffer[iout] = 0;
else {
buffer[iout++] = ':';
buffer[iout++] = ' ';
@@ -167,7 +167,7 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_voidp
png_get_error_ptr(png_structp png_ptr)
{
return png_ptr->error_ptr;
return ((png_voidp)png_ptr->error_ptr);
}

402
pngget.c
View File

@@ -1,12 +1,12 @@
/* pngget.c - retrieval of values from info struct
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
#define PNG_INTERNAL
@@ -15,7 +15,7 @@
png_uint_32
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
{
if (info_ptr != NULL)
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->valid & flag);
else
return(0);
@@ -24,28 +24,307 @@ png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
png_uint_32
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->rowbytes);
else
return(0);
}
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* easy access to info, added in libpng-0.99 */
png_uint_32
png_get_image_width(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->width;
}
return (0);
}
png_uint_32
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->height;
}
return (0);
}
png_byte
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->bit_depth;
}
return (0);
}
png_byte
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->color_type;
}
return (0);
}
png_byte
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->filter_type;
}
return (0);
}
png_byte
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->interlace_type;
}
return (0);
}
png_byte
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->compression_type;
}
return (0);
}
png_uint_32
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->x_pixels_per_unit);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->y_pixels_per_unit);
}
else
#endif
return (0);
}
png_uint_32
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
return (0);
else return (info_ptr->x_pixels_per_unit);
}
else
#endif
return (0);
}
float
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
if (info_ptr->x_pixels_per_unit == 0)
return ((float)0.0);
else
return ((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit);
}
else
#endif
return ((float)0.0);
}
png_uint_32
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->x_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->y_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->x_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->y_offset);
}
else
#endif
return (0);
}
#ifdef PNG_INCH_CONVERSIONS
png_uint_32
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
}
png_uint_32
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
}
png_uint_32
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
}
float
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5)
}
float
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5)
}
#if defined(PNG_READ_pHYs_SUPPORTED)
png_uint_32
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
if (res_x != NULL)
{
*res_x = info_ptr->x_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (res_y != NULL)
{
*res_y = info_ptr->y_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (unit_type != NULL)
{
*unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs;
if(unit_type == 1)
{
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50);
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50);
}
}
}
return (retval);
}
#endif
#endif /* PNG_INCH_CONVERSIONS */
/* png_get_channels really belongs in here, too, but it's been around longer */
#endif /* PNG_EASY_ACCESS_SUPPORTED */
png_byte
png_get_channels(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->channels);
else
return(0);
return (0);
}
png_bytep
png_get_signature(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->signature);
else
return(NULL);
return (NULL);
}
#if defined(PNG_READ_bKGD_SUPPORTED)
@@ -53,8 +332,8 @@ png_uint_32
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
png_color_16p *background)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_bKGD &&
background != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
&& background != NULL)
{
png_debug1(1, "in %s retrieval function\n", "bKGD");
*background = &(info_ptr->background);
@@ -70,7 +349,7 @@ png_get_cHRM(png_structp png_ptr, png_infop info_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)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
{
png_debug1(1, "in %s retrieval function\n", "cHRM");
if (white_x != NULL)
@@ -99,8 +378,8 @@ png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
png_uint_32
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA &&
file_gamma != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& file_gamma != NULL)
{
png_debug1(1, "in %s retrieval function\n", "gAMA");
*file_gamma = (double)info_ptr->gamma;
@@ -112,14 +391,13 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
#if defined(PNG_READ_sRGB_SUPPORTED)
png_uint_32
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, png_bytep
file_srgb_intent)
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB &&
file_srgb_intent != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
&& file_srgb_intent != NULL)
{
png_debug1(1, "in %s retrieval function\n", "sRGB");
*file_srgb_intent = info_ptr->srgb_intent;
*file_srgb_intent = (int)info_ptr->srgb_intent;
return (PNG_INFO_sRGB);
}
return (0);
@@ -130,7 +408,8 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, png_bytep
png_uint_32
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_hIST && hist != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
&& hist != NULL)
{
png_debug1(1, "in %s retrieval function\n", "hIST");
*hist = info_ptr->hist;
@@ -147,9 +426,12 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
int *filter_type)
{
if (info_ptr != NULL && width != NULL && height != NULL &&
if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
bit_depth != NULL && color_type != NULL)
{
int pixel_depth, channels;
png_uint_32 rowbytes_per_pixel;
png_debug1(1, "in %s retrieval function\n", "IHDR");
*width = info_ptr->width;
*height = info_ptr->height;
@@ -161,6 +443,23 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
*filter_type = info_ptr->filter_type;
if (interlace_type != NULL)
*interlace_type = info_ptr->interlace_type;
/* check for potential overflow of rowbytes */
if (*color_type == PNG_COLOR_TYPE_PALETTE)
channels = 1;
else if (*color_type & PNG_COLOR_MASK_COLOR)
channels = 3;
else
channels = 1;
if (*color_type & PNG_COLOR_MASK_ALPHA)
channels++;
pixel_depth = *bit_depth * channels;
rowbytes_per_pixel = (pixel_depth + 7) >> 3;
if ((*width > (png_uint_32)2147483647L/rowbytes_per_pixel))
{
png_warning(png_ptr,
"Width too large for libpng to process image data.");
}
return (1);
}
return (0);
@@ -171,8 +470,8 @@ png_uint_32
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs &&
offset_x != NULL && offset_y != NULL && unit_type != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
{
png_debug1(1, "in %s retrieval function\n", "oFFs");
*offset_x = info_ptr->x_offset;
@@ -190,7 +489,7 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
png_charp *units, png_charpp *params)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
nparams != NULL && units != NULL && params != NULL)
{
@@ -215,12 +514,16 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
{
png_uint_32 retval = 0;
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
if (res_x != NULL && res_y != NULL)
if (res_x != NULL)
{
*res_x = info_ptr->x_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (res_y != NULL)
{
*res_y = info_ptr->y_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
@@ -229,9 +532,8 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
*unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs;
}
return (retval);
}
return (0);
return (retval);
}
#endif
@@ -239,7 +541,8 @@ png_uint_32
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
int *num_palette)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE && palette != NULL)
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE &&
palette != NULL)
{
png_debug1(1, "in %s retrieval function\n", "PLTE");
*palette = info_ptr->palette;
@@ -254,7 +557,8 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
png_uint_32
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT && sig_bit != NULL)
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT &&
sig_bit != NULL)
{
png_debug1(1, "in %s retrieval function\n", "sBIT");
*sig_bit = &(info_ptr->sig_bit);
@@ -269,10 +573,11 @@ png_uint_32
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
int *num_text)
{
if ((info_ptr != NULL) || (info_ptr->num_text > 0))
if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
{
png_debug1(1, "in %s retrieval function\n",
(png_ptr->chunk_name[0] == '\0' ? "text" : png_ptr->chunk_name));
(png_ptr->chunk_name[0] == '\0' ? "text"
: (png_const_charp)png_ptr->chunk_name));
if (text_ptr != NULL)
*text_ptr = info_ptr->text;
if (num_text != NULL)
@@ -287,7 +592,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
png_uint_32
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME && mod_time != NULL)
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME &&
mod_time != NULL)
{
png_debug1(1, "in %s retrieval function\n", "tIME");
*mod_time = &(info_ptr->mod_time);
@@ -302,25 +608,37 @@ png_uint_32
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep *trans, int *num_trans, png_color_16p *trans_values)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
{
png_debug1(1, "in %s retrieval function\n", "tRNS");
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE && trans != NULL)
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
*trans = info_ptr->trans;
if (trans != NULL)
{
*trans = info_ptr->trans;
retval |= PNG_INFO_tRNS;
}
if (trans_values != NULL)
*trans_values = &(info_ptr->trans_values);
}
else if (trans_values != NULL)
else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
{
*trans_values = &(info_ptr->trans_values);
if (trans_values != NULL)
{
*trans_values = &(info_ptr->trans_values);
retval |= PNG_INFO_tRNS;
}
if(trans != NULL)
*trans = NULL;
}
else
if(num_trans != NULL)
{
return (0);
*num_trans = info_ptr->num_trans;
retval |= PNG_INFO_tRNS;
}
*num_trans = info_ptr->num_trans;
return (PNG_INFO_tRNS);
}
return (0);
return (retval);
}
#endif

View File

@@ -1,12 +1,12 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* This file provides a location for all memory allocation. Users which
* need special memory handling are expected to modify the code in this file
@@ -16,6 +16,16 @@
#define PNG_INTERNAL
#include "png.h"
/* The following "hides" PNG_MALLOC and PNG_FREE thus allowing the pngtest
application to put a wrapper on top of them. */
#ifdef PNGTEST_MEMORY_DEBUG
#define PNG_MALLOC png_debug_malloc
#define PNG_FREE png_debug_free
#else
#define PNG_MALLOC png_malloc
#define PNG_FREE png_free
#endif
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* if you change this, be sure to change the one in png.h also */
@@ -33,7 +43,7 @@ png_create_struct(int type)
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return (png_voidp)NULL;
return ((png_voidp)NULL);
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
{
@@ -49,7 +59,10 @@ void
png_destroy_struct(png_voidp struct_ptr)
{
if (struct_ptr != NULL)
{
farfree (struct_ptr);
struct_ptr = NULL;
}
}
/* Allocate memory. For reasonable files, size should never exceed
@@ -72,11 +85,11 @@ png_destroy_struct(png_voidp struct_ptr)
* (which should cause a fatal error) and introducing major problems.
*/
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size)
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
if (png_ptr == NULL || size == 0)
return ((voidp)NULL);
return ((png_voidp)NULL);
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
@@ -98,8 +111,10 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
png_byte huge * hptr;
if (ret != NULL)
{
farfree(ret);
ret = NULL;
ret = NULL;
}
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
if (num_blocks < 1)
@@ -115,7 +130,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
if (table == NULL)
{
png_error(png_ptr, "Out of Memory");
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
}
if ((png_size_t)table & 0xfff0)
@@ -129,7 +144,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
if (png_ptr->offset_table_ptr == NULL)
{
png_error(png_ptr, "Out of memory");
png_error(png_ptr, "Out Of memory.");
}
hptr = (png_byte huge *)table;
@@ -151,7 +166,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
}
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
png_error(png_ptr, "Out of Memory");
png_error(png_ptr, "Out of Memory.");
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
}
@@ -160,17 +175,17 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
if (ret == NULL)
{
png_error(png_ptr, "Out of Memory");
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
}
return ret;
return (ret);
}
/* free a pointer allocated by png_malloc(). In the default
/* free a pointer allocated by PNG_MALLOC(). In the default
configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */
void
png_free(png_structp png_ptr, png_voidp ptr)
PNG_FREE(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
@@ -198,7 +213,10 @@ png_free(png_structp png_ptr, png_voidp ptr)
}
if (ptr != NULL)
{
farfree(ptr);
ptr = NULL;
}
}
#else /* Not the Borland DOS special memory handler */
@@ -217,7 +235,7 @@ png_create_struct(int type)
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return (png_voidp)NULL;
return ((png_voidp)NULL);
#if defined(__TURBOC__) && !defined(__FLAT__)
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
@@ -241,6 +259,7 @@ void
png_destroy_struct(png_voidp struct_ptr)
{
if (struct_ptr != NULL)
{
#if defined(__TURBOC__) && !defined(__FLAT__)
farfree(struct_ptr);
#else
@@ -250,6 +269,7 @@ png_destroy_struct(png_voidp struct_ptr)
free(struct_ptr);
# endif
#endif
}
}
@@ -260,11 +280,12 @@ png_destroy_struct(png_voidp struct_ptr)
have the ability to do that. */
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size)
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
if (png_ptr == NULL || size == 0)
return (NULL);
return ((png_voidp)NULL);
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
@@ -272,12 +293,12 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
#endif
#if defined(__TURBOC__) && !defined(__FLAT__)
ret = farmalloc((png_size_t)size);
ret = farmalloc(size);
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
ret = halloc(size, 1);
# else
ret = malloc(size);
ret = malloc((size_t)size);
# endif
#endif
@@ -286,14 +307,14 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
png_error(png_ptr, "Out of Memory");
}
return ret;
return (ret);
}
/* Free a pointer allocated by png_malloc(). In the default
/* Free a pointer allocated by PNG_MALLOC(). In the default
configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */
void
png_free(png_structp png_ptr, png_voidp ptr)
PNG_FREE(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
@@ -311,3 +332,29 @@ png_free(png_structp png_ptr, png_voidp ptr)
#endif /* Not Borland DOS special memory handler */
png_voidp
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
png_uint_32 length)
{
png_size_t size;
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));
}
png_voidp
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
png_uint_32 length)
{
png_size_t size;
size = (png_size_t)length;
if ((png_uint_32)size != length)
png_error(png_ptr,"Overflow in png_memset_check.");
return (png_memset (s1, value, size));
}

View File

@@ -1,12 +1,12 @@
/* pngpread.c - read a png file in push mode
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
#define PNG_INTERNAL
@@ -466,7 +466,8 @@ 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, new_max);
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);
png_ptr->save_buffer_max = new_max;
@@ -527,7 +528,12 @@ png_push_read_IDAT(png_structp png_ptr)
png_size_t save_size;
if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
save_size = png_ptr->idat_size;
{
save_size = (png_size_t)png_ptr->idat_size;
/* check for overflow */
if((png_uint_32)save_size != png_ptr->idat_size)
png_error(png_ptr, "save_size overflowed in pngpread");
}
else
save_size = png_ptr->save_buffer_size;
@@ -544,7 +550,12 @@ png_push_read_IDAT(png_structp png_ptr)
png_size_t save_size;
if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
save_size = png_ptr->idat_size;
{
save_size = (png_size_t)png_ptr->idat_size;
/* check for overflow */
if((png_uint_32)save_size != png_ptr->idat_size)
png_error(png_ptr, "save_size overflowed in pngpread");
}
else
save_size = png_ptr->current_buffer_size;
@@ -580,7 +591,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
png_ptr->zstream.next_in = buffer;
png_ptr->zstream.avail_in = (uInt)buffer_length;
while(1)
for(;;)
{
ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
if (ret == Z_STREAM_END)
@@ -619,6 +630,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);
@@ -626,7 +638,8 @@ png_push_process_row(png_structp png_ptr)
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1);
if (png_ptr->transformations)
png_do_read_transformations(png_ptr);
@@ -761,7 +774,8 @@ png_read_push_finish_row(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_memset_check(png_ptr, png_ptr->prev_row, 0,
png_ptr->rowbytes + 1);
do
{
png_ptr->pass++;
@@ -771,8 +785,10 @@ png_read_push_finish_row(png_structp png_ptr)
png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
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 +
@@ -793,7 +809,11 @@ void
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
png_error(png_ptr, "Out of place tEXt");
{
png_error(png_ptr, "Out of place tEXt");
/* to quiet some compiler warnings */
if(info_ptr == NULL) return;
}
#ifdef PNG_MAX_MALLOC_64K
png_ptr->skip_length = 0; /* This may not be necessary */
@@ -806,11 +826,12 @@ 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, length+1);
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;
png_ptr->current_text_size = length;
png_ptr->current_text_left = length;
png_ptr->current_text_size = (png_size_t)length;
png_ptr->current_text_left = (png_size_t)length;
png_ptr->process_mode = PNG_READ_tEXt_MODE;
}
@@ -857,7 +878,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
if (text != key + png_ptr->current_text_size)
text++;
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
text_ptr->text = text;
@@ -874,7 +895,11 @@ void
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
png_error(png_ptr, "Out of place zTXt");
{
png_error(png_ptr, "Out of place zTXt");
/* to quiet some compiler warnings */
if(info_ptr == NULL) return;
}
#ifdef PNG_MAX_MALLOC_64K
/* We can't handle zTXt chunks > 64K, since we don't have enough space
@@ -889,11 +914,12 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
}
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr, length+1);
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;
png_ptr->current_text_size = length;
png_ptr->current_text_left = length;
png_ptr->current_text_size = (png_size_t)length;
png_ptr->current_text_left = (png_size_t)length;
png_ptr->process_mode = PNG_READ_zTXt_MODE;
}
@@ -955,7 +981,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
(text - key));
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = png_ptr->zbuf_size;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
key_size = text - key;
text_size = 0;
@@ -978,8 +1004,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr,
png_ptr->zbuf_size - png_ptr->zstream.avail_out +
key_size + 1);
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out +
key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size);
@@ -992,8 +1018,9 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
png_charp tmp;
tmp = text;
text = png_malloc(png_ptr, text_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
text = (png_charp)png_malloc(png_ptr, text_size +
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
+ 1));
png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf,
@@ -1029,9 +1056,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
png_free(png_ptr, key);
key = text;
text += key_size;
text_size -= key_size;
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
text_ptr->key = key;
text_ptr->text = text;
@@ -1058,6 +1084,8 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
if (!(png_ptr->chunk_name[0] & 0x20))
{
png_chunk_error(png_ptr, "unknown critical chunk");
/* to quiet some compiler warnings */
if(info_ptr == NULL) return;
}
png_push_crc_skip(png_ptr, length);

View File

@@ -1,12 +1,12 @@
/* pngread.c - read a PNG file
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* This file contains routines that an application calls directly to
* read a PNG file or stream.
@@ -17,7 +17,7 @@
/* Create a PNG structure for reading, and allocate any memory needed. */
png_structp
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_create_read_struct(png_const_charp user_png_ver, voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn)
{
png_structp png_ptr;
@@ -58,7 +58,8 @@ png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
@@ -100,7 +101,8 @@ png_read_init(png_structp png_ptr)
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
@@ -152,7 +154,7 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
}
}
while (1)
for(;;)
{
png_byte chunk_length[4];
png_uint_32 length;
@@ -407,14 +409,17 @@ 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,
(int)(png_ptr->row_buf[0]));
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1);
if (png_ptr->transformations)
png_do_read_transformations(png_ptr);
@@ -444,6 +449,9 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_combine_row(png_ptr, dsp_row, 0xff);
}
png_read_finish_row(png_ptr);
if (png_ptr->read_row_fn != NULL)
(*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
}
/* Read one or more rows of image data. If the image is interlaced,
@@ -655,12 +663,18 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (info_ptr != NULL)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, info_ptr->text);
#endif
png_destroy_struct((png_voidp)info_ptr);
*info_ptr_ptr = (png_infop)NULL;
}
if (end_info_ptr != NULL)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, end_info_ptr->text);
#endif
png_destroy_struct((png_voidp)end_info_ptr);
*end_info_ptr_ptr = (png_infop)NULL;
}
@@ -704,7 +718,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_to_1);
#endif
if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
png_free(png_ptr, png_ptr->palette);
png_zfree(png_ptr, png_ptr->palette);
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_bKGD_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
png_free(png_ptr, png_ptr->trans);
@@ -767,3 +781,9 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
}
void
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
{
png_ptr->read_row_fn = read_row_fn;
}

View File

@@ -1,12 +1,12 @@
/* pngrio.c - functions for data input
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* This file provides a location for all input. Users which need
* special handling are expected to write a function which has the same
@@ -99,7 +99,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
while (remaining != 0);
}
if (check != length)
if ((png_uint_32)check != (png_uint_32)length)
{
png_error(png_ptr, "read Error");
}

View File

@@ -1,12 +1,12 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG.
@@ -184,7 +184,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
int i;
png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
(png_uint_32)(num_palette * sizeof (png_byte)));
for (i = 0; i < num_palette; i++)
png_ptr->dither_index[i] = (png_byte)i;
}
@@ -200,7 +200,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
png_bytep sort;
/* initialize an array to sort colors */
sort = (png_bytep)png_malloc(png_ptr, num_palette * sizeof (png_byte));
sort = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_palette
* sizeof (png_byte)));
/* initialize the sort array */
for (i = 0; i < num_palette; i++)
@@ -243,11 +244,11 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
move the others */
for (i = 0, j = num_palette; i < maximum_colors; i++)
{
if (sort[i] >= maximum_colors)
if ((int)sort[i] >= maximum_colors)
{
do
j--;
while (sort[j] >= maximum_colors);
while ((int)sort[j] >= maximum_colors);
palette[i] = palette[j];
}
}
@@ -261,13 +262,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (i = 0, j = num_palette; i < maximum_colors; i++)
{
/* only move the colors we need to */
if (sort[i] >= maximum_colors)
if ((int)sort[i] >= maximum_colors)
{
png_color tmp_color;
do
j--;
while (sort[j] >= maximum_colors);
while ((int)sort[j] >= maximum_colors);
tmp_color = palette[j];
palette[j] = palette[i];
@@ -281,7 +282,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
/* find closest color for those colors we are not using */
for (i = 0; i < num_palette; i++)
{
if (png_ptr->dither_index[i] >= maximum_colors)
if ((int)png_ptr->dither_index[i] >= maximum_colors)
{
int min_d, k, min_k, d_index;
@@ -328,9 +329,9 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
/* initialize palette index arrays */
index_to_palette = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
(png_uint_32)(num_palette * sizeof (png_byte)));
palette_to_index = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
(png_uint_32)(num_palette * sizeof (png_byte)));
/* initialize the sort array */
for (i = 0; i < num_palette; i++)
@@ -339,7 +340,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
palette_to_index[i] = (png_byte)i;
}
hash = (png_dsortpp)png_malloc(png_ptr, 769 * sizeof (png_dsortp));
hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
sizeof (png_dsortp)));
for (i = 0; i < 769; i++)
hash[i] = NULL;
/* png_memset(hash, 0, 769 * sizeof (png_dsortp)); */
@@ -372,7 +374,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
png_dsortp t;
t = png_malloc(png_ptr, sizeof (png_dsort));
t = (png_dsortp)png_malloc(png_ptr, (png_uint_32)(sizeof
(png_dsort)));
t->next = hash[d];
t->left = (png_byte)i;
t->right = (png_byte)j;
@@ -389,8 +392,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (p = hash[i]; p; p = p->next)
{
if (index_to_palette[p->left] < num_new_palette &&
index_to_palette[p->right] < num_new_palette)
if ((int)index_to_palette[p->left] < num_new_palette &&
(int)index_to_palette[p->right] < num_new_palette)
{
int j, next_j;
@@ -417,7 +420,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
index_to_palette[j])
png_ptr->dither_index[k] =
index_to_palette[next_j];
if (png_ptr->dither_index[k] ==
if ((int)png_ptr->dither_index[k] ==
num_new_palette)
png_ptr->dither_index[k] =
index_to_palette[j];
@@ -488,11 +491,12 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
num_entries = ((png_size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
num_entries * sizeof (png_byte));
(png_uint_32)(num_entries * sizeof (png_byte)));
png_memset(png_ptr->palette_lookup, 0, num_entries * sizeof (png_byte));
distance = (png_bytep)png_malloc(png_ptr, num_entries * sizeof(png_byte));
distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
sizeof(png_byte)));
png_memset(distance, 0xff, num_entries * sizeof(png_byte));
@@ -527,7 +531,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
dmax = ((dm > db) ? dm : db);
d = dmax + dt + db;
if (d < distance[d_index])
if (d < (int)distance[d_index])
{
distance[d_index] = (png_byte)d;
png_ptr->palette_lookup[d_index] = (png_byte)i;
@@ -549,13 +553,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
* also needlessly introduces small errors.
*/
void
png_set_gamma(png_structp png_ptr, double screen_gamma, double file_gamma)
png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
{
png_debug(1, "in png_set_gamma\n");
if (fabs(screen_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
if (fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
png_ptr->transformations |= PNG_GAMMA;
png_ptr->gamma = (float)file_gamma;
png_ptr->display_gamma = (float)screen_gamma;
png_ptr->screen_gamma = (float)scrn_gamma;
}
#endif
@@ -592,6 +596,18 @@ png_set_rgb_to_gray(png_structp png_ptr, int gray_bits)
png_debug(1, "in png_set_rgb_to_gray\n");
png_ptr->transformations |= PNG_RGB_TO_GRAY;
/* Need to do something with gray_bits here. */
png_warning(png_ptr, "RGB to GRAY transformation is not yet implemented.");
}
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
void
png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
read_user_transform_fn)
{
png_debug(1, "in png_set_read_user_transform_fn\n");
png_ptr->transformations |= PNG_USER_TRANSFORM;
png_ptr->read_user_transform_fn = read_user_transform_fn;
}
#endif
@@ -644,6 +660,23 @@ png_init_read_transformations(png_structp png_ptr)
png_ptr->palette[png_ptr->background.index].green;
png_ptr->background.blue =
png_ptr->palette[png_ptr->background.index].blue;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
{
#if defined(PNG_READ_EXPAND_SUPPORTED)
if (png_ptr->transformations & !PNG_EXPAND)
#endif
{
/* invert the alpha channel (in tRNS) unless the pixels are
going to be expanded, in which case leave it for later */
int i;
for (i=0; i<(int)png_ptr->num_trans; i++)
png_ptr->trans[i] = 255 - png_ptr->trans[i];
}
}
#endif
}
}
#endif
@@ -681,7 +714,7 @@ png_init_read_transformations(png_structp png_ptr)
{
double g;
g = 1.0 / (png_ptr->background_gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
if (png_ptr->background_gamma_type==PNG_BACKGROUND_GAMMA_SCREEN||
fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
@@ -749,8 +782,9 @@ png_init_read_transformations(png_structp png_ptr)
}
}
}
else
/* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN)*/
else
/* color_type != PNG_COLOR_TYPE_PALETTE */
{
double g, gs, m;
@@ -761,22 +795,23 @@ png_init_read_transformations(png_structp png_ptr)
switch (png_ptr->background_gamma_type)
{
case PNG_BACKGROUND_GAMMA_SCREEN:
g = (png_ptr->display_gamma);
g = (png_ptr->screen_gamma);
gs = 1.0;
break;
case PNG_BACKGROUND_GAMMA_FILE:
g = 1.0 / (png_ptr->gamma);
gs = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
break;
case PNG_BACKGROUND_GAMMA_UNIQUE:
g = 1.0 / (png_ptr->background_gamma);
gs = 1.0 / (png_ptr->background_gamma *
png_ptr->display_gamma);
png_ptr->screen_gamma);
break;
}
if (color_type & PNG_COLOR_MASK_COLOR)
{
/* RGB or RGBA */
png_ptr->background_1.red = (png_uint_16)(pow(
(double)png_ptr->background.red / m, g) * m + .5);
png_ptr->background_1.green = (png_uint_16)(pow(
@@ -792,6 +827,7 @@ png_init_read_transformations(png_structp png_ptr)
}
else
{
/* GRAY or GRAY ALPHA */
png_ptr->background_1.gray = (png_uint_16)(pow(
(double)png_ptr->background.gray / m, g) * m + .5);
png_ptr->background.gray = (png_uint_16)(pow(
@@ -800,6 +836,7 @@ png_init_read_transformations(png_structp png_ptr)
}
}
else
/* transformation does not include PNG_BACKGROUND */
#endif
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
@@ -822,6 +859,7 @@ png_init_read_transformations(png_structp png_ptr)
#endif
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
/* No GAMMA transformation */
if (png_ptr->transformations & PNG_BACKGROUND &&
color_type == PNG_COLOR_TYPE_PALETTE)
{
@@ -834,7 +872,7 @@ png_init_read_transformations(png_structp png_ptr)
back.green = (png_byte)png_ptr->background.green;
back.blue = (png_byte)png_ptr->background.blue;
for (i = 0; i < png_ptr->num_trans; i++)
for (i = 0; i < (int)png_ptr->num_trans; i++)
{
if (png_ptr->trans[i] == 0)
{
@@ -954,7 +992,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
else
info_ptr->channels = 1;
#if defined(PNG_STRIP_ALPHA_SUPPORTED)
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
{
@@ -977,8 +1015,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
info_ptr->bit_depth);
info_ptr->rowbytes =
(png_size_t)((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
}
/* Transform the row. The order of transformations is significant,
@@ -1052,7 +1089,7 @@ png_do_read_transformations(png_structp png_ptr)
png_ptr->gamma_shift);
#endif
#if defined(PNG_RGB_TO_GRAY_SUPPORTED)
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
png_do_rgb_to_gray(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
@@ -1067,6 +1104,8 @@ png_do_read_transformations(png_structp png_ptr)
{
png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->palette_lookup, png_ptr->dither_index);
if(png_ptr->row_info.rowbytes == (png_uint_32)0)
png_error(png_ptr, "png_do_dither returned rowbytes=0");
}
#endif
@@ -1107,6 +1146,11 @@ png_do_read_transformations(png_structp png_ptr)
(png_uint_32)png_ptr->filler, png_ptr->flags);
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -1116,6 +1160,22 @@ png_do_read_transformations(png_structp png_ptr)
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
if (png_ptr->transformations & PNG_USER_TRANSFORM)
if(png_ptr->read_user_transform_fn != NULL)
(*(png_ptr->read_user_transform_fn)) /* user read transform function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
/* png_uint_32 width; width of row */
/* png_uint_32 rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#endif
}
#if defined(PNG_READ_PACK_SUPPORTED)
@@ -1204,7 +1264,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
}
row_info->bit_depth = 8;
row_info->pixel_depth = (png_byte)(8 * row_info->channels);
row_info->rowbytes = (png_size_t)row_info->width * row_info->channels;
row_info->rowbytes = row_info->width * row_info->channels;
}
}
#endif
@@ -1263,7 +1323,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 2:
{
png_bytep bp;
png_size_t i;
png_uint_32 i;
for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++)
{
@@ -1276,7 +1336,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
{
png_bytep bp;
png_byte mask;
png_size_t i;
png_uint_32 i;
mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
(png_byte)((int)0xf >> shift[0]);
@@ -1290,11 +1350,11 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 8:
{
png_bytep bp;
png_size_t i;
png_uint_32 i;
for (bp = row, i = 0; i < row_info->width; i++)
{
for (c = 0; c < row_info->channels; c++, bp++)
for (c = 0; c < (int)row_info->channels; c++, bp++)
{
*bp >>= shift[c];
}
@@ -1308,7 +1368,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
for (bp = row, i = 0; i < row_info->width; i++)
{
for (c = 0; c < row_info->channels; c++, bp += 2)
for (c = 0; c < (int)row_info->channels; c++, bp += 2)
{
value = (png_uint_16)((*bp << 8) + *(bp + 1));
value >>= shift[c];
@@ -1372,7 +1432,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
}
row_info->bit_depth = 8;
row_info->pixel_depth = (png_byte)(8 * row_info->channels);
row_info->rowbytes = (png_size_t)row_info->width * row_info->channels;
row_info->rowbytes = row_info->width * row_info->channels;
}
}
#endif
@@ -1468,6 +1528,87 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
}
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
void
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_read_invert_alpha\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
/* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = 255 - *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
}
}
/* This inverts the alpha channel in RRGGBBAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = 255 - *(--sp);
*(--dp) = 255 - *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
}
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* This inverts the alpha channel in GA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = 255 - *(--sp);
*(--dp) = *(--sp);
}
}
/* This inverts the alpha channel in GGAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = 255 - *(--sp);
*(--dp) = 255 - *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
}
}
}
}
}
#endif
#if defined(PNG_READ_FILLER_SUPPORTED)
/* Add filler channel if we have RGB color */
void
@@ -1500,7 +1641,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
*(--dp) = (png_byte)filler;
row_info->channels = 4;
row_info->pixel_depth = 32;
row_info->rowbytes = (png_size_t)row_info->width * 4;
row_info->rowbytes = row_info->width * 4;
}
/* This changes the data from RGB to XRGB */
else
@@ -1517,7 +1658,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
}
row_info->channels = 4;
row_info->pixel_depth = 32;
row_info->rowbytes = (png_size_t)row_info->width * 4;
row_info->rowbytes = row_info->width * 4;
}
}
}
@@ -1611,7 +1752,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
row_info->color_type |= PNG_COLOR_MASK_COLOR;
row_info->pixel_depth = (png_byte)(row_info->channels *
row_info->bit_depth);
row_info->rowbytes = (png_size_t)((row_info->width *
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
}
}
@@ -1693,7 +1834,7 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
{
double g;
g = 1.0 / (png_ptr->background_gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
@@ -1804,24 +1945,21 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
{
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
int i;
png_color back;
back.red = (png_byte)png_ptr->background.red;
back.green = (png_byte)png_ptr->background.green;
back.blue = (png_byte)png_ptr->background.blue;
for (i = 0; i < num_palette; i++)
for (i = 0; i < (int)png_ptr->num_trans; i++)
{
if (i >= (int)png_ptr->num_trans ||
png_ptr->trans[i] == 0)
if (png_ptr->trans[i] == 0)
{
palette[i].red = back.red;
palette[i].green = back.green;
palette[i].blue = back.blue;
}
else if (i < (int)png_ptr->num_trans ||
png_ptr->trans[i] != 0xff)
else if (png_ptr->trans[i] != 0xff)
{
png_composite(palette[i].red, png_ptr->palette[i].red,
png_ptr->trans[i], back.red);
@@ -1880,7 +2018,6 @@ png_do_background(png_row_infop row_info, png_bytep row,
{
case PNG_COLOR_TYPE_GRAY:
{
/* We currently don't do gamma correction for 2 and 4 bit */
switch (row_info->bit_depth)
{
case 1:
@@ -1889,7 +2026,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 7;
for (i = 0; i < row_info->width; i++)
{
if (((*sp >> shift) & 0x1) == trans_values->gray)
if ((png_uint_16)((*sp >> shift) & 0x1)
== trans_values->gray)
{
*sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
@@ -1910,7 +2048,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 6;
for (i = 0; i < row_info->width; i++)
{
if (((*sp >> shift) & 0x3) == trans_values->gray)
if ((png_uint_16)((*sp >> shift) & 0x3)
== trans_values->gray)
{
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
@@ -1931,7 +2070,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 4;
for (i = 0; i < row_info->width; i++)
{
if (((*sp >> shift) & 0xf) == trans_values->gray)
if ((png_uint_16)((*sp >> shift) & 0xf)
== trans_values->gray)
{
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
@@ -2439,7 +2579,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
row_info->channels--;
row_info->pixel_depth = (png_byte)(row_info->channels *
row_info->bit_depth);
row_info->rowbytes = (png_size_t)((row_info->width *
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
}
}
@@ -2720,7 +2860,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = (png_size_t)row_info->width;
row_info->rowbytes = row_info->width;
}
switch (row_info->bit_depth)
{
@@ -2744,7 +2884,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 32;
row_info->rowbytes = (png_size_t)row_info->width * 4;
row_info->rowbytes = row_info->width * 4;
row_info->color_type = 6;
row_info->channels = 4;
}
@@ -2762,7 +2902,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 24;
row_info->rowbytes = (png_size_t)row_info->width * 3;
row_info->rowbytes = row_info->width * 3;
row_info->color_type = 2;
row_info->channels = 3;
}
@@ -2868,7 +3008,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = (png_size_t)row_info->width;
row_info->rowbytes = row_info->width;
}
if (trans_value != NULL)
@@ -2911,7 +3051,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
row_info->channels = 2;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes =
(png_size_t)((row_info->width * row_info->pixel_depth) >> 3);
((row_info->width * row_info->pixel_depth) >> 3);
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
@@ -2966,7 +3106,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
row_info->channels = 4;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
row_info->rowbytes =
(png_size_t)((row_info->width * row_info->pixel_depth) >> 3);
((row_info->width * row_info->pixel_depth) >> 3);
}
}
}
@@ -3019,7 +3159,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
row_info->channels = 1;
row_info->pixel_depth = row_info->bit_depth;
row_info->rowbytes =
((row_info->width * row_info->pixel_depth + 7) >> 3);
((row_info->width * row_info->pixel_depth + 7) >> 3);
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
palette_lookup != NULL && row_info->bit_depth == 8)
@@ -3049,7 +3189,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
row_info->channels = 1;
row_info->pixel_depth = row_info->bit_depth;
row_info->rowbytes =
(png_size_t)((row_info->width * row_info->pixel_depth + 7) >> 3);
((row_info->width * row_info->pixel_depth + 7) >> 3);
}
else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
dither_lookup && row_info->bit_depth == 8)
@@ -3082,7 +3222,7 @@ png_build_gamma_table(png_structp png_ptr)
int i;
double g;
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
@@ -3107,7 +3247,7 @@ png_build_gamma_table(png_structp png_ptr)
g) * 255.0 + .5);
}
g = 1.0 / (png_ptr->display_gamma);
g = 1.0 / (png_ptr->screen_gamma);
png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
@@ -3160,10 +3300,10 @@ png_build_gamma_table(png_structp png_ptr)
num = (1 << (8 - shift));
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p));
(png_uint_32)(num * sizeof (png_uint_16p)));
if ((png_ptr->transformations & PNG_16_TO_8) &&
!(png_ptr->transformations & PNG_BACKGROUND))
@@ -3174,7 +3314,7 @@ png_build_gamma_table(png_structp png_ptr)
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
}
g = 1.0 / g;
@@ -3204,7 +3344,7 @@ png_build_gamma_table(png_structp png_ptr)
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++)
@@ -3222,12 +3362,12 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0 / (png_ptr->gamma);
png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p ));
(png_uint_32)(num * sizeof (png_uint_16p )));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4);
@@ -3238,15 +3378,15 @@ png_build_gamma_table(png_structp png_ptr)
65535.0, g) * 65535.0 + .5);
}
}
g = 1.0 / (png_ptr->display_gamma);
g = 1.0 / (png_ptr->screen_gamma);
png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p));
(png_uint_32)(num * sizeof (png_uint_16p)));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4);

View File

@@ -1,12 +1,12 @@
/* pngrutil.c - utilities to read a PNG file
*
* libpng 0.97
* libpng 0.99
* 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
* January 7, 1998
* March 7, 1998
*
* This file contains routines which are only called from within
* libpng itself during the course of reading an image.
@@ -27,7 +27,7 @@ png_get_uint_32(png_bytep buf)
((png_uint_32)(*(buf + 2)) << 8) +
(png_uint_32)(*(buf + 3));
return i;
return (i);
}
#if defined(PNG_READ_pCAL_SUPPORTED)
@@ -44,7 +44,7 @@ png_get_int_32(png_bytep buf)
((png_int_32)(*(buf + 2)) << 8) +
(png_int_32)(*(buf + 3));
return i;
return (i);
}
#endif /* PNG_READ_pCAL_SUPPORTED */
@@ -57,7 +57,7 @@ png_get_uint_16(png_bytep buf)
i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
(png_uint_16)(*(buf + 1)));
return i;
return (i);
}
#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
@@ -100,13 +100,13 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip)
{
png_chunk_error(png_ptr, "CRC error");
}
return 1;
return (1);
}
return 0;
return (0);
}
/* Compare the CRC stored in the PNG file with that calulated by libpng from
/* Compare the CRC stored in the PNG file with that calculated by libpng from
the data it has read thus far. */
int
png_crc_error(png_structp png_ptr)
@@ -132,10 +132,10 @@ png_crc_error(png_structp png_ptr)
if (need_crc)
{
crc = png_get_uint_32(crc_bytes);
return (crc != png_ptr->crc);
return ((int)(crc != png_ptr->crc));
}
else
return 0;
return (0);
}
@@ -226,7 +226,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* set up other useful info */
png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
png_ptr->channels);
png_ptr->channels);
png_ptr->rowbytes = ((png_ptr->width *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3);
png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
@@ -258,6 +258,20 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_ptr->mode |= PNG_HAVE_PLTE;
#if defined (PNG_READ_tRNS_SUPPORTED)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
{
if (png_ptr->num_trans > png_ptr->num_palette)
{
png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
png_ptr->num_trans = png_ptr->num_palette;
}
}
}
#endif
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
{
@@ -281,7 +295,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
num = (int)length / 3;
palette = (png_colorp)png_zalloc(png_ptr, num, sizeof (png_color));
palette = (png_colorp)png_zalloc(png_ptr, (uInt)num, sizeof (png_color));
png_ptr->flags |= PNG_FLAG_FREE_PALETTE;
for (i = 0; i < num; i++)
{
@@ -298,10 +312,13 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
whatever the normal CRC configuration tells us. However, if we
have an RGB image, the PLTE can be considered ancillary, so
we will act as though it is. */
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
#endif
{
png_crc_finish(png_ptr, 0);
}
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
{
/* If we don't want to use the data from an ancillary chunk,
@@ -318,7 +335,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_chunk_warning(png_ptr, "CRC error");
png_ptr->flags &= ~PNG_FLAG_FREE_PALETTE;
png_free(png_ptr, palette);
png_zfree(png_ptr, palette);
return;
}
}
@@ -328,7 +345,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_chunk_warning(png_ptr, "CRC error");
}
}
#endif
png_ptr->palette = palette;
png_ptr->num_palette = (png_uint_16)num;
png_set_PLTE(png_ptr, info_ptr, palette, num);
@@ -342,6 +359,10 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
{
png_error(png_ptr, "No image in file");
/* to quiet compiler warnings about unused info_ptr */
if (info_ptr == NULL)
return;
}
png_ptr->mode |= PNG_AFTER_IDAT | PNG_HAVE_IEND;
@@ -416,7 +437,9 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif /* PNG_READ_sRGB_SUPPORTED */
file_gamma = (float)igamma / (float)100000.0;
#ifdef PNG_READ_GAMMA_SUPPORTED
png_ptr->gamma = file_gamma;
#endif
png_set_gAMA(png_ptr, info_ptr, file_gamma);
}
#endif
@@ -626,7 +649,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_byte intent;
int intent;
png_byte buf[1];
png_debug(1, "in png_handle_sRGB\n");
@@ -663,13 +686,13 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
intent = buf[0];
/* check for bad intent */
if (intent > 3)
if (intent >= PNG_sRGB_INTENT_LAST)
{
png_warning(png_ptr, "Unknown sRGB intent");
return;
}
#ifdef PNG_READ_gAMA_SUPPORTED
#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)
{
@@ -717,7 +740,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
{
png_warning(png_ptr, "Duplcate tRNS chunk");
png_warning(png_ptr, "Duplicate tRNS chunk");
png_crc_finish(png_ptr, length);
return;
}
@@ -904,7 +927,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
num = (int)length / 2;
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
num * sizeof (png_uint_16));
(png_uint_32)(num * sizeof (png_uint_16)));
png_ptr->flags |= PNG_FLAG_FREE_HIST;
for (i = 0; i < num; i++)
{
@@ -1017,6 +1040,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_byte type, nparams;
png_charp buf, units, endptr;
png_charpp params;
png_size_t slength;
int i;
png_debug(1, "in png_handle_pCAL\n");
@@ -1039,7 +1063,8 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug1(2, "Allocating and reading pCAL chunk data (%d bytes)\n",
length + 1);
purpose = (png_charp)png_malloc(png_ptr, length + 1);
png_crc_read(png_ptr, (png_bytep)purpose, (png_size_t)length);
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)purpose, slength);
if (png_crc_finish(png_ptr, 0))
{
@@ -1047,13 +1072,13 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return;
}
purpose[length] = '\0'; /* null terminate the last string */
purpose[slength] = 0x00; /* null terminate the last string */
png_debug(3, "Finding end of pCAL purpose string\n");
for (buf = purpose; *buf != '\0'; buf++)
/* empty loop */;
endptr = purpose + length;
endptr = purpose + slength;
/* We need to have at least 12 bytes after the purpose string
in order to get the parameter information. */
@@ -1089,19 +1114,20 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
/* Empty loop to move past the units string. */
for (buf = units; *buf != '\0'; buf++);
for (buf = units; *buf != 0x00; buf++);
png_debug(3, "Allocating pCAL parameters array\n");
params = (png_charpp)png_malloc(png_ptr, nparams*sizeof(png_charp)) ;
params = (png_charpp)png_malloc(png_ptr, (png_uint_32)(nparams
*sizeof(png_charp))) ;
/* Get pointers to the start of each parameter string. */
for (i = 0; i < nparams; i++)
for (i = 0; i < (int)nparams; i++)
{
buf++; /* Skip the null string terminator from previous parameter. */
png_debug1(3, "Reading pCAL parameter %d\n", i);
/* Empty loop to move past each paramter string */
for (params[i] = buf; *buf != '\0' && buf <= endptr; buf++);
for (params[i] = buf; *buf != 0x00 && buf <= endptr; buf++);
/* Make sure we haven't run out of data yet */
if (buf > endptr)
@@ -1173,6 +1199,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_charp key;
png_charp text;
png_uint_32 skip = 0;
png_size_t slength;
png_debug(1, "in png_handle_tEXt\n");
@@ -1192,7 +1219,8 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif
key = (png_charp)png_malloc(png_ptr, length + 1);
png_crc_read(png_ptr, (png_bytep)key, (png_size_t)length);
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)key, slength);
if (png_crc_finish(png_ptr, skip))
{
@@ -1200,15 +1228,15 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return;
}
key[length] = '\0';
key[slength] = 0x00;
for (text = key; *text; text++)
/* empty loop to find end of key */ ;
if (text != key + (png_size_t)length)
if (text != key + slength)
text++;
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
text_ptr->text = text;
@@ -1229,6 +1257,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_charp key;
png_charp text;
int comp_type = PNG_TEXT_COMPRESSION_NONE;
png_size_t slength;
png_debug(1, "in png_handle_zTXt\n");
@@ -1250,20 +1279,21 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif
key = (png_charp)png_malloc(png_ptr, length + 1);
png_crc_read(png_ptr, (png_bytep)key, (png_size_t)length);
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)key, slength);
if (png_crc_finish(png_ptr, 0))
{
png_free(png_ptr, key);
return;
}
key[length] = '\0';
key[slength] = 0x00;
for (text = key; *text; text++)
/* empty loop */ ;
/* zTXt must have some text after the keyword */
if (text == key + (png_size_t)length)
if (text == key + slength)
{
png_warning(png_ptr, "Zero length zTXt chunk");
}
@@ -1275,9 +1305,9 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_ptr->zstream.next_in = (png_bytep)text;
png_ptr->zstream.avail_in = (uInt)(length - (text - key));
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = png_ptr->zbuf_size;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
key_size = text - key;
key_size = (png_size_t)(text - key);
text_size = 0;
text = NULL;
@@ -1298,14 +1328,14 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text == NULL)
{
text_size = key_size + sizeof(msg) + 1;
text = (png_charp)png_malloc(png_ptr, text_size);
text = (png_charp)png_malloc(png_ptr, (png_uint_32)text_size);
png_memcpy(text, key, key_size);
}
text[text_size - 1] = '\0';
text[text_size - 1] = 0x00;
/* Copy what we can of the error message into the text chunk */
text_size = length - (text - key) - 1;
text_size = (png_size_t)(slength - (text - key) - 1);
text_size = sizeof(msg) > text_size ? text_size : sizeof(msg);
png_memcpy(text + key_size, msg, text_size + 1);
break;
@@ -1315,28 +1345,28 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr,
png_ptr->zbuf_size - png_ptr->zstream.avail_out +
key_size + 1);
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
+ key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size);
text_size = key_size + png_ptr->zbuf_size -
png_ptr->zstream.avail_out;
*(text + text_size) = '\0';
*(text + text_size) = 0x00;
}
else
{
png_charp tmp;
tmp = text;
text = png_malloc(png_ptr, text_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
text = (png_charp)png_malloc(png_ptr, (png_uint_32)(text_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf,
(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
*(text + text_size) = '\0';
*(text + text_size) = 0x00;
}
if (ret != Z_STREAM_END)
{
@@ -1356,7 +1386,6 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_free(png_ptr, key);
key = text;
text += key_size;
text_size -= key_size;
}
else /* if (comp_type >= PNG_TEXT_COMPRESSION_LAST) */
{
@@ -1371,12 +1400,12 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif
/* Copy what we can of the error message into the text chunk */
text_size = (png_size_t)length - (text - key) - 1;
text_size = (png_size_t)(slength - (text - key) - 1);
text_size = sizeof(msg) > text_size ? text_size : sizeof(msg);
png_memcpy(text, msg, text_size + 1);
}
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = comp_type;
text_ptr->key = key;
text_ptr->text = text;
@@ -1404,12 +1433,17 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (!(png_ptr->chunk_name[0] & 0x20))
{
png_chunk_error(png_ptr, "unknown critical chunk");
/* to quiet compiler warnings about unused info_ptr */
if (info_ptr == NULL)
return;
}
if (png_ptr->mode & PNG_HAVE_IDAT)
png_ptr->mode |= PNG_AFTER_IDAT;
png_crc_finish(png_ptr, length);
}
/* This function is called to verify that a chunk name is valid.
@@ -1729,13 +1763,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
int s_start, s_end, s_inc;
png_uint_32 i;
sp = row + (png_size_t)((row_info->width - 1) >> 2);
dp = row + (png_size_t)((final_width - 1) >> 2);
sp = row + (png_uint_32)((row_info->width - 1) >> 2);
dp = row + (png_uint_32)((final_width - 1) >> 2);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
dshift = (png_size_t)(((final_width + 3) & 3) << 1);
sshift = (int)(((row_info->width + 3) & 3) << 1);
dshift = (int)(((final_width + 3) & 3) << 1);
s_start = 6;
s_end = 0;
s_inc = -2;
@@ -1743,8 +1777,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
else
#endif
{
sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
sshift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
dshift = (int)((3 - ((final_width + 3) & 3)) << 1);
s_start = 0;
s_end = 6;
s_inc = 2;
@@ -1790,8 +1824,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
dshift = (png_size_t)(((final_width + 1) & 1) << 2);
sshift = (int)(((row_info->width + 1) & 1) << 2);
dshift = (int)(((final_width + 1) & 1) << 2);
s_start = 4;
s_end = 0;
s_inc = -4;
@@ -1799,8 +1833,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
else
#endif
{
sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
sshift = (int)((1 - ((row_info->width + 1) & 1)) << 2);
dshift = (int)((1 - ((final_width + 1) & 1)) << 2);
s_start = 0;
s_end = 4;
s_inc = 4;
@@ -1842,8 +1876,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
pixel_bytes = (row_info->pixel_depth >> 3);
sp = row + (row_info->width - 1) * pixel_bytes;
dp = row + (final_width - 1) * pixel_bytes;
sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
for (i = row_info->width; i; i--)
{
png_byte v[8];
@@ -1874,6 +1908,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
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:
@@ -1987,7 +2022,7 @@ png_read_finish_row(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
do
{
png_ptr->pass++;
@@ -1997,8 +2032,9 @@ png_read_finish_row(png_structp png_ptr)
png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
png_ptr->irowbytes = ((png_ptr->iwidth *
png_ptr->pixel_depth + 7) >> 3) + 1;
png_ptr->irowbytes = ((png_ptr->iwidth *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
if (!(png_ptr->transformations & PNG_INTERLACE))
{
png_ptr->num_rows = (png_ptr->height +
@@ -2023,7 +2059,7 @@ png_read_finish_row(png_structp png_ptr)
png_ptr->zstream.next_out = (Byte *)&extra;
png_ptr->zstream.avail_out = (uInt)1;
do
for(;;)
{
if (!(png_ptr->zstream.avail_in))
{
@@ -2066,7 +2102,7 @@ png_read_finish_row(png_structp png_ptr)
if (!(png_ptr->zstream.avail_out))
png_error(png_ptr, "Extra compressed data");
} while (1);
}
png_ptr->zstream.avail_out = 0;
}
@@ -2099,8 +2135,12 @@ png_read_start_row(png_structp png_ptr)
png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
png_ptr->irowbytes = ((png_ptr->iwidth *
png_ptr->pixel_depth + 7) >> 3) + 1;
rowbytes = ((png_ptr->iwidth *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
png_ptr->irowbytes = (png_size_t)rowbytes;
if((png_uint_32)png_ptr->irowbytes != rowbytes)
png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
}
else
{
@@ -2189,9 +2229,10 @@ png_read_start_row(png_structp png_ptr)
if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
png_error(png_ptr, "This image requires a row greater than 64KB");
#endif
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
png_ptr->rowbytes + 1));
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_debug1(3, "width = %d,\n", png_ptr->width);
png_debug1(3, "height = %d,\n", png_ptr->height);

View File

@@ -1,12 +1,12 @@
/* pngset.c - storage of image information into info struct
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* The functions here are used during reads to store data from the file
* into the info struct, and during writes to store application data
@@ -22,7 +22,7 @@ void
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
{
png_debug1(1, "in %s storage function\n", "bKGD");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
png_memcpy(&(info_ptr->background), background, sizeof(png_color_16));
@@ -37,7 +37,7 @@ png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
double green_x, double green_y, double blue_x, double blue_y)
{
png_debug1(1, "in %s storage function\n", "cHRM");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_white = (float)white_x;
@@ -57,7 +57,7 @@ void
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
{
png_debug1(1, "in %s storage function\n", "gAMA");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->gamma = (float)file_gamma;
@@ -70,7 +70,7 @@ void
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{
png_debug1(1, "in %s storage function\n", "hIST");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->hist = hist;
@@ -84,8 +84,9 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
int color_type, int interlace_type, int compression_type,
int filter_type)
{
int rowbytes_per_pixel;
png_debug1(1, "in %s storage function\n", "IHDR");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->width = width;
@@ -104,7 +105,16 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
info_ptr->channels++;
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
/* check for overflow */
rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;
info_ptr->rowbytes = info_ptr->width * rowbytes_per_pixel;
if (( width > (png_uint_32)2147483647L/rowbytes_per_pixel))
{
png_warning(png_ptr,
"Width too large to process image data; rowbytes will overflow.");
info_ptr->rowbytes = (png_size_t)0;
}
}
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
@@ -113,7 +123,7 @@ png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
{
png_debug1(1, "in %s storage function\n", "oFFs");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_offset = offset_x;
@@ -129,17 +139,17 @@ png_set_pCAL(png_structp png_ptr, png_infop info_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 length;
png_uint_32 length;
int i;
png_debug1(1, "in %s storage function\n", "pCAL");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%d bytes)\n", length);
info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_purpose, purpose, length);
png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
png_debug(3, "storing X0, X1, type, and nparams in info\n");
info_ptr->pcal_X0 = X0;
@@ -150,10 +160,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%d bytes)\n", length);
info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_units, units, length);
png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
(nparams + 1) * sizeof(png_charp));
(png_uint_32)((nparams + 1) * sizeof(png_charp)));
info_ptr->pcal_params[nparams] = NULL;
for (i = 0; i < nparams; i++)
@@ -161,7 +171,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length);
info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_params[i], params[i], length);
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
}
info_ptr->valid |= PNG_INFO_pCAL;
@@ -174,7 +184,7 @@ png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
{
png_debug1(1, "in %s storage function\n", "pHYs");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_pixels_per_unit = res_x;
@@ -189,7 +199,7 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
png_colorp palette, int num_palette)
{
png_debug1(1, "in %s storage function\n", "PLTE");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->palette = palette;
@@ -203,7 +213,7 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
png_color_8p sig_bit)
{
png_debug1(1, "in %s storage function\n", "sBIT");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof (png_color_8));
@@ -213,18 +223,18 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
void
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, png_byte intent)
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
{
png_debug1(1, "in %s storage function\n", "sRGB");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->srgb_intent = intent;
info_ptr->srgb_intent = (png_byte)intent;
info_ptr->valid |= PNG_INFO_sRGB;
}
void
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
png_byte intent)
int intent)
{
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
float file_gamma;
@@ -233,7 +243,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
#endif
png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
png_set_sRGB(png_ptr, info_ptr, intent);
@@ -269,9 +279,9 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
int i;
png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
"text" : png_ptr->chunk_name));
"text" : (png_const_charp)png_ptr->chunk_name));
if (info_ptr == NULL || num_text == 0)
if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
return;
/* Make sure we have enough space in the "text" array in info_struct
@@ -288,8 +298,9 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->max_text = info_ptr->num_text + num_text + 8;
old_text = info_ptr->text;
info_ptr->text = (png_textp)png_malloc(png_ptr,
info_ptr->max_text * sizeof (png_text));
png_memcpy(info_ptr->text, old_text, old_max * sizeof(png_text));
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
sizeof(png_text)));
png_free(png_ptr, old_text);
}
else
@@ -297,7 +308,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->max_text = num_text + 8;
info_ptr->num_text = 0;
info_ptr->text = (png_textp)png_malloc(png_ptr,
info_ptr->max_text * sizeof (png_text));
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
}
png_debug1(3, "allocated %d entries for info_ptr->text\n",
info_ptr->max_text);
@@ -308,7 +319,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].text == NULL)
text_ptr[i].text = "";
text_ptr[i].text = (png_charp)"";
if (text_ptr[i].text[0] == '\0')
{
@@ -333,7 +344,7 @@ 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 (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time));
@@ -347,7 +358,7 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep trans, int num_trans, png_color_16p trans_values)
{
png_debug1(1, "in %s storage function\n", "tRNS");
if (info_ptr == NULL)
if (png_ptr == NULL || info_ptr == NULL)
return;
if (trans != NULL)

491
pngtest.c
View File

@@ -1,12 +1,12 @@
/* pngtest.c - a simple test program to test libpng
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* 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
@@ -37,6 +37,8 @@
#include "png.h"
int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
#ifdef __TURBOC__
#include <mem.h>
#endif
@@ -45,10 +47,134 @@
/* #define STDERR stderr */
#define STDERR stdout /* for DOS */
/* example of using row callbacks to make a simple progress meter */
static int status_pass=1;
static int status_dots_requested=0;
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(status_pass != pass)
{
fprintf(stdout,"\n Pass %d: ",pass);
status_pass = pass;
status_dots = 30;
}
status_dots--;
if(status_dots == 0)
{
fprintf(stdout, "\n ");
status_dots=30;
}
fprintf(stdout, "r");
}
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;
fprintf(stdout, "w");
}
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
/* example of using user transform callback (we don't transform anything,
but merely count the black pixels) */
static png_uint_32 black_pixels;
void
count_black_pixels(png_structp png_ptr, png_row_infop row_info, png_bytep data)
{
png_bytep dp = data;
if(png_ptr == NULL)return;
/* contents of row_info:
* png_uint_32 width width of row
* png_uint_32 rowbytes number of bytes in row
* png_byte color_type color type of pixels
* png_byte bit_depth bit depth of samples
* png_byte channels number of channels (1-4)
* png_byte pixel_depth bits per pixel (depth*channels)
*/
/* counts the number of black pixels (or zero pixels if color_type is 3 */
if(row_info->color_type == 0 || row_info->color_type == 3)
{
int pos=0;
png_uint_32 n;
for (n=0; n<row_info->width; n++)
{
if(row_info->bit_depth == 1)
if(((*dp << pos++ )& 0x80) == 0) black_pixels++;
if(pos == 8)
{
pos=0;
dp++;
}
if(row_info->bit_depth == 2)
if(((*dp << (pos+=2))& 0xc0) == 0) black_pixels++;
if(pos == 8)
{
pos=0;
dp++;
}
if(row_info->bit_depth == 4)
if(((*dp << (pos+=4))& 0xf0) == 0) black_pixels++;
if(pos == 8)
{
pos=0;
dp++;
}
if(row_info->bit_depth == 8)
if(*dp++ == 0) black_pixels++;
if(row_info->bit_depth == 16)
{
if((*dp | *(dp+1)) == 0) black_pixels++;
dp+=2;
}
}
}
else /* other color types */
{
png_uint_32 n;
int channel;
int color_channels = row_info->channels;
if(row_info->color_type > 3)color_channels--;
for (n=0; n<row_info->width; n++)
{
for (channel = 0; channel < color_channels; channel++)
{
if(row_info->bit_depth == 8)
if(*dp++ == 0) black_pixels++;
if(row_info->bit_depth == 16)
{
if((*dp | *(dp+1)) == 0) black_pixels++;
dp+=2;
}
}
if(row_info->color_type > 3)
{
dp++;
if(row_info->bit_depth == 16)dp++;
}
}
}
}
#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
static int verbose = 0;
static int wrote_question = 0;
#if defined(PNG_NO_STDIO)
/* START of code to validate stdio-free compilation */
/* These copies of the default read/write functions come from pngrio.c and */
/* pngwio.c. They allow "don't include stdio" testing of the library. */
#if defined(PNG_NO_STDIO)
/* This is the function which does the actual reading of data. If you are
not reading from a standard C stream, you should create a replacement
read_data function and use it at run time with png_set_read_fn(), rather
@@ -118,7 +244,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_error(png_ptr, "read Error");
}
}
#endif
#endif /* USE_FAR_KEYWORD */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
static void
@@ -196,7 +322,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
}
#endif
#endif /* USE_FAR_KEYWORD */
/* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything
@@ -224,13 +350,115 @@ png_default_error(png_structp png_ptr, png_const_charp message)
/* We can return because png_error calls the default handler which is
* actually ok in this case. */
}
#endif
#endif /* PNG_NO_STDIO */
/* END of code to validate stdio-free compilation */
/* Test one file */
int test(PNG_CONST char *inname, PNG_CONST char *outname)
/* START of code to validate memory allocation and deallocation */
#ifdef PNGTEST_MEMORY_DEBUG
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
ERROR - memory debugging is not supported on this platform
#else
/* Allocate memory. For reasonable files, size should never exceed
64K. However, zlib may allocate more then 64K if you don't tell
it not to. See zconf.h and png.h for more information. zlib does
need to allocate exactly 64K, so whatever you call here must
have the ability to do that.
This piece of code can be compiled to validate max 64K allocations
by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
typedef struct memory_information {
png_uint_32 size;
png_voidp pointer;
struct memory_information FAR *next;
} memory_information;
typedef memory_information FAR *memory_infop;
static memory_infop pinformation = NULL;
static int current_allocation = 0;
static int maximum_allocation = 0;
extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
png_uint_32 size));
extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
png_voidp ptr));
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size) {
if (png_ptr == NULL) {
fprintf(STDERR, "NULL pointer to memory allocator\n");
return (NULL);
}
if (size == 0)
return (png_voidp)(NULL);
/* This calls the library allocator twice, once to get the requested
buffer and once to get a new free list entry. */
{
memory_infop pinfo = png_debug_malloc(png_ptr, sizeof *pinfo);
pinfo->size = size;
current_allocation += size;
if (current_allocation > maximum_allocation)
maximum_allocation = current_allocation;
pinfo->pointer = png_debug_malloc(png_ptr, size);
pinfo->next = pinformation;
pinformation = pinfo;
/* Make sure the caller isn't assuming zeroed memory. */
png_memset(pinfo->pointer, 0xdd, pinfo->size);
return (png_voidp)(pinfo->pointer);
}
}
/* Free a pointer. It is removed from the list at the same time. */
void
png_free(png_structp png_ptr, png_voidp ptr)
{
FILE *fpin, *fpout;
if (png_ptr == NULL)
fprintf(STDERR, "NULL pointer to memory allocator\n");
if (ptr == 0) {
#if 0 /* This happens all the time. */
fprintf(STDERR, "WARNING: freeing NULL pointer\n");
#endif
return;
}
/* Unlink the element from the list. */
{
memory_infop FAR *ppinfo = &pinformation;
for (;;) {
memory_infop pinfo = *ppinfo;
if (pinfo->pointer == ptr) {
*ppinfo = pinfo->next;
current_allocation -= pinfo->size;
if (current_allocation < 0)
fprintf(STDERR, "Duplicate free of memory\n");
/* We must free the list element too, but first kill
the memory which is to be freed. */
memset(ptr, 0x55, pinfo->size);
png_debug_free(png_ptr, pinfo);
break;
}
if (pinfo->next == NULL) {
fprintf(STDERR, "Pointer %x not found\n", ptr);
break;
}
ppinfo = &pinfo->next;
}
}
/* Finally free the data. */
png_debug_free(png_ptr, ptr);
}
#endif /* Not Borland DOS special memory handler */
#endif
/* END of code to test memory allocation/deallocation */
/* Test one file */
int
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_bytep row_buf;
@@ -249,30 +477,32 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
if ((fpin = fopen(inname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find input file %s\n", inname);
return 1;
return (1);
}
if ((fpout = fopen(outname, "wb")) == NULL)
{
fprintf(STDERR, "Could not open output file %s\n", outname);
fclose(fpin);
return 1;
return (1);
}
png_debug(0, "Allocating read and write structures\n");
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
#if defined(PNG_NO_STDIO)
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, png_default_warning);
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
png_default_warning);
#endif
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
#if defined(PNG_NO_STDIO)
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, png_default_warning);
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
png_default_warning);
#endif
png_debug(0, "Allocating read_info, write_info and end_info structures\n");
read_info_ptr = png_create_info_struct(read_ptr);
write_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);
png_debug(0, "Setting jmpbuf for read struct\n");
@@ -287,7 +517,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
png_debug(0, "Setting jmpbuf for write struct\n");
@@ -303,7 +533,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
#ifdef USE_FAR_KEYWORD
@@ -321,6 +551,22 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
#else
NULL);
#endif
#endif
if(status_dots_requested == 1)
{
png_set_write_status_fn(write_ptr, write_row_callback);
png_set_read_status_fn(read_ptr, read_row_callback);
}
else
{
png_set_write_status_fn(write_ptr, NULL);
png_set_read_status_fn(read_ptr, NULL);
}
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
black_pixels=0;
png_set_write_user_transform_fn(write_ptr, count_black_pixels);
#endif
png_debug(0, "Reading info struct\n");
@@ -334,7 +580,11 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
&color_type, &interlace_type, &compression_type, &filter_type))
{
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
color_type, interlace_type, compression_type, filter_type);
#else
color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
#endif
}
}
#if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED)
@@ -371,7 +621,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
{
png_byte intent;
int intent;
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
{
@@ -486,6 +736,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_debug(0, "\nWriting info struct\n");
png_write_info(write_ptr, write_info_ptr);
png_debug(0, "\nAllocating row buffer \n");
row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr));
if (row_buf == NULL)
@@ -495,14 +746,16 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
png_debug(0, "Writing row data\n");
num_pass = png_set_interlace_handling(read_ptr);
png_set_interlace_handling(write_ptr);
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);
@@ -513,31 +766,41 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
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);
#ifdef PNG_EASY_ACCESS_SUPPORTED
if(verbose)
{
png_uint_32 iwidth, iheight;
iwidth = png_get_image_width(write_ptr, write_info_ptr);
iheight = png_get_image_height(write_ptr, write_info_ptr);
fprintf(STDERR, "Image width = %lu, height = %lu\n",
iwidth, iheight);
}
#endif
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_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
png_free(read_ptr, row_buf);
png_debug(0, "Opening files for comparison\n");
if ((fpin = fopen(inname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", inname);
return 1;
return (1);
}
if ((fpout = fopen(outname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", outname);
fclose(fpin);
return 1;
return (1);
}
while (1)
for(;;)
{
png_size_t num_in, num_out;
@@ -548,9 +811,20 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
{
fprintf(STDERR, "Files %s and %s are of a different size\n",
inname, outname);
if(wrote_question == 0)
{
fprintf(STDERR,
" Was %s written with the same chunk size (8k),",inname);
fprintf(STDERR,
" filtering\n heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default)\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question=1;
}
fclose(fpin);
fclose(fpout);
return 1;
return (0);
}
if (!num_in)
@@ -559,25 +833,36 @@ int test(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);
if(wrote_question == 0)
{
fprintf(STDERR,
" Was %s written with the same chunk size (8k),",inname);
fprintf(STDERR,
" filtering\n heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default)\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question=1;
}
fclose(fpin);
fclose(fpout);
return 1;
return (0);
}
}
fclose(fpin);
fclose(fpout);
return 0;
return (0);
}
/* input and output filenames */
#ifdef RISCOS
PNG_CONST char *inname = "pngtest_png";
PNG_CONST char *outname = "pngout_png";
PNG_CONST char *inname = "pngtest/png";
PNG_CONST char *outname = "pngout/png";
#else
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";
#endif
int
@@ -587,6 +872,19 @@ main(int argc, char *argv[])
int ierror = 0;
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
/* 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
tests should be impossible because of the way the macros are set
in pngconf.h */
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
#endif
/* I think the following can happen. */
#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
#endif
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
{
@@ -599,41 +897,144 @@ main(int argc, char *argv[])
if (argc > 1)
{
if (strcmp(argv[1], "-m") == 0)
multiple = 1;
else
inname = argv[1];
if (strcmp(argv[1], "-m") == 0)
{
multiple = 1;
status_dots_requested = 0;
}
else if (strcmp(argv[1], "-mv") == 0 ||
strcmp(argv[1], "-vm") == 0 )
{
multiple = 1;
verbose = 1;
status_dots_requested = 1;
}
else if (strcmp(argv[1], "-v") == 0)
{
verbose = 1;
status_dots_requested = 1;
inname = argv[2];
}
else
{
inname = argv[1];
status_dots_requested = 0;
}
}
if (!multiple && argc == 3)
outname = argv[2];
if (!multiple && argc == 3+verbose)
outname = argv[2+verbose];
if (!multiple && argc > 3 || multiple && argc < 2)
if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
{
fprintf(STDERR, "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
fprintf(STDERR,
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
argv[0], argv[0]);
fprintf(STDERR, " reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR, " with -m %s is used as a temporary file\n", outname);
fprintf(STDERR,
" reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR,
" with -m %s is used as a temporary file\n", outname);
exit(1);
}
if (multiple)
{
int i;
#ifdef PNGTEST_MEMORY_DEBUG
int allocation_now = current_allocation;
#endif
for (i=2; i<argc; ++i)
{
fprintf(STDERR, "Testing %s:\n",argv[i]);
ierror += test(argv[i], outname);
{
int kerror;
fprintf(STDERR, "Testing %s:",argv[i]);
kerror = test_one_file(argv[i], outname);
if (kerror == 0)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
fprintf(STDERR, " PASS (%lu black pixels)\n",black_pixels);
#else
fprintf(STDERR, " PASS\n");
#endif
else {
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
#ifdef PNGTEST_MEMORY_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
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) {
fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
pinfo = pinfo->next;
}
}
#endif
}
#ifdef PNGTEST_MEMORY_DEBUG
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
maximum_allocation);
#endif
}
else
{
ierror += test(inname, outname);
int i;
for (i=0; i<3; ++i) {
int kerror;
#ifdef PNGTEST_MEMORY_DEBUG
int allocation_now = current_allocation;
#endif
if (i == 1) status_dots_requested = 1;
else if(verbose == 0)status_dots_requested = 0;
if (i == 0 || verbose == 1 || ierror != 0)
fprintf(STDERR, "Testing %s:",inname);
kerror = test_one_file(inname, outname);
if(kerror == 0)
{
if(verbose == 1 || i == 2)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
fprintf(STDERR, " PASS (%lu black pixels)\n",black_pixels);
#else
fprintf(STDERR, " PASS\n");
#endif
}
else
{
if(verbose == 0 && i != 2)
fprintf(STDERR, "Testing %s:",inname);
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
#ifdef PNGTEST_MEMORY_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
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) {
fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
pinfo = pinfo->next;
}
}
#endif
}
#ifdef PNGTEST_MEMORY_DEBUG
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
maximum_allocation);
#endif
}
if (ierror == 0)
fprintf(STDERR, "libpng passes test\n");
else
fprintf(STDERR, "libpng FAILS test\n");
return ierror != 0;
return (int)(ierror != 0);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@@ -1,12 +1,12 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
#define PNG_INTERNAL
@@ -68,7 +68,8 @@ png_set_shift(png_structp png_ptr, png_color_8p true_bits)
}
#endif
#if defined(PNG_READ_INTERLACING_SUPPORTED) || defined(PNG_WRITE_INTERLACING_SUPPORTED)
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
int
png_set_interlace_handling(png_structp png_ptr)
{
@@ -76,10 +77,10 @@ png_set_interlace_handling(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->transformations |= PNG_INTERLACE;
return 7;
return (7);
}
return 1;
return (1);
}
#endif
@@ -118,6 +119,16 @@ png_set_swap_alpha(png_structp png_ptr)
}
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void
png_set_invert_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_invert_alpha\n");
png_ptr->transformations |= PNG_INVERT_ALPHA;
}
#endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
void
png_set_invert_mono(png_structp png_ptr)
@@ -289,7 +300,7 @@ png_do_packswap(png_row_infop row_info, png_bytep row)
png_debug(1, "in png_do_packswap\n");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL
row != NULL && row_info != NULL &&
#endif
row_info->bit_depth < 8)
{

View File

@@ -1,12 +1,12 @@
/* pngwio.c - functions for data output
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*
* This file provides a location for all output. Users which need
* special handling are expected to write functions which have the same
@@ -180,7 +180,7 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
#if defined(USE_FAR_KEYWORD)
#if defined(_MSC_VER)
void *far_to_near(png_structp png_ptr,png_voidp ptr, int check)
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;
@@ -192,7 +192,7 @@ void *far_to_near(png_structp png_ptr,png_voidp ptr, int check)
return(near_ptr);
}
# else
void *far_to_near(png_structp png_ptr,png_voidp ptr, int check)
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;

View File

@@ -1,12 +1,12 @@
/* pngwrite.c - general routines to write a PNG file
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
/* get internal access to png.h */
@@ -34,7 +34,12 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
/* write IHDR information. */
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
info_ptr->filter_type, info_ptr->interlace_type);
info_ptr->filter_type,
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
info_ptr->interlace_type);
#else
0);
#endif
/* the rest of these check to see if the valid field has the appropriate
flag set, and if it does, writes the chunk. */
#if defined(PNG_WRITE_gAMA_SUPPORTED)
@@ -43,7 +48,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
#endif
#if defined(PNG_WRITE_sRGB_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sRGB)
png_write_sRGB(png_ptr, info_ptr->srgb_intent);
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
#endif
#if defined(PNG_WRITE_sBIT_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sBIT)
@@ -62,10 +67,23 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
(png_uint_32)info_ptr->num_palette);
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Valid palette required for paletted images\n");
#if defined(PNG_WRITE_tRNS_SUPPORTED)
if (info_ptr->valid & PNG_INFO_tRNS)
{
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel (in tRNS) */
if (png_ptr->transformations & PNG_INVERT_ALPHA &&
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
int j;
for (j=0; j<(int)info_ptr->num_trans; j++)
info_ptr->trans[j] = 255 - info_ptr->trans[j];
}
#endif
png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
info_ptr->num_trans, info_ptr->color_type);
}
#endif
#if defined(PNG_WRITE_bKGD_SUPPORTED)
if (info_ptr->valid & PNG_INFO_bKGD)
@@ -200,19 +218,21 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
png_write_IEND(png_ptr);
}
#if defined(PNG_TIME_RFC1152_SUPPORTED)
/* Convert the supplied time into an RFC 1152 string suitable for use in
#if defined(PNG_TIME_RFC1123_SUPPORTED)
/* Convert the supplied time into an RFC 1123 string suitable for use in
* a "Creation Time" or other text-based time string.
*/
png_charp
png_convert_to_rfc1152(png_structp png_ptr, png_timep ptime)
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
{
const char *short_months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static const char short_months[12][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if (png_ptr->time_buffer == NULL)
{
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, 29*sizeof(char));
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
sizeof(char)));
}
#ifdef USE_FAR_KEYWORD
@@ -231,9 +251,9 @@ png_convert_to_rfc1152(png_structp png_ptr, png_timep ptime)
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
#endif
return png_ptr->time_buffer;
return ((png_charp)png_ptr->time_buffer);
}
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if defined(PNG_WRITE_tIME_SUPPORTED)
void
@@ -271,7 +291,7 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
png_debug(1, "in png_create_write_struct\n");
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
{
return (png_structp)NULL;
return ((png_structp)NULL);
}
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
@@ -281,7 +301,7 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
{
png_free(png_ptr, png_ptr->zbuf);
png_destroy_struct(png_ptr);
return (png_structp)NULL;
return ((png_structp)NULL);
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
@@ -302,7 +322,8 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
@@ -311,7 +332,7 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
1, NULL, NULL);
#endif
return (png_ptr);
return ((png_structp)png_ptr);
}
@@ -333,7 +354,8 @@ png_write_init(png_structp png_ptr)
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -373,9 +395,13 @@ png_write_image(png_structp png_ptr, png_bytepp image)
png_bytepp rp; /* points to current row */
png_debug(1, "in png_write_image\n");
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* intialize interlace handling. If image is not interlaced,
this will set pass to 1 */
num_pass = png_set_interlace_handling(png_ptr);
#else
num_pass = 1;
#endif
/* loop through passes */
for (pass = 0; pass < num_pass; pass++)
{
@@ -465,6 +491,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
png_ptr->row_info.channels);
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
@@ -476,7 +503,8 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_debug1(3, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes);
/* Copy user's row into buffer, leaving room for filter byte. */
png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes);
png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
png_ptr->row_info.rowbytes);
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* handle interlacing */
@@ -500,6 +528,9 @@ png_write_row(png_structp png_ptr, png_bytep row)
/* Find a filter if necessary, filter the row and write it out. */
png_write_find_filter(png_ptr, &(png_ptr->row_info));
if (png_ptr->write_row_fn != NULL)
(*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
}
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
@@ -582,6 +613,19 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
{
#ifdef PNG_WRITE_tEXt_SUPPORTED
png_free(png_ptr, info_ptr->text);
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
png_free(png_ptr, info_ptr->pcal_purpose);
png_free(png_ptr, info_ptr->pcal_units);
if (info_ptr->pcal_params != NULL)
{
int i;
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
}
png_free(png_ptr, info_ptr->pcal_params);
}
#endif
png_destroy_struct((png_voidp)info_ptr);
*info_ptr_ptr = (png_infop)NULL;
@@ -617,9 +661,9 @@ png_write_destroy(png_structp png_ptr)
png_free(png_ptr, png_ptr->up_row);
png_free(png_ptr, png_ptr->avg_row);
png_free(png_ptr, png_ptr->paeth_row);
#if defined(PNG_TIME_RFC1152_SUPPORTED)
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_free(png_ptr, png_ptr->time_buffer);
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_free(png_ptr, png_ptr->prev_filters);
png_free(png_ptr, png_ptr->filter_weights);
@@ -679,7 +723,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
if (png_ptr->do_filter & PNG_FILTER_SUB && png_ptr->sub_row == NULL)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
@@ -693,7 +737,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
else
{
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
}
@@ -708,7 +752,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
else
{
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
}
@@ -723,8 +767,8 @@ png_set_filter(png_structp png_ptr, int method, int filters)
}
else
{
png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
}
@@ -780,7 +824,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->prev_filters == NULL)
{
png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
sizeof(png_byte) * num_weights);
(png_uint_32)(sizeof(png_byte) * num_weights));
/* To make sure that the weighting starts out fairly */
for (i = 0; i < num_weights; i++)
@@ -791,11 +835,11 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->filter_weights == NULL)
{
png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * num_weights);
png_ptr->filter_weights = (png_uint_16p) png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * num_weights));
png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * num_weights);
png_ptr->inv_filter_weights = (png_uint_16p) png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * num_weights));
for (i = 0; i < num_weights; i++)
{
@@ -826,11 +870,11 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
*/
if (png_ptr->filter_costs == NULL)
{
png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST);
png_ptr->filter_costs = (png_uint_16p) png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST);
png_ptr->inv_filter_costs = (png_uint_16p) png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
{
@@ -907,3 +951,20 @@ png_set_compression_method(png_structp png_ptr, int method)
png_ptr->zlib_method = method;
}
void
png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
{
png_ptr->write_row_fn = write_row_fn;
}
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
void
png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
write_user_transform_fn)
{
png_debug(1, "in png_set_write_user_transform_fn\n");
png_ptr->transformations |= PNG_USER_TRANSFORM;
png_ptr->write_user_transform_fn = write_user_transform_fn;
}
#endif

View File

@@ -1,12 +1,12 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
#define PNG_INTERNAL
@@ -19,11 +19,30 @@ void
png_do_write_transformations(png_structp png_ptr)
{
png_debug(1, "in png_do_write_transformations\n");
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
if (png_ptr->transformations & PNG_USER_TRANSFORM)
if(png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* user write transform function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
/* png_uint_32 width; width of row */
/* png_uint_32 rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED)
if (png_ptr->transformations & PNG_FILLER)
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->flags);
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED)
if (png_ptr->transformations & PNG_PACK)
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
@@ -38,6 +57,10 @@ png_do_write_transformations(png_structp png_ptr)
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);
#endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -219,7 +242,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
channels++;
}
/* with low row dephts, could only be grayscale, so one channel */
/* with low row depths, could only be grayscale, so one channel */
if (row_info->bit_depth < 8)
{
png_bytep bp;
@@ -394,3 +417,79 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
}
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_invert_alpha\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
/* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
}
}
/* This inverts the alpha channel in RRGGBBAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
*(dp++) = 255 - *(sp++);
}
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* This inverts the alpha channel in GA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
}
}
/* This inverts the alpha channel in GGAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
*(dp++) = 255 - *(sp++);
}
}
}
}
}
#endif

View File

@@ -1,12 +1,12 @@
/* pngwutil.c - utilities to write a PNG file
*
* libpng 0.97
* libpng 1.00
* 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
* January 7, 1998
* March 7, 1998
*/
#define PNG_INTERNAL
@@ -200,12 +200,16 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
filter_type = PNG_FILTER_TYPE_BASE;
}
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
if (interlace_type != PNG_INTERLACE_NONE &&
interlace_type != PNG_INTERLACE_ADAM7)
{
png_warning(png_ptr, "Invalid interlace type specified");
interlace_type = PNG_INTERLACE_ADAM7;
}
#else
interlace_type=PNG_INTERLACE_NONE;
#endif
/* save off the relevent information */
png_ptr->bit_depth = (png_byte)bit_depth;
@@ -346,15 +350,15 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
#if defined(PNG_WRITE_sRGB_SUPPORTED)
/* write a sRGB chunk */
void
png_write_sRGB(png_structp png_ptr, png_byte srgb_intent)
png_write_sRGB(png_structp png_ptr, int srgb_intent)
{
png_byte buf[1];
png_debug(1, "in png_write_sRGB\n");
if(srgb_intent > 3)
if(srgb_intent >= PNG_sRGB_INTENT_LAST)
png_warning(png_ptr,
"Invalid sRGB rendering intent specified");
buf[0]=srgb_intent;
buf[0]=(png_byte)srgb_intent;
png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
}
#endif
@@ -371,7 +375,7 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
/* make sure we don't depend upon the order of PNG_COLOR_8 */
if (color_type & PNG_COLOR_MASK_COLOR)
{
int maxbits;
png_byte maxbits;
maxbits = color_type==PNG_COLOR_TYPE_PALETTE ? 8:png_ptr->usr_bit_depth;
if (sbit->red == 0 || sbit->red > maxbits ||
@@ -482,7 +486,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
png_debug(1, "in png_write_tRNS\n");
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
if (num_trans <= 0 || num_trans > png_ptr->num_palette)
if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
{
png_warning(png_ptr,"Invalid number of transparent colors specified");
return;
@@ -506,7 +510,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
}
else
{
png_warning(png_ptr, "Can't write tRNS with and alpha channel");
png_warning(png_ptr, "Can't write tRNS with an alpha channel");
}
}
#endif
@@ -547,13 +551,13 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
#if defined(PNG_WRITE_hIST_SUPPORTED)
/* write the histogram */
void
png_write_hIST(png_structp png_ptr, png_uint_16p hist, png_uint_32 num_hist)
png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
{
png_uint_32 i;
int i;
png_byte buf[3];
png_debug(1, "in png_write_hIST\n");
if (num_hist > png_ptr->num_palette)
if (num_hist > (int)png_ptr->num_palette)
{
png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
png_ptr->num_palette);
@@ -561,7 +565,7 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, png_uint_32 num_hist)
return;
}
png_write_chunk_start(png_ptr, png_hIST, num_hist * 2);
png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
for (i = 0; i < num_hist; i++)
{
png_save_uint_16(buf, hist[i]);
@@ -595,12 +599,12 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
if (key == NULL || (key_len = png_strlen(key)) == 0)
{
png_chunk_warning(png_ptr, "zero length keyword");
return 0;
return ((png_size_t)0);
}
png_debug1(2, "Keyword to be checked is '%s'\n", key);
*new_key = (png_charp)png_malloc(png_ptr, key_len + 1);
*new_key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + 1));
/* Replace non-printing characters with a blank and print a warning */
for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
@@ -684,7 +688,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
key_len = 79;
}
return key_len;
return (key_len);
}
#endif
@@ -811,17 +815,18 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
old_ptr = output_ptr;
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charpp));
(png_uint_32)(max_output_ptr * sizeof (png_charpp)));
png_memcpy(output_ptr, old_ptr, old_max * sizeof (png_charp));
png_free(png_ptr, old_ptr);
}
else
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charp));
(png_uint_32)(max_output_ptr * sizeof (png_charp)));
}
/* save the data */
output_ptr[num_output_ptr] = png_malloc(png_ptr, png_ptr->zbuf_size);
output_ptr[num_output_ptr] = (png_charp)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size);
num_output_ptr++;
@@ -864,18 +869,18 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
old_ptr = output_ptr;
/* This could be optimized to realloc() */
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charpp));
(png_uint_32)(max_output_ptr * sizeof (png_charpp)));
png_memcpy(output_ptr, old_ptr, old_max * sizeof (png_charp));
png_free(png_ptr, old_ptr);
}
else
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charp));
(png_uint_32)(max_output_ptr * sizeof (png_charp)));
}
/* save off the data */
output_ptr[num_output_ptr] = png_malloc(png_ptr,
png_ptr->zbuf_size);
output_ptr[num_output_ptr] = (png_charp)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size);
num_output_ptr++;
@@ -963,7 +968,8 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
png_debug1(3, "pCAL units length = %d\n", units_len);
total_len = purpose_len + units_len + 10;
params_len = (png_uint_32p)png_malloc(png_ptr, nparams*sizeof(png_uint_32));
params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
*sizeof(png_uint_32)));
/* Find the length of each parameter, making sure we don't count the
null terminator for the last parameter. */
@@ -975,7 +981,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, total_len);
png_write_chunk_start(png_ptr, 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);
@@ -992,6 +998,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
(png_size_t)params_len[i]);
}
png_free(png_ptr, params_len);
png_write_chunk_end(png_ptr);
}
#endif
@@ -1057,14 +1064,14 @@ png_write_start_row(png_structp png_ptr)
png_ptr->usr_bit_depth + 7) >> 3) + 1);
/* set up row buffer */
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size);
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
/* set up filtering buffer, if using this filter */
if (png_ptr->do_filter & PNG_FILTER_SUB)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
@@ -1072,31 +1079,32 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
{
/* set up previous row buffer */
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, buf_size);
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
png_memset(png_ptr->prev_row, 0, buf_size);
if (png_ptr->do_filter & PNG_FILTER_UP)
{
png_ptr->up_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
if (png_ptr->do_filter & PNG_FILTER_AVG)
{
png_ptr->avg_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
if (png_ptr->do_filter & PNG_FILTER_PAETH)
{
png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
}
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* if interlaced, we need to set up width and height of pass */
if (png_ptr->interlaced)
{
@@ -1114,6 +1122,7 @@ png_write_start_row(png_structp png_ptr)
}
}
else
#endif
{
png_ptr->num_rows = png_ptr->height;
png_ptr->usr_width = png_ptr->width;
@@ -1136,6 +1145,7 @@ png_write_finish_row(png_structp png_ptr)
if (png_ptr->row_number < png_ptr->num_rows)
return;
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* if interlaced, go to next pass */
if (png_ptr->interlaced)
{
@@ -1177,6 +1187,7 @@ png_write_finish_row(png_structp png_ptr)
return;
}
}
#endif
/* if we get here, we've just written the last row, so we need
to flush the compressor */
@@ -1347,7 +1358,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
i += png_pass_inc[pass])
{
/* find out where the original pixel is */
sp = row + i * pixel_bytes;
sp = row + (png_size_t)i * pixel_bytes;
/* move the pixel */
if (dp != sp)
png_memcpy(dp, sp, pixel_bytes);
@@ -1362,9 +1373,8 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
png_pass_inc[pass] - 1 -
png_pass_start[pass]) /
png_pass_inc[pass];
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
}
}
#endif
@@ -1373,10 +1383,10 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
* been specified by the application, and then writes the row out with the
* chosen filter.
*/
#define PNG_MAXSUM (png_uint_32)(~0x0UL >> 1)
#define PNG_MAXSUM (~((png_uint_32)0) >> 1)
#define PNG_HISHIFT 10
#define PNG_LOMASK (png_uint_32)0xffffL
#define PNG_HIMASK (png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)
#define PNG_LOMASK ((png_uint_32)0xffffL)
#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
void
png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
@@ -1395,7 +1405,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
* smallest value when summing the absolute values of the distances
* from zero using anything >= 128 as negative numbers. This is known
* as the "minimum sum of absolute differences" heuristic. Other
* heruistics are the "weighted minumum sum of absolute differences"
* heuristics are the "weighted minumum sum of absolute differences"
* (experimental and can in theory improve compression), and the "zlib
* predictive" method (not implemented in libpng 0.95), which does test
* compressions of lines using different filter methods, and then chooses
@@ -1411,7 +1421,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp;
png_uint_32 sum = 0;
png_size_t i;
png_uint_32 i;
int v;
for (i = 0, rp = row_buf + 1; i < row_info->rowbytes; i++, rp++)
@@ -1428,7 +1438,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
/* Reduce the sum if we match any of the previous rows */
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_NONE)
{
@@ -1462,7 +1472,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, lp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1476,7 +1486,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
{
@@ -1506,7 +1516,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sum += (v < 128) ? v : 256 - v;
}
for (lp = row_buf + 1; i < row_info->rowbytes; i++, rp++, lp++, dp++)
for (lp = row_buf + 1; i < row_info->rowbytes;
i++, rp++, lp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
@@ -1523,7 +1534,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
{
@@ -1558,7 +1569,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1568,7 +1579,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
{
@@ -1592,7 +1603,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
pp = prev_row + 1; i < row_info->rowbytes; i++, rp++, pp++, dp++)
pp = prev_row + 1; i < row_info->rowbytes;
i++, rp++, pp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
@@ -1609,7 +1621,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_UP)
{
@@ -1644,7 +1656,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, lp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1654,7 +1666,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_AVG)
{
@@ -1737,7 +1749,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, cp, lp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1771,7 +1783,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
pp = prev_row + 1; (unsigned)i < bpp; i++, rp++, pp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
@@ -1849,9 +1861,9 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* Save the type of filter we picked this time for future calculations */
if (png_ptr->num_prev_filters > 0)
{
png_byte i;
int i;
for (i = 1; i < png_ptr->num_prev_filters; i++)
for (i = 1; i < (int)png_ptr->num_prev_filters; i++)
{
png_ptr->prev_filters[i] = png_ptr->prev_filters[i - 1];
}
@@ -1920,4 +1932,3 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
}
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
}

View File

@@ -29,7 +29,7 @@ libpng.a: $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest

View File

@@ -23,7 +23,7 @@ libpng.a: $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
coff2exe pngtest
test: pngtest

View File

@@ -34,8 +34,8 @@ libpng.a: ansi2knr $(OBJS)
ar rc $@ $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a ansi2knr
cc -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest

View File

@@ -1,6 +1,6 @@
# makefile for libpng on Linux ELF with gcc
# Copyright (C) 1996, 1997 Andreas Dilger
# Copyright (C) 1998 Glenn Randers-Pehrson
# Copyright (C) 1998 Greg Roelofs
# For conditions of distribution and use, see copyright notice in png.h
CC=gcc
@@ -21,8 +21,10 @@ LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -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 = 0.97
PNGMIN = 1.00
PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h
@@ -54,7 +56,7 @@ libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
libpng.so.$(PNGVER): $(OBJSDLL)
gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
$(CC) -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
$(OBJSDLL)
pngtest: pngtest.o libpng.so

View File

@@ -24,7 +24,7 @@ libpng.a: $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
cc -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest

View File

@@ -5,7 +5,7 @@
# ------------- Microsoft C 5.1 and later -------------
MODEL=-AL
CFLAGS=-Oait -Gs -nologo -W2 $(MODEL) -I..\zlib
CFLAGS=-Oait -Gs -nologo -W3 $(MODEL) -I..\zlib
#-Ox generates bad code with MSC 5.1
CC=cl
LD=link

69
scripts/makefile.os2 Normal file
View File

@@ -0,0 +1,69 @@
# makefile for libpng on OS/2 with gcc
# For conditions of distribution and use, see copyright notice in png.h
# Related files: pngos2.def
CC=gcc -Zomf -s
# Where the zlib library and include files are located
ZLIBLIB=../zlib
ZLIBINC=../zlib
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
-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
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lzdll -Zcrtdll
AR=emxomfar
PNGLIB=png.lib
IMPLIB=emximp
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
.SUFFIXES: .c .o
all: $(PNGLIB) $(SHAREDLIB) $(SHAREDLIBIMP)
$(PNGLIB): $(OBJS)
$(AR) rc $@ $(OBJS)
$(SHAREDLIB): $(OBJS) pngos2.def
$(CC) $(LDFLAGS) -Zdll -o $@ $^
$(SHAREDLIBIMP): pngos2.def
$(IMPLIB) -o $@ $^
pngtest.exe: pngtest.o png.dll pngdll.lib
$(CC) -o $@ $(CFLAGS) $< $(LDFLAGS)
test: pngtest.exe
./pngtest.exe
clean:
rm -f *.o $(PNGLIB) png.dll pngdll.lib pngtest.exe 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

98
scripts/makefile.s2x Normal file
View File

@@ -0,0 +1,98 @@
makefile for libpng on Solaris 2.x with gcc
# Contributed by William L. Sebok, based on makefile.lnx
# 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
# Where the zlib library and include files are located
ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
-Wmissing-declarations -Wtraditional -Wcast-align \
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
CFLAGS=-I$(ZLIBINC) -Wall -O3 \
#$(WARNMORE) -g -DPNG_DEBUG=5
LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng -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.00
PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h
prefix=/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:.o=.pic.o)
.SUFFIXES: .c .o .pic.o
.c.pic.o:
$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
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
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
libpng.so.$(PNGVER): $(OBJSDLL)
$(LD) -G -L$(LIBPATH) -R$(LIBPATH) -h libpng.so.$(PNGMAJ) \
-o libpng.so.$(PNGVER) $(OBJSDLL) -lz
pngtest: pngtest.o libpng.so
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
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

69
scripts/makefile.sgi Normal file
View File

@@ -0,0 +1,69 @@
# makefile for libpng
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
# For conditions of distribution and use, see copyright notice in png.h
# Where the zlib library and include files are located
#ZLIBLIB=/usr/local/lib
#ZLIBINC=/usr/local/include
ZLIBLIB=../zlib
ZLIBINC=../zlib
CC=cc
CFLAGS=-I$(ZLIBINC) -O -fullwarn # -g -DPNG_DEBUG=1
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
libpng.a: $(OBJS)
ar rc $@ $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CFLAGS) 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

View File

@@ -29,7 +29,7 @@ libpng.a: $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest

View File

@@ -33,7 +33,7 @@ libpng.a: $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest

View File

@@ -1,7 +1,7 @@
# Makefile for libpng
# TurboC++ 3.0 (Note: All modules are compiled in C mode)
# To use, do "make -fmakefile.tc"
# To use, do "make -fmakefile.tc3"
# ------------- Turbo C++ 3.0 -------------
MODEL=-ml
@@ -9,18 +9,22 @@ CFLAGS=-O2 -Z $(MODEL) -I..\zlib
CC=tcc
LD=tcc
LIB=tlib
LDFLAGS=$(MODEL)
LDFLAGS=$(MODEL) -L..\zlib
O=.obj
E=.exe
# variables
OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)
OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O)
pngwutil$(O)
OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)
OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
OBJSL1 = +png$(O) +pngset$(O) +pngget$(O) +pngrutil$(O) +pngtrans$(O)
OBJSL2 = +pngwutil$(O) +pngmem$(O) +pngpread$(O) +pngread$(O) +pngerror$(O)
OBJSL3 = +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O) +pngwio$(O)
OBJSL2 = +pngwutil$(O) +pngmem$(O) +pngpread$(O) +pngread$(O)
+pngerror$(O)
OBJSL3 = +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O)
+pngwio$(O)
all: libpng.lib
all: libpng.lib pngtest.exe
png$(O): png.h pngconf.h
$(CC) -c $(CFLAGS) $*.c
@@ -75,4 +79,7 @@ libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
$(LIB) libpng +$(OBJSL2)
$(LIB) libpng +$(OBJSL3)
# End of makefile for libpng
pngtest$(E): pngtest$(O) libpng.lib
$(CC) $(LDFLAGS) pngtest.obj libpng.lib zlib.lib
# End of makefile for libpng

88
scripts/makefile.wat Normal file
View File

@@ -0,0 +1,88 @@
# Makefile for libpng
# Watcom 10a+ 32-bit protected mode flat memory model
# Adapted by Pawel Mrochen, based on makefile.msc
# 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
# To use, do "wmake -f makefile.wat"
# ------------- Watcom 10a+ -------------
MODEL=-mf
CFLAGS= $(MODEL) -fpi87 -fp5 -5r -oaeilmnrt -s -i=..\zlib
CC=wcc386
LD=wcl386
LIB=wlib -b -c
LDFLAGS=
O=.obj
#uncomment next to put error messages in a file
#ERRFILE= >> pngerrs
# variables
OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)
OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)
OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
all: test
png$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngset$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngget$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngread$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngpread$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngrtran$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngrutil$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngerror$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngmem$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngrio$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngwio$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngtest$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngtrans$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngwrite$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngwtran$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
pngwutil$(O): png.h pngconf.h
$(CC) $(CFLAGS) $*.c $(ERRFILE)
libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
$(LIB) -n libpng.lib +$(OBJS1)
$(LIB) libpng.lib +$(OBJS2)
$(LIB) libpng.lib +$(OBJS3)
pngtest.exe: pngtest.obj libpng.lib
$(LD) $(LDFLAGS) pngtest.obj libpng.lib ..\zlib\zlib.lib
test: pngtest.exe
pngtest
# End of makefile for libpng

286
scripts/pngos2.def Normal file
View File

@@ -0,0 +1,286 @@
;----------------------------------------
; PNGLIB module definition file for OS/2
;----------------------------------------
LIBRARY PNG
DESCRIPTION "PNG image compression library for OS/2"
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
EXPORTS
png_set_sig_bytes
png_sig_cmp
png_check_sig
png_create_read_struct
png_create_write_struct
png_write_chunk
png_write_chunk_start
png_write_chunk_data
png_write_chunk_end
png_create_info_struct
png_info_init
png_write_info
png_read_info
png_convert_to_rfc1123
png_convert_from_struct_tm
png_convert_from_time_t
png_set_expand
png_set_bgr
png_set_gray_to_rgb
; png_set_rgb_to_gray
png_build_grayscale_palette
png_set_strip_alpha
png_set_swap_alpha
png_set_invert_alpha
png_set_filler
png_set_swap
png_set_packing
png_set_packswap
png_set_shift
png_set_interlace_handling
png_set_invert_mono
png_set_background
png_set_strip_16
png_set_dither
png_set_gamma
png_set_flush
png_write_flush
png_start_read_image
png_read_update_info
png_read_rows
png_read_row
png_read_image
png_write_row
png_write_rows
png_write_image
png_write_end
png_read_end
png_destroy_info_struct
png_destroy_read_struct
png_read_destroy
png_destroy_write_struct
; png_write_destroy_info
png_write_destroy
png_set_crc_action
png_set_filter
png_set_filter_heuristics
png_set_compression_level
png_set_compression_mem_level
png_set_compression_strategy
png_set_compression_window_bits
png_set_compression_method
png_init_io
png_set_error_fn
png_get_error_ptr
png_set_write_fn
png_set_read_fn
png_set_write_status_fn
png_set_read_status_fn
png_get_io_ptr
png_set_progressive_read_fn
png_set_read_status_fn
png_set_read_user_transform_fn
png_set_write_status_fn
png_set_write_user_transform_fn
png_get_progressive_ptr
png_process_data
png_progressive_combine_row
png_malloc
png_free
png_memcpy_check
png_memset_check
; png_debug_malloc
; png_debug_free
; png_far_to_near
png_error
png_chunk_error
png_warning
png_chunk_warning
png_get_valid
png_get_rowbytes
png_get_channels
png_get_image_width
png_get_image_height
png_get_bit_depth
png_get_color_type
png_get_filter_type
png_get_interlace_type
png_get_compression_type
png_get_pixels_per_meter
png_get_pixel_aspect_ratio
png_get_x_offset_pixels
png_get_y_offset_pixels
png_get_x_offset_microns
png_get_y_offset_microns
png_get_signature
png_get_bKGD
png_set_bKGD
png_get_cHRM
png_set_cHRM
png_get_gAMA
png_set_gAMA
png_get_hIST
png_set_hIST
png_get_IHDR
png_set_IHDR
png_get_oFFs
png_set_oFFs
png_get_pCAL
png_set_pCAL
png_get_pHYs
png_set_pHYs
png_get_PLTE
png_set_PLTE
png_get_sBIT
png_set_sBIT
png_get_sRGB
png_set_sRGB
png_set_sRGB_gAMA_and_cHRM
png_get_text
png_set_text
png_get_tIME
png_set_tIME
png_get_tRNS
png_set_tRNS
png_create_struct
png_destroy_struct
png_info_destroy
png_zalloc
png_zfree
png_reset_crc
png_write_data
png_read_data
png_crc_read
png_crc_finish
png_crc_error
png_calculate_crc
png_flush
png_save_uint_32
png_save_int_32
png_save_uint_16
png_write_sig
png_write_IHDR
png_write_PLTE
png_write_IDAT
png_write_IEND
png_write_gAMA
png_write_sBIT
png_write_cHRM
png_write_sRGB
png_write_tRNS
png_write_bKGD
png_write_hIST
png_check_keyword
png_write_tEXt
png_write_zTXt
png_write_oFFs
png_write_pCAL
png_write_pHYs
png_write_tIME
png_write_finish_row
png_write_start_row
png_build_gamma_table
png_combine_row
png_do_read_interlace
png_do_write_interlace
png_read_filter_row
png_write_find_filter
png_write_filtered_row
png_read_finish_row
png_read_start_row
png_read_transform_info
png_do_read_filler
png_do_read_swap_alpha
png_do_write_swap_alpha
png_do_read_invert_alpha
png_do_write_invert_alpha
png_do_strip_filler
png_do_swap
png_do_packswap
; png_do_rgb_to_gray
png_do_gray_to_rgb
png_do_unpack
png_do_unshift
png_do_invert
png_do_chop
png_do_dither
; png_correct_palette
png_do_bgr
png_do_pack
png_do_shift
png_do_background
png_do_gamma
png_do_expand_palette
png_do_expand
png_handle_IHDR
png_handle_PLTE
png_handle_IEND
png_handle_gAMA
png_handle_sBIT
png_handle_cHRM
png_handle_sRGB
png_handle_tRNS
png_handle_bKGD
png_handle_hIST
png_handle_oFFs
png_handle_pCAL
png_handle_pHYs
png_handle_tIME
png_handle_tEXt
png_handle_zTXt
png_handle_unknown
png_check_chunk_name
png_do_read_transformations
png_do_write_transformations
png_init_read_transformations
png_push_read_chunk
png_push_read_sig
; png_push_check_crc
png_push_crc_skip
png_push_crc_finish
png_push_fill_buffer
png_push_save_buffer
png_push_restore_buffer
png_push_read_IDAT
png_process_IDAT_data
png_push_process_row
png_push_handle_unknown
png_push_have_info
png_push_have_end
png_push_have_row
; png_push_read_end
png_process_some_data
png_read_push_finish_row
png_push_handle_tEXt
png_push_read_tEXt
png_push_handle_zTXt
png_push_read_zTXt
png_libpng_ver
png_pass_start
png_pass_inc
png_pass_ystart
png_pass_yinc
png_pass_mask
png_pass_dsp_mask
; png_pass_width
; png_pass_height
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