Imported from libpng-1.0.1e.tar

This commit is contained in:
Glenn Randers-Pehrson 1998-06-06 15:31:35 -05:00
parent 8686fff347
commit f7d1a17033
33 changed files with 782 additions and 258 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.0.1d May 21, 1998 Libpng 1.0.1e - June 6, 1998
This is not intended to be a public release. It will be replaced 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. within a few weeks by a public version or by another test version.
@ -36,7 +36,7 @@ version 1.0.1c [May 11, 1998]
Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
filler bytes should have been 0xff instead of 0xf. filler bytes should have been 0xff instead of 0xf.
Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images. Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
Moved PNG_WRIGHT_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED, Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
for consistency, in pngconf.h for consistency, in pngconf.h
@ -44,10 +44,9 @@ version 1.0.1c [May 11, 1998]
to make it easier to remove unwanted capabilities via the compile line to make it easier to remove unwanted capabilities via the compile line
Made some corrections to grammar (which, it's) in documentation (Greg). Made some corrections to grammar (which, it's) in documentation (Greg).
Corrected example.c, use of row_pointers in png_write_image(). Corrected example.c, use of row_pointers in png_write_image().
version 1.0.1d [May 21, 1998] version 1.0.1d [May 24, 1998]
Corrected several statements that some compilers interpret as illegal use Corrected several statements that used side effects illegally in pngrutil.c
of side effects in pngrutil.c and pngtrans.c, that were introduced in and pngtrans.c, that were introduced in version 1.0.1b
version 1.0.1b
Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert) Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
More corrections to example.c, use of row_pointers in png_write_image() More corrections to example.c, use of row_pointers in png_write_image()
and png_read_rows(). and png_read_rows().
@ -55,6 +54,21 @@ version 1.0.1d [May 21, 1998]
Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5 Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.) Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
Changed several loops from count-down to count-up, for consistency. Changed several loops from count-down to count-up, for consistency.
version 1.0.1e [June 5, 1998]
Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
added warnings when people try to set png_read_fn and png_write_fn in
the same structure.
Added a test such that png_do_gamma will be done when num_trans==0
for truecolor images that have defined a background. This corrects an
error that was introduced in libpng-0.90 that can cause gamma processing
to be skipped.
Added tests in png.h to include "trans" and "trans_values" in structures
when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined.
Add png_free(png_ptr->time_buffer) in png_destroy_read_struct()
Moved png_convert_to_rfc_1123() from pngwrite.c to png.c
Added capability for user-provided malloc_fn() and free_fn() functions,
and revised pngtest.c to demonstrate their use, replacing the
PNGTEST_DEBUG_MEM feature.
Send comments/corrections/commendations to Send comments/corrections/commendations to
png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu

24
CHANGES
View File

@ -316,7 +316,7 @@ version 1.0.1c [May 11, 1998]
Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
filler bytes should have been 0xff instead of 0xf. filler bytes should have been 0xff instead of 0xf.
Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images. Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
Moved PNG_WRIGHT_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED, Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
for consistency, in pngconf.h for consistency, in pngconf.h
@ -324,10 +324,9 @@ version 1.0.1c [May 11, 1998]
to remove unwanted capabilities via the compile line to remove unwanted capabilities via the compile line
Made some corrections to grammar (which, it's) in documentation (Greg). Made some corrections to grammar (which, it's) in documentation (Greg).
Corrected example.c, use of row_pointers in png_write_image(). Corrected example.c, use of row_pointers in png_write_image().
version 1.0.1d [May 21, 1998] version 1.0.1d [May 24, 1998]
Corrected several statements that some compilers interpret as illegal use Corrected several statements that used side effects illegally in pngrutil.c
of side effects in pngrutil.c and pngtrans.c, that were introduced in and pngtrans.c, that were introduced in version 1.0.1b
version 1.0.1b
Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert) Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
More corrections to example.c, use of row_pointers in png_write_image() More corrections to example.c, use of row_pointers in png_write_image()
and png_read_rows(). and png_read_rows().
@ -335,3 +334,18 @@ version 1.0.1d [May 21, 1998]
Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5 Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.) Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
Changed several loops from count-down to count-up, for consistency. Changed several loops from count-down to count-up, for consistency.
version 1.0.1e [June 6, 1998]
Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
added warnings when people try to set png_read_fn and png_write_fn in
the same structure.
Added a test such that png_do_gamma will be done when num_trans==0
for truecolor images that have defined a background. This corrects an
error that was introduced in libpng-0.90 that can cause gamma processing
to be skipped.
Added tests in png.h to include "trans" and "trans_values" in structures
when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined.
Add png_free(png_ptr->time_buffer) in png_destroy_read_struct()
Moved png_convert_to_rfc_1123() from pngwrite.c to png.c
Added capability for user-provided malloc_fn() and free_fn() functions,
and revised pngtest.c to demonstrate their use, replacing the
PNGTEST_DEBUG_MEM feature.

View File

@ -1,5 +1,5 @@
Installing libpng version %VER% %DATE% Installing libpng version 1.0.1e - June 6, 1998
Before installing libpng, you must first install zlib. zlib Before installing libpng, you must first install zlib. zlib
can usually be found wherever you got libpng. zlib can be 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. version of zlib that's installed.
You can rename the directories that you downloaded (they You can rename the directories that you downloaded (they
might be called "libpng-%VER% or "lpng100" and "zlib-1.1.2" might be called "libpng-1.0.1e" or "lpng102" and "zlib-1.1.2"
or "zlib112") so that you have directories called "zlib" and "libpng". or "zlib112") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this: Your directory structure should look like this:

View File

@ -184,3 +184,13 @@ Known bugs and suggested enhancements in libpng-1.0.1
STATUS: STATUS:
Added to distribution in libpng-1.0.1d Added to distribution in libpng-1.0.1d
20. May 26, 1998 -- BUG -- png_do_gamma is skipped -- Magnus Holmgren
When a background color is defined for a truecolor image, but no
transparent color is defined, gamma correction is not done.
The test in pngrtran should include " && !png_ptr->trans_values"
STATUS:
Fixed in libpng-1.0.1e

2
README
View File

@ -1,4 +1,4 @@
README for libpng %VER% (shared library 2.1) README for libpng 1.0.1e - June 6, 1998 (shared library 2.1)
See the note about version numbers near the top of png.h See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng. See INSTALL for instructions on how to install libpng.

2
TODO
View File

@ -1,7 +1,6 @@
TODO - list of things to do for libpng TODO - list of things to do for libpng
fix problem with C++ and EXTERN "C" fix problem with C++ and EXTERN "C"
add capability to set user malloc/free functions at run time
add "grayscale->palette" transformation and "palette->grayscale" detection add "grayscale->palette" transformation and "palette->grayscale" detection
color to gray transformation color to gray transformation
improved dithering improved dithering
@ -21,3 +20,4 @@ support for application-defined chunk handlers
keep up with public chunks keep up with public chunks
better C++ wrapper/full C++ implementation? better C++ wrapper/full C++ implementation?
text conversion between different code pages (Latin-1 -> Mac and DOS) text conversion between different code pages (Latin-1 -> Mac and DOS)
improve API by hiding the info_ptr

View File

@ -1,6 +1,6 @@
.TH LIBPNG 3 "May 21, 1998" .TH LIBPNG 3 "June 6, 1998"
.SH NAME .SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library libpng \- Portable Network Graphics (PNG) Reference Library 1.0.1e - June 6, 1998
.SH SYNOPSIS .SH SYNOPSIS
#include <png.h> #include <png.h>
@ -27,11 +27,19 @@ png_structp png_create_read_struct (png_const_charp
user_png_ver, voidp error_ptr, png_error_ptr error_fn, user_png_ver, voidp error_ptr, png_error_ptr error_fn,
png_error_ptr warn_fn); png_error_ptr warn_fn);
png_create_read_struct_2(png_const_charp user_png_ver,
png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr
warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn,
png_free_ptr free_fn)
png_structp png_create_write_struct (png_const_charp png_structp png_create_write_struct (png_const_charp
user_png_ver, voidp error_ptr, png_error_ptr error_fn, user_png_ver, voidp error_ptr, png_error_ptr error_fn,
png_error_ptr warn_fn); png_error_ptr warn_fn);
void png_debug_free (png_structp png_ptr, png_voidp ptr); png_structp png_create_write_struct_2(png_const_charp
user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
png_voidp png_debug_malloc (png_structp png_ptr, png_uint_32 png_voidp png_debug_malloc (png_structp png_ptr, png_uint_32
size); size);
@ -49,6 +57,8 @@ void png_error (png_structp png_ptr, png_const_charp error);
void png_free (png_structp png_ptr, png_voidp ptr); void png_free (png_structp png_ptr, png_voidp ptr);
void png_free_default(png_structp png_ptr, png_voidp ptr)
png_byte png_get_bit_depth (png_structp png_ptr, png_infop png_byte png_get_bit_depth (png_structp png_ptr, png_infop
info_ptr); info_ptr);
@ -80,6 +90,11 @@ info_ptr, double *file_gamma);
png_uint_32 png_get_hIST (png_structp png_ptr, png_infop png_uint_32 png_get_hIST (png_structp png_ptr, png_infop
info_ptr, png_uint_16p *hist); info_ptr, png_uint_16p *hist);
png_uint_32 png_get_IHDR (png_structp png_ptr, png_infop
info_ptr, png_uint_32 *width, png_uint_32 *height, int
*bit_depth, int *color_type, int *interlace_type, int
*compression_type, int *filter_type);
png_uint_32 png_get_image_height (png_structp png_ptr, png_uint_32 png_get_image_height (png_structp png_ptr,
png_infop info_ptr); png_infop info_ptr);
@ -91,10 +106,7 @@ info_ptr);
png_voidp png_get_io_ptr (png_structp png_ptr); png_voidp png_get_io_ptr (png_structp png_ptr);
png_uint_32 png_get_IHDR (png_structp png_ptr, png_infop png_voidp png_get_mem_ptr(png_structp png_ptr)
info_ptr, png_uint_32 *width, png_uint_32 *height, int
*bit_depth, int *color_type, int *interlace_type, int
*compression_type, int *filter_type);
png_uint_32 png_get_oFFs (png_structp png_ptr, png_infop png_uint_32 png_get_oFFs (png_structp png_ptr, png_infop
info_ptr, png_uint_32 *offset_x, png_uint_32 *offset_y, int info_ptr, png_uint_32 *offset_x, png_uint_32 *offset_y, int
@ -168,6 +180,9 @@ void png_init_io (png_structp png_ptr, FILE *fp);
png_voidp png_malloc (png_structp png_ptr, png_uint_32 size); png_voidp png_malloc (png_structp png_ptr, png_uint_32 size);
png_voidp png_malloc_default(png_structp png_ptr,
png_uint_32 size)
voidp png_memcpy (png_voidp s1, png_voidp s2, png_size_t size); voidp png_memcpy (png_voidp s1, png_voidp s2, png_size_t size);
png_voidp png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp png_memcpy_check (png_structp png_ptr, png_voidp s1,
@ -276,6 +291,9 @@ png_uint_32 width, png_uint_32 height, int bit_depth, int
color_type, int interlace_type, int compression_type, int color_type, int interlace_type, int compression_type, int
filter_type); filter_type);
void png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
void png_set_oFFs (png_structp png_ptr, png_infop info_ptr, void png_set_oFFs (png_structp png_ptr, png_infop info_ptr,
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type); png_uint_32 offset_x, png_uint_32 offset_y, int unit_type);
@ -302,10 +320,10 @@ void png_set_read_fn (png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr read_data_fn); png_rw_ptr read_data_fn);
void png_set_read_status_fn (png_structp png_ptr, png_read_status_ptr void png_set_read_status_fn (png_structp png_ptr, png_read_status_ptr
read_row_fn); read_row_fn);
void png_set_read_user_transform_fn (png_structp png_ptr, void png_set_read_user_transform_fn (png_structp png_ptr,
png_user_transform_ptr read_user_transform_fn); png_user_transform_ptr read_user_transform_fn);
void png_set_rgb_to_gray (png_structp png_ptr); void png_set_rgb_to_gray (png_structp png_ptr);
@ -344,10 +362,10 @@ void png_set_write_fn (png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn); png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn);
void png_set_write_status_fn (png_structp png_ptr, png_write_status_ptr void png_set_write_status_fn (png_structp png_ptr, png_write_status_ptr
write_row_fn); write_row_fn);
void png_set_write_user_transform_fn (png_structp png_ptr, void png_set_write_user_transform_fn (png_structp png_ptr,
png_user_transform_ptr write_user_transform_fn); png_user_transform_ptr write_user_transform_fn);
int png_sig_cmp (png_bytep sig, png_size_t start, png_size_t int png_sig_cmp (png_bytep sig, png_size_t start, png_size_t
num_to_check); num_to_check);
@ -375,7 +393,7 @@ void png_write_destroy_info (png_infop info_ptr);
void png_write_end (png_structp png_ptr, png_infop info_ptr); void png_write_end (png_structp png_ptr, png_infop info_ptr);
void png_write_flush (png_structp png_ptr); void png_write_flush (png_structp png_ptr);
void png_write_image (png_structp png_ptr, png_bytepp image); void png_write_image (png_structp png_ptr, png_bytepp image);
void png_write_info (png_structp png_ptr, png_infop info_ptr); void png_write_info (png_structp png_ptr, png_infop info_ptr);
@ -396,7 +414,7 @@ Following is a copy of the libpng.txt file that accompanies libpng.
.SH LIBPNG.TXT .SH LIBPNG.TXT
libpng.txt - A description on how to use and modify libpng libpng.txt - A description on how to use and modify libpng
libpng version 1.0.1d May 21, 1998 libpng version 1.0.1e - June 6, 1998
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu> <randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson Copyright (c) 1998, Glenn Randers-Pehrson
@ -560,10 +578,21 @@ on Changes to Libpng below regarding the old initialization functions.
return; return;
} }
If you want to use your own memory allocation routines,
define PNG_USER_MEM_SUPPORTED and use
png_create_read_struct_2() instead of png_create_read_struct():
The error handling routines passed to png_create_read_struct() are only png_structp png_ptr = png_create_read_struct_2
necessary if you are not using the libpng supplied error handling (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
functions. When libpng encounters an error, it expects to longjmp back user_error_fn, user_warning_fn, (png_voidp)
user_mem_ptr, user_malloc_fn, user_free_fn);
The error handling routines passed to png_create_read_struct()
and the memory alloc/free routines passed to png_create_struct_2()
are only necessary if you are not using the libpng supplied error
handling and memory alloc/free functions.
When libpng encounters an error, it expects to longjmp back
to your routine. Therefore, you will need to call setjmp and pass the to your routine. Therefore, you will need to call setjmp and pass the
jmpbuf field of your png_struct. If you read the file from different jmpbuf field of your png_struct. If you read the file from different
routines, you will need to update the jmpbuf field every time you enter routines, you will need to update the jmpbuf field every time you enter
@ -1454,6 +1483,15 @@ both "png_ptr"; you can call them anything you like, such as
return; return;
} }
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_structp png_ptr = png_create_write_struct_2
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn, (png_voidp)
user_mem_ptr, user_malloc_fn, user_free_fn);
After you have these structures, you will need to set up the After you have these structures, you will need to set up the
error handling. When libpng encounters an error, it expects to error handling. When libpng encounters an error, it expects to
longjmp() back to your routine. Therefore, you will need to call longjmp() back to your routine. Therefore, you will need to call
@ -2001,14 +2039,15 @@ time, instead of calling the png_init_io() function. These functions
also provide a void pointer that can be retrieved via the function also provide a void pointer that can be retrieved via the function
png_get_io_ptr(). For example: png_get_io_ptr(). For example:
png_set_read_fn(png_structp png_ptr, png_set_read_fn(png_structp read_ptr,
voidp io_ptr, png_rw_ptr read_data_fn) voidp read_io_ptr, png_rw_ptr read_data_fn)
png_set_write_fn(png_structp png_ptr, png_set_write_fn(png_structp write_ptr,
voidp io_ptr, png_rw_ptr write_data_fn, voidp write_io_ptr, png_rw_ptr write_data_fn,
png_flush_ptr output_flush_fn); png_flush_ptr output_flush_fn);
voidp io_ptr = png_get_io_ptr(png_ptr); 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 should have prototypes as follows:
@ -2020,7 +2059,7 @@ The replacement I/O functions should have prototypes as follows:
Supplying NULL for the read, write, or flush functions sets them back Supplying NULL for the read, write, or flush functions sets them back
to using the default C stream functions. It is an error to read from to using the default C stream functions. It is an error to read from
a write stream, and vice versa. a write stream, and vice versa.
Error handling in libpng is done through png_error() and png_warning(). Error handling in libpng is done through png_error() and png_warning().
Errors handled through png_error() are fatal, meaning that png_error() Errors handled through png_error() are fatal, meaning that png_error()
@ -2374,7 +2413,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation. Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.0.1d May 21, 1998: Libpng version 1.0.1e - June 6, 1998:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc. Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (randeg@alumni.rpi.edu). Currently maintained by Glenn Randers-Pehrson (randeg@alumni.rpi.edu).

View File

@ -1,6 +1,6 @@
libpng.txt - A description on how to use and modify libpng libpng.txt - A description on how to use and modify libpng
libpng version 1.0.1d May 21, 1998 libpng version 1.0.1e - June 6, 1998
Updated and distributed by Glenn Randers-Pehrson Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu> <randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson Copyright (c) 1998, Glenn Randers-Pehrson
@ -164,10 +164,21 @@ on Changes to Libpng below regarding the old initialization functions.
return; return;
} }
If you want to use your own memory allocation routines,
define PNG_USER_MEM_SUPPORTED and use
png_create_read_struct_2() instead of png_create_read_struct():
The error handling routines passed to png_create_read_struct() are only png_structp png_ptr = png_create_read_struct_2
necessary if you are not using the libpng supplied error handling (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
functions. When libpng encounters an error, it expects to longjmp back user_error_fn, user_warning_fn, (png_voidp)
user_mem_ptr, user_malloc_fn, user_free_fn);
The error handling routines passed to png_create_read_struct()
and the memory alloc/free routines passed to png_create_struct_2()
are only necessary if you are not using the libpng supplied error
handling and memory alloc/free functions.
When libpng encounters an error, it expects to longjmp back
to your routine. Therefore, you will need to call setjmp and pass the to your routine. Therefore, you will need to call setjmp and pass the
jmpbuf field of your png_struct. If you read the file from different jmpbuf field of your png_struct. If you read the file from different
routines, you will need to update the jmpbuf field every time you enter routines, you will need to update the jmpbuf field every time you enter
@ -1058,6 +1069,15 @@ both "png_ptr"; you can call them anything you like, such as
return; return;
} }
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_structp png_ptr = png_create_write_struct_2
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn, (png_voidp)
user_mem_ptr, user_malloc_fn, user_free_fn);
After you have these structures, you will need to set up the After you have these structures, you will need to set up the
error handling. When libpng encounters an error, it expects to error handling. When libpng encounters an error, it expects to
longjmp() back to your routine. Therefore, you will need to call longjmp() back to your routine. Therefore, you will need to call
@ -1605,14 +1625,15 @@ time, instead of calling the png_init_io() function. These functions
also provide a void pointer that can be retrieved via the function also provide a void pointer that can be retrieved via the function
png_get_io_ptr(). For example: png_get_io_ptr(). For example:
png_set_read_fn(png_structp png_ptr, png_set_read_fn(png_structp read_ptr,
voidp io_ptr, png_rw_ptr read_data_fn) voidp read_io_ptr, png_rw_ptr read_data_fn)
png_set_write_fn(png_structp png_ptr, png_set_write_fn(png_structp write_ptr,
voidp io_ptr, png_rw_ptr write_data_fn, voidp write_io_ptr, png_rw_ptr write_data_fn,
png_flush_ptr output_flush_fn); png_flush_ptr output_flush_fn);
voidp io_ptr = png_get_io_ptr(png_ptr); 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 should have prototypes as follows:
@ -1624,7 +1645,7 @@ The replacement I/O functions should have prototypes as follows:
Supplying NULL for the read, write, or flush functions sets them back Supplying NULL for the read, write, or flush functions sets them back
to using the default C stream functions. It is an error to read from to using the default C stream functions. It is an error to read from
a write stream, and vice versa. a write stream, and vice versa.
Error handling in libpng is done through png_error() and png_warning(). Error handling in libpng is done through png_error() and png_warning().
Errors handled through png_error() are fatal, meaning that png_error() Errors handled through png_error() are fatal, meaning that png_error()

View File

@ -1,6 +1,6 @@
.TH LIBPNGPF 3 "May 21, 1998" .TH LIBPNGPF 3 "June 6, 1998"
.SH NAME .SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library libpng \- Portable Network Graphics (PNG) Reference Library 1.0.1e - June 6, 1998
(private functions) (private functions)
.SH SYNOPSIS .SH SYNOPSIS
#include <png.h> #include <png.h>
@ -31,10 +31,15 @@ int png_crc_finish (png_structp png_ptr, png_uint_32 skip);
void png_crc_read (png_structp png_ptr, png_bytep buf, void png_crc_read (png_structp png_ptr, png_bytep buf,
png_size_t length); png_size_t length);
png_voidp png_create_struct (int type); png_voidp png_create_struct (int type, png_malloc_ptr malloc_fn);
png_voidp png_create_struct_2 (int type);
void png_destroy_struct (png_voidp struct_ptr); void png_destroy_struct (png_voidp struct_ptr);
void png_destroy_struct_2 (png_voidp struct_ptr, png_free_ptr
free_fn);
void png_do_background (png_row_infop row_info, png_bytep row, void png_do_background (png_row_infop row_info, png_bytep row,
png_color_16p trans_values, png_color_16p background, png_color_16p trans_values, png_color_16p background,
png_color_16p background_1, png_bytep gamma_table, png_bytep png_color_16p background_1, png_bytep gamma_table, png_bytep

2
png.5
View File

@ -1,4 +1,4 @@
.TH PNG 5 "May 21, 1998" .TH PNG 5 "June 6, 1998"
.SH NAME .SH NAME
png \- Portable Network Graphics (PNG) format png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION .SH DESCRIPTION

63
png.c
View File

@ -1,12 +1,11 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@ -16,7 +15,7 @@
/* Version information for C files. This had better match the version /* Version information for C files. This had better match the version
* string defined in png.h. * string defined in png.h.
*/ */
char png_libpng_ver[12] = "1.0.1d"; char png_libpng_ver[12] = "1.0.1e";
/* Place to hold the signature string for a PNG file. */ /* Place to hold the signature string for a PNG file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
@ -128,12 +127,10 @@ png_check_sig(png_bytep sig, int num)
voidpf voidpf
png_zalloc(voidpf png_ptr, uInt items, uInt size) png_zalloc(voidpf png_ptr, uInt items, uInt size)
{ {
png_voidp ptr; png_uint_32 num_bytes = (png_uint_32)items * size;
png_uint_32 num_bytes; png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
num_bytes = (png_uint_32)items * size; if (num_bytes > (png_uint_32)0x8000L)
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
if (num_bytes > (png_uint_32)0x8000)
{ {
png_memset(ptr, 0, (png_size_t)0x8000L); png_memset(ptr, 0, (png_size_t)0x8000L);
png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0, png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
@ -201,7 +198,12 @@ png_create_info_struct(png_structp png_ptr)
png_debug(1, "in png_create_info_struct\n"); png_debug(1, "in png_create_info_struct\n");
if(png_ptr == NULL) return (NULL); if(png_ptr == NULL) return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
png_ptr->malloc_fn)) != NULL)
#else
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL) if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
#endif
{ {
png_info_init(info_ptr); png_info_init(info_ptr);
} }
@ -227,7 +229,11 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
{ {
png_info_destroy(png_ptr, info_ptr); png_info_destroy(png_ptr, info_ptr);
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn);
#else
png_destroy_struct((png_voidp)info_ptr); png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL; *info_ptr_ptr = (png_infop)NULL;
} }
} }
@ -252,11 +258,10 @@ void
png_info_destroy(png_structp png_ptr, png_infop info_ptr) png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{ {
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED) #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
int i;
png_debug(1, "in png_info_destroy\n"); png_debug(1, "in png_info_destroy\n");
if (info_ptr->text != NULL) if (info_ptr->text != NULL)
{ {
int i;
for (i = 0; i < info_ptr->num_text; i++) for (i = 0; i < info_ptr->num_text; i++)
{ {
png_free(png_ptr, info_ptr->text[i].key); png_free(png_ptr, info_ptr->text[i].key);
@ -269,6 +274,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_free(png_ptr, info_ptr->pcal_units); png_free(png_ptr, info_ptr->pcal_units);
if (info_ptr->pcal_params != NULL) if (info_ptr->pcal_params != NULL)
{ {
int i;
for (i = 0; i < (int)info_ptr->pcal_nparams; i++) for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{ {
png_free(png_ptr, info_ptr->pcal_params[i]); png_free(png_ptr, info_ptr->pcal_params[i]);
@ -302,3 +308,40 @@ png_init_io(png_structp png_ptr, FILE *fp)
png_ptr->io_ptr = (png_voidp)fp; png_ptr->io_ptr = (png_voidp)fp;
} }
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
/* Convert the supplied time into an RFC 1123 string suitable for use in
* a "Creation Time" or other text-based time string.
*/
png_charp
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
{
static PNG_CONST char short_months[12][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if (png_ptr->time_buffer == NULL)
{
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
sizeof(char)));
}
#ifdef USE_FAR_KEYWORD
{
char near_time_buf[29];
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
png_memcpy(png_ptr->time_buffer, near_time_buf,
29*sizeof(char));
}
#else
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
#endif
return ((png_charp)png_ptr->time_buffer);
}
#endif /* PNG_TIME_RFC1123_SUPPORTED */

101
png.h
View File

@ -1,12 +1,11 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see the COPYRIGHT NOTICE below. * For conditions of distribution and use, see the COPYRIGHT NOTICE below.
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998 Glenn Randers-Pehrson * Copyright (c) 1998 Glenn Randers-Pehrson
* May 21, 1998
* *
* Note about libpng version numbers: * Note about libpng version numbers:
* *
@ -16,24 +15,22 @@
* The following table summarizes matters since version 0.89c, which was * The following table summarizes matters since version 0.89c, which was
* the first widely used release: * the first widely used release:
* *
* source png.h png.h shared-lib * source png.h png.h shared-lib
* version string int version * version string int version
* ------- ------ ----- ---------- * ------- ------ ----- ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89 * 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.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.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.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.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.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98 * 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99 * 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99 * 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [int should be 10000] * 1.00 1.00 100 2.1.0 [int should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000] * 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
* 1.0.1 1.0.1 10001 2.1.0 * 1.0.1 1.0.1 10001 2.1.0
* 1.0.1a 1.0.1a 10002 2.1.0.1a * 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
* 1.0.1b 1.0.1b 10002 2.1.0.1b
* 1.0.1c 1.0.1c 10002 2.1.0.1c
* *
* Henceforth the source version will match the shared-library minor * Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be * and patch numbers; the shared-library major version number will be
@ -120,7 +117,7 @@ extern "C" {
*/ */
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.0.1d" #define PNG_LIBPNG_VER_STRING "1.0.1e"
/* Careful here. At one time, Guy wanted to use 082, but that would be octal. /* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros. * We must not include leading zeros.
@ -314,7 +311,8 @@ typedef struct png_info_struct
*/ */
png_color_8 sig_bit; /* significant bits in color channels */ png_color_8 sig_bit; /* significant bits in color channels */
#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */ #endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) #if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) || \
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
/* The tRNS chunk supplies transparency data for paletted images and /* The tRNS chunk supplies transparency data for paletted images and
* other image types that don't need a full alpha channel. There are * other image types that don't need a full alpha channel. There are
* "num_trans" transparency values for a paletted image, stored in the * "num_trans" transparency values for a paletted image, stored in the
@ -520,6 +518,9 @@ typedef void (*png_user_transform_ptr) PNGARG((png_structp,
png_row_infop, png_bytep)); png_row_infop, png_bytep));
#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */ #endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
typedef void (*png_free_ptr) PNGARG((png_structp, png_structp));
/* The structure that holds the information to read and write PNG files. /* The structure that holds the information to read and write PNG files.
* The only people who need to care about what is inside of this are the * The only people who need to care about what is inside of this are the
* people who will be modifying the library for their own special needs. * people who will be modifying the library for their own special needs.
@ -607,7 +608,7 @@ struct png_struct_def
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ 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 */ png_uint_32 flush_rows; /* number of rows written since last flush */
#endif /* PNG_WRITE_FLUSH_SUPPORTED */ #endif /* PNG_WRITE_FLUSH_SUPPORTED */
#if defined(PNG_READ_GAMMA_SUPPORTED) #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */ int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
float gamma; /* file gamma value */ float gamma; /* file gamma value */
float screen_gamma; /* screen gamma value (display_gamma/viewing_gamma */ float screen_gamma; /* screen gamma value (display_gamma/viewing_gamma */
@ -626,10 +627,11 @@ struct png_struct_def
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
png_color_8 shift; /* shift for significant bit tranformation */ png_color_8 shift; /* shift for significant bit tranformation */
#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */ #endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) #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_bytep trans; /* transparency values for paletted files */
png_color_16 trans_values; /* transparency values for non-paletted files */ png_color_16 trans_values; /* transparency values for non-paletted files */
#endif /* PNG_READ_tRNS_SUPPORTED || PNG_READ_BACKGROUND_SUPPORTED */ #endif /* PNG_READ|WRITE_tRNS_SUPPORTED||PNG_READ_EXPAND|BACKGROUND_SUPPORTED */
png_read_status_ptr read_row_fn; /* called after each row is decoded */ 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 */ png_write_status_ptr write_row_fn; /* called after each row is encoded */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
@ -682,6 +684,11 @@ struct png_struct_def
#if defined(PNG_TIME_RFC1123_SUPPORTED) #if defined(PNG_TIME_RFC1123_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1123 time text */ png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif /* PNG_TIME_RFC1123_SUPPORTED */ #endif /* PNG_TIME_RFC1123_SUPPORTED */
#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 /* PNG_USER_MEM_SUPPORTED */
}; };
typedef png_struct FAR * FAR * png_structpp; typedef png_struct FAR * FAR * png_structpp;
@ -716,11 +723,22 @@ extern PNG_EXPORT(png_structp,png_create_read_struct)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn)); png_error_ptr error_fn, png_error_ptr warn_fn));
/* Allocate and initialize png_ptr struct for reading, and any other memory */ /* Allocate and initialize png_ptr struct for writing, and any other memory */
extern PNG_EXPORT(png_structp,png_create_write_struct) extern PNG_EXPORT(png_structp,png_create_write_struct)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn)); png_error_ptr error_fn, png_error_ptr warn_fn));
#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,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn));
extern PNG_EXPORT(png_structp,png_create_write_struct_2)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn));
#endif
/* Write a PNG chunk - size, type, (optional) data, CRC. */ /* Write a PNG chunk - size, type, (optional) data, CRC. */
extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
png_bytep chunk_name, png_bytep data, png_size_t length)); png_bytep chunk_name, png_bytep data, png_size_t length));
@ -1114,6 +1132,15 @@ extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
png_write_status_ptr write_row_fn)); png_write_status_ptr write_row_fn));
#ifdef PNG_USER_MEM_SUPPORTED
/* Replace the default memory allocation functions with user supplied one(s). */
extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
/* Return the user pointer associated with the memory functions */
extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
#endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
png_ptr, png_user_transform_ptr read_user_transform_fn)); png_ptr, png_user_transform_ptr read_user_transform_fn));
@ -1154,19 +1181,19 @@ extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
/* frees a pointer allocated by png_malloc() */ /* frees a pointer allocated by png_malloc() */
extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr)); extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
#ifdef PNG_USER_MEM_SUPPORTED
extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
png_uint_32 size));
extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
png_voidp ptr));
#endif /* PNG_USER_MEM_SUPPORTED */
extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr, extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
png_voidp s1, png_voidp s2, png_uint_32 size)); png_voidp s1, png_voidp s2, png_uint_32 size));
extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr, extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
png_voidp s1, int value, png_uint_32 size)); png_voidp s1, int value, png_uint_32 size));
#ifdef PNGTEST_MEMORY_DEBUG
/* debugging versions of png_malloc() and png_free() */
extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
png_uint_32 size));
extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
png_voidp ptr));
#endif
#if defined(USE_FAR_KEYWORD) /* memory model conversion function */ #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
int check)); int check));
@ -1650,6 +1677,11 @@ PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
/* free memory from internal libpng struct */ /* free memory from internal libpng struct */
PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
malloc_fn));
PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
png_free_ptr free_fn));
/* free any memory that info_ptr points to and reset struct. */ /* free any memory that info_ptr points to and reset struct. */
PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
png_infop info_ptr)); png_infop info_ptr));
@ -1765,7 +1797,8 @@ PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
int num_hist)); int num_hist));
#endif #endif
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
defined(PNG_WRITE_pCAL_SUPPORTED)
PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
png_charp key, png_charpp new_key)); png_charp key, png_charpp new_key));
#endif #endif

View File

@ -1,12 +1,11 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
/* Any machine specific code is near the front of this file, so if you /* Any machine specific code is near the front of this file, so if you
@ -400,6 +399,7 @@ __dont__ include it again
/* very little testing */ /* very little testing */
/* /*
#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED #define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
#define PNG_USER_MEM_SUPPORTED
*/ */
/* This is only for PowerPC big-endian and 680x0 systems */ /* This is only for PowerPC big-endian and 680x0 systems */
@ -663,6 +663,7 @@ typedef z_stream FAR * png_zstreamp;
# define NOCHECK 0 # define NOCHECK 0
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
# define png_strcpy _fstrcpy
# define png_strlen _fstrlen # define png_strlen _fstrlen
# define png_memcmp _fmemcmp /* SJT: added */ # define png_memcmp _fmemcmp /* SJT: added */
# define png_memcpy _fmemcpy # define png_memcpy _fmemcpy
@ -670,6 +671,7 @@ typedef z_stream FAR * png_zstreamp;
#else /* use the usual functions */ #else /* use the usual functions */
# define CVT_PTR(ptr) (ptr) # define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr) # define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strcpy strcpy
# define png_strlen strlen # define png_strlen strlen
# define png_memcmp memcmp /* SJT: added */ # define png_memcmp memcmp /* SJT: added */
# define png_memcpy memcpy # define png_memcpy memcpy

View File

@ -1,12 +1,11 @@
/* pngerror.c - stub functions for i/o and memory allocation /* pngerror.c - stub functions for i/o and memory allocation
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This file provides a location for all error handling. Users who * This file provides a location for all error handling. Users who
* need special error handling are expected to write replacement functions * need special error handling are expected to write replacement functions

View File

@ -1,12 +1,11 @@
/* pngget.c - retrieval of values from info struct /* pngget.c - retrieval of values from info struct
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@ -302,11 +301,11 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
} }
return (retval); return (retval);
} }
#endif #endif /* PNG_READ_pHYs_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS */ #endif /* PNG_INCH_CONVERSIONS */
/* png_get_channels really belongs in here, too, but it's been around longer */ /* png_get_channels really belongs in here, too, but it's been around longer */
#endif /* PNG_EASY_ACCESS_SUPPORTED */ #endif /* PNG_EASY_ACCESS_SUPPORTED */
png_byte png_byte

193
pngmem.c
View File

@ -1,12 +1,11 @@
/* pngmem.c - stub functions for memory allocation /* pngmem.c - stub functions for memory allocation
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This file provides a location for all memory allocation. Users who * This file provides a location for all memory allocation. Users who
* need special memory handling are expected to modify the code in this file * need special memory handling are expected to modify the code in this file
@ -16,16 +15,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
/* The following "hides" PNG_MALLOC and PNG_FREE thus allowing the pngtest
application to put a wrapper on top of them. */
#ifdef PNGTEST_MEMORY_DEBUG
#define PNG_MALLOC png_debug_malloc
#define PNG_FREE png_debug_free
#else
#define PNG_MALLOC png_malloc
#define PNG_FREE png_free
#endif
/* Borland DOS special memory handler */ /* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* if you change this, be sure to change the one in png.h also */ /* if you change this, be sure to change the one in png.h also */
@ -35,6 +24,15 @@
png_voidp png_voidp
png_create_struct(int type) png_create_struct(int type)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size; png_size_t size;
png_voidp struct_ptr; png_voidp struct_ptr;
@ -45,11 +43,18 @@ png_create_struct(int type)
else else
return ((png_voidp)NULL); return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL) if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
{ {
png_memset(struct_ptr, 0, size); png_memset(struct_ptr, 0, size);
} }
return (struct_ptr); return (struct_ptr);
} }
@ -58,8 +63,27 @@ png_create_struct(int type)
void void
png_destroy_struct(png_voidp struct_ptr) png_destroy_struct(png_voidp struct_ptr)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
#endif
if (struct_ptr != NULL) if (struct_ptr != NULL)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
if(free_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
(*(free_fn))(png_ptr, struct_ptr);
struct_ptr = NULL;
return;
}
#endif /* PNG_USER_MEM_SUPPORTED */
farfree (struct_ptr); farfree (struct_ptr);
struct_ptr = NULL; struct_ptr = NULL;
} }
@ -85,12 +109,27 @@ png_destroy_struct(png_voidp struct_ptr)
* (which should cause a fatal error) and introducing major problems. * (which should cause a fatal error) and introducing major problems.
*/ */
png_voidp png_voidp
PNG_MALLOC(png_structp png_ptr, png_uint_32 size) png_malloc(png_structp png_ptr, png_uint_32 size)
{ {
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret; png_voidp ret;
#endif
if (png_ptr == NULL || size == 0) if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL); return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
else
return png_malloc_default(png_ptr, size);
}
png_voidp
png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
#endif PNG_USER_MEM_SUPPORTED
#ifdef PNG_MAX_MALLOC_64K #ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L) if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K"); png_error(png_ptr, "Cannot Allocate > 64K");
@ -181,15 +220,30 @@ PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
return (ret); return (ret);
} }
/* free a pointer allocated by PNG_MALLOC(). In the default /* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed in case it configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */ is needed. If ptr is NULL, return without taking any action. */
void void
PNG_FREE(png_structp png_ptr, png_voidp ptr) png_free(png_structp png_ptr, png_voidp ptr)
{ {
if (png_ptr == NULL || ptr == NULL) if (png_ptr == NULL || ptr == NULL)
return; return;
#ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->free_fn != NULL)
{
(*(png_ptr->free_fn))(png_ptr, ptr);
ptr = NULL;
return;
}
else png_free_default(png_ptr, ptr);
}
void
png_free_default(png_structp png_ptr, png_voidp ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (png_ptr->offset_table != NULL) if (png_ptr->offset_table != NULL)
{ {
int i; int i;
@ -227,6 +281,17 @@ PNG_FREE(png_structp png_ptr, png_voidp ptr)
png_voidp png_voidp
png_create_struct(int type) png_create_struct(int type)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
}
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/
png_voidp
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size; png_size_t size;
png_voidp struct_ptr; png_voidp struct_ptr;
@ -237,6 +302,15 @@ png_create_struct(int type)
else else
return ((png_voidp)NULL); return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__) #if defined(__TURBOC__) && !defined(__FLAT__)
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL) if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
#else #else
@ -258,15 +332,37 @@ png_create_struct(int type)
void void
png_destroy_struct(png_voidp struct_ptr) png_destroy_struct(png_voidp struct_ptr)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (struct_ptr != NULL) if (struct_ptr != NULL)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
if(free_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
(*(free_fn))(png_ptr, struct_ptr);
struct_ptr = NULL;
return;
}
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__) #if defined(__TURBOC__) && !defined(__FLAT__)
farfree(struct_ptr); farfree(struct_ptr);
struct_ptr = NULL;
#else #else
# if defined(_MSC_VER) && defined(MAXSEG_64K) # if defined(_MSC_VER) && defined(MAXSEG_64K)
hfree(struct_ptr); hfree(struct_ptr);
struct_ptr = NULL;
# else # else
free(struct_ptr); free(struct_ptr);
struct_ptr = NULL;
# endif # endif
#endif #endif
} }
@ -280,13 +376,26 @@ png_destroy_struct(png_voidp struct_ptr)
have the ability to do that. */ have the ability to do that. */
png_voidp png_voidp
PNG_MALLOC(png_structp png_ptr, png_uint_32 size) png_malloc(png_structp png_ptr, png_uint_32 size)
{ {
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret; png_voidp ret;
#endif
if (png_ptr == NULL || size == 0) if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL); return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
else
return (png_malloc_default(png_ptr, size));
}
png_voidp
png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
#endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_MAX_MALLOC_64K #ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L) if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K"); png_error(png_ptr, "Cannot Allocate > 64K");
@ -310,22 +419,38 @@ PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
return (ret); return (ret);
} }
/* Free a pointer allocated by PNG_MALLOC(). In the default /* Free a pointer allocated by png_malloc(). If ptr is NULL, return
configuration, png_ptr is not used, but is passed in case it without taking any action. */
is needed. If ptr is NULL, return without taking any action. */
void void
PNG_FREE(png_structp png_ptr, png_voidp ptr) png_free(png_structp png_ptr, png_voidp ptr)
{ {
if (png_ptr == NULL || ptr == NULL) if (png_ptr == NULL || ptr == NULL)
return; return;
#ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->free_fn != NULL)
{
(*(png_ptr->free_fn))(png_ptr, ptr);
ptr = NULL;
return;
}
else png_free_default(png_ptr, ptr);
}
void
png_free_default(png_structp png_ptr, png_voidp ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__) #if defined(__TURBOC__) && !defined(__FLAT__)
farfree(ptr); farfree(ptr);
ptr = NULL;
#else #else
# if defined(_MSC_VER) && defined(MAXSEG_64K) # if defined(_MSC_VER) && defined(MAXSEG_64K)
hfree(ptr); hfree(ptr);
ptr = NULL;
# else # else
free(ptr); free(ptr);
ptr = NULL;
# endif # endif
#endif #endif
} }
@ -358,3 +483,27 @@ png_memset_check (png_structp png_ptr, png_voidp s1, int value,
return (png_memset (s1, value, size)); return (png_memset (s1, value, size));
} }
#ifdef PNG_USER_MEM_SUPPORTED
/* This function is called when the application wants to use another method
* of allocating and freeing memory.
*/
void
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn)
{
png_ptr->mem_ptr = mem_ptr;
png_ptr->malloc_fn = malloc_fn;
png_ptr->free_fn = free_fn;
}
/* This function returns a pointer to the mem_ptr associated with the user
* functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called.
*/
png_voidp
png_get_mem_ptr(png_structp png_ptr)
{
return ((png_voidp)png_ptr->mem_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */

View File

@ -1,12 +1,11 @@
/* pngpread.c - read a png file in push mode /* pngpread.c - read a png file in push mode
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL

View File

@ -1,12 +1,11 @@
/* pngread.c - read a PNG file /* pngread.c - read a PNG file
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This file contains routines that an application calls directly to * This file contains routines that an application calls directly to
* read a PNG file or stream. * read a PNG file or stream.
@ -20,12 +19,31 @@ png_structp
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn) png_error_ptr error_fn, png_error_ptr warn_fn)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL));
}
/* Alternate create PNG structure for reading, and allocate any memory needed. */
png_structp
png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr; png_structp png_ptr;
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf; jmp_buf jmpbuf;
#endif #endif
png_debug(1, "in png_create_read_struct\n"); png_debug(1, "in png_create_read_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn)) == NULL)
#else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
#endif
{ {
return (png_structp)NULL; return (png_structp)NULL;
} }
@ -42,6 +60,11 @@ png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
#endif /* PNG_USER_MEM_SUPPORTED */
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
@ -489,7 +512,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
/* Read one or more rows of image data. If the image is interlaced, /* Read one or more rows of image data. If the image is interlaced,
* and png_set_interlace_handling() has been called, the rows need to * and png_set_interlace_handling() has been called, the rows need to
* contain the contents of the rows from the previous pass. If the * contain the contents of the rows from the previous pass. If the
* image has alpha or transparency, and png_handle_alpha() has been * image has alpha or transparency, and png_handle_alpha()[*] has been
* called, the rows contents must be initialized to the contents of the * called, the rows contents must be initialized to the contents of the
* screen. * screen.
* *
@ -506,6 +529,8 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
* also, but you may. If the image is not interlaced, or if you have * also, but you may. If the image is not interlaced, or if you have
* not called png_set_interlace_handling(), the display_row buffer will * not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it. * be ignored, so pass NULL to it.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.1e.
*/ */
void void
@ -683,6 +708,9 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
{ {
png_structp png_ptr = NULL; png_structp png_ptr = NULL;
png_infop info_ptr = NULL, end_info_ptr = NULL; png_infop info_ptr = NULL, end_info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL;
#endif /* PNG_USER_MEM_SUPPORTED */
png_debug(1, "in png_destroy_read_struct\n"); png_debug(1, "in png_destroy_read_struct\n");
/* save jump buffer and error functions */ /* save jump buffer and error functions */
@ -695,6 +723,10 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (end_info_ptr_ptr != NULL) if (end_info_ptr_ptr != NULL)
end_info_ptr = *end_info_ptr_ptr; end_info_ptr = *end_info_ptr_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
#endif
png_read_destroy(png_ptr, info_ptr, end_info_ptr); png_read_destroy(png_ptr, info_ptr, end_info_ptr);
if (info_ptr != NULL) if (info_ptr != NULL)
@ -702,7 +734,12 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED) #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, info_ptr->text); png_free(png_ptr, info_ptr->text);
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
#else
png_destroy_struct((png_voidp)info_ptr); png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL; *info_ptr_ptr = (png_infop)NULL;
} }
@ -711,13 +748,21 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED) #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, end_info_ptr->text); png_free(png_ptr, end_info_ptr->text);
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
#else
png_destroy_struct((png_voidp)end_info_ptr); png_destroy_struct((png_voidp)end_info_ptr);
#endif
*end_info_ptr_ptr = (png_infop)NULL; *end_info_ptr_ptr = (png_infop)NULL;
} }
if (png_ptr != NULL) if (png_ptr != NULL)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
#else
png_destroy_struct((png_voidp)png_ptr); png_destroy_struct((png_voidp)png_ptr);
#endif
*png_ptr_ptr = (png_structp)NULL; *png_ptr_ptr = (png_structp)NULL;
} }
} }
@ -730,6 +775,9 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_error_ptr error_fn; png_error_ptr error_fn;
png_error_ptr warning_fn; png_error_ptr warning_fn;
png_voidp error_ptr; png_voidp error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn;
#endif
png_debug(1, "in png_read_destroy\n"); png_debug(1, "in png_read_destroy\n");
/* save jump buffer and error functions */ /* save jump buffer and error functions */
@ -771,7 +819,6 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_16_table[i]); png_free(png_ptr, png_ptr->gamma_16_table[i]);
} }
} }
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) #if defined(PNG_READ_BACKGROUND_SUPPORTED)
png_free(png_ptr, png_ptr->gamma_16_table); png_free(png_ptr, png_ptr->gamma_16_table);
if (png_ptr->gamma_16_from_1 != NULL) if (png_ptr->gamma_16_from_1 != NULL)
@ -795,6 +842,10 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
} }
png_free(png_ptr, png_ptr->gamma_16_to_1); png_free(png_ptr, png_ptr->gamma_16_to_1);
#endif #endif
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_free(png_ptr, png_ptr->time_buffer);
#endif /* PNG_TIME_RFC1123_SUPPORTED */
inflateEnd(&png_ptr->zstream); inflateEnd(&png_ptr->zstream);
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
@ -809,12 +860,18 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
error_fn = png_ptr->error_fn; error_fn = png_ptr->error_fn;
warning_fn = png_ptr->warning_fn; warning_fn = png_ptr->warning_fn;
error_ptr = png_ptr->error_ptr; error_ptr = png_ptr->error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
#endif
png_memset(png_ptr, 0, sizeof (png_struct)); png_memset(png_ptr, 0, sizeof (png_struct));
png_ptr->error_fn = error_fn; png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn; png_ptr->warning_fn = warning_fn;
png_ptr->error_ptr = error_ptr; png_ptr->error_ptr = error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
png_ptr->free_fn = free_fn;
#endif
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
} }

View File

@ -1,12 +1,11 @@
/* pngrio.c - functions for data input /* pngrio.c - functions for data input
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This file provides a location for all input. Users who need * This file provides a location for all input. Users who need
* special handling are expected to write a function that has the same * special handling are expected to write a function that has the same
@ -136,7 +135,14 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
#endif #endif
/* It is an error to write to a read device */ /* It is an error to write to a read device */
png_ptr->write_data_fn = NULL; if (png_ptr->write_data_fn != NULL)
{
png_ptr->write_data_fn = NULL;
png_warning(png_ptr,
"It's an error to set both read_data_fn and write_data_fn in the ");
png_warning(png_ptr,
"same structure. Resetting write_data_fn to NULL.");
}
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #if defined(PNG_WRITE_FLUSH_SUPPORTED)
png_ptr->output_flush_fn = NULL; png_ptr->output_flush_fn = NULL;

View File

@ -1,12 +1,11 @@
/* pngrtran.c - transforms the data in a row for PNG readers /* pngrtran.c - transforms the data in a row for PNG readers
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This file contains functions optionally called by an application * This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG. * in order to tell libpng how to handle data when reading a PNG.
@ -927,6 +926,11 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
} }
#endif #endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->transformations & PNG_GAMMA)
info_ptr->gamma = png_ptr->gamma;
#endif
#if defined(PNG_READ_16_TO_8_SUPPORTED) #if defined(PNG_READ_16_TO_8_SUPPORTED)
if ((png_ptr->transformations & PNG_16_TO_8) && info_ptr->bit_depth == 16) if ((png_ptr->transformations & PNG_16_TO_8) && info_ptr->bit_depth == 16)
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
@ -1013,7 +1017,7 @@ png_do_read_transformations(png_structp png_ptr)
png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->palette, png_ptr->trans, png_ptr->num_trans); png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
} }
else if (png_ptr->transformations & PNG_EXPAND) else
{ {
if (png_ptr->num_trans) if (png_ptr->num_trans)
png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
@ -1084,7 +1088,11 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
#if defined(PNG_READ_GAMMA_SUPPORTED) #if defined(PNG_READ_GAMMA_SUPPORTED)
if ((png_ptr->transformations & PNG_GAMMA) && if ((png_ptr->transformations & PNG_GAMMA) &&
!(png_ptr->transformations & PNG_BACKGROUND) && #if defined(PNG_READ_BACKGROUND_SUPPORTED)
!((png_ptr->transformations & PNG_BACKGROUND) &&
((png_ptr->num_trans != 0) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
#endif
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->gamma_table, png_ptr->gamma_16_table, png_ptr->gamma_table, png_ptr->gamma_16_table,
@ -2197,45 +2205,112 @@ png_do_background(png_row_infop row_info, png_bytep row,
} }
case 2: case 2:
{ {
sp = row; #if defined(PNG_READ_GAMMA_SUPPORTED)
shift = 6; if (gamma_table != NULL)
for (i = 0; i < row_width; i++)
{ {
if ((png_uint_16)((*sp >> shift) & 0x3) sp = row;
== trans_values->gray) shift = 6;
for (i = 0; i < row_width; i++)
{ {
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); if ((png_uint_16)((*sp >> shift) & 0x3)
*sp |= (png_byte)(background->gray << shift); == trans_values->gray)
{
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
}
else
{
png_byte p = (*sp >> shift) & 0x3;
png_byte g = (gamma_table [p | (p << 2) | (p << 4) |
(p << 6)] >> 6) & 0x3;
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*sp |= (png_byte)(g << shift);
}
if (!shift)
{
shift = 6;
sp++;
}
else
shift -= 2;
} }
if (!shift) }
else
#endif
{
sp = row;
shift = 6;
for (i = 0; i < row_width; i++)
{ {
shift = 6; if ((png_uint_16)((*sp >> shift) & 0x3)
sp++; == trans_values->gray)
{
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
}
if (!shift)
{
shift = 6;
sp++;
}
else
shift -= 2;
} }
else
shift -= 2;
} }
break; break;
} }
case 4: case 4:
{ {
sp = row; #if defined(PNG_READ_GAMMA_SUPPORTED)
shift = 4; if (gamma_table != NULL)
for (i = 0; i < row_width; i++)
{ {
if ((png_uint_16)((*sp >> shift) & 0xf) sp = row;
== trans_values->gray) shift = 4;
for (i = 0; i < row_width; i++)
{ {
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); if ((png_uint_16)((*sp >> shift) & 0xf)
*sp |= (png_byte)(background->gray << shift); == trans_values->gray)
{
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
}
else
{
png_byte p = (*sp >> shift) & 0xf;
png_byte g = (gamma_table[p | (p << 4)] >> 4) & 0xf;
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
*sp |= (png_byte)(g << shift);
}
if (!shift)
{
shift = 4;
sp++;
}
else
shift -= 4;
} }
if (!shift) }
else
#endif
{
sp = row;
shift = 4;
for (i = 0; i < row_width; i++)
{ {
shift = 4; if ((png_uint_16)((*sp >> shift) & 0xf)
sp++; == trans_values->gray)
{
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
}
if (!shift)
{
shift = 4;
sp++;
}
else
shift -= 4;
} }
else
shift -= 4;
} }
break; break;
} }

View File

@ -1,12 +1,11 @@
/* pngrutil.c - utilities to read a PNG file /* pngrutil.c - utilities to read a PNG file
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This file contains routines that are only called from within * This file contains routines that are only called from within
* libpng itself during the course of reading an image. * libpng itself during the course of reading an image.

View File

@ -1,12 +1,11 @@
/* pngset.c - storage of image information into info struct /* pngset.c - storage of image information into info struct
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* The functions here are used during reads to store data from the file * The functions here are used during reads to store data from the file
* into the info struct, and during writes to store application data * into the info struct, and during writes to store application data

102
pngtest.c
View File

@ -1,12 +1,11 @@
/* pngtest.c - a simple test program to test libpng /* pngtest.c - a simple test program to test libpng
* *
* libpng 1.0.1d * libpng 1.0.1e -June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This program reads in a PNG image, writes it out again, and then * This program reads in a PNG image, writes it out again, and then
* compares the two files. If the files are identical, this shows that * compares the two files. If the files are identical, this shows that
@ -16,7 +15,7 @@
* *
* The program will fail in certain legitimate cases: * The program will fail in certain legitimate cases:
* 1) when the compression level or filter selection method is changed. * 1) when the compression level or filter selection method is changed.
* 2) when the chunk size is smaller than 8K. * 2) when the chunk size is not 8K.
* 3) unknown ancillary chunks exist in the input file. * 3) unknown ancillary chunks exist in the input file.
* 4) others not listed here... * 4) others not listed here...
* In these cases, it is best to check with another tool such as "pngcheck" * In these cases, it is best to check with another tool such as "pngcheck"
@ -24,7 +23,8 @@
* *
* If a filename is given on the command-line, then this file is used * If a filename is given on the command-line, then this file is used
* for the input, rather than the default "pngtest.png". This allows * for the input, rather than the default "pngtest.png". This allows
* testing a wide variety of files easily. * testing a wide variety of files easily. You can also test a number
* of files at once by typing "pngtest -m file1.png file2.png ..."
*/ */
#include <stdio.h> #include <stdio.h>
@ -37,6 +37,11 @@
#include "png.h" #include "png.h"
#if defined(PNG_TIME_RFC1123_SUPPORTED)
static int tIME_chunk_present=0;
static png_charp tIME_string = "no tIME chunk present in file";
#endif /* PNG_TIME_RFC1123_SUPPORTED */
int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
#ifdef __TURBOC__ #ifdef __TURBOC__
@ -359,11 +364,7 @@ png_default_error(png_structp png_ptr, png_const_charp message)
/* END of code to validate stdio-free compilation */ /* END of code to validate stdio-free compilation */
/* START of code to validate memory allocation and deallocation */ /* START of code to validate memory allocation and deallocation */
#ifdef PNGTEST_MEMORY_DEBUG #ifdef PNG_USER_MEM_SUPPORTED
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
ERROR - memory debugging is not supported on this platform
#else
/* Allocate memory. For reasonable files, size should never exceed /* Allocate memory. For reasonable files, size should never exceed
64K. However, zlib may allocate more then 64K if you don't tell 64K. However, zlib may allocate more then 64K if you don't tell
@ -375,7 +376,7 @@ ERROR - memory debugging is not supported on this platform
by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */ by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
typedef struct memory_information { typedef struct memory_information {
png_uint_32 size; png_uint_32 size;
png_voidp pointer; png_voidp pointer;
struct memory_information FAR *next; struct memory_information FAR *next;
} memory_information; } memory_information;
typedef memory_information FAR *memory_infop; typedef memory_information FAR *memory_infop;
@ -390,23 +391,23 @@ extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
png_voidp ptr)); png_voidp ptr));
png_voidp png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size) { png_debug_malloc(png_structp png_ptr, png_uint_32 size) {
if (png_ptr == NULL) {
fprintf(STDERR, "NULL pointer to memory allocator\n"); /* png_malloc has already tested for NULL; png_create_struct calls
return (NULL); png_debug_malloc directly, with png_ptr == NULL which is OK */
}
if (size == 0) if (size == 0)
return (png_voidp)(NULL); return (png_voidp)(NULL);
/* This calls the library allocator twice, once to get the requested /* This calls the library allocator twice, once to get the requested
buffer and once to get a new free list entry. */ buffer and once to get a new free list entry. */
{ {
memory_infop pinfo = png_debug_malloc(png_ptr, sizeof *pinfo); memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo);
pinfo->size = size; pinfo->size = size;
current_allocation += size; current_allocation += size;
if (current_allocation > maximum_allocation) if (current_allocation > maximum_allocation)
maximum_allocation = current_allocation; maximum_allocation = current_allocation;
pinfo->pointer = png_debug_malloc(png_ptr, size); pinfo->pointer = png_malloc_default(png_ptr, size);
pinfo->next = pinformation; pinfo->next = pinformation;
pinformation = pinfo; pinformation = pinfo;
/* Make sure the caller isn't assuming zeroed memory. */ /* Make sure the caller isn't assuming zeroed memory. */
@ -417,10 +418,10 @@ png_malloc(png_structp png_ptr, png_uint_32 size) {
/* Free a pointer. It is removed from the list at the same time. */ /* Free a pointer. It is removed from the list at the same time. */
void void
png_free(png_structp png_ptr, png_voidp ptr) png_debug_free(png_structp png_ptr, png_voidp ptr)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
fprintf(STDERR, "NULL pointer to memory allocator\n"); fprintf(STDERR, "NULL pointer to png_debug_free.\n");
if (ptr == 0) { if (ptr == 0) {
#if 0 /* This happens all the time. */ #if 0 /* This happens all the time. */
fprintf(STDERR, "WARNING: freeing NULL pointer\n"); fprintf(STDERR, "WARNING: freeing NULL pointer\n");
@ -441,7 +442,7 @@ png_free(png_structp png_ptr, png_voidp ptr)
/* We must free the list element too, but first kill /* We must free the list element too, but first kill
the memory that is to be freed. */ the memory that is to be freed. */
memset(ptr, 0x55, pinfo->size); memset(ptr, 0x55, pinfo->size);
png_debug_free(png_ptr, pinfo); png_free_default(png_ptr, pinfo);
break; break;
} }
if (pinfo->next == NULL) { if (pinfo->next == NULL) {
@ -453,10 +454,9 @@ png_free(png_structp png_ptr, png_voidp ptr)
} }
/* Finally free the data. */ /* Finally free the data. */
png_debug_free(png_ptr, ptr); png_free_default(png_ptr, ptr);
} }
#endif /* Not Borland DOS special memory handler */ #endif /* PNG_USER_MEM_SUPPORTED */
#endif
/* END of code to test memory allocation/deallocation */ /* END of code to test memory allocation/deallocation */
/* Test one file */ /* Test one file */
@ -493,14 +493,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
png_debug(0, "Allocating read and write structures\n"); png_debug(0, "Allocating read and write structures\n");
#ifdef PNG_USER_MEM_SUPPORTED
read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
#else
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL); (png_error_ptr)NULL, (png_error_ptr)NULL);
#endif
#if defined(PNG_NO_STDIO) #if defined(PNG_NO_STDIO)
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
png_default_warning); png_default_warning);
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED
write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
#else
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL); (png_error_ptr)NULL, (png_error_ptr)NULL);
#endif
#if defined(PNG_NO_STDIO) #if defined(PNG_NO_STDIO)
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
png_default_warning); png_default_warning);
@ -509,6 +521,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
read_info_ptr = png_create_info_struct(read_ptr); read_info_ptr = png_create_info_struct(read_ptr);
write_info_ptr = png_create_info_struct(write_ptr); write_info_ptr = png_create_info_struct(write_ptr);
end_info_ptr = png_create_info_struct(read_ptr); end_info_ptr = png_create_info_struct(read_ptr);
#ifdef PNG_USER_MEM_SUPPORTED
#endif
png_debug(0, "Setting jmpbuf for read struct\n"); png_debug(0, "Setting jmpbuf for read struct\n");
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
@ -720,6 +734,15 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{ {
png_set_tIME(write_ptr, write_info_ptr, mod_time); png_set_tIME(write_ptr, write_info_ptr, mod_time);
} }
#if defined(PNG_TIME_RFC1123_SUPPORTED)
{
/* we have to use png_strcpy instead of "=" because the string
pointed to by png_convert_to_rfc1123() gets free'ed before
we use it */
png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
tIME_chunk_present++;
}
#endif /* PNG_TIME_RFC1123_SUPPORTED */
} }
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED) #if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED)
@ -944,7 +967,7 @@ main(int argc, char *argv[])
if (multiple) if (multiple)
{ {
int i; int i;
#ifdef PNGTEST_MEMORY_DEBUG #ifdef PNG_USER_MEM_SUPPORTED
int allocation_now = current_allocation; int allocation_now = current_allocation;
#endif #endif
for (i=2; i<argc; ++i) for (i=2; i<argc; ++i)
@ -953,16 +976,24 @@ main(int argc, char *argv[])
fprintf(STDERR, "Testing %s:",argv[i]); fprintf(STDERR, "Testing %s:",argv[i]);
kerror = test_one_file(argv[i], outname); kerror = test_one_file(argv[i], outname);
if (kerror == 0) if (kerror == 0)
{
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples); fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
#else #else
fprintf(STDERR, " PASS\n"); fprintf(STDERR, " PASS\n");
#endif #endif
else { #if defined(PNG_TIME_RFC1123_SUPPORTED)
if(tIME_chunk_present != 0)
fprintf(STDERR, " tIME = %s\n",tIME_string);
tIME_chunk_present = 0;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
else
{
fprintf(STDERR, " FAIL\n"); fprintf(STDERR, " FAIL\n");
ierror += kerror; ierror += kerror;
} }
#ifdef PNGTEST_MEMORY_DEBUG #ifdef PNG_USER_MEM_SUPPORTED
if (allocation_now != current_allocation) if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation-allocation_now); current_allocation-allocation_now);
@ -978,7 +1009,7 @@ main(int argc, char *argv[])
} }
#endif #endif
} }
#ifdef PNGTEST_MEMORY_DEBUG #ifdef PNG_USER_MEM_SUPPORTED
fprintf(STDERR, "Maximum memory allocation: %d bytes\n", fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
maximum_allocation); maximum_allocation);
#endif #endif
@ -988,7 +1019,7 @@ main(int argc, char *argv[])
int i; int i;
for (i=0; i<3; ++i) { for (i=0; i<3; ++i) {
int kerror; int kerror;
#ifdef PNGTEST_MEMORY_DEBUG #ifdef PNG_USER_MEM_SUPPORTED
int allocation_now = current_allocation; int allocation_now = current_allocation;
#endif #endif
if (i == 1) status_dots_requested = 1; if (i == 1) status_dots_requested = 1;
@ -999,11 +1030,17 @@ main(int argc, char *argv[])
if(kerror == 0) if(kerror == 0)
{ {
if(verbose == 1 || i == 2) if(verbose == 1 || i == 2)
{
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples); fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
#else #else
fprintf(STDERR, " PASS\n"); fprintf(STDERR, " PASS\n");
#endif #endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
if(tIME_chunk_present != 0)
fprintf(STDERR, " tIME = %s\n",tIME_string);
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
} }
else else
{ {
@ -1012,7 +1049,7 @@ main(int argc, char *argv[])
fprintf(STDERR, " FAIL\n"); fprintf(STDERR, " FAIL\n");
ierror += kerror; ierror += kerror;
} }
#ifdef PNGTEST_MEMORY_DEBUG #ifdef PNG_USER_MEM_SUPPORTED
if (allocation_now != current_allocation) if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation-allocation_now); current_allocation-allocation_now);
@ -1028,7 +1065,7 @@ main(int argc, char *argv[])
} }
#endif #endif
} }
#ifdef PNGTEST_MEMORY_DEBUG #ifdef PNG_USER_MEM_SUPPORTED
fprintf(STDERR, "Maximum memory allocation: %d bytes\n", fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
maximum_allocation); maximum_allocation);
#endif #endif
@ -1040,3 +1077,4 @@ main(int argc, char *argv[])
fprintf(STDERR, "libpng FAILS test\n"); fprintf(STDERR, "libpng FAILS test\n");
return (int)(ierror != 0); return (int)(ierror != 0);
} }

View File

@ -1,12 +1,11 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers) /* pngtrans.c - transforms the data in a row (used by both readers and writers)
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL

View File

@ -1,12 +1,11 @@
/* pngwio.c - functions for data output /* pngwio.c - functions for data output
* *
* libpng 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
* *
* This file provides a location for all output. Users who need * This file provides a location for all output. Users who need
* special handling are expected to write functions that have the same * special handling are expected to write functions that have the same
@ -175,7 +174,14 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
#endif /* PNG_WRITE_FLUSH_SUPPORTED */ #endif /* PNG_WRITE_FLUSH_SUPPORTED */
/* It is an error to read while writing a png file */ /* It is an error to read while writing a png file */
png_ptr->read_data_fn = NULL; if (png_ptr->read_data_fn != NULL)
{
png_ptr->read_data_fn = NULL;
png_warning(png_ptr,
"Attempted to set both read_data_fn and write_data_fn in");
png_warning(png_ptr,
"the same structure. Resetting read_data_fn to NULL.");
}
} }
#if defined(USE_FAR_KEYWORD) #if defined(USE_FAR_KEYWORD)

View File

@ -1,12 +1,11 @@
/* pngwrite.c - general routines to write a PNG file /* pngwrite.c - general routines to write a PNG file
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
/* get internal access to png.h */ /* get internal access to png.h */
@ -218,43 +217,6 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
png_write_IEND(png_ptr); png_write_IEND(png_ptr);
} }
#if defined(PNG_TIME_RFC1123_SUPPORTED)
/* Convert the supplied time into an RFC 1123 string suitable for use in
* a "Creation Time" or other text-based time string.
*/
png_charp
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
{
static PNG_CONST char short_months[12][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if (png_ptr->time_buffer == NULL)
{
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
sizeof(char)));
}
#ifdef USE_FAR_KEYWORD
{
char near_time_buf[29];
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
png_memcpy(png_ptr->time_buffer, near_time_buf,
29*sizeof(char));
}
#else
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
#endif
return ((png_charp)png_ptr->time_buffer);
}
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if defined(PNG_WRITE_tIME_SUPPORTED) #if defined(PNG_WRITE_tIME_SUPPORTED)
void void
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
@ -284,12 +246,29 @@ png_structp
png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn) png_error_ptr error_fn, png_error_ptr warn_fn)
{ {
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL));
}
/* Alternate initialize png_ptr structure, and allocate any memory needed */
png_structp
png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr; png_structp png_ptr;
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf; jmp_buf jmpbuf;
#endif #endif
png_debug(1, "in png_create_write_struct\n"); png_debug(1, "in png_create_write_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn)) == NULL)
#else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
#endif /* PNG_USER_MEM_SUPPORTED */
{ {
return ((png_structp)NULL); return ((png_structp)NULL);
} }
@ -306,6 +285,9 @@ png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
#endif /* PNG_USER_MEM_SUPPORTED */
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
@ -335,7 +317,6 @@ png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
return ((png_structp)png_ptr); return ((png_structp)png_ptr);
} }
/* Initialize png_ptr structure, and allocate any memory needed */ /* Initialize png_ptr structure, and allocate any memory needed */
void void
png_write_init(png_structp png_ptr) png_write_init(png_structp png_ptr)
@ -631,10 +612,18 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
{ {
png_structp png_ptr = NULL; png_structp png_ptr = NULL;
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL;
#endif
png_debug(1, "in png_destroy_write_struct\n"); png_debug(1, "in png_destroy_write_struct\n");
if (png_ptr_ptr != NULL) if (png_ptr_ptr != NULL)
{
png_ptr = *png_ptr_ptr; png_ptr = *png_ptr_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
#endif
}
if (info_ptr_ptr != NULL) if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr; info_ptr = *info_ptr_ptr;
@ -657,14 +646,22 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
png_free(png_ptr, info_ptr->pcal_params); png_free(png_ptr, info_ptr->pcal_params);
} }
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
#else
png_destroy_struct((png_voidp)info_ptr); png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL; *info_ptr_ptr = (png_infop)NULL;
} }
if (png_ptr != NULL) if (png_ptr != NULL)
{ {
png_write_destroy(png_ptr); png_write_destroy(png_ptr);
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
#else
png_destroy_struct((png_voidp)png_ptr); png_destroy_struct((png_voidp)png_ptr);
#endif
*png_ptr_ptr = (png_structp)NULL; *png_ptr_ptr = (png_structp)NULL;
} }
} }
@ -678,6 +675,9 @@ png_write_destroy(png_structp png_ptr)
png_error_ptr error_fn; png_error_ptr error_fn;
png_error_ptr warning_fn; png_error_ptr warning_fn;
png_voidp error_ptr; png_voidp error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn;
#endif
png_debug(1, "in png_write_destroy\n"); png_debug(1, "in png_write_destroy\n");
/* free any memory zlib uses */ /* free any memory zlib uses */
@ -708,12 +708,18 @@ png_write_destroy(png_structp png_ptr)
error_fn = png_ptr->error_fn; error_fn = png_ptr->error_fn;
warning_fn = png_ptr->warning_fn; warning_fn = png_ptr->warning_fn;
error_ptr = png_ptr->error_ptr; error_ptr = png_ptr->error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
#endif
png_memset(png_ptr, 0, sizeof (png_struct)); png_memset(png_ptr, 0, sizeof (png_struct));
png_ptr->error_fn = error_fn; png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn; png_ptr->warning_fn = warning_fn;
png_ptr->error_ptr = error_ptr; png_ptr->error_ptr = error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
png_ptr->free_fn = free_fn;
#endif
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
} }

View File

@ -1,12 +1,11 @@
/* pngwtran.c - transforms the data in a row for PNG writers /* pngwtran.c - transforms the data in a row for PNG writers
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL

View File

@ -1,12 +1,11 @@
/* pngwutil.c - utilities to write a PNG file /* pngwutil.c - utilities to write a PNG file
* *
* 1.0.1d * libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@ -575,7 +574,8 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
} }
#endif #endif
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
defined(PNG_WRITE_pCAL_SUPPORTED)
/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, /* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
* and if invalid, correct the keyword rather than discarding the entire * and if invalid, correct the keyword rather than discarding the entire
* chunk. The PNG 1.0 specification requires keywords 1-79 characters in * chunk. The PNG 1.0 specification requires keywords 1-79 characters in
@ -1416,10 +1416,19 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
* as the "minimum sum of absolute differences" heuristic. Other * as the "minimum sum of absolute differences" heuristic. Other
* heuristics are the "weighted minimum sum of absolute differences" * heuristics are the "weighted minimum sum of absolute differences"
* (experimental and can in theory improve compression), and the "zlib * (experimental and can in theory improve compression), and the "zlib
* predictive" method (not implemented in libpng 0.95), which does test * predictive" method (not implemented yet), which does test compressions
* compressions of lines using different filter methods, and then chooses * of lines using different filter methods, and then chooses the
* the (series of) filter(s) which give minimum compressed data size (VERY * (series of) filter(s) that give minimum compressed data size (VERY
* computationally expensive). * computationally expensive).
*
* GRR 980525: consider also
* (1) minimum sum of absolute differences from running average (i.e.,
* keep running sum of non-absolute differences & count of bytes)
* [track dispersion, too? restart average if dispersion too large?]
* (1b) minimum sum of absolute differences from sliding average, probably
* with window size <= deflate window (usually 32K)
* (2) minimum sum of squared differences from zero or running average
* (i.e., ~ root-mean-square approach)
*/ */

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ unit pngdef;
interface interface
const const
PNG_LIBPNG_VER_STRING = '1.0.1d'; PNG_LIBPNG_VER_STRING = '1.0.1e';
PNG_LIBPNG_VER = 10001; PNG_LIBPNG_VER = 10001;
type type

View File

@ -12,7 +12,9 @@ EXPORTS
png_sig_cmp png_sig_cmp
png_check_sig png_check_sig
png_create_read_struct png_create_read_struct
; png_create_read_struct_2
png_create_write_struct png_create_write_struct
; png_create_write_struct_2
png_write_chunk png_write_chunk
png_write_chunk_start png_write_chunk_start
png_write_chunk_data png_write_chunk_data
@ -72,6 +74,8 @@ EXPORTS
png_init_io png_init_io
png_set_error_fn png_set_error_fn
png_get_error_ptr png_get_error_ptr
; png_get_mem_fn
; png_set_mem_fn
png_set_write_fn png_set_write_fn
png_set_read_fn png_set_read_fn
png_set_write_status_fn png_set_write_status_fn
@ -89,8 +93,8 @@ EXPORTS
png_free png_free
png_memcpy_check png_memcpy_check
png_memset_check png_memset_check
; png_debug_malloc ; png_malloc_default
; png_debug_free ; png_free_default
; png_far_to_near ; png_far_to_near
png_error png_error
png_chunk_error png_chunk_error