diff options
-rw-r--r-- | README.txt | 34 | ||||
-rw-r--r-- | png.c | 63 | ||||
-rw-r--r-- | png.h | 152 | ||||
-rw-r--r-- | pngasmrd.h | 4 | ||||
-rw-r--r-- | pngconf.h | 10 | ||||
-rw-r--r-- | pngcrush.c | 241 | ||||
-rw-r--r-- | pngcrush.h | 18 | ||||
-rw-r--r-- | pngerror.c | 4 | ||||
-rw-r--r-- | pngget.c | 35 | ||||
-rw-r--r-- | pngmem.c | 2 | ||||
-rw-r--r-- | pngpread.c | 2 | ||||
-rw-r--r-- | pngread.c | 53 | ||||
-rw-r--r-- | pngrio.c | 2 | ||||
-rw-r--r-- | pngrtran.c | 82 | ||||
-rw-r--r-- | pngrutil.c | 142 | ||||
-rw-r--r-- | pngset.c | 70 | ||||
-rw-r--r-- | pngtrans.c | 2 | ||||
-rw-r--r-- | pngtypes.h | 5 | ||||
-rw-r--r-- | pngvcrd.c | 2 | ||||
-rw-r--r-- | pngwio.c | 2 | ||||
-rw-r--r-- | pngwrite.c | 60 | ||||
-rw-r--r-- | pngwtran.c | 6 | ||||
-rw-r--r-- | pngwutil.c | 12 |
23 files changed, 609 insertions, 394 deletions
diff --git a/README.txt b/README.txt index 94dcdf250..1d298250e 100644 --- a/README.txt +++ b/README.txt @@ -1,8 +1,8 @@ - | pngcrush 1.3.0, Copyright (C) 1998, 1999, Glenn Randers-Pehrson + | pngcrush 1.3.1, Copyright (C) 1998, 1999, Glenn Randers-Pehrson | This is a free, open-source program. Permission is | granted to everyone to use pngcrush without fee. - | This program was built with libpng version 1.0.5j, + | This program was built with libpng version 1.0.5k, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., | Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1998, 1999, Glenn Randers-Pehrson, @@ -22,6 +22,7 @@ options: -f user_filter [0-5] -force (Write a new output file even if larger than input) -g gamma_value (float, e.g., 0.45455) + -itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -l zlib_compression_level [0-9] -m method [0 through 200] -max maximum_IDAT_size [1 through 524288] @@ -39,21 +40,6 @@ options: -h (help) -p (pause) - | pngcrush 1.3.0, Copyright (C) 1998, 1999, Glenn Randers-Pehrson - | This is a free, open-source program. Permission is - | granted to everyone to use pngcrush without fee. - | This program was built with libpng version 1.0.5j, - | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., - | Copyright (C) 1996, 1997 Andreas Dilger, - | Copyright (C) 1998, 1999, Glenn Randers-Pehrson, - | and zlib version 1.1.3, Copyright (c) 1998, - | Jean-loup Gailly and Mark Adler. - - -usage: pngcrush [options] infile.png outfile.png - pngcrush -e ext [other options] files.png ... - pngcrush -d dir [other options] files.png ... - options: -brute (Use brute-force, try 114 different methods) @@ -108,6 +94,10 @@ options: file has no gAMA chunk. To replace an existing gAMA chunk, use the '-replace_gamma' option. + -itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" + + Compressed iTXt chunk to insert (see -text). + -l zlib_compression_level [0-9] zlib compression level to use with method specified @@ -169,7 +159,7 @@ options: tEXt chunk to insert. keyword < 80 chars, text < 2048 chars. For now, you can only add ten - tEXt or zTXt chunks per pngcrush run. + tEXt, iTXt, or zTXt chunks per pngcrush run. -trns index red green blue gray @@ -194,6 +184,14 @@ options: zlib compression strategy to use with the preceding '-m method' argument. + -zitxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" + + Compressed iTXt chunk to insert (see -text). + + -ztxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" + + zTXt chunk to insert (see -text). + -h (help) Display this information. @@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions * - * libpng version 1.0.5j - December 21, 1999 + * libpng version 1.0.5k - December 27, 1999 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1998, 1999 Glenn Randers-Pehrson @@ -19,7 +19,7 @@ #ifdef PNG_USE_GLOBAL_ARRAYS /* png_libpng_ver was changed to a function in version 1.0.5c */ -char png_libpng_ver[12] = "1.0.5j"; +char png_libpng_ver[12] = "1.0.5k"; /* png_sig was changed to a function in version 1.0.5c */ /* Place to hold the signature string for a PNG file. */ @@ -289,6 +289,21 @@ png_free_text(png_structp png_ptr, png_infop info_ptr, int num) } #endif +#if defined(PNG_tRNS_SUPPORTED) +/* free any tRNS entry */ +void +png_free_tRNS(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + if (info_ptr->valid & PNG_INFO_tRNS) + { + png_free(png_ptr, info_ptr->trans); + info_ptr->valid &= ~PNG_INFO_tRNS; + } +} +#endif + #if defined(PNG_sCAL_SUPPORTED) /* free any sCAL entry */ void @@ -298,7 +313,7 @@ png_free_sCAL(png_structp png_ptr, png_infop info_ptr) return; if (info_ptr->valid & PNG_INFO_sCAL) { -#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED) +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) png_free(png_ptr, info_ptr->scal_s_width); png_free(png_ptr, info_ptr->scal_s_height); #else @@ -405,6 +420,17 @@ png_free_unknown_chunks(png_structp png_ptr, png_infop info_ptr, int num) info_ptr->unknown_chunks_num = 0; } } +void +png_free_chunk_list(png_structp png_ptr) +{ + if (png_ptr == NULL) + return; + if (png_ptr->num_chunk_list) + { + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->num_chunk_list=0; + } +} #endif #if defined(PNG_hIST_SUPPORTED) @@ -433,6 +459,9 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) #if defined(PNG_READ_TEXT_SUPPORTED) png_free_text(png_ptr, info_ptr, -1); #endif +#if defined(PNG_READ_tRNS_SUPPORTED) + png_free_tRNS(png_ptr, info_ptr); +#endif #if defined(PNG_READ_sCAL_SUPPORTED) png_free_sCAL(png_ptr, info_ptr); #endif @@ -447,6 +476,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) #endif #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) png_free_unknown_chunks(png_ptr, info_ptr, -1); + png_free_chunk_list(png_ptr); #endif #if defined(PNG_hIST_SUPPORTED) png_free_hIST(png_ptr, info_ptr); @@ -528,7 +558,7 @@ png_charp png_get_copyright(png_structp png_ptr) { if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */ - return ("\n libpng version 1.0.5j - December 21, 1999\n\ + return ("\n libpng version 1.0.5k - December 27, 1999\n\ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\ Copyright (c) 1996, 1997 Andreas Dilger\n\ Copyright (c) 1998, 1999 Glenn Randers-Pehrson\n"); @@ -546,8 +576,8 @@ png_get_libpng_ver(png_structp png_ptr) { /* Version of *.c files used when building libpng */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return("1.0.5j"); - return("1.0.5j"); + return("1.0.5k"); + return("1.0.5k"); } png_charp @@ -571,8 +601,25 @@ png_get_header_version(png_structp png_ptr) /* Generate a compiler error if there is an old png.h in the search path. */ void png_check_version - (version_1_0_5j png_h_is_not_version_1_0_5j) + (version_1_0_5k png_h_is_not_version_1_0_5k) { - if(png_h_is_not_version_1_0_5j == NULL) + if(png_h_is_not_version_1_0_5k == NULL) return; } + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +int +png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) +{ + /* check chunk_name and return "keep" value if it's on the list, else 0 */ + int i; + png_bytep p; + if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0) + return 0; + p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5; + for (i = png_ptr->num_chunk_list; i; i--, p-=5) + if (!png_memcmp(chunk_name, p, 4)) + return ((int)*(p+4)); + return 0; +} +#endif @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.0.5j - December 21, 1999 + * libpng version 1.0.5k - December 27, 1999 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1998, 1999 Glenn Randers-Pehrson @@ -9,19 +9,19 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.89c, May 1996: Guy Schalnat * libpng versions 0.90, December 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.0.5j - December 21, 1999: Glenn + * libpng versions 0.97, January 1998, through 1.0.5k - December 27, 1999: Glenn * See also "Contributing Authors", below. * * Y2K compliance in libpng: * ========================= * - * December 21, 1999 + * December 27, 1999 * * 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.5j are Y2K compliant. It is my belief that earlier + * upward through 1.0.5k 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 @@ -98,7 +98,7 @@ * 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f * 1.0.5 1.0.5 10005 2.1.0.5 * 1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d - * 1.0.5e-j 1.0.5e-j 10100 2.1.0.5e-j + * 1.0.5e-k 1.0.5e-k 10100 2.1.0.5e-k * 1.1.0 1.1.0 10100 3.1.0.0 * * Henceforth the source version will match the shared-library minor @@ -123,7 +123,7 @@ * Copyright (c) 1996, 1997 Andreas Dilger * (libpng versions 0.90, December 1996, through 0.96, May 1997) * Copyright (c) 1998, 1999 Glenn Randers-Pehrson - * (libpng versions 0.97, January 1998, through 1.0.5j, December 21, 1999) + * (libpng versions 0.97, January 1998, through 1.0.5k, December 27, 1999) * * For the purposes of this copyright and license, "Contributing Authors" * is defined as the following set of individuals: @@ -224,7 +224,7 @@ extern "C" { */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.0.5j" +#define PNG_LIBPNG_VER_STRING "1.0.5k" /* Careful here. At one time, Guy wanted to use 082, but that would be octal. * We must not include leading zeros. @@ -416,11 +416,11 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; * that use the old direct-access method with png_info_struct. * * The following members may have allocated storage attached that should be - * cleaned up before the structure is discarded: palette, text, pcal_purpose, - * pcal_units, pcal_params, hist, iccp_name, iccp_profile, splt_palettes, and - * scal_unit. Of these, the text, pcal_*, hist, iccp_*, splt_*, and scal_unit - * members are automatically freed when the info structure is deallocated. - * The palette member is not. + * cleaned up before the structure is discarded: palette, trans, text, + * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, + * splt_palettes, and scal_unit. Of these, the text, pcal_*, hist, iccp_*, + * splt_*, and scal_unit members are automatically freed when the info + * structure is deallocated. The palette member is not. * * More allocation details: all the chunk-reading functions that change these * members go through the corresponding png_set_* functions. Functions to @@ -466,10 +466,8 @@ typedef struct png_info_struct #ifdef PNG_FLOATING_POINT_SUPPORTED float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */ #endif -#ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point int_gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */ #endif -#endif #if defined(PNG_sRGB_SUPPORTED) /* GR-P, 0.96a */ @@ -902,10 +900,8 @@ struct png_struct_def float gamma; /* file gamma value */ float screen_gamma; /* screen gamma value (display_exponent) */ #endif -#ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point int_gamma; #endif -#endif #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) png_bytep gamma_table; /* gamma table for 8-bit depth files */ @@ -1007,12 +1003,17 @@ struct png_struct_def defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) png_byte empty_plte_permitted; #endif + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + int num_chunk_list; + png_bytep chunk_list; +#endif }; /* This prevents a compiler error in png_get_copyright() in png.c if png.c -and png.h are both at * version 1.0.5j +and png.h are both at * version 1.0.5k */ -typedef png_structp version_1_0_5j; +typedef png_structp version_1_0_5k; typedef png_struct FAR * FAR * png_structpp; @@ -1698,22 +1699,18 @@ extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr, png_infop info_ptr, double *file_gamma)); #endif -#ifdef PNG_FIXED_POINT_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr, png_infop info_ptr, png_fixed_point *int_file_gamma)); #endif -#endif #if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr, png_infop info_ptr, double file_gamma)); #endif -#ifdef PNG_FIXED_POINT_SUPPORTED extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr, png_infop info_ptr, png_fixed_point int_file_gamma)); #endif -#endif #if defined(PNG_READ_hIST_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr, @@ -1804,13 +1801,13 @@ extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr, #if defined(PNG_READ_iCCP_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr, png_infop info_ptr, png_charpp name, int *compression_type, - png_charpp profile, png_int_32 *proflen)); + png_charpp profile, png_uint_32 *proflen)); #endif #if defined(PNG_iCCP_SUPPORTED) extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr, png_infop info_ptr, png_charp name, int compression_type, - png_charp profile, int proflen)); + png_charp profile, png_uint_32 proflen)); extern PNG_EXPORT(void,png_free_iCCP) PNGARG((png_structp png_ptr, png_infop info_ptr)); #endif @@ -1874,6 +1871,11 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, png_color_16p trans_values)); #endif +#if defined(PNG_tRNS_SUPPORTED) +extern PNG_EXPORT(void,png_free_tRNS) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + #if defined(PNG_READ_sCAL_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr, @@ -1903,14 +1905,24 @@ extern PNG_EXPORT(void,png_free_sCAL) PNGARG((png_structp png_ptr, #endif /* PNG_READ_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */ #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +/* provide a list of chunks and how they are to be handled, if the built-in + handling or default unknown chunk handling is not desired. Any chunks not + listed will be handled in the default manner. The IHDR and IEND chunks + must not be listed. + keep = 0: follow default behavour + = 1: do not keep + = 2: keep only if safe-to-copy + = 3: keep even if unsafe-to-copy +*/ extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp png_ptr, int keep, png_bytep chunk_list, int num_chunks)); extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr, png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)); extern PNG_EXPORT(void,png_free_unknown_chunks) PNGARG((png_structp png_ptr, png_infop info_ptr, int num)); -extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_unknown_chunkpp entries)); +extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp + png_ptr, png_infop info_ptr, png_unknown_chunkpp entries)); +extern PNG_EXPORT(void,png_free_chunk_list) PNGARG((png_structp png_ptr)); #endif /* Define PNG_DEBUG at compile time for debugging information. Higher @@ -1952,7 +1964,7 @@ extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr)); -#define PNG_HEADER_VERSION_STRING " libpng version 1.0.5j - December 21, 1999 (header)\n" +#define PNG_HEADER_VERSION_STRING " libpng version 1.0.5k - December 27, 1999 (header)\n" #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* With these routines we avoid an integer divide, which will be slower on @@ -2075,6 +2087,11 @@ extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr)); #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L +/* For use in png_set_keep_unknown, png_handle_as_unknown */ +#define HANDLE_CHUNK_AS_DEFAULT 0 +#define HANDLE_CHUNK_NEVER 1 +#define HANDLE_CHUNK_IF_SAFE 2 +#define HANDLE_CHUNK_ALWAYS 3 #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ PNG_FLAG_CRC_ANCILLARY_NOWARN) @@ -2160,18 +2177,18 @@ PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5]; * values, which is almost certainly true. */ #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED) -#if defined(PNG_READ_pCAL_SUPPORTED) -#define png_get_int_32(buf) ( *((png_int_32p) (buf))) -#endif /* PNG_READ_pCAL_SUPPORTED */ -#define png_get_uint_32(buf) ( *((png_uint_32p) (buf))) -#define png_get_uint_16(buf) ( *((png_uint_16p) (buf))) +# if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED) +# define png_get_int_32(buf) ( *((png_int_32p) (buf))) +# endif +# define png_get_uint_32(buf) ( *((png_uint_32p) (buf))) +# define png_get_uint_16(buf) ( *((png_uint_16p) (buf))) #else -#if defined(PNG_READ_pCAL_SUPPORTED) +# if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED) PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf)); -#endif /* PNG_READ_pCAL_SUPPORTED */ +# endif PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf)); PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf)); -#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */ +#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */ /* Initialize png_ptr struct for reading, and allocate any other memory. * (old interface - NOT DLL EXPORTED). @@ -2575,23 +2592,23 @@ PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); -#if defined(PNG_READ_gAMA_SUPPORTED) -PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_bKGD_SUPPORTED) +PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_sBIT_SUPPORTED) -PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_cHRM_SUPPORTED) +PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_cHRM_SUPPORTED) -PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_gAMA_SUPPORTED) +PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_sRGB_SUPPORTED) -PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_hIST_SUPPORTED) +PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif @@ -2600,33 +2617,28 @@ extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif /* PNG_READ_iCCP_SUPPORTED */ -#if defined(PNG_READ_sPLT_SUPPORTED) -extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_sPLT_SUPPORTED */ - -#if defined(PNG_READ_tRNS_SUPPORTED) -PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_iTXt_SUPPORTED) +PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_bKGD_SUPPORTED) -PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_oFFs_SUPPORTED) +PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_hIST_SUPPORTED) -PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_pCAL_SUPPORTED) +PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_oFFs_SUPPORTED) -PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_pHYs_SUPPORTED) +PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_pCAL_SUPPORTED) -PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_sBIT_SUPPORTED) +PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif @@ -2635,8 +2647,18 @@ PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_pHYs_SUPPORTED) -PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_sPLT_SUPPORTED) +extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#if defined(PNG_READ_sRGB_SUPPORTED) +PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_tEXt_SUPPORTED) +PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif @@ -2645,8 +2667,8 @@ PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_tEXt_SUPPORTED) -PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, +#if defined(PNG_READ_tRNS_SUPPORTED) +PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif @@ -2655,9 +2677,9 @@ PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif -#if defined(PNG_READ_iTXt_SUPPORTED) -PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +PNG_EXTERN int png_handle_as_unknown PNGARG((png_structp png_ptr, png_bytep + chunk_name)); #endif PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, diff --git a/pngasmrd.h b/pngasmrd.h index 02c328218..c9aa882bd 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.4e - October 10, 1999 + * libpng 1.0.5k - December 27, 1999 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1999 Glenn Randers-Pehrson * @@ -21,7 +21,7 @@ /* Set this in the makefile for gcc on Pentium, not in pngconf.h */ #ifdef PNG_USE_PNGGCCRD /* Platform must be Pentium. Makefile must assemble and load pnggccrd.c - * (not available in libpng 1.0.4e). + * (not available in libpng 1.0.5k). * MMX will be detected at run time and used if present. */ #define PNG_HAVE_ASSEMBLER_COMBINE_ROW @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -554,6 +554,9 @@ __dont__ include it again #ifndef PNG_NO_READ_UNKNOWN_CHUNKS # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED # define PNG_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_NO_HANDLE_AS_UNKNOWN +# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# endif #endif #ifndef PNG_NO_READ_OPT_PLTE # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */ @@ -678,6 +681,11 @@ __dont__ include it again # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED # define PNG_UNKNOWN_CHUNKS_SUPPORTED # endif +# ifndef PNG_NO_HANDLE_AS_UNKNOWN +# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# endif +# endif #endif #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \ defined(PNG_WRITE_zTXt_SUPPORTED) diff --git a/pngcrush.c b/pngcrush.c index 19a14cb28..5d1cc7c00 100644 --- a/pngcrush.c +++ b/pngcrush.c @@ -9,13 +9,13 @@ * Optionally, it can remove unwanted chunks or add gAMA, sRGB, bKGD, * tEXt/zTXt, and tRNS chunks. * - * Uses libpng-1.0.5i. This program was based upon libpng's pngtest.c. + * Uses libpng and zlib. This program was based upon libpng's pngtest.c. * * Thanks to Greg Roelofs for various bug fixes, suggestions, and * occasionally creating Linux executables. */ -#define PNGCRUSH_VERSION "1.2.2" +#define PNGCRUSH_VERSION "1.3.1" /* * COPYRIGHT NOTICE, DISCLAIMER, AND LICENSE: @@ -44,21 +44,26 @@ /* To do: * - * Version 1.2.*: check for unused alpha channel and ok-to-reduce-depth. + * Version 1.3.*: check for unused alpha channel and ok-to-reduce-depth. * Rearrange palette to put most-used color first and * transparent color second. Finish pplt (partial palette) feature. * - * Version 1.2.*: Use an alternate write function for the trial passes, that + * Version 1.3.*: Use an alternate write function for the trial passes, that * simply counts bytes rather than actually writing to a file, to save wear * and tear on disk drives. * - * Version 1.2.*: Drop explicit support for pCAL, hIST, sCAL, sPLT, iCCP, - * tIME, and cHRM chunks and handle them as unknown but safe-to-copy, once - * libpng is able to override the unsafe-to-copy status of unknown chunks. - * * Change log: * - * Version 1.2.2: Added support for handling unknown chunks. + * Version 1.3.1 (built with libpng-1.0.5k): Eliminated some spurious warnings + * that were being issued by libpng-1.0.5j. Added -itxt, -ztxt, and + * -zitxt descriptions to the help screen. + * + * Dropped explicit support for pCAL, hIST, sCAL, sPLT, iCCP, tIME, and + * cHRM chunks and handle them as unknown but safe-to-copy instead, using + * new png_handle_as_unknown function available in libpng-1.0.5k. + * + * Version 1.3.0 (built with libpng-1.0.5j): Added support for handling + * unknown chunks. * * pngcrush is now fixed-point only, unless PNG_NO_FLOATING_POINT_SUPPORTED * is undefined in pngcrush.h. @@ -82,11 +87,12 @@ * The "-m method" can be used any of the 124 methods, without having to * specify the filter, level, and strategy, instead of just the first 10. * - * Version 1.2.1: Fixed -srgb parameter so it really does take an argument, - * and so it continues to use "0" if an integer does not follow the -srgb. + * Version 1.2.1 (built with libpng-1.0.5f): Fixed -srgb parameter so it + * really does take an argument, and so it continues to use "0" if an + * integer does not follow the -srgb. + * * Added "-plte_len n" argument for truncating the PLTE. Be sure not to * truncate it to less than the greatest index actually appearing in IDAT. - * Built with libpng-1.0.5f. * * Version 1.2.0: Removed registration requirement. Added open source * license. Redefined TOO_FAR=32k in deflate.c. @@ -158,6 +164,7 @@ static PNG_CONST char *outname = "pngout.png"; static PNG_CONST char *dirname = "pngcrush.bak"; static PNG_CONST char *extension = "_C.png"; +static int all_chunks_are_safe=0; static int number_of_open_files; static int do_pplt = 0; char pplt_string[1024]; @@ -788,6 +795,8 @@ main(int argc, char *argv[]) names++; i++; } + else if( !strncmp(argv[i],"-save",5)) + all_chunks_are_safe++; else if( !strncmp(argv[i],"-srgb",5) || !strncmp(argv[i],"-sRGB",5)) { @@ -808,9 +817,7 @@ main(int argc, char *argv[]) i--; } else if(!strncmp(argv[i],"-s",2)) - { verbose=0; - } else if( !strncmp(argv[i],"-text",5) || !strncmp(argv[i],"-tEXt",5) || !strncmp(argv[i],"-ztxt",5) || !strncmp(argv[i],"-zTXt",5) || !strncmp(argv[i],"-zitxt",6) || !strncmp(argv[i],"-ziTXt",6) || @@ -942,15 +949,13 @@ main(int argc, char *argv[]) } } + if(verbose > 0) { fprintf(STDERR, "\n | %s %s, Copyright (C) 1998, 1999, Glenn Randers-Pehrson\n", progname, PNGCRUSH_VERSION); fprintf(STDERR, " | This is a free, open-source program. Permission is\n"); fprintf(STDERR, " | granted to everyone to use pngcrush without fee.\n"); - } - if(verbose > 0) - { fprintf(STDERR, " | This program was built with libpng version %s,\n", PNG_LIBPNG_VER_STRING); @@ -1124,6 +1129,11 @@ main(int argc, char *argv[]) " gAMA chunk, use the '-replace_gamma' option.\n\n"); png_crush_pause(); fprintf(STDERR, + " -itxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n"); + if(verbose > 1) + fprintf(STDERR, + "\n Compressed iTXt chunk to insert (see -text).\n\n"); + fprintf(STDERR, " -l zlib_compression_level [0-9]\n"); if(verbose > 1) { @@ -1229,15 +1239,15 @@ main(int argc, char *argv[]) } /* fprintf(STDERR, - " -save chunkname\n"); + " -save (keep all copy-unsafe chunks)\n"); if(verbose > 1) { fprintf(STDERR, - "\n Name of an otherwise unknown ancillary chunk that\n"); + "\n Save otherwise unknown ancillary chunks that\n"); fprintf(STDERR, " would be considered copy-unsafe. This option makes\n"); fprintf(STDERR, - " the chunk 'known' to %s, so it can be copied.\n\n", + " all chunks 'known' to %s, so they can be copied.\n\n", progname); } */ @@ -1257,7 +1267,7 @@ main(int argc, char *argv[]) fprintf(STDERR, "\n text < 2048 chars. For now, you can only add ten\n"); fprintf(STDERR, - " tEXt or zTXt chunks per pngcrush run.\n\n"); + " tEXt, iTXt, or zTXt chunks per pngcrush run.\n\n"); } fprintf(STDERR, " -trns index red green blue gray\n"); @@ -1299,17 +1309,16 @@ main(int argc, char *argv[]) fprintf(STDERR, " '-m method' argument.\n\n"); } -#if 0 fprintf(STDERR, - " -ztxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n"); + " -zitxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n"); if(verbose > 1) fprintf(STDERR, - "\n zTXt chunk to insert. keyword < 80 chars,\n"); + "\n Compressed iTXt chunk to insert (see -text).\n\n"); fprintf(STDERR, - "\n text < 2048 chars. For now, you can only add ten\n"); + " -ztxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n"); + if(verbose > 1) fprintf(STDERR, - " tEXt or zTXt chunks per pngcrush run.\n\n"); -#endif + "\n zTXt chunk to insert (see -text).\n\n"); png_crush_pause(); } fprintf(STDERR, @@ -1694,11 +1703,70 @@ main(int argc, char *argv[]) } #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) - png_set_keep_unknown_chunks(read_ptr, 2, (png_bytep)NULL, 0); + png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)NULL, 0); #endif #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) if(nosave == 0) - png_set_keep_unknown_chunks(write_ptr, 1, (png_bytep)NULL, 0); + if(all_chunks_are_safe != 0) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)NULL, 0); + else + { +#ifdef PNG_USE_LOCAL_ARRAYS +#if !defined(PNG_cHRM_SUPPORTED) + PNG_cHRM; +#endif +#if !defined(PNG_hIST_SUPPORTED) + PNG_hIST; +#endif +#if !defined(PNG_iCCP_SUPPORTED) + PNG_iCCP; +#endif +#if !defined(PNG_pCAL_SUPPORTED) + PNG_pCAL; +#endif +#if !defined(PNG_sCAL_SUPPORTED) + PNG_sCAL; +#endif +#if !defined(PNG_sPLT_SUPPORTED) + PNG_sPLT; +#endif +#if !defined(PNG_tIME_SUPPORTED) + PNG_tIME; +#endif +#endif + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, + (png_bytep)NULL, 0); +#if !defined(PNG_cHRM_SUPPORTED) + 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); +#endif +#if !defined(PNG_iCCP_SUPPORTED) + 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); +#endif +#if !defined(PNG_pCAL_SUPPORTED) + 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); +#endif +#if !defined(PNG_tIME_SUPPORTED) + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + (png_bytep)png_tIME, 1); +#endif + } #endif png_debug(0, "Reading info struct\n"); @@ -1741,7 +1809,8 @@ main(int argc, char *argv[]) if((color_type == 2 || color_type == 6 || color_type == 3) && (output_color_type == 0 || output_color_type == 4)) { -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) && \ + defined(PNG_FLOATING_POINT_SUPPORTED) png_set_rgb_to_gray(read_ptr, 1, 54./255., 183./255.); if(output_bit_depth < 8)output_bit_depth=8; if(color_type == 3) need_expand = 1; @@ -1848,7 +1917,6 @@ main(int argc, char *argv[]) output_bit_depth, output_color_type, interlace_type, compression_type, filter_type); - if(output_color_type != input_color_type) things_have_changed++; } } @@ -1913,8 +1981,9 @@ main(int argc, char *argv[]) if(keep_chunk("gAMA",argv)) { if(verbose > 1 && trial == 1) - fprintf(STDERR, " gamma=(%lu/100000)\n", file_gamma); - if(double_gamma)file_gamma+=file_gamma; + fprintf(STDERR, " gamma=(%d/100000)\n", (int)file_gamma); + if(double_gamma) + file_gamma+=file_gamma; png_set_gAMA_fixed(write_ptr, write_info_ptr, file_gamma); } } @@ -1928,8 +1997,7 @@ main(int argc, char *argv[]) " Inserting gAMA chunk with gamma=(%d/100000)\n", specified_gamma); } - png_set_gAMA_fixed(write_ptr, write_info_ptr, - (png_fixed_point)specified_gamma); + png_set_gAMA_fixed(write_ptr, write_info_ptr, specified_gamma); file_gamma=(png_fixed_point)specified_gamma; } } @@ -1971,22 +2039,11 @@ main(int argc, char *argv[]) } } #endif -#if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED) - { - png_uint_16p hist; - - if (png_get_hIST(read_ptr, read_info_ptr, &hist)) - { - if(keep_chunk("hIST",argv)) - png_set_hIST(write_ptr, write_info_ptr, hist); - } - } -#endif -#if defined(PNG_iCCP_SUPPORTED) +#if defined(PNG_READ_iCCP_SUPPORTED) && defined(PNG_WRITE_iCCP_SUPPORTED) { png_charp name; png_charp profile; - png_int_32 proflen; + png_uint_32 proflen; int compression_type; if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, @@ -2060,6 +2117,46 @@ main(int argc, char *argv[]) } #endif + if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) + { + if (plte_len > 0) + num_palette=plte_len; + if (do_pplt != 0) + { + printf("PPLT: %s\n",pplt_string); + } + if(output_color_type == 3) + png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); + else if(keep_chunk("PLTE",argv)) + png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); + if(verbose > 1 && trial == 1) + { + int i; + png_colorp p = palette; + fprintf(STDERR, " Palette:\n"); + fprintf(STDERR, " I R G B ( color ) A\n"); + for (i=0; i<num_palette; i++) + { + fprintf(STDERR, " %4d %4d %4d %4d (#%2.2x%2.2x%2.2x) %4d\n", + i, p->red, p->green, p->blue, + p->red, p->green, p->blue, + trns_array[i]); + p++; + } + } + } + +#if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED) + { + png_uint_16p hist; + + if (png_get_hIST(read_ptr, read_info_ptr, &hist)) + { + if(keep_chunk("hIST",argv)) + png_set_hIST(write_ptr, write_info_ptr, hist); + } + } +#endif #if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED) { png_bytep trans; @@ -2157,36 +2254,6 @@ main(int argc, char *argv[]) } #endif - - if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) - { - if (plte_len > 0) - num_palette=plte_len; - if (do_pplt != 0) - { - printf("PPLT: %s\n",pplt_string); - } - if(output_color_type == 3) - png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); - else if(keep_chunk("PLTE",argv)) - png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); - if(verbose > 1 && trial == 1) - { - int i; - png_colorp p = palette; - fprintf(STDERR, " Palette:\n"); - fprintf(STDERR, " I R G B ( color ) A\n"); - for (i=0; i<num_palette; i++) - { - fprintf(STDERR, " %4d %4d %4d %4d (#%2.2x%2.2x%2.2x) %4d\n", - i, p->red, p->green, p->blue, - p->red, p->green, p->blue, - trns_array[i]); - p++; - } - } - } - #if defined(PNG_READ_sBIT_SUPPORTED) && defined(PNG_WRITE_sBIT_SUPPORTED) { png_color_8p sig_bit; @@ -2211,6 +2278,18 @@ main(int argc, char *argv[]) } #endif #if defined(PNG_sCAL_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED + { + int unit; + double width, height; + + if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &width, &height)) + { + png_set_sCAL(write_ptr, write_info_ptr, unit, width, height); + } + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED { int unit; png_charp width, height; @@ -2222,6 +2301,8 @@ main(int argc, char *argv[]) } } #endif +#endif +#endif #if defined(PNG_sPLT_SUPPORTED) { png_spalette_p entries; @@ -2458,7 +2539,8 @@ main(int argc, char *argv[]) } -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) && \ + defined(PNG_FLOATING_POINT_SUPPORTED) if((color_type == 2 || color_type == 6 || color_type == 3) && (output_color_type == 0 || output_color_type == 4)) { @@ -2562,6 +2644,7 @@ main(int argc, char *argv[]) if (num_unknowns && nosave == 0) { png_size_t i; + printf("setting %d unknown chunks after IDAT\n",num_unknowns); png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, num_unknowns); for (i = 0; i < read_info_ptr->unknown_chunks_num; i++) diff --git a/pngcrush.h b/pngcrush.h index 5e48ecfbe..c32f53316 100644 --- a/pngcrush.h +++ b/pngcrush.h @@ -3,8 +3,23 @@ /* Special defines for pngcrush, mostly just to reduce the size of the static executable. */ -#define PNG_NO_FLOATING_POINT_SUPPORTED /* undef this if you want to be able +#define PNG_NO_FLOAING_POINT_SUPPORTED /* undef this if you want to be able to reduce color to gray */ +#define PNG_NO_READ_cHRM +#define PNG_NO_WRITE_cHRM +#define PNG_NO_READ_hIST +#define PNG_NO_WRITE_hIST +#define PNG_NO_READ_iCCP +#define PNG_NO_WRITE_iCCP +#define PNG_NO_READ_pCAL +#define PNG_NO_WRITE_pCAL +#define PNG_NO_READ_sCAL +#define PNG_NO_WRITE_sCAL +#define PNG_NO_READ_sPLT +#define PNG_NO_WRITE_sPLT +#define PNG_NO_READ_tIME +#define PNG_NO_WRITE_tIME + #define PNG_NO_EASY_ACCESS #define PNG_NO_READ_EMPTY_PLTE #define PNG_NO_WRITE_TRANSFORMS @@ -27,4 +42,3 @@ #define PNG_NO_GLOBAL_ARRAYS */ #define TOO_FAR 32767 /* Improves zlib/deflate compression */ - diff --git a/pngerror.c b/pngerror.c index 6ebc5aa72..1449a9dbd 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -72,7 +72,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message if (isnonalpha(c)) { buffer[iout++] = '['; buffer[iout++] = png_digit[(c & 0xf0) >> 4]; - buffer[iout++] = png_digit[c & 0xf]; + buffer[iout++] = png_digit[c & 0x0f]; buffer[iout++] = ']'; } else { buffer[iout++] = (png_byte)c; @@ -1,7 +1,7 @@ /* pngget.c - retrieval of values from info struct * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -277,7 +277,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, { png_uint_32 retval = 0; - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs) + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) { png_debug1(1, "in %s retrieval function\n", "pHYs"); if (res_x != NULL) @@ -423,7 +423,6 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) return (0); } #endif -#ifdef PNG_FIXED_POINT_SUPPORTED png_uint_32 png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point *int_file_gamma) @@ -438,7 +437,6 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, return (0); } #endif -#endif #if defined(PNG_READ_sRGB_SUPPORTED) png_uint_32 @@ -459,7 +457,7 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) png_uint_32 png_get_iCCP(png_structp png_ptr, png_infop info_ptr, png_charpp name, int *compression_type, - png_charpp profile, png_int_32 *proflen) + png_charpp profile, png_uint_32 *proflen) { if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) && name != NULL && profile != NULL && proflen != NULL) @@ -573,8 +571,8 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *units, png_charpp *params) { - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL && - purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) + && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && nparams != NULL && units != NULL && params != NULL) { png_debug1(1, "in %s retrieval function\n", "pCAL"); @@ -597,7 +595,8 @@ png_uint_32 png_get_sCAL(png_structp png_ptr, png_infop info_ptr, int *unit, double *width, double *height) { - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sCAL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) { *unit = info_ptr->scal_unit; *width = info_ptr->scal_pixel_width; @@ -612,7 +611,8 @@ png_uint_32 png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, int *unit, png_charpp width, png_charpp height) { - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sCAL) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) { *unit = info_ptr->scal_unit; *width = info_ptr->scal_s_width; @@ -632,7 +632,8 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr, { png_uint_32 retval = 0; - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs) + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs)) { png_debug1(1, "in %s retrieval function\n", "pHYs"); if (res_x != NULL) @@ -659,8 +660,8 @@ png_uint_32 png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette) { - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE && - palette != NULL) + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) + && palette != NULL) { png_debug1(1, "in %s retrieval function\n", "PLTE"); *palette = info_ptr->palette; @@ -675,8 +676,8 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, png_uint_32 png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) { - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT && - sig_bit != NULL) + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) + && sig_bit != NULL) { png_debug1(1, "in %s retrieval function\n", "sBIT"); *sig_bit = &(info_ptr->sig_bit); @@ -710,8 +711,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, png_uint_32 png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) { - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME && - mod_time != NULL) + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) + && mod_time != NULL) { png_debug1(1, "in %s retrieval function\n", "tIME"); *mod_time = &(info_ptr->mod_time); @@ -727,7 +728,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values) { png_uint_32 retval = 0; - if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS) + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) { png_debug1(1, "in %s retrieval function\n", "tRNS"); if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 diff --git a/pngpread.c b/pngpread.c index cd1c82c3f..070ab76a8 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,7 +1,7 @@ /* pngpread.c - read a png file in push mode * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -253,10 +253,29 @@ png_read_info(png_structp png_ptr, png_infop info_ptr) */ if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) png_handle_IHDR(png_ptr, info_ptr, length); - else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) - png_handle_PLTE(png_ptr, info_ptr, length); else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) png_handle_IEND(png_ptr, info_ptr, length); +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) + { + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + png_ptr->mode |= PNG_HAVE_IDAT; + png_handle_unknown(png_ptr, info_ptr, length); + if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + break; + } + } +#endif + else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_handle_PLTE(png_ptr, info_ptr, length); else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) { if (!(png_ptr->mode & PNG_HAVE_IHDR)) @@ -421,7 +440,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) switch (png_ptr->pass) { case 0: - if (png_ptr->row_number & 7) + if (png_ptr->row_number & 0x07) { if (dsp_row != NULL) png_combine_row(png_ptr, dsp_row, @@ -431,7 +450,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) } break; case 1: - if ((png_ptr->row_number & 7) || png_ptr->width < 5) + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) { if (dsp_row != NULL) png_combine_row(png_ptr, dsp_row, @@ -441,7 +460,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) } break; case 2: - if ((png_ptr->row_number & 7) != 4) + if ((png_ptr->row_number & 0x07) != 4) { if (dsp_row != NULL && (png_ptr->row_number & 4)) png_combine_row(png_ptr, dsp_row, @@ -546,6 +565,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) png_ptr->row_info.rowbytes = ((png_ptr->row_info.width * (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3); + if(png_ptr->row_buf[0]) png_read_filter_row(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr->prev_row + 1, (int)(png_ptr->row_buf[0])); @@ -607,7 +627,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.5j. + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5k. */ void @@ -656,7 +676,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.5j. + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5k. */ void png_read_image(png_structp png_ptr, png_bytepp image) @@ -776,6 +796,21 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) png_handle_IHDR(png_ptr, info_ptr, length); + else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + png_handle_IEND(png_ptr, info_ptr, length); +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) + { + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT) + png_error(png_ptr, "Too many IDAT's found"); + else + png_ptr->mode |= PNG_AFTER_IDAT; + png_handle_unknown(png_ptr, info_ptr, length); + if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + } +#endif else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) { /* Zero length IDATs are legal after the last IDAT has been @@ -788,8 +823,6 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) } else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) png_handle_PLTE(png_ptr, info_ptr, length); - else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) - png_handle_IEND(png_ptr, info_ptr, length); #if defined(PNG_READ_bKGD_SUPPORTED) else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) png_handle_bKGD(png_ptr, info_ptr, length); @@ -1,7 +1,7 @@ /* pngrio.c - functions for data input * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 diff --git a/pngrtran.c b/pngrtran.c index 33367c3a4..ec9a311e6 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.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -367,7 +367,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette, { int j, next_j; - if (num_new_palette & 1) + if (num_new_palette & 0x01) { j = p->left; next_j = p->right; @@ -897,8 +897,8 @@ png_init_read_transformations(png_structp png_ptr) #endif #if defined(PNG_READ_BACKGROUND_SUPPORTED) /* No GAMMA transformation */ - if (png_ptr->transformations & PNG_BACKGROUND && - color_type == PNG_COLOR_TYPE_PALETTE) + if ((png_ptr->transformations & PNG_BACKGROUND) && + (color_type == PNG_COLOR_TYPE_PALETTE)) { int i; int istop = (int)png_ptr->num_trans; @@ -931,7 +931,7 @@ png_init_read_transformations(png_structp png_ptr) #if defined(PNG_READ_SHIFT_SUPPORTED) if ((png_ptr->transformations & PNG_SHIFT) && - color_type == PNG_COLOR_TYPE_PALETTE) + (color_type == PNG_COLOR_TYPE_PALETTE)) { png_uint_16 i; png_uint_16 istop = png_ptr->num_palette; @@ -1009,7 +1009,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) #endif #if defined(PNG_READ_16_TO_8_SUPPORTED) - if ((png_ptr->transformations & PNG_16_TO_8) && info_ptr->bit_depth == 16) + if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16)) info_ptr->bit_depth = 8; #endif @@ -1026,7 +1026,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) #endif #if defined(PNG_READ_PACK_SUPPORTED) - if ((png_ptr->transformations & PNG_PACK) && info_ptr->bit_depth < 8) + if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) info_ptr->bit_depth = 8; #endif @@ -1057,9 +1057,9 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) #if defined(PNG_READ_FILLER_SUPPORTED) /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ - if (png_ptr->transformations & PNG_FILLER && - (info_ptr->color_type == PNG_COLOR_TYPE_RGB || - info_ptr->color_type == PNG_COLOR_TYPE_GRAY)) + if ((png_ptr->transformations & PNG_FILLER) && + ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) info_ptr->channels++; #endif @@ -1177,7 +1177,7 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998: #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) /* if gray -> RGB, do so now only if background is non-gray; else do later * for performance reasons */ - if (png_ptr->transformations & PNG_GRAY_TO_RGB && + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); #endif @@ -1251,8 +1251,8 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998: #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) /* if gray -> RGB, do so now only if we did not do so above */ - if (png_ptr->transformations & PNG_GRAY_TO_RGB && - png_ptr->mode & PNG_BACKGROUND_IS_GRAY) + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); #endif @@ -1330,10 +1330,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row) { png_bytep sp = row + (png_size_t)((row_width - 1) >> 3); png_bytep dp = row + (png_size_t)row_width - 1; - png_uint_32 shift = 7 - (int)((row_width + 7) & 7); + png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07); for (i = 0; i < row_width; i++) { - *dp = (png_byte)((*sp >> shift) & 0x1); + *dp = (png_byte)((*sp >> shift) & 0x01); if (shift == 7) { shift = 0; @@ -1351,10 +1351,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row) png_bytep sp = row + (png_size_t)((row_width - 1) >> 2); png_bytep dp = row + (png_size_t)row_width - 1; - png_uint_32 shift = (int)((3 - ((row_width + 3) & 3)) << 1); + png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); for (i = 0; i < row_width; i++) { - *dp = (png_byte)((*sp >> shift) & 0x3); + *dp = (png_byte)((*sp >> shift) & 0x03); if (shift == 6) { shift = 0; @@ -1371,10 +1371,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row) { png_bytep sp = row + (png_size_t)((row_width - 1) >> 1); png_bytep dp = row + (png_size_t)row_width - 1; - png_uint_32 shift = (int)((1 - ((row_width + 1) & 1)) << 2); + png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); for (i = 0; i < row_width; i++) { - *dp = (png_byte)((*sp >> shift) & 0xf); + *dp = (png_byte)((*sp >> shift) & 0x0f); if (shift == 4) { shift = 0; @@ -2518,7 +2518,7 @@ png_do_background(png_row_infop row_info, png_bytep row, shift = 7; for (i = 0; i < row_width; i++) { - if ((png_uint_16)((*sp >> shift) & 0x1) + if ((png_uint_16)((*sp >> shift) & 0x01) == trans_values->gray) { *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); @@ -2543,7 +2543,7 @@ png_do_background(png_row_infop row_info, png_bytep row, shift = 6; for (i = 0; i < row_width; i++) { - if ((png_uint_16)((*sp >> shift) & 0x3) + if ((png_uint_16)((*sp >> shift) & 0x03) == trans_values->gray) { *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); @@ -2551,9 +2551,9 @@ png_do_background(png_row_infop row_info, png_bytep row, } else { - png_byte p = (png_byte)((*sp >> shift) & 0x3); + png_byte p = (png_byte)((*sp >> shift) & 0x03); png_byte g = (png_byte)((gamma_table [p | (p << 2) | - (p << 4) | (p << 6)] >> 6) & 0x3); + (p << 4) | (p << 6)] >> 6) & 0x03); *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); *sp |= (png_byte)(g << shift); } @@ -2573,7 +2573,7 @@ png_do_background(png_row_infop row_info, png_bytep row, shift = 6; for (i = 0; i < row_width; i++) { - if ((png_uint_16)((*sp >> shift) & 0x3) + if ((png_uint_16)((*sp >> shift) & 0x03) == trans_values->gray) { *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); @@ -2599,7 +2599,7 @@ png_do_background(png_row_infop row_info, png_bytep row, shift = 4; for (i = 0; i < row_width; i++) { - if ((png_uint_16)((*sp >> shift) & 0xf) + if ((png_uint_16)((*sp >> shift) & 0x0f) == trans_values->gray) { *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); @@ -2607,9 +2607,9 @@ png_do_background(png_row_infop row_info, png_bytep row, } else { - png_byte p = (png_byte)((*sp >> shift) & 0xf); + png_byte p = (png_byte)((*sp >> shift) & 0x0f); png_byte g = (png_byte)((gamma_table[p | - (p << 4)] >> 4) & 0xf); + (p << 4)] >> 4) & 0x0f); *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); *sp |= (png_byte)(g << shift); } @@ -2629,7 +2629,7 @@ png_do_background(png_row_infop row_info, png_bytep row, shift = 4; for (i = 0; i < row_width; i++) { - if ((png_uint_16)((*sp >> shift) & 0xf) + if ((png_uint_16)((*sp >> shift) & 0x0f) == trans_values->gray) { *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); @@ -3362,10 +3362,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, { sp = row + (png_size_t)((row_width - 1) >> 3); dp = row + (png_size_t)row_width - 1; - shift = 7 - (int)((row_width + 7) & 7); + shift = 7 - (int)((row_width + 7) & 0x07); for (i = 0; i < row_width; i++) { - if ((*sp >> shift) & 0x1) + if ((*sp >> shift) & 0x01) *dp = 1; else *dp = 0; @@ -3385,10 +3385,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, { sp = row + (png_size_t)((row_width - 1) >> 2); dp = row + (png_size_t)row_width - 1; - shift = (int)((3 - ((row_width + 3) & 3)) << 1); + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); for (i = 0; i < row_width; i++) { - value = (*sp >> shift) & 0x3; + value = (*sp >> shift) & 0x03; *dp = (png_byte)value; if (shift == 6) { @@ -3406,10 +3406,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, { sp = row + (png_size_t)((row_width - 1) >> 1); dp = row + (png_size_t)row_width - 1; - shift = (int)((row_width & 1) << 2); + shift = (int)((row_width & 0x01) << 2); for (i = 0; i < row_width; i++) { - value = (*sp >> shift) & 0xf; + value = (*sp >> shift) & 0x0f; *dp = (png_byte)value; if (shift == 4) { @@ -3508,10 +3508,10 @@ png_do_expand(png_row_infop row_info, png_bytep row, gray = (png_uint_16)(gray*0xff); sp = row + (png_size_t)((row_width - 1) >> 3); dp = row + (png_size_t)row_width - 1; - shift = 7 - (int)((row_width + 7) & 7); + shift = 7 - (int)((row_width + 7) & 0x07); for (i = 0; i < row_width; i++) { - if ((*sp >> shift) & 0x1) + if ((*sp >> shift) & 0x01) *dp = 0xff; else *dp = 0; @@ -3532,10 +3532,10 @@ png_do_expand(png_row_infop row_info, png_bytep row, gray = (png_uint_16)(gray*0x55); sp = row + (png_size_t)((row_width - 1) >> 2); dp = row + (png_size_t)row_width - 1; - shift = (int)((3 - ((row_width + 3) & 3)) << 1); + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); for (i = 0; i < row_width; i++) { - value = (*sp >> shift) & 0x3; + value = (*sp >> shift) & 0x03; *dp = (png_byte)(value | (value << 2) | (value << 4) | (value << 6)); if (shift == 6) @@ -3555,10 +3555,10 @@ png_do_expand(png_row_infop row_info, png_bytep row, gray = (png_uint_16)(gray*0x11); sp = row + (png_size_t)((row_width - 1) >> 1); dp = row + (png_size_t)row_width - 1; - shift = (int)((1 - ((row_width + 1) & 1)) << 2); + shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); for (i = 0; i < row_width; i++) { - value = (*sp >> shift) & 0xf; + value = (*sp >> shift) & 0x0f; *dp = (png_byte)(value | (value << 4)); if (shift == 4) { @@ -3809,7 +3809,7 @@ png_build_gamma_table(png_structp png_ptr) #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY)) + if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY)) { g = 1.0 / (png_ptr->gamma); diff --git a/pngrutil.c b/pngrutil.c index 94db0afe9..8b6afe8bd 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -31,7 +31,7 @@ png_get_uint_32(png_bytep buf) return (i); } -#if defined(PNG_READ_pCAL_SUPPORTED) +#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED) /* Grab a signed 32-bit integer from a buffer in big-endian format. The * data is stored in the PNG file in two's complement format, and it is * assumed that the machine format for signed integers is the same. */ @@ -87,10 +87,10 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip) if (png_crc_error(png_ptr)) { - if ((png_ptr->chunk_name[0] & 0x20 && /* Ancillary */ + if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */ !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) || (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */ - png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)) + (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))) { png_chunk_warning(png_ptr, "CRC error"); } @@ -455,7 +455,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #if defined (PNG_READ_tRNS_SUPPORTED) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { - if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS) + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) { if (png_ptr->num_trans > png_ptr->num_palette) { @@ -482,7 +482,7 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; } - png_ptr->mode |= PNG_AFTER_IDAT | PNG_HAVE_IEND; + png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); if (length != 0) { @@ -515,7 +515,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Out of place gAMA chunk"); - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) #if defined(PNG_READ_sRGB_SUPPORTED) && !(info_ptr->valid & PNG_INFO_sRGB) #endif @@ -549,7 +549,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_warning(png_ptr, "Ignoring incorrect gAMA value when sRGB is also present"); #ifndef PNG_NO_CONSOLE_IO - fprintf(stderr, "igamma = %lu\n", igamma); + fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma); #endif return; } @@ -557,10 +557,10 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_FLOATING_POINT_SUPPORTED file_gamma = (float)igamma / (float)100000.0; -#ifdef PNG_READ_GAMMA_SUPPORTED - png_ptr->gamma = file_gamma; -#endif - png_set_gAMA(png_ptr, info_ptr, file_gamma); +# ifdef PNG_READ_GAMMA_SUPPORTED + png_ptr->gamma = file_gamma; +# endif + png_set_gAMA(png_ptr, info_ptr, file_gamma); #endif #ifdef PNG_FIXED_POINT_SUPPORTED png_set_gAMA_fixed(png_ptr, info_ptr, igamma); @@ -592,7 +592,7 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Out of place sBIT chunk"); } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)) { png_warning(png_ptr, "Duplicate sBIT chunk"); png_crc_finish(png_ptr, length); @@ -659,7 +659,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Missing PLTE before cHRM"); - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) #if defined(PNG_READ_sRGB_SUPPORTED) && !(info_ptr->valid & PNG_INFO_sRGB) #endif @@ -796,9 +796,6 @@ void png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { int intent; -#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) - int igamma; -#endif png_byte buf[1]; png_debug(1, "in png_handle_sRGB\n"); @@ -815,7 +812,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Out of place sRGB chunk"); - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) { png_warning(png_ptr, "Duplicate sRGB chunk"); png_crc_finish(png_ptr, length); @@ -842,26 +839,31 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED - igamma=png_ptr->gamma * 100000.; + if ((info_ptr->valid & PNG_INFO_gAMA)) + { + int igamma; +#ifdef PNG_FIXED_POINT_SUPPORTED + igamma=(int)info_ptr->int_gamma; #else -# ifdef PNG_FIXED_POINT_SUPPORTED - igamma=(int)png_ptr->int_gamma; +# ifdef PNG_FLOATING_POINT_SUPPORTED + igamma=info_ptr->gamma * 100000.; # endif #endif - if ((info_ptr->valid & PNG_INFO_gAMA)) if(igamma < 45000L || igamma > 46000L) { png_warning(png_ptr, "Ignoring incorrect gAMA value when sRGB is also present"); #ifndef PNG_NO_CONSOLE_IO -#ifdef PNG_FLOATING_POINT_SUPPORTED - fprintf(stderr,"gamma=%f\n",png_ptr->gamma); -#else - fprintf(stderr,"gamma=(%lu/100000)\n",png_ptr->int_gamma); -#endif +# ifdef PNG_FIXED_POINT_SUPPORTED + fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma); +# else +# ifdef PNG_FLOATING_POINT_SUPPORTED + fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma); +# endif +# endif #endif } + } #endif /* PNG_READ_gAMA_SUPPORTED */ #ifdef PNG_READ_cHRM_SUPPORTED @@ -909,7 +911,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Out of place iCCP chunk"); - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_iCCP) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)) { png_warning(png_ptr, "Duplicate iCCP chunk"); png_crc_finish(png_ptr, length); @@ -984,16 +986,6 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place sPLT chunk"); - - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sPLT) - { - png_warning(png_ptr, "Duplicate sPLT chunk"); - png_crc_finish(png_ptr, length); - return; - } #ifdef PNG_MAX_MALLOC_64K if (length > (png_uint_32)65535L) @@ -1087,7 +1079,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) { png_warning(png_ptr, "Duplicate tRNS chunk"); png_crc_finish(png_ptr, length); @@ -1190,7 +1182,7 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_bKGD) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)) { png_warning(png_ptr, "Duplicate bKGD chunk"); png_crc_finish(png_ptr, length); @@ -1278,7 +1270,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_hIST) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)) { png_warning(png_ptr, "Duplicate hIST chunk"); png_crc_finish(png_ptr, length); @@ -1329,7 +1321,7 @@ png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) { png_warning(png_ptr, "Duplicate pHYS chunk"); png_crc_finish(png_ptr, length); @@ -1372,7 +1364,7 @@ png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) { png_warning(png_ptr, "Duplicate oFFs chunk"); png_crc_finish(png_ptr, length); @@ -1420,7 +1412,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)) { png_warning(png_ptr, "Duplicate pCAL chunk"); png_crc_finish(png_ptr, length); @@ -1540,7 +1532,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sCAL) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) { png_warning(png_ptr, "Duplicate sCAL chunk"); png_crc_finish(png_ptr, length); @@ -1597,7 +1589,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_warning(png_ptr, "Invalid sCAL data"); png_free(png_ptr, buffer); -#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED) +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) png_free(png_ptr, swidth); png_free(png_ptr, sheight); #endif @@ -1614,7 +1606,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #endif png_free(png_ptr, buffer); -#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED) +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) png_free(png_ptr, swidth); png_free(png_ptr, sheight); #endif @@ -1632,7 +1624,7 @@ png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (!(png_ptr->mode & PNG_HAVE_IHDR)) png_error(png_ptr, "Out of place tIME chunk"); - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME) + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)) { png_warning(png_ptr, "Duplicate tIME chunk"); png_crc_finish(png_ptr, length); @@ -1905,17 +1897,26 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_debug(1, "in png_handle_unknown\n"); if (png_ptr->mode & PNG_HAVE_IDAT) - png_ptr->mode |= PNG_AFTER_IDAT; + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; +#endif + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */ + png_ptr->mode |= PNG_AFTER_IDAT; + } + + png_check_chunk_name(png_ptr, png_ptr->chunk_name); /* In the future we can have code here that calls user-supplied * callback functions for unknown chunks before they are ignored or * cause an error. */ - png_check_chunk_name(png_ptr, png_ptr->chunk_name); if (!(png_ptr->chunk_name[0] & 0x20)) { - png_chunk_error(png_ptr, "unknown critical chunk"); + if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + HANDLE_CHUNK_ALWAYS) + png_chunk_error(png_ptr, "unknown critical chunk"); /* to quiet compiler warnings about unused info_ptr */ if (info_ptr == NULL) @@ -1927,7 +1928,6 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_unknown_chunk chunk; - #ifdef PNG_MAX_MALLOC_64K if (length > (png_uint_32)65535L) { @@ -1946,9 +1946,11 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } else #endif - skip = length; + + skip = length; png_crc_finish(png_ptr, skip); + } /* This function is called to verify that a chunk name is valid. @@ -2032,7 +2034,7 @@ png_combine_row { int value; - value = (*sp >> shift) & 0x1; + value = (*sp >> shift) & 0x01; *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); *dp |= (png_byte)(value << shift); } @@ -2085,7 +2087,7 @@ png_combine_row { if (m & mask) { - value = (*sp >> shift) & 0x3; + value = (*sp >> shift) & 0x03; *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); *dp |= (png_byte)(value << shift); } @@ -2227,8 +2229,8 @@ png_do_read_interlace #if defined(PNG_READ_PACKSWAP_SUPPORTED) if (transformations & PNG_PACKSWAP) { - sshift = (int)((row_info->width + 7) & 7); - dshift = (int)((final_width + 7) & 7); + sshift = (int)((row_info->width + 7) & 0x07); + dshift = (int)((final_width + 7) & 0x07); s_start = 7; s_end = 0; s_inc = -1; @@ -2236,8 +2238,8 @@ png_do_read_interlace else #endif { - sshift = 7 - (int)((row_info->width + 7) & 7); - dshift = 7 - (int)((final_width + 7) & 7); + sshift = 7 - (int)((row_info->width + 7) & 0x07); + dshift = 7 - (int)((final_width + 7) & 0x07); s_start = 0; s_end = 7; s_inc = 1; @@ -2245,7 +2247,7 @@ png_do_read_interlace for (i = 0; i < row_info->width; i++) { - v = (png_byte)((*sp >> sshift) & 0x1); + v = (png_byte)((*sp >> sshift) & 0x01); for (j = 0; j < jstop; j++) { *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff); @@ -2280,8 +2282,8 @@ png_do_read_interlace #if defined(PNG_READ_PACKSWAP_SUPPORTED) if (transformations & PNG_PACKSWAP) { - sshift = (int)(((row_info->width + 3) & 3) << 1); - dshift = (int)(((final_width + 3) & 3) << 1); + sshift = (int)(((row_info->width + 3) & 0x03) << 1); + dshift = (int)(((final_width + 3) & 0x03) << 1); s_start = 6; s_end = 0; s_inc = -2; @@ -2289,8 +2291,8 @@ png_do_read_interlace else #endif { - sshift = (int)((3 - ((row_info->width + 3) & 3)) << 1); - dshift = (int)((3 - ((final_width + 3) & 3)) << 1); + sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1); + dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1); s_start = 0; s_end = 6; s_inc = 2; @@ -2301,7 +2303,7 @@ png_do_read_interlace png_byte v; int j; - v = (png_byte)((*sp >> sshift) & 0x3); + v = (png_byte)((*sp >> sshift) & 0x03); for (j = 0; j < jstop; j++) { *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff); @@ -2336,8 +2338,8 @@ png_do_read_interlace #if defined(PNG_READ_PACKSWAP_SUPPORTED) if (transformations & PNG_PACKSWAP) { - sshift = (int)(((row_info->width + 1) & 1) << 2); - dshift = (int)(((final_width + 1) & 1) << 2); + sshift = (int)(((row_info->width + 1) & 0x01) << 2); + dshift = (int)(((final_width + 1) & 0x01) << 2); s_start = 4; s_end = 0; s_inc = -4; @@ -2345,8 +2347,8 @@ png_do_read_interlace else #endif { - sshift = (int)((1 - ((row_info->width + 1) & 1)) << 2); - dshift = (int)((1 - ((final_width + 1) & 1)) << 2); + sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2); + dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2); s_start = 0; s_end = 4; s_inc = 4; @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -112,7 +112,6 @@ png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) } #endif #endif -#ifdef PNG_FIXED_POINT_SUPPORTED void png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point int_gamma) @@ -127,7 +126,6 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point info_ptr->int_gamma = int_gamma; info_ptr->valid |= PNG_INFO_gAMA; } -#endif #if defined(PNG_hIST_SUPPORTED) void @@ -137,8 +135,9 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) if (png_ptr == NULL || info_ptr == NULL) return; - info_ptr->hist = png_malloc(png_ptr, sizeof(png_uint_16) * info_ptr->num_palette); - memcpy(info_ptr->hist, hist, sizeof(png_uint_16) * info_ptr->num_palette); + info_ptr->hist = png_malloc(png_ptr, sizeof(png_uint_16) * + info_ptr->num_palette); + png_memcpy(info_ptr->hist, hist, sizeof(png_uint_16) * info_ptr->num_palette); info_ptr->valid |= PNG_INFO_hIST; } #endif @@ -420,7 +419,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, void png_set_iCCP(png_structp png_ptr, png_infop info_ptr, png_charp name, int compression_type, - png_charp profile, int proflen) + png_charp profile, png_uint_32 proflen) { png_debug1(1, "in %s storage function\n", "iCCP"); if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) @@ -429,8 +428,8 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, info_ptr->iccp_name = png_malloc(png_ptr, png_strlen(name)+1); strcpy(info_ptr->iccp_name, name); info_ptr->iccp_profile = png_malloc(png_ptr, proflen); - memcpy(info_ptr->iccp_profile, profile, proflen); - info_ptr->iccp_proflen = (png_uint_32)proflen; + png_memcpy(info_ptr->iccp_profile, profile, (png_size_t)proflen); + info_ptr->iccp_proflen = proflen; /* Compression is always zero but is here so the API and info structure * does not have to change * if we introduce multiple compression types */ info_ptr->iccp_compression = (png_byte)compression_type; @@ -596,7 +595,8 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, if (trans != NULL) { - info_ptr->trans = trans; + info_ptr->trans = png_malloc(png_ptr, num_trans); + png_memcpy(info_ptr->trans, trans, num_trans); } if (trans_values != NULL) @@ -622,7 +622,7 @@ png_set_spalettes(png_structp png_ptr, np = (png_spalette_p)png_malloc(png_ptr, (info_ptr->splt_palettes_num + nentries) * sizeof(png_spalette)); - memcpy(np, info_ptr->splt_palettes, + png_memcpy(np, info_ptr->splt_palettes, info_ptr->splt_palettes_num * sizeof(png_spalette)); png_free(png_ptr, info_ptr->splt_palettes); @@ -636,7 +636,7 @@ png_set_spalettes(png_structp png_ptr, png_strcpy(to->name, from->name); to->entries = (png_spalette_entryp)png_malloc(png_ptr, from->nentries * sizeof(png_spalette)); - memcpy(to->entries, from->entries, + png_memcpy(to->entries, from->entries, from->nentries * sizeof(png_spalette)); to->nentries = from->nentries; to->depth = from->depth; @@ -663,7 +663,7 @@ png_set_unknown_chunks(png_structp png_ptr, (info_ptr->unknown_chunks_num + num_unknowns) * sizeof(png_unknown_chunk)); - memcpy(np, info_ptr->unknown_chunks, + png_memcpy(np, info_ptr->unknown_chunks, info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk)); png_free(png_ptr, info_ptr->unknown_chunks); @@ -674,7 +674,7 @@ png_set_unknown_chunks(png_structp png_ptr, png_strcpy((png_charp)to->name, (png_charp)from->name); to->data = (png_bytep)png_malloc(png_ptr, from->size); - memcpy(to->data, from->data, from->size); + png_memcpy(to->data, from->data, from->size); to->size = from->size; /* note our location in the read or write sequence */ @@ -699,43 +699,37 @@ png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) void -png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep chunk_list, - int num_chunks) +png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep + chunk_list, int num_chunks) { - -/* - png_set_keep_unknown_chunks(png_ptr, keep, chunk_list, - num_chunks); - keep - 0: do not keep - 1: keep only if safe-to-copy - 2: keep even if unsafe-to-copy - The following are not yet implemented - in libpng version 1.0.5j: - chunk_list - list of chunks affected, NULL if - num_chunks is 0. - num_chunks - number of chunks affected. If 0, all - unknown chunks are affected. -*/ - + png_bytep new_list, p; + int i, old_num_chunks; if (num_chunks == 0) { - if(keep) + if(keep == HANDLE_CHUNK_ALWAYS || keep == HANDLE_CHUNK_IF_SAFE) png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; else png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; - if(keep == 2) + if(keep == HANDLE_CHUNK_ALWAYS) png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; else png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; + return; } - else + if (chunk_list == NULL) + return; + old_num_chunks=png_ptr->num_chunk_list; + new_list=png_malloc(png_ptr,5*(num_chunks+old_num_chunks)); + if(png_ptr->chunk_list != (png_bytep)NULL) { - /* to do: set up chunk_list processing */ - png_warning(png_ptr, - "chunk_list not yet implemented in png_set_keep_unknown_chunks"); - if (chunk_list == NULL || num_chunks == 0) - /* do nothing right now */ ; + png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); + png_free_chunk_list(png_ptr); } + png_memcpy(new_list+5*old_num_chunks, chunk_list, 5*num_chunks); + for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5) + *p=(png_byte)keep; + png_ptr->num_chunk_list=old_num_chunks+num_chunks; + png_ptr->chunk_list=new_list; } #endif diff --git a/pngtrans.c b/pngtrans.c index eabd096ba..53cdbc89d 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.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 diff --git a/pngtypes.h b/pngtypes.h index 9b5049c6f..3725d3d4f 100644 --- a/pngtypes.h +++ b/pngtypes.h @@ -1,6 +1,6 @@ /* pngtypes.h - array of chunk-types for libpng * - * libpng 1.0.5d - November 28, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -19,10 +19,13 @@ PNG_bKGD; PNG_cHRM; PNG_gAMA; PNG_hIST; +PNG_iCCP; +PNG_iTXt; PNG_oFFs; PNG_pCAL; PNG_pHYs; PNG_sBIT; +PNG_sPLT; PNG_sRGB; PNG_tEXt; PNG_tIME; @@ -2,7 +2,7 @@ * * For Intel x86 CPU and Microsoft Visual C++ compiler * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, Intel Corporation * Copyright (c) 1998, 1999 Glenn Randers-Pehrson @@ -1,7 +1,7 @@ /* pngwio.c - functions for data output * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 diff --git a/pngwrite.c b/pngwrite.c index 62ec55a19..dd55c0e07 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,7 +1,7 @@ /* pngwrite.c - general routines to write a PNG file * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -95,9 +95,11 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; up++) { - if (up->location && (!(up->location & PNG_HAVE_PLTE)) && - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS || - up->name[3] & 0x20)) + int keep=png_handle_as_unknown(png_ptr, up->name); + if (keep != HANDLE_CHUNK_NEVER && + up->location && (!(up->location & PNG_HAVE_PLTE)) && + ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) { png_write_chunk(png_ptr, up->name, up->data, up->size); } @@ -130,7 +132,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) { #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) /* invert the alpha channel (in tRNS) */ - if (png_ptr->transformations & PNG_INVERT_ALPHA && + if ((png_ptr->transformations & PNG_INVERT_ALPHA) && info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { int j; @@ -253,10 +255,12 @@ png_write_info(png_structp png_ptr, png_infop info_ptr) up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; up++) { - if (up->location && (up->location& PNG_HAVE_PLTE) && - !(up->location& PNG_HAVE_IDAT) && - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS || - up->name[3] & 0x20)) + int keep=png_handle_as_unknown(png_ptr, up->name); + if (keep != HANDLE_CHUNK_NEVER && + up->location && (up->location & PNG_HAVE_PLTE) && + !(up->location & PNG_HAVE_IDAT) && + ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) { png_write_chunk(png_ptr, up->name, up->data, up->size); } @@ -285,7 +289,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) #endif #if defined(PNG_WRITE_tIME_SUPPORTED) /* check to see if user has supplied a time chunk */ - if (info_ptr->valid & PNG_INFO_tIME && + if ((info_ptr->valid & PNG_INFO_tIME) && !(png_ptr->mode & PNG_WROTE_tIME)) png_write_tIME(png_ptr, &(info_ptr->mod_time)); #endif @@ -351,9 +355,11 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; up++) { - if ((up->location && (up->location & PNG_AFTER_IDAT)) && - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS || - up->name[3] & 0x20)) + int keep=png_handle_as_unknown(png_ptr, up->name); + if (keep != HANDLE_CHUNK_NEVER && + up->location && (up->location & PNG_AFTER_IDAT) && + ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) { png_write_chunk(png_ptr, up->name, up->data, up->size); } @@ -594,49 +600,49 @@ png_write_row(png_structp png_ptr, png_bytep row) switch (png_ptr->pass) { case 0: - if (png_ptr->row_number & 7) + if (png_ptr->row_number & 0x07) { png_write_finish_row(png_ptr); return; } break; case 1: - if ((png_ptr->row_number & 7) || png_ptr->width < 5) + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) { png_write_finish_row(png_ptr); return; } break; case 2: - if ((png_ptr->row_number & 7) != 4) + if ((png_ptr->row_number & 0x07) != 4) { png_write_finish_row(png_ptr); return; } break; case 3: - if ((png_ptr->row_number & 3) || png_ptr->width < 3) + if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) { png_write_finish_row(png_ptr); return; } break; case 4: - if ((png_ptr->row_number & 3) != 2) + if ((png_ptr->row_number & 0x03) != 2) { png_write_finish_row(png_ptr); return; } break; case 5: - if ((png_ptr->row_number & 1) || png_ptr->width < 2) + if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) { png_write_finish_row(png_ptr); return; } break; case 6: - if (!(png_ptr->row_number & 1)) + if (!(png_ptr->row_number & 0x01)) { png_write_finish_row(png_ptr); return; @@ -784,6 +790,9 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) #if defined(PNG_WRITE_TEXT_SUPPORTED) png_free_text(png_ptr, info_ptr, -1); #endif +#if defined(PNG_WRITE_tRNS_SUPPORTED) + png_free_tRNS(png_ptr, info_ptr); +#endif #if defined(PNG_WRITE_sCAL_SUPPORTED) png_free_sCAL(png_ptr, info_ptr); #endif @@ -796,8 +805,9 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) #if defined(PNG_WRITE_sPLT_SUPPORTED) png_free_spalettes(png_ptr, info_ptr, -1); #endif -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) +#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) png_free_unknown_chunks(png_ptr, info_ptr, -1); + png_free_chunk_list(png_ptr); #endif #if defined(PNG_hIST_SUPPORTED) png_free_hIST(png_ptr, info_ptr); @@ -915,14 +925,14 @@ png_set_filter(png_structp png_ptr, int method, int filters) */ if (png_ptr->row_buf != NULL) { - if (png_ptr->do_filter & PNG_FILTER_SUB && png_ptr->sub_row == NULL) + if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) { png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, (png_ptr->rowbytes + 1)); png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; } - if (png_ptr->do_filter & PNG_FILTER_UP && png_ptr->up_row == NULL) + if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) { if (png_ptr->prev_row == NULL) { @@ -937,7 +947,7 @@ png_set_filter(png_structp png_ptr, int method, int filters) } } - if (png_ptr->do_filter & PNG_FILTER_AVG && png_ptr->avg_row == NULL) + if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) { if (png_ptr->prev_row == NULL) { @@ -952,7 +962,7 @@ png_set_filter(png_structp png_ptr, int method, int filters) } } - if (png_ptr->do_filter & PNG_FILTER_PAETH && + if ((png_ptr->do_filter & PNG_FILTER_PAETH) && png_ptr->paeth_row == NULL) { if (png_ptr->prev_row == NULL) diff --git a/pngwtran.c b/pngwtran.c index 66282a287..15798a1a6 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.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -140,7 +140,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) { png_byte value; - value = (png_byte)(*sp & 0x3); + value = (png_byte)(*sp & 0x03); v |= (value << shift); if (shift == 0) { @@ -172,7 +172,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) { png_byte value; - value = (png_byte)(*sp & 0xf); + value = (png_byte)(*sp & 0x0f); v |= (value << shift); if (shift == 0) diff --git a/pngwutil.c b/pngwutil.c index 050f1a811..afd3f8bf8 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,7 +1,7 @@ /* pngwutil.c - utilities to write a PNG file * - * libpng 1.0.5j - December 21, 1999 + * libpng 1.0.5k - December 27, 1999 * 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 @@ -584,8 +584,8 @@ png_write_gAMA(png_structp png_ptr, double file_gamma) png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); } #endif -void #ifdef PNG_FIXED_POINT_SUPPORTED +void png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) { #ifdef PNG_USE_LOCAL_ARRAYS @@ -1741,7 +1741,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) i += png_pass_inc[pass]) { sp = row + (png_size_t)(i >> 3); - value = (int)(*sp >> (7 - (int)(i & 7))) & 0x1; + value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01; d |= (value << shift); if (shift == 0) @@ -1775,7 +1775,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) i += png_pass_inc[pass]) { sp = row + (png_size_t)(i >> 2); - value = (*sp >> ((3 - (int)(i & 3)) << 1)) & 0x3; + value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03; d |= (value << shift); if (shift == 0) @@ -1808,7 +1808,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) i += png_pass_inc[pass]) { sp = row + (png_size_t)(i >> 1); - value = (*sp >> ((1 - (int)(i & 1)) << 2)) & 0xf; + value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f; d |= (value << shift); if (shift == 0) @@ -1915,7 +1915,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info) /* We don't need to test the 'no filter' case if this is the only filter * that has been chosen, as it doesn't actually do anything to the data. */ - if (filter_to_do & PNG_FILTER_NONE && + if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE) { png_bytep rp; |