From 0f3e4443074fb43b6450eef0b285e96ac0da2ab3 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sat, 9 Jun 2001 10:30:01 -0500 Subject: [PATCH] Imported from pngcrush-1.5.5.tar --- README.txt | 18 ++++--- png.c | 53 ++++++++++++++------- png.h | 92 +++++++++++++++++++++++++----------- pngasmrd.h | 2 +- pngconf.h | 98 ++++++++++++++++++++++++-------------- pngcrush.c | 129 +++++++++++++++++++++++++++++++++----------------- pngcrush.h | 3 +- pngerror.c | 106 +++++++++++++++++++++++++++++++++++++++-- pnggccrd.c | 30 +++++++++++- pngget.c | 3 +- pngmem.c | 46 +++++++++++++----- pngpread.c | 2 +- pngread.c | 136 +++++++++++++++++++++++++++++++++++++++++++---------- pngrio.c | 4 +- pngrtran.c | 2 +- pngrutil.c | 32 +++++++++---- pngset.c | 8 ++-- pngtrans.c | 2 +- pngvcrd.c | 2 +- pngwio.c | 2 +- pngwrite.c | 130 ++++++++++++++++++++++++++++++++++++++++---------- pngwtran.c | 2 +- pngwutil.c | 47 ++++++++++-------- zlib.h | 5 ++ zutil.h | 6 ++- 25 files changed, 721 insertions(+), 239 deletions(-) diff --git a/README.txt b/README.txt index f4d38648d..254501241 100644 --- a/README.txt +++ b/README.txt @@ -41,12 +41,13 @@ case of any discrepancy, the copy in pngcrush.c shall prevail): This is the output of "pngcrush" and "pngcrush -help": - | pngcrush 1.5.4, Copyright (C) 1998-2001 Glenn Randers-Pehrson + + | pngcrush 1.5.5, Copyright (C) 1998-2001 Glenn Randers-Pehrson | This is a free, open-source program. Permission is irrevocably | granted to everyone to use this version of pngcrush without | payment of any fee. - | This program was built with libpng version 1.0.11, and is - | running with libpng version 1.0.11 - April 27, 2001 (header) + | This program was built with libpng version 1.0.12, and is + | running with libpng version 1.0.12 - June 8, 2001 (header) | Copyright (C) 1998-2001 Glenn Randers-Pehrson, | Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., @@ -88,16 +89,20 @@ options: -v (display more detailed information) -version (display the pngcrush version) -w compression_window_size [32, 16, 8, 4, 2, 1, 512] + -z zlib_strategy [0, 1, or 2] + -zmem zlib_compression_mem_level [1-9, default 9] + -zitxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" + -ztxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -h (help and legal notices) -p (pause) - | pngcrush 1.5.4, Copyright (C) 1998-2001 Glenn Randers-Pehrson + | pngcrush 1.5.5, Copyright (C) 1998-2001 Glenn Randers-Pehrson | This is a free, open-source program. Permission is irrevocably | granted to everyone to use this version of pngcrush without | payment of any fee. - | This program was built with libpng version 1.0.11, and is - | running with libpng version 1.0.11 - April 27, 2001 (header) + | This program was built with libpng version 1.0.12, and is + | running with libpng version 1.0.12 - June 8, 2001 (header) | Copyright (C) 1998-2001 Glenn Randers-Pehrson, | Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., @@ -310,4 +315,3 @@ options (Note: any option can be spelled out for clarity, e.g., e.g., type 'pngcrush -pause -help', if the help screen scrolls out of sight. - diff --git a/png.c b/png.c index e2cf0b7d2..0cc4e8ee4 100644 --- a/png.c +++ b/png.c @@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions * - * libpng version 1.0.11 - April 27, 2001 + * libpng version 1.0.12 - June 8, 2001 * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -13,14 +13,14 @@ #include "png.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_0_11 Your_png_h_is_not_version_1_0_11; +typedef version_1_0_12 Your_png_h_is_not_version_1_0_12; /* Version information for C files. This had better match the version * string defined in png.h. */ #ifdef PNG_USE_GLOBAL_ARRAYS /* png_libpng_ver was changed to a function in version 1.0.5c */ -const char png_libpng_ver[18] = "1.0.11"; +const char png_libpng_ver[18] = "1.0.12"; /* png_sig was changed to a function in version 1.0.5c */ /* Place to hold the signature string for a PNG file. */ @@ -213,12 +213,12 @@ png_create_info_struct(png_structp png_ptr) 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) + png_ptr->malloc_fn, png_ptr->mem_ptr)) != NULL) #else if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL) #endif { - png_info_init(info_ptr); + png_info_init_3(&info_ptr, sizeof(png_info)); } return (info_ptr); @@ -243,7 +243,8 @@ 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); + png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, + png_ptr->mem_ptr); #else png_destroy_struct((png_voidp)info_ptr); #endif @@ -255,10 +256,28 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) * and applications using it are urged to use png_create_info_struct() * instead. */ -void /* PRIVATE */ +#undef png_info_init +void PNGAPI png_info_init(png_infop info_ptr) { - png_debug(1, "in png_info_init\n"); + /* We only come here via pre-1.0.12-compiled applications */ + png_info_init_3(&info_ptr, 0); +} + +void PNGAPI +png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) +{ + png_infop info_ptr = *ptr_ptr; + + png_debug(1, "in png_info_init_3\n"); + + if(sizeof(png_info) > png_info_struct_size) + { + png_destroy_struct(info_ptr); + info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); + *ptr_ptr = info_ptr; + } + /* set everything to 0 */ png_memset(info_ptr, 0, sizeof (png_info)); } @@ -537,7 +556,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) } #endif - png_info_init(info_ptr); + png_info_init_3(&info_ptr, sizeof(png_info)); } /* This function returns a pointer to the io_ptr associated with the user @@ -627,7 +646,7 @@ png_charp PNGAPI png_get_copyright(png_structp png_ptr) { if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */ - return ((png_charp) "\n libpng version 1.0.11 - April 27, 2001\n\ + return ((png_charp) "\n libpng version 1.0.12 - June 8, 2001\n\ Copyright (c) 1998-2001 Glenn Randers-Pehrson\n\ Copyright (c) 1996, 1997 Andreas Dilger\n\ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n"); @@ -645,8 +664,8 @@ png_get_libpng_ver(png_structp png_ptr) { /* Version of *.c files used when building libpng */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return((png_charp) "1.0.11"); - return((png_charp) "1.0.11"); + return((png_charp) "1.0.12"); + return((png_charp) "1.0.12"); } png_charp PNGAPI @@ -696,17 +715,15 @@ png_uint_32 PNGAPI png_access_version_number(void) { /* Version of *.c files used when building libpng */ - return((png_uint_32) 10011L); + return((png_uint_32) 10012L); } - -#if 0 /* delay this until version 1.2.0 */ -/* this function was added to libpng 1.0.9 (porting aid to libpng-1.2.0) */ -#ifndef PNG_ASSEMBLER_CODE_SUPPORTED +/* this function was added to libpng 1.2.0 */ +#if !defined(PNG_USE_PNGGCCRD) && \ + !(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)) int PNGAPI png_mmx_support(void) { return -1; } #endif -#endif /* 0 */ diff --git a/png.h b/png.h index a8fc40c8e..ad41d48fc 100644 --- a/png.h +++ b/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.0.11 - April 27, 2001 + * libpng version 1.0.12 - June 8, 2001 * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -9,7 +9,7 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.0.11 - April 27, 2001: Glenn + * libpng versions 0.97, January 1998, through 1.0.12 - June 8, 2001: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -70,6 +70,7 @@ * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 * 1.0.11rc1 1 10011 2.1.0.11rc1 * 1.0.11 1 10011 2.1.0.11 + * 1.0.12beta1-2 2 10012 2.1.0.11beta1-2 * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -99,7 +100,7 @@ * If you modify libpng you may insert additional notices immediately following * this sentence. * - * libpng versions 1.0.7, July 1, 2000, through 1.0.11, April 27, 2001, are + * libpng versions 1.0.7, July 1, 2000, through 1.0.12, June 8, 2001, are * Copyright (c) 2000, 2001 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.0.6 * with the following individuals added to the list of Contributing Authors @@ -204,13 +205,13 @@ * Y2K compliance in libpng: * ========================= * - * April 27, 2001 + * June 8, 2001 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.0.11 are Y2K compliant. It is my belief that earlier + * upward through 1.0.12 are Y2K compliant. It is my belief that earlier * versions were also Y2K compliant. * * Libpng only has three year fields. One is a 2-byte unsigned integer @@ -266,7 +267,7 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.0.11" +#define PNG_LIBPNG_VER_STRING "1.0.12" #define PNG_LIBPNG_VER_SONUM 2 #define PNG_LIBPNG_VER_DLLNUM %DLLNUM% @@ -274,7 +275,7 @@ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MINOR 0 -#define PNG_LIBPNG_VER_RELEASE 11 +#define PNG_LIBPNG_VER_RELEASE 12 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ @@ -293,7 +294,7 @@ * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only * version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10011 /* 1.0.11 */ +#define PNG_LIBPNG_VER 10012 /* 1.0.12 */ #ifndef PNG_VERSION_INFO_ONLY @@ -699,6 +700,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) png_byte pcal_nparams; /* number of parameters given in pcal_params */ #endif +/* New members added in libpng-1.0.6 */ #ifdef PNG_FREE_ME_SUPPORTED png_uint_32 free_me; /* flags items libpng is responsible for freeing */ #endif @@ -1139,12 +1141,6 @@ struct png_struct_def png_charp time_buffer; /* String to hold RFC 1123 time text */ #endif -#ifdef PNG_USER_MEM_SUPPORTED - png_voidp mem_ptr; /* user supplied struct for mem functions */ - png_malloc_ptr malloc_fn; /* function for allocating memory */ - png_free_ptr free_fn; /* function for freeing memory */ -#endif - /* New members added in libpng-1.0.6 */ #ifdef PNG_FREE_ME_SUPPORTED @@ -1161,35 +1157,59 @@ struct png_struct_def png_bytep chunk_list; #endif +/* New members added in libpng-1.0.3 */ #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) png_byte rgb_to_gray_status; + /* These were changed from png_byte in libpng-1.0.6 */ png_uint_16 rgb_to_gray_red_coeff; png_uint_16 rgb_to_gray_green_coeff; png_uint_16 rgb_to_gray_blue_coeff; #endif +/* New member added in libpng-1.0.4 (renamed in 1.0.9) */ #if defined(PNG_MNG_FEATURES_SUPPORTED) || \ defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) -/* Note to maintainer: change this to png_uint_32 at next opportunity */ +/* changed from png_byte to png_uint_32 at version 1.2.0 */ png_byte mng_features_permitted; #endif +/* New member added in libpng-1.0.7 */ #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) png_fixed_point int_gamma; #endif +/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) png_byte filter_type; +#endif +#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD) +/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */ png_uint_32 row_buf_size; +#endif + +/* New members added in libpng-1.2.0 */ +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + png_byte mmx_bitdepth_threshold; + png_uint_32 mmx_rowbytes_threshold; + png_uint_32 asm_flags; +#endif + +/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ +#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 }; /* This prevents a compiler error in png_get_copyright() in png.c if png.c -and png.h are both at * version 1.0.11 + and png.h are both at version 1.0.12 */ -typedef png_structp version_1_0_11; +typedef png_structp version_1_0_12; typedef png_struct FAR * FAR * png_structpp; @@ -1240,6 +1260,7 @@ extern PNG_EXPORT(void,png_set_compression_buffer_size) /* Reset the compression stream */ extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr)); +/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ #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, @@ -1270,8 +1291,11 @@ extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_infop,png_create_info_struct) PNGARG((png_structp png_ptr)); -/* Initialize the info structure (old interface - NOT DLL EXPORTED) */ -extern void png_info_init PNGARG((png_infop info_ptr)); +/* Initialize the info structure (old interface - DEPRECATED) */ +extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr)); +#define png_info_init(info_ptr) png_info_init_3(&info_ptr, sizeof(png_info)); +extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, + png_size_t png_info_struct_size)); /* Writes all the PNG information before the image. */ extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr, @@ -2229,15 +2253,23 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp png_ptr, png_uint_32 mng_features_permitted)); #endif -#if 0 /* delay these until version 1.2.0 */ +/* png_mmx_support will be included unconditionally starting in version 1.2.0 */ +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) || defined(PNG_USE_PNGGCCRD) /* png.c, pnggccrd.c, or pngvcrd.c */ extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ + +/* Strip the prepended error numbers ("#nnn ") from error and warning + * messages before passing them to the error or warning handler. */ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp + png_ptr, png_uint_32 strip_mode)); #endif /* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */ #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.0.11 - April 27, 2001 (header)\n" + " libpng version 1.0.12 - June 8, 2001 (header)\n" #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* With these routines we avoid an integer divide, which will be slower on @@ -2360,6 +2392,8 @@ extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L +#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L +#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L /* For use in png_set_keep_unknown, png_handle_as_unknown */ #define HANDLE_CHUNK_AS_DEFAULT 0 @@ -2468,8 +2502,10 @@ PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf)); * (old interface - DEPRECATED - use png_create_read_struct instead). */ extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr)); -#define png_read_init(png_ptr) png_read_init_2(png_ptr, \ - PNG_LIBPNG_VER_STRING, sizeof(png_struct), sizeof(png_info)); +#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, sizeof(png_struct)); +extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t png_info_size)); @@ -2478,8 +2514,10 @@ extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, * (old interface - DEPRECATED - use png_create_write_struct instead). */ extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr)); -#define png_write_init(png_ptr) png_write_init_2(png_ptr, \ - PNG_LIBPNG_VER_STRING, sizeof(png_struct), sizeof(png_info)); +#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, sizeof(png_struct)); +extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr, png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t png_info_size)); @@ -2491,9 +2529,9 @@ PNG_EXTERN png_voidp png_create_struct PNGARG((int type)); 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)); + malloc_fn, png_voidp mem_ptr)); PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, - png_free_ptr free_fn)); + png_free_ptr free_fn, png_voidp mem_ptr)); /* Free any memory that info_ptr points to and reset struct. */ PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, diff --git a/pngasmrd.h b/pngasmrd.h index 1ed10e46f..2db18524d 100644 --- a/pngasmrd.h +++ b/pngasmrd.h @@ -1,6 +1,6 @@ /* pngasmrd.h - assembler version of utilities to read a PNG file * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 2001 Glenn Randers-Pehrson * diff --git a/pngconf.h b/pngconf.h index 6ecbc2d90..aa3ae1db3 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,6 +1,6 @@ /* pngconf.h - machine configurable file for libpng * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -47,8 +47,8 @@ # define PNG_WRITE_SUPPORTED #endif -/* Enable if you need to support PNGs that are embedded in MNG - datastreams */ +/* Enabled by default in 1.2.0. You can disable this if you don't need to + support PNGs that are embedded in MNG datastreams */ /* #ifndef PNG_NO_MNG_FEATURES # ifndef PNG_MNG_FEATURES_SUPPORTED @@ -93,47 +93,58 @@ * this bit of #ifdefs will define the 'correct' config variables based on * that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but * unnecessary. + * + * Also, the precedence order is: + * ALL_STATIC (since we can't #undef something outside our namespace) + * PNG_BUILD_DLL + * PNG_STATIC + * (nothing) == PNG_USE_DLL */ #if defined(__CYGWIN__) -# if defined(PNG_BUILD_DLL) +# if defined(ALL_STATIC) +# if defined(PNG_BUILD_DLL) +# undef PNG_BUILD_DLL +# endif # if defined(PNG_USE_DLL) # undef PNG_USE_DLL # endif -# if !defined(PNG_DLL) -# define PNG_DLL +# if defined(PNG_DLL) +# undef PNG_DLL # endif -# if defined(PNG_STATIC) -# undef PNG_STATIC -# endif -# else -# if defined(ALL_STATIC) +# if !defined(PNG_STATIC) # define PNG_STATIC # endif -# if defined(PNG_STATIC) +# else +# if defined (PNG_BUILD_DLL) +# if defined(PNG_STATIC) +# undef PNG_STATIC +# endif # if defined(PNG_USE_DLL) # undef PNG_USE_DLL # endif -# if defined(PNG_DLL) -# undef PNG_DLL +# if !defined(PNG_DLL) +# define PNG_DLL # endif # else -# if defined(PNG_USE_DLL) +# if defined(PNG_STATIC) +# if defined(PNG_USE_DLL) +# undef PNG_USE_DLL +# endif +# if defined(PNG_DLL) +# undef PNG_DLL +# endif +# else +# if !defined(PNG_USE_DLL) +# define PNG_USE_DLL +# endif # if !defined(PNG_DLL) # define PNG_DLL # endif -# else -# if defined(PNG_DLL) -# define PNG_USE_DLL -# else -# define PNG_USE_DLL -# define PNG_DLL -# endif -# endif -# endif +# endif +# endif # endif #endif - /* This protects us against compilers that run on a windowing system * and thus don't have or would rather us not use the stdio types: * stdin, stdout, and stderr. The only one currently used is stderr @@ -308,7 +319,8 @@ # include "alloc.h" #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \ + defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__)) # include #endif @@ -580,6 +592,13 @@ # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED #endif +/* Will be enabled in libpng-1.2.0 */ +/* +#ifndef PNG_NO_ERROR_NUMBERS +#define PNG_ERROR_NUMBERS_SUPPORTED +#endif +*/ + #ifndef PNG_NO_WRITE_FLUSH # define PNG_WRITE_FLUSH_SUPPORTED #endif @@ -611,12 +630,22 @@ * png_get_x_offset_microns() * png_get_y_offset_microns() */ -#ifndef PNG_NO_EASY_ACCESS +#if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED) # define PNG_EASY_ACCESS_SUPPORTED #endif -/* PNG_ASSEMBLER_CODE will be enabled by default in version 1.2.0 +/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined */ +/* +#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) +# ifndef PNG_ASSEMBLER_CODE_SUPPORTED +# define PNG_ASSEMBLER_CODE_SUPPORTED +# endif +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_MMX_CODE_SUPPORTED +# endif +#endif +*/ #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) # if defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD) # ifndef PNG_ASSEMBLER_CODE_SUPPORTED @@ -628,6 +657,13 @@ # endif #endif +/* This will be enabled by default in libpng-1.2.0 */ +/* +#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED) +# define PNG_USER_MEM_SUPPORTED +#endif +*/ + /* These are currently experimental features, define them if you want */ /* very little testing */ @@ -637,12 +673,6 @@ # define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED # endif #endif -#ifndef PNG_NO_USER_MEM -# define PNG_USER_MEM_SUPPORTED -#endif -#ifndef PNG_NO_ZALLOC_ZERO -# define PNG_ZALLOC_ZERO -#endif */ /* This is only for PowerPC big-endian and 680x0 systems */ diff --git a/pngcrush.c b/pngcrush.c index 5a7aea3a0..aa03b1c21 100644 --- a/pngcrush.c +++ b/pngcrush.c @@ -25,7 +25,7 @@ * */ -#define PNGCRUSH_VERSION "1.5.4" +#define PNGCRUSH_VERSION "1.5.5" /* #define PNGCRUSH_COUNT_COLORS @@ -66,6 +66,14 @@ */ /* Change log: + * + * Version 1.5.5 (built with libpng-1.0.12) + * + * Reset reduce_to_gray and it_is_opaque flags prior to processing each + * image. + * + * Enable removal of safe-to-copy chunks that are being handled as unknown + * e.g., "-rem time". * * Version 1.5.4 (built with libpng-1.0.11) * @@ -787,7 +795,8 @@ png_voidp 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 */ + png_debug_malloc directly (with png_ptr == NULL prior to libpng-1.2.0 + which is OK since we are not using a user mem_ptr) */ if (size == 0) return (png_voidp)(NULL); @@ -806,7 +815,8 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size) { /* Make sure the caller isn't assuming zeroed memory. */ png_memset(pinfo->pointer, 0xdd, pinfo->size); if(verbose > 2) - fprintf(STDERR, "Pointer %x allocated\n", (int)pinfo->pointer); + fprintf(STDERR, "Pointer %x allocated %lu bytes\n", + (int)pinfo->pointer, size); return (png_voidp)(pinfo->pointer); } } @@ -837,9 +847,10 @@ png_debug_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_free_default(png_ptr, pinfo); if(verbose > 2) - fprintf(STDERR, "Pointer %x freed\n", (int)ptr); + fprintf(STDERR, "Pointer %x freed %lu bytes\n", (int)ptr, + pinfo->size); + png_free_default(png_ptr, pinfo); break; } if (pinfo->next == NULL) { @@ -2124,6 +2135,7 @@ main(int argc, char *argv[]) " The program will use a smaller window anyway when\n"); fprintf(STDERR, " the uncompressed file is smaller than 16k.\n\n"); + } fprintf(STDERR, " -z zlib_strategy [0, 1, or 2]\n"); if(verbose > 1) @@ -2147,6 +2159,7 @@ main(int argc, char *argv[]) fprintf(STDERR, " -ztxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n"); if(verbose > 1) + { fprintf(STDERR, "\n zTXt chunk to insert (see -text).\n\n"); png_crush_pause(); @@ -2360,6 +2373,8 @@ main(int argc, char *argv[]) idat_length[0]=1; #ifdef PNGCRUSH_COUNT_COLORS + reduce_to_gray=0; + it_is_opaque=0; output_color_type = input_color_type; if (do_color_count) { @@ -2720,32 +2735,39 @@ main(int argc, char *argv[]) /* Process the following chunks as if safe-to-copy since it is known that recompressing the IDAT chunks has no effect on them */ #if !defined(PNG_cHRM_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - (png_bytep)png_cHRM, 1); + if(keep_chunk("cHRM",argv)) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_cHRM, 1); #endif #if !defined(PNG_hIST_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - (png_bytep)png_hIST, 1); + if(keep_chunk("hIST",argv)) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_hIST, 1); #endif #if !defined(PNG_iCCP_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - (png_bytep)png_iCCP, 1); + if(keep_chunk("iCCP",argv)) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_iCCP, 1); #endif #if !defined(PNG_sCAL_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - (png_bytep)png_sCAL, 1); + if(keep_chunk("sCAL",argv)) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_sCAL, 1); #endif #if !defined(PNG_pCAL_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - (png_bytep)png_pCAL, 1); + if(keep_chunk("pCAL",argv)) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_pCAL, 1); #endif #if !defined(PNG_sPLT_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - (png_bytep)png_sPLT, 1); + if(keep_chunk("sPLT",argv)) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_sPLT, 1); #endif #if !defined(PNG_tIME_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - (png_bytep)png_tIME, 1); + if(keep_chunk("tIME",argv)) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_tIME, 1); #endif #else /* PNG_UINT_IHDR is defined; we are using libpng newer than 1.0.6 */ @@ -2761,39 +2783,60 @@ main(int argc, char *argv[]) png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, NULL, 0); #if !defined(PNG_cHRM_SUPPORTED) - png_save_uint_32(chunk_name, PNG_UINT_cHRM); - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - chunk_name, 1); + if(keep_chunk("cHRM",argv)) + { + png_save_uint_32(chunk_name, PNG_UINT_cHRM); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); + } #endif #if !defined(PNG_hIST_SUPPORTED) - png_save_uint_32(chunk_name, PNG_UINT_hIST); - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - chunk_name, 1); + if(keep_chunk("hIST",argv)) + { + png_save_uint_32(chunk_name, PNG_UINT_hIST); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); + } #endif #if !defined(PNG_iCCP_SUPPORTED) - png_save_uint_32(chunk_name, PNG_UINT_iCCP); - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - chunk_name, 1); + if(keep_chunk("iCCP",argv)) + { + png_save_uint_32(chunk_name, PNG_UINT_iCCP); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); + } #endif #if !defined(PNG_sCAL_SUPPORTED) - png_save_uint_32(chunk_name, PNG_UINT_sCAL); - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - chunk_name, 1); + if(keep_chunk("sCAL",argv)) + { + png_save_uint_32(chunk_name, PNG_UINT_sCAL); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); + } #endif #if !defined(PNG_pCAL_SUPPORTED) - png_save_uint_32(chunk_name, PNG_UINT_pCAL); - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - chunk_name, 1); + if(keep_chunk("pCAL",argv)) + { + png_save_uint_32(chunk_name, PNG_UINT_pCAL); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); + } #endif #if !defined(PNG_sPLT_SUPPORTED) - png_save_uint_32(chunk_name, PNG_UINT_sPLT); - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - chunk_name, 1); + if(keep_chunk("sPLT",argv)) + { + png_save_uint_32(chunk_name, PNG_UINT_sPLT); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); + } #endif #if !defined(PNG_tIME_SUPPORTED) - png_save_uint_32(chunk_name, PNG_UINT_tIME); - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, - chunk_name, 1); + if(keep_chunk("tIME",argv)) + { + png_save_uint_32(chunk_name, PNG_UINT_tIME); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); + } #endif #endif /* PNG_UINT_IHDR */ } @@ -4466,7 +4509,7 @@ count_colors(FILE *fpin) png_debug(0, "Allocating read_info structure\n"); read_info_ptr = png_create_info_struct(read_ptr); if (read_info_ptr == NULL) - png_destroy_read_struct(&read_ptr, NULL, NULL); + png_destroy_read_struct(&read_ptr, (png_infop)NULL, (png_infop)NULL); } else read_info_ptr = NULL; @@ -4839,7 +4882,7 @@ count_colors(FILE *fpin) png_free (read_ptr, row_buf); row_buf = (png_bytep)NULL; png_debug(0, "Destroying data structs\n"); - png_destroy_read_struct(&read_ptr, &read_info_ptr, NULL); + png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infop)NULL); } else result=2; @@ -4849,7 +4892,7 @@ count_colors(FILE *fpin) fprintf(STDERR, "\nWhile checking alphas in %s ", inname); fprintf(STDERR,"pngcrush caught libpng error:\n %s\n\n",msg); png_free (read_ptr, row_buf); row_buf = (png_bytep)NULL; - png_destroy_read_struct(&read_ptr, &read_info_ptr, NULL); + png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infop)NULL); png_debug(0, "Destroyed data structs\n"); result=2; } diff --git a/pngcrush.h b/pngcrush.h index 580a6749c..a630f30bb 100644 --- a/pngcrush.h +++ b/pngcrush.h @@ -18,7 +18,8 @@ #define PNGCRUSH_LIBPNG_VER 10007 #endif -#if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_USE_PNGVCRD) +#if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_USE_PNGVCRD) && \ + !defined(PNG_NO_ASSEMBLER_CODE) #define PNG_NO_ASSEMBLER_CODE #endif diff --git a/pngerror.c b/pngerror.c index c991b538c..c2285ff6d 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -31,6 +31,38 @@ png_default_warning PNGARG((png_structp png_ptr, void PNGAPI png_error(png_structp png_ptr, png_const_charp message) { +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + char msg[16]; + if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) + { + int offset = 0; + if (*message == '#') + { + for (offset=1; offset<15; offset++) + if (*(message+offset) == ' ') + break; + if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + { + int i; + for (i=0; iflags&PNG_FLAG_STRIP_ERROR_TEXT) + { + msg[0]='0'; + msg[1]='\0'; + message=msg; + } + } + } +#endif if (png_ptr->error_fn != NULL) (*(png_ptr->error_fn))(png_ptr, message); @@ -47,10 +79,22 @@ png_error(png_structp png_ptr, png_const_charp message) void PNGAPI png_warning(png_structp png_ptr, png_const_charp message) { + int offset = 0; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) +#endif + { + if (*message == '#') + { + for (offset=1; offset<15; offset++) + if (*(message+offset) == ' ') + break; + } + } if (png_ptr->warning_fn != NULL) - (*(png_ptr->warning_fn))(png_ptr, message); + (*(png_ptr->warning_fn))(png_ptr, (png_const_charp)(message+offset)); else - png_default_warning(png_ptr, message); + png_default_warning(png_ptr, (png_const_charp)(message+offset)); } /* These utilities are used internally to build an error message that relates @@ -122,6 +166,27 @@ static void /* PRIVATE */ png_default_error(png_structp png_ptr, png_const_charp message) { #ifndef PNG_NO_CONSOLE_IO +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*message == '#') + { + int offset; + char error_number[16]; + for (offset=0; offset<15; offset++) + { + error_number[offset] = *(message+offset+1); + if (*(message+offset) == ' ') + break; + } + if((offset > 1) && (offset < 15)) + { + error_number[offset-1]='\0'; + fprintf(stderr, "libpng error no. %s: %s\n", error_number, message+offset); + } + else + fprintf(stderr, "libpng error: %s, offset=%d\n", message,offset); + } + else +#endif fprintf(stderr, "libpng error: %s\n", message); #else if (message) @@ -154,7 +219,29 @@ static void /* PRIVATE */ png_default_warning(png_structp png_ptr, png_const_charp message) { #ifndef PNG_NO_CONSOLE_IO - fprintf(stderr, "libpng warning: %s\n", message); +# ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*message == '#') + { + int offset; + char warning_number[16]; + for (offset=0; offset<15; offset++) + { + warning_number[offset]=*(message+offset+1); + if (*(message+offset) == ' ') + break; + } + if((offset > 1) && (offset < 15)) + { + warning_number[offset-1]='\0'; + fprintf(stderr, "libpng warning no. %s: %s\n", warning_number, + message+offset); + } + else + fprintf(stderr, "libpng warning: %s\n", message); + } + else +# endif + fprintf(stderr, "libpng warning: %s\n", message); #else if (message) /* appease compiler */ ; @@ -189,4 +276,15 @@ png_get_error_ptr(png_structp png_ptr) } +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +void +png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) +{ + if(png_ptr != NULL) + { + png_ptr->flags &= + ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); + } +} +#endif diff --git a/pnggccrd.c b/pnggccrd.c index b4703ee77..62ea6905b 100644 --- a/pnggccrd.c +++ b/pnggccrd.c @@ -6,7 +6,7 @@ * and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm * for Intel's performance analysis of the MMX vs. non-MMX code. * - * libpng version 1.0.11 - April 27, 2001 + * libpng version 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * Copyright (c) 1998, Intel Corporation @@ -333,6 +333,34 @@ static int _dif; static int _patemp; // temp variables for Paeth routine static int _pbtemp; static int _pctemp; + +static void /* PRIVATE */ +png_squelch_warnings(void) +{ + _dif = _dif; + _patemp = _patemp; + _pbtemp = _pbtemp; + _pctemp = _pctemp; + _const4 = _const4; + _const6 = _const6; + _MMXLength = _MMXLength; + _mask8_0 = _mask8_0; + _mask16_1 = _mask16_1; + _mask16_0 = _mask16_0; + _mask24_2 = _mask24_2; + _mask24_1 = _mask24_1; + _mask24_0 = _mask24_0; + _mask32_3 = _mask32_3; + _mask32_2 = _mask32_2; + _mask32_1 = _mask32_1; + _mask32_0 = _mask32_0; + _mask48_5 = _mask48_5; + _mask48_4 = _mask48_4; + _mask48_3 = _mask48_3; + _mask48_2 = _mask48_2; + _mask48_1 = _mask48_1; + _mask48_0 = _mask48_0; +} #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ static int _mmx_supported = 2; diff --git a/pngget.c b/pngget.c index 5348c60e3..208918f0c 100644 --- a/pngget.c +++ b/pngget.c @@ -1,7 +1,7 @@ /* pngget.c - retrieval of values from info struct * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -826,3 +826,4 @@ png_get_compression_buffer_size(png_structp png_ptr) return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); } + diff --git a/pngmem.c b/pngmem.c index 425df56b6..dd74715eb 100644 --- a/pngmem.c +++ b/pngmem.c @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -27,12 +27,12 @@ png_voidp /* PRIVATE */ png_create_struct(int type) { #ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL)); + return (png_create_struct_2(type, NULL, NULL)); } /* Alternate version of png_create_struct, for use with user-defined malloc. */ png_voidp /* PRIVATE */ -png_create_struct_2(int type, png_malloc_ptr malloc_fn) +png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) { #endif /* PNG_USER_MEM_SUPPORTED */ png_size_t size; @@ -48,9 +48,18 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn) #ifdef PNG_USER_MEM_SUPPORTED if(malloc_fn != NULL) { - if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL) + if (mem_ptr != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(png_ptr, size); + } + else + struct_ptr = (*(malloc_fn))(NULL, size); + if (struct_ptr != NULL) png_memset(struct_ptr, 0, size); - return (struct_ptr); + return (struct_ptr); } #endif /* PNG_USER_MEM_SUPPORTED */ if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL) @@ -66,12 +75,13 @@ void /* PRIVATE */ png_destroy_struct(png_voidp struct_ptr) { #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL); + png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL, (png_voidp)NULL); } /* Free memory allocated by a png_create_struct() call */ void /* PRIVATE */ -png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn) +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) { #endif if (struct_ptr != NULL) @@ -81,6 +91,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn) { png_struct dummy_struct; png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; (*(free_fn))(png_ptr, struct_ptr); return; } @@ -286,14 +297,14 @@ png_voidp /* PRIVATE */ png_create_struct(int type) { #ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL)); + return (png_create_struct_2(type, NULL, 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 /* PRIVATE */ -png_create_struct_2(int type, png_malloc_ptr malloc_fn) +png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) { #endif /* PNG_USER_MEM_SUPPORTED */ png_size_t size; @@ -309,7 +320,16 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn) #ifdef PNG_USER_MEM_SUPPORTED if(malloc_fn != NULL) { - if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL) + if (mem_ptr != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(png_ptr, size); + } + else + struct_ptr = (*(malloc_fn))(NULL, size); + if (struct_ptr != NULL) png_memset(struct_ptr, 0, size); return (struct_ptr); } @@ -337,12 +357,13 @@ void /* PRIVATE */ png_destroy_struct(png_voidp struct_ptr) { #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL); + png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL, (png_voidp)NULL); } /* Free memory allocated by a png_create_struct() call */ void /* PRIVATE */ -png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn) +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) { #endif /* PNG_USER_MEM_SUPPORTED */ if (struct_ptr != NULL) @@ -352,6 +373,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn) { png_struct dummy_struct; png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; (*(free_fn))(png_ptr, struct_ptr); return; } diff --git a/pngpread.c b/pngpread.c index 9b4a9e516..9b4b77a93 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,7 +1,7 @@ /* pngpread.c - read a png file in push mode * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngread.c b/pngread.c index f84ede846..ca6969982 100644 --- a/pngread.c +++ b/pngread.c @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -46,7 +46,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, 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) + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr)) == NULL) #else if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) #endif @@ -92,22 +92,55 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, * only check the first digit. */ if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || + (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || (user_png_ver[0] == '0' && user_png_ver[2] < '9')) { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif png_error(png_ptr, "Incompatible libpng version in application and library"); } /* Libpng 1.0.6 was not binary compatible, due to insertion of the - info_ptr->free_me member. Note to maintainer: this test can be - removed from version 2.0.0 and beyond because the previous test - would have already rejected it. */ + info_ptr->free_me member. Libpng-1.0.1 and earlier were not + compatible due to insertion of the user transform function. Note + to maintainer: this test can be removed from version 1.2.0 and + beyond because the previous test would have already rejected it. */ - if (user_png_ver[4] == '6' && user_png_ver[2] == '0' && - user_png_ver[0] == '1' && user_png_ver[5] == '\0') + if (user_png_ver[0] == '1' && user_png_ver[2] == '0' && + (user_png_ver[4] < '2' || user_png_ver[4] == '6') && + user_png_ver[5] == '\0') { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif png_error(png_ptr, - "Application must be recompiled; version 1.0.6 was incompatible"); + "Application must be recompiled; versions <= 1.0.6 were incompatible"); } } @@ -144,18 +177,64 @@ void PNGAPI png_read_init(png_structp png_ptr) { /* We only come here via pre-1.0.7-compiled applications */ - png_read_init_2(png_ptr, "1.0.0", 10000, 10000); + png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); } +#undef png_read_init_2 void PNGAPI png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t png_info_size) +{ + /* We only come here via pre-1.0.12-compiled applications */ +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + if(sizeof(png_struct) > png_struct_size || sizeof(png_info) > png_info_size) + { + char msg[80]; + png_ptr->warning_fn=(png_error_ptr)NULL; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); + } +#endif + if(sizeof(png_struct) > png_struct_size) + { + png_ptr->error_fn=(png_error_ptr)NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for reading is too small."); + } + if(sizeof(png_info) > png_info_size) + { + png_ptr->error_fn=(png_error_ptr)NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The info struct allocated by application for reading is too small."); + } + png_read_init_3(&png_ptr, user_png_ver, png_struct_size); +} + +void PNGAPI +png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) { #ifdef PNG_SETJMP_SUPPORTED jmp_buf tmp_jmp; /* to save current jump buffer */ #endif int i=0; + + png_structp png_ptr=*ptr_ptr; + do { if(user_png_ver[i] != png_libpng_ver[i]) @@ -163,28 +242,28 @@ png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, #ifdef PNG_LEGACY_SUPPORTED png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; #else - png_ptr->error_fn=(png_error_ptr)NULL; - png_error(png_ptr, - "Application uses deprecated png_read_init() and must be recompiled."); + png_ptr->warning_fn=(png_error_ptr)NULL; + png_warning(png_ptr, + "Application uses deprecated png_read_init() and should be recompiled."); + break; #endif } } while (png_libpng_ver[i++]); - if(sizeof(png_struct) > png_struct_size || - sizeof(png_info) > png_info_size) - { - png_ptr->error_fn=(png_error_ptr)NULL; - png_error(png_ptr, - "Application and library have different sized structs. Please recompile."); - } - - png_debug(1, "in png_read_init_2\n"); + png_debug(1, "in png_read_init_3\n"); #ifdef PNG_SETJMP_SUPPORTED /* save jump buffer and error functions */ png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); #endif + if(sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + png_ptr = *ptr_ptr; + } + /* reset all variables to 0 */ png_memset(png_ptr, 0, sizeof (png_struct)); @@ -715,7 +794,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) * not called png_set_interlace_handling(), the display_row buffer will * be ignored, so pass NULL to it. * - * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.11 + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.12 */ void PNGAPI @@ -764,7 +843,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row, * only call this function once. If you desire to have an image for * each pass of a interlaced image, use png_read_rows() instead. * - * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.11 + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.12 */ void PNGAPI png_read_image(png_structp png_ptr, png_bytepp image) @@ -994,6 +1073,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infop info_ptr = NULL, end_info_ptr = NULL; #ifdef PNG_USER_MEM_SUPPORTED png_free_ptr free_fn = NULL; + png_voidp mem_ptr = NULL; #endif png_debug(1, "in png_destroy_read_struct\n"); @@ -1009,6 +1089,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, #ifdef PNG_USER_MEM_SUPPORTED free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; #endif png_read_destroy(png_ptr, info_ptr, end_info_ptr); @@ -1020,7 +1101,8 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, #endif #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, free_fn); + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); #else png_destroy_struct((png_voidp)info_ptr); #endif @@ -1033,7 +1115,8 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); #endif #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)end_info_ptr, free_fn); + png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); #else png_destroy_struct((png_voidp)end_info_ptr); #endif @@ -1043,7 +1126,8 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, if (png_ptr != NULL) { #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, free_fn); + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); #else png_destroy_struct((png_voidp)png_ptr); #endif diff --git a/pngrio.c b/pngrio.c index 4290624e9..707a139d4 100644 --- a/pngrio.c +++ b/pngrio.c @@ -1,7 +1,7 @@ /* pngrio.c - functions for data input * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -26,7 +26,7 @@ void /* PRIVATE */ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { - png_debug1(4,"reading %d bytes\n", length); + png_debug1(4,"reading %d bytes\n", (int)length); if (png_ptr->read_data_fn != NULL) (*(png_ptr->read_data_fn))(png_ptr, data, length); else diff --git a/pngrtran.c b/pngrtran.c index af7631ee3..ef070c88e 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,7 +1,7 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngrutil.c b/pngrutil.c index 284f636de..ec970ce41 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -339,7 +339,9 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_ptr->bit_depth = (png_byte)bit_depth; png_ptr->interlaced = (png_byte)interlace_type; png_ptr->color_type = (png_byte)color_type; +#if defined(PNG_MNG_FEATURES_SUPPORTED) png_ptr->filter_type = (png_byte)filter_type; +#endif /* find number of channels */ switch (png_ptr->color_type) @@ -396,6 +398,13 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_ptr->mode |= PNG_HAVE_PLTE; + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring PLTE chunk in grayscale PNG"); + png_crc_finish(png_ptr, length); + return; + } #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) { @@ -512,9 +521,7 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_error(png_ptr, "No image in file"); - /* to quiet compiler warnings about unused info_ptr */ - if (info_ptr == NULL) - return; + info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */ } png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); @@ -1022,6 +1029,13 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) profile_length = data_length - prefix_length; + if ( profile_length < 4) + { + png_free(png_ptr, chunkdata); + png_warning(png_ptr, "Profile size field missing from iCCP chunk"); + return; + } + /* Check the profile_size recorded in the first 32 bits of the ICC profile */ profile_size = ((*(chunkdata+prefix_length))<<24) | ((*(chunkdata+prefix_length+1))<<16) | @@ -1033,6 +1047,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if(profile_size > profile_length) { + png_free(png_ptr, chunkdata); png_warning(png_ptr, "Ignoring truncated iCCP profile.\n"); return; } @@ -2083,8 +2098,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, skip); #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED) - if (info_ptr == NULL) - /* quiet compiler warnings about unused info_ptr */ ; + info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */ #endif } @@ -2545,9 +2559,7 @@ png_do_read_interlace(png_structp png_ptr) (png_uint_32)row_info->pixel_depth + 7) >> 3); } #if !defined(PNG_READ_PACKSWAP_SUPPORTED) - /* silence compiler warning */ - if (transformations) - return; + transformations = transformations; /* silence compiler warning */ #endif } #endif /* !PNG_HAVE_ASSEMBLER_READ_INTERLACE */ @@ -2964,7 +2976,9 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) png_error(png_ptr, "This image requires a row greater than 64KB"); #endif png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, row_bytes); +#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD) png_ptr->row_buf_size = row_bytes; +#endif #ifdef PNG_MAX_MALLOC_64K if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L) diff --git a/pngset.c b/pngset.c index 61de5dd00..ddc4d0cb7 100644 --- a/pngset.c +++ b/pngset.c @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -654,8 +654,9 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, textp->key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4)); - png_debug2(2, "Allocated %d bytes at %x in png_set_text\n", - key_len + lang_len + lang_key_len + text_length + 4, (int)textp->key); + png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n", + (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4), + (int)textp->key); png_memcpy(textp->key, text_ptr[i].key, (png_size_t)(key_len)); @@ -968,3 +969,4 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) info_ptr->valid &= ~(mask); } + diff --git a/pngtrans.c b/pngtrans.c index a3b80a38e..3e757c171 100644 --- a/pngtrans.c +++ b/pngtrans.c @@ -1,7 +1,7 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngvcrd.c b/pngvcrd.c index b00a56d45..f464f34cb 100644 --- a/pngvcrd.c +++ b/pngvcrd.c @@ -2,7 +2,7 @@ * * For Intel x86 CPU and Microsoft Visual C++ compiler * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * Copyright (c) 1998, Intel Corporation diff --git a/pngwio.c b/pngwio.c index a5bd4570a..23f881e98 100644 --- a/pngwio.c +++ b/pngwio.c @@ -1,7 +1,7 @@ /* pngwio.c - functions for data output * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngwrite.c b/pngwrite.c index e0291d39d..63208b629 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,7 +1,7 @@ /* pngwrite.c - general routines to write a PNG file * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -444,7 +444,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, 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) + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr)) == NULL) #else if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) #endif /* PNG_USER_MEM_SUPPORTED */ @@ -489,22 +489,55 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, * only check the first digit. */ if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || + (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || (user_png_ver[0] == '0' && user_png_ver[2] < '9')) { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif png_error(png_ptr, "Incompatible libpng version in application and library"); } /* Libpng 1.0.6 was not binary compatible, due to insertion of the - info_ptr->free_me member. Note to maintainer: this test can be - removed from version 2.0.0 and beyond because the previous test - would have already rejected it. */ + info_ptr->free_me member. Libpng-1.0.1 and earlier were not + compatible due to insertion of the user transform function. Note + to maintainer: this test can be removed from version 1.2.0 and + beyond because the previous test would have already rejected it. */ - if (user_png_ver[4] == '6' && user_png_ver[2] == '0' && - user_png_ver[0] == '1' && user_png_ver[5] == '\0') + if (user_png_ver[0] == '1' && user_png_ver[2] == '0' && + (user_png_ver[4] < '2' || user_png_ver[4] == '6') && + user_png_ver[5] == '\0') { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif png_error(png_ptr, - "Application must be recompiled; version 1.0.6 was incompatible"); + "Application must be recompiled; versions <= 1.0.6 were incompatible"); } } @@ -529,13 +562,58 @@ void PNGAPI png_write_init(png_structp png_ptr) { /* We only come here via pre-1.0.7-compiled applications */ - png_write_init_2(png_ptr, "1.0.0", 10000, 10000); + png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); } +#undef png_write_init_2 void PNGAPI png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t png_info_size) { + /* We only come here via pre-1.0.12-compiled applications */ +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + if(sizeof(png_struct) > png_struct_size || sizeof(png_info) > png_info_size) + { + char msg[80]; + png_ptr->warning_fn=(png_error_ptr)NULL; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); + } +#endif + if(sizeof(png_struct) > png_struct_size) + { + png_ptr->error_fn=(png_error_ptr)NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for writing is too small."); + } + if(sizeof(png_info) > png_info_size) + { + png_ptr->error_fn=(png_error_ptr)NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The info struct allocated by the application for writing is too small."); + } + png_write_init_3(&png_ptr, user_png_ver, png_struct_size); +} + + +void PNGAPI +png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) +{ + png_structp png_ptr=*ptr_ptr; #ifdef PNG_SETJMP_SUPPORTED jmp_buf tmp_jmp; /* to save current jump buffer */ #endif @@ -547,28 +625,28 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, #ifdef PNG_LEGACY_SUPPORTED png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; #else - png_ptr->error_fn=(png_error_ptr)NULL; - png_error(png_ptr, - "Application uses deprecated png_write_init() and must be recompiled."); + png_ptr->warning_fn=(png_error_ptr)NULL; + png_warning(png_ptr, + "Application uses deprecated png_write_init() and should be recompiled."); + break; #endif } } while (png_libpng_ver[i++]); - if (sizeof(png_struct) > png_struct_size || - sizeof(png_info) > png_info_size) - { - png_ptr->error_fn=(png_error_ptr)NULL; - png_error(png_ptr, - "Application and library have different sized structs. Please recompile."); - } - - png_debug(1, "in png_write_init_2\n"); + png_debug(1, "in png_write_init_3\n"); #ifdef PNG_SETJMP_SUPPORTED /* save jump buffer and error functions */ png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); #endif + if (sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + *ptr_ptr = png_ptr; + } + /* reset all variables to 0 */ png_memset(png_ptr, 0, sizeof (png_struct)); @@ -577,11 +655,12 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); #endif + png_set_write_fn(png_ptr, NULL, NULL, NULL); + /* initialize zbuf - compression buffer */ png_ptr->zbuf_size = PNG_ZBUF_SIZE; png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size); - png_set_write_fn(png_ptr, NULL, NULL, NULL); #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, @@ -876,6 +955,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) png_infop info_ptr = NULL; #ifdef PNG_USER_MEM_SUPPORTED png_free_ptr free_fn = NULL; + png_voidp mem_ptr = NULL; #endif png_debug(1, "in png_destroy_write_struct\n"); @@ -904,7 +984,8 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) #endif #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, free_fn); + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); #else png_destroy_struct((png_voidp)info_ptr); #endif @@ -915,7 +996,8 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) { png_write_destroy(png_ptr); #ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, free_fn); + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); #else png_destroy_struct((png_voidp)png_ptr); #endif diff --git a/pngwtran.c b/pngwtran.c index fc18c6033..3cc60672a 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -1,7 +1,7 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngwutil.c b/pngwutil.c index b8c822269..a1db9c291 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,7 +1,7 @@ /* pngwutil.c - utilities to write a PNG file * - * libpng 1.0.11 - April 27, 2001 + * libpng 1.0.12 - June 8, 2001 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2001 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -285,7 +285,7 @@ png_text_compress(png_structp png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr, (png_uint_32)(comp->max_output_ptr * sizeof (png_charpp))); png_memcpy(comp->output_ptr, old_ptr, - old_max * sizeof (png_charp)); + old_max * sizeof (png_charp)); png_free(png_ptr, old_ptr); } else @@ -435,7 +435,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, #if defined(PNG_MNG_FEATURES_SUPPORTED) !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && - (color_type == PNG_COLOR_TYPE_RGB || + (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) && (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && #endif @@ -460,7 +460,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, png_ptr->bit_depth = (png_byte)bit_depth; png_ptr->color_type = (png_byte)color_type; png_ptr->interlaced = (png_byte)interlace_type; +#if defined(PNG_MNG_FEATURES_SUPPORTED) png_ptr->filter_type = (png_byte)filter_type; +#endif png_ptr->width = width; png_ptr->height = height; @@ -536,20 +538,27 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) png_debug(1, "in png_write_PLTE\n"); if (( #if defined(PNG_MNG_FEATURES_SUPPORTED) || \ - defined (PNG_WRITE_EMPTY_PLTE_SUPPORTED) + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && #endif num_pal == 0) || num_pal > 256) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - png_error(png_ptr, "Invalid number of colors in palette"); - } - else - { - png_warning(png_ptr, "Invalid number of colors in palette"); - return; - } + png_error(png_ptr, "Invalid number of colors in palette"); + } + else + { + png_warning(png_ptr, "Invalid number of colors in palette"); + return; + } + } + + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring request to write a PLTE chunk in grayscale PNG"); + return; } png_ptr->num_palette = (png_uint_16)num_pal; @@ -1020,7 +1029,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) { if ( #if defined(PNG_MNG_FEATURES_SUPPORTED) || \ - defined (PNG_WRITE_EMPTY_PLTE_SUPPORTED) + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) (png_ptr->num_palette || (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && #endif @@ -1109,7 +1118,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key) png_debug1(2, "Keyword to be checked is '%s'\n", key); *new_key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + 2)); - + /* Replace non-printing characters with a blank and print a warning */ for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++) { @@ -1417,9 +1426,9 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; - png_debug1(3, "pCAL purpose length = %d\n", purpose_len); + png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len); units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); - png_debug1(3, "pCAL units length = %d\n", units_len); + png_debug1(3, "pCAL units length = %d\n", (int)units_len); total_len = purpose_len + units_len + 10; params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams @@ -1434,7 +1443,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, total_len += (png_size_t)params_len[i]; } - png_debug1(3, "pCAL total length = %d\n", total_len); + png_debug1(3, "pCAL total length = %d\n", (int)total_len); png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len); png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len); png_save_int_32(buf, X0); @@ -1486,7 +1495,7 @@ png_write_sCAL(png_structp png_ptr, int unit, double width,double height) #endif total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf); - png_debug1(3, "sCAL total length = %d\n", total_len); + png_debug1(3, "sCAL total length = %d\n", (int)total_len); png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len); png_write_chunk_data(png_ptr, (png_bytep)&unit, 1); png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1); diff --git a/zlib.h b/zlib.h index c9764b504..f06812208 100644 --- a/zlib.h +++ b/zlib.h @@ -35,6 +35,11 @@ * * The switch statement in inflate.c was rearranged so that case BLOCKS is * checked first. Glenn Randers-Pehrson, April 2001. + * + * Added tests for Windows platforms at line 136 in zutil.h, since some + * emulators will use MSC compiler on other platforms. Glenn Randers-Pehrson, + * May 2001. Suggested by Emmanuel Blot. + * */ #ifndef _ZLIB_H diff --git a/zutil.h b/zutil.h index 6f2cb97ca..fe7583314 100644 --- a/zutil.h +++ b/zutil.h @@ -8,6 +8,8 @@ subject to change. Applications should only use zlib.h. */ +/* Added tests for Windows platforms at line 136. glennrp, May 2001 */ + /* @(#) $Id$ */ #ifndef _Z_UTIL_H @@ -133,7 +135,9 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ # define fdopen(fd,mode) NULL /* No fdopen() */ #endif -#if (defined(_MSC_VER) && (_MSC_VER > 600)) +#if (defined(_MSC_VER) && (_MSC_VER > 600)) && (defined(WIN32) || \ + defined(_Windows) || defined(_WINDOWS) || defined(_WIN32) || \ + defined(__WIN32__)) # define fdopen(fd,type) _fdopen(fd,type) #endif