diff --git a/ANNOUNCE b/ANNOUNCE index 8739266e..8448585a 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -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 diff --git a/CHANGES b/CHANGES index 925706a6..458cb1f2 100644 --- a/CHANGES +++ b/CHANGES @@ -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. diff --git a/INSTALL b/INSTALL index aa92a3ff..3141d2ef 100644 --- a/INSTALL +++ b/INSTALL @@ -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: diff --git a/KNOWNBUG b/KNOWNBUG index 76c51e7c..0ad64324 100644 --- a/KNOWNBUG +++ b/KNOWNBUG @@ -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 diff --git a/README b/README index 6afca2bf..b913b23e 100644 --- a/README +++ b/README @@ -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. diff --git a/TODO b/TODO index 36f2a783..49bd5fff 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/libpng.3 b/libpng.3 index 167e1f0e..4e5836ed 100644 --- a/libpng.3 +++ b/libpng.3 @@ -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 @@ -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 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). diff --git a/libpng.txt b/libpng.txt index 7506e572..7fb5a682 100644 --- a/libpng.txt +++ b/libpng.txt @@ -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 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() diff --git a/libpngpf.3 b/libpngpf.3 index 824f4dd5..bd0be6b3 100644 --- a/libpngpf.3 +++ b/libpngpf.3 @@ -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 @@ -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 diff --git a/png.5 b/png.5 index 3ba30791..a5f90b6c 100644 --- a/png.5 +++ b/png.5 @@ -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 diff --git a/png.c b/png.c index 82bee278..a4f3352d 100644 --- a/png.c +++ b/png.c @@ -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 */ diff --git a/png.h b/png.h index 03213da5..6fe00e86 100644 --- a/png.h +++ b/png.h @@ -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 diff --git a/pngconf.h b/pngconf.h index cc9d693e..0973f0f3 100644 --- a/pngconf.h +++ b/pngconf.h @@ -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 diff --git a/pngerror.c b/pngerror.c index 39e89358..e9a24e76 100644 --- a/pngerror.c +++ b/pngerror.c @@ -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 diff --git a/pngget.c b/pngget.c index 37e9bb97..9d033149 100644 --- a/pngget.c +++ b/pngget.c @@ -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 diff --git a/pngmem.c b/pngmem.c index 47880e96..0b98055a 100644 --- a/pngmem.c +++ b/pngmem.c @@ -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 */ diff --git a/pngpread.c b/pngpread.c index 22168b7c..5386060f 100644 --- a/pngpread.c +++ b/pngpread.c @@ -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 diff --git a/pngread.c b/pngread.c index 0d361986..8af9e5b3 100644 --- a/pngread.c +++ b/pngread.c @@ -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, so pass NULL to it. + * + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.1e. */ 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_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"); /* 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) 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); 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) png_free(png_ptr, info_ptr->text); #endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, free_fn); +#else png_destroy_struct((png_voidp)info_ptr); +#endif *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) png_free(png_ptr, end_info_ptr->text); #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); +#endif *end_info_ptr_ptr = (png_infop)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); +#endif *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 warning_fn; png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif png_debug(1, "in png_read_destroy\n"); /* 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]); } } -#endif #if defined(PNG_READ_BACKGROUND_SUPPORTED) png_free(png_ptr, png_ptr->gamma_16_table); 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); #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); #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; warning_fn = png_ptr->warning_fn; 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_ptr->error_fn = error_fn; png_ptr->warning_fn = warning_fn; 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)); } diff --git a/pngrio.c b/pngrio.c index a17c64dd..b57b5637 100644 --- a/pngrio.c +++ b/pngrio.c @@ -1,12 +1,11 @@ /* 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 * 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 input. Users who need * 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 /* 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) png_ptr->output_flush_fn = NULL; diff --git a/pngrtran.c b/pngrtran.c index fd2cc229..a5542f42 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,12 +1,11 @@ /* 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 * 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 functions optionally called by an application * 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 +#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 ((png_ptr->transformations & PNG_16_TO_8) && info_ptr->bit_depth == 16) 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_ptr->palette, png_ptr->trans, png_ptr->num_trans); } - else if (png_ptr->transformations & PNG_EXPAND) + else { if (png_ptr->num_trans) 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 ((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_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, 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: { - sp = row; - shift = 6; - for (i = 0; i < row_width; i++) +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_table != NULL) { - if ((png_uint_16)((*sp >> shift) & 0x3) - == trans_values->gray) + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) { - *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *sp |= (png_byte)(background->gray << shift); + if ((png_uint_16)((*sp >> shift) & 0x3) + == 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; - sp++; + if ((png_uint_16)((*sp >> shift) & 0x3) + == 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; } case 4: { - sp = row; - shift = 4; - for (i = 0; i < row_width; i++) +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_table != NULL) { - if ((png_uint_16)((*sp >> shift) & 0xf) - == trans_values->gray) + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) { - *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *sp |= (png_byte)(background->gray << shift); + if ((png_uint_16)((*sp >> shift) & 0xf) + == 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; - sp++; + if ((png_uint_16)((*sp >> shift) & 0xf) + == 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; } diff --git a/pngrutil.c b/pngrutil.c index b476eb76..a45c0084 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,12 +1,11 @@ /* 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 * 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 are only called from within * libpng itself during the course of reading an image. diff --git a/pngset.c b/pngset.c index 05511780..293f0236 100644 --- a/pngset.c +++ b/pngset.c @@ -1,12 +1,11 @@ /* 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 * 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 * * The functions here are used during reads to store data from the file * into the info struct, and during writes to store application data diff --git a/pngtest.c b/pngtest.c index fed8e9c9..84e84c36 100644 --- a/pngtest.c +++ b/pngtest.c @@ -1,12 +1,11 @@ /* 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 * 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 program reads in a PNG image, writes it out again, and then * compares the two files. If the files are identical, this shows that @@ -16,7 +15,7 @@ * * The program will fail in certain legitimate cases: * 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. * 4) others not listed here... * 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 * 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 @@ -37,6 +37,11 @@ #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)); #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 */ /* START of code to validate memory allocation and deallocation */ -#ifdef PNGTEST_MEMORY_DEBUG -/* Borland DOS special memory handler */ -#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) -ERROR - memory debugging is not supported on this platform -#else +#ifdef PNG_USER_MEM_SUPPORTED /* Allocate memory. For reasonable files, size should never exceed 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. */ typedef struct memory_information { png_uint_32 size; - png_voidp pointer; + png_voidp pointer; struct memory_information FAR *next; } memory_information; 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 -png_malloc(png_structp png_ptr, png_uint_32 size) { - if (png_ptr == NULL) { - fprintf(STDERR, "NULL pointer to memory allocator\n"); - return (NULL); - } +png_debug_malloc(png_structp png_ptr, png_uint_32 size) { + + /* png_malloc has already tested for NULL; png_create_struct calls + png_debug_malloc directly, with png_ptr == NULL which is OK */ + if (size == 0) return (png_voidp)(NULL); /* This calls the library allocator twice, once to get the requested buffer and once to get a new free list entry. */ { - memory_infop pinfo = png_debug_malloc(png_ptr, sizeof *pinfo); + memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo); pinfo->size = size; current_allocation += size; if (current_allocation > maximum_allocation) maximum_allocation = current_allocation; - pinfo->pointer = png_debug_malloc(png_ptr, size); + pinfo->pointer = png_malloc_default(png_ptr, size); pinfo->next = pinformation; pinformation = pinfo; /* 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. */ void -png_free(png_structp png_ptr, png_voidp ptr) +png_debug_free(png_structp png_ptr, png_voidp ptr) { 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 0 /* This happens all the time. */ 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 the memory that is to be freed. */ memset(ptr, 0x55, pinfo->size); - png_debug_free(png_ptr, pinfo); + png_free_default(png_ptr, pinfo); break; } if (pinfo->next == NULL) { @@ -453,10 +454,9 @@ png_free(png_structp png_ptr, png_voidp ptr) } /* Finally free the data. */ - png_debug_free(png_ptr, ptr); + png_free_default(png_ptr, ptr); } -#endif /* Not Borland DOS special memory handler */ -#endif +#endif /* PNG_USER_MEM_SUPPORTED */ /* END of code to test memory allocation/deallocation */ /* 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"); +#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, (png_error_ptr)NULL, (png_error_ptr)NULL); +#endif #if defined(PNG_NO_STDIO) png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, png_default_warning); #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, (png_error_ptr)NULL, (png_error_ptr)NULL); +#endif #if defined(PNG_NO_STDIO) png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, 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); write_info_ptr = png_create_info_struct(write_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"); #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); } +#if defined(PNG_TIME_RFC1123_SUPPORTED) + { + /* we have to use png_strcpy instead of "=" because the string + pointed to by png_convert_to_rfc1123() gets free'ed before + we use it */ + png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); + tIME_chunk_present++; + } +#endif /* PNG_TIME_RFC1123_SUPPORTED */ } #endif #if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED) @@ -944,7 +967,7 @@ main(int argc, char *argv[]) if (multiple) { int i; -#ifdef PNGTEST_MEMORY_DEBUG +#ifdef PNG_USER_MEM_SUPPORTED int allocation_now = current_allocation; #endif for (i=2; iread_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) diff --git a/pngwrite.c b/pngwrite.c index 02ee7b09..4190efb2 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,12 +1,11 @@ /* 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 * 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 */ /* 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); } -#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) void 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_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; #ifdef USE_FAR_KEYWORD jmp_buf jmpbuf; #endif 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) +#endif /* PNG_USER_MEM_SUPPORTED */ { 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 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 @@ -335,7 +317,6 @@ png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, return ((png_structp)png_ptr); } - /* Initialize png_ptr structure, and allocate any memory needed */ void 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_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"); if (png_ptr_ptr != NULL) + { png_ptr = *png_ptr_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; +#endif + } if (info_ptr_ptr != NULL) 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); } #endif +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, free_fn); +#else png_destroy_struct((png_voidp)info_ptr); +#endif *info_ptr_ptr = (png_infop)NULL; } if (png_ptr != NULL) { 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); +#endif *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 warning_fn; png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif png_debug(1, "in png_write_destroy\n"); /* free any memory zlib uses */ @@ -708,12 +708,18 @@ png_write_destroy(png_structp png_ptr) error_fn = png_ptr->error_fn; warning_fn = png_ptr->warning_fn; 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_ptr->error_fn = error_fn; png_ptr->warning_fn = warning_fn; 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)); } diff --git a/pngwtran.c b/pngwtran.c index 3b43996d..9b02ebaf 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -1,12 +1,11 @@ /* 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 * 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 diff --git a/pngwutil.c b/pngwutil.c index 8e0dc219..969386e8 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,12 +1,11 @@ /* 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 * 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 @@ -575,7 +574,8 @@ png_write_hIST(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) /* 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 * 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 * heuristics are the "weighted minimum sum of absolute differences" * (experimental and can in theory improve compression), and the "zlib - * predictive" method (not implemented in libpng 0.95), which does test - * compressions of lines using different filter methods, and then chooses - * the (series of) filter(s) which give minimum compressed data size (VERY + * predictive" method (not implemented yet), which does test compressions + * of lines using different filter methods, and then chooses the + * (series of) filter(s) that give minimum compressed data size (VERY * 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) */ diff --git a/scripts/makefile.lnx b/scripts/makefile.lnx index 33351cff..9ea04db5 100644 --- a/scripts/makefile.lnx +++ b/scripts/makefile.lnx @@ -29,7 +29,7 @@ RANLIB=ranlib # read libpng.txt or png.h to see why PNGMAJ is 2. You should not # have to change it. PNGMAJ = 2 -PNGMIN = 1.0.1d +PNGMIN = 1.0.1e PNGVER = $(PNGMAJ).$(PNGMIN) # where make install puts libpng.a, libpng.so*, and png.h diff --git a/scripts/makefile.s2x b/scripts/makefile.s2x index 167828cb..9d19e73b 100644 --- a/scripts/makefile.s2x +++ b/scripts/makefile.s2x @@ -29,7 +29,7 @@ RANLIB=echo # read libpng.txt or png.h to see why PNGMAJ is 2. You should not # have to change it. PNGMAJ = 2 -PNGMIN = 1.0.1d +PNGMIN = 1.0.1e PNGVER = $(PNGMAJ).$(PNGMIN) # where make install puts libpng.a, libpng.so*, and png.h diff --git a/scripts/makefile.sco b/scripts/makefile.sco index 65d5fb28..a88772af 100644 --- a/scripts/makefile.sco +++ b/scripts/makefile.sco @@ -22,7 +22,7 @@ RANLIB=echo # read libpng.txt or png.h to see why PNGMAJ is 2. You should not # have to change it. PNGMAJ = 2 -PNGMIN = 1.0.1d +PNGMIN = 1.0.1e PNGVER = $(PNGMAJ).$(PNGMIN) # where make install puts libpng.a, libpng.so*, and png.h diff --git a/scripts/pngdef.pas b/scripts/pngdef.pas index 7c9acb57..0739c420 100644 --- a/scripts/pngdef.pas +++ b/scripts/pngdef.pas @@ -3,7 +3,7 @@ unit pngdef; interface const - PNG_LIBPNG_VER_STRING = '1.0.1d'; + PNG_LIBPNG_VER_STRING = '1.0.1e'; PNG_LIBPNG_VER = 10001; type diff --git a/scripts/pngos2.def b/scripts/pngos2.def index ba2d3e3d..72620de6 100644 --- a/scripts/pngos2.def +++ b/scripts/pngos2.def @@ -12,7 +12,9 @@ EXPORTS png_sig_cmp png_check_sig png_create_read_struct +; png_create_read_struct_2 png_create_write_struct +; png_create_write_struct_2 png_write_chunk png_write_chunk_start png_write_chunk_data @@ -72,6 +74,8 @@ EXPORTS png_init_io png_set_error_fn png_get_error_ptr +; png_get_mem_fn +; png_set_mem_fn png_set_write_fn png_set_read_fn png_set_write_status_fn @@ -89,8 +93,8 @@ EXPORTS png_free png_memcpy_check png_memset_check -; png_debug_malloc -; png_debug_free +; png_malloc_default +; png_free_default ; png_far_to_near png_error png_chunk_error