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
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
filler bytes should have been 0xff instead of 0xf.
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
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
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
Made some corrections to grammar (which, it's) in documentation (Greg).
Corrected example.c, use of row_pointers in png_write_image().
version 1.0.1d [May 21, 1998]
Corrected several statements that some compilers interpret as illegal use
of side effects in pngrutil.c and pngtrans.c, that were introduced in
version 1.0.1b
version 1.0.1d [May 24, 1998]
Corrected several statements that used side effects illegally in pngrutil.c
and pngtrans.c, that were introduced in version 1.0.1b
Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
More corrections to example.c, use of row_pointers in png_write_image()
and png_read_rows().
@ -55,6 +54,21 @@ version 1.0.1d [May 21, 1998]
Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
Changed several loops from count-down to count-up, for consistency.
version 1.0.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
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
filler bytes should have been 0xff instead of 0xf.
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
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
for consistency, in pngconf.h
@ -324,10 +324,9 @@ version 1.0.1c [May 11, 1998]
to remove unwanted capabilities via the compile line
Made some corrections to grammar (which, it's) in documentation (Greg).
Corrected example.c, use of row_pointers in png_write_image().
version 1.0.1d [May 21, 1998]
Corrected several statements that some compilers interpret as illegal use
of side effects in pngrutil.c and pngtrans.c, that were introduced in
version 1.0.1b
version 1.0.1d [May 24, 1998]
Corrected several statements that used side effects illegally in pngrutil.c
and pngtrans.c, that were introduced in version 1.0.1b
Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
More corrections to example.c, use of row_pointers in png_write_image()
and png_read_rows().
@ -335,3 +334,18 @@ version 1.0.1d [May 21, 1998]
Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
Changed several loops from count-down to count-up, for consistency.
version 1.0.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
can usually be found wherever you got libpng. zlib can be
@ -10,7 +10,7 @@ zlib.h and zconf.h include files that correspond to the
version of zlib that's installed.
You can rename the directories that you downloaded (they
might be called "libpng-%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".
Your directory structure should look like this:

View File

@ -184,3 +184,13 @@ Known bugs and suggested enhancements in libpng-1.0.1
STATUS:
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 INSTALL for instructions on how to install libpng.

2
TODO
View File

@ -1,7 +1,6 @@
TODO - list of things to do for libpng
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
color to gray transformation
improved dithering
@ -21,3 +20,4 @@ support for application-defined chunk handlers
keep up with public chunks
better C++ wrapper/full C++ implementation?
text conversion between different code pages (Latin-1 -> Mac and DOS)
improve API by hiding the info_ptr

View File

@ -1,6 +1,6 @@
.TH LIBPNG 3 "May 21, 1998"
.TH LIBPNG 3 "June 6, 1998"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.1e - June 6, 1998
.SH SYNOPSIS
#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,
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
user_png_ver, voidp error_ptr, png_error_ptr error_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
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_default(png_structp png_ptr, png_voidp ptr)
png_byte png_get_bit_depth (png_structp png_ptr, png_infop
info_ptr);
@ -80,6 +90,11 @@ info_ptr, double *file_gamma);
png_uint_32 png_get_hIST (png_structp png_ptr, png_infop
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_infop info_ptr);
@ -91,10 +106,7 @@ info_ptr);
png_voidp png_get_io_ptr (png_structp png_ptr);
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_voidp png_get_mem_ptr(png_structp png_ptr)
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
@ -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_default(png_structp png_ptr,
png_uint_32 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,
@ -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
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,
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);
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,
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);
@ -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);
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,
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
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_flush (png_structp png_ptr);
void png_write_image (png_structp png_ptr, png_bytepp image);
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
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
<randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson
@ -560,10 +578,21 @@ on Changes to Libpng below regarding the old initialization functions.
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
necessary if you are not using the libpng supplied error handling
functions. When libpng encounters an error, it expects to longjmp back
png_structp png_ptr = png_create_read_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);
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
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
@ -1454,6 +1483,15 @@ both "png_ptr"; you can call them anything you like, such as
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
error handling. When libpng encounters an error, it expects to
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
png_get_io_ptr(). For example:
png_set_read_fn(png_structp png_ptr,
voidp io_ptr, png_rw_ptr read_data_fn)
png_set_read_fn(png_structp read_ptr,
voidp read_io_ptr, png_rw_ptr read_data_fn)
png_set_write_fn(png_structp png_ptr,
voidp io_ptr, png_rw_ptr write_data_fn,
png_set_write_fn(png_structp write_ptr,
voidp write_io_ptr, png_rw_ptr write_data_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:
@ -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
to using the default C stream functions. It is an error to read from
a write stream, and vice versa.
a write stream, and vice versa.
Error handling in libpng is done through png_error() and png_warning().
Errors handled through png_error() are fatal, meaning that png_error()
@ -2374,7 +2413,7 @@ possible without all of you.
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.
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 version 1.0.1d May 21, 1998
libpng version 1.0.1e - June 6, 1998
Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson
@ -164,10 +164,21 @@ on Changes to Libpng below regarding the old initialization functions.
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
necessary if you are not using the libpng supplied error handling
functions. When libpng encounters an error, it expects to longjmp back
png_structp png_ptr = png_create_read_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);
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
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
@ -1058,6 +1069,15 @@ both "png_ptr"; you can call them anything you like, such as
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
error handling. When libpng encounters an error, it expects to
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
png_get_io_ptr(). For example:
png_set_read_fn(png_structp png_ptr,
voidp io_ptr, png_rw_ptr read_data_fn)
png_set_read_fn(png_structp read_ptr,
voidp read_io_ptr, png_rw_ptr read_data_fn)
png_set_write_fn(png_structp png_ptr,
voidp io_ptr, png_rw_ptr write_data_fn,
png_set_write_fn(png_structp write_ptr,
voidp write_io_ptr, png_rw_ptr write_data_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:
@ -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
to using the default C stream functions. It is an error to read from
a write stream, and vice versa.
a write stream, and vice versa.
Error handling in libpng is done through png_error() and png_warning().
Errors handled through png_error() are fatal, meaning that png_error()

View File

@ -1,6 +1,6 @@
.TH LIBPNGPF 3 "May 21, 1998"
.TH LIBPNGPF 3 "June 6, 1998"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.1e - June 6, 1998
(private functions)
.SH SYNOPSIS
#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,
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_2 (png_voidp struct_ptr, png_free_ptr
free_fn);
void png_do_background (png_row_infop row_info, png_bytep row,
png_color_16p trans_values, png_color_16p background,
png_color_16p background_1, png_bytep gamma_table, png_bytep

2
png.5
View File

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

63
png.c
View File

@ -1,12 +1,11 @@
/* 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
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/
#define PNG_INTERNAL
@ -16,7 +15,7 @@
/* Version information for C files. This had better match the version
* 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. */
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
png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
png_voidp ptr;
png_uint_32 num_bytes;
png_uint_32 num_bytes = (png_uint_32)items * size;
png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
num_bytes = (png_uint_32)items * size;
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
if (num_bytes > (png_uint_32)0x8000)
if (num_bytes > (png_uint_32)0x8000L)
{
png_memset(ptr, 0, (png_size_t)0x8000L);
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");
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)
#endif
{
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);
#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);
#endif
*info_ptr_ptr = (png_infop)NULL;
}
}
@ -252,11 +258,10 @@ void
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
int i;
png_debug(1, "in png_info_destroy\n");
if (info_ptr->text != NULL)
{
int i;
for (i = 0; i < info_ptr->num_text; i++)
{
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);
if (info_ptr->pcal_params != NULL)
{
int i;
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
@ -302,3 +308,40 @@ png_init_io(png_structp png_ptr, FILE *fp)
png_ptr->io_ptr = (png_voidp)fp;
}
#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
*
* libpng 1.0.1d
* libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see the COPYRIGHT NOTICE below.
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998 Glenn Randers-Pehrson
* May 21, 1998
*
* Note about libpng version numbers:
*
@ -16,24 +15,22 @@
* The following table summarizes matters since version 0.89c, which was
* the first widely used release:
*
* source png.h png.h shared-lib
* version string int version
* ------- ------ ----- ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
* 0.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [int should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
* 1.0.1 1.0.1 10001 2.1.0
* 1.0.1a 1.0.1a 10002 2.1.0.1a
* 1.0.1b 1.0.1b 10002 2.1.0.1b
* 1.0.1c 1.0.1c 10002 2.1.0.1c
* source png.h png.h shared-lib
* version string int version
* ------- ------ ----- ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
* 0.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [int should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
* 1.0.1 1.0.1 10001 2.1.0
* 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
*
* Henceforth the source version will match the shared-library minor
* 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 */
#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.
* 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 */
#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
* other image types that don't need a full alpha channel. There are
* "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));
#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 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.
@ -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_rows; /* number of rows written since last flush */
#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 */
float gamma; /* file gamma value */
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)
png_color_8 shift; /* shift for significant bit tranformation */
#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_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_write_status_ptr write_row_fn; /* called after each row is encoded */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
@ -682,6 +684,11 @@ struct png_struct_def
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1123 time text */
#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;
@ -716,11 +723,22 @@ extern PNG_EXPORT(png_structp,png_create_read_struct)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
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)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
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. */
extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
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,
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
extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
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() */
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,
png_voidp s1, png_voidp s2, png_uint_32 size));
extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
png_voidp s1, int value, png_uint_32 size));
#ifdef PNGTEST_MEMORY_DEBUG
/* debugging versions of png_malloc() and png_free() */
extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
png_uint_32 size));
extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
png_voidp ptr));
#endif
#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
int check));
@ -1650,6 +1677,11 @@ PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
/* free memory from internal libpng struct */
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. */
PNG_EXTERN void png_info_destroy PNGARG((png_structp png_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));
#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_charp key, png_charpp new_key));
#endif

View File

@ -1,12 +1,11 @@
/* 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
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/
/* 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 */
/*
#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
#define PNG_USER_MEM_SUPPORTED
*/
/* This is only for PowerPC big-endian and 680x0 systems */
@ -663,6 +663,7 @@ typedef z_stream FAR * png_zstreamp;
# define NOCHECK 0
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
# define png_strcpy _fstrcpy
# define png_strlen _fstrlen
# define png_memcmp _fmemcmp /* SJT: added */
# define png_memcpy _fmemcpy
@ -670,6 +671,7 @@ typedef z_stream FAR * png_zstreamp;
#else /* use the usual functions */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strcpy strcpy
# define png_strlen strlen
# define png_memcmp memcmp /* SJT: added */
# define png_memcpy memcpy

View File

@ -1,12 +1,11 @@
/* 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
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*
* This file provides a location for all error handling. Users who
* need special error handling are expected to write replacement functions

View File

@ -1,12 +1,11 @@
/* 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
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/
#define PNG_INTERNAL
@ -302,11 +301,11 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
}
return (retval);
}
#endif
#endif /* PNG_READ_pHYs_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS */
/* png_get_channels really belongs in here, too, but it's been around longer */
#endif /* PNG_EASY_ACCESS_SUPPORTED */
png_byte

193
pngmem.c
View File

@ -1,12 +1,11 @@
/* 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
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*
* This file provides a location for all memory allocation. Users who
* need special memory handling are expected to modify the code in this file
@ -16,16 +15,6 @@
#define PNG_INTERNAL
#include "png.h"
/* The following "hides" PNG_MALLOC and PNG_FREE thus allowing the pngtest
application to put a wrapper on top of them. */
#ifdef PNGTEST_MEMORY_DEBUG
#define PNG_MALLOC png_debug_malloc
#define PNG_FREE png_debug_free
#else
#define PNG_MALLOC png_malloc
#define PNG_FREE png_free
#endif
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* if you change this, be sure to change the one in png.h also */
@ -35,6 +24,15 @@
png_voidp
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_voidp struct_ptr;
@ -45,11 +43,18 @@ png_create_struct(int type)
else
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)
{
png_memset(struct_ptr, 0, size);
}
return (struct_ptr);
}
@ -58,8 +63,27 @@ png_create_struct(int type)
void
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)
{
#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);
struct_ptr = NULL;
}
@ -85,12 +109,27 @@ png_destroy_struct(png_voidp struct_ptr)
* (which should cause a fatal error) and introducing major problems.
*/
png_voidp
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
png_malloc(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret;
#endif
if (png_ptr == NULL || size == 0)
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
if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
@ -181,15 +220,30 @@ PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
return (ret);
}
/* free a pointer allocated by PNG_MALLOC(). In the default
/* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */
void
PNG_FREE(png_structp png_ptr, png_voidp ptr)
png_free(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
#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)
{
int i;
@ -227,6 +281,17 @@ PNG_FREE(png_structp png_ptr, png_voidp ptr)
png_voidp
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_voidp struct_ptr;
@ -237,6 +302,15 @@ png_create_struct(int type)
else
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 ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
#else
@ -258,15 +332,37 @@ png_create_struct(int type)
void
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)
{
#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__)
farfree(struct_ptr);
struct_ptr = NULL;
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
hfree(struct_ptr);
struct_ptr = NULL;
# else
free(struct_ptr);
struct_ptr = NULL;
# endif
#endif
}
@ -280,13 +376,26 @@ png_destroy_struct(png_voidp struct_ptr)
have the ability to do that. */
png_voidp
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
png_malloc(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret;
#endif
if (png_ptr == NULL || size == 0)
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
if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
@ -310,22 +419,38 @@ PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
return (ret);
}
/* Free a pointer allocated by PNG_MALLOC(). In the default
configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
without taking any action. */
void
PNG_FREE(png_structp png_ptr, png_voidp ptr)
png_free(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
#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__)
farfree(ptr);
ptr = NULL;
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
hfree(ptr);
ptr = NULL;
# else
free(ptr);
ptr = NULL;
# endif
#endif
}
@ -358,3 +483,27 @@ png_memset_check (png_structp png_ptr, png_voidp s1, int value,
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
*
* 1.0.1d
* libpng 1.0.1e - June 6, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*/
#define PNG_INTERNAL

View File

@ -1,12 +1,11 @@
/* 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
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* May 21, 1998
*
* This file contains routines that an application calls directly to
* 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_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;
#ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf;
#endif
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)
#endif
{
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
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#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);
/* 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,
* and png_set_interlace_handling() has been called, the rows need to
* 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
* 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
* not called png_set_interlace_handling(), the display_row buffer will
* be ignored,