Compare commits

...

7 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
98c9d73605 Imported from libpng-1.0.6j.tar 2009-04-06 16:05:04 -05:00
Glenn Randers-Pehrson
6942d53c25 Imported from libpng-1.0.6i.tar 2009-04-06 16:05:02 -05:00
Glenn Randers-Pehrson
326320e5a9 Imported from libpng-1.0.6h.tar 2009-04-06 16:05:01 -05:00
Glenn Randers-Pehrson
228bd390ac Imported from libpng-1.0.6g.tar 2009-04-06 16:04:59 -05:00
Glenn Randers-Pehrson
4accabb590 Imported from libpng-1.0.6f.tar 2009-04-06 16:04:58 -05:00
Glenn Randers-Pehrson
38e6e77419 Imported from libpng-1.0.6e.tar 2009-04-06 16:04:56 -05:00
Glenn Randers-Pehrson
81fdf8aca1 Imported from libpng-1.0.6d.tar 2009-04-06 16:04:55 -05:00
46 changed files with 1901 additions and 618 deletions

View File

@@ -1,12 +1,12 @@
Libpng 1.0.6a - April 2, 2000
Libpng 1.0.6j - May 4, 2000
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
Changes since the last public release (1.0.6):
version 1.0.6a [April 2, 2000]
version 1.0.6d [April 8, 2000]
Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO
Added data_length parameter to png_decompress_chunk() function
Revised documentation to remove reference to abandoned png_free_chnk functions
@@ -15,6 +15,55 @@ version 1.0.6a [April 2, 2000]
Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file
Added a check for info_ptr->free_me&PNG_FREE_TEXT when free'ing text in png.c
Simplify png_sig_bytes() function to remove use of non-ISO-C strdup().
version 1.0.6e [April 9, 2000]
Added png_data_freer() function.
In the code that checks for over-length tRNS chunks, added check of
info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann)
Minor revisions of libpng.txt/libpng.3.
Check for existing data and free it if the free_me flag is set, in png_set_*()
and png_handle_*().
Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED
is defined.
Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c
and mentioned the purposes of the two macros in libpng.txt/libpng.3.
version 1.0.6f [April 14, 2000]
Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data.
Add checks in png_set_text() for NULL members of the input text structure.
Revised libpng.txt/libpng.3.
Removed superfluous prototype for png_set_itxt from png.h
Removed "else" from pngread.c, after png_error(), and changed "0" to "length".
Changed several png_errors about malformed ancillary chunks to png_warnings.
version 1.0.6g [April 24, 2000]
Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined.
Relocated paragraph about png_set_background() in libpng.3/libpng.txt
and other revisions (Matthias Benckmann)
Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and
png_ptr members to restore binary compatibility with libpng-1.0.5
(breaks compatibility with libpng-1.0.6).
version 1.0.6h [April 24, 2000]
Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds
libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h)
This is a temporary change for test purposes.
version 1.0.6i [May 3, 2000]
Added documentation of user memory functions in libpng.txt/libpng.3
Modified png_read_png so that it will use user_allocated row_pointers
if present, unless free_me directs that it be freed, and added description
of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3.
Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version
1.00) members of png_struct and png_info, to regain binary compatibility
when you define this macro. Capabilities lost in this event
are user transforms (new in version 1.0.0),the user transform pointer
(new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT,
the high-level interface, and unknown chunks support (all new in 1.0.6).
This was necessary because of old applications that allocate the structs
directly instead of using png_create_*(), as authors were instructed to
do in libpng-0.88 and earlier.
Added makefile.intel and updated makefile.watcom (Pawel Mrochen)
version 1.0.6j [May 4, 2000]
Overloaded png_read_init() and png_write_init() with macros that convert
calls to png_read_init_2() or png_write_init_2() that check the version
and structure sizes.
Restored original shared library so-number pattern (2.x.y.z)
Send comments/corrections/commendations to
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu

63
CHANGES
View File

@@ -123,6 +123,7 @@ version 0.90 [January, 1997]
- all chunk handling routines have the same prototypes, so we will
be able to handle all chunks via a callback mechanism
try to fix Linux "setjmp" buffer size problems
removed png_large_malloc, png_large_free, and png_realloc functions.
version 0.95 [March, 1997]
fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
fixed bug in PNG file signature compares when start != 0
@@ -259,6 +260,7 @@ 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
Added user transform capability
version 1.00 [March 7, 1998]
Changed several typedefs in pngrutil.c
Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)
@@ -660,7 +662,7 @@ version 1.0.5v [March 11, 2000]
version 1.0.6 [March 20, 2000]
Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c
Added makefile.sggcc (SGI IRIX with gcc)
version 1.0.6a [April 2, 2000]
version 1.0.6d [April 7, 2000]
Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO
Added data_length parameter to png_decompress_chunk() function
Revised documentation to remove reference to abandoned png_free_chnk functions
@@ -669,6 +671,65 @@ version 1.0.6a [April 2, 2000]
Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file
Added a check for info_ptr->free_me&PNG_FREE_TEXT when free'ing text in png.c
Simplify png_sig_bytes() function to remove use of non-ISO-C strdup().
version 1.0.6e [April 9, 2000]
Added png_data_freer() function.
In the code that checks for over-length tRNS chunks, added check of
info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann)
Minor revisions of libpng.txt/libpng.3.
Check for existing data and free it if the free_me flag is set, in png_set_*()
and png_handle_*().
Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED
is defined.
Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c
and mentioned the purposes of the two macros in libpng.txt/libpng.3.
version 1.0.6f [April 14, 2000]
Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data.
Add checks in png_set_text() for NULL members of the input text structure.
Revised libpng.txt/libpng.3.
Removed superfluous prototype for png_set_itxt from png.h
Removed "else" from pngread.c, after png_error(), and changed "0" to "length".
Changed several png_errors about malformed ancillary chunks to png_warnings.
version 1.0.6g [April 24, 2000]
Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined.
Relocated paragraph about png_set_background() in libpng.3/libpng.txt
and other revisions (Matthias Benckmann)
Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and
png_ptr members to restore binary compatibility with libpng-1.0.5
(breaks compatibility with libpng-1.0.6).
version 1.0.6h [April 24, 2000]
Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds
libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h)
This is a temporary change for test purposes.
version 1.0.6i [May 2, 2000]
Rearranged some members at the end of png_info and png_struct, to put
unknown_chunks_num and free_me within the original size of the png_structs
and free_me, png_read_user_fn, and png_free_fn within the original png_info,
because some old applications allocate the structs directly instead of
using png_create_*().
Added documentation of user memory functions in libpng.txt/libpng.3
Modified png_read_png so that it will use user_allocated row_pointers
if present, unless free_me directs that it be freed, and added description
of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3.
Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version
1.00) members of png_struct and png_info, to regain binary compatibility
when you define this macro. Capabilities lost in this event
are user transforms (new in version 1.0.0),the user transform pointer
(new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT,
the high-level interface, and unknown chunks support (all new in 1.0.6).
This was necessary because of old applications that allocate the structs
directly instead of using png_create_*(), as authors were instructed to
do in libpng-0.88 and earlier.
Added modes PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT which
can be used to detect codes that directly allocate the structs, and
code to check these modes in png_read_init() and png_write_init() and
generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED
was not defined.
Added makefile.intel and updated makefile.watcom (Pawel Mrochen)
version 1.0.6j [May 4, 2000]
Overloaded png_read_init() and png_write_init() with macros that convert
calls to png_read_init_2() or png_write_init_2() that check the version
and structure sizes.
Send comments/corrections/commendations to
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu

12
INSTALL
View File

@@ -1,5 +1,5 @@
Installing libpng version 1.0.6a - April 2, 2000
Installing libpng version 1.0.6j - May 4, 2000
Before installing libpng, you must first install zlib. zlib
can usually be found wherever you got libpng. zlib can be
@@ -10,7 +10,7 @@ zlib.h and zconf.h include files that correspond to the
version of zlib that's installed.
You can rename the directories that you downloaded (they
might be called "libpng-1.0.6a" or "lpng106" and "zlib-1.1.3"
might be called "libpng-1.0.6j" or "lpng106" and "zlib-1.1.3"
or "zlib113") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this:
@@ -47,8 +47,8 @@ The files that are presently available in the scripts directory
include
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.6a)
makefile.gcmmx => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.6a,
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.6j)
makefile.gcmmx => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.6j,
uses assembler code tuned for Intel MMX platform)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
@@ -59,9 +59,9 @@ include
makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
libpng.icc => Project file for IBM VisualAge/C++ version 4.0 or later
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
makefile.sggcc => Silicon Graphics (gcc, creates libpng.so.2.1.0.6a)
makefile.sggcc => Silicon Graphics (gcc, creates libpng.so.2.1.0.6j)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.6a)
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.6j)
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
makefile.mips => MIPS makefile
makefile.acorn => Acorn makefile

View File

@@ -1,47 +1,97 @@
Known bugs and suggested enhancements in libpng-1.0.6
1. April 1, 2000 -- BUG
1. April 24, 2000 -- BUG -- binary incompatibility
Libpng-1.0.6 is binary incompatible with old applications that
allocate the png_struct and png_info structures themselves instead
of using png_create_*(). They do not allocate enough space for
the structures because they have an incorrect notion of
sizeof(png_struct) and sizeof(png_info). Although such applications
should be considered broken rather than considering libpng to be broken,
they are numerous and include products of the PNG group, such
as gif2png and pnmtopng-2.36 (pnmtopng-2.37 is OK), so libpng will
be fixed in version 1.0.7 to work around this problem.
Applications that use png_create_*() instead of png_ptr=malloc(...)
are immune to this problem.
STATUS: Fixed in libpng-1.0.6ad, libpng-1.0.6j, and patch-d
which are currently being tested by the PNG group.
The fix necessarily reintroduces a binary incompatibility with any
application that makes direct access to the png_info and
png_struct members that deal with the pCAL chunk, palette_lookup,
dither_index, time_buffer, or weighted filtering, i.e., any members
coming after the new "free_me" member of either structure. It
is believed that applications affected by this reintroduced binary
incompatibility are rare (none are known to the PNG group). An
effective workaround for this and the next bug is to recompile the
old applications with the installed version of libpng.
2. April 23, 2000 -- BUG -- binary incompatibility
Libpng-1.0.6 introduced binary incompatibility for applications that
make direct access to members of the png_struct and png_info structures,
due to the insertion of the free_me member ahead of some previously
existing members.
Applications that use png_set_*(), png_get_*() are immune to this
problem, but people are still to this day writing applications that
make ill-advised direct access to members of the png_struct and
png_info structures, so libpng-1.0.6 will be patched to work around
this problem.
STATUS: Fixed in libpng-1.0.6j and patch-d, which are currently being
tested by the PNG group. Users can work around the problem without
patching libpng by recompiling their applications.
3. April 15, 2000 -- BUG -- pnggccrd.c
If PNG_NO_GLOBAL_ARRAYS is defined, pnggccrd.c will not compile.
STATUS: Fixed in libpng-1.0.6g
4. April 1, 2000 -- BUG
Under some circumstances old applications that make direct access to
the info_ptr->text and its members might free the same memory that
is also free'ed by libpng during the png_destroy_struct process.
Fixed in libpng-1.0.6-patch-c and libpng-1.0.6a. The PNG_FREE_TEXT flag
Fixed in libpng-1.0.6-patch-c and libpng-1.0.6d. The PNG_FREE_TEXT flag
bit in info_ptr->free_me is now checked to make sure libpng is responsible
for freeing the memory.
2. April 1, 2000 -- BUG
5. April 1, 2000 -- BUG
The non-ISO-C "strdup()" function is used in png.c
STATUS: The function has been simplified and no longer uses strdup()
in libpng-1.0.6-patch-c and libpng-1.0.6a.
in libpng-1.0.6-patch-c and libpng-1.0.6d.
3. March 24, 2000 -- BUG
6. March 24, 2000 -- BUG
The png_set_rgb_to_gray_fixed() function is setting incorrect weighting
factors.
STATUS: Fixed in libpng-1.0.6-patch-b and libpng-1.0.6a.
STATUS: Fixed in libpng-1.0.6-patch-b and libpng-1.0.6d.
4. March 22, 2000 -- BUG
7. March 22, 2000 -- BUG
There are some printf() and fprintf() statements active in pngwutil.c
when PNG_NO_STDIO and PNG_sCAL_SUPPORTED are both defined.
STATUS: Fixed in libpng-1.0.6-patch-a and libpng-1.0.6a. The strcpy()
STATUS: Fixed in libpng-1.0.6-patch-a and libpng-1.0.6d. The strcpy()
function is used instead.
5. March 22, 2000 -- BUG
8. March 22, 2000 -- BUG
The length of the iCCP chunk data is calculated incorrectly; because
it can contain zeroes, strlen() doesn't work.
STATUS: Fixed in libpng-1.0.6-patch-a by adding a data_length parameter
to the png_decompress_chunk() function.
STATUS: Fixed in libpng-1.0.6-patch-a and libpng-1.0.6d by adding a
data_length parameter to the png_decompress_chunk() function.
6. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
9. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
Loops need to be optimized everywhere
@@ -56,7 +106,7 @@ Known bugs and suggested enhancements in libpng-1.0.6
libpng-1.1.0. About 160 loops will be turned around
in libpng-1.1.Nn, for testing.
7. July 4, 1998 -- ENHANCEMENT -- Glenn R-P
10. July 4, 1998 -- ENHANCEMENT -- Glenn R-P
libpng-1.0.5 and earlier transform colors to gamma=1.0 space for
merging with background, and then back to the image's gamma. The
@@ -68,12 +118,12 @@ Known bugs and suggested enhancements in libpng-1.0.6
STATUS: under development.
8. September 1999 -- ENHANCEMENT --
11. September 1999 -- ENHANCEMENT --
It should be possible to use libpng without floating-point aritmetic.
STATUS: Under investigation, implementation postponed until after
libpng-1.0.5. The application interface will change because replacements
libpng-1.0.6. The application interface will change because replacements
for the png_set_gAMA(), png_set_cHRM(), and corresponding png_get_()
functions will be needed.

View File

@@ -5,7 +5,7 @@ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Copyright (c) 1996, 1997 Andreas Dilger
(libpng versions 0.90, December 1996, through 0.96, May 1997)
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
(libpng versions 0.97, January 1998, through 1.0.6a, April 2, 2000)
(libpng versions 0.97, January 1998, through 1.0.6j, May 4, 2000)
For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:
@@ -68,4 +68,4 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
randeg@alum.rpi.edu
April 2, 2000
May 4, 2000

10
README
View File

@@ -1,4 +1,4 @@
README for libpng 1.0.6a - April 2, 2000 (shared library 2.1)
README for libpng 1.0.6j - May 4, 2000 (shared library 2.1)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
@@ -172,9 +172,9 @@ Files in this distribution:
descrip.mms => VMS makefile for MMS or MMK
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.linux => Linux/ELF makefile
(gcc, creates libpng.so.2.1.0.6a)
(gcc, creates libpng.so.2.1.0.6j)
makefile.gcmmx => Linux/ELF makefile (gcc, creates
libpng.so.2.1.0.6a, uses assembler code
libpng.so.2.1.0.6j, uses assembler code
tuned for Intel MMX platform)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
@@ -185,10 +185,10 @@ Files in this distribution:
makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
libpng.icc => Project file, IBM VisualAge/C++ 4.0 or later
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
makefile.sggcc => Silicon Graphics (gcc, creates libpng.so.2.1.0.6a)
makefile.sggcc => Silicon Graphics (gcc, creates libpng.so.2.1.0.6j)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile
(gcc, creates libpng.so.2.1.0.6a)
(gcc, creates libpng.so.2.1.0.6j)
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
makefile.mips => MIPS makefile
makefile.acorn => Acorn makefile

View File

@@ -1,13 +1,13 @@
Y2K compliance in libpng:
=========================
April 2, 2000
May 4, 2000
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.0.6a are Y2K compliant. It is my belief that earlier
upward through 1.0.6j are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer

2
configure vendored
View File

@@ -1,5 +1,5 @@
echo "
There is no \"configure\" script for Libpng-1.0.6a. Instead, please
There is no \"configure\" script for Libpng-1.0.6j. Instead, please
copy the appropriate makefile for your system from the \"scripts\"
directory. Read the INSTALL file for more details.
"

View File

@@ -1,52 +0,0 @@
# Makefile for PngMinus (png2pnm and pnm2png)
# Linux / Unix
CC=cc -O -n32
LD=cc -O -n32
#CC=gcc -O
#LD=gcc -O
LB=ar
RM=rm
CP=cp
PNGPATH = /usr/local
PNGINC = $(PNGPATH)/include
PNGLIB = $(PNGPATH)/lib -lpng
# PNGLIB = $(PNGPATH)/libpng.a
ZPATH = /usr/local
ZINC = $(ZPATH)/include
ZLIB = $(ZPATH)/lib -lz
# ZLIB = $(ZPATH)/libz.a
CCFLAGS=-I$(PNGINC) -I$(ZINC)
LDFLAGS=-L$(PNGLIB) -L$(ZLIB) -lm
C=.c
O=.o
L=.a
E=
# dependencies
all: png2pnm$(E) pnm2png$(E)
png2pnm$(O): png2pnm$(C)
$(CC) -c $(CCFLAGS) png2pnm$(C)
png2pnm$(E): png2pnm$(O)
$(LD) -o png2pnm$(E) png2pnm$(O) $(LDFLAGS)
pnm2png$(O): pnm2png$(C)
$(CC) -c $(CCFLAGS) pnm2png$(C)
pnm2png$(E): pnm2png$(O)
$(LD) -o pnm2png$(E) pnm2png$(O) $(LDFLAGS)
clean:
$(RM) png2pnm$(O)
$(RM) pnm2png$(O)
$(RM) png2pnm$(E)
$(RM) pnm2png$(E)
# End of makefile for png2pnm / pnm2png

View File

@@ -307,7 +307,8 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
}
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
png_set_bgr(png_ptr);
if (color_type & PNG_COLOR_MASK_COLOR)
png_set_bgr(png_ptr);
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
png_set_swap_alpha(png_ptr);

456
libpng.3
View File

@@ -1,6 +1,6 @@
.TH LIBPNG 3 "April 2, 2000"
.TH LIBPNG 3 "May 4, 2000"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6a
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6j
.SH SYNOPSIS
\fI\fB
@@ -234,7 +234,7 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6a
\fI\fB
\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fI*splt_ptr\fP\fB, int \fInum\fP\fB);\fP
\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
\fI\fB
@@ -294,6 +294,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6a
\fI\fB
\fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP
\fI\fB
\fBvoid png_info_init (png_infop \fIinfo_ptr\fP\fB);\fP
\fI\fB
@@ -614,6 +618,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6a
\fI\fB
\fBvoid png_set_unknown_chunk_location(png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP
\fI\fB
\fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP
\fI\fB
@@ -634,6 +642,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6a
\fI\fB
\fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
\fI\fB
\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP
\fI\fB
@@ -713,7 +725,7 @@ Following is a copy of the libpng.txt file that accompanies libpng.
.SH LIBPNG.TXT
libpng.txt - A description on how to use and modify libpng
libpng version 1.0.6a - April 2, 2000
libpng version 1.0.6j - May 4, 2000
Updated and distributed by Glenn Randers-Pehrson
<randeg@alum.rpi.edu>
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -831,10 +843,10 @@ You will want to do the I/O initialization(*) before you get into libpng,
so if it doesn't work, you don't have much to undo. Of course, you
will also want to insure that you are, in fact, dealing with a PNG
file. Libpng provides a simple check to see if a file is a PNG file.
To use it, pass in the first 1 to 8 bytes of the file, and it will
return true or false (1 or 0) depending on whether the bytes could be
part of a PNG file. Of course, the more bytes you pass in, the
greater the accuracy of the prediction.
To use it, pass in the first 1 to 8 bytes of the file to the function
png_sig_cmp(), and it will return 0 if the bytes match the corresponding
bytes of the PNG signature, or nonzero otherwise. Of course, the more bytes
you pass in, the greater the accuracy of the prediction.
If you are intending to keep the file pointer open for use in libpng,
you must ensure you don't read more than 8 bytes from the beginning
@@ -1050,14 +1062,39 @@ dithering, and setting filler.) If this is the case, simply do this:
png_read_png(png_ptr, info_ptr, png_transforms, NULL)
where png_transforms is an integer containing the logical-or of some set of
transformation flags. This call is equivalent to png_read_info(),
where png_transforms is an integer containing the logical OR of
some set of transformation flags. This call is equivalent to png_read_info(),
followed the set of transformations indicated by the transform mask,
followed by png_update_info(), followed by a read of the image bytes
to the info member `rowpointers', followed by png_read_end().
then png_read_image(), and finally png_read_end().
(The final parameter of this call is not yet used. Someday it
will point to transformation parameters.)
(The final parameter of this call is not yet used. Someday it might point
to transformation parameters required by some future input transform.)
After you have called png_read_png(), you can retrieve the image data
with
row_pointers = png_get_rows(png_ptr, info_ptr);
where row_pointers is an array of pointers to the pixel data for each row:
png_bytep row_pointers[height];
If you know your image size and pixel size ahead of time, you can allocate
row_pointers prior to calling png_read_png() with
row_pointers = png_malloc(png_ptr, height*sizeof(png_bytep));
for (int i=0; i<height, i++)
row_pointers[i]=png_malloc(png_ptr, width*pixel_size);
png_set_rows(png_ptr, info_ptr, &row_pointers);
Alternatively you could allocate your image in one big block and define
row_pointers[i] to point into the proper places in your block.
If you use png_set_rows(), the application is responsible for freeing
row_pointers (and row_pointers[i], if they were separately allocated).
If you don't allocate row_pointers ahead of time, png_read_png() will
do it, and it'll be free'ed when you call png_destroy_*().
.SS The low-level read interface
@@ -1112,8 +1149,8 @@ in until png_read_end() has read the chunk data following the image.
interlace_type - (PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7)
Any or all of interlace_type, compression_type, of
filter_type can be
NULL if you are not interested in their values.
filter_type can be NULL if you are not
interested in their values.
channels = png_get_channels(png_ptr, info_ptr);
channels - number of channels of info for the
@@ -1205,7 +1242,7 @@ into the info_ptr is returned for any complex types.
png_get_hIST(png_ptr, info_ptr, &hist);
(PNG_INFO_hIST)
hist - histogram of palette (array of
png_color_16)
png_uint_16)
png_get_tIME(png_ptr, info_ptr, &mod_time);
mod_time - time image was last modified
@@ -1221,26 +1258,34 @@ into the info_ptr is returned for any complex types.
num_comments - number of comments
text_ptr - array of png_text holding image
comments
text_ptr[i]->compression - type of compression used
text_ptr[i].compression - type of compression used
on "text" PNG_TEXT_COMPRESSION_NONE
PNG_TEXT_COMPRESSION_zTXt
PNG_ITXT_COMPRESSION_NONE
PNG_ITXT_COMPRESSION_zTXt
text_ptr[i]->key - keyword for comment.
text_ptr[i]->text - text comments for current
keyword.
text_ptr[i]->text_length - length of text string,
text_ptr[i].key - keyword for comment. Must contain
1-79 characters.
text_ptr[i].text - text comments for current
keyword. Can empty.
text_ptr[i].text_length - length of text string,
after decompression, 0 for iTXt
text_ptr[i]->itxt_length - length of itxt string,
text_ptr[i].itxt_length - length of itxt string,
after decompression, 0 for tEXt/zTXt
text_ptr[i]->lang - language of comment (NULL for unknown).
text_ptr[i]->translated_keyword - keyword in UTF-8 (NULL
for unknown).
text_ptr[i].lang - language of comment (empty
string for unknown).
text_ptr[i].translated_keyword - keyword in UTF-8
(empty string for unknown).
num_text - number of comments (same as num_comments;
you can put NULL here to avoid the duplication)
num_spalettes = png_get_spalettes(png_ptr, info_ptr, &palette_ptr);
palette_ptr - array of png_spalette structures holding contents
of one or more sPLT chunks read.
Note while png_set_text() will accept text, language, and
translated keywords that can be NULL pointers, the structure
returned by png_get_text will always contain regular
zero-terminated C strings. They might be empty strings but
they will never be NULL pointers.
num_spalettes = png_get_sPLT(png_ptr, info_ptr, &palette_ptr);
palette_ptr - array of palette structures holding
contents of one or more sPLT chunks read.
num_spalettes - number of sPLT chunks read.
png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
@@ -1261,9 +1306,16 @@ into the info_ptr is returned for any complex types.
PNG_RESOLUTION_METER
png_get_sCAL(png_ptr, info_ptr, &unit, &width, &height)
unit - physical scale units (a string)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are doubles)
png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, &height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
num_unknown_chunks = png_get_unknown_chunks(png_ptr, info_ptr,
&unknowns)
@@ -1271,9 +1323,12 @@ into the info_ptr is returned for any complex types.
unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk
unknowns[i].size - size of unknown chunk's data
unknowns[i].location - position of chunk in file
The value of "i" corresponds to the order in which the chunks were read
from the PNG file or inserted with the png_set_unknown_chunks() function.
The data from the pHYs chunk can be retrieved in several convenient
forms:
@@ -1283,6 +1338,12 @@ forms:
info_ptr)
res_x_and_y = png_get_pixels_per_meter(png_ptr,
info_ptr)
res_x = png_get_x_pixels_per_inch(png_ptr,
info_ptr)
res_y = png_get_y_pixels_per_inch(png_ptr,
info_ptr)
res_x_and_y = png_get_pixels_per_inch(png_ptr,
info_ptr)
aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
info_ptr)
@@ -1290,6 +1351,18 @@ forms:
the data is not present or if res_x is 0;
res_x_and_y is 0 if res_x != res_y)
The data from the oFFs chunk can be retrieved in several convenient
forms:
x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
(Each of these returns 0 [signifying "unknown" if both
x and y are 0] if the data is not present or if the chunk
is present but the unit is the pixel)
For more information, see the png_info definition in png.h and the
PNG specification for chunk contents. Be careful with trusting
rowbytes, as some of the transformations could increase the space
@@ -1310,7 +1383,8 @@ trailing spaces, but non-consecutive spaces are allowed within the
keyword. It is possible to have the same keyword any number of times.
The text_ptr is an array of png_text structures, each holding a
pointer to a language string, a pointer to a keyword and a pointer to
a text string. Only the text string may be null. The keyword/text
a text string. The text string, language code, and translated
keyword may be empty or NULL pointers. The keyword/text
pairs are put into the array in the order that they are received.
However, some or all of the text chunks may be after the image, so, to
make sure you have read all the text chunks, don't mess with these
@@ -1356,8 +1430,8 @@ transparency information in a tRNS chunk. This is most useful on
grayscale images with bit depths of 2 or 4 or if there is a multiple-image
viewing application that wishes to treat all images in the same way.
if (color_type == PNG_COLOR_TYPE_PALETTE &&
bit_depth <= 8) png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY &&
bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
@@ -1376,17 +1450,6 @@ PNG can have files with 16 bits per channel. If you only can handle
if (bit_depth == 16)
png_set_strip_16(png_ptr);
The png_set_background() function tells libpng to composite images
with alpha or simple transparency against the supplied background
color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
you may use this color, or supply another color more suitable for
the current display (e.g., the background color from a web page). You
need to tell libpng whether the color is in the gamma space of the
display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
know why anyone would use this, but it's here).
If, for some reason, you don't need the alpha channel on an image,
and you want to remove it rather than combining it with the background
(but the image author certainly had in mind that you *would* combine
@@ -1530,6 +1593,17 @@ or as an RGB triplet that may or may not be in the palette (need_expand = 0).
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
The png_set_background() function tells libpng to composite images
with alpha or simple transparency against the supplied background
color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
you may use this color, or supply another color more suitable for
the current display (e.g., the background color from a web page). You
need to tell libpng whether the color is in the gamma space of the
display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
know why anyone would use this, but it's here).
To properly display PNG images on any kind of system, the application needs
to know what the display gamma is. Ideally, the user will know this, and
the application will allow them to set it. One method of allowing the user
@@ -1726,10 +1800,10 @@ If you are doing this just one row at a time, you can do this with
a single row_pointer instead of an array of row_pointers:
png_bytep row_pointer = row;
png_read_row(png_ptr, row_pointers, NULL);
png_read_row(png_ptr, row_pointer, NULL);
If the file is interlaced (info_ptr->interlace_type != 0), things get
somewhat harder. The only current (PNG Specification version 1.2)
If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
get somewhat harder. The only current (PNG Specification version 1.2)
interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
is a somewhat complicated 2D interlace scheme, known as Adam7, that
breaks down an image into seven smaller images of varying size, based
@@ -1823,11 +1897,10 @@ point to libpng-allocated storage with the following functions:
png_free_data(png_ptr, info_ptr, mask, n)
mask - identifies data to be freed, a mask
made up by the OR one or more of
containing the logical OR of one or more of
PNG_FREE_PLTE, PNG_FREE_TRNS,
PNG_FREE_HIST, PNG_FREE_ICCP,
PNG_FREE_SPLT, PNG_FREE_ROWS,
PNG_FREE_PCAL, PNG_FREE_SCAL,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
n - sequence number of item to be freed
@@ -1839,7 +1912,34 @@ by the user and not by libpng, and will in those
cases do nothing. The "n" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "n" is not
-1, and multiple items are allowed for the data type identified in
the mask, such as text or splt, only the n'th item is freed.
the mask, such as text or sPLT, only the n'th item is freed.
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
mask - which data elements are affected
same choices as in png_free_data()
freer - one of
PNG_DESTROY_WILL_FREE_DATA
PNG_SET_WILL_FREE_DATA
PNG_USER_WILL_FREE_DATA
This function only affects data that has already been allocated.
You can call this function after reading the PNG data but before calling
any png_set_*() functions, to control whether the user or the png_set_*()
function is responsible for freeing any existing data that might be present,
and again after the png_set_*() functions to control whether the user
or png_destroy_*() is supposed to free the data. When the user assumes
responsibility for libpng-allocated data, the application must use
png_free() to free it.
If you allocated your row_pointers in a single block, as suggested above in
the description of the high level read interface, you must not transfer
responsibility for freeing it to the png_set_rows or png_read_destroy function,
because they would also try to free the individual row_pointers[i].
For a more compact example of reading a PNG image, see the file example.c.
@@ -2057,7 +2157,7 @@ both "png_ptr"; you can call them anything you like, such as
If you want to use your own memory allocation routines,
define PNG_USER_MEM_SUPPORTED and use
png_create_write_struct_2() instead of png_create_read_struct():
png_create_write_struct_2() instead of png_create_write_struct():
png_structp png_ptr = png_create_write_struct_2
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
@@ -2126,21 +2226,33 @@ speed/compression ratio. The second parameter to png_set_filter() is
the filter method, for which the only valid value is '0' (as of the
July 1999 PNG specification, version 1.2). The third parameter is a
flag that indicates which filter type(s) are to be tested for each
scanline. See the Compression Library for details on the specific filter
scanline. See the PNG specification for details on the specific filter
types.
/* turn on or off filtering, and/or choose
specific filters */
specific filters. You can use either a single PNG_FILTER_VALUE_NAME
or the logical OR of one or more PNG_FILTER_NAME masks. */
png_set_filter(png_ptr, 0,
PNG_FILTER_NONE | PNG_FILTER_SUB |
PNG_FILTER_PAETH);
PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
PNG_FILTER_AVE | PNG_FILTER_VALUE_AVE |
PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
PNG_ALL_FILTERS);
If an application
wants to start and stop using particular filters during compression,
it should start out with all of the filters (to ensure that the previous
row of pixels will be stored in case it's needed later), and then add
and remove them after the start of compression.
The png_set_compression_*() functions interface to the zlib compression
library, and should mostly be ignored unless you really know what you are
doing. The only generally useful call is png_set_compression_level()
which changes how much time zlib spends on trying to compress the image
data. See the Compression Library for details on the compression levels.
data. See the Compression Library (zlib.h and algorithm.txt, distributed
with zlib) for details on the compression levels.
/* set the zlib compression level */
png_set_compression_level(png_ptr,
@@ -2152,6 +2264,9 @@ data. See the Compression Library for details on the compression levels.
Z_DEFAULT_STRATEGY);
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
png_set_compression_buffer_size(png_ptr, 8192)
extern PNG_EXPORT(void,png_set_zbuf_size)
.SS Setting the contents of info for output
@@ -2272,7 +2387,7 @@ Some of the more important parts of the png_info are:
png_set_hIST(png_ptr, info_ptr, hist);
(PNG_INFO_hIST)
hist - histogram of palette (array of
png_color_16)
png_uint_16)
png_set_tIME(png_ptr, info_ptr, mod_time);
mod_time - time image was last modified
@@ -2284,26 +2399,29 @@ Some of the more important parts of the png_info are:
png_set_text(png_ptr, info_ptr, text_ptr, num_text);
text_ptr - array of png_text holding image
comments
text_ptr[i]->compression - type of compression used
text_ptr[i].compression - type of compression used
on "text" PNG_TEXT_COMPRESSION_NONE
PNG_TEXT_COMPRESSION_zTXt
PNG_ITXT_COMPRESSION_NONE
PNG_ITXT_COMPRESSION_zTXt
text_ptr[i]->key - keyword for comment.
text_ptr[i]->text - text comments for current
keyword.
text_ptr[i]->text_length - length of text string,
text_ptr[i].key - keyword for comment. Must contain
1-79 characters.
text_ptr[i].text - text comments for current
keyword. Can be NULL or empty.
text_ptr[i].text_length - length of text string,
after decompression, 0 for iTXt
text_ptr[i]->itxt_length - length of itxt string,
text_ptr[i].itxt_length - length of itxt string,
after decompression, 0 for tEXt/zTXt
text_ptr[i]->lang - language of comment (NULL for unknown).
text_ptr[i]->translated_keyword - keyword in UTF-8 (NULL
for unknown).
text_ptr[i].lang - language of comment (NULL or
empty for unknown).
text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
or empty for unknown).
num_text - number of comments
png_set_spalettes(png_ptr, info_ptr, &palette_ptr, num_spalettes);
palette_ptr - array of png_spalette structures to be added to
the list of palettes in the info structure.
png_set_sPLT(png_ptr, info_ptr, &palette_ptr, num_spalettes);
palette_ptr - array of png_sPLT_struct structures to be
added to the list of palettes in the info
structure.
num_spalettes - number of palette structures to be added.
png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
@@ -2324,16 +2442,23 @@ Some of the more important parts of the png_info are:
PNG_RESOLUTION_METER
png_set_sCAL(png_ptr, info_ptr, unit, width, height)
unit - physical scale units (a string)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are doubles)
png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, num_unknowns)
unknowns - array of png_unknown_chunk structures holding
unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk
unknowns[i].size - size of unknown chunk's data
unknowns[i].location - position to write chunk in file
0: do not write chunk
PNG_HAVE_IHDR: before PLTE
@@ -2342,22 +2467,25 @@ Some of the more important parts of the png_info are:
The "location" member is set automatically according to
what part of the output file has already been written.
You can change its value after calling png_set_unknown_chunks()
as demonstrated in pngtest.c.
as demonstrated in pngtest.c. Within each of the "locations",
the chunks are sequenced according to their position in the
structure (that is, the value of "i", which is the order in which
the chunk was either read from the input file or defined with
png_set_unknown_chunks).
A quick word about text and num_text. text is an array of png_text
structures. num_text is the number of valid structures in the array.
If you want, you can use max_text to hold the size of the array, but
libpng ignores it for writing (it does use it for reading). Each
png_text structure holds a language code, a keyword, a text value, and
a compression type.
Each png_text structure holds a language code, a keyword, a text value,
and a compression type.
The compression types have the same valid numbers as the compression
types of the image data. Currently, the only valid number is zero.
However, you can store text either compressed or uncompressed, unlike
images, which always have to be compressed. So if you don't want the
text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Because compressed-text chunks don't have a language field, if you
specify compression any language code will not be written out.
Because tEXt and zTXt chunks don't have a language field, if you
specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
any language code or translated keyword will not be written out.
Until text gets around 1000 bytes, it is not worth compressing it.
After the text has been written out to the file, the compression type
@@ -2401,7 +2529,7 @@ Compressed pairs must have a text string, as only the text string
is compressed anyway, so the compression would be meaningless.
PNG supports modification time via the png_time structure. Two
conversion routines are proved, png_convert_from_time_t() for
conversion routines are provided, png_convert_from_time_t() for
time_t and png_convert_from_struct_tm() for struct tm. The
time_t routine uses gmtime(). You don't have to use either of
these, but if you wish to fill in the png_time structure directly,
@@ -2439,7 +2567,7 @@ specification's ordering rules.
At this point there are two ways to proceed; through the high-level
write interface, or through a sequence of low-level write operations.
You can use the high-level interface if your image data is present
on the rowpointers member of the info structure. All defined output
in the info structure. All defined output
transformations are permitted, enabled by the following masks.
PNG_TRANSFORM_IDENTITY No transformation
@@ -2453,18 +2581,17 @@ transformations are permitted, enabled by the following masks.
PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
PNG_TRANSFORM_STRIP_FILLER Strip out filler bytes.
If you have valid image data on the rowpointers member, simply do this:
If you have valid image data in the info structure, simply do this:
png_write_png(png_ptr, info_ptr, png_transforms, NULL)
where png_transforms is an integer containing the logical-or of some set of
where png_transforms is an integer containing the logical OR of some set of
transformation flags. This call is equivalent to png_write_info(),
followed by the set of transformations indicated by the transform
mask, followed by followed by a write of the image bytes from the info
member `rowpointers', followed by png_write_end().
followed the set of transformations indicated by the transform mask,
then png_write_image(), and finally png_write_end().
(The final parameter of this call is not yet used. Someday it
may point to output transformation parameters.)
(The final parameter of this call is not yet used. Someday it might point
to transformation parameters required by some future output transform.)
.SS The low-level write interface
@@ -2517,8 +2644,8 @@ bytes per pixel).
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
PNG_FILLER_AFTER, depending upon whether the filler byte in the is stored
XRGB or RGBX.
PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
is stored XRGB or RGBX.
PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
they can, resulting in, for example, 8 pixels per byte for 1 bit files.
@@ -2529,7 +2656,7 @@ correctly pack the pixels into a single byte:
PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
data is of another bit depth, you can write an sBIT chunk into the
file so that decoders can get the original data if desired.
file so that decoders can recover the original data if desired.
/* Set the true bit depth of the image data */
if (color_type & PNG_COLOR_MASK_COLOR)
@@ -2604,8 +2731,8 @@ callback function.
The user_channels and user_depth parameters of this function are ignored
when writing; you can set them to zero as shown.
You can retrieve the pointer via the function
png_get_user_transform_ptr(). For example:
You can retrieve the pointer via the function png_get_user_transform_ptr().
For example:
voidp write_user_transform_ptr =
png_get_user_transform_ptr(png_ptr);
@@ -2667,7 +2794,7 @@ a single row_pointer instead of an array of row_pointers:
png_write_row(png_ptr, row_pointer);
When the file is interlaced, things can get a good deal more
complicated. The only currently (as of January 2000 -- PNG Specification
complicated. The only currently (as of the PNG Specification
version 1.2, dated July 1999) defined interlacing scheme for PNG files
is the "Adam7" interlace scheme, that breaks down an
image into seven smaller images of varying size. libpng will build
@@ -2715,27 +2842,62 @@ point to libpng-allocated storage with the following functions:
png_free_data(png_ptr, info_ptr, mask, n)
mask - identifies data to be freed, a mask
made up by the OR one or more of
containing the logical OR of one or more of
PNG_FREE_PLTE, PNG_FREE_TRNS,
PNG_FREE_HIST, PNG_FREE_ICCP,
PNG_FREE_SPLT, PNG_FREE_ROWS,
PNG_FREE_PCAL, PNG_FREE_SCAL,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
n - sequence number of item to be freed
(-1 for all items)
These functions may be safely called when the relevant storage has
already been freed, or has not yet been allocated, and will in that
case do nothing. The "n" parameter is ignored if only one item
already been freed, or has not yet been allocated, or was allocated
by the user and not by libpng, and will in those
cases do nothing. The "n" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "n" is not
-1, and multiple items are allowed for the data type identified in
the mask, such as text or splt, only the n'th item is freed.
the mask, such as text or sPLT, only the n'th item is freed.
If you allocated data such as a palette that you passed in to libpng with
png_set_*, you must not free it until just before the call to
If you allocated data such as a palette that you passed
in to libpng with png_set_*, you must not free it until just before the call to
png_destroy_write_struct().
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
mask - which data elements are affected
same choices as in png_free_data()
freer - one of
PNG_DESTROY_WILL_FREE_DATA
PNG_SET_WILL_FREE_DATA
PNG_USER_WILL_FREE_DATA
For example, to transfer responsibility for some data from a read structure
to a write structure, you could use
png_data_freer(read_ptr, read_info_ptr,
PNG_USER_WILL_FREE_DATA,
PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
png_data_freer(write_ptr, write_info_ptr,
PNG_DESTROY_WILL_FREE_DATA,
PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
thereby briefly reassigning responsibility for freeing to the user but
immediately afterwards reassigning it once more to the write_destroy
function. Having done this, it would then be safe to destroy the read
structure and continue to use the PLTE, tRNS, and hIST data in the write
structure.
This function only affects data that has already been allocated.
You can call this function before calling after the png_set_*() functions
to control whether the user or png_destroy_*() is supposed to free the data.
When the user assumes responsibility for libpng-allocated data, the
application must use png_free() to free it.
For a more compact example of writing a PNG image, see the file example.c.
.SH V. Modifying/Customizing libpng:
@@ -2747,25 +2909,35 @@ adding new transformations, and generally changing how libpng works.
All of the memory allocation, input/output, and error handling in libpng
goes through callbacks that are user settable. The default routines are
in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively. To change
in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
these functions, call the appropriate png_set_*_fn() function.
Memory allocation is done through the functions png_large_malloc(),
png_malloc(), png_realloc(), png_large_free(), and png_free(). These
currently just call the standard C functions. The large functions must
handle exactly 64K, but they don't have to handle more than that. If
Memory allocation is done through the functions png_malloc(), png_zalloc(),
and png_free(). These currently just call the standard C functions. If
your pointers can't access more then 64K at a time, you will want to set
MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
memory allocation on a platform will change between applications, these
functions must be modified in the library at compile time.
functions must be modified in the library at compile time. If you prefer
to use a different method of allocating and freeing data, you can use
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn)
This function also provides a void pointer that can be retrieved via
mem_ptr=png_get_mem_ptr(png_ptr);
Your replacement memory functions must have prototypes as follows:
png_voidp malloc_fn(png_structp png_ptr, png_uint_32 size);
void free_fn(png_structp png_ptr, png_voidp ptr);
Input/Output in libpng is done through png_read() and png_write(),
which currently just call fread() and fwrite(). The FILE * is stored in
png_struct and is initialized via png_init_io(). If you wish to change
the method of I/O, the library supplies callbacks that you can set
through the function png_set_read_fn() and png_set_write_fn() at run
time, instead of calling the png_init_io() function.
These functions
time, instead of calling the png_init_io() function. These functions
also provide a void pointer that can be retrieved via the function
png_get_io_ptr(). For example:
@@ -2779,7 +2951,7 @@ png_get_io_ptr(). For example:
voidp read_io_ptr = png_get_io_ptr(read_ptr);
voidp write_io_ptr = png_get_io_ptr(write_ptr);
The replacement I/O functions should have prototypes as follows:
The replacement I/O functions must have prototypes as follows:
void user_read_data(png_structp png_ptr,
png_bytep data, png_uint_32 length);
@@ -2801,11 +2973,13 @@ but you could change this to do things like exit() if you should wish.
On non-fatal errors, png_warning() is called
to print a warning message, and then control returns to the calling code.
By default png_error() and png_warning() print a message on stderr via
fprintf() unless the library is compiled with PNG_NO_STDIO defined. If
you wish to change the behavior of the error functions, you will need to
set up your own message callbacks. These functions are normally supplied
at the time that the png_struct is created. It is also possible to change
these functions after png_create_*_struct() has been called by calling:
fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
(because you don't want the messages) or PNG_NO_STDIO defined (because
fprintf() isn't available). If you wish to change the behavior of the error
functions, you will need to set up your own message callbacks. These
functions are normally supplied at the time that the png_struct is created.
It is also possible to redirect errors and warnings to your own replacement
functions after png_create_*_struct() has been called by calling:
png_set_error_fn(png_structp png_ptr,
png_voidp error_ptr, png_error_ptr error_fn,
@@ -2829,7 +3003,8 @@ as there is no need to check every return code of every function call.
However, there are some uncertainties about the status of local variables
after a longjmp, so the user may want to be careful about doing anything after
setjmp returns non-zero besides returning itself. Consult your compiler
documentation for more details.
documentation for more details. For an alternative approach, you may wish
to use the "cexcept" facility (see http://cexcept.sourceforge.net).
.SS Custom chunks
@@ -2859,10 +3034,7 @@ can be found in the comments inside the code itself.
.SS Configuring for 16 bit platforms
You may need to change the png_large_malloc() and png_large_free()
routines in pngmem.c, as these are required to allocate 64K, although
there is already support for many of the common DOS compilers. Also,
you will want to look into zconf.h to tell zlib (and thus libpng) that
You will want to look into zconf.h to tell zlib (and thus libpng) that
it cannot allocate more then 64K at a time. Even if you can, the memory
won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
@@ -2931,6 +3103,7 @@ zlib.h for more information on what these mean.
png_set_compression_window_bits(png_ptr,
window_bits);
png_set_compression_method(png_ptr, method);
png_set_compression_buffer_size(png_ptr, size);
.SS Controlling row filtering
@@ -2951,15 +3124,21 @@ to turn filtering on and off, respectively.
Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
ORed together '|' to specify one or more filters to use. These
filters are described in more detail in the PNG specification. If
ORed together with '|' to specify one or more filters to use.
These filters are described in more detail in the PNG specification. If
you intend to change the filter type during the course of writing
the image, you should start with flags set for all of the filters
you intend to use so that libpng can initialize its internal
structures appropriately for all of the filter types.
filters = PNG_FILTER_NONE | PNG_FILTER_SUB
| PNG_FILTER_UP;
PNG_FILTER_UP | PNG_FILTER_AVE |
PNG_FILTER_PAETH | PNG_ALL_FILTERS;
or
filters = one of PNG_FILTER_VALUE_NONE,
PNG_FILTER_VALUE_SUB, PNG_FILTER_VALUE_UP,
PNG_FILTER_VALUE_AVE, PNG_FILTER_VALUE_PAETH
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
filters);
@@ -3008,7 +3187,7 @@ you can turn off individual capabilities with defines that begin with
PNG_NO_.
You can also turn all of the transforms and ancillary chunk capabilities
off en masse with compiler directives that define
off en masse with compiler directives that define
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
or all four,
along with directives to turn on any of the capabilities that you do
@@ -3108,13 +3287,13 @@ the old method.
.SH VII. Y2K Compliance in libpng
April 2, 2000
May 4, 2000
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.0.6a are Y2K compliant. It is my belief that earlier
upward through 1.0.6j are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer that
@@ -3193,20 +3372,21 @@ the first widely used release:
1.0.3a-d 1.0.3a-d 10004 2.1.0.3a-d
1.0.4 1.0.4 10004 2.1.0.4
1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
1.0.5 1.0.5 10005 2.1.0.5
1.0.5 (+ 2 patches) 1.0.5 10005 2.1.0.5
1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d
1.0.5e-r 1.0.5e-r 10100 2.1.0.5e-r (not compatible)
1.0.5s-v 1.0.5s-v 10006 2.1.0.5s-v (compatible)
1.0.6 1.0.6 10006 2.1.0.6
1.0.6a 1.0.6a 10007 2.1.0.6a
1.3.0 1.3.0 10300 3.1.3.0
1.0.6 (+ 3 patches) 1.0.6 10006 2.1.0.6
1.0.6d 1.0.6d 10007 2.1.0.6d
1.0.7 1.0.7 10007 2.1.0.7 (still compatible)
Henceforth the source version will match the shared-library
minor and patch numbers; the shared-library major version number will be
used for changes in backward compatibility, as it is intended.
The PNG_PNGLIB_VER macro, which is not used within libpng but
is available for applications, is an unsigned integer of the form
xyyzz corresponding to the source version x.y.z (leading zeros in y and z).
Henceforth the source version will match the shared-library minor
and patch numbers; the shared-library major version number will be
used for changes in backward compatibility, as it is intended. The
PNG_PNGLIB_VER macro, which is not used within libpng but is available
for applications, is an unsigned integer of the form xyyzz corresponding
to the source version x.y.z (leading zeros in y and z). Beta versions
are given the previous public release number plus a letter or two.
.SH "SEE ALSO"
libpngpf(3), png(5)
@@ -3254,7 +3434,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.0.6a - April 2, 2000:
Libpng version 1.0.6j - May 4, 2000:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (randeg@alum.rpi.edu).
@@ -3269,7 +3449,7 @@ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Copyright (c) 1996, 1997 Andreas Dilger
(libpng versions 0.89c, May 1996, through 0.96, May 1997)
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
(libpng versions 0.97, January 1998, through 1.0.6a, April 2, 2000)
(libpng versions 0.97, January 1998, through 1.0.6j, May 4, 2000)
For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:

View File

@@ -1,6 +1,6 @@
libpng.txt - A description on how to use and modify libpng
libpng version 1.0.6a - April 2, 2000
libpng version 1.0.6j - May 4, 2000
Updated and distributed by Glenn Randers-Pehrson
<randeg@alum.rpi.edu>
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -118,10 +118,10 @@ You will want to do the I/O initialization(*) before you get into libpng,
so if it doesn't work, you don't have much to undo. Of course, you
will also want to insure that you are, in fact, dealing with a PNG
file. Libpng provides a simple check to see if a file is a PNG file.
To use it, pass in the first 1 to 8 bytes of the file, and it will
return true or false (1 or 0) depending on whether the bytes could be
part of a PNG file. Of course, the more bytes you pass in, the
greater the accuracy of the prediction.
To use it, pass in the first 1 to 8 bytes of the file to the function
png_sig_cmp(), and it will return 0 if the bytes match the corresponding
bytes of the PNG signature, or nonzero otherwise. Of course, the more bytes
you pass in, the greater the accuracy of the prediction.
If you are intending to keep the file pointer open for use in libpng,
you must ensure you don't read more than 8 bytes from the beginning
@@ -337,14 +337,39 @@ dithering, and setting filler.) If this is the case, simply do this:
png_read_png(png_ptr, info_ptr, png_transforms, NULL)
where png_transforms is an integer containing the logical-or of some set of
transformation flags. This call is equivalent to png_read_info(),
where png_transforms is an integer containing the logical OR of
some set of transformation flags. This call is equivalent to png_read_info(),
followed the set of transformations indicated by the transform mask,
followed by png_update_info(), followed by a read of the image bytes
to the info member `rowpointers', followed by png_read_end().
then png_read_image(), and finally png_read_end().
(The final parameter of this call is not yet used. Someday it
will point to transformation parameters.)
(The final parameter of this call is not yet used. Someday it might point
to transformation parameters required by some future input transform.)
After you have called png_read_png(), you can retrieve the image data
with
row_pointers = png_get_rows(png_ptr, info_ptr);
where row_pointers is an array of pointers to the pixel data for each row:
png_bytep row_pointers[height];
If you know your image size and pixel size ahead of time, you can allocate
row_pointers prior to calling png_read_png() with
row_pointers = png_malloc(png_ptr, height*sizeof(png_bytep));
for (int i=0; i<height, i++)
row_pointers[i]=png_malloc(png_ptr, width*pixel_size);
png_set_rows(png_ptr, info_ptr, &row_pointers);
Alternatively you could allocate your image in one big block and define
row_pointers[i] to point into the proper places in your block.
If you use png_set_rows(), the application is responsible for freeing
row_pointers (and row_pointers[i], if they were separately allocated).
If you don't allocate row_pointers ahead of time, png_read_png() will
do it, and it'll be free'ed when you call png_destroy_*().
The low-level read interface
@@ -399,8 +424,8 @@ in until png_read_end() has read the chunk data following the image.
interlace_type - (PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7)
Any or all of interlace_type, compression_type, of
filter_type can be
NULL if you are not interested in their values.
filter_type can be NULL if you are not
interested in their values.
channels = png_get_channels(png_ptr, info_ptr);
channels - number of channels of info for the
@@ -492,7 +517,7 @@ into the info_ptr is returned for any complex types.
png_get_hIST(png_ptr, info_ptr, &hist);
(PNG_INFO_hIST)
hist - histogram of palette (array of
png_color_16)
png_uint_16)
png_get_tIME(png_ptr, info_ptr, &mod_time);
mod_time - time image was last modified
@@ -508,26 +533,34 @@ into the info_ptr is returned for any complex types.
num_comments - number of comments
text_ptr - array of png_text holding image
comments
text_ptr[i]->compression - type of compression used
text_ptr[i].compression - type of compression used
on "text" PNG_TEXT_COMPRESSION_NONE
PNG_TEXT_COMPRESSION_zTXt
PNG_ITXT_COMPRESSION_NONE
PNG_ITXT_COMPRESSION_zTXt
text_ptr[i]->key - keyword for comment.
text_ptr[i]->text - text comments for current
keyword.
text_ptr[i]->text_length - length of text string,
text_ptr[i].key - keyword for comment. Must contain
1-79 characters.
text_ptr[i].text - text comments for current
keyword. Can empty.
text_ptr[i].text_length - length of text string,
after decompression, 0 for iTXt
text_ptr[i]->itxt_length - length of itxt string,
text_ptr[i].itxt_length - length of itxt string,
after decompression, 0 for tEXt/zTXt
text_ptr[i]->lang - language of comment (NULL for unknown).
text_ptr[i]->translated_keyword - keyword in UTF-8 (NULL
for unknown).
text_ptr[i].lang - language of comment (empty
string for unknown).
text_ptr[i].translated_keyword - keyword in UTF-8
(empty string for unknown).
num_text - number of comments (same as num_comments;
you can put NULL here to avoid the duplication)
num_spalettes = png_get_spalettes(png_ptr, info_ptr, &palette_ptr);
palette_ptr - array of png_spalette structures holding contents
of one or more sPLT chunks read.
Note while png_set_text() will accept text, language, and
translated keywords that can be NULL pointers, the structure
returned by png_get_text will always contain regular
zero-terminated C strings. They might be empty strings but
they will never be NULL pointers.
num_spalettes = png_get_sPLT(png_ptr, info_ptr, &palette_ptr);
palette_ptr - array of palette structures holding
contents of one or more sPLT chunks read.
num_spalettes - number of sPLT chunks read.
png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
@@ -548,9 +581,16 @@ into the info_ptr is returned for any complex types.
PNG_RESOLUTION_METER
png_get_sCAL(png_ptr, info_ptr, &unit, &width, &height)
unit - physical scale units (a string)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are doubles)
png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, &height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
num_unknown_chunks = png_get_unknown_chunks(png_ptr, info_ptr,
&unknowns)
@@ -558,9 +598,12 @@ into the info_ptr is returned for any complex types.
unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk
unknowns[i].size - size of unknown chunk's data
unknowns[i].location - position of chunk in file
The value of "i" corresponds to the order in which the chunks were read
from the PNG file or inserted with the png_set_unknown_chunks() function.
The data from the pHYs chunk can be retrieved in several convenient
forms:
@@ -570,6 +613,12 @@ forms:
info_ptr)
res_x_and_y = png_get_pixels_per_meter(png_ptr,
info_ptr)
res_x = png_get_x_pixels_per_inch(png_ptr,
info_ptr)
res_y = png_get_y_pixels_per_inch(png_ptr,
info_ptr)
res_x_and_y = png_get_pixels_per_inch(png_ptr,
info_ptr)
aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
info_ptr)
@@ -577,6 +626,18 @@ forms:
the data is not present or if res_x is 0;
res_x_and_y is 0 if res_x != res_y)
The data from the oFFs chunk can be retrieved in several convenient
forms:
x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
(Each of these returns 0 [signifying "unknown" if both
x and y are 0] if the data is not present or if the chunk
is present but the unit is the pixel)
For more information, see the png_info definition in png.h and the
PNG specification for chunk contents. Be careful with trusting
rowbytes, as some of the transformations could increase the space
@@ -597,7 +658,8 @@ trailing spaces, but non-consecutive spaces are allowed within the
keyword. It is possible to have the same keyword any number of times.
The text_ptr is an array of png_text structures, each holding a
pointer to a language string, a pointer to a keyword and a pointer to
a text string. Only the text string may be null. The keyword/text
a text string. The text string, language code, and translated
keyword may be empty or NULL pointers. The keyword/text
pairs are put into the array in the order that they are received.
However, some or all of the text chunks may be after the image, so, to
make sure you have read all the text chunks, don't mess with these
@@ -643,8 +705,8 @@ transparency information in a tRNS chunk. This is most useful on
grayscale images with bit depths of 2 or 4 or if there is a multiple-image
viewing application that wishes to treat all images in the same way.
if (color_type == PNG_COLOR_TYPE_PALETTE &&
bit_depth <= 8) png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY &&
bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
@@ -663,17 +725,6 @@ PNG can have files with 16 bits per channel. If you only can handle
if (bit_depth == 16)
png_set_strip_16(png_ptr);
The png_set_background() function tells libpng to composite images
with alpha or simple transparency against the supplied background
color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
you may use this color, or supply another color more suitable for
the current display (e.g., the background color from a web page). You
need to tell libpng whether the color is in the gamma space of the
display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
know why anyone would use this, but it's here).
If, for some reason, you don't need the alpha channel on an image,
and you want to remove it rather than combining it with the background
(but the image author certainly had in mind that you *would* combine
@@ -817,6 +868,17 @@ or as an RGB triplet that may or may not be in the palette (need_expand = 0).
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
The png_set_background() function tells libpng to composite images
with alpha or simple transparency against the supplied background
color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
you may use this color, or supply another color more suitable for
the current display (e.g., the background color from a web page). You
need to tell libpng whether the color is in the gamma space of the
display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
know why anyone would use this, but it's here).
To properly display PNG images on any kind of system, the application needs
to know what the display gamma is. Ideally, the user will know this, and
the application will allow them to set it. One method of allowing the user
@@ -1013,10 +1075,10 @@ If you are doing this just one row at a time, you can do this with
a single row_pointer instead of an array of row_pointers:
png_bytep row_pointer = row;
png_read_row(png_ptr, row_pointers, NULL);
png_read_row(png_ptr, row_pointer, NULL);
If the file is interlaced (info_ptr->interlace_type != 0), things get
somewhat harder. The only current (PNG Specification version 1.2)
If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
get somewhat harder. The only current (PNG Specification version 1.2)
interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
is a somewhat complicated 2D interlace scheme, known as Adam7, that
breaks down an image into seven smaller images of varying size, based
@@ -1110,11 +1172,10 @@ point to libpng-allocated storage with the following functions:
png_free_data(png_ptr, info_ptr, mask, n)
mask - identifies data to be freed, a mask
made up by the OR one or more of
containing the logical OR of one or more of
PNG_FREE_PLTE, PNG_FREE_TRNS,
PNG_FREE_HIST, PNG_FREE_ICCP,
PNG_FREE_SPLT, PNG_FREE_ROWS,
PNG_FREE_PCAL, PNG_FREE_SCAL,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
n - sequence number of item to be freed
@@ -1126,7 +1187,34 @@ by the user and not by libpng, and will in those
cases do nothing. The "n" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "n" is not
-1, and multiple items are allowed for the data type identified in
the mask, such as text or splt, only the n'th item is freed.
the mask, such as text or sPLT, only the n'th item is freed.
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
mask - which data elements are affected
same choices as in png_free_data()
freer - one of
PNG_DESTROY_WILL_FREE_DATA
PNG_SET_WILL_FREE_DATA
PNG_USER_WILL_FREE_DATA
This function only affects data that has already been allocated.
You can call this function after reading the PNG data but before calling
any png_set_*() functions, to control whether the user or the png_set_*()
function is responsible for freeing any existing data that might be present,
and again after the png_set_*() functions to control whether the user
or png_destroy_*() is supposed to free the data. When the user assumes
responsibility for libpng-allocated data, the application must use
png_free() to free it.
If you allocated your row_pointers in a single block, as suggested above in
the description of the high level read interface, you must not transfer
responsibility for freeing it to the png_set_rows or png_read_destroy function,
because they would also try to free the individual row_pointers[i].
For a more compact example of reading a PNG image, see the file example.c.
@@ -1344,7 +1432,7 @@ both "png_ptr"; you can call them anything you like, such as
If you want to use your own memory allocation routines,
define PNG_USER_MEM_SUPPORTED and use
png_create_write_struct_2() instead of png_create_read_struct():
png_create_write_struct_2() instead of png_create_write_struct():
png_structp png_ptr = png_create_write_struct_2
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
@@ -1413,21 +1501,33 @@ speed/compression ratio. The second parameter to png_set_filter() is
the filter method, for which the only valid value is '0' (as of the
July 1999 PNG specification, version 1.2). The third parameter is a
flag that indicates which filter type(s) are to be tested for each
scanline. See the Compression Library for details on the specific filter
scanline. See the PNG specification for details on the specific filter
types.
/* turn on or off filtering, and/or choose
specific filters */
specific filters. You can use either a single PNG_FILTER_VALUE_NAME
or the logical OR of one or more PNG_FILTER_NAME masks. */
png_set_filter(png_ptr, 0,
PNG_FILTER_NONE | PNG_FILTER_SUB |
PNG_FILTER_PAETH);
PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
PNG_FILTER_AVE | PNG_FILTER_VALUE_AVE |
PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
PNG_ALL_FILTERS);
If an application
wants to start and stop using particular filters during compression,
it should start out with all of the filters (to ensure that the previous
row of pixels will be stored in case it's needed later), and then add
and remove them after the start of compression.
The png_set_compression_*() functions interface to the zlib compression
library, and should mostly be ignored unless you really know what you are
doing. The only generally useful call is png_set_compression_level()
which changes how much time zlib spends on trying to compress the image
data. See the Compression Library for details on the compression levels.
data. See the Compression Library (zlib.h and algorithm.txt, distributed
with zlib) for details on the compression levels.
/* set the zlib compression level */
png_set_compression_level(png_ptr,
@@ -1439,6 +1539,9 @@ data. See the Compression Library for details on the compression levels.
Z_DEFAULT_STRATEGY);
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
png_set_compression_buffer_size(png_ptr, 8192)
extern PNG_EXPORT(void,png_set_zbuf_size)
Setting the contents of info for output
@@ -1559,7 +1662,7 @@ Some of the more important parts of the png_info are:
png_set_hIST(png_ptr, info_ptr, hist);
(PNG_INFO_hIST)
hist - histogram of palette (array of
png_color_16)
png_uint_16)
png_set_tIME(png_ptr, info_ptr, mod_time);
mod_time - time image was last modified
@@ -1571,26 +1674,29 @@ Some of the more important parts of the png_info are:
png_set_text(png_ptr, info_ptr, text_ptr, num_text);
text_ptr - array of png_text holding image
comments
text_ptr[i]->compression - type of compression used
text_ptr[i].compression - type of compression used
on "text" PNG_TEXT_COMPRESSION_NONE
PNG_TEXT_COMPRESSION_zTXt
PNG_ITXT_COMPRESSION_NONE
PNG_ITXT_COMPRESSION_zTXt
text_ptr[i]->key - keyword for comment.
text_ptr[i]->text - text comments for current
keyword.
text_ptr[i]->text_length - length of text string,
text_ptr[i].key - keyword for comment. Must contain
1-79 characters.
text_ptr[i].text - text comments for current
keyword. Can be NULL or empty.
text_ptr[i].text_length - length of text string,
after decompression, 0 for iTXt
text_ptr[i]->itxt_length - length of itxt string,
text_ptr[i].itxt_length - length of itxt string,
after decompression, 0 for tEXt/zTXt
text_ptr[i]->lang - language of comment (NULL for unknown).
text_ptr[i]->translated_keyword - keyword in UTF-8 (NULL
for unknown).
text_ptr[i].lang - language of comment (NULL or
empty for unknown).
text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
or empty for unknown).
num_text - number of comments
png_set_spalettes(png_ptr, info_ptr, &palette_ptr, num_spalettes);
palette_ptr - array of png_spalette structures to be added to
the list of palettes in the info structure.
png_set_sPLT(png_ptr, info_ptr, &palette_ptr, num_spalettes);
palette_ptr - array of png_sPLT_struct structures to be
added to the list of palettes in the info
structure.
num_spalettes - number of palette structures to be added.
png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
@@ -1611,16 +1717,23 @@ Some of the more important parts of the png_info are:
PNG_RESOLUTION_METER
png_set_sCAL(png_ptr, info_ptr, unit, width, height)
unit - physical scale units (a string)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are doubles)
png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, num_unknowns)
unknowns - array of png_unknown_chunk structures holding
unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk
unknowns[i].size - size of unknown chunk's data
unknowns[i].location - position to write chunk in file
0: do not write chunk
PNG_HAVE_IHDR: before PLTE
@@ -1629,22 +1742,25 @@ Some of the more important parts of the png_info are:
The "location" member is set automatically according to
what part of the output file has already been written.
You can change its value after calling png_set_unknown_chunks()
as demonstrated in pngtest.c.
as demonstrated in pngtest.c. Within each of the "locations",
the chunks are sequenced according to their position in the
structure (that is, the value of "i", which is the order in which
the chunk was either read from the input file or defined with
png_set_unknown_chunks).
A quick word about text and num_text. text is an array of png_text
structures. num_text is the number of valid structures in the array.
If you want, you can use max_text to hold the size of the array, but
libpng ignores it for writing (it does use it for reading). Each
png_text structure holds a language code, a keyword, a text value, and
a compression type.
Each png_text structure holds a language code, a keyword, a text value,
and a compression type.
The compression types have the same valid numbers as the compression
types of the image data. Currently, the only valid number is zero.
However, you can store text either compressed or uncompressed, unlike
images, which always have to be compressed. So if you don't want the
text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Because compressed-text chunks don't have a language field, if you
specify compression any language code will not be written out.
Because tEXt and zTXt chunks don't have a language field, if you
specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
any language code or translated keyword will not be written out.
Until text gets around 1000 bytes, it is not worth compressing it.
After the text has been written out to the file, the compression type
@@ -1688,7 +1804,7 @@ Compressed pairs must have a text string, as only the text string
is compressed anyway, so the compression would be meaningless.
PNG supports modification time via the png_time structure. Two
conversion routines are proved, png_convert_from_time_t() for
conversion routines are provided, png_convert_from_time_t() for
time_t and png_convert_from_struct_tm() for struct tm. The
time_t routine uses gmtime(). You don't have to use either of
these, but if you wish to fill in the png_time structure directly,
@@ -1726,7 +1842,7 @@ The high-level write interface
At this point there are two ways to proceed; through the high-level
write interface, or through a sequence of low-level write operations.
You can use the high-level interface if your image data is present
on the rowpointers member of the info structure. All defined output
in the info structure. All defined output
transformations are permitted, enabled by the following masks.
PNG_TRANSFORM_IDENTITY No transformation
@@ -1740,18 +1856,17 @@ transformations are permitted, enabled by the following masks.
PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
PNG_TRANSFORM_STRIP_FILLER Strip out filler bytes.
If you have valid image data on the rowpointers member, simply do this:
If you have valid image data in the info structure, simply do this:
png_write_png(png_ptr, info_ptr, png_transforms, NULL)
where png_transforms is an integer containing the logical-or of some set of
where png_transforms is an integer containing the logical OR of some set of
transformation flags. This call is equivalent to png_write_info(),
followed by the set of transformations indicated by the transform
mask, followed by followed by a write of the image bytes from the info
member `rowpointers', followed by png_write_end().
followed the set of transformations indicated by the transform mask,
then png_write_image(), and finally png_write_end().
(The final parameter of this call is not yet used. Someday it
may point to output transformation parameters.)
(The final parameter of this call is not yet used. Someday it might point
to transformation parameters required by some future output transform.)
The low-level write interface
@@ -1804,8 +1919,8 @@ bytes per pixel).
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
PNG_FILLER_AFTER, depending upon whether the filler byte in the is stored
XRGB or RGBX.
PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
is stored XRGB or RGBX.
PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
they can, resulting in, for example, 8 pixels per byte for 1 bit files.
@@ -1816,7 +1931,7 @@ correctly pack the pixels into a single byte:
PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
data is of another bit depth, you can write an sBIT chunk into the
file so that decoders can get the original data if desired.
file so that decoders can recover the original data if desired.
/* Set the true bit depth of the image data */
if (color_type & PNG_COLOR_MASK_COLOR)
@@ -1891,8 +2006,8 @@ callback function.
The user_channels and user_depth parameters of this function are ignored
when writing; you can set them to zero as shown.
You can retrieve the pointer via the function
png_get_user_transform_ptr(). For example:
You can retrieve the pointer via the function png_get_user_transform_ptr().
For example:
voidp write_user_transform_ptr =
png_get_user_transform_ptr(png_ptr);
@@ -1954,7 +2069,7 @@ a single row_pointer instead of an array of row_pointers:
png_write_row(png_ptr, row_pointer);
When the file is interlaced, things can get a good deal more
complicated. The only currently (as of January 2000 -- PNG Specification
complicated. The only currently (as of the PNG Specification
version 1.2, dated July 1999) defined interlacing scheme for PNG files
is the "Adam7" interlace scheme, that breaks down an
image into seven smaller images of varying size. libpng will build
@@ -2002,27 +2117,62 @@ point to libpng-allocated storage with the following functions:
png_free_data(png_ptr, info_ptr, mask, n)
mask - identifies data to be freed, a mask
made up by the OR one or more of
containing the logical OR of one or more of
PNG_FREE_PLTE, PNG_FREE_TRNS,
PNG_FREE_HIST, PNG_FREE_ICCP,
PNG_FREE_SPLT, PNG_FREE_ROWS,
PNG_FREE_PCAL, PNG_FREE_SCAL,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
n - sequence number of item to be freed
(-1 for all items)
These functions may be safely called when the relevant storage has
already been freed, or has not yet been allocated, and will in that
case do nothing. The "n" parameter is ignored if only one item
already been freed, or has not yet been allocated, or was allocated
by the user and not by libpng, and will in those
cases do nothing. The "n" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "n" is not
-1, and multiple items are allowed for the data type identified in
the mask, such as text or splt, only the n'th item is freed.
the mask, such as text or sPLT, only the n'th item is freed.
If you allocated data such as a palette that you passed in to libpng with
png_set_*, you must not free it until just before the call to
If you allocated data such as a palette that you passed
in to libpng with png_set_*, you must not free it until just before the call to
png_destroy_write_struct().
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
mask - which data elements are affected
same choices as in png_free_data()
freer - one of
PNG_DESTROY_WILL_FREE_DATA
PNG_SET_WILL_FREE_DATA
PNG_USER_WILL_FREE_DATA
For example, to transfer responsibility for some data from a read structure
to a write structure, you could use
png_data_freer(read_ptr, read_info_ptr,
PNG_USER_WILL_FREE_DATA,
PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
png_data_freer(write_ptr, write_info_ptr,
PNG_DESTROY_WILL_FREE_DATA,
PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
thereby briefly reassigning responsibility for freeing to the user but
immediately afterwards reassigning it once more to the write_destroy
function. Having done this, it would then be safe to destroy the read
structure and continue to use the PLTE, tRNS, and hIST data in the write
structure.
This function only affects data that has already been allocated.
You can call this function before calling after the png_set_*() functions
to control whether the user or png_destroy_*() is supposed to free the data.
When the user assumes responsibility for libpng-allocated data, the
application must use png_free() to free it.
For a more compact example of writing a PNG image, see the file example.c.
V. Modifying/Customizing libpng:
@@ -2034,25 +2184,35 @@ adding new transformations, and generally changing how libpng works.
All of the memory allocation, input/output, and error handling in libpng
goes through callbacks that are user settable. The default routines are
in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively. To change
in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
these functions, call the appropriate png_set_*_fn() function.
Memory allocation is done through the functions png_large_malloc(),
png_malloc(), png_realloc(), png_large_free(), and png_free(). These
currently just call the standard C functions. The large functions must
handle exactly 64K, but they don't have to handle more than that. If
Memory allocation is done through the functions png_malloc(), png_zalloc(),
and png_free(). These currently just call the standard C functions. If
your pointers can't access more then 64K at a time, you will want to set
MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
memory allocation on a platform will change between applications, these
functions must be modified in the library at compile time.
functions must be modified in the library at compile time. If you prefer
to use a different method of allocating and freeing data, you can use
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn)
This function also provides a void pointer that can be retrieved via
mem_ptr=png_get_mem_ptr(png_ptr);
Your replacement memory functions must have prototypes as follows:
png_voidp malloc_fn(png_structp png_ptr, png_uint_32 size);
void free_fn(png_structp png_ptr, png_voidp ptr);
Input/Output in libpng is done through png_read() and png_write(),
which currently just call fread() and fwrite(). The FILE * is stored in
png_struct and is initialized via png_init_io(). If you wish to change
the method of I/O, the library supplies callbacks that you can set
through the function png_set_read_fn() and png_set_write_fn() at run
time, instead of calling the png_init_io() function.
These functions
time, instead of calling the png_init_io() function. These functions
also provide a void pointer that can be retrieved via the function
png_get_io_ptr(). For example:
@@ -2066,7 +2226,7 @@ png_get_io_ptr(). For example:
voidp read_io_ptr = png_get_io_ptr(read_ptr);
voidp write_io_ptr = png_get_io_ptr(write_ptr);
The replacement I/O functions should have prototypes as follows:
The replacement I/O functions must have prototypes as follows:
void user_read_data(png_structp png_ptr,
png_bytep data, png_uint_32 length);
@@ -2088,11 +2248,13 @@ but you could change this to do things like exit() if you should wish.
On non-fatal errors, png_warning() is called
to print a warning message, and then control returns to the calling code.
By default png_error() and png_warning() print a message on stderr via
fprintf() unless the library is compiled with PNG_NO_STDIO defined. If
you wish to change the behavior of the error functions, you will need to
set up your own message callbacks. These functions are normally supplied
at the time that the png_struct is created. It is also possible to change
these functions after png_create_*_struct() has been called by calling:
fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
(because you don't want the messages) or PNG_NO_STDIO defined (because
fprintf() isn't available). If you wish to change the behavior of the error
functions, you will need to set up your own message callbacks. These
functions are normally supplied at the time that the png_struct is created.
It is also possible to redirect errors and warnings to your own replacement
functions after png_create_*_struct() has been called by calling:
png_set_error_fn(png_structp png_ptr,
png_voidp error_ptr, png_error_ptr error_fn,
@@ -2116,7 +2278,8 @@ as there is no need to check every return code of every function call.
However, there are some uncertainties about the status of local variables
after a longjmp, so the user may want to be careful about doing anything after
setjmp returns non-zero besides returning itself. Consult your compiler
documentation for more details.
documentation for more details. For an alternative approach, you may wish
to use the "cexcept" facility (see http://cexcept.sourceforge.net).
Custom chunks
@@ -2146,10 +2309,7 @@ can be found in the comments inside the code itself.
Configuring for 16 bit platforms
You may need to change the png_large_malloc() and png_large_free()
routines in pngmem.c, as these are required to allocate 64K, although
there is already support for many of the common DOS compilers. Also,
you will want to look into zconf.h to tell zlib (and thus libpng) that
You will want to look into zconf.h to tell zlib (and thus libpng) that
it cannot allocate more then 64K at a time. Even if you can, the memory
won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
@@ -2218,6 +2378,7 @@ zlib.h for more information on what these mean.
png_set_compression_window_bits(png_ptr,
window_bits);
png_set_compression_method(png_ptr, method);
png_set_compression_buffer_size(png_ptr, size);
Controlling row filtering
@@ -2238,15 +2399,21 @@ to turn filtering on and off, respectively.
Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
ORed together '|' to specify one or more filters to use. These
filters are described in more detail in the PNG specification. If
ORed together with '|' to specify one or more filters to use.
These filters are described in more detail in the PNG specification. If
you intend to change the filter type during the course of writing
the image, you should start with flags set for all of the filters
you intend to use so that libpng can initialize its internal
structures appropriately for all of the filter types.
filters = PNG_FILTER_NONE | PNG_FILTER_SUB
| PNG_FILTER_UP;
PNG_FILTER_UP | PNG_FILTER_AVE |
PNG_FILTER_PAETH | PNG_ALL_FILTERS;
or
filters = one of PNG_FILTER_VALUE_NONE,
PNG_FILTER_VALUE_SUB, PNG_FILTER_VALUE_UP,
PNG_FILTER_VALUE_AVE, PNG_FILTER_VALUE_PAETH
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
filters);
@@ -2295,7 +2462,7 @@ you can turn off individual capabilities with defines that begin with
PNG_NO_.
You can also turn all of the transforms and ancillary chunk capabilities
off en masse with compiler directives that define
off en masse with compiler directives that define
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
or all four,
along with directives to turn on any of the capabilities that you do
@@ -2395,13 +2562,13 @@ the old method.
VII. Y2K Compliance in libpng
April 2, 2000
May 4, 2000
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.0.6a are Y2K compliant. It is my belief that earlier
upward through 1.0.6j are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer that

View File

@@ -1,6 +1,6 @@
.TH LIBPNGPF 3 April 2, 2000
.TH LIBPNGPF 3 "May 4, 2000"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6a
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6j
(private functions)
.SH SYNOPSIS
\fB#include <png.h>\fP

2
png.5
View File

@@ -1,4 +1,4 @@
.TH PNG 5 "April 2, 2000"
.TH PNG 5 "May 4, 2000"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION

78
png.c
View File

@@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions
*
* libpng version 1.0.6a - April 2, 2000
* libpng version 1.0.6j - May 4, 2000
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -14,14 +14,14 @@
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_0_6a Your_png_h_is_not_version_1_0_6a;
typedef version_1_0_6j Your_png_h_is_not_version_1_0_6j;
/* Version information for C files. This had better match the version
* string defined in png.h. */
#ifdef PNG_USE_GLOBAL_ARRAYS
/* png_libpng_ver was changed to a function in version 1.0.5c */
char png_libpng_ver[12] = "1.0.6a";
char png_libpng_ver[12] = "1.0.6j";
/* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */
@@ -134,7 +134,7 @@ png_check_sig(png_bytep sig, int num)
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
}
/* Function to allocate memory for zlib. */
/* Function to allocate memory for zlib and clear it to 0. */
voidpf
png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
@@ -261,15 +261,36 @@ png_info_init(png_infop info_ptr)
png_memset(info_ptr, 0, sizeof (png_info));
}
#ifdef PNG_FREE_ME_SUPPORTED
void
png_data_freer(png_structp png_ptr, png_infop info_ptr,
int freer, png_uint_32 mask)
{
png_debug(1, "in png_data_freer\n");
if (png_ptr == NULL || info_ptr == NULL)
return;
if(freer == PNG_DESTROY_WILL_FREE_DATA)
info_ptr->free_me |= mask;
else if(freer == PNG_USER_WILL_FREE_DATA)
info_ptr->free_me &= ~mask;
else
png_warning(png_ptr,
"Unknown freer parameter in png_data_freer.");
}
#endif
void
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num)
{
png_debug(1, "in png_free_data\n");
if (png_ptr == NULL || info_ptr == NULL)
return;
#if defined(PNG_TEXT_SUPPORTED)
/* free text item num or (if num == -1) all text items */
if (mask & PNG_FREE_TEXT & info_ptr->free_me & PNG_FREE_TEXT)
#ifdef PNG_FREE_ME_SUPPORTED
if (mask & info_ptr->free_me & PNG_FREE_TEXT)
#endif
{
if (num != -1)
{
@@ -297,7 +318,11 @@ if (mask & PNG_FREE_TRNS)
{
if (info_ptr->valid & PNG_INFO_tRNS)
{
#ifdef PNG_FREE_ME_SUPPORTED
if (info_ptr->free_me & PNG_FREE_TRNS)
#else
if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
#endif
png_free(png_ptr, info_ptr->trans);
info_ptr->valid &= ~PNG_INFO_tRNS;
}
@@ -306,7 +331,6 @@ if (mask & PNG_FREE_TRNS)
#if defined(PNG_sCAL_SUPPORTED)
/* free any sCAL entry */
if (mask & PNG_FREE_SCAL)
{
if (info_ptr->valid & PNG_INFO_sCAL)
{
@@ -321,7 +345,6 @@ if (mask & PNG_FREE_SCAL)
#if defined(PNG_pCAL_SUPPORTED)
/* free any pCAL entry */
if (mask & PNG_FREE_PCAL)
{
if (info_ptr->valid & PNG_INFO_pCAL)
{
@@ -347,7 +370,9 @@ if (mask & PNG_FREE_ICCP)
{
if (info_ptr->valid & PNG_INFO_iCCP)
{
#ifdef PNG_FREE_ME_SUPPORTED
if (info_ptr->free_me & PNG_FREE_ICCP)
#endif
{
png_free(png_ptr, info_ptr->iccp_name);
png_free(png_ptr, info_ptr->iccp_profile);
@@ -412,7 +437,11 @@ if (mask & PNG_FREE_HIST)
{
if (info_ptr->valid & PNG_INFO_hIST)
{
#ifdef PNG_FREE_ME_SUPPORTED
if (info_ptr->free_me & PNG_FREE_HIST)
#else
if (png_ptr->flags & PNG_FLAG_FREE_HIST)
#endif
png_free(png_ptr, info_ptr->hist);
info_ptr->valid &= ~PNG_INFO_hIST;
}
@@ -424,7 +453,11 @@ if (mask & PNG_FREE_PLTE)
{
if (info_ptr->valid & PNG_INFO_PLTE)
{
#ifdef PNG_FREE_ME_SUPPORTED
if (info_ptr->free_me & PNG_FREE_PLTE)
#else
if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
#endif
png_zfree(png_ptr, info_ptr->palette);
info_ptr->valid &= ~(PNG_INFO_PLTE);
info_ptr->num_palette = 0;
@@ -435,7 +468,9 @@ if (mask & PNG_FREE_PLTE)
/* free any image bits attached to the info structure */
if (mask & PNG_FREE_ROWS)
{
#ifdef PNG_FREE_ME_SUPPORTED
if (info_ptr->free_me & PNG_FREE_ROWS)
#endif
{
int row;
@@ -445,8 +480,10 @@ if (mask & PNG_FREE_ROWS)
}
}
#endif
#ifdef PNG_FREE_ME_SUPPORTED
if(num == -1)
info_ptr->free_me &= ~mask;
#endif
}
/* This is an internal routine to free any memory that the info struct is
@@ -460,7 +497,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
@@ -484,7 +521,9 @@ png_get_io_ptr(png_structp png_ptr)
#if !defined(PNG_NO_STDIO)
/* Initialize the default input/output functions for the PNG file. If you
* use your own read or write routines, you can call either png_set_read_fn()
* or png_set_write_fn() instead of png_init_io().
* or png_set_write_fn() instead of png_init_io(). If you have defined
* PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
* necessarily available.
*/
void
png_init_io(png_structp png_ptr, FILE *fp)
@@ -531,20 +570,20 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
}
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if 0
/* Signature string for a PNG file. */
png_bytep
png_sig_bytes(png_structp png_ptr)
png_sig_bytes(void)
{
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
return ("\212\120\116\107\015\012\032\012");
return ("");
return ((png_bytep)"\211\120\116\107\015\012\032\012");
}
#endif
png_charp
png_get_copyright(png_structp png_ptr)
{
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
return ("\n libpng version 1.0.6a - April 2, 2000\n\
return ("\n libpng version 1.0.6j - May 4, 2000\n\
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
Copyright (c) 1996, 1997 Andreas Dilger\n\
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n");
@@ -562,8 +601,8 @@ png_get_libpng_ver(png_structp png_ptr)
{
/* Version of *.c files used when building libpng */
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
return("1.0.6a");
return("1.0.6a");
return("1.0.6j");
return("1.0.6j");
}
png_charp
@@ -600,3 +639,10 @@ png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
return 0;
}
#endif
/* This function, added to libpng-1.0.6g, is untested. */
int
png_reset_zstream(png_structp png_ptr)
{
return (inflateReset(&png_ptr->zstream));
}

331
png.h
View File

@@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.0.6a - April 2, 2000
* libpng version 1.0.6j - May 4, 2000
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -9,7 +9,7 @@
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.0.6a - April 2, 2000: Glenn
* libpng versions 0.97, January 1998, through 1.0.6j - May 4, 2000: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -20,44 +20,52 @@
* The following table summarizes matters since version 0.89c, which was
* the first widely used release:
*
* source png.h png.h shared-lib
* version string int version
* ------- ------ ----- ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
* 0.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [100 should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [100 should be 10000]
* 1.0.1 1.0.1 10001 2.1.0
* 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
* 1.0.2 1.0.2 10002 2.1.0.2
* 1.0.2a-b 1.0.2a-b 10003 2.1.0.2a-b
* 1.0.3 1.0.3 10003 2.1.0.3
* 1.0.3a-d 1.0.3a-d 10004 2.1.0.3a-d
* 1.0.4 1.0.4 10004 2.1.0.4
* 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
* 1.0.5 1.0.5 10005 2.1.0.5
* 1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d
* 1.0.5e-r 1.0.5e-r 10100 2.1.0.5e-r (not compatible)
* 1.0.5s-v 1.0.5s-v 10006 2.1.0.5s-v (compatible)
* 1.0.6 1.0.6 10006 2.1.0.6
* 1.0.6a 1.0.6a 10007 2.1.0.6a
* 1.3.0 1.3.0 10300 3.1.3.0
* source png.h png.h shared-lib
* version string int version
* ------- ------ ----- ----------
* 0.89c "1.0 beta 3" 0.89 89 1.0.89
* 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90]
* 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95]
* 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96]
* 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97]
* 0.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [100 should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [100 should be 10000]
* 1.0.1 1.0.1 10001 2.1.0
* 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
* 1.0.2 1.0.2 10002 2.1.0.2
* 1.0.2a-b 1.0.2a-b 10003 2.1.0.2a-b
* 1.0.3 1.0.3 10003 2.1.0.3
* 1.0.3a-d 1.0.3a-d 10004 2.1.0.3a-d
* 1.0.4 1.0.4 10004 2.1.0.4
* 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
* 1.0.5 (+ 2 patches) 1.0.5 10005 2.1.0.5
* 1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d
* 1.0.5e-r 1.0.5e-r 10100 2.1.0.5e-r (not source compatible)
* 1.0.5s-v 1.0.5s-v 10006 2.1.0.5s-v (not binary compatible)
* 1.0.6 (+ 3 patches) 1.0.6 10006 2.1.0.6 (still binary incompat)
* 1.0.6d-f 1.0.6d-f 10007 2.1.0.6d-f (still binary incompat)
* 1.0.6g 1.0.6g 10007 2.1.0.6g
* 1.0.6h 1.0.6h 10007 10.6h (testing xy.z so-numbering)
* 1.0.6i 1.0.6i 10007 10.6i (can be compatible w/ 1.0.0)
* 1.0.6j 1.0.6j 10007 2.1.0.6j (compatible with 1.0.0)
* 1.0.6 (+ 4 patches) 1.0.6 10006 2.1.0.6ad (compatible with 1.0.0)
* 1.0.7 1.0.7 10007 2.1.0.7 (still compatible)
*
* Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
* used for changes in backward compatibility, as it is intended. The
* PNG_PNGLIB_VER macro, which is not used within libpng but is available
* for applications, is an unsigned integer of the form xyyzz corresponding
* to the source version x.y.z (leading zeros in y and z). Internal
* png-group beta versions (x.y.z[a-z]) will be given the next higher
* number.
* to the source version x.y.z (leading zeros in y and z). Beta versions
* are given the previous public release number plus a letter or two.
*
* Binary incompatibility exists only when applications make direct access
* to the info_ptr or png_ptr members through png.h, and the compiled
* application is loaded with a different version of the library.
*
* See libpng.txt or libpng.3 for more information. The PNG specification
* is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
@@ -74,7 +82,7 @@
* Copyright (c) 1996, 1997 Andreas Dilger
* (libpng versions 0.89c, June 1996, through 0.96, May 1997)
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (libpng versions 0.97, January 1998, through 1.0.6a, April 2, 2000)
* (libpng versions 0.97, January 1998, through 1.0.6j, May 4, 2000)
*
* For the purposes of this copyright and license, "Contributing Authors"
* is defined as the following set of individuals:
@@ -149,13 +157,13 @@
* Y2K compliance in libpng:
* =========================
*
* April 2, 2000
* May 4, 2000
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.0.6a are Y2K compliant. It is my belief that earlier
* upward through 1.0.6j are Y2K compliant. It is my belief that earlier
* versions were also Y2K compliant.
*
* Libpng only has three year fields. One is a 2-byte unsigned integer
@@ -233,7 +241,7 @@ extern "C" {
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.0.6a"
#define PNG_LIBPNG_VER_STRING "1.0.6j"
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros.
@@ -324,12 +332,17 @@ typedef struct png_sPLT_entry_struct
typedef png_sPLT_entry FAR * png_sPLT_entryp;
typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
/* When the depth of the sPLT palette is 8 bits, the color and alpha samples
* occupy the LSB of their respective members, and the MSB of each member
* is zero-filled. The frequency member always occupies the full 16 bits.
*/
typedef struct png_sPLT_struct
{
png_charp name; /* palette name */
png_byte depth; /* depth of palette samples */
png_sPLT_entryp entries; /* palette entries */
png_int_32 nentries; /* number of palette entries */
png_charp name; /* palette name */
png_byte depth; /* depth of palette samples */
png_sPLT_entryp entries; /* palette entries */
png_int_32 nentries; /* number of palette entries */
} png_sPLT_t;
typedef png_sPLT_t FAR * png_sPLT_tp;
typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
@@ -337,21 +350,28 @@ typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
#ifdef PNG_TEXT_SUPPORTED
/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
* and whether that contents is compressed or not. The "key" field
* points to a regular C string. */
* points to a regular zero-terminated C string. The "text", "lang", and
* "lang_key" fields can be regular C strings, empty strings, or NULL pointers.
* However, the * structure returned by png_get_text() will always contain
* regular zero-terminated C strings (possibly empty), never NULL pointers,
* so they can be safely used in printf() and other string-handling functions.
*/
typedef struct png_text_struct
{
int compression; /* compression value:
-1: tEXt, none
0: zTXt, deflate
1: iTXt, none
2: iTXt, deflate */
int compression; /* compression value:
-1: tEXt, none
0: zTXt, deflate
1: iTXt, none
2: iTXt, deflate */
png_charp key; /* keyword, 1-79 character description of "text" */
png_charp text; /* comment, may be an empty string (ie "") */
png_charp text; /* comment, may be an empty string (ie "")
or a NULL pointer */
png_size_t text_length; /* length of the text string */
png_size_t itxt_length; /* length of the itxt string */
png_charp lang; /* language code, 1-79 characters */
png_charp lang; /* language code, 0-79 characters
or a NULL pointer */
png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
chars */
chars or a NULL pointer */
} png_text;
typedef png_text FAR * png_textp;
typedef png_text FAR * FAR * png_textpp;
@@ -429,16 +449,20 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
* The following members may have allocated storage attached that should be
* cleaned up before the structure is discarded: palette, trans, text,
* pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
* splt_palettes, scal_unit, and row_pointers. These are automatically
* freed when the info structure is deallocated.
* splt_palettes, scal_unit, row_pointers, and unknowns. By default, these are
* automatically freed when the info structure is deallocated, if they were
* allocated internally by libpng. This behavior can be changed by means
* of the png_data_freer() function.
*
* More allocation details: all the chunk-reading functions that change these
* members go through the corresponding png_set_* functions. Functions to
* clear these members are available: see png_free_*. The png_set_* functions
* do not depend on being able to point info structure members to any of the
* storage they are passed (they make their own copies), EXCEPT that the
* png_set_text function uses the same storage passed to them
* in the text_ptr or itxt_ptr structure argument.
* members go through the corresponding png_set_* functions. A function to
* clear these members is available: see png_free_data(). Some of the
* png_set_* functions do not depend on being able to point info structure
* members to any of the storage they are passed (they make their own copies),
* EXCEPT that the png_set_text functions use the same storage passed to them
* in the text_ptr or itxt_ptr structure argument, and the png_set_tRNS,
* png_set_PLTE, png_set_hIST, png_set_iCCP, png_set_rows, png_set_sPLT,
* and png_set_unknowns do not make their own copies.
*/
typedef struct png_info_struct
{
@@ -468,18 +492,13 @@ typedef struct png_info_struct
* and initialize the appropriate fields below.
*/
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#if defined(PNG_gAMA_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
#if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_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.
*/
#ifdef PNG_FLOATING_POINT_SUPPORTED
float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
#endif
png_fixed_point int_gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
#endif
#if defined(PNG_sRGB_SUPPORTED)
/* GR-P, 0.96a */
@@ -499,9 +518,6 @@ typedef struct png_info_struct
int num_text; /* number of comments read/to write */
int max_text; /* current size of text array */
png_textp text; /* array of comments read/to write */
int num_text_old; /* number of comments read/to write */
png_textp text_old; /* array of comments read/to write, backward
compatible with libpng-1.0.5 and earlier */
#endif /* PNG_TEXT_SUPPORTED */
#if defined(PNG_tIME_SUPPORTED)
@@ -577,7 +593,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
png_uint_16p hist;
#endif
#if defined(PNG_cHRM_SUPPORTED)
#ifdef PNG_cHRM_SUPPORTED
/* The cHRM chunk describes the CIE color characteristics of the monitor
* on which the PNG was created. This data allows the viewer to do gamut
* mapping of the input image to ensure that the viewer sees the same
@@ -594,16 +610,6 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
float x_blue;
float y_blue;
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
png_fixed_point int_x_white;
png_fixed_point int_y_white;
png_fixed_point int_x_red;
png_fixed_point int_y_red;
png_fixed_point int_x_green;
png_fixed_point int_y_green;
png_fixed_point int_x_blue;
png_fixed_point int_y_blue;
#endif
#endif
#if defined(PNG_pCAL_SUPPORTED)
@@ -628,6 +634,16 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
png_byte pcal_nparams; /* number of parameters given in pcal_params */
#endif
#ifdef PNG_FREE_ME_SUPPORTED
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* storage for unknown chunks that the library doesn't recognize. */
png_unknown_chunkp unknown_chunks;
png_size_t unknown_chunks_num;
#endif
#if defined(PNG_iCCP_SUPPORTED)
/* iCCP chunk data. */
png_charp iccp_name; /* profile name */
@@ -661,17 +677,27 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
#endif
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* storage for unknown chunks that the library doesn't recognize. */
png_unknown_chunkp unknown_chunks;
png_size_t unknown_chunks_num;
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
/* Data valid if (valid & PNG_INFO_IDAT) non-zero */
png_bytepp row_pointers; /* the image bits */
#endif
#if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
#endif
#if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
png_fixed_point int_x_white;
png_fixed_point int_y_white;
png_fixed_point int_x_red;
png_fixed_point int_y_red;
png_fixed_point int_x_green;
png_fixed_point int_y_green;
png_fixed_point int_x_blue;
png_fixed_point int_y_blue;
#endif
} png_info;
typedef png_info FAR * png_infop;
@@ -802,7 +828,8 @@ typedef void (*png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
typedef void (*png_user_transform_ptr) PNGARG((png_structp,
png_row_infop, png_bytep));
#endif
@@ -859,21 +886,18 @@ struct png_struct_def
png_user_transform_ptr write_user_transform_fn; /* user write transform */
#endif
/* These were added in libpng-1.0.2 */
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
png_voidp user_transform_ptr; /* user supplied struct for user transform */
png_byte user_transform_depth; /* bit depth of user transformed pixels */
png_byte user_transform_channels; /* channels in user transformed pixels */
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
png_voidp user_chunk_ptr;
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
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 free_me; /* flags items libpng is responsible for freeing */
png_uint_32 transformations; /* which transformations to perform */
z_stream zstream; /* pointer to decompression structure (below) */
@@ -921,14 +945,18 @@ struct png_struct_def
png_byte sig_bytes; /* magic bytes read/written from start of file */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
#ifdef PNG_LEGACY_SUPPORTED
png_byte filler; /* filler byte for pixel expansion */
#else
png_uint_16 filler; /* filler bytes for pixel expansion */
#endif
#endif
#if defined(PNG_READ_bKGD_SUPPORTED)
png_byte background_gamma_type;
#ifdef PNG_FLOATING_POINT_SUPPORTED
# ifdef PNG_FLOATING_POINT_SUPPORTED
float background_gamma;
#endif
# endif
png_color_16 background; /* background color in screen gamma space */
# if defined(PNG_READ_GAMMA_SUPPORTED)
png_color_16 background_1; /* background normalized to gamma 1.0 */
@@ -947,7 +975,6 @@ struct png_struct_def
float gamma; /* file gamma value */
float screen_gamma; /* screen gamma value (display_exponent) */
#endif
png_fixed_point int_gamma;
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
@@ -959,7 +986,7 @@ struct png_struct_def
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED)
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_sBIT_SUPPORTED)
png_color_8 sig_bit; /* significant bits in each available channel */
#endif
@@ -1039,6 +1066,22 @@ struct png_struct_def
png_free_ptr free_fn; /* function for freeing memory */
#endif
/* New members added in libpng-1.0.6 */
#ifdef PNG_FREE_ME_SUPPORTED
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
png_voidp user_chunk_ptr;
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
int num_chunk_list;
png_bytep chunk_list;
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
png_byte rgb_to_gray_status;
png_uint_16 rgb_to_gray_red_coeff;
@@ -1051,16 +1094,16 @@ struct png_struct_def
png_byte empty_plte_permitted;
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
int num_chunk_list;
png_bytep chunk_list;
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_fixed_point int_gamma;
#endif
};
/* This prevents a compiler error in png_get_copyright() in png.c if png.c
and png.h are both at * version 1.0.6a
and png.h are both at * version 1.0.6j
*/
typedef png_structp version_1_0_6a;
typedef png_structp version_1_0_6j;
typedef png_struct FAR * FAR * png_structpp;
@@ -1099,6 +1142,15 @@ extern PNG_EXPORT(png_structp,png_create_write_struct)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn));
extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_set_compression_buffer_size)
PNGARG((png_structp png_ptr, png_uint_32 size));
/* Reset the compression stream */
extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
#ifdef PNG_USER_MEM_SUPPORTED
extern PNG_EXPORT(png_structp,png_create_read_struct_2)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
@@ -1535,18 +1587,21 @@ extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
#endif
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_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
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_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
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
int user_transform_channels));
@@ -1592,22 +1647,32 @@ 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));
/* free data that was allocated internally */
/* Free data that was allocated internally */
extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 free_me, int num));
/* flags for png_ptr->free_me and info_ptr->free_me */
#define PNG_FREE_PLTE 0x0001
#define PNG_FREE_TRNS 0x0002
#define PNG_FREE_TEXT 0x0004
#ifdef PNG_FREE_ME_SUPPORTED
/* Reassign responsibility for freeing existing data, whether allocated
* by libpng or by the application */
extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
png_infop info_ptr, int freer, png_uint_32 mask));
#endif
/* assignments for png_data_freer */
#define PNG_DESTROY_WILL_FREE_DATA 1
#define PNG_SET_WILL_FREE_DATA 1
#define PNG_USER_WILL_FREE_DATA 2
/* Flags for png_ptr->free_me and info_ptr->free_me */
#define PNG_FREE_HIST 0x0008
#define PNG_FREE_ICCP 0x0010
#define PNG_FREE_SPLT 0x0020
#define PNG_FREE_ROWS 0x0040
#define PNG_FREE_PCAL 0x0080
#define PNG_FREE_SCAL 0x0100
#define PNG_FREE_PCAL 0x0080 /* not used any more */
#define PNG_FREE_SCAL 0x0100 /* not used any more */
#define PNG_FREE_UNKN 0x0200
#define PNG_FREE_LIST 0x0400
#define PNG_FREE_ALL 0x07ff
#define PNG_FREE_PLTE 0x1000
#define PNG_FREE_TRNS 0x2000
#define PNG_FREE_TEXT 0x4000
#define PNG_FREE_ALL 0x3fff
#ifdef PNG_USER_MEM_SUPPORTED
extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
@@ -1899,18 +1964,20 @@ extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_sPLT_tp entries, int nentries));
#endif
#if defined(PNG_TEXT_SUPPORTED)
extern PNG_EXPORT(void,png_set_itxt) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp text_ptr, int num_text));
#endif
#if defined(PNG_READ_TEXT_SUPPORTED)
/* Old interface; apps should use png_get_itxt instead */
/* png_get_text also returns the number of text chunks in *num_text */
extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp *text_ptr, int *num_text));
#endif
/*
* Note while png_set_text() will accept a structure whose text,
* language, and translated keywords are NULL pointers, the structure
* returned by png_get_text will always contain regular
* zero-terminated C strings. They might be empty strings but
* they will never be NULL pointers.
*/
#if defined(PNG_TEXT_SUPPORTED)
extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp text_ptr, int num_text));
@@ -1978,11 +2045,14 @@ extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
png_ptr, int keep, png_bytep chunk_list, int num_chunks));
extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
extern PNG_EXPORT(void, png_set_unknown_chunk_location)
PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* The "params" pointer is currently not used and is for future expansion. */
extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
png_infop info_ptr,
int transforms,
@@ -2025,7 +2095,7 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
#define png_debug2(l, m, p1, p2)
#endif
extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void));
extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
@@ -2033,7 +2103,7 @@ extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr)
extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.0.6a - April 2, 2000 (header)\n"
" libpng version 1.0.6j - May 4, 2000 (header)\n"
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
/* With these routines we avoid an integer divide, which will be slower on
@@ -2099,6 +2169,8 @@ extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
#define PNG_WROTE_tIME 0x200
#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
#define PNG_BACKGROUND_IS_GRAY 0x800
#define PNG_CREATED_READ_STRUCT 0x1000
#define PNG_CREATED_WRITE_STRUCT 0x2000
/* flags for the transformations the PNG library does on the image data */
#define PNG_BGR 0x0001
@@ -2149,8 +2221,11 @@ extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x1000
#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x2000
#define PNG_FLAG_FREE_PLTE 0x1000
#define PNG_FLAG_FREE_TRNS 0x2000
#define PNG_FLAG_FREE_HIST 0x4000
#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
/* For use in png_set_keep_unknown, png_handle_as_unknown */
#define HANDLE_CHUNK_AS_DEFAULT 0
@@ -2259,11 +2334,21 @@ PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
* (old interface - NOT DLL EXPORTED).
*/
extern void png_read_init PNGARG((png_structp png_ptr));
#define png_read_init(png_ptr) png_read_init_2(png_ptr, \
PNG_LIBPNG_VER_STRING, sizeof(png_struct), sizeof(png_info));
extern void png_read_init_2 PNGARG((png_structp png_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
png_info_size));
/* Initialize png_ptr struct for writing, and allocate any other memory.
* (old interface - NOT DLL EXPORTED).
*/
extern void png_write_init PNGARG((png_structp png_ptr));
#define png_write_init(png_ptr) png_write_init_2(png_ptr, \
PNG_LIBPNG_VER_STRING, sizeof(png_struct), sizeof(png_info));
extern void png_write_init_2 PNGARG((png_structp png_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
png_info_size));
/* Allocate memory for an internal libpng struct */
PNG_EXTERN png_voidp png_create_struct PNGARG((int type));

221
png_ptr.h Normal file
View File

@@ -0,0 +1,221 @@
struct png_struct_def
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf jmpbuf; /* used in png_error */
#endif
png_error_ptr error_fn; /* function for printing errors and aborting */
png_error_ptr warning_fn; /* function for printing warnings */
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 */
png_voidp io_ptr; /* ptr to application struct for I/O functions*/
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
png_user_transform_ptr read_user_transform_fn; /* user read transform */
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
png_user_transform_ptr write_user_transform_fn; /* user write transform */
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
png_voidp user_transform_ptr; /* user supplied struct for user transform */
png_byte user_transform_depth; /* bit depth of user transformed pixels */
png_byte user_transform_channels; /* channels in user transformed pixels */
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
png_voidp user_chunk_ptr;
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
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 */
z_stream zstream; /* pointer to decompression structure (below) */
png_bytep zbuf; /* buffer for zlib */
png_size_t zbuf_size; /* size of zbuf */
int zlib_level; /* holds zlib compression level */
int zlib_method; /* holds zlib compression method */
int zlib_window_bits; /* holds zlib compression window bits */
int zlib_mem_level; /* holds zlib compression memory level */
int zlib_strategy; /* holds zlib compression strategy */
png_uint_32 width; /* width of image in pixels */
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_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 */
png_bytep row_buf; /* buffer to save current (unfiltered) row */
png_bytep sub_row; /* buffer to save "sub" row when filtering */
png_bytep up_row; /* buffer to save "up" row when filtering */
png_bytep avg_row; /* buffer to save "avg" row when filtering */
png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
png_row_info row_info; /* used for transformation routines */
png_uint_32 idat_size; /* current IDAT size for read */
png_uint_32 crc; /* current chunk CRC value */
png_colorp palette; /* palette from the input file */
png_uint_16 num_palette; /* number of color entries in palette */
png_uint_16 num_trans; /* number of transparency values */
png_byte chunk_name[5]; /* null-terminated name of current chunk */
png_byte compression; /* file compression type (always 0) */
png_byte filter; /* file filter type (always 0) */
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
png_byte pass; /* current interlace pass (0 - 6) */
png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
png_byte color_type; /* color type of file */
png_byte bit_depth; /* bit depth of file */
png_byte usr_bit_depth; /* bit depth of users row */
png_byte pixel_depth; /* number of bits per pixel */
png_byte channels; /* number of channels in file */
png_byte usr_channels; /* channels at start of write */
png_byte sig_bytes; /* magic bytes read/written from start of file */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
png_uint_16 filler; /* filler bytes for pixel expansion */
#endif
#if defined(PNG_READ_bKGD_SUPPORTED)
png_byte background_gamma_type;
#ifdef PNG_FLOATING_POINT_SUPPORTED
float background_gamma;
#endif
png_color_16 background; /* background color in screen gamma space */
# if defined(PNG_READ_GAMMA_SUPPORTED)
png_color_16 background_1; /* background normalized to gamma 1.0 */
# endif /* PNG_READ_GAMMA && PNG_READ_bKGD_SUPPORTED */
#endif /* PNG_READ_bKGD_SUPPORTED */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
png_flush_ptr output_flush_fn;/* Function for flushing output */
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
png_uint_32 flush_rows; /* number of rows written since last flush */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
#ifdef PNG_FLOATING_POINT_SUPPORTED
float gamma; /* file gamma value */
float screen_gamma; /* screen gamma value (display_exponent) */
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_bytep gamma_table; /* gamma table for 8-bit depth files */
png_bytep gamma_from_1; /* converts from 1.0 to screen */
png_bytep gamma_to_1; /* converts from file to 1.0 */
png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED)
png_color_8 sig_bit; /* significant bits in each available channel */
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
png_color_8 shift; /* shift for significant bit tranformation */
#endif
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_bytep trans; /* transparency values for paletted files */
png_color_16 trans_values; /* transparency values for non-paletted files */
#endif
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 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 */
png_bytep current_buffer_ptr; /* current location in current_buffer */
png_bytep current_buffer; /* buffer for recently used data */
png_uint_32 push_length; /* size of current input chunk */
png_uint_32 skip_length; /* bytes to skip in input data */
png_size_t save_buffer_size; /* amount of data now in save_buffer */
png_size_t save_buffer_max; /* total size of save_buffer */
png_size_t buffer_size; /* total amount of available input data */
png_size_t current_buffer_size; /* amount of data now in current_buffer */
int process_mode; /* what push library is currently doing */
int cur_palette; /* current push library palette index */
# if defined(PNG_READ_TEXT_SUPPORTED)
png_size_t current_text_size; /* current size of text input data */
png_size_t current_text_left; /* how much text left to read in input */
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_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;
png_bytep offset_table;
png_uint_16 offset_table_number;
png_uint_16 offset_table_count;
png_uint_16 offset_table_count_free;
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
png_bytep palette_lookup; /* lookup table for dithering */
png_bytep dither_index; /* index translation for palette files */
#endif
#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 */
png_bytep prev_filters; /* filter type(s) of previous row(s) */
png_uint_16p filter_weights; /* weight(s) for previous line(s) */
png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
png_uint_16p filter_costs; /* relative filter calculation cost */
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_voidp mem_ptr; /* user supplied struct for mem functions */
png_malloc_ptr malloc_fn; /* function for allocating memory */
png_free_ptr free_fn; /* function for freeing memory */
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
png_byte rgb_to_gray_status;
png_uint_16 rgb_to_gray_red_coeff;
png_uint_16 rgb_to_gray_green_coeff;
png_uint_16 rgb_to_gray_blue_coeff;
#endif
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
png_byte empty_plte_permitted;
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
int num_chunk_list;
png_bytep chunk_list;
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_fixed_point int_gamma;
#endif
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
};

View File

@@ -1,6 +1,6 @@
/* pngasmrd.h - assembler version of utilities to read a PNG file
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1999, 2000 Glenn Randers-Pehrson
*

View File

@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -255,7 +255,7 @@
* things to happen if the library and/or application ever change.
*/
/* Any transformations you will not be using can be undef'ed here */
/* Any features you will not be using can be undef'ed here */
/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user
to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS
@@ -267,7 +267,44 @@
1.0.1c, for consistency)
*/
/* The following support, added after version 1.0.0, can be turned off here en
* masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility
* with old applications that require the length of png_struct and png_info
* to remain unchanged.
*/
#ifdef PNG_LEGACY_SUPPORTED
#define PNG_NO_FREE_ME
#define PNG_NO_READ_UNKNOWN_CHUNKS
#define PNG_NO_WRITE_UNKNOWN_CHUNKS
#define PNG_NO_READ_USER_CHUNKS
#define PNG_NO_READ_iCCP
#define PNG_NO_WRITE_iCCP
#define PNG_NO_READ_sCAL
#define PNG_NO_WRITE_sCAL
#define PNG_NO_READ_sPLT
#define PNG_NO_WRITE_sPLT
#define PNG_NO_INFO_IMAGE
#define PNG_NO_READ_RGB_TO_GRAY
#define PNG_NO_READ_USER_TRANSFORM
#define PNG_NO_WRITE_USER_TRANSFORM
#define PNG_NO_USER_MEM
#define PNG_NO_READ_EMPTY_PLTE
#endif
#ifndef PNG_NO_FLOATING_POINT_SUPPORTED
#define PNG_FLOATING_POINT_SUPPORTED
#endif
/* Ignore attempt to turn off both floating and fixed point support */
#ifndef PNG_FLOATING_POINT_SUPPORTED
#define PNG_FIXED_POINT_SUPPORTED
#endif
#ifndef PNG_NO_FREE_ME
#define PNG_FREE_ME_SUPPORTED
#endif
#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
!defined(PNG_NO_READ_TRANSFORMS)
@@ -342,9 +379,11 @@
/* still have interlacing unless you change the following line: */
#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
#ifndef PNG_NO_READ_COMPOSITED_NODIV
#ifndef PNG_NO_READ_COMPOSITE_NODIV
#ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel and SGI */
#endif
#endif
#ifndef PNG_NO_READ_EMPTY_PLTE
#define PNG_READ_EMPTY_PLTE_SUPPORTED /* useful for MNG applications */
@@ -383,11 +422,19 @@
#endif
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
#ifndef PNG_NO_USER_TRANSFORM_PTR
#define PNG_USER_TRANSFORM_PTR_SUPPORTED
#endif
#endif
#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
encoders, but can cause trouble
if left undefined */
#ifndef PNG_NO_WRITE_WEIGHTED_FILTER
#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
defined(PNG_FLOATING_POINT_SUPPORTED)
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif
@@ -428,14 +475,6 @@
#define PNG_ASSEMBLER_CODE_SUPPORTED
#endif
#ifndef PNG_NO_FLOATING_POINT_SUPPORTED
#define PNG_FLOATING_POINT_SUPPORTED
#endif
#ifndef PNG_NO_FIXED_POINT_SUPPORTED
#define PNG_FIXED_POINT_SUPPORTED
#endif
/* Do not use global arrays (helps with building DLL's)
* They are no longer used in libpng itself, since version 1.0.5c,
* but might be required for some pre-1.0.5c applications.
@@ -456,7 +495,9 @@
/* very little testing */
/*
#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
#ifndef PNG_NO_USER_MEM
#define PNG_USER_MEM_SUPPORTED
#endif
*/
/* This is only for PowerPC big-endian and 680x0 systems */
@@ -561,7 +602,17 @@
# define PNG_READ_zTXt_SUPPORTED
# define PNG_zTXt_SUPPORTED
#endif
#ifndef PNG_NO_READ_USER_CHUNKS
#ifndef PNG_NO_READ_UNKNOWN_CHUNKS
# define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
# define PNG_UNKNOWN_CHUNKS_SUPPORTED
# endif
# ifndef PNG_NO_HANDLE_AS_UNKNOWN
# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
# endif
#endif
#if !defined (PNG_NO_READ_USER_CHUNKS) && \
defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
# define PNG_READ_USER_CHUNKS_SUPPORTED
# define PNG_USER_CHUNKS_SUPPORTED
# ifdef PNG_NO_READ_UNKNOWN_CHUNKS
@@ -571,13 +622,6 @@
# undef PNG_NO_HANDLE_AS_UNKNOWN
# endif
#endif
#ifndef PNG_NO_READ_UNKNOWN_CHUNKS
# define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
# define PNG_UNKNOWN_CHUNKS_SUPPORTED
# ifndef PNG_NO_HANDLE_AS_UNKNOWN
# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
# endif
#endif
#ifndef PNG_NO_READ_OPT_PLTE
# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
#endif /* optional PLTE chunk in RGB and RGBA images */

View File

@@ -1,7 +1,7 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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

View File

@@ -6,7 +6,7 @@
* and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
* for Intel's performance analysis of the MMX vs. non-MMX code.
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, Intel Corporation
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -137,6 +137,12 @@ int mmxsupport(void);
static int mmx_supported = 2;
#ifdef PNG_USE_LOCAL_ARRAYS
static const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
static const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const int png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
#endif
// djgpp adds its own underscores to global variables, so define them without:
#ifdef __DJGPP__
# define _unmask unmask
@@ -4494,7 +4500,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
break;
default:
png_error(png_ptr, "Bad adaptive filter type");
png_error(png_ptr, "#103 Bad adaptive filter type");
break;
}
}

View File

@@ -1,7 +1,7 @@
/* pngget.c - retrieval of values from info struct
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -434,6 +434,7 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
return (0);
}
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point *int_file_gamma)
@@ -448,6 +449,7 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
return (0);
}
#endif
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
png_uint_32
@@ -801,3 +803,9 @@ png_get_user_chunk_ptr(png_structp png_ptr)
}
#endif
png_uint_32
png_get_compression_buffer_size(png_structp png_ptr)
{
return(png_ptr->zbuf_size);
}

View File

@@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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

View File

@@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -1336,12 +1336,14 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
if (!(png_ptr->chunk_name[0] & 0x20))
{
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
#endif
)
#endif
png_chunk_error(png_ptr, "unknown critical chunk");
/* to quiet compiler warnings about unused info_ptr */

View File

@@ -1,7 +1,7 @@
/* pngread.c - read a PNG file
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -86,6 +86,18 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
"Incompatible libpng version in application and library");
}
/* Libpng 1.0.6 was not binary compatible, due to insertion of the
info_ptr->free_me member. Note to maintainer: this test can be
removed from version 2.0.0 and beyond because the previous test
would have already rejected it. */
if (user_png_ver[4] == '6' && user_png_ver[2] == '0' &&
user_png_ver[0] == '1' && user_png_ver[5] == '\0')
{
png_error(png_ptr,
"Application must be recompiled; version 1.0.6 was incompatible");
}
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
@@ -108,20 +120,52 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_set_read_fn(png_ptr, NULL, NULL);
png_ptr->mode |= PNG_CREATED_READ_STRUCT;
return (png_ptr);
}
/* Initialize PNG structure for reading, and allocate any memory needed.
This interface is deprecated in favour of the png_create_read_struct(),
and it will eventually disappear. */
#undef png_read_init
void
png_read_init(png_structp png_ptr)
{
/* We only come here via pre-1.0.7-compiled applications */
png_read_init_2(png_ptr, "1.0.0", 10000, 10000);
}
void
png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size, png_size_t png_info_size)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
png_debug(1, "in png_read_init\n");
#ifndef PNG_LEGACY_SUPPORTED
int i=0;
do
{
if(user_png_ver[i] != png_libpng_ver[i])
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application uses deprecated png_read_init() and must be recompiled.");
}
} while (png_libpng_ver[i++]);
#endif
if(sizeof(png_struct) > png_struct_size ||
sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application and library have different sized structs. Please recompile.");
}
png_debug(1, "in png_read_init_2\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
@@ -157,6 +201,11 @@ png_read_init(png_structp png_ptr)
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL);
#ifdef PNG_LEGACY_SUPPORTED
if (user_png_ver)
return;
#endif
}
/* Read the information before the actual image data. This has been
@@ -641,7 +690,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
* not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6a.
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6j.
*/
void
@@ -690,7 +739,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
* only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6a.
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6j.
*/
void
png_read_image(png_structp png_ptr, png_bytepp image)
@@ -834,8 +883,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
*/
if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT)
png_error(png_ptr, "Too many IDAT's found");
else
png_crc_finish(png_ptr, 0);
png_crc_finish(png_ptr, length);
}
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length);
@@ -1014,19 +1062,37 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_from_1);
png_free(png_ptr, png_ptr->gamma_to_1);
#endif
#ifdef PNG_FREE_ME_SUPPORTED
if (png_ptr->free_me & PNG_FREE_PLTE)
png_zfree(png_ptr, png_ptr->palette);
png_ptr->free_me &= ~PNG_FREE_PLTE;
#else
if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
png_zfree(png_ptr, png_ptr->palette);
png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
#endif
#if defined(PNG_tRNS_SUPPORTED) || \
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
#ifdef PNG_FREE_ME_SUPPORTED
if (png_ptr->free_me & PNG_FREE_TRNS)
png_free(png_ptr, png_ptr->trans);
png_ptr->free_me &= ~PNG_FREE_TRNS;
#else
if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
png_free(png_ptr, png_ptr->trans);
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
#endif
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#ifdef PNG_FREE_ME_SUPPORTED
if (png_ptr->free_me & PNG_FREE_HIST)
png_free(png_ptr, png_ptr->hist);
png_ptr->free_me &= ~PNG_FREE_HIST;
#else
if (png_ptr->flags & PNG_FLAG_FREE_HIST)
png_free(png_ptr, png_ptr->hist);
png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table != NULL)
@@ -1219,15 +1285,29 @@ void png_read_png(png_structp png_ptr, png_infop info_ptr,
/* -------------- image transformations end here ------------------- */
if(info_ptr->row_pointers)
{
#ifdef PNG_FREE_ME_SUPPORTED
if(info_ptr->free_me & PNG_FREE_ROWS)
{
for (row = 0; row < (int)info_ptr->height; row++)
png_free(png_ptr, info_ptr->row_pointers[row]);
png_free(png_ptr, info_ptr->row_pointers);
info_ptr->row_pointers = NULL;
}
#endif
}
if(info_ptr->row_pointers == NULL)
{
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
info_ptr->height * sizeof(png_bytep));
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ROWS;
#endif
for (row = 0; row < (int)info_ptr->height; row++)
info_ptr->row_pointers[row] = png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr));
}
for (row = 0; row < (int)info_ptr->height; row++)
info_ptr->row_pointers[row] = png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr));
png_read_image(png_ptr, info_ptr->row_pointers);
info_ptr->valid |= PNG_INFO_IDAT;

View File

@@ -1,7 +1,7 @@
/* pngrio.c - functions for data input
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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

View File

@@ -1,7 +1,7 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -645,14 +645,23 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
}
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_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");
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
png_ptr->transformations |= PNG_USER_TRANSFORM;
png_ptr->read_user_transform_fn = read_user_transform_fn;
#endif
#ifdef PNG_LEGACY_SUPPORTED
if(read_user_transform_fn)
png_warning(png_ptr,
"This version of libpng does not support user transforms");
#endif
}
#endif
@@ -1079,7 +1088,8 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->channels++;
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
if(png_ptr->transformations & PNG_USER_TRANSFORM)
{
if(info_ptr->bit_depth < png_ptr->user_transform_depth)
@@ -1307,10 +1317,12 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
/* 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 */
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if(png_ptr->user_transform_depth)
png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
if(png_ptr->user_transform_channels)
png_ptr->row_info.channels = png_ptr->user_transform_channels;
#endif
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 *

View File

@@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -133,7 +133,7 @@ png_crc_error(png_structp png_ptr)
}
#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_sPLT_SUPPORTED)
defined(PNG_READ_iCCP_SUPPORTED)
/*
* Decompress trailing data in a chunk. The assumption is that chunkdata
* points at an allocated area holding the contents of a chunk with a
@@ -392,8 +392,9 @@ 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, (uInt)num, sizeof (png_color));
png_ptr->free_me |= PNG_FREE_PLTE;
for (i = 0; i < num; i++)
{
png_byte buf[3];
@@ -431,7 +432,6 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
else
{
png_chunk_warning(png_ptr, "CRC error");
png_ptr->free_me &= ~PNG_FREE_PLTE;
png_zfree(png_ptr, palette);
return;
}
@@ -445,17 +445,29 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif
png_ptr->palette = palette;
png_ptr->num_palette = (png_uint_16)num;
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
png_ptr->free_me |= PNG_FREE_PLTE;
#else
png_ptr->flags |= PNG_FLAG_FREE_PLTE;
#endif
png_set_PLTE(png_ptr, info_ptr, palette, num);
#if defined (PNG_READ_tRNS_SUPPORTED)
#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)
if (png_ptr->num_trans > (png_uint_16)num)
{
png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
png_ptr->num_trans = png_ptr->num_palette;
png_ptr->num_trans = (png_uint_16)num;
}
if (info_ptr->num_trans > (png_uint_16)num)
{
png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
info_ptr->num_trans = (png_uint_16)num;
}
}
}
@@ -543,7 +555,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO
#ifndef PNG_NO_STDIO
fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
#endif
return;
@@ -753,7 +765,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_warning(png_ptr,
"Ignoring incorrect cHRM value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO
#ifndef PNG_NO_STDIO
#ifdef PNG_FLOATING_POINT_SUPPORTED
fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
white_x, white_y, red_x, red_y);
@@ -765,7 +777,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
int_x_green, int_y_green, int_x_blue, int_y_blue);
#endif
#endif /* PNG_NO_CONSOLE_IO */
#endif /* PNG_NO_STDIO */
}
png_crc_finish(png_ptr, 0);
return;
@@ -841,14 +853,25 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
igamma=(int)info_ptr->int_gamma;
#else
# ifdef PNG_FLOATING_POINT_SUPPORTED
igamma=info_ptr->gamma * 100000.;
igamma=(int)(info_ptr->gamma * 100000.);
# endif
#endif
#if 0 && defined(PNG_cHRM_SUPPORTED) && !defined(PNG_FIXED_POINT_SUPPORTED)
/* We need to define these here because they aren't in png.h */
png_fixed_point int_x_white;
png_fixed_point int_y_white;
png_fixed_point int_x_red;
png_fixed_point int_y_red;
png_fixed_point int_x_green;
png_fixed_point int_y_green;
png_fixed_point int_x_blue;
png_fixed_point int_y_blue;
#endif
if(igamma < 45000L || igamma > 46000L)
{
png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO
#ifndef PNG_NO_STDIO
# ifdef PNG_FIXED_POINT_SUPPORTED
fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
# else
@@ -862,6 +885,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif /* PNG_READ_gAMA_SUPPORTED */
#ifdef PNG_READ_cHRM_SUPPORTED
#ifdef PNG_FIXED_POINT_SUPPORTED
if (info_ptr->valid & PNG_INFO_cHRM)
if (abs(info_ptr->int_x_white - 31270L) > 1000 ||
abs(info_ptr->int_y_white - 32900L) > 1000 ||
@@ -875,6 +899,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_warning(png_ptr,
"Ignoring incorrect cHRM value when sRGB is also present");
}
#endif /* PNG_FIXED_POINT_SUPPORTED */
#endif /* PNG_READ_cHRM_SUPPORTED */
png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
@@ -923,7 +948,6 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif
chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
png_ptr->free_me |= PNG_FREE_ICCP;
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
@@ -944,7 +968,8 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (profile >= chunkdata + slength)
{
png_free(png_ptr, chunkdata);
png_error(png_ptr, "malformed iCCP chunk");
png_warning(png_ptr, "malformed iCCP chunk");
return;
}
/* compression should always be zero */
@@ -1012,7 +1037,8 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (entry_start > chunkdata + slength)
{
png_free(png_ptr, chunkdata);
png_error(png_ptr, "malformed sPLT chunk");
png_warning(png_ptr, "malformed sPLT chunk");
return;
}
new_palette.depth = *entry_start++;
@@ -1103,7 +1129,6 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
png_ptr->trans = (png_bytep)png_malloc(png_ptr, length);
png_ptr->free_me |= PNG_FREE_TRNS;
png_crc_read(png_ptr, png_ptr->trans, (png_size_t)length);
png_ptr->num_trans = (png_uint_16)length;
}
@@ -1149,6 +1174,12 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (png_crc_finish(png_ptr, 0))
return;
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
png_ptr->free_me |= PNG_FREE_TRNS;
#else
png_ptr->flags |= PNG_FLAG_FREE_TRNS;
#endif
png_set_tRNS(png_ptr, info_ptr, png_ptr->trans, png_ptr->num_trans,
&(png_ptr->trans_values));
}
@@ -1283,7 +1314,6 @@ 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,
(png_uint_32)(num * sizeof (png_uint_16)));
png_ptr->free_me |= PNG_FREE_HIST;
for (i = 0; i < num; i++)
{
png_byte buf[2];
@@ -1295,6 +1325,12 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (png_crc_finish(png_ptr, 0))
return;
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
png_ptr->free_me |= PNG_FREE_HIST;
#else
png_ptr->flags |= PNG_FLAG_FREE_HIST;
#endif
png_set_hIST(png_ptr, info_ptr, png_ptr->hist);
}
#endif
@@ -1554,7 +1590,10 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#ifdef PNG_FLOATING_POINT_SUPPORTED
width = strtod(ep, &vp);
if (*vp)
png_error(png_ptr, "malformed width string in sCAL chunk");
{
png_warning(png_ptr, "malformed width string in sCAL chunk");
return;
}
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
swidth = (png_charp)png_malloc(png_ptr, strlen(ep) + 1);
@@ -1569,7 +1608,10 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#ifdef PNG_FLOATING_POINT_SUPPORTED
height = strtod(ep, &vp);
if (*vp)
png_error(png_ptr, "malformed height string in sCAL chunk");
{
png_warning(png_ptr, "malformed height string in sCAL chunk");
return;
}
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
sheight = (png_charp)png_malloc(png_ptr, strlen(ep) + 1);
@@ -1907,12 +1949,14 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (!(png_ptr->chunk_name[0] & 0x20))
{
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
#endif
)
#endif
png_chunk_error(png_ptr, "unknown critical chunk");
}
@@ -2814,7 +2858,8 @@ png_read_start_row(png_structp png_ptr)
}
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if(png_ptr->transformations & PNG_USER_TRANSFORM)
{
int user_pixel_depth=png_ptr->user_transform_depth*

View File

@@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -123,7 +123,9 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
#ifdef PNG_FLOATING_POINT_SUPPORTED
info_ptr->gamma = (float)(int_gamma/100000.);
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
info_ptr->int_gamma = int_gamma;
#endif
info_ptr->valid |= PNG_INFO_gAMA;
}
@@ -421,19 +423,29 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charp name, int compression_type,
png_charp profile, png_uint_32 proflen)
{
png_charp new_iccp_name;
png_charp new_iccp_profile;
png_debug1(1, "in %s storage function\n", "iCCP");
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
return;
info_ptr->iccp_name = png_malloc(png_ptr, png_strlen(name)+1);
strcpy(info_ptr->iccp_name, name);
info_ptr->iccp_profile = png_malloc(png_ptr, proflen);
png_memcpy(info_ptr->iccp_profile, profile, (png_size_t)proflen);
new_iccp_name = png_malloc(png_ptr, png_strlen(name)+1);
strcpy(new_iccp_name, name);
new_iccp_profile = png_malloc(png_ptr, proflen);
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
info_ptr->iccp_proflen = proflen;
info_ptr->iccp_name = new_iccp_name;
info_ptr->iccp_profile = new_iccp_profile;
/* Compression is always zero but is here so the API and info structure
* does not have to change * if we introduce multiple compression types */
* does not have to change if we introduce multiple compression types */
info_ptr->iccp_compression = (png_byte)compression_type;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ICCP;
#endif
info_ptr->valid |= PNG_INFO_iCCP;
}
#endif
@@ -494,8 +506,14 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
if(text_ptr[i].compression > 0)
{
/* set iTXt data */
lang_len = png_strlen(text_ptr[i].lang);
lang_key_len = png_strlen(text_ptr[i].lang_key);
if (text_ptr[i].key != (png_charp)NULL)
lang_len = png_strlen(text_ptr[i].lang);
else
lang_len = 0;
if (text_ptr[i].lang_key != (png_charp)NULL)
lang_key_len = png_strlen(text_ptr[i].lang_key);
else
lang_key_len = 0;
}
else
{
@@ -503,7 +521,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
lang_key_len = 0;
}
if (text_ptr[i].text[0] == '\0')
if (text_ptr[i].text == (png_charp)NULL || text_ptr[i].text[0] == '\0')
{
text_length = 0;
if(text_ptr[i].compression > 0)
@@ -537,19 +555,15 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
}
else
{
textp->lang=NULL;
textp->lang_key=NULL;
textp->lang=(png_charp)NULL;
textp->lang_key=(png_charp)NULL;
textp->text=textp->key + key_len + 1;
}
if(text_length)
{
png_memcpy(textp->text, text_ptr[i].text,
(png_size_t)(text_length));
*(textp->text+text_length) = '\0';
}
else
textp->text--;
*(textp->text+text_length) = '\0';
if(textp->compression > 0)
{
@@ -564,7 +578,9 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->text[info_ptr->num_text]= *textp;
info_ptr->num_text++;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TEXT;
#endif
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
}
}
@@ -642,7 +658,9 @@ png_set_sPLT(png_structp png_ptr,
info_ptr->splt_palettes = np;
info_ptr->splt_palettes_num += nentries;
info_ptr->valid |= PNG_INFO_sPLT;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_SPLT;
#endif
}
#endif /* PNG_sPLT_SUPPORTED */
@@ -681,7 +699,17 @@ png_set_unknown_chunks(png_structp png_ptr,
info_ptr->unknown_chunks = np;
info_ptr->unknown_chunks_num += num_unknowns;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_UNKN;
#endif
}
void
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
int chunk, int location)
{
if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
(int)info_ptr->unknown_chunks_num)
info_ptr->unknown_chunks[chunk].location = (png_byte)location;
}
#endif
@@ -731,7 +759,9 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
*p=(png_byte)keep;
png_ptr->num_chunk_list=old_num_chunks+num_chunks;
png_ptr->chunk_list=new_list;
#ifdef PNG_FREE_ME_SUPPORTED
png_ptr->free_me |= PNG_FREE_LIST;
#endif
}
#endif
@@ -754,8 +784,21 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->row_pointers = row_pointers;
info_ptr->free_me |= PNG_FREE_ROWS;
if(info_ptr->row_pointers != row_pointers)
{
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
info_ptr->row_pointers = row_pointers;
}
}
#endif
void
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
{
if(png_ptr->zbuf)
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = (png_size_t)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}

View File

@@ -1,7 +1,7 @@
/* pngtest.c - a simple test program to test libpng
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -687,11 +687,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
}
}
#if defined(PNG_FIXED_POINT_SUPPORTED)
#if defined(PNG_cHRM_SUPPORTED)
{
png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
blue_y;
if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
&red_y, &green_x, &green_y, &blue_x, &blue_y))
{
@@ -710,6 +710,32 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
}
#endif
#else /* Use floating point versions */
#if defined(PNG_FLOATING_POINT_SUPPORTED)
#if defined(PNG_cHRM_SUPPORTED)
{
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
blue_y;
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
&red_y, &green_x, &green_y, &blue_x, &blue_y))
{
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
red_y, green_x, green_y, blue_x, blue_y);
}
}
#endif
#if defined(PNG_gAMA_SUPPORTED)
{
double gamma;
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
{
png_set_gAMA(write_ptr, write_info_ptr, gamma);
}
}
#endif
#endif /* floating point */
#endif /* fixed point */
#if defined(PNG_iCCP_SUPPORTED)
{
png_charp name;
@@ -893,7 +919,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
generated locations in write_info_ptr are wrong because we
haven't written anything yet */
for (i = 0; i < (png_size_t)num_unknowns; i++)
write_info_ptr->unknown_chunks[i].location = unknowns[i].location;
png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
unknowns[i].location);
}
}
#endif
@@ -1007,8 +1034,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
generated locations in write_end_info_ptr are wrong because we
haven't written the end_info yet */
for (i = 0; i < (png_size_t)num_unknowns; i++)
write_end_info_ptr->unknown_chunks[i].location =
unknowns[i].location;
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
unknowns[i].location);
}
}
#endif
@@ -1128,6 +1155,8 @@ main(int argc, char *argv[])
fprintf(STDERR," library:%s",png_get_header_version(NULL));
/* Show the version of libpng used in building the application */
fprintf(STDERR," pngtest:%s",PNG_HEADER_VERSION_STRING);
fprintf(STDERR," sizeof(png_struct)=%d, sizeof(png_info)=%d\n",
sizeof(png_struct), sizeof(png_info));
/* 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
@@ -1200,7 +1229,10 @@ main(int argc, char *argv[])
#endif
for (i=2; i<argc; ++i)
{
int k, kerror;
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
int k;
#endif
int kerror;
fprintf(STDERR, "Testing %s:",argv[i]);
kerror = test_one_file(argv[i], outname);
if (kerror == 0)
@@ -1270,7 +1302,9 @@ main(int argc, char *argv[])
{
if(verbose == 1 || i == 2)
{
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
int k;
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
#else
@@ -1344,4 +1378,4 @@ main(int argc, char *argv[])
}
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_0_6a your_png_h_is_not_version_1_0_6a;
typedef version_1_0_6j your_png_h_is_not_version_1_0_6j;

View File

@@ -1,7 +1,7 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -571,16 +571,24 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
void
png_set_user_transform_info(png_structp png_ptr, png_voidp
user_transform_ptr, int user_transform_depth, int user_transform_channels)
{
png_debug(1, "in png_set_user_transform_info\n");
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
png_ptr->user_transform_ptr = user_transform_ptr;
png_ptr->user_transform_depth = (png_byte)user_transform_depth;
png_ptr->user_transform_channels = (png_byte)user_transform_channels;
#else
if(user_transform_ptr || user_transform_depth || user_transform_channels)
png_warning(png_ptr,
"This version of libpng does not support user transform info");
#endif
}
#endif
/* This function returns a pointer to the user_transform_ptr associated with
* the user transform functions. The application should free any memory
@@ -590,6 +598,11 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp
png_voidp
png_get_user_transform_ptr(png_structp png_ptr)
{
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
return ((png_voidp)png_ptr->user_transform_ptr);
}
#else
if(png_ptr)
return (NULL);
return (NULL);
#endif
}

View File

@@ -2,7 +2,7 @@
*
* For Intel x86 CPU and Microsoft Visual C++ compiler
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, Intel Corporation
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson

View File

@@ -1,7 +1,7 @@
/* pngwio.c - functions for data output
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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

View File

@@ -1,7 +1,7 @@
/* pngwrite.c - general routines to write a PNG file
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -468,6 +468,19 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
"Incompatible libpng version in application and library");
}
/* Libpng 1.0.6 was not binary compatible, due to insertion of the
info_ptr->free_me member. Note to maintainer: this test can be
removed from version 2.0.0 and beyond because the previous test
would have already rejected it. */
if (user_png_ver[4] == '6' && user_png_ver[2] == '0' &&
user_png_ver[0] == '1' && user_png_ver[5] == '\0')
{
png_error(png_ptr,
"Application must be recompiled; version 1.0.6 was incompatible");
}
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
@@ -480,18 +493,49 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
1, NULL, NULL);
#endif
png_ptr->mode |= PNG_CREATED_WRITE_STRUCT;
return ((png_structp)png_ptr);
}
/* Initialize png_ptr structure, and allocate any memory needed */
#undef png_write_init
void
png_write_init(png_structp png_ptr)
{
/* We only come here via pre-1.0.7-compiled applications */
png_write_init_2(png_ptr, "1.0.0", 10000, 10000);
}
void
png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size, png_size_t png_info_size)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
#ifndef PNG_LEGACY_SUPPORTED
int i = 0;
do
{
if (user_png_ver[i] != png_libpng_ver[i])
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application uses deprecated png_write_init() and must be recompiled.");
}
} while (png_libpng_ver[i++]);
#endif
if (sizeof(png_struct) > png_struct_size ||
sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application and library have different sized structs. Please recompile.");
}
png_debug(1, "in png_write_init_2\n");
png_debug(1, "in png_write_init\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
@@ -515,6 +559,11 @@ png_write_init(png_structp png_ptr)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, NULL, NULL);
#endif
#ifdef PNG_LEGACY_SUPPORTED
if (user_png_ver)
return;
#endif
}
/* Write a few rows of image data. If the image is interlaced,
@@ -804,11 +853,13 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
{
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->num_chunk_list=0;
}
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn);

View File

@@ -1,7 +1,7 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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

View File

@@ -1,7 +1,7 @@
/* pngwutil.c - utilities to write a PNG file
*
* libpng 1.0.6a - April 2, 2000
* libpng 1.0.6j - May 4, 2000
* 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
@@ -167,7 +167,7 @@ png_text_compress(png_structp png_ptr,
{
comp->input = text;
comp->input_len = text_len;
return(text_len);
return((int)text_len);
}
if (compression >= PNG_TEXT_COMPRESSION_LAST)
@@ -314,7 +314,7 @@ png_text_compress(png_structp png_ptr,
if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
return(text_len);
return((int)text_len);
}
/* ship the compressed text out via chunk writes */
@@ -647,8 +647,8 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
profile_len = 0;
if (profile_len)
profile_len = png_text_compress(png_ptr, profile, profile_len,
PNG_TEXT_COMPRESSION_zTXt, &comp);
profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
PNG_TEXT_COMPRESSION_zTXt, &comp);
/* make sure we include the NULL after the name and the compression type */
png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
@@ -1204,7 +1204,8 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
png_free(png_ptr, new_key);
/* compute the compressed data; do it now for the length */
text_len = png_text_compress(png_ptr, text, text_len, compression, &comp);
text_len = png_text_compress(png_ptr, text, text_len, compression,
&comp);
/* write start of chunk */
png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, (png_uint_32)
@@ -1256,7 +1257,8 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
text_len = 0;
/* compute the compressed data; do it now for the length */
text_len = png_text_compress(png_ptr, text, text_len, compression-2, &comp);
text_len = png_text_compress(png_ptr, text, text_len, compression-2,
&comp);
/* make sure we include the compression flag, the compression byte,
* and the NULs after the key, lang, and lang_key parts */

View File

@@ -31,7 +31,7 @@ RANLIB=ranlib
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.6a
PNGMIN = 1.0.6j
PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h

View File

@@ -14,7 +14,7 @@ ZLIBINC=../zlib
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.6a
PNGMIN = 1.0.6j
PNGVER = $(PNGMAJ).$(PNGMIN)
CC=cc

View File

@@ -34,7 +34,7 @@ RANLIB=ranlib
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.6a
PNGMIN = 1.0.6j
PNGVER = $(PNGMAJ).$(PNGMIN)
INCPATH=$(prefix)/include

114
scripts/makefile.intel Normal file
View File

@@ -0,0 +1,114 @@
# Makefile for libpng
# Microsoft Visual C++ with Intel C/C++ Compiler 4.0 and later
# Copyright (C) 2000, Pawel Mrochen, based on makefile.msc which is
# copyright 1995 Guy Eric Schalnat, Group 42, Inc.
# For conditions of distribution and use, see copyright notice in png.h
# To use, do "nmake /f scripts\makefile.intel"
# ------------------- Intel C/C++ Compiler 4.0 and later -------------------
# Caution: the assembler code was introduced at libpng version 1.0.4 and has
# not yet been thoroughly tested.
# Use assembler code
ASMCODE=-DPNG_USE_PNGVCRD
# Where the zlib library and include files are located
ZLIBLIB=..\zlib
ZLIBINC=..\zlib
# Target CPU
CPU=6 # Pentium II
#CPU=5 # Pentium
# Calling convention
CALLING=r # __fastcall
#CALLING=z # __stdcall
#CALLING=d # __cdecl
# Uncomment next to put error messages in a file
#ERRFILE=>>pngerrs
# --------------------------------------------------------------------------
CC=icl -c
CFLAGS=-O2 -G$(CPU)$(CALLING) -Qip -Qunroll4 -I$(ZLIBINC) $(ASMCODE) -nologo
LD=link
LDFLAGS=/SUBSYSTEM:CONSOLE /NOLOGO
O=.obj
OBJS=png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)\
pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)\
pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O) pngvcrd$(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)
pngvcrd$(O): png.h pngconf.h pngasmrd.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: $(OBJS)
if exist libpng.lib del libpng.lib
lib /NOLOGO /OUT:libpng.lib $(OBJS)
pngtest.exe: pngtest.obj libpng.lib
$(LD) $(LDFLAGS) /OUT:pngtest.exe pngtest.obj libpng.lib $(ZLIBLIB)\zlib.lib
test: pngtest.exe
pngtest.exe
# End of makefile for libpng

View File

@@ -34,7 +34,7 @@ RANLIB=ranlib
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.6a
PNGMIN = 1.0.6j
PNGVER = $(PNGMAJ).$(PNGMIN)
INCPATH=$(prefix)/include

View File

@@ -25,7 +25,7 @@ RANLIB=echo
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.6a
PNGMIN = 1.0.6j
PNGVER = $(PNGMAJ).$(PNGMIN)
INCPATH=$(prefix)/include

View File

@@ -19,8 +19,8 @@ CFLAGS=-I$(ZLIBINC) -O2 $(WARNMORE) -fPIC -mabi=n32 # -g -DPNG_DEBUG=5
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
LDSHARED=gcc -shared
VER=1.0.6a
LIBS=libpng.so.1.0.6a
VER=1.0.6j
LIBS=libpng.so.1.0.6j
SHAREDLIB=libpng.so
libdir=$(prefix)/lib32

View File

@@ -31,7 +31,7 @@ RANLIB=echo
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.6a
PNGMIN = 1.0.6j
PNGVER = $(PNGMAJ).$(PNGMIN)
INCPATH=$(prefix)/include

View File

@@ -1,28 +1,48 @@
# Makefile for libpng
# Watcom 10.0 and later 32-bit protected mode flat memory model
# Watcom C/C++ 10.0 and later, 32-bit protected mode, flat memory model
# Adapted by Pawel Mrochen, based on makefile.msc
# Copyright (C) 2000, Pawel Mrochen, based on makefile.msc which is
# copyright 1995 Guy Eric Schalnat, Group 42, Inc.
# 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 scripts\makefile.watcom"
# ------------- Watcom 10.0 and later -------------
MODEL=-mf
CFLAGS= $(MODEL) -5r -fp5 -fpi87 -oneatx -i=..\zlib
# ---------------------- Watcom C/C++ 10.0 and later -----------------------
# Where the zlib library and include files are located
ZLIBLIB=..\zlib
ZLIBINC=..\zlib
# Target OS
OS=DOS
#OS=NT
# Target CPU
CPU=6 # Pentium Pro
#CPU=5 # Pentium
# Calling convention
CALLING=r # registers
#CALLING=s # stack
# Uncomment next to put error messages in a file
#ERRFILE=>>pngerrs
# --------------------------------------------------------------------------
CC=wcc386
CFLAGS=-$(CPU)$(CALLING) -fp$(CPU) -fpi87 -oneatx -mf -bt=$(OS) -i=$(ZLIBINC) -zq
LD=wcl386
LIB=wlib -b -c
LDFLAGS=
LDFLAGS=-zq
O=.obj
#uncomment next to put error messages in a file
#ERRFILE= >> pngerrs
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)
# 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
@@ -75,14 +95,15 @@ 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)
wlib -b -c -n -q libpng.lib $(OBJS1)
wlib -b -c -q libpng.lib $(OBJS2)
wlib -b -c -q libpng.lib $(OBJS3)
pngtest.exe: pngtest.obj libpng.lib
$(LD) $(LDFLAGS) pngtest.obj libpng.lib ..\zlib\zlib.lib
$(LD) $(LDFLAGS) pngtest.obj libpng.lib $(ZLIBLIB)\zlib.lib
test: pngtest.exe .symbolic
pngtest
pngtest.exe
# End of makefile for libpng

View File

@@ -3,7 +3,7 @@ unit pngdef;
interface
const
PNG_LIBPNG_VER_STRING = '1.0.6a';
PNG_LIBPNG_VER_STRING = '1.0.6j';
PNG_LIBPNG_VER = 10007;
type