From 4df0ff379fe90fed48540869211f7cbec8c3356f Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sun, 29 Apr 2001 07:40:43 -0500 Subject: [PATCH] Imported from pngcrush-1.5.4.tar --- README.txt | 101 ++++----- inflate.c | 92 ++++---- png.c | 73 ++++--- png.h | 193 ++++++++++------- pngasmrd.h | 36 +-- pngconf.h | 626 +++++++++++++++++++++++++++++++---------------------- pngcrush.c | 330 +++++++++++++++++----------- pngcrush.h | 11 +- pngerror.c | 13 +- pnggccrd.c | 624 +++++++++++++++++++++++++++++----------------------- pngget.c | 51 ++--- pngmem.c | 22 +- pngpread.c | 84 +++++-- pngread.c | 25 ++- pngrio.c | 4 +- pngrtran.c | 4 +- pngrutil.c | 191 +++++++--------- pngset.c | 162 ++++++++++++-- pngtrans.c | 10 +- pngvcrd.c | 196 ++++++++--------- pngwio.c | 6 +- pngwrite.c | 42 +++- pngwtran.c | 6 +- pngwutil.c | 52 +++-- zlib.h | 3 + 25 files changed, 1689 insertions(+), 1268 deletions(-) diff --git a/README.txt b/README.txt index 6e694e472..f4d38648d 100644 --- a/README.txt +++ b/README.txt @@ -10,7 +10,7 @@ case of any discrepancy, the copy in pngcrush.c shall prevail): * If you have modified this source, you may insert additional notices * immediately after this sentence. * - * Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) + * Copyright (C) 1998-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu) * * The pngcrush computer program is supplied "AS IS". The Author disclaims all * warranties, expressed or implied, including, without limitation, the @@ -25,7 +25,7 @@ case of any discrepancy, the copy in pngcrush.c shall prevail): * risk of satisfactory quality, performance, accuracy, and effort is with * the user. * - * Permission is hereby irrevocably granted to anyone to use, copy, modify, + * Permission is hereby irrevocably granted to everyone to use, copy, modify, * and distribute this source code, or portions hereof, for any purpose, * without payment of any fee, subject to the following restrictions: * @@ -40,13 +40,14 @@ case of any discrepancy, the copy in pngcrush.c shall prevail): This is the output of "pngcrush" and "pngcrush -help": - | pngcrush 1.5.3, Copyright (C) 1998, 1999, 2000 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.9beta5, - | and is running with libpng version 1.0.9beta5 - December 14, 2000 (header) - | Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson, + + | pngcrush 1.5.4, 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) + | Copyright (C) 1998-2001 Glenn Randers-Pehrson, | Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., | and zlib version 1.1.3pc, Copyright (C) 1998, @@ -58,9 +59,9 @@ usage: pngcrush [options] infile.png outfile.png pngcrush -d dir [other options] files.png ... options: -already already_crushed_size [e.g., 8192] + -bit_depth depth (bit_depth to use in output file) -brute (Use brute-force, try 114 different methods [11-124]) -c color_type of output file [0, 2, 4, or 6] - -cc (do color counting) -d directory_name (where output files will go) -double_gamma (used for fixing gamma in PhotoShop 5.0/5.02 files) -e extension (used for creating output filename) @@ -71,9 +72,9 @@ options: -iccp length "Profile Name" iccp_file -itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -l zlib_compression_level [0-9] + -loco ("loco crush" truecolor PNGs) -m method [0 through 200] - -max maximum_IDAT_size [default 524288] - -no_cc (no color counting) + -max maximum_IDAT_size [default 8192] -n (no save; does not do compression or write output PNG) -plte_len n (truncate PLTE) -q (quiet) @@ -82,7 +83,6 @@ options: -replace_gamma gamma (float or fixed*100000) even if gAMA is present. -res dpi -srgb [0, 1, 2, or 3] - -loco ("loco crush" truecolor PNGs) -text b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -trns index red green blue gray -v (display more detailed information) @@ -91,6 +91,24 @@ options: -h (help and legal notices) -p (pause) + + | pngcrush 1.5.4, 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) + | Copyright (C) 1998-2001 Glenn Randers-Pehrson, + | Copyright (C) 1996, 1997 Andreas Dilger, + | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., + | and zlib version 1.1.3pc, 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 (Note: any option can be spelled out for clarity, e.g., "pngcrush -dir New -method 7 -remove bkgd *.png" is the same as "pngcrush -d New -m 7 -rem bkgd *.png"): @@ -102,6 +120,10 @@ options (Note: any option can be spelled out for clarity, e.g., not be processed, unless you are making other changes or the "-force" option is present. + -bit_depth depth (bit_depth to use in output file) + + Default output depth is same as input depth. + -brute (Use brute-force, try 114 different methods [11-124]) Very time-consuming and generally not worthwhile. @@ -120,8 +142,6 @@ options (Note: any option can be spelled out for clarity, e.g., Use 0 or 2 to delete an unwanted alpha channel. Default is to use same color type as the input file. - -cc (do color counting) - -d directory_name (where output files will go) If a directory name is given, then the output @@ -174,6 +194,15 @@ options (Note: any option can be spelled out for clarity, e.g., with the preceding '-m method' or '-brute_force' argument. + -loco ("loco crush" truecolor PNGs) + + Make the file more compressible by performing a + lossless reversible color transformation. + The resulting file is a MNG, not a PNG, and should + be given the ".mng" file extension. The + "loco" option has no effect on grayscale or + indexed-color PNG files. + -m method [0 through 200] pngcrush method to try (0 means try all of 1-10). @@ -184,10 +213,7 @@ options (Note: any option can be spelled out for clarity, e.g., 1, 4, and 7 use no filtering; methods 11 and up use specified filter, compression level, and strategy. - -max maximum_IDAT_size [default 524288] - - -no_cc (no color counting) - + -max maximum_IDAT_size [default 8192] -n (no save; does not do compression or write output PNG) Useful in conjunction with -v option to get info. @@ -229,15 +255,6 @@ options (Note: any option can be spelled out for clarity, e.g., Value of 'rendering intent' for sRGB chunk. - -loco ("loco crush" truecolor PNGs) - - Make the file more compressible by performing a - lossless reversible color transformation. - The resulting file is a MNG, not a PNG, and should - be given the ".mng" file extension. The - "loco" option has no effect on grayscale or - indexed-color PNG files. - -text b[efore_IDAT]|a[fter_IDAT] "keyword" "text" tEXt chunk to insert. keyword < 80 chars, @@ -294,31 +311,3 @@ options (Note: any option can be spelled out for clarity, e.g., screen scrolls out of sight. -Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) - - -DISCLAIMER: The pngcrush computer program is supplied "AS IS". -The Author disclaims all warranties, expressed or implied, including, -without limitation, the warranties of merchantability and of fitness -for any purpose. The Author assumes no liability for direct, indirect, -incidental, special, exemplary, or consequential damages, which may -result from the use of the computer program, even if advised of the -possibility of such damage. There is no warranty against interference -with your enjoyment of the computer program or against infringement. -There is no warranty that my efforts or the computer program will -fulfill any of your particular purposes or needs. This computer -program is provided with all faults, and the entire risk of satisfactory -quality, performance, accuracy, and effort is with the user. - -LICENSE: Permission is hereby irrevocably granted to everyone to use, -copy, modify, and distribute this computer program, or portions hereof, -purpose, without payment of any fee, subject to the following -restrictions: - -1. The origin of this binary or source code must not be misrepresented. - -2. Altered versions must be plainly marked as such and must not be -misrepresented as being the original binary or source. - -3. The Copyright notice, disclaimer, and license may not be removed -or altered from any source, binary, or altered source distribution. diff --git a/inflate.c b/inflate.c index 1e4cf8bca..bbefae46e 100644 --- a/inflate.c +++ b/inflate.c @@ -160,6 +160,52 @@ int f; r = Z_BUF_ERROR; while (1) switch (z->state->mode) { + case BLOCKS: + r = inflate_blocks(z->state->blocks, z, r); + if (r == Z_DATA_ERROR) + { + z->state->mode = BAD; + z->state->sub.marker = 0; /* can try inflateSync */ + break; + } + if (r == Z_OK) + r = f; + if (r != Z_STREAM_END) + return r; + r = f; + inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); + if (z->state->nowrap) + { + z->state->mode = DONE; + break; + } + z->state->mode = CHECK4; + case CHECK4: + NEEDBYTE + z->state->sub.check.need = (uLong)NEXTBYTE << 24; + z->state->mode = CHECK3; + case CHECK3: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE << 16; + z->state->mode = CHECK2; + case CHECK2: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE << 8; + z->state->mode = CHECK1; + case CHECK1: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE; + if (z->state->sub.check.was != z->state->sub.check.need) + { + z->state->mode = BAD; + z->msg = (char*)"incorrect data check"; + z->state->sub.marker = 5; /* can't try inflateSync */ + break; + } + Tracev((stderr, "inflate: zlib check ok\n")); + z->state->mode = DONE; + case DONE: + return Z_STREAM_END; case METHOD: NEEDBYTE if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) @@ -217,52 +263,6 @@ int f; z->msg = (char*)"need dictionary"; z->state->sub.marker = 0; /* can try inflateSync */ return Z_STREAM_ERROR; - case BLOCKS: - r = inflate_blocks(z->state->blocks, z, r); - if (r == Z_DATA_ERROR) - { - z->state->mode = BAD; - z->state->sub.marker = 0; /* can try inflateSync */ - break; - } - if (r == Z_OK) - r = f; - if (r != Z_STREAM_END) - return r; - r = f; - inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); - if (z->state->nowrap) - { - z->state->mode = DONE; - break; - } - z->state->mode = CHECK4; - case CHECK4: - NEEDBYTE - z->state->sub.check.need = (uLong)NEXTBYTE << 24; - z->state->mode = CHECK3; - case CHECK3: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 16; - z->state->mode = CHECK2; - case CHECK2: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 8; - z->state->mode = CHECK1; - case CHECK1: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE; - if (z->state->sub.check.was != z->state->sub.check.need) - { - z->state->mode = BAD; - z->msg = (char*)"incorrect data check"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - Tracev((stderr, "inflate: zlib check ok\n")); - z->state->mode = DONE; - case DONE: - return Z_STREAM_END; case BAD: return Z_DATA_ERROR; default: diff --git a/png.c b/png.c index 45b4701a2..e2cf0b7d2 100644 --- a/png.c +++ b/png.c @@ -1,8 +1,8 @@ /* png.c - location for general purpose libpng functions * - * libpng version 1.0.9beta5 - December 14, 2000 - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * libpng version 1.0.11 - April 27, 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_9beta5 Your_png_h_is_not_version_1_0_9beta5; +typedef version_1_0_11 Your_png_h_is_not_version_1_0_11; /* 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.9beta5"; +const char png_libpng_ver[18] = "1.0.11"; /* png_sig was changed to a function in version 1.0.5c */ /* Place to hold the signature string for a PNG file. */ @@ -135,7 +135,7 @@ png_check_sig(png_bytep sig, int num) } /* Function to allocate memory for zlib and clear it to 0. */ -voidpf PNGAPI +voidpf /* PRIVATE */ png_zalloc(voidpf png_ptr, uInt items, uInt size) { png_uint_32 num_bytes = (png_uint_32)items * size; @@ -157,7 +157,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size) } /* function to free memory for zlib */ -void PNGAPI +void /* PRIVATE */ png_zfree(voidpf png_ptr, voidpf ptr) { png_free((png_structp)png_ptr, (png_voidp)ptr); @@ -255,7 +255,7 @@ 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 PNGAPI +void /* PRIVATE */ png_info_init(png_infop info_ptr) { png_debug(1, "in png_info_init\n"); @@ -282,7 +282,8 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr, #endif void PNGAPI -png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num) +png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, + int num) { png_debug(1, "in png_free_data\n"); if (png_ptr == NULL || info_ptr == NULL) @@ -582,31 +583,31 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) } #if defined(_WIN32_WCE) - { - wchar_t time_buf[29]; - wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), - ptime->day % 32, short_months[(ptime->month - 1) % 12], - ptime->year, ptime->hour % 24, ptime->minute % 60, - ptime->second % 61); - WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29, - NULL, NULL); - } + { + wchar_t time_buf[29]; + wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); + WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29, + NULL, NULL); + } #else #ifdef USE_FAR_KEYWORD { char near_time_buf[29]; sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000", - ptime->day % 32, short_months[(ptime->month - 1) % 12], - ptime->year, ptime->hour % 24, ptime->minute % 60, - ptime->second % 61); + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); png_memcpy(png_ptr->time_buffer, near_time_buf, - 29*sizeof(char)); + 29*sizeof(char)); } #else sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000", - ptime->day % 32, short_months[(ptime->month - 1) % 12], - ptime->year, ptime->hour % 24, ptime->minute % 60, - ptime->second % 61); + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); #endif #endif /* _WIN32_WCE */ return ((png_charp)png_ptr->time_buffer); @@ -626,8 +627,8 @@ 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.9beta5 - December 14, 2000\n\ - Copyright (c) 1998-2000 Glenn Randers-Pehrson\n\ + return ((png_charp) "\n libpng version 1.0.11 - April 27, 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"); return ((png_charp) ""); @@ -644,8 +645,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.9beta5"); - return((png_charp) "1.0.9beta5"); + return((png_charp) "1.0.11"); + return((png_charp) "1.0.11"); } png_charp PNGAPI @@ -667,7 +668,7 @@ png_get_header_version(png_structp png_ptr) } #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -int PNGAPI +int /* PRIVATE */ 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 */ @@ -695,5 +696,17 @@ png_uint_32 PNGAPI png_access_version_number(void) { /* Version of *.c files used when building libpng */ - return((png_uint_32) 10009L); + return((png_uint_32) 10011L); } + + +#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 +int PNGAPI +png_mmx_support(void) +{ + return -1; +} +#endif +#endif /* 0 */ diff --git a/png.h b/png.h index 404293f87..a8fc40c8e 100644 --- a/png.h +++ b/png.h @@ -1,15 +1,15 @@ /* png.h - header file for PNG reference library * - * libpng version 1.0.9beta5 - December 14, 2000 - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * libpng version 1.0.11 - April 27, 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.) * * 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.9beta5 - December 14, 2000: Glenn + * libpng versions 0.97, January 1998, through 1.0.11 - April 27, 2001: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -52,18 +52,29 @@ * 1.0.6h 10007 10.6h (testing xy.z so-numbering) * 1.0.6i 10007 10.6i * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) - * 1.0.7beta11-18 10007 2.1.0.7beta11-18 (binary compatible) - * 1.0.7rc1-2 10007 2.1.0.7rc1-2 (binary compatible) - * 1.0.7 10007 (still compatible) - * 1.0.8beta1-4 10008 2.1.0.8beta1-4 - * 1.0.8rc1 10008 2.1.0.8rc1 - * 1.0.8 10008 2.1.0.8 - * 1.0.9beta1-5 10009 2.1.0.9beta1-5 + * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) + * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) + * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) + * 1.0.7 1 10007 (still compatible) + * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 + * 1.0.8rc1 1 10008 2.1.0.8rc1 + * 1.0.8 1 10008 2.1.0.8 + * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 + * 1.0.9rc1 1 10009 2.1.0.9rc1 + * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 + * 1.0.9rc2 1 10009 2.1.0.9rc2 + * 1.0.9 1 10009 2.1.0.9 + * 1.0.10beta1 1 10010 2.1.0.10beta1 + * 1.0.10rc1 1 10010 2.1.0.10rc1 + * 1.0.10 1 10010 2.1.0.10 + * 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 * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be * used for changes in backward compatibility, as it is intended. The - * PNG_PNGLIB_VER macro, which is not used within libpng but is available + * PNG_LIBPNG_VER macro, which is not used within libpng but is available * for applications, is an unsigned integer of the form xyyzz corresponding * to the source version x.y.z (leading zeros in y and z). Beta versions * were given the previous public release number plus a letter, until @@ -74,6 +85,9 @@ * to the info_ptr or png_ptr members through png.h, and the compiled * application is loaded with a different version of the library. * + * DLLNUM will change each time there are forward or backward changes + * in binary compatibility (e.g., when a new feature is added). + * * See libpng.txt or libpng.3 for more information. The PNG specification * is available as RFC 2083 * and as a W3C Recommendation @@ -85,8 +99,8 @@ * If you modify libpng you may insert additional notices immediately following * this sentence. * - * libpng versions 1.0.7, July 1, 2000, through 1.0.9beta5, December 14, 2000, are - * Copyright (c) 2000 Glenn Randers-Pehrson, and are + * libpng versions 1.0.7, July 1, 2000, through 1.0.11, April 27, 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 * @@ -150,11 +164,11 @@ * * 1. The origin of this source code must not be misrepresented. * - * 2. Altered versions must be plainly marked as such and must not - * be misrepresented as being the original source. + * 2. Altered versions must be plainly marked as such and + * must not be misrepresented as being the original source. * - * 3. This Copyright notice may not be removed or altered from any - * source or altered source distribution. + * 3. This Copyright notice may not be removed or altered from + * any source or altered source distribution. * * The Contributing Authors and Group 42, Inc. specifically permit, without * fee, and encourage the use of this source code as a component to @@ -190,13 +204,13 @@ * Y2K compliance in libpng: * ========================= * - * December 14, 2000 + * April 27, 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.9beta5 are Y2K compliant. It is my belief that earlier + * upward through 1.0.11 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 @@ -252,18 +266,19 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.0.9beta5" +#define PNG_LIBPNG_VER_STRING "1.0.11" #define PNG_LIBPNG_VER_SONUM 2 +#define PNG_LIBPNG_VER_DLLNUM %DLLNUM% /* 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 9 +#define PNG_LIBPNG_VER_RELEASE 11 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ -#define PNG_LIBPNG_VER_BUILD 5 +#define PNG_LIBPNG_VER_BUILD 0 #define PNG_LIBPNG_BUILD_ALPHA 1 #define PNG_LIBPNG_BUILD_BETA 2 @@ -271,28 +286,23 @@ #define PNG_LIBPNG_BUILD_STABLE 4 #define PNG_LIBPNG_BUILD_TYPEMASK 7 #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with STABLE only */ -#define PNG_LIBPNG_BUILD_TYPE 2 +#define PNG_LIBPNG_BUILD_TYPE 4 /* Careful here. At one time, Guy wanted to use 082, but that would be octal. * We must not include leading zeros. * 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 10009 /* 1.0.9 */ +#define PNG_LIBPNG_VER 10011 /* 1.0.11 */ #ifndef PNG_VERSION_INFO_ONLY /* include the compression library's header */ #include "zlib.h" -/* include all user configurable info */ +/* include all user configurable info, including optional assembler routines */ #include "pngconf.h" -/* macros for optional assembler routines */ -#if defined(PNG_INTERNAL) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) -# include "pngasmrd.h" -#endif - /* Inhibit C++ name-mangling for libpng functions but not for system calls. */ #ifdef __cplusplus extern "C" { @@ -446,7 +456,7 @@ typedef png_text FAR * FAR * png_textpp; * Two conversions are provided, both from time_t and struct tm. There * is no portable way to convert to either of these structures, as far * as I know. If you know of a portable way, send it to me. As a side - * note - PNG is Year 2000 compliant! + * note - PNG has always been Year 2000 compliant! */ typedef struct png_time_struct { @@ -504,20 +514,20 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; * The following members may have allocated storage attached that should be * cleaned up before the structure is discarded: palette, trans, text, * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, - * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these are - * automatically freed when the info structure is deallocated, if they were + * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these + * are automatically freed when the info structure is deallocated, if they were * allocated internally by libpng. This behavior can be changed by means * of the png_data_freer() function. * - * More allocation details: all the chunk-reading functions that change these - * members go through the corresponding png_set_* functions. A function to - * clear these members is available: see png_free_data(). Some of the - * png_set_* functions do not depend on being able to point info structure - * members to any of the storage they are passed (they make their own copies), - * EXCEPT that the png_set_text functions use the same storage passed to them - * in the text_ptr or itxt_ptr structure argument, and the png_set_tRNS, - * png_set_PLTE, png_set_hIST, png_set_iCCP, png_set_rows, png_set_sPLT, - * and png_set_unknowns do not make their own copies. + * More allocation details: all the chunk-reading functions that + * change these members go through the corresponding png_set_* + * functions. A function to clear these members is available: see + * png_free_data(). The png_set_* functions do not depend on being + * able to point info structure members to any of the storage they are + * passed (they make their own copies), EXCEPT that the png_set_text + * functions use the same storage passed to them in the text_ptr or + * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns + * functions do not make their own copies. */ typedef struct png_info_struct { @@ -825,6 +835,8 @@ typedef png_info FAR * FAR * png_infopp; /* This is for text chunks */ #define PNG_KEYWORD_MAX_LENGTH 79 +/* Maximum number of entries in PLTE/sPLT/tRNS arrays */ +#define PNG_MAX_PALETTE_LENGTH 256 /* These determine if an ancillary chunk's data has been successfully read * from the PNG header, or if the application has filled in the corresponding @@ -896,10 +908,10 @@ typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp, png_row_infop, png_bytep)); #endif -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) +#if defined(PNG_USER_CHUNKS_SUPPORTED) typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp)); #endif -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); #endif @@ -920,9 +932,8 @@ typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); /* Flags for MNG supported features */ #define PNG_FLAG_MNG_EMPTY_PLTE 0x01 -#define PNG_MODE_EMBEDDED_IN_MNG 0x02 #define PNG_FLAG_MNG_FILTER_64 0x04 -#define PNG_ALL_MNG_FEATURES 0x07 +#define PNG_ALL_MNG_FEATURES 0x05 typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t)); typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp)); @@ -1020,7 +1031,7 @@ struct png_struct_def #endif #endif -#if defined(PNG_READ_bKGD_SUPPORTED) +#if defined(PNG_bKGD_SUPPORTED) png_byte background_gamma_type; # ifdef PNG_FLOATING_POINT_SUPPORTED float background_gamma; @@ -1028,8 +1039,8 @@ struct png_struct_def png_color_16 background; /* background color in screen gamma space */ # if defined(PNG_READ_GAMMA_SUPPORTED) png_color_16 background_1; /* background normalized to gamma 1.0 */ -# endif /* PNG_READ_GAMMA && PNG_READ_bKGD_SUPPORTED */ -#endif /* PNG_READ_bKGD_SUPPORTED */ +# endif /* PNG_READ_GAMMA && PNG_bKGD_SUPPORTED */ +#endif /* PNG_bKGD_SUPPORTED */ #if defined(PNG_WRITE_FLUSH_SUPPORTED) png_flush_ptr output_flush_fn;/* Function for flushing output */ @@ -1054,7 +1065,7 @@ struct png_struct_def png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ #endif -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_sBIT_SUPPORTED) +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) png_color_8 sig_bit; /* significant bits in each available channel */ #endif @@ -1062,7 +1073,7 @@ struct png_struct_def png_color_8 shift; /* shift for significant bit tranformation */ #endif -#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) png_bytep trans; /* transparency values for paletted files */ png_color_16 trans_values; /* transparency values for non-paletted files */ @@ -1087,12 +1098,12 @@ struct png_struct_def int process_mode; /* what push library is currently doing */ int cur_palette; /* current push library palette index */ -# if defined(PNG_READ_TEXT_SUPPORTED) +# if defined(PNG_TEXT_SUPPORTED) png_size_t current_text_size; /* current size of text input data */ png_size_t current_text_left; /* how much text left to read in input */ png_charp current_text; /* current text chunk buffer */ png_charp current_text_ptr; /* current location in current_text */ -# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_TEXT_SUPPORTED */ +# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */ #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ @@ -1110,7 +1121,7 @@ struct png_struct_def png_bytep dither_index; /* index translation for palette files */ #endif -#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED) +#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED) png_uint_16p hist; /* histogram */ #endif @@ -1140,7 +1151,7 @@ struct png_struct_def png_uint_32 free_me; /* flags items libpng is responsible for freeing */ #endif -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) +#if defined(PNG_USER_CHUNKS_SUPPORTED) png_voidp user_chunk_ptr; png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ #endif @@ -1170,12 +1181,15 @@ struct png_struct_def png_byte filter_type; + png_uint_32 row_buf_size; + }; + /* This prevents a compiler error in png_get_copyright() in png.c if png.c -and png.h are both at * version 1.0.9beta5 +and png.h are both at * version 1.0.11 */ -typedef png_structp version_1_0_9beta5; +typedef png_structp version_1_0_11; typedef png_struct FAR * FAR * png_structpp; @@ -1689,7 +1703,7 @@ extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr) PNGARG((png_structp png_ptr)); #endif -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +#ifdef PNG_USER_CHUNKS_SUPPORTED extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr, png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp @@ -1882,7 +1896,7 @@ png_ptr, png_infop info_ptr)); extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr, png_infop info_ptr)); -#if defined(PNG_READ_bKGD_SUPPORTED) +#if defined(PNG_bKGD_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr, png_infop info_ptr, png_color_16p *background)); #endif @@ -1892,7 +1906,7 @@ extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr, png_infop info_ptr, png_color_16p background)); #endif -#if defined(PNG_READ_cHRM_SUPPORTED) +#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr, png_infop info_ptr, double *white_x, double *white_y, double *red_x, @@ -1923,7 +1937,7 @@ extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, #endif #endif -#if defined(PNG_READ_gAMA_SUPPORTED) +#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr, png_infop info_ptr, double *file_gamma)); @@ -1941,7 +1955,7 @@ extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr, png_infop info_ptr, png_fixed_point int_file_gamma)); #endif -#if defined(PNG_READ_hIST_SUPPORTED) +#if defined(PNG_hIST_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)); #endif @@ -1961,7 +1975,7 @@ extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr, int color_type, int interlace_method, int compression_method, int filter_method)); -#if defined(PNG_READ_oFFs_SUPPORTED) +#if defined(PNG_oFFs_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr, png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)); @@ -1973,7 +1987,7 @@ extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr, int unit_type)); #endif -#if defined(PNG_READ_pCAL_SUPPORTED) +#if defined(PNG_pCAL_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((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)); @@ -1985,7 +1999,7 @@ extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr, int type, int nparams, png_charp units, png_charpp params)); #endif -#if defined(PNG_READ_pHYs_SUPPORTED) +#if defined(PNG_pHYs_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); #endif @@ -2001,7 +2015,7 @@ extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr, png_infop info_ptr, png_colorp palette, int num_palette)); -#if defined(PNG_READ_sBIT_SUPPORTED) +#if defined(PNG_sBIT_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)); #endif @@ -2011,7 +2025,7 @@ extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr, png_infop info_ptr, png_color_8p sig_bit)); #endif -#if defined(PNG_READ_sRGB_SUPPORTED) +#if defined(PNG_sRGB_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr, png_infop info_ptr, int *intent)); #endif @@ -2023,7 +2037,7 @@ extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr, png_infop info_ptr, int intent)); #endif -#if defined(PNG_READ_iCCP_SUPPORTED) +#if defined(PNG_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_uint_32 *proflen)); @@ -2037,7 +2051,7 @@ extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr, /* Note to maintainer: profile should be png_bytep */ #endif -#if defined(PNG_READ_sPLT_SUPPORTED) +#if defined(PNG_sPLT_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr, png_infop info_ptr, png_sPLT_tpp entries)); #endif @@ -2047,7 +2061,7 @@ extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr, png_infop info_ptr, png_sPLT_tp entries, int nentries)); #endif -#if defined(PNG_READ_TEXT_SUPPORTED) +#if defined(PNG_TEXT_SUPPORTED) /* png_get_text also returns the number of text chunks in *num_text */ extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, int *num_text)); @@ -2066,7 +2080,7 @@ extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, int num_text)); #endif -#if defined(PNG_READ_tIME_SUPPORTED) +#if defined(PNG_tIME_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); #endif @@ -2076,7 +2090,7 @@ extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr, png_infop info_ptr, png_timep mod_time)); #endif -#if defined(PNG_READ_tRNS_SUPPORTED) +#if defined(PNG_tRNS_SUPPORTED) extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values)); @@ -2091,7 +2105,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, #if defined(PNG_tRNS_SUPPORTED) #endif -#if defined(PNG_READ_sCAL_SUPPORTED) +#if defined(PNG_sCAL_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr, png_infop info_ptr, int *unit, double *width, double *height)); @@ -2101,7 +2115,7 @@ extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr, png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); #endif #endif -#endif /* PNG_READ_sCAL_SUPPORTED */ +#endif /* PNG_sCAL_SUPPORTED */ #if defined(PNG_sCAL_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED @@ -2112,7 +2126,7 @@ extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, png_infop info_ptr, int unit, png_charp swidth, png_charp sheight)); #endif -#endif /* PNG_READ_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */ +#endif /* PNG_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 @@ -2215,8 +2229,15 @@ 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.c, pnggccrd.c, or pngvcrd.c */ +extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); +#endif + +/* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */ + #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.0.9beta5 - December 14, 2000 (header)\n" + " libpng version 1.0.11 - April 27, 2001 (header)\n" #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* With these routines we avoid an integer divide, which will be slower on @@ -2282,6 +2303,7 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp #define PNG_WROTE_tIME 0x200 #define PNG_WROTE_INFO_BEFORE_PLTE 0x400 #define PNG_BACKGROUND_IS_GRAY 0x800 +#define PNG_HAVE_PNG_SIGNATURE 0x1000 /* flags for the transformations the PNG library does on the image data */ #define PNG_BGR 0x0001 @@ -2429,13 +2451,13 @@ 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) || defined(PNG_READ_oFFs_SUPPORTED) +# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_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) || defined(PNG_READ_oFFs_SUPPORTED) +# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED) PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf)); # endif PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf)); @@ -2443,7 +2465,7 @@ PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf)); #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */ /* Initialize png_ptr struct for reading, and allocate any other memory. - * (old interface - DEPRECATED). + * (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, \ @@ -2453,7 +2475,7 @@ extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, png_info_size)); /* Initialize png_ptr struct for writing, and allocate any other memory. - * (old interface - DEPRECATED). + * (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, \ @@ -2499,8 +2521,8 @@ PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, png_size_t length)); /* Decompress data in a chunk that uses compression */ -#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \ - defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_sPLT_SUPPORTED) +#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \ + defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr, int comp_type, png_charp chunkdata, png_size_t chunklength, png_size_t prefix_length, png_size_t *data_length)); @@ -2695,10 +2717,15 @@ PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, #if defined(PNG_READ_INTERLACING_SUPPORTED) /* expand an interlaced row */ +/* OLD pre-1.0.9 interface: PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, png_bytep row, int pass, png_uint_32 transformations)); + */ +PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr)); #endif +/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ + #if defined(PNG_WRITE_INTERLACING_SUPPORTED) /* grab pixels out of a row for an interlaced pass */ PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, @@ -3010,6 +3037,8 @@ PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, png_bytep row)); #endif +/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + #endif /* PNG_INTERNAL */ #ifdef __cplusplus diff --git a/pngasmrd.h b/pngasmrd.h index ad0bfcf3a..1ed10e46f 100644 --- a/pngasmrd.h +++ b/pngasmrd.h @@ -1,39 +1,11 @@ /* pngasmrd.h - assembler version of utilities to read a PNG file * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1999, 2000 Glenn Randers-Pehrson + * Copyright (c) 2001 Glenn Randers-Pehrson * */ -#ifndef PNGASMRD_H -#define PNGASMRD_H - -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED - -/* Set this in the makefile for VC++ on Pentium, not in pngconf.h */ -/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c . - * MMX will be detected at run time and used if present. +/* This file is obsolete in libpng-1.0.9 and later; its contents now appear + * at the end of pngconf.h. */ -#ifdef PNG_USE_PNGVCRD -# define PNG_HAVE_ASSEMBLER_COMBINE_ROW -# define PNG_HAVE_ASSEMBLER_READ_INTERLACE -# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW -#endif - -/* Set this in the makefile for gcc/as on Pentium, not in pngconf.h */ -/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c . - * MMX will be detected at run time and used if present. - */ -#ifdef PNG_USE_PNGGCCRD -# define PNG_HAVE_ASSEMBLER_COMBINE_ROW -# define PNG_HAVE_ASSEMBLER_READ_INTERLACE -# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW -#endif -/* - GRR notes: - - see pnggccrd.c for info about what is currently enabled - */ - -#endif -#endif /* PNGASMRD_H */ diff --git a/pngconf.h b/pngconf.h index d29d2e8aa..6ecbc2d90 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,8 +1,8 @@ /* pngconf.h - machine configurable file for libpng * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) */ @@ -32,11 +32,35 @@ */ #ifndef PNG_ZBUF_SIZE -#define PNG_ZBUF_SIZE 8192 +# define PNG_ZBUF_SIZE 8192 #endif +/* Enable if you want a write-only libpng */ + +#ifndef PNG_NO_READ_SUPPORTED +# define PNG_READ_SUPPORTED +#endif + +/* Enable if you want a read-only libpng */ + +#ifndef PNG_NO_WRITE_SUPPORTED +# define PNG_WRITE_SUPPORTED +#endif + +/* Enable if you need to support PNGs that are embedded in MNG + datastreams */ +/* +#ifndef PNG_NO_MNG_FEATURES +# ifndef PNG_MNG_FEATURES_SUPPORTED +# define PNG_MNG_FEATURES_SUPPORTED +# endif +#endif +*/ + #ifndef PNG_NO_FLOATING_POINT_SUPPORTED -#define PNG_FLOATING_POINT_SUPPORTED +# ifndef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FLOATING_POINT_SUPPORTED +# endif #endif /* If you are running on a machine where you cannot allocate more @@ -48,7 +72,7 @@ #define PNG_MAX_MALLOC_64K */ #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) -#define PNG_MAX_MALLOC_64K +# define PNG_MAX_MALLOC_64K #endif /* Special munging to support doing things the 'cygwin' way: @@ -61,7 +85,9 @@ * PNG_BUILD_DLL -- building the dll * (no define) -- building an application, linking to the dll * PNG_STATIC -- building the static lib, or building an application - * which links to the static lib. + * that links to the static lib. + * ALL_STATIC -- building various static libs, or building an application + * that links to the static libs. * Thus, * a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and * this bit of #ifdefs will define the 'correct' config variables based on @@ -80,6 +106,9 @@ # undef PNG_STATIC # endif # else +# if defined(ALL_STATIC) +# define PNG_STATIC +# endif # if defined(PNG_STATIC) # if defined(PNG_USE_DLL) # undef PNG_USE_DLL @@ -119,12 +148,12 @@ */ #if defined(_WIN32_WCE) -#include -/* Console I/O functions are not supported on WindowsCE */ -#define PNG_NO_CONSOLE_IO -#ifdef PNG_DEBUG -# undef PNG_DEBUG -#endif +# include + /* Console I/O functions are not supported on WindowsCE */ +# define PNG_NO_CONSOLE_IO +# ifdef PNG_DEBUG +# undef PNG_DEBUG +# endif #endif #ifdef PNG_BUILD_DLL @@ -161,13 +190,13 @@ #ifndef PNGARG #ifdef OF /* zlib prototype munger */ -#define PNGARG(arglist) OF(arglist) +# define PNGARG(arglist) OF(arglist) #else #ifdef _NO_PROTO -#define PNGARG(arglist) () +# define PNGARG(arglist) () #else -#define PNGARG(arglist) arglist +# define PNGARG(arglist) arglist #endif /* _NO_PROTO */ #endif /* OF */ @@ -179,15 +208,15 @@ * on non-Mac platforms. */ #ifndef MACOS -#if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ - defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) -#define MACOS -#endif +# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ + defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) +# define MACOS +# endif #endif /* enough people need this for various reasons to include it here */ #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE) -#include +# include #endif #ifndef PNG_SETJMP_NOT_SUPPORTED @@ -208,10 +237,10 @@ __png.h__ already includes setjmp.h; __dont__ include it again.; # endif -#endif /* __linux__ */ +# endif /* __linux__ */ -/* include setjmp.h for error handling */ -#include + /* include setjmp.h for error handling */ +# include # ifdef __linux__ # ifdef PNG_SAVE_BSD_SOURCE @@ -221,20 +250,15 @@ # endif /* __linux__ */ #endif /* PNG_SETJMP_SUPPORTED */ -#if defined(_AIX) && defined(__xlC__) -/* This prevents "AIX/xlC" from generating an "index(s,c)" macro in strings.h - * that conflicts with libpng's png_color_16.index */ -#undef __STR__ -#endif - #ifdef BSD -#include +# include #else -#include +# include #endif /* Other defines for things like memory and the like can go here. */ #ifdef PNG_INTERNAL + #include /* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which @@ -251,28 +275,28 @@ */ #if defined(PNG_FLOATING_POINT_SUPPORTED) -#if defined(MACOS) -/* We need to check that hasn't already been included earlier - * as it seems it doesn't agree with , yet we should really use - * if possible. - */ -#if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) -#include -#endif -#else -#include -#endif -#if defined(_AMIGA) && defined(__SASC) && defined(_M68881) -/* Amiga SAS/C: We must include builtin FPU functions when compiling using - * MATH=68881 - */ -#include -#endif +# if defined(MACOS) + /* We need to check that hasn't already been included earlier + * as it seems it doesn't agree with , yet we should really use + * if possible. + */ +# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) +# include +# endif +# else +# include +# endif +# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) + /* Amiga SAS/C: We must include builtin FPU functions when compiling using + * MATH=68881 + */ +# include +# endif #endif /* Codewarrior on NT has linking problems without this. */ #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__) -#define PNG_ALWAYS_EXTERN +# define PNG_ALWAYS_EXTERN #endif /* For some reason, Borland C++ defines memcmp, etc. in mem.h, not @@ -280,12 +304,12 @@ * "feature"? */ #ifdef __TURBOC__ -#include -#include "alloc.h" +# include +# include "alloc.h" #endif #ifdef _MSC_VER -#include +# include #endif /* This controls how fine the dithering gets. As this allocates @@ -293,13 +317,13 @@ * with dithering quality can decrease some or all of these. */ #ifndef PNG_DITHER_RED_BITS -#define PNG_DITHER_RED_BITS 5 +# define PNG_DITHER_RED_BITS 5 #endif #ifndef PNG_DITHER_GREEN_BITS -#define PNG_DITHER_GREEN_BITS 5 +# define PNG_DITHER_GREEN_BITS 5 #endif #ifndef PNG_DITHER_BLUE_BITS -#define PNG_DITHER_BLUE_BITS 5 +# define PNG_DITHER_BLUE_BITS 5 #endif /* This controls how fine the gamma correction becomes when you @@ -310,14 +334,14 @@ */ #ifndef PNG_MAX_GAMMA_8 -#define PNG_MAX_GAMMA_8 11 +# define PNG_MAX_GAMMA_8 11 #endif /* This controls how much a difference in gamma we can tolerate before * we actually start doing gamma conversion. */ #ifndef PNG_GAMMA_THRESHOLD -#define PNG_GAMMA_THRESHOLD 0.05 +# define PNG_GAMMA_THRESHOLD 0.05 #endif #endif /* PNG_INTERNAL */ @@ -363,7 +387,7 @@ * iTXt is supported. It is turned off by default, to support old apps * that malloc the png_text structure instead of calling png_set_text() * and letting libpng malloc it. It will be turned on by default in - * libpng-2.0.0. + * libpng-1.3.0. */ #ifndef PNG_iTXt_SUPPORTED @@ -382,163 +406,169 @@ */ #ifdef PNG_LEGACY_SUPPORTED -#define PNG_NO_FREE_ME -#define PNG_NO_READ_UNKNOWN_CHUNKS -#define PNG_NO_WRITE_UNKNOWN_CHUNKS -#define PNG_NO_READ_USER_CHUNKS -#define PNG_NO_READ_iCCP -#define PNG_NO_WRITE_iCCP -#define PNG_NO_READ_iTXt -#define PNG_NO_WRITE_iTXt -#define PNG_NO_READ_sCAL -#define PNG_NO_WRITE_sCAL -#define PNG_NO_READ_sPLT -#define PNG_NO_WRITE_sPLT -#define PNG_NO_INFO_IMAGE -#define PNG_NO_READ_RGB_TO_GRAY -#define PNG_NO_READ_USER_TRANSFORM -#define PNG_NO_WRITE_USER_TRANSFORM -#define PNG_NO_USER_MEM -#define PNG_NO_READ_EMPTY_PLTE -#define PNG_NO_MNG_FEATURES -#define PNG_NO_FIXED_POINT_SUPPORTED +# define PNG_NO_FREE_ME +# define PNG_NO_READ_UNKNOWN_CHUNKS +# define PNG_NO_WRITE_UNKNOWN_CHUNKS +# define PNG_NO_READ_USER_CHUNKS +# define PNG_NO_READ_iCCP +# define PNG_NO_WRITE_iCCP +# define PNG_NO_READ_iTXt +# define PNG_NO_WRITE_iTXt +# define PNG_NO_READ_sCAL +# define PNG_NO_WRITE_sCAL +# define PNG_NO_READ_sPLT +# define PNG_NO_WRITE_sPLT +# define PNG_NO_INFO_IMAGE +# define PNG_NO_READ_RGB_TO_GRAY +# define PNG_NO_READ_USER_TRANSFORM +# define PNG_NO_WRITE_USER_TRANSFORM +# define PNG_NO_USER_MEM +# define PNG_NO_READ_EMPTY_PLTE +# define PNG_NO_MNG_FEATURES +# define PNG_NO_FIXED_POINT_SUPPORTED #endif /* Ignore attempt to turn off both floating and fixed point support */ #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \ - !defined(PNG_NO_FIXED_POINT_SUPPORTED) -#define PNG_FIXED_POINT_SUPPORTED + !defined(PNG_NO_FIXED_POINT_SUPPORTED) +# define PNG_FIXED_POINT_SUPPORTED #endif #ifndef PNG_NO_FREE_ME -#define PNG_FREE_ME_SUPPORTED +# define PNG_FREE_ME_SUPPORTED #endif +#if defined(PNG_READ_SUPPORTED) + #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \ - !defined(PNG_NO_READ_TRANSFORMS) -#define PNG_READ_TRANSFORMS_SUPPORTED -#endif -#if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ - !defined(PNG_NO_WRITE_TRANSFORMS) -#define PNG_WRITE_TRANSFORMS_SUPPORTED + !defined(PNG_NO_READ_TRANSFORMS) +# define PNG_READ_TRANSFORMS_SUPPORTED #endif #ifdef PNG_READ_TRANSFORMS_SUPPORTED -#ifndef PNG_NO_READ_EXPAND -#define PNG_READ_EXPAND_SUPPORTED -#endif -#ifndef PNG_NO_READ_SHIFT -#define PNG_READ_SHIFT_SUPPORTED -#endif -#ifndef PNG_NO_READ_PACK -#define PNG_READ_PACK_SUPPORTED -#endif -#ifndef PNG_NO_READ_BGR -#define PNG_READ_BGR_SUPPORTED -#endif -#ifndef PNG_NO_READ_SWAP -#define PNG_READ_SWAP_SUPPORTED -#endif -#ifndef PNG_NO_READ_PACKSWAP -#define PNG_READ_PACKSWAP_SUPPORTED -#endif -#ifndef PNG_NO_READ_INVERT -#define PNG_READ_INVERT_SUPPORTED -#endif -#ifndef PNG_NO_READ_DITHER -#define PNG_READ_DITHER_SUPPORTED -#endif -#ifndef PNG_NO_READ_BACKGROUND -#define PNG_READ_BACKGROUND_SUPPORTED -#endif -#ifndef PNG_NO_READ_16_TO_8 -#define PNG_READ_16_TO_8_SUPPORTED -#endif -#ifndef PNG_NO_READ_FILLER -#define PNG_READ_FILLER_SUPPORTED -#endif -#ifndef PNG_NO_READ_GAMMA -#define PNG_READ_GAMMA_SUPPORTED -#endif -#ifndef PNG_NO_READ_GRAY_TO_RGB -#define PNG_READ_GRAY_TO_RGB_SUPPORTED -#endif -#ifndef PNG_NO_READ_SWAP_ALPHA -#define PNG_READ_SWAP_ALPHA_SUPPORTED -#endif -#ifndef PNG_NO_READ_INVERT_ALPHA -#define PNG_READ_INVERT_ALPHA_SUPPORTED -#endif -#ifndef PNG_NO_READ_STRIP_ALPHA -#define PNG_READ_STRIP_ALPHA_SUPPORTED -#endif -#ifndef PNG_NO_READ_USER_TRANSFORM -#define PNG_READ_USER_TRANSFORM_SUPPORTED -#endif -#ifndef PNG_NO_READ_RGB_TO_GRAY -#define PNG_READ_RGB_TO_GRAY_SUPPORTED -#endif +# ifndef PNG_NO_READ_EXPAND +# define PNG_READ_EXPAND_SUPPORTED +# endif +# ifndef PNG_NO_READ_SHIFT +# define PNG_READ_SHIFT_SUPPORTED +# endif +# ifndef PNG_NO_READ_PACK +# define PNG_READ_PACK_SUPPORTED +# endif +# ifndef PNG_NO_READ_BGR +# define PNG_READ_BGR_SUPPORTED +# endif +# ifndef PNG_NO_READ_SWAP +# define PNG_READ_SWAP_SUPPORTED +# endif +# ifndef PNG_NO_READ_PACKSWAP +# define PNG_READ_PACKSWAP_SUPPORTED +# endif +# ifndef PNG_NO_READ_INVERT +# define PNG_READ_INVERT_SUPPORTED +# endif +# ifndef PNG_NO_READ_DITHER +# define PNG_READ_DITHER_SUPPORTED +# endif +# ifndef PNG_NO_READ_BACKGROUND +# define PNG_READ_BACKGROUND_SUPPORTED +# endif +# ifndef PNG_NO_READ_16_TO_8 +# define PNG_READ_16_TO_8_SUPPORTED +# endif +# ifndef PNG_NO_READ_FILLER +# define PNG_READ_FILLER_SUPPORTED +# endif +# ifndef PNG_NO_READ_GAMMA +# define PNG_READ_GAMMA_SUPPORTED +# endif +# ifndef PNG_NO_READ_GRAY_TO_RGB +# define PNG_READ_GRAY_TO_RGB_SUPPORTED +# endif +# ifndef PNG_NO_READ_SWAP_ALPHA +# define PNG_READ_SWAP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_INVERT_ALPHA +# define PNG_READ_INVERT_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_STRIP_ALPHA +# define PNG_READ_STRIP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_USER_TRANSFORM +# define PNG_READ_USER_TRANSFORM_SUPPORTED +# endif +# ifndef PNG_NO_READ_RGB_TO_GRAY +# define PNG_READ_RGB_TO_GRAY_SUPPORTED +# endif #endif /* PNG_READ_TRANSFORMS_SUPPORTED */ #if !defined(PNG_NO_PROGRESSIVE_READ) && \ - !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */ -#define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ + !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */ +# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ #endif /* about interlacing capability! You'll */ /* still have interlacing unless you change the following line: */ + #define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */ #ifndef PNG_NO_READ_COMPOSITE_NODIV -#ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */ -#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel and SGI */ -#endif +# ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */ +# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */ +# endif #endif -#ifndef PNG_NO_MNG_FEATURES -#define PNG_MNG_FEATURES_SUPPORTED /* Useful for MNG applications */ -#endif -/* Deprecated, will be removed */ +/* Deprecated, will be removed from version 2.0.0. + Use PNG_MNG_FEATURES_SUPPORTED instead. */ #ifndef PNG_NO_READ_EMPTY_PLTE -#define PNG_READ_EMPTY_PLTE_SUPPORTED +# define PNG_READ_EMPTY_PLTE_SUPPORTED +#endif + +#endif /* PNG_READ_SUPPORTED */ + +#if defined(PNG_WRITE_SUPPORTED) + +# if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ + !defined(PNG_NO_WRITE_TRANSFORMS) +# define PNG_WRITE_TRANSFORMS_SUPPORTED #endif #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED -#ifndef PNG_NO_WRITE_SHIFT -#define PNG_WRITE_SHIFT_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_PACK -#define PNG_WRITE_PACK_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_BGR -#define PNG_WRITE_BGR_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_SWAP -#define PNG_WRITE_SWAP_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_PACKSWAP -#define PNG_WRITE_PACKSWAP_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_INVERT -#define PNG_WRITE_INVERT_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_FILLER -#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */ -#endif -#ifndef PNG_NO_WRITE_SWAP_ALPHA -#define PNG_WRITE_SWAP_ALPHA_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_INVERT_ALPHA -#define PNG_WRITE_INVERT_ALPHA_SUPPORTED -#endif -#ifndef PNG_NO_WRITE_USER_TRANSFORM -#define PNG_WRITE_USER_TRANSFORM_SUPPORTED -#endif +# ifndef PNG_NO_WRITE_SHIFT +# define PNG_WRITE_SHIFT_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_PACK +# define PNG_WRITE_PACK_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_BGR +# define PNG_WRITE_BGR_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_SWAP +# define PNG_WRITE_SWAP_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_PACKSWAP +# define PNG_WRITE_PACKSWAP_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_INVERT +# define PNG_WRITE_INVERT_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_FILLER +# define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */ +# endif +# ifndef PNG_NO_WRITE_SWAP_ALPHA +# define PNG_WRITE_SWAP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_INVERT_ALPHA +# define PNG_WRITE_INVERT_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_USER_TRANSFORM +# define PNG_WRITE_USER_TRANSFORM_SUPPORTED +# endif #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ -defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) -#ifndef PNG_NO_USER_TRANSFORM_PTR -#define PNG_USER_TRANSFORM_PTR_SUPPORTED -#endif + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +# ifndef PNG_NO_USER_TRANSFORM_PTR +# define PNG_USER_TRANSFORM_PTR_SUPPORTED +# endif #endif #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant @@ -547,20 +577,22 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \ defined(PNG_FLOATING_POINT_SUPPORTED) -#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +# define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED #endif #ifndef PNG_NO_WRITE_FLUSH -#define PNG_WRITE_FLUSH_SUPPORTED +# define PNG_WRITE_FLUSH_SUPPORTED #endif /* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */ #ifndef PNG_NO_WRITE_EMPTY_PLTE -#define PNG_WRITE_EMPTY_PLTE_SUPPORTED +# define PNG_WRITE_EMPTY_PLTE_SUPPORTED #endif +#endif /* PNG_WRITE_SUPPORTED */ + #ifndef PNG_NO_STDIO -#define PNG_TIME_RFC1123_SUPPORTED +# define PNG_TIME_RFC1123_SUPPORTED #endif /* This adds extra functions in pngget.c for accessing data from the @@ -580,31 +612,47 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) * png_get_y_offset_microns() */ #ifndef PNG_NO_EASY_ACCESS -#define PNG_EASY_ACCESS_SUPPORTED +# define PNG_EASY_ACCESS_SUPPORTED #endif -#if defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD) && \ - !defined(PNG_NO_ASSEMBLER_CODE) -#define PNG_ASSEMBLER_CODE_SUPPORTED +/* PNG_ASSEMBLER_CODE will be 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) +# if defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD) +# 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 #endif /* These are currently experimental features, define them if you want */ /* very little testing */ /* -#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +#ifdef PNG_READ_SUPPORTED +# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +# define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +# endif +#endif #ifndef PNG_NO_USER_MEM -#define PNG_USER_MEM_SUPPORTED +# define PNG_USER_MEM_SUPPORTED #endif #ifndef PNG_NO_ZALLOC_ZERO -#define PNG_ZALLOC_ZERO +# define PNG_ZALLOC_ZERO #endif */ /* This is only for PowerPC big-endian and 680x0 systems */ /* some testing */ /* -#define PNG_READ_BIG_ENDIAN_SUPPORTED +#ifdef PNG_READ_SUPPORTED +# ifndef PNG_PNG_READ_BIG_ENDIAN_SUPPORTED +# define PNG_READ_BIG_ENDIAN_SUPPORTED +# endif +#endif */ /* Buggy compilers (e.g., gcc 2.7.2.2) need this */ @@ -624,13 +672,16 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) * a bit smaller. */ -#if !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ +#if defined(PNG_READ_SUPPORTED) && \ + !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ !defined(PNG_NO_READ_ANCILLARY_CHUNKS) -#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED +# define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED #endif -#if !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ + +#if defined(PNG_WRITE_SUPPORTED) && \ + !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS) -#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED +# define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED #endif #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED @@ -732,13 +783,15 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */ #endif /* optional PLTE chunk in RGB and RGBA images */ #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \ - defined(PNG_READ_zTXt_SUPPORTED) + defined(PNG_READ_zTXt_SUPPORTED) # define PNG_READ_TEXT_SUPPORTED # define PNG_TEXT_SUPPORTED #endif + #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */ #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED + #ifdef PNG_NO_WRITE_TEXT # define PNG_NO_WRITE_iTXt # define PNG_NO_WRITE_tEXt @@ -858,12 +911,13 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) # endif #endif #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \ - defined(PNG_WRITE_zTXt_SUPPORTED) + defined(PNG_WRITE_zTXt_SUPPORTED) # define PNG_WRITE_TEXT_SUPPORTED # ifndef PNG_TEXT_SUPPORTED # define PNG_TEXT_SUPPORTED # endif #endif + #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */ /* Turn this off to disable png_read_png() and @@ -913,28 +967,26 @@ typedef size_t png_size_t; /* Separate compiler dependencies (problem here is that zlib.h always defines FAR. (SJT) */ #ifdef __BORLANDC__ -#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) -#define LDATA 1 -#else -#define LDATA 0 -#endif - -#if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) -#define PNG_MAX_MALLOC_64K -#if (LDATA != 1) -#ifndef FAR -#define FAR __far -#endif -#define USE_FAR_KEYWORD -#endif /* LDATA != 1 */ - -/* Possibly useful for moving data out of default segment. - * Uncomment it if you want. Could also define FARDATA as - * const if your compiler supports it. (SJT) -# define FARDATA FAR - */ -#endif /* __WIN32__, __FLAT__, __CYGWIN__ */ - +# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) +# define LDATA 1 +# else +# define LDATA 0 +# endif + /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ +# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) +# define PNG_MAX_MALLOC_64K +# if (LDATA != 1) +# ifndef FAR +# define FAR __far +# endif +# define USE_FAR_KEYWORD +# endif /* LDATA != 1 */ + /* Possibly useful for moving data out of default segment. + * Uncomment it if you want. Could also define FARDATA as + * const if your compiler supports it. (SJT) +# define FARDATA FAR + */ +# endif /* __WIN32__, __FLAT__, __CYGWIN__ */ #endif /* __BORLANDC__ */ @@ -946,20 +998,20 @@ typedef size_t png_size_t; /* MSC Medium model */ #if defined(FAR) # if defined(M_I86MM) -# define USE_FAR_KEYWORD -# define FARDATA FAR -# include +# define USE_FAR_KEYWORD +# define FARDATA FAR +# include # endif #endif /* SJT: default case */ #ifndef FAR -# define FAR +# define FAR #endif /* At this point FAR is always defined */ #ifndef FARDATA -#define FARDATA +# define FARDATA #endif /* Typedef for floating-point numbers that are converted @@ -976,11 +1028,15 @@ typedef png_int_16 FAR * png_int_16p; typedef PNG_CONST char FAR * png_const_charp; typedef char FAR * png_charp; typedef png_fixed_point FAR * png_fixed_point_p; + +#ifndef PNG_NO_STDIO #if defined(_WIN32_WCE) typedef HANDLE png_FILE_p; #else typedef FILE * png_FILE_p; #endif +#endif + #ifdef PNG_FLOATING_POINT_SUPPORTED typedef double FAR * png_doublep; #endif @@ -998,7 +1054,7 @@ typedef png_fixed_point FAR * FAR * png_fixed_point_pp; typedef double FAR * FAR * png_doublepp; #endif -/* Pointers to pointers to pointers; i.e. pointer to array */ +/* Pointers to pointers to pointers; i.e., pointer to array */ typedef char FAR * FAR * FAR * png_charppp; /* libpng typedefs for types in zlib. If zlib changes @@ -1014,7 +1070,7 @@ typedef z_stream FAR * png_zstreamp; * LIBPNG DLL. * * Define PNG_USE_DLL if you want to *link* to the Windows LIBPNG DLL. - * It is equivalent to Microsoft predefined macro _DLL which is + * It is equivalent to Microsoft predefined macro _DLL that is * automatically defined when you compile using the share * version of the CRT (C Run-Time library) * @@ -1066,8 +1122,8 @@ typedef z_stream FAR * png_zstreamp; # endif #endif -#ifndef PNGAPI +#ifndef PNGAPI #if defined(__MINGW32__) || defined(__CYGWIN__) && !defined(PNG_MODULEDEF) # ifndef PNG_NO_MODULEDEF @@ -1084,7 +1140,7 @@ typedef z_stream FAR * png_zstreamp; defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \ ) && !defined(__CYGWIN__)) -# ifdef __GNUC__ +# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) # define PNGAPI __cdecl # else # define PNGAPI _cdecl @@ -1131,10 +1187,15 @@ typedef z_stream FAR * png_zstreamp; # endif # define PNGAPI __cdecl # else -# if 0 /* ... other platforms, with other meanings */ +# if (defined(__IBMC__) || defined(IBMCPP__)) && defined(__OS2__) +# define PNGAPI _System +# define PNG_IMPEXP # else -# define PNGAPI -# define PNG_IMPEXP +# if 0 /* ... other platforms, with other meanings */ +# else +# define PNGAPI +# define PNG_IMPEXP +# endif # endif # endif #endif @@ -1152,9 +1213,9 @@ typedef z_stream FAR * png_zstreamp; #endif #ifdef PNG_USE_GLOBAL_ARRAYS -#ifndef PNG_EXPORT_VAR -# define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type -#endif +# ifndef PNG_EXPORT_VAR +# define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type +# endif #endif /* User may want to use these so they are not in PNG_INTERNAL. Any library @@ -1162,35 +1223,35 @@ typedef z_stream FAR * png_zstreamp; */ #ifndef PNG_ABORT -# define PNG_ABORT() abort() +# define PNG_ABORT() abort() #endif #ifdef PNG_SETJMP_SUPPORTED -# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) #else -# define png_jmpbuf(png_ptr) \ - (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) +# define png_jmpbuf(png_ptr) \ + (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) #endif #if defined(USE_FAR_KEYWORD) /* memory model independent fns */ /* use this to make far-to-near assignments */ -# define CHECK 1 -# define NOCHECK 0 -# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) -# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) -# define png_strcpy _fstrcpy -# define png_strlen _fstrlen -# define png_memcmp _fmemcmp /* SJT: added */ -# define png_memcpy _fmemcpy -# define png_memset _fmemset +# define CHECK 1 +# define NOCHECK 0 +# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) +# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) +# define png_strcpy _fstrcpy +# define png_strlen _fstrlen +# define png_memcmp _fmemcmp /* SJT: added */ +# define png_memcpy _fmemcpy +# define png_memset _fmemset #else /* use the usual functions */ -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strcpy strcpy -# define png_strlen strlen -# define png_memcmp memcmp /* SJT: added */ -# define png_memcpy memcpy -# define png_memset memset +# define CVT_PTR(ptr) (ptr) +# define CVT_PTR_NOCHECK(ptr) (ptr) +# define png_strcpy strcpy +# define png_strlen strlen +# define png_memcmp memcmp /* SJT: added */ +# define png_memcpy memcpy +# define png_memset memset #endif /* End of memory model independent support */ @@ -1198,9 +1259,50 @@ typedef z_stream FAR * png_zstreamp; * contradictory. */ #if (PNG_ZBUF_SIZE > 65536) && defined(PNG_MAX_MALLOC_64K) -#undef PNG_ZBUF_SIZE -#define PNG_ZBUF_SIZE 65536 +# undef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 65536 #endif +#ifdef PNG_READ_SUPPORTED +/* Prior to libpng-1.0.9, this block was in pngasmrd.h */ +#if defined(PNG_INTERNAL) + +/* These are the default thresholds before the MMX code kicks in; if either + * rowbytes or bitdepth is below the threshold, plain C code is used. These + * can be overridden at runtime via the png_set_mmx_thresholds() call in + * libpng 1.2.0 and later. The values below were chosen by Intel. + */ + +#ifndef PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT +# define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT 128 /* >= */ +#endif +#ifndef PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT +# define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT 9 /* >= */ +#endif + +/* Set this in the makefile for VC++ on Pentium, not here. */ +/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c . + * MMX will be detected at run time and used if present. + */ +#ifdef PNG_USE_PNGVCRD +# define PNG_HAVE_ASSEMBLER_COMBINE_ROW +# define PNG_HAVE_ASSEMBLER_READ_INTERLACE +# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW +#endif + +/* Set this in the makefile for gcc/as on Pentium, not here. */ +/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c . + * MMX will be detected at run time and used if present. + */ +#ifdef PNG_USE_PNGGCCRD +# define PNG_HAVE_ASSEMBLER_COMBINE_ROW +# define PNG_HAVE_ASSEMBLER_READ_INTERLACE +# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW +#endif +/* - see pnggccrd.c for info about what is currently enabled */ + +#endif /* PNG_INTERNAL */ +#endif /* PNG_READ_SUPPORTED */ + #endif /* PNGCONF_H */ diff --git a/pngcrush.c b/pngcrush.c index 1f38013c6..5a7aea3a0 100644 --- a/pngcrush.c +++ b/pngcrush.c @@ -1,5 +1,5 @@ /* pngcrush.c - recompresses png files - * Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) + * Copyright (C) 1998-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu) * * The most recent version of pngcrush can be found at * http://pmt.sourceforge.net/pngcrush/ @@ -11,7 +11,9 @@ * it turns out to be the best. * * Optionally, it can remove unwanted chunks or add gAMA, sRGB, bKGD, - * tEXt/zTXt, and tRNS chunks. + * tEXt/zTXt, and tRNS chunks. It will remove some chunks such as gAMA, + * cHRM, pHYs, and oFFs when their data fields contain all zero, which is a + * mistake. * * Uses libpng and zlib. This program was based upon libpng's pngtest.c. * @@ -23,11 +25,11 @@ * */ -#define PNGCRUSH_VERSION "1.5.3" +#define PNGCRUSH_VERSION "1.5.4" /* -*/ #define PNGCRUSH_COUNT_COLORS +*/ /* * COPYRIGHT NOTICE, DISCLAIMER, AND LICENSE: @@ -35,7 +37,7 @@ * If you have modified this source, you may insert additional notices * immediately after this sentence. * - * Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) + * Copyright (C) 1998-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu) * * The pngcrush computer program is supplied "AS IS". The Author disclaims all * warranties, expressed or implied, including, without limitation, the @@ -64,6 +66,23 @@ */ /* Change log: + * + * Version 1.5.4 (built with libpng-1.0.11) + * + * Added 262 to the length of uncompressed data when calculating + * required_window_size, to account for zlib/deflate implementation. + * + * Added "-bit_depth n" to the help screen. + * + * Call png_set_packing() when increasing bit_depth to 2 or 4. + * + * Added warning about not overwriting an existing tRNS chunk. + * + * Reduced the memory usage + * + * Write 500K IDAT chunks even when system libpng is being used. + * + * Ignore all-zero cHRM chunks, with a warning. * * Version 1.5.3 (built with libpng-1.0.9beta5) * @@ -310,6 +329,10 @@ */ /* To do: + * + * Reset CINFO to reflect decoder's required window size (instead of + * libz-1.1.3 encoder's required window size, which is 262 bytes larger). + * See discussion about zlib in png-list archives for April 2001. * * Add a "pcRu" ancillary chunk that keeps track of the best method, * methods already tried, and whether "loco crushing" was effective. @@ -420,6 +443,7 @@ main() #define DIREX_MODE 3 #define FOPEN(file, how) fopen(file, how) #define FCLOSE(file) {fclose(file); file=NULL;--number_of_open_files;}; +#define P0 if(first_trial && verbose > 0)printf #define P1 if(verbose > 1)printf #define P2 if(verbose > 2)printf @@ -627,9 +651,9 @@ static FILE *fpin, *fpout; png_uint_32 measure_idats(FILE *fpin); #ifdef PNGCRUSH_LOCO static int do_loco=0; -#endif static int input_format=0; /* 0: PNG 1: MNG */ static int output_format=0; +#endif static int do_color_count; static int reduction_ok=0; #ifdef PNGCRUSH_COUNT_COLORS @@ -645,7 +669,7 @@ static int filter_type, zlib_level; static png_bytep png_row_filters=NULL; static TIME_T t_start, t_stop, t_decode, t_encode, t_misc; -static png_uint_32 max_idat_size = PNG_ZBUF_SIZE; +static png_uint_32 max_idat_size = 524288L; /* increases the IDAT size */ static png_uint_32 crushed_idat_size = 0x3ffffffL; static int already_crushed = 0; int ia; @@ -1190,7 +1214,9 @@ main(int argc, char *argv[]) extension= argv[names++]; } else if(!strncmp(argv[i],"-force",6)) + { global_things_have_changed=1; + } else if(!strncmp(argv[i],"-fix",4)) fix++; else if(!strncmp(argv[i],"-f",2)) @@ -1230,10 +1256,15 @@ main(int argc, char *argv[]) brute_force_filter++; } } -#ifdef PNGCRUSH_LOCO else if(!strncmp(argv[i],"-loco",5)) + { +#ifdef PNGCRUSH_LOCO do_loco=1; +#else + printf( + "Cannot do -loco because libpng was compiled without MNG features"); #endif + } else if(!strncmp(argv[i],"-l",2)) { int lev, strat, filt; @@ -1346,9 +1377,8 @@ main(int argc, char *argv[]) names++; BUMP_I; max_idat_size = (png_uint_32)atoi(argv[i]); -#if 0 - if (max_idat_size > PNG_ZBUF_SIZE) max_idat_size=PNG_ZBUF_SIZE; -#endif + if (max_idat_size == 0 || max_idat_size > PNG_MAX_UINT) + max_idat_size=PNG_ZBUF_SIZE; } else if(!strncmp(argv[i],"-m",2)) { @@ -1634,21 +1664,24 @@ main(int argc, char *argv[]) /* If you have modified this source, you may insert additional notices * immediately after this sentence. */ fprintf(STDERR, - "\n | %s %s, Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson\n", + "\n | %s %s, Copyright (C) 1998-2001 Glenn Randers-Pehrson\n", progname, PNGCRUSH_VERSION); - fprintf(STDERR, " | This is a free, open-source program. Permission is\n"); - fprintf(STDERR, " | irrevocably granted to everyone to use this version\n"); - fprintf(STDERR, " | of pngcrush without payment of any fee.\n"); + fprintf(STDERR, + " | This is a free, open-source program. Permission is irrevocably\n"); + fprintf(STDERR, + " | granted to everyone to use this version of pngcrush without\n"); + fprintf(STDERR, + " | payment of any fee.\n"); fprintf(STDERR, - " | This program was built with libpng version %s,\n", + " | This program was built with libpng version %s, and is\n", PNG_LIBPNG_VER_STRING); #if PNG_LIBPNG_VER > 10001 fprintf(STDERR, - " | and is running with %s", png_get_header_version(NULL)); + " | running with %s", png_get_header_version(NULL)); #endif #if PNG_LIBPNG_VER > 96 fprintf(STDERR, - " | Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson,\n"); + " | Copyright (C) 1998-2001 Glenn Randers-Pehrson,\n"); #endif #if PNG_LIBPNG_VER > 89 fprintf(STDERR, @@ -1740,6 +1773,13 @@ main(int argc, char *argv[]) fprintf(STDERR, " or the \"-force\" option is present.\n\n"); } + + fprintf(STDERR, + " -bit_depth depth (bit_depth to use in output file)\n"); + if(verbose > 1) + fprintf(STDERR, + "\n Default output depth is same as input depth.\n\n"); + fprintf(STDERR, " -brute (Use brute-force, try 114 different methods [11-124])\n"); if(verbose > 1) @@ -1884,6 +1924,25 @@ main(int argc, char *argv[]) fprintf(STDERR, " argument.\n\n"); } +#ifdef PNGCRUSH_LOCO + fprintf(STDERR, + " -loco (\"loco crush\" truecolor PNGs)\n"); + if(verbose > 1) + { + fprintf(STDERR, + "\n Make the file more compressible by performing a\n"); + fprintf(STDERR, + " lossless reversible color transformation.\n"); + fprintf(STDERR, + " The resulting file is a MNG, not a PNG, and should\n"); + fprintf(STDERR, + " be given the \".mng\" file extension. The\n"); + fprintf(STDERR, + " \"loco\" option has no effect on grayscale or\n"); + fprintf(STDERR, + " indexed-color PNG files.\n\n"); + } +#endif fprintf(STDERR, " -m method [0 through %d]\n",MAX_METHODS); if(verbose > 1) @@ -1908,8 +1967,6 @@ main(int argc, char *argv[]) fprintf(STDERR, " -max maximum_IDAT_size [default %d]\n",PNG_ZBUF_SIZE); - if(verbose > 1) - fprintf(STDERR,"\n"); #if 0 fprintf(STDERR, " -ni (no interlace)\n"); @@ -2015,25 +2072,6 @@ main(int argc, char *argv[]) if(verbose > 1) fprintf(STDERR, "\n Value of 'rendering intent' for sRGB chunk.\n\n"); -#ifdef PNGCRUSH_LOCO - fprintf(STDERR, - " -loco (\"loco crush\" truecolor PNGs)\n"); - if(verbose > 1) - { - fprintf(STDERR, - "\n Make the file more compressible by performing a\n"); - fprintf(STDERR, - " lossless reversible color transformation.\n"); - fprintf(STDERR, - " The resulting file is a MNG, not a PNG, and should\n"); - fprintf(STDERR, - " be given the \".mng\" file extension. The\n"); - fprintf(STDERR, - " \"loco\" option has no effect on grayscale or\n"); - fprintf(STDERR, - " indexed-color PNG files.\n\n"); - } -#endif fprintf(STDERR, " -text b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\"\n"); if(verbose > 1) @@ -2132,7 +2170,7 @@ main(int argc, char *argv[]) /* If you have modified this source, you may insert additional notices * immediately after this sentence. */ fprintf (STDERR, - "\nCopyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu)\n\n"); + "\nCopyright (C) 1998-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu)\n\n"); fprintf(STDERR, "\nDISCLAIMER: The pngcrush computer program is supplied \"AS IS\".\n"); fprintf(STDERR, @@ -2184,12 +2222,15 @@ main(int argc, char *argv[]) for (ia=0; ia<256; ia++) trns_array[ia]=255; + P2 (" gthc=%d\n",global_things_have_changed); + for(;;) /* loop on input files */ { first_trial = 1; things_have_changed=global_things_have_changed; + P2 (" thc=%d\n",things_have_changed); if(png_row_filters != NULL) { @@ -2440,7 +2481,7 @@ main(int argc, char *argv[]) } number_of_open_files++; - P2("copying input to output..."); + P2("copying input to output... tc=%d ...",things_have_changed); #ifdef __riscos /* (brokenly) assume that they're different */ @@ -2635,24 +2676,6 @@ main(int argc, char *argv[]) png_set_crc_action(read_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE); #endif -#if (PNG_LIBPNG_VER >= 10000) - /* reinitialize zbuf - compression buffer */ - - if(png_get_compression_buffer_size(read_ptr) < max_idat_size) - { - P2("reinitializing read zbuf.\n"); - png_set_compression_buffer_size(read_ptr, max_idat_size); - } - if(nosave == 0) - { - if(png_get_compression_buffer_size(write_ptr) != max_idat_size) - { - P2("reinitializing write zbuf.\n"); - png_set_compression_buffer_size(write_ptr, max_idat_size); - } - } -#endif - #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS, (png_bytep)NULL, 0); @@ -2809,14 +2832,14 @@ main(int argc, char *argv[]) png_read_info(read_ptr, read_info_ptr); #if (PNG_LIBPNG_VER > 90) - png_debug(0, "Transferring info struct\n"); { int interlace_method, compression_method, filter_method; + png_debug(0, "Transferring info struct\n"); + if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, &color_type, &interlace_method, &compression_method, &filter_method)) { - int compression_window; int need_expand = 0; int output_interlace_method=interlace_method; input_color_type=color_type; @@ -2839,6 +2862,8 @@ main(int argc, char *argv[]) #ifndef PNG_WRITE_PACK_SUPPORTED if(output_bit_depth == 0) +#else + if(force_output_bit_depth == 0) #endif { output_bit_depth=input_bit_depth; @@ -2927,45 +2952,6 @@ main(int argc, char *argv[]) png_set_expand(read_ptr); #endif - if(nosave == 0) - { - int required_window; - int channels=0; - - png_set_compression_strategy(write_ptr, z_strategy); - png_set_compression_mem_level(write_ptr, compression_mem_level); - - if (output_color_type == 0)channels=1; - if (output_color_type == 2)channels=3; - if (output_color_type == 3)channels=1; - if (output_color_type == 4)channels=2; - if (output_color_type == 6)channels=4; - - required_window=(int)(height*((width*channels*bit_depth+15)>>3)); - -#ifdef WBITS_8_OK - if (required_window <= 256)compression_window = 8; - else if(required_window <= 512)compression_window = 9; -#else - if (required_window <= 512)compression_window = 9; -#endif - else if(required_window <= 1024)compression_window = 10; - else if(required_window <= 2048)compression_window = 11; - else if(required_window <= 4096)compression_window = 12; - else if(required_window <= 8192)compression_window = 13; - else if(required_window <= 16384)compression_window = 14; - else compression_window = 15; - if(compression_window > default_compression_window || - force_compression_window) - compression_window = default_compression_window; - - if(verbose > 1 && first_trial && (compression_window != 15 || - force_compression_window)) - fprintf(STDERR, " Compression window for output= %d\n", - 1 << compression_window); - - png_set_compression_window_bits(write_ptr, compression_window); - } if(verbose > 1) fprintf(STDERR, " Setting IHDR\n"); @@ -2986,6 +2972,7 @@ main(int argc, char *argv[]) if(input_format != output_format) things_have_changed = 1; #endif + png_set_IHDR(write_ptr, write_info_ptr, width, height, output_bit_depth, output_color_type, output_interlace_method, compression_method, filter_method); @@ -3034,8 +3021,14 @@ main(int argc, char *argv[]) &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y)) { if(keep_chunk("cHRM",argv)) - png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, - red_x, red_y, green_x, green_y, blue_x, blue_y); + { + if (white_x == 0 && white_y == 0 && red_x == 0 && red_y == 0 && + green_x == 0 && green_y == 0 && blue_x == 0 && blue_y == 0) + png_warning (write_ptr, "Deleting all-zero cHRM chunk"); + else + png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, + red_x, red_y, green_x, green_y, blue_x, blue_y); + } } } #else @@ -3047,8 +3040,14 @@ main(int argc, char *argv[]) &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y)) { if(keep_chunk("cHRM",argv)) - png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, - red_x, red_y, green_x, green_y, blue_x, blue_y); + { + if (white_x == 0 && white_y == 0 && red_x == 0 && red_y == 0 && + green_x == 0 && green_y == 0 && blue_x == 0 && blue_y == 0) + png_warning (write_ptr, "Deleting all-zero cHRM chunk"); + else + png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, + red_x, red_y, green_x, green_y, blue_x, blue_y); + } } } #endif @@ -3189,6 +3188,8 @@ main(int argc, char *argv[]) &profile, &proflen)) { P1 ("Got iccp chunk, proflen=%lu\n",proflen); + if(iccp_length) + P0 ("Will not replace existing iccp chunk.\n"); if(keep_chunk("iCCP",argv)) png_set_iCCP(write_ptr, write_info_ptr, name, compression_method, profile, proflen); @@ -3256,16 +3257,16 @@ main(int argc, char *argv[]) if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) { - if(res_x == 0 && res_y == 0) - { - if(verbose > 0 && first_trial) - fprintf(STDERR, " Deleting useless pHYs 0 0 chunk\n"); - } - else - { - if(keep_chunk("pHYs",argv)) - png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); - } + if(res_x == 0 && res_y == 0) + { + if(verbose > 0 && first_trial) + fprintf(STDERR, " Deleting useless pHYs 0 0 chunk\n"); + } + else + { + if(keep_chunk("pHYs",argv)) + png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); + } } } else @@ -3329,7 +3330,9 @@ main(int argc, char *argv[]) &trans_values)) { if(verbose > 1) - fprintf(STDERR," Got tRNS chunk.\n"); + fprintf(STDERR," Found tRNS chunk in input file.\n"); + if (have_trns == 1) + P0 (" Will not overwrite existing tRNS chunk.\n"); if(keep_chunk("tRNS",argv)) { int last_nonmax = -1; @@ -3383,8 +3386,7 @@ main(int argc, char *argv[]) trans_data.gray = trns_gray; trans_values = &trans_data; - if(verbose > 1) - fprintf(STDERR,"png_set_tRNS\n"); + P0 (" Adding a tRNS chunk\n"); png_set_tRNS(write_ptr, write_info_ptr, trns_array, num_trans, trans_values); @@ -3613,7 +3615,6 @@ main(int argc, char *argv[]) if(nosave == 0) { - png_set_compression_level(write_ptr, zlib_level); if (filter_type == 0)png_set_filter(write_ptr,0,PNG_FILTER_NONE); else if(filter_type == 1)png_set_filter(write_ptr,0,PNG_FILTER_SUB); @@ -3665,8 +3666,8 @@ main(int argc, char *argv[]) buffer[7]=(png_byte)((height ) & 0xff); for (i=8; i<27; i++) buffer[i]=0x00; - buffer[15]=1; /* frame count */ - buffer[19]=2; /* layer count */ + buffer[15]=2; /* layer count */ + buffer[19]=1; /* frame count */ if(output_color_type == 6) buffer[27]=0x09; /* simplicity profile: MNG-VLC with transparency */ else @@ -3674,14 +3675,79 @@ main(int argc, char *argv[]) png_write_chunk(write_ptr, (png_bytep)png_MHDR, buffer, (png_size_t)28); } #endif + P2("writing info structure.\n"); png_crush_pause(); png_debug(0, "\nWriting info struct\n"); + +#if 0 + /* if zTXt other compressed chunk */ + png_set_compression_level(write_ptr, 9); + png_set_compression_window_bits(write_ptr, 15); +#endif + + png_crush_pause(); + { + int compression_window; +#if (PNG_LIBPNG_VER >= 10000) + png_uint_32 zbuf_size; +#endif + png_uint_32 required_window; + int channels=0; + png_set_compression_strategy(write_ptr, z_strategy); + png_set_compression_mem_level(write_ptr, compression_mem_level); + + if (output_color_type == 0)channels=1; + if (output_color_type == 2)channels=3; + if (output_color_type == 3)channels=1; + if (output_color_type == 4)channels=2; + if (output_color_type == 6)channels=4; + + required_window= + (png_uint_32)(height*((width*channels*bit_depth+15)>>3)+262); + +#if (PNG_LIBPNG_VER >= 10000) + zbuf_size = png_get_compression_buffer_size(write_ptr); + + /* reinitialize zbuf - compression buffer */ + if (zbuf_size != max_idat_size) + { + png_uint_32 max_possible_size=required_window; + if(max_possible_size > max_idat_size) + max_possible_size=max_idat_size; + P2("reinitializing write zbuf to %lu.\n",max_possible_size); + png_set_compression_buffer_size(write_ptr, max_possible_size); + } +#endif + +#ifdef WBITS_8_OK + if (required_window <= 256)compression_window = 8; + else if(required_window <= 512)compression_window = 9; +#else + if (required_window <= 512)compression_window = 9; +#endif + else if(required_window <= 1024)compression_window = 10; + else if(required_window <= 2048)compression_window = 11; + else if(required_window <= 4096)compression_window = 12; + else if(required_window <= 8192)compression_window = 13; + else if(required_window <= 16384)compression_window = 14; + else compression_window = 15; + if(compression_window > default_compression_window || + force_compression_window) + compression_window = default_compression_window; + + if(verbose > 1 && first_trial && (compression_window != 15 || + force_compression_window)) + fprintf(STDERR, " Compression window for output= %d\n", + 1 << compression_window); + + png_set_compression_window_bits(write_ptr, compression_window); + } + + png_set_compression_level(write_ptr, zlib_level); png_write_info(write_ptr, write_info_ptr); png_debug(0, "\nWrote info struct\n"); - P2("wrote info structure.\n"); - png_crush_pause(); #if (PNG_LIBPNG_VER > 90) #ifdef PNG_WRITE_PACK_SUPPORTED @@ -3690,8 +3756,9 @@ main(int argc, char *argv[]) png_color_8 true_bits; true_bits.gray = (png_byte)(8 - (input_bit_depth - output_bit_depth)); png_set_shift(read_ptr, &true_bits); - png_set_packing(write_ptr); } + if(output_bit_depth != input_bit_depth && output_bit_depth < 8) + png_set_packing(write_ptr); #endif #endif /* PNG_LIBPNG_VER > 90 */ } /* no save */ @@ -3985,7 +4052,16 @@ main(int argc, char *argv[]) #endif /* PNG_LIBPNG_VER > 90 */ if(nosave == 0) + { +#if 0 + /* if zTXt other compressed chunk */ + png_set_compression_level(write_ptr, 9); + png_set_compression_window_bits(write_ptr, 15); + png_set_compression_buffer_size(write_ptr, PNG_ZBUF_SIZE); + png_set_compression_strategy(write_ptr, 0); +#endif png_write_end(write_ptr, write_end_info_ptr); + } png_debug(0, "Destroying data structs\n"); if(row_buf != (png_bytep)NULL) @@ -4080,7 +4156,7 @@ main(int argc, char *argv[]) if(verbose > 0 && trial != MAX_METHODS) { fprintf(STDERR, - " IDAT length with method %d (fm %d zl %d zs %d)= %8lu\n", + " IDAT length with method %3d (fm %d zl %d zs %d)= %8lu\n", trial,filter_type,zlib_level,z_strategy,idat_length[trial]); fflush(STDERR); } @@ -4152,7 +4228,7 @@ main(int argc, char *argv[]) png_uint_32 measure_idats(FILE *fpin) { - /* Copyright (C) 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) + /* Copyright (C) 1999-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu) See notice in pngcrush.c for conditions of use and distribution */ P2("measure_idats:\n"); png_debug(0, "Allocating read structure\n"); @@ -4191,7 +4267,7 @@ measure_idats(FILE *fpin) png_uint_32 png_measure_idat(png_structp png_ptr) { - /* Copyright (C) 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) + /* Copyright (C) 1999-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu) See notice in pngcrush.c for conditions of use and distribution */ png_uint_32 sum_idat_length=0; @@ -4334,7 +4410,7 @@ png_measure_idat(png_structp png_ptr) int count_colors(FILE *fpin) { - /* Copyright (C) 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) + /* Copyright (C) 2000-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu) See notice in pngcrush.c for conditions of use and distribution */ int bit_depth, color_type, interlace_method, filter_method, compression_method; png_uint_32 rowbytes; diff --git a/pngcrush.h b/pngcrush.h index 74af4443d..580a6749c 100644 --- a/pngcrush.h +++ b/pngcrush.h @@ -18,6 +18,10 @@ #define PNGCRUSH_LIBPNG_VER 10007 #endif +#if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_USE_PNGVCRD) +#define PNG_NO_ASSEMBLER_CODE +#endif + #ifndef PNG_NO_ZALLOC_ZERO # define PNG_NO_ZALLOC_ZERO /* speeds it up a little */ #endif @@ -26,7 +30,7 @@ # define PNG_USER_MEM_SUPPORTED #endif -#define PNG_MNG_FEATURES_SUPPORTED /* extra filter types */ +#define PNG_MNG_FEATURES_SUPPORTED /* extra filter type */ #ifndef PNG_NO_LEGACY_SUPPORTED # define PNG_NO_LEGACY_SUPPORTED @@ -41,8 +45,6 @@ #define PNG_READ_GRAY_TO_RGB_SUPPORTED #endif -#define PNG_NO_READ_cHRM -#define PNG_NO_WRITE_cHRM #define PNG_NO_READ_hIST #define PNG_NO_WRITE_hIST #define PNG_NO_READ_pCAL @@ -88,9 +90,6 @@ # define PNG_NO_READ_RGB_TO_GRAY # endif #endif -#if !defined(PNG_ZBUF_SIZE) && (PNGCRUSH_LIBPNG_VER > 97) -# define PNG_ZBUF_SIZE 524288 /* increases the IDAT size */ -#endif /* Changed in version 0.99 */ #if PNGCRUSH_LIBPNG_VER < 99 diff --git a/pngerror.c b/pngerror.c index 9d5bd6a93..c991b538c 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,9 +1,9 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * @@ -61,11 +61,12 @@ png_warning(png_structp png_ptr, png_const_charp message) */ #define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97)) static PNG_CONST char png_digit[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' -}; + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', + 'F' }; static void /* PRIVATE */ -png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message) +png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp + message) { int iout = 0, iin = 0; @@ -107,7 +108,7 @@ png_chunk_error(png_structp png_ptr, png_const_charp message) void PNGAPI png_chunk_warning(png_structp png_ptr, png_const_charp message) { - char msg[16+64]; + char msg[18+64]; png_format_buffer(png_ptr, msg, message); png_warning(png_ptr, msg); } diff --git a/pnggccrd.c b/pnggccrd.c index eb303a435..b4703ee77 100644 --- a/pnggccrd.c +++ b/pnggccrd.c @@ -6,14 +6,14 @@ * and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm * for Intel's performance analysis of the MMX vs. non-MMX code. * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng version 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * Copyright (c) 1998-2001 Glenn Randers-Pehrson * Copyright (c) 1998, Intel Corporation * * Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998. * Interface to libpng contributed by Gilles Vollant, 1999. - * GNU C port by Greg Roelofs, 1999-2000. + * GNU C port by Greg Roelofs, 1999-2001. * * Lines 2350-4300 converted in place with intel2gas 1.3.1: * @@ -95,11 +95,11 @@ * variables, not the other way around. Hence _const4, _mask8_0, etc. * * 19991024: - * - fixed mmxsupport()/png_do_interlace() first-row bug + * - fixed mmxsupport()/png_do_read_interlace() first-row bug * This one was severely weird: even though mmxsupport() doesn't touch * ebx (where "row" pointer was stored), it nevertheless managed to zero * the register (even in static/non-fPIC code--see below), which in turn - * caused png_do_interlace() to return prematurely on the first row of + * caused png_do_read_interlace() to return prematurely on the first row of * interlaced images (i.e., without expanding the interlaced pixels). * Inspection of the generated assembly code didn't turn up any clues, * although it did point at a minor optimization (i.e., get rid of @@ -203,6 +203,18 @@ * - "_ShiftRem.use = 40;" should have been "_ShiftRem.use = 48;" * - "psllq _ShiftRem, %%mm2" should have been "psrlq _ShiftRem, %%mm2" * + * 20010103: + * - renamed mmxsupport() to png_mmx_support(), with auto-set of mmx_supported, + * and made it public + * + * 20010104: + * - removed dependency on png_read_filter_row_c() (C code already duplicated + * within MMX version of png_read_filter_row()) so no longer necessary to + * compile it into pngrutil.o + * + * 20010310: + * - fixed buffer-overrun bug in png_combine_row() C code (non-MMX) + * * STILL TO DO: * - test png_do_read_interlace() 64-bit case (pixel_bytes == 8) * - write MMX code for 48-bit case (pixel_bytes == 6) @@ -211,22 +223,24 @@ * (only width_mmx case) (near line 1606) * - rewrite all MMX interlacing code so it's aligned with beginning * of the row buffer, not the end (see 19991007 for details) - * - pick one version of mmxsupport() and get rid of the other + * x pick one version of mmxsupport() and get rid of the other * - add error messages to any remaining bogus default cases * - enable pixel_depth == 8 cases in png_read_filter_row()? (test speed) * - add support for runtime enable/disable/query of various MMX routines */ -//#define PNG_DEBUG 2 // GRR +/* +#ifndef PNG_DEBUG +# define PNG_DEBUG 0 +#endif +*/ #define PNG_INTERNAL #include "png.h" -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGGCCRD) +#if defined(PNG_USE_PNGGCCRD) -int mmxsupport(void); - -static int mmx_supported = 2; +int PNGAPI png_mmx_support(void); #ifdef PNG_USE_LOCAL_ARRAYS static const int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; @@ -234,9 +248,11 @@ static const int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1}; #endif -// djgpp, Win32, and Cygwin add their own underscores to global variables, -// so define them without: +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +/* djgpp, Win32, and Cygwin add their own underscores to global variables, + * so define them without: */ #if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) +# define _mmx_supported mmx_supported # define _unmask unmask # define _const4 const4 # define _const6 const6 @@ -271,6 +287,7 @@ static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1}; # define _pctemp pctemp #endif + /* These constants are used in the inlined MMX assembly code. Ignore gcc's "At top level: defined but not used" warnings. */ @@ -316,23 +333,24 @@ static int _dif; static int _patemp; // temp variables for Paeth routine static int _pbtemp; static int _pctemp; +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ +static int _mmx_supported = 2; -void /* PRIVATE */ -png_read_filter_row_c(png_structp png_ptr, png_row_infop row_info, - png_bytep row, png_bytep prev_row, int filter); - - - - -//===========================================================================// -// // -// P N G _ C O M B I N E _ R O W // -// // -//===========================================================================// +/*===========================================================================*/ +/* */ +/* P N G _ C O M B I N E _ R O W */ +/* */ +/*===========================================================================*/ #if defined(PNG_HAVE_ASSEMBLER_COMBINE_ROW) +#define BPP2 2 +#define BPP3 3 /* bytes per pixel (a.k.a. pixel_bytes) */ +#define BPP4 4 +#define BPP6 6 /* (defined only to help avoid cut-and-paste errors) */ +#define BPP8 8 + /* Combines the row recently read in with the previous row. This routine takes care of alpha and transparency if requested. This routine also handles the two methods of progressive display @@ -350,23 +368,23 @@ png_read_filter_row_c(png_structp png_ptr, png_row_infop row_info, void /* PRIVATE */ png_combine_row(png_structp png_ptr, png_bytep row, int mask) { - png_debug(1,"in png_combine_row_asm\n"); + png_debug(1, "in png_combine_row (pnggccrd.c)\n"); - if (mmx_supported == 2) - mmx_supported = mmxsupport(); + if (_mmx_supported == 2) { + png_mmx_support(); + } if (mask == 0xff) { + png_debug(2,"mask == 0xff: doing single png_memcpy()\n"); png_memcpy(row, png_ptr->row_buf + 1, (png_size_t)((png_ptr->width * png_ptr->row_info.pixel_depth + 7) >> 3)); } - /* GRR: add "else if (mask == 0)" case? - * or does png_combine_row() not even get called in that case? */ - else + else /* (png_combine_row() is never called with mask == 0) */ { switch (png_ptr->row_info.pixel_depth) { - case 1: // png_ptr->row_info.pixel_depth + case 1: /* png_ptr->row_info.pixel_depth */ { png_bytep sp; png_bytep dp; @@ -423,7 +441,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) break; } - case 2: // png_ptr->row_info.pixel_depth + case 2: /* png_ptr->row_info.pixel_depth */ { png_bytep sp; png_bytep dp; @@ -478,7 +496,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) break; } - case 4: // png_ptr->row_info.pixel_depth + case 4: /* png_ptr->row_info.pixel_depth */ { png_bytep sp; png_bytep dp; @@ -532,12 +550,13 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) break; } - case 8: // png_ptr->row_info.pixel_depth + case 8: /* png_ptr->row_info.pixel_depth */ { png_bytep srcptr; png_bytep dstptr; - if (mmx_supported) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported ) { png_uint_32 len; int diff; @@ -550,7 +569,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr = png_ptr->row_buf + 1; dstptr = row; len = png_ptr->width &~7; // reduce to multiple of 8 - diff = png_ptr->width & 7; // amount lost + diff = (int) (png_ptr->width & 7); // amount lost __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern @@ -624,15 +643,18 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { register png_uint_32 i; png_uint_32 initial_val = png_pass_start[png_ptr->pass]; - // png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */ register int stride = png_pass_inc[png_ptr->pass]; - // png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */ register int rep_bytes = png_pass_width[png_ptr->pass]; - // png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; - register png_uint_32 final_val = png_ptr->width; + /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */ + png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */ + int diff = (int) (png_ptr->width & 7); /* amount lost */ + register png_uint_32 final_val = len; /* GRR bugfix */ srcptr = png_ptr->row_buf + 1 + initial_val; dstptr = row + initial_val; @@ -643,17 +665,31 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr += stride; dstptr += stride; } - } /* end of else */ + if (diff) /* number of leftover pixels: 3 for pngtest */ + { + final_val+=diff /* *BPP1 */ ; + for (; i < final_val; i += stride) + { + if (rep_bytes > (int)(final_val-i)) + rep_bytes = (int)(final_val-i); + png_memcpy(dstptr, srcptr, rep_bytes); + srcptr += stride; + dstptr += stride; + } + } + + } /* end of else (_mmx_supported) */ break; - } // end 8 bpp + } /* end 8 bpp */ - case 16: // png_ptr->row_info.pixel_depth + case 16: /* png_ptr->row_info.pixel_depth */ { png_bytep srcptr; png_bytep dstptr; - if (mmx_supported) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported ) { png_uint_32 len; int diff; @@ -666,7 +702,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr = png_ptr->row_buf + 1; dstptr = row; len = png_ptr->width &~7; // reduce to multiple of 8 - diff = png_ptr->width & 7; // amount lost + diff = (int) (png_ptr->width & 7); // amount lost // __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern @@ -756,15 +792,18 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { register png_uint_32 i; - png_uint_32 initial_val = 2 * png_pass_start[png_ptr->pass]; - // png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; - register int stride = 2 * png_pass_inc[png_ptr->pass]; - // png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; - register int rep_bytes = 2 * png_pass_width[png_ptr->pass]; - // png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; - register png_uint_32 final_val = 2 * png_ptr->width; + png_uint_32 initial_val = BPP2 * png_pass_start[png_ptr->pass]; + /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */ + register int stride = BPP2 * png_pass_inc[png_ptr->pass]; + /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */ + register int rep_bytes = BPP2 * png_pass_width[png_ptr->pass]; + /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */ + png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */ + int diff = (int) (png_ptr->width & 7); /* amount lost */ + register png_uint_32 final_val = BPP2 * len; /* GRR bugfix */ srcptr = png_ptr->row_buf + 1 + initial_val; dstptr = row + initial_val; @@ -775,17 +814,30 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr += stride; dstptr += stride; } - } /* end of else */ + if (diff) /* number of leftover pixels: 3 for pngtest */ + { + final_val+=diff*BPP2; + for (; i < final_val; i += stride) + { + if (rep_bytes > (int)(final_val-i)) + rep_bytes = (int)(final_val-i); + png_memcpy(dstptr, srcptr, rep_bytes); + srcptr += stride; + dstptr += stride; + } + } + } /* end of else (_mmx_supported) */ break; - } // end 16 bpp + } /* end 16 bpp */ - case 24: // png_ptr->row_info.pixel_depth + case 24: /* png_ptr->row_info.pixel_depth */ { png_bytep srcptr; png_bytep dstptr; - if (mmx_supported) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported ) { png_uint_32 len; int diff; @@ -798,7 +850,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr = png_ptr->row_buf + 1; dstptr = row; len = png_ptr->width &~7; // reduce to multiple of 8 - diff = png_ptr->width & 7; // amount lost + diff = (int) (png_ptr->width & 7); // amount lost // __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern @@ -903,15 +955,18 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { register png_uint_32 i; - png_uint_32 initial_val = 3 * png_pass_start[png_ptr->pass]; - // png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; - register int stride = 3 * png_pass_inc[png_ptr->pass]; - // png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; - register int rep_bytes = 3 * png_pass_width[png_ptr->pass]; - // png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; - register png_uint_32 final_val = 3 * png_ptr->width; + png_uint_32 initial_val = BPP3 * png_pass_start[png_ptr->pass]; + /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */ + register int stride = BPP3 * png_pass_inc[png_ptr->pass]; + /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */ + register int rep_bytes = BPP3 * png_pass_width[png_ptr->pass]; + /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */ + png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */ + int diff = (int) (png_ptr->width & 7); /* amount lost */ + register png_uint_32 final_val = BPP3 * len; /* GRR bugfix */ srcptr = png_ptr->row_buf + 1 + initial_val; dstptr = row + initial_val; @@ -922,17 +977,30 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr += stride; dstptr += stride; } - } /* end of else */ + if (diff) /* number of leftover pixels: 3 for pngtest */ + { + final_val+=diff*BPP3; + for (; i < final_val; i += stride) + { + if (rep_bytes > (int)(final_val-i)) + rep_bytes = (int)(final_val-i); + png_memcpy(dstptr, srcptr, rep_bytes); + srcptr += stride; + dstptr += stride; + } + } + } /* end of else (_mmx_supported) */ break; - } // end 24 bpp + } /* end 24 bpp */ - case 32: // png_ptr->row_info.pixel_depth + case 32: /* png_ptr->row_info.pixel_depth */ { png_bytep srcptr; png_bytep dstptr; - if (mmx_supported) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported ) { png_uint_32 len; int diff; @@ -945,7 +1013,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr = png_ptr->row_buf + 1; dstptr = row; len = png_ptr->width &~7; // reduce to multiple of 8 - diff = png_ptr->width & 7; // amount lost + diff = (int) (png_ptr->width & 7); // amount lost // __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern @@ -1057,15 +1125,18 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { register png_uint_32 i; - png_uint_32 initial_val = 4 * png_pass_start[png_ptr->pass]; - // png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; - register int stride = 4 * png_pass_inc[png_ptr->pass]; - // png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; - register int rep_bytes = 4 * png_pass_width[png_ptr->pass]; - // png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; - register png_uint_32 final_val = 4 * png_ptr->width; + png_uint_32 initial_val = BPP4 * png_pass_start[png_ptr->pass]; + /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */ + register int stride = BPP4 * png_pass_inc[png_ptr->pass]; + /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */ + register int rep_bytes = BPP4 * png_pass_width[png_ptr->pass]; + /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */ + png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */ + int diff = (int) (png_ptr->width & 7); /* amount lost */ + register png_uint_32 final_val = BPP4 * len; /* GRR bugfix */ srcptr = png_ptr->row_buf + 1 + initial_val; dstptr = row + initial_val; @@ -1076,17 +1147,30 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr += stride; dstptr += stride; } - } /* end of else */ + if (diff) /* number of leftover pixels: 3 for pngtest */ + { + final_val+=diff*BPP4; + for (; i < final_val; i += stride) + { + if (rep_bytes > (int)(final_val-i)) + rep_bytes = (int)(final_val-i); + png_memcpy(dstptr, srcptr, rep_bytes); + srcptr += stride; + dstptr += stride; + } + } + } /* end of else (_mmx_supported) */ break; - } // end 32 bpp + } /* end 32 bpp */ - case 48: // png_ptr->row_info.pixel_depth + case 48: /* png_ptr->row_info.pixel_depth */ { png_bytep srcptr; png_bytep dstptr; - if (mmx_supported) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported ) { png_uint_32 len; int diff; @@ -1099,7 +1183,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr = png_ptr->row_buf + 1; dstptr = row; len = png_ptr->width &~7; // reduce to multiple of 8 - diff = png_ptr->width & 7; // amount lost + diff = (int) (png_ptr->width & 7); // amount lost // __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern @@ -1228,15 +1312,18 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) ); } else /* mmx _not supported - Use modified C routine */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { register png_uint_32 i; - png_uint_32 initial_val = 6 * png_pass_start[png_ptr->pass]; - // png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; - register int stride = 6 * png_pass_inc[png_ptr->pass]; - // png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; - register int rep_bytes = 6 * png_pass_width[png_ptr->pass]; - // png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; - register png_uint_32 final_val = 6 * png_ptr->width; + png_uint_32 initial_val = BPP6 * png_pass_start[png_ptr->pass]; + /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */ + register int stride = BPP6 * png_pass_inc[png_ptr->pass]; + /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */ + register int rep_bytes = BPP6 * png_pass_width[png_ptr->pass]; + /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */ + png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */ + int diff = (int) (png_ptr->width & 7); /* amount lost */ + register png_uint_32 final_val = BPP6 * len; /* GRR bugfix */ srcptr = png_ptr->row_buf + 1 + initial_val; dstptr = row + initial_val; @@ -1247,23 +1334,37 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr += stride; dstptr += stride; } - } /* end of else */ + if (diff) /* number of leftover pixels: 3 for pngtest */ + { + final_val+=diff*BPP6; + for (; i < final_val; i += stride) + { + if (rep_bytes > (int)(final_val-i)) + rep_bytes = (int)(final_val-i); + png_memcpy(dstptr, srcptr, rep_bytes); + srcptr += stride; + dstptr += stride; + } + } + } /* end of else (_mmx_supported) */ break; - } // end 48 bpp + } /* end 48 bpp */ - case 64: // png_ptr->row_info.pixel_depth + case 64: /* png_ptr->row_info.pixel_depth */ { png_bytep srcptr; png_bytep dstptr; register png_uint_32 i; - png_uint_32 initial_val = 8 * png_pass_start[png_ptr->pass]; - // png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; - register int stride = 8 * png_pass_inc[png_ptr->pass]; - // png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; - register int rep_bytes = 8 * png_pass_width[png_ptr->pass]; - // png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; - register png_uint_32 final_val = 8 * png_ptr->width; + png_uint_32 initial_val = BPP8 * png_pass_start[png_ptr->pass]; + /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */ + register int stride = BPP8 * png_pass_inc[png_ptr->pass]; + /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */ + register int rep_bytes = BPP8 * png_pass_width[png_ptr->pass]; + /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */ + png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */ + int diff = (int) (png_ptr->width & 7); /* amount lost */ + register png_uint_32 final_val = BPP8 * len; /* GRR bugfix */ srcptr = png_ptr->row_buf + 1 + initial_val; dstptr = row + initial_val; @@ -1274,12 +1375,25 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) srcptr += stride; dstptr += stride; } - break; - } // end 64 bpp + if (diff) /* number of leftover pixels: 3 for pngtest */ + { + final_val+=diff*BPP8; + for (; i < final_val; i += stride) + { + if (rep_bytes > (int)(final_val-i)) + rep_bytes = (int)(final_val-i); + png_memcpy(dstptr, srcptr, rep_bytes); + srcptr += stride; + dstptr += stride; + } + } - default: // png_ptr->row_info.pixel_depth != 1,2,4,8,16,24,32,48,64 + break; + } /* end 64 bpp */ + + default: /* png_ptr->row_info.pixel_depth != 1,2,4,8,16,24,32,48,64 */ { - // this should never happen + /* this should never happen */ fprintf(stderr, "libpng internal error: png_ptr->row_info.pixel_depth = %d\n", png_ptr->row_info.pixel_depth); @@ -1297,11 +1411,11 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) -//===========================================================================// -// // -// P N G _ D O _ R E A D _ I N T E R L A C E // -// // -//===========================================================================// +/*===========================================================================*/ +/* */ +/* P N G _ D O _ R E A D _ I N T E R L A C E */ +/* */ +/*===========================================================================*/ #if defined(PNG_READ_INTERLACING_SUPPORTED) #if defined(PNG_HAVE_ASSEMBLER_READ_INTERLACE) @@ -1311,13 +1425,20 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) */ void /* PRIVATE */ -png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, - png_uint_32 transformations) +png_do_read_interlace(png_structp png_ptr) { - png_debug(1,"in png_do_read_interlace\n"); + png_row_infop row_info = &(png_ptr->row_info); + png_bytep row = png_ptr->row_buf + 1; + int pass = png_ptr->pass; +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + png_uint_32 transformations = png_ptr->transformations; +#endif - if (mmx_supported == 2) - mmx_supported = mmxsupport(); + png_debug(1, "in png_do_read_interlace (pnggccrd.c)\n"); + + if (_mmx_supported == 2) { + png_mmx_support(); + } if (row != NULL && row_info != NULL) { @@ -1497,30 +1618,33 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, break; } - //==================================================================== + /*====================================================================*/ - default: // 8-bit or larger (this is where the routine is modified) + default: /* 8-bit or larger (this is where the routine is modified) */ { +#if 0 // static unsigned long long _const4 = 0x0000000000FFFFFFLL; no good // static unsigned long long const4 = 0x0000000000FFFFFFLL; no good // unsigned long long _const4 = 0x0000000000FFFFFFLL; no good // unsigned long long const4 = 0x0000000000FFFFFFLL; no good +#endif png_bytep sptr, dp; png_uint_32 i; png_size_t pixel_bytes; - int width = row_info->width; + int width = (int)row_info->width; pixel_bytes = (row_info->pixel_depth >> 3); - // point sptr at the last pixel in the pre-expanded row: + /* point sptr at the last pixel in the pre-expanded row: */ sptr = row + (width - 1) * pixel_bytes; - // point dp at the last pixel position in the expanded row: + /* point dp at the last pixel position in the expanded row: */ dp = row + (final_width - 1) * pixel_bytes; - // New code by Nirav Chhatrapati - Intel Corporation + /* New code by Nirav Chhatrapati - Intel Corporation */ - if (mmx_supported) // use MMX code if machine supports it +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported ) { //-------------------------------------------------------------- if (pixel_bytes == 3) @@ -1771,7 +1895,9 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, */ for (j = 0; j < png_pass_inc[pass]; j++) + { *dp-- = *sptr; + } --sptr; } } @@ -1824,7 +1950,9 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, int j; for (j = 0; j < png_pass_inc[pass]; j++) + { *dp-- = *sptr; + } --sptr; } } @@ -1876,7 +2004,9 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, int j; for (j = 0; j < png_pass_inc[pass]; j++) + { *dp-- = *sptr; + } --sptr; } } @@ -2398,13 +2528,14 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, sptr-= pixel_bytes; } } - } // end of mmx_supported ========================================= + } // end of _mmx_supported ======================================== else /* MMX not supported: use modified C code - takes advantage - * of inlining of memcpy for a constant */ + * of inlining of png_memcpy for a constant */ /* GRR 19991007: does it? or should pixel_bytes in each * block be replaced with immediate value (e.g., 1)? */ /* GRR 19991017: replaced with constants in each case */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { if (pixel_bytes == 1) { @@ -2412,7 +2543,9 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, { int j; for (j = 0; j < png_pass_inc[pass]; j++) + { *dp-- = *sptr; + } --sptr; } } @@ -2455,6 +2588,14 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, png_memcpy(v, sptr, 4); for (j = 0; j < png_pass_inc[pass]; j++) { +#ifdef PNG_DEBUG + if (dp < row || dp+3 > row+png_ptr->row_buf_size) + { + printf("dp out of bounds: row=%d, dp=%d, rp=%d\n",row, dp, + row+png_ptr->row_buf_size); + printf("row_buf=%d\n",png_ptr->row_buf_size); + } +#endif png_memcpy(dp, v, 4); dp -= 4; } @@ -2491,7 +2632,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, sptr -= 8; } } - else // GRR: should never be reached + else /* GRR: should never be reached */ { for (i = width; i; i--) { @@ -2525,6 +2666,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + // These variables are utilized in the functions below. They are declared // globally here to ensure alignment on 8-byte boundaries. @@ -2537,7 +2680,6 @@ union uAll { - //===========================================================================// // // // P N G _ R E A D _ F I L T E R _ R O W _ M M X _ A V G // @@ -4731,61 +4873,54 @@ png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row, } // end of png_read_filter_row_mmx_up() +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ -//===========================================================================// -// // -// P N G _ R E A D _ F I L T E R _ R O W // -// // -//===========================================================================// + +/*===========================================================================*/ +/* */ +/* P N G _ R E A D _ F I L T E R _ R O W */ +/* */ +/*===========================================================================*/ #if defined(PNG_HAVE_ASSEMBLER_READ_FILTER_ROW) -// Optimized png_read_filter_row routines +/* Optimized png_read_filter_row routines */ void /* PRIVATE */ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter) { #ifdef PNG_DEBUG - char filnm[6]; + char filnm[10]; #endif -#define UseMMX 1 - +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +/* GRR: these are superseded by png_ptr->asm_flags: */ #define UseMMX_sub 1 // GRR: converted 20000730 #define UseMMX_up 1 // GRR: converted 20000729 #define UseMMX_avg 1 // GRR: converted 20000828 (+ 16-bit bugfix 20000916) #define UseMMX_paeth 1 // GRR: converted 20000828 - if (mmx_supported == 2) - mmx_supported = mmxsupport(); - - if (!mmx_supported) - { - png_read_filter_row_c(png_ptr, row_info, row, prev_row, filter); - return; + if (_mmx_supported == 2) { + png_mmx_support(); } +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ #ifdef PNG_DEBUG - png_debug(1, "in png_read_filter_row\n"); -#if (UseMMX == 1) - png_debug1(0,"%s, ", "MMX"); -#else - png_debug1(0,"%s, ", "x86"); -#endif + png_debug(1, "in png_read_filter_row (pnggccrd.c)\n"); switch (filter) { case 0: sprintf(filnm, "none"); break; - case 1: sprintf(filnm, "sub"); + case 1: sprintf(filnm, "sub-%s", "MMX"); break; - case 2: sprintf(filnm, "up"); + case 2: sprintf(filnm, "up-%s", "MMX"); break; - case 3: sprintf(filnm, "avg"); + case 3: sprintf(filnm, "avg-%s", "MMX"); break; - case 4: sprintf(filnm, "Paeth"); + case 4: sprintf(filnm, "Paeth-%s", "MMX"); break; default: sprintf(filnm, "unknw"); break; @@ -4795,7 +4930,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep png_debug2(0, "pixdepth=%2d, bytes=%d, ", (int)row_info->pixel_depth, (int)((row_info->pixel_depth + 7) >> 3)); png_debug1(0,"rowbytes=%8ld\n", row_info->rowbytes); -#endif +#endif /* PNG_DEBUG */ switch (filter) { @@ -4803,13 +4938,15 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep break; case PNG_FILTER_VALUE_SUB: -#if (UseMMX_sub == 1) - if ((row_info->pixel_depth > 8) && (row_info->rowbytes >= 128)) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported && + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_sub(row_info, row); } else -#endif +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { png_uint_32 i; png_uint_32 istop = row_info->rowbytes; @@ -4822,37 +4959,43 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff); rp++; } - } //end !UseMMX_sub + } /* end !UseMMX_sub */ break; case PNG_FILTER_VALUE_UP: -#if (UseMMX_up == 1) - if ((row_info->pixel_depth > 8) && (row_info->rowbytes >= 128)) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported && + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_up(row_info, row, prev_row); } - else -#endif + else +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { - png_bytep rp; - png_bytep pp; png_uint_32 i; - for (i = 0, rp = row, pp = prev_row; - i < row_info->rowbytes; i++, rp++, pp++) + png_uint_32 istop = row_info->rowbytes; + png_bytep rp = row; + png_bytep pp = prev_row; + + for (i = 0; i < istop; ++i) { - *rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff); + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; } - } //end !UseMMX_up + } /* end !UseMMX_up */ break; case PNG_FILTER_VALUE_AVG: -#if (UseMMX_avg == 1) - if ((row_info->pixel_depth > 8) && (row_info->rowbytes >= 128)) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported && + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_avg(row_info, row, prev_row); } else -#endif +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { png_uint_32 i; png_bytep rp = row; @@ -4874,17 +5017,19 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep ((int)(*pp++ + *lp++) >> 1)) & 0xff); rp++; } - } //end !UseMMX_avg + } /* end !UseMMX_avg */ break; case PNG_FILTER_VALUE_PAETH: -#if (UseMMX_paeth == 1) - if ((row_info->pixel_depth > 8) && (row_info->rowbytes >= 128)) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + if ( _mmx_supported && + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_paeth(row_info, row, prev_row); } else -#endif +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ { png_uint_32 i; png_bytep rp = row; @@ -4892,7 +5037,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep png_bytep lp = row; png_bytep cp = prev_row; png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; - png_uint_32 istop=row_info->rowbytes - bpp; + png_uint_32 istop = row_info->rowbytes - bpp; for (i = 0; i < bpp; i++) { @@ -4900,7 +5045,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep rp++; } - for (i = 0; i < istop; i++) // use leftover rp,pp + for (i = 0; i < istop; i++) /* use leftover rp,pp */ { int a, b, c, pa, pb, pc, p; @@ -4930,16 +5075,16 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep p = c; */ - p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c; *rp = (png_byte)(((int)(*rp) + p) & 0xff); rp++; } - } //end !UseMMX_paeth + } /* end !UseMMX_paeth */ break; default: - png_warning(png_ptr, "Ignoring bad adaptive filter type"); + png_warning(png_ptr, "Ignoring bad row-filter type"); *row=0; break; } @@ -4948,101 +5093,40 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep #endif /* PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */ +/*===========================================================================*/ +/* */ +/* P N G _ M M X _ S U P P O R T */ +/* */ +/*===========================================================================*/ +/* GRR NOTES: (1) the following code assumes 386 or better (pushfl/popfl) + * (2) all instructions compile with gcc 2.7.2.3 and later + * (3) the function is moved down here to prevent gcc from + * inlining it in multiple places and then barfing be- + * cause the ".NOT_SUPPORTED" label is multiply defined + * [is there a way to signal that a *single* function should + * not be inlined? is there a way to modify the label for + * each inlined instance, e.g., by appending _1, _2, etc.? + * maybe if don't use leading "." in label name? (nope...sigh)] + */ -//===========================================================================// -// // -// M M X S U P P O R T // -// // -//===========================================================================// - -// GRR NOTES: (1) the following code assumes 386 or better (pushfl/popfl) -// (2) all instructions compile with gcc 2.7.2.3 and later -// (3) the function is moved down here to prevent gcc from -// inlining it in multiple places and then barfing be- -// cause the ".NOT_SUPPORTED" label is multiply defined -// [is there a way to signal that a *single* function should -// not be inlined? is there a way to modify the label for -// each inlined instance, e.g., by appending _1, _2, etc.? -// maybe if don't use leading "." in label name? (not tested)] - -#ifdef ORIG_THAT_USED_TO_CLOBBER_EBX - -int mmxsupport(void) -{ - int mmx_supported_local = 0; - - __asm__ __volatile__ ( -// ".byte 0x66 \n\t" // convert 16-bit pushf to 32-bit pushfd -// "pushf \n\t" // save Eflag to stack - "pushfl \n\t" // save Eflag to stack - "popl %%eax \n\t" // get Eflag from stack into eax - "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx - "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) - "pushl %%eax \n\t" // save modified Eflag back to stack -// ".byte 0x66 \n\t" // convert 16-bit popf to 32-bit popfd -// "popf \n\t" // restore modified value to Eflag reg - "popfl \n\t" // restore modified value to Eflag reg - "pushfl \n\t" // save Eflag to stack - "popl %%eax \n\t" // get Eflag from stack - "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag - "jz .NOT_SUPPORTED \n\t" // if same, CPUID instr. is not supported - - "xorl %%eax, %%eax \n\t" // set eax to zero -// ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode) - "cpuid \n\t" // get the CPU identification info - "cmpl $1, %%eax \n\t" // make sure eax return non-zero value - "jl .NOT_SUPPORTED \n\t" // if eax is zero, MMX is not supported - - "xorl %%eax, %%eax \n\t" // set eax to zero and... - "incl %%eax \n\t" // ...increment eax to 1. This pair is - // faster than the instruction "mov eax, 1" - "cpuid \n\t" // get the CPU identification info again - "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23) - "cmpl $0, %%edx \n\t" // 0 = MMX not supported - "jz .NOT_SUPPORTED \n\t" // non-zero = yes, MMX IS supported - - "movl $1, %0 \n\t" // set return value to 1 and fall through - - ".NOT_SUPPORTED: \n\t" // target label for jump instructions - "movl %0, %%eax \n\t" // move return value to eax - // DONE - - : "=m" (mmx_supported_local) // %0 (output list: memory only) - - : // any variables used on input (none) - - : "%eax", "%ebx", // clobber list - "%ecx", "%edx" -// , "memory" // if write to a variable gcc thought was in a reg -// , "cc" // "condition codes" (flag bits) - ); - - //mmx_supported_local=0; // test code for force don't support MMX - //printf("MMX : %u (1=MMX supported)\n",mmx_supported_local); - - return mmx_supported_local; -} - - -#else /* !ORIG_THAT_USED_TO_CLOBBER_EBX */ - - -int mmxsupport(void) +int PNGAPI +png_mmx_support(void) { +#if defined(PNG_MMX_CODE_SUPPORTED) __asm__ __volatile__ ( "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction "pushl %%ecx \n\t" // so does ecx... "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux) // ".byte 0x66 \n\t" // convert 16-bit pushf to 32-bit pushfd -// "pushf \n\t" // save Eflag to stack +// "pushf \n\t" // 16-bit pushf "pushfl \n\t" // save Eflag to stack "popl %%eax \n\t" // get Eflag from stack into eax "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) "pushl %%eax \n\t" // save modified Eflag back to stack // ".byte 0x66 \n\t" // convert 16-bit popf to 32-bit popfd -// "popf \n\t" // restore modified value to Eflag reg +// "popf \n\t" // 16-bit popf "popfl \n\t" // restore modified value to Eflag reg "pushfl \n\t" // save Eflag to stack "popl %%eax \n\t" // get Eflag from stack @@ -5064,20 +5148,20 @@ int mmxsupport(void) "jz .NOT_SUPPORTED \n\t" // non-zero = yes, MMX IS supported "movl $1, %%eax \n\t" // set return value to 1 - "popl %%edx \n\t" // restore edx - "popl %%ecx \n\t" // restore ecx - "popl %%ebx \n\t" // restore ebx ("row" in png_do_interlace) - "ret \n\t" // DONE: have MMX support + "jmp .RETURN \n\t" // DONE: have MMX support ".NOT_SUPPORTED: \n\t" // target label for jump instructions "movl $0, %%eax \n\t" // set return value to 0 + ".RETURN: \n\t" // target label for jump instructions + "movl %%eax, _mmx_supported \n\t" // save in global static variable, too "popl %%edx \n\t" // restore edx "popl %%ecx \n\t" // restore ecx - "popl %%ebx \n\t" // restore ebx ("row" in png_do_interlace) + "popl %%ebx \n\t" // restore ebx + // "ret \n\t" // DONE: no MMX support // (fall through to standard C "ret") - : // "=m" (mmx_supported_local) // %0 (output list: memory only) + : // output list (none) : // any variables used on input (none) @@ -5086,13 +5170,11 @@ int mmxsupport(void) // , "memory" // if write to a variable gcc thought was in a reg // , "cc" // "condition codes" (flag bits) ); +#else + _mmx_supported = 0; +#endif /* PNG_MMX_CODE_SUPPORTED */ - //mmx_supported_local=0; // test code for force don't support MMX - //printf("MMX : %u (1=MMX supported)\n",mmx_supported_local); - - //return mmx_supported_local; + return _mmx_supported; } -#endif /* ?ORIG_THAT_USED_TO_CLOBBER_EBX */ - -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED && PNG_USE_PNGGCCRD */ +#endif /* PNG_USE_PNGGCCRD */ diff --git a/pngget.c b/pngget.c index 00f0d5f30..5348c60e3 100644 --- a/pngget.c +++ b/pngget.c @@ -1,9 +1,9 @@ /* pngget.c - retrieval of values from info struct * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) */ @@ -137,7 +137,7 @@ png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) #if defined(PNG_pHYs_SUPPORTED) if (info_ptr->valid & PNG_INFO_pHYs) { - png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); + png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) return (0); else return (info_ptr->y_pixels_per_unit); @@ -297,7 +297,7 @@ png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) *.00003937); } -#if defined(PNG_READ_pHYs_SUPPORTED) +#if defined(PNG_pHYs_SUPPORTED) png_uint_32 PNGAPI png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) @@ -330,7 +330,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, } return (retval); } -#endif /* PNG_READ_pHYs_SUPPORTED */ +#endif /* PNG_pHYs_SUPPORTED */ #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ /* png_get_channels really belongs in here, too, but it's been around longer */ @@ -355,7 +355,7 @@ png_get_signature(png_structp png_ptr, png_infop info_ptr) return (NULL); } -#if defined(PNG_READ_bKGD_SUPPORTED) +#if defined(PNG_bKGD_SUPPORTED) png_uint_32 PNGAPI png_get_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p *background) @@ -371,7 +371,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr, } #endif -#if defined(PNG_READ_cHRM_SUPPORTED) +#if defined(PNG_cHRM_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI png_get_cHRM(png_structp png_ptr, png_infop info_ptr, @@ -435,7 +435,7 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, #endif #endif -#if defined(PNG_READ_gAMA_SUPPORTED) +#if defined(PNG_gAMA_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) @@ -467,7 +467,7 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, #endif #endif -#if defined(PNG_READ_sRGB_SUPPORTED) +#if defined(PNG_sRGB_SUPPORTED) png_uint_32 PNGAPI png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) { @@ -482,7 +482,7 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) } #endif -#if defined(PNG_READ_iCCP_SUPPORTED) +#if defined(PNG_iCCP_SUPPORTED) png_uint_32 PNGAPI png_get_iCCP(png_structp png_ptr, png_infop info_ptr, png_charpp name, int *compression_type, @@ -504,7 +504,7 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr, } #endif -#if defined(PNG_READ_sPLT_SUPPORTED) +#if defined(PNG_sPLT_SUPPORTED) png_uint_32 PNGAPI png_get_sPLT(png_structp png_ptr, png_infop info_ptr, png_sPLT_tpp spalettes) @@ -515,7 +515,7 @@ png_get_sPLT(png_structp png_ptr, png_infop info_ptr, } #endif -#if defined(PNG_READ_hIST_SUPPORTED) +#if defined(PNG_hIST_SUPPORTED) png_uint_32 PNGAPI png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) { @@ -576,7 +576,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr, return (0); } -#if defined(PNG_READ_oFFs_SUPPORTED) +#if defined(PNG_oFFs_SUPPORTED) png_uint_32 PNGAPI png_get_oFFs(png_structp png_ptr, png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) @@ -594,7 +594,7 @@ png_get_oFFs(png_structp png_ptr, png_infop info_ptr, } #endif -#if defined(PNG_READ_pCAL_SUPPORTED) +#if defined(PNG_pCAL_SUPPORTED) png_uint_32 PNGAPI 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, @@ -618,7 +618,7 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr, } #endif -#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) +#if defined(PNG_sCAL_SUPPORTED) #ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI png_get_sCAL(png_structp png_ptr, png_infop info_ptr, @@ -654,7 +654,7 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, #endif #endif -#if defined(PNG_READ_pHYs_SUPPORTED) +#if defined(PNG_pHYs_SUPPORTED) png_uint_32 PNGAPI png_get_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) @@ -701,7 +701,7 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, return (0); } -#if defined(PNG_READ_sBIT_SUPPORTED) +#if defined(PNG_sBIT_SUPPORTED) png_uint_32 PNGAPI png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) { @@ -716,7 +716,7 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) } #endif -#if defined(PNG_READ_TEXT_SUPPORTED) +#if defined(PNG_TEXT_SUPPORTED) png_uint_32 PNGAPI png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, int *num_text) @@ -738,7 +738,7 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, } #endif -#if defined(PNG_READ_tIME_SUPPORTED) +#if defined(PNG_tIME_SUPPORTED) png_uint_32 PNGAPI png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) { @@ -753,7 +753,7 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) } #endif -#if defined(PNG_READ_tRNS_SUPPORTED) +#if defined(PNG_tRNS_SUPPORTED) png_uint_32 PNGAPI png_get_tRNS(png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values) @@ -792,7 +792,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr, } #endif -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) png_uint_32 PNGAPI png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_unknown_chunkpp unknowns) @@ -807,15 +807,15 @@ png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_byte PNGAPI png_get_rgb_to_gray_status (png_structp png_ptr) { - return png_ptr->rgb_to_gray_status; + return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0); } #endif -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) +#if defined(PNG_USER_CHUNKS_SUPPORTED) png_voidp PNGAPI png_get_user_chunk_ptr(png_structp png_ptr) { - return (png_ptr->user_chunk_ptr); + return (png_ptr? png_ptr->user_chunk_ptr : NULL); } #endif @@ -823,5 +823,6 @@ png_get_user_chunk_ptr(png_structp png_ptr) png_uint_32 PNGAPI png_get_compression_buffer_size(png_structp png_ptr) { - return(png_ptr->zbuf_size); + return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); } + diff --git a/pngmem.c b/pngmem.c index 5ee83adb2..425df56b6 100644 --- a/pngmem.c +++ b/pngmem.c @@ -1,9 +1,9 @@ /* pngmem.c - stub functions for memory allocation * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * @@ -119,7 +119,12 @@ png_malloc(png_structp png_ptr, png_uint_32 size) #ifdef PNG_USER_MEM_SUPPORTED if(png_ptr->malloc_fn != NULL) - return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); + { + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); + if (ret == NULL) + png_error(png_ptr, "Out of memory!"); + return (ret); + } else return png_malloc_default(png_ptr, size); } @@ -373,15 +378,18 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn) png_voidp PNGAPI png_malloc(png_structp png_ptr, png_uint_32 size) { -#ifndef PNG_USER_MEM_SUPPORTED png_voidp ret; -#endif if (png_ptr == NULL || size == 0) return ((png_voidp)NULL); #ifdef PNG_USER_MEM_SUPPORTED if(png_ptr->malloc_fn != NULL) - return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); + { + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); + if (ret == NULL) + png_error(png_ptr, "Out of Memory!"); + return (ret); + } else return (png_malloc_default(png_ptr, size)); } @@ -407,9 +415,7 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size) #endif if (ret == NULL) - { png_error(png_ptr, "Out of Memory"); - } return (ret); } diff --git a/pngpread.c b/pngpread.c index fa0dc53e2..9b4a9e516 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,9 +1,9 @@ /* pngpread.c - read a png file in push mode * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) */ @@ -772,18 +772,42 @@ png_push_process_row(png_structp png_ptr) if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) { if (png_ptr->pass < 6) +/* old interface (pre-1.0.9): png_do_read_interlace(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); + */ + png_do_read_interlace(png_ptr); - switch (png_ptr->pass) - { + switch (png_ptr->pass) + { case 0: { int i; for (i = 0; i < 8 && png_ptr->pass == 0; i++) { png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); + png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */ + } + if (png_ptr->pass == 2) /* pass 1 might be empty */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + if (png_ptr->pass == 4 && png_ptr->height <= 4) + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + if (png_ptr->pass == 6 && png_ptr->height <= 4) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); } break; } @@ -795,7 +819,7 @@ png_push_process_row(png_structp png_ptr) png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_read_push_finish_row(png_ptr); } - if (png_ptr->pass == 2) + if (png_ptr->pass == 2) /* skip top 4 generated rows */ { for (i = 0; i < 4 && png_ptr->pass == 2; i++) { @@ -818,6 +842,14 @@ png_push_process_row(png_structp png_ptr) png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } + if (png_ptr->pass == 4) /* pass 3 might be empty */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } break; } case 3: @@ -828,7 +860,7 @@ png_push_process_row(png_structp png_ptr) png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_read_push_finish_row(png_ptr); } - if (png_ptr->pass == 4) + if (png_ptr->pass == 4) /* skip top two generated rows */ { for (i = 0; i < 2 && png_ptr->pass == 4; i++) { @@ -851,6 +883,11 @@ png_push_process_row(png_structp png_ptr) png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } + if (png_ptr->pass == 6) /* pass 5 might be empty */ + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } break; } case 5: @@ -861,7 +898,7 @@ png_push_process_row(png_structp png_ptr) png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_read_push_finish_row(png_ptr); } - if (png_ptr->pass == 6) + if (png_ptr->pass == 6) /* skip top generated row */ { png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); @@ -928,6 +965,11 @@ png_read_push_finish_row(png_structp png_ptr) do { png_ptr->pass++; + if ((png_ptr->pass == 1 && png_ptr->width < 5) || + (png_ptr->pass == 3 && png_ptr->width < 3) || + (png_ptr->pass == 5 && png_ptr->width < 2)) + png_ptr->pass++; + if (png_ptr->pass >= 7) break; @@ -953,7 +995,8 @@ png_read_push_finish_row(png_structp png_ptr) #if defined(PNG_READ_tEXt_SUPPORTED) void /* PRIVATE */ -png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) { if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) { @@ -965,7 +1008,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length #ifdef PNG_MAX_MALLOC_64K png_ptr->skip_length = 0; /* This may not be necessary */ - if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */ + if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ { png_warning(png_ptr, "tEXt chunk too large to fit in memory"); png_ptr->skip_length = length - (png_uint_32)65535L; @@ -1044,7 +1087,8 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) #if defined(PNG_READ_zTXt_SUPPORTED) void /* PRIVATE */ -png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) { if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) { @@ -1156,8 +1200,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) if (text == NULL) { text = (png_charp)png_malloc(png_ptr, - (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + - key_size + 1)); + (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + + key_size + 1)); png_memcpy(text + key_size, png_ptr->zbuf, png_ptr->zbuf_size - png_ptr->zstream.avail_out); png_memcpy(text, key, key_size); @@ -1228,7 +1272,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) #if defined(PNG_READ_iTXt_SUPPORTED) void /* PRIVATE */ -png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) { if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) { @@ -1240,7 +1285,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length #ifdef PNG_MAX_MALLOC_64K png_ptr->skip_length = 0; /* This may not be necessary */ - if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */ + if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ { png_warning(png_ptr, "iTXt chunk too large to fit in memory"); png_ptr->skip_length = length - (png_uint_32)65535L; @@ -1338,7 +1383,8 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) * name or a critical chunk), the chunk is (currently) silently ignored. */ void /* PRIVATE */ -png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) { png_uint_32 skip=0; png_check_chunk_name(png_ptr, png_ptr->chunk_name); @@ -1349,7 +1395,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != HANDLE_CHUNK_ALWAYS #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) - && png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL + && png_ptr->read_user_chunk_fn == NULL #endif ) #endif @@ -1374,12 +1420,12 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len } #endif - strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name); + png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name); chunk.data = (png_bytep)png_malloc(png_ptr, length); png_crc_read(png_ptr, chunk.data, length); chunk.size = length; #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) - if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL) + if(png_ptr->read_user_chunk_fn != NULL) { /* callback to user unknown chunk handler */ if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0) diff --git a/pngread.c b/pngread.c index e85c405f2..f84ede846 100644 --- a/pngread.c +++ b/pngread.c @@ -1,9 +1,9 @@ /* pngread.c - read a PNG file * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * @@ -246,6 +246,8 @@ png_read_info(png_structp png_ptr, png_infop info_ptr) else png_error(png_ptr, "PNG file corrupted by ASCII conversion"); } + if (num_checked < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; } for(;;) @@ -665,8 +667,11 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) (png_ptr->transformations & PNG_INTERLACE)) { if (png_ptr->pass < 6) +/* old interface (pre-1.0.9): png_do_read_interlace(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); + */ + png_do_read_interlace(png_ptr); if (dsp_row != NULL) png_combine_row(png_ptr, dsp_row, @@ -710,7 +715,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.9beta5 + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.11 */ void PNGAPI @@ -759,7 +764,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.9beta5 + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.11 */ void PNGAPI png_read_image(png_structp png_ptr, png_bytepp image) @@ -1047,7 +1052,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, } /* free all memory used by the read (old method) */ -void PNGAPI +void /* PRIVATE */ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr) { #ifdef PNG_SETJMP_SUPPORTED @@ -1300,7 +1305,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, /* Optional call to gamma correct and add the background to the palette * and update info structure. REQUIRED if you are expecting libpng to - * update the palette for you (ie you selected such a transform above). + * update the palette for you (i.e., you selected such a transform above). */ png_read_update_info(png_ptr, info_ptr); @@ -1312,13 +1317,15 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, if(info_ptr->row_pointers == NULL) { info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, - info_ptr->height * sizeof(png_bytep)); + info_ptr->height * sizeof(png_bytep)); #ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_ROWS; #endif for (row = 0; row < (int)info_ptr->height; row++) - info_ptr->row_pointers[row] = png_malloc(png_ptr, + { + info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); + } } png_read_image(png_ptr, info_ptr->row_pointers); @@ -1327,7 +1334,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ png_read_end(png_ptr, info_ptr); - if(transforms == 0 || params == (voidp)NULL) + if(transforms == 0 || params == NULL) /* quiet compiler warnings */ return; } diff --git a/pngrio.c b/pngrio.c index 037496905..4290624e9 100644 --- a/pngrio.c +++ b/pngrio.c @@ -1,9 +1,9 @@ /* pngrio.c - functions for data input * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * diff --git a/pngrtran.c b/pngrtran.c index 9064b4833..af7631ee3 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,9 +1,9 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * libpng 1.0.9beta5 - December 15, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * diff --git a/pngrutil.c b/pngrutil.c index 1ff1c1912..284f636de 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,9 +1,9 @@ /* pngrutil.c - utilities to read a PNG file * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * @@ -30,7 +30,7 @@ __inline double strtod(const char *nptr, char **endptr) MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len); result = wcstod(str, &end); len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL); - *endptr = (char *)nptr + (strlen(nptr) - len + 1); + *endptr = (char *)nptr + (png_strlen(nptr) - len + 1); free(str); } return result; @@ -174,7 +174,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_charp text = NULL; png_size_t text_size; - if (comp_type == PNG_TEXT_COMPRESSION_zTXt) + if (comp_type == PNG_COMPRESSION_TYPE_BASE) { int ret = Z_OK; png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size); @@ -220,7 +220,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_ptr->zbuf_size - png_ptr->zstream.avail_out; text = (png_charp)png_malloc(png_ptr, text_size + 1); png_memcpy(text + prefix_size, png_ptr->zbuf, - text_size - prefix_size); + text_size - prefix_size); png_memcpy(text, chunkdata, prefix_size); *(text + text_size) = 0x00; } @@ -266,6 +266,13 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_warning(png_ptr, "Incomplete compressed datastream in chunk other than IDAT"); #endif + text_size=prefix_size; + if (text == NULL) + { + text = (png_charp)png_malloc(png_ptr, text_size+1); + png_memcpy(text, chunkdata, prefix_size); + } + *(text + text_size) = 0x00; } inflateReset(&png_ptr->zstream); @@ -275,7 +282,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, chunkdata = text; *newlength=text_size; } - else /* if (comp_type != PNG_TEXT_COMPRESSION_zTXt) */ + else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ { #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) char umsg[50]; @@ -286,10 +293,8 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_warning(png_ptr, "Unknown zTXt compression type"); #endif - /* Copy what we can of the error message into the text chunk */ - text_size = (png_size_t)(chunklength - (text - chunkdata)); - text_size = sizeof(msg) > text_size ? text_size : sizeof(msg); - png_memcpy(text, msg, text_size); + *(chunkdata + prefix_size) = 0x00; + *newlength=prefix_size; } return chunkdata; @@ -327,41 +332,6 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) filter_type = buf[11]; interlace_type = buf[12]; - /* check for width and height valid values */ - if (width == 0 || width > PNG_MAX_UINT || height == 0 || - height > PNG_MAX_UINT) - png_error(png_ptr, "Invalid image size in IHDR"); - - /* check other values */ - if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && - bit_depth != 8 && bit_depth != 16) - png_error(png_ptr, "Invalid bit depth in IHDR"); - - if (color_type < 0 || color_type == 1 || - color_type == 5 || color_type > 6) - png_error(png_ptr, "Invalid color type in IHDR"); - - if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || - ((color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA || - color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) - png_error(png_ptr, "Invalid color type/bit depth combination in IHDR"); - - if (interlace_type >= PNG_INTERLACE_LAST) - png_error(png_ptr, "Unknown interlace method in IHDR"); - - if (compression_type != PNG_COMPRESSION_TYPE_BASE) - png_error(png_ptr, "Unknown compression method in IHDR"); - - if( -#if defined(PNG_MNG_FEATURES_SUPPORTED) - !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && - (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && - (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && -#endif - filter_type != PNG_FILTER_TYPE_BASE) - png_error(png_ptr, "Unknown filter method in IHDR"); /* set internal variables */ png_ptr->width = width; @@ -405,7 +375,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) void /* PRIVATE */ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { - png_colorp palette; + png_color palette[PNG_MAX_PALETTE_LENGTH]; int num, i; #ifndef PNG_NO_POINTER_INDEXING png_colorp pal_ptr; @@ -434,7 +404,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } #endif - if (length > 768 || length % 3) + if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) { if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) { @@ -450,8 +420,6 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) num = (int)length / 3; - palette = (png_colorp)png_zalloc(png_ptr, (uInt)num, sizeof (png_color)); - #ifndef PNG_NO_POINTER_INDEXING for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) { @@ -501,7 +469,6 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) else { png_chunk_warning(png_ptr, "CRC error"); - png_zfree(png_ptr, palette); return; } } @@ -512,15 +479,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } } #endif - png_ptr->palette = palette; - png_ptr->num_palette = (png_uint_16)num; -#ifdef PNG_FREE_ME_SUPPORTED - png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); - png_ptr->free_me |= PNG_FREE_PLTE; -#else - png_ptr->flags |= PNG_FLAG_FREE_PLTE; -#endif png_set_PLTE(png_ptr, info_ptr, palette, num); #if defined(PNG_READ_tRNS_SUPPORTED) @@ -616,7 +575,11 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) igamma = (png_fixed_point)png_get_uint_32(buf); /* check for zero gamma */ if (igamma == 0) - return; + { + png_warning(png_ptr, + "Ignoring gAMA chunk with gamma=0"); + return; + } #if defined(PNG_READ_sRGB_SUPPORTED) if (info_ptr->valid & PNG_INFO_sRGB) @@ -1058,6 +1021,8 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) slength, prefix_length, &data_length); profile_length = data_length - prefix_length; + + /* 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) | ((*(chunkdata+prefix_length+2))<< 8) | @@ -1073,7 +1038,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type, - chunkdata + prefix_length, data_length-prefix_length); + chunkdata + prefix_length, profile_length); png_free(png_ptr, chunkdata); } #endif /* PNG_READ_iCCP_SUPPORTED */ @@ -1115,7 +1080,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) chunkdata = (png_bytep)png_malloc(png_ptr, length + 1); slength = (png_size_t)length; - png_crc_read(png_ptr, chunkdata, slength); + png_crc_read(png_ptr, (png_bytep)chunkdata, slength); if (png_crc_finish(png_ptr, skip)) { @@ -1145,7 +1110,8 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (data_length % entry_size) { png_free(png_ptr, chunkdata); - png_error(png_ptr, "sPLT chunk has bad length"); + png_warning(png_ptr, "sPLT chunk has bad length"); + return; } new_palette.nentries = data_length / entry_size; @@ -1210,6 +1176,8 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) void /* PRIVATE */ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { + png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; + png_debug(1, "in png_handle_tRNS\n"); if (!(png_ptr->mode & PNG_HAVE_IHDR)) @@ -1247,8 +1215,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; } - png_ptr->trans = (png_bytep)png_malloc(png_ptr, length); - png_crc_read(png_ptr, png_ptr->trans, (png_size_t)length); + png_crc_read(png_ptr, readbuf, (png_size_t)length); png_ptr->num_trans = (png_uint_16)length; } else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) @@ -1293,15 +1260,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if (png_crc_finish(png_ptr, 0)) return; -#ifdef PNG_FREE_ME_SUPPORTED - png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - png_ptr->free_me |= PNG_FREE_TRNS; -#else - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - png_ptr->flags |= PNG_FLAG_FREE_TRNS; -#endif - png_set_tRNS(png_ptr, info_ptr, png_ptr->trans, png_ptr->num_trans, + png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, &(png_ptr->trans_values)); } #endif @@ -1400,6 +1359,7 @@ void /* PRIVATE */ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { int num, i; + png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; png_debug(1, "in png_handle_hIST\n"); @@ -1424,34 +1384,26 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; } - if (length != (png_uint_32)(2 * png_ptr->num_palette)) + num = (int)length / 2 ; + if (num != png_ptr->num_palette) { png_warning(png_ptr, "Incorrect hIST chunk length"); png_crc_finish(png_ptr, length); return; } - num = (int)length / 2 ; - png_ptr->hist = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(num * sizeof (png_uint_16))); for (i = 0; i < num; i++) { png_byte buf[2]; png_crc_read(png_ptr, buf, 2); - png_ptr->hist[i] = png_get_uint_16(buf); + readbuf[i] = png_get_uint_16(buf); } if (png_crc_finish(png_ptr, 0)) return; -#ifdef PNG_FREE_ME_SUPPORTED - png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); - png_ptr->free_me |= PNG_FREE_HIST; -#else - png_ptr->flags |= PNG_FLAG_FREE_HIST; -#endif - png_set_hIST(png_ptr, info_ptr, png_ptr->hist); + png_set_hIST(png_ptr, info_ptr, readbuf); } #endif @@ -1716,8 +1668,8 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } #else #ifdef PNG_FIXED_POINT_SUPPORTED - swidth = (png_charp)png_malloc(png_ptr, strlen(ep) + 1); - png_memcpy(swidth, ep, (png_size_t)strlen(ep)); + swidth = (png_charp)png_malloc(png_ptr, png_strlen(ep) + 1); + png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); #endif #endif @@ -1734,8 +1686,8 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } #else #ifdef PNG_FIXED_POINT_SUPPORTED - sheight = (png_charp)png_malloc(png_ptr, strlen(ep) + 1); - png_memcpy(sheight, ep, (png_size_t)strlen(ep)); + sheight = (png_charp)png_malloc(png_ptr, png_strlen(ep) + 1); + png_memcpy(sheight, ep, (png_size_t)png_strlen(ep)); #endif #endif @@ -1908,7 +1860,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #endif chunkdata = (png_charp)png_malloc(png_ptr, length + 1); - slength = (png_size_t)length; + slength = (png_size_t)length; png_crc_read(png_ptr, (png_bytep)chunkdata, slength); if (png_crc_finish(png_ptr, 0)) { @@ -1930,6 +1882,11 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) else { comp_type = *(++text); + if (comp_type != PNG_TEXT_COMPRESSION_zTXt) + { + png_warning(png_ptr, "Unknown compression type in zTXt chunk"); + comp_type = PNG_TEXT_COMPRESSION_zTXt; + } text++; /* skip the compression_method byte */ } prefix_len = text - chunkdata; @@ -2077,7 +2034,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != HANDLE_CHUNK_ALWAYS #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) - && png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL + && png_ptr->read_user_chunk_fn == NULL #endif ) #endif @@ -2097,12 +2054,12 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) length = (png_uint_32)65535L; } #endif - strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name); + png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name); chunk.data = (png_bytep)png_malloc(png_ptr, length); - png_crc_read(png_ptr, chunk.data, length); - chunk.size = length; + chunk.size = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)chunk.data, length); #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) - if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL) + if(png_ptr->read_user_chunk_fn != NULL) { /* callback to user unknown chunk handler */ if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0) @@ -2160,13 +2117,9 @@ png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name) a zero indicates the pixel is to be skipped. This is in addition to any alpha or transparency value associated with the pixel. If you want all pixels to be combined, pass 0xff (255) in mask. */ +#ifndef PNG_HAVE_ASSEMBLER_COMBINE_ROW void /* PRIVATE */ -#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW -png_combine_row_c -#else -png_combine_row -#endif /* PNG_HAVE_ASSEMBLER_COMBINE_ROW */ - (png_structp png_ptr, png_bytep row, int mask) +png_combine_row(png_structp png_ptr, png_bytep row, int mask) { png_debug(1,"in png_combine_row\n"); if (mask == 0xff) @@ -2366,25 +2319,28 @@ png_combine_row } } } +#endif /* !PNG_HAVE_ASSEMBLER_COMBINE_ROW */ -#if defined(PNG_READ_INTERLACING_SUPPORTED) -void /* PRIVATE */ -#ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE -png_do_read_interlace_c -#else -png_do_read_interlace -#endif /* PNG_HAVE_ASSEMBLER_READ_INTERLACE */ - (png_row_infop row_info, png_bytep row, int pass, +#ifdef PNG_READ_INTERLACING_SUPPORTED +#ifndef PNG_HAVE_ASSEMBLER_READ_INTERLACE /* else in pngvcrd.c, pnggccrd.c */ +/* OLD pre-1.0.9 interface: +void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, png_uint_32 transformations) + */ +void /* PRIVATE */ +png_do_read_interlace(png_structp png_ptr) { + png_row_infop row_info = &(png_ptr->row_info); + png_bytep row = png_ptr->row_buf + 1; + int pass = png_ptr->pass; + png_uint_32 transformations = png_ptr->transformations; #ifdef PNG_USE_LOCAL_ARRAYS /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - /* offset to next interlace block */ const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; #endif - png_debug(1,"in png_do_read_interlace\n"); + png_debug(1,"in png_do_read_interlace (stock C version)\n"); if (row != NULL && row_info != NULL) { png_uint_32 final_width; @@ -2594,15 +2550,12 @@ png_do_read_interlace return; #endif } -#endif +#endif /* !PNG_HAVE_ASSEMBLER_READ_INTERLACE */ +#endif /* PNG_READ_INTERLACING_SUPPORTED */ +#ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW void /* PRIVATE */ -#ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW -png_read_filter_row_c -#else -png_read_filter_row -#endif /* PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */ - (png_structp png_ptr, png_row_infop row_info, png_bytep row, +png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter) { png_debug(1, "in png_read_filter_row\n"); @@ -2723,6 +2676,7 @@ png_read_filter_row break; } } +#endif /* !PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */ void /* PRIVATE */ png_read_finish_row(png_structp png_ptr) @@ -3010,6 +2964,7 @@ 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); + png_ptr->row_buf_size = row_bytes; #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 754414e01..61de5dd00 100644 --- a/pngset.c +++ b/pngset.c @@ -1,9 +1,9 @@ /* pngset.c - storage of image information into info struct * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * @@ -109,9 +109,10 @@ png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) info_ptr->int_gamma = (int)(file_gamma*100000.+.5); #endif info_ptr->valid |= PNG_INFO_gAMA; + if(file_gamma == 0.0) + png_warning(png_ptr, "Setting gamma=0"); } #endif -#endif void PNGAPI png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point int_gamma) @@ -127,18 +128,43 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point info_ptr->int_gamma = int_gamma; #endif info_ptr->valid |= PNG_INFO_gAMA; + if(int_gamma == 0) + png_warning(png_ptr, "Setting gamma=0"); } +#endif #if defined(PNG_hIST_SUPPORTED) void PNGAPI png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) { + int i; + png_debug1(1, "in %s storage function\n", "hIST"); if (png_ptr == NULL || info_ptr == NULL) return; + if (info_ptr->num_palette == 0) + { + png_warning(png_ptr, + "Palette size 0, hIST allocation skipped."); + return; + } - info_ptr->hist = hist; +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); +#endif + png_ptr->hist = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(info_ptr->num_palette * sizeof (png_uint_16))); + + for (i = 0; i < info_ptr->num_palette; i++) + png_ptr->hist[i] = hist[i]; + info_ptr->hist = png_ptr->hist; info_ptr->valid |= PNG_INFO_hIST; + +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_HIST; +#else + png_ptr->flags |= PNG_FLAG_FREE_HIST; +#endif } #endif @@ -153,6 +179,61 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr, if (png_ptr == NULL || info_ptr == NULL) return; + /* check for width and height valid values */ + if (width == 0 || height == 0) + png_error(png_ptr, "Image width or height is zero in IHDR"); + if (width > PNG_MAX_UINT || height > PNG_MAX_UINT) + png_error(png_ptr, "Invalid image size in IHDR"); + + /* check other values */ + if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && + bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth in IHDR"); + + if (color_type < 0 || color_type == 1 || + color_type == 5 || color_type > 6) + png_error(png_ptr, "Invalid color type in IHDR"); + + if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || + ((color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) + png_error(png_ptr, "Invalid color type/bit depth combination in IHDR"); + + if (interlace_type >= PNG_INTERLACE_LAST) + png_error(png_ptr, "Unknown interlace method in IHDR"); + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + png_error(png_ptr, "Unknown compression method in IHDR"); + +#if defined(PNG_MNG_FEATURES_SUPPORTED) + /* Accept filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not read a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted) + png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n"); + if(filter_type != PNG_FILTER_TYPE_BASE) + { + if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && + ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA))) + png_error(png_ptr, "Unknown filter method in IHDR"); + if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) + png_warning(png_ptr, "Invalid filter method in IHDR"); + } +#else + if(filter_type != PNG_FILTER_TYPE_BASE) + png_error(png_ptr, "Unknown filter method in IHDR"); +#endif + info_ptr->width = width; info_ptr->height = height; info_ptr->bit_depth = (png_byte)bit_depth; @@ -229,6 +310,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr, (png_uint_32)((nparams + 1) * sizeof(png_charp))); + info_ptr->pcal_params[nparams] = NULL; for (i = 0; i < nparams; i++) @@ -283,7 +365,7 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, length = png_strlen(sheight) + 1; png_debug1(3, "allocating unit for info (%d bytes)\n", length); - info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length); + info_ptr->scal_s_height = (png_charp)png_malloc(png_ptr, length); png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); info_ptr->valid |= PNG_INFO_sCAL; @@ -320,9 +402,26 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr, if (png_ptr == NULL || info_ptr == NULL) return; - info_ptr->palette = palette; + /* + * It may not actually be necessary to set png_ptr->palette here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); +#endif + png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette, + sizeof (png_color)); + png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color)); + info_ptr->palette = png_ptr->palette; + info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; + +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_PLTE; +#else + png_ptr->flags |= PNG_FLAG_FREE_PLTE; +#endif - info_ptr->num_palette = (png_uint_16)num_palette; info_ptr->valid |= PNG_INFO_PLTE; } @@ -436,9 +535,9 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) return; - new_iccp_name = png_malloc(png_ptr, png_strlen(name)+1); - strcpy(new_iccp_name, name); - new_iccp_profile = png_malloc(png_ptr, proflen); + new_iccp_name = (png_charp)png_malloc(png_ptr, png_strlen(name)+1); + png_strcpy(new_iccp_name, name); + new_iccp_profile = (png_charp)png_malloc(png_ptr, proflen); png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); @@ -507,7 +606,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, png_size_t lang_len,lang_key_len; png_textp textp = &(info_ptr->text[info_ptr->num_text]); - if (text_ptr[i].key == (png_charp)NULL) + if (text_ptr[i].key == NULL) continue; key_len = png_strlen(text_ptr[i].key); @@ -521,11 +620,11 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, #ifdef PNG_iTXt_SUPPORTED { /* set iTXt data */ - if (text_ptr[i].key != (png_charp)NULL) + if (text_ptr[i].key != NULL) lang_len = png_strlen(text_ptr[i].lang); else lang_len = 0; - if (text_ptr[i].lang_key != (png_charp)NULL) + if (text_ptr[i].lang_key != NULL) lang_key_len = png_strlen(text_ptr[i].lang_key); else lang_key_len = 0; @@ -537,7 +636,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, } #endif - if (text_ptr[i].text == (png_charp)NULL || text_ptr[i].text[0] == '\0') + if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') { text_length = 0; #ifdef PNG_iTXt_SUPPORTED @@ -631,7 +730,24 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, return; if (trans != NULL) - info_ptr->trans = trans; + { + /* + * It may not actually be necessary to set png_ptr->trans here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); +#endif + png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, + num_trans); + png_memcpy(info_ptr->trans, trans, num_trans); +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_TRNS; +#else + png_ptr->flags |= PNG_FLAG_FREE_TRNS; +#endif + } if (trans_values != NULL) { @@ -667,12 +783,12 @@ png_set_sPLT(png_structp png_ptr, png_sPLT_tp from = entries + i; to->name = (png_charp)png_malloc(png_ptr, - png_strlen(from->name) + 1); + png_strlen(from->name) + 1); png_strcpy(to->name, from->name); to->entries = (png_sPLT_entryp)png_malloc(png_ptr, - from->nentries * sizeof(png_sPLT_t)); + from->nentries * sizeof(png_sPLT_t)); png_memcpy(to->entries, from->entries, - from->nentries * sizeof(png_sPLT_t)); + from->nentries * sizeof(png_sPLT_t)); to->nentries = from->nentries; to->depth = from->depth; } @@ -686,7 +802,7 @@ png_set_sPLT(png_structp png_ptr, } #endif /* PNG_sPLT_SUPPORTED */ -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) void PNGAPI png_set_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) @@ -788,8 +904,8 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep 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) + new_list=(png_bytep)png_malloc(png_ptr,5*(num_chunks+old_num_chunks)); + if(png_ptr->chunk_list != NULL) { png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); png_free(png_ptr, png_ptr->chunk_list); @@ -831,7 +947,6 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) info_ptr->row_pointers = row_pointers; if(row_pointers) info_ptr->valid |= PNG_INFO_IDAT; - } #endif @@ -842,8 +957,6 @@ png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size) png_free(png_ptr, png_ptr->zbuf); png_ptr->zbuf_size = (png_size_t)size; png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); - if(!png_ptr->zbuf) - png_error(png_ptr,"Unable to malloc zbuf"); png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; } @@ -854,3 +967,4 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) if (png_ptr && info_ptr) info_ptr->valid &= ~(mask); } + diff --git a/pngtrans.c b/pngtrans.c index ba03c0ee2..a3b80a38e 100644 --- a/pngtrans.c +++ b/pngtrans.c @@ -1,9 +1,9 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) */ @@ -392,11 +392,12 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) sp += 8; dp += 6; for (i = 1; i < row_width; i++) { - /* This could be (although memcpy is probably slower): + /* This could be (although png_memcpy is probably slower): png_memcpy(dp, sp, 6); sp += 8; dp += 6; */ + *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp++; @@ -411,11 +412,12 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */ for (i = 0; i < row_width; i++) { - /* This could be (although memcpy is probably slower): + /* This could be (although png_memcpy is probably slower): png_memcpy(dp, sp, 6); sp += 8; dp += 6; */ + sp+=2; *dp++ = *sp++; *dp++ = *sp++; diff --git a/pngvcrd.c b/pngvcrd.c index 522e71c96..b00a56d45 100644 --- a/pngvcrd.c +++ b/pngvcrd.c @@ -2,13 +2,20 @@ * * For Intel x86 CPU and Microsoft Visual C++ compiler * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * Copyright (c) 1998-2001 Glenn Randers-Pehrson * Copyright (c) 1998, Intel Corporation * * Contributed by Nirav Chhatrapati, Intel Corporation, 1998 * Interface to libpng contributed by Gilles Vollant, 1999 + * Debugging and cleanup by Greg Roelofs, 2000, 2001 + * + * In png_do_read_interlace() in libpng versions 1.0.3a through 1.0.4d, + * a sign error in the post-MMX cleanup code for each pixel_depth resulted + * in bad pixels at the beginning of some rows of some images, and also + * (due to out-of-range memory reads and writes) caused heap corruption + * when compiled with MSVC 6.0. The error was fixed in version 1.0.4e. * * [png_read_filter_row_mmx_avg() bpp == 2 bugfix, GRR 20000916] * @@ -19,19 +26,11 @@ #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD) -/* - One of these might need to be defined. -#define DISABLE_PNGVCRD_COMBINE -#define DISABLE_PNGVCRD_INTERLACE -*/ - static int mmx_supported=2; -void /* PRIVATE */ -png_read_filter_row_c(png_structp png_ptr, png_row_infop row_info, - png_bytep row, png_bytep prev_row, int filter); -static int mmxsupport() +int PNGAPI +png_mmx_support(void) { int mmx_supported_local = 0; _asm { @@ -83,6 +82,7 @@ NOT_SUPPORTED: //mmx_supported_local=0; // test code for force don't support MMX //printf("MMX : %u (1=MMX supported)\n",mmx_supported_local); + mmx_supported = mmx_supported_local; return mmx_supported_local; } @@ -106,19 +106,12 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) #ifdef PNG_USE_LOCAL_ARRAYS const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; #endif -#ifdef DISABLE_PNGVCRD_COMBINE - int save_mmx_supported = mmx_supported; -#endif png_debug(1,"in png_combine_row_asm\n"); -#ifdef DISABLE_PNGVCRD_COMBINE - if ((png_ptr->transformations & PNG_INTERLACE) && png_ptr->pass != 6) - mmx_supported = 0; - else -#endif - if (mmx_supported == 2) - mmx_supported = mmxsupport(); + if (mmx_supported == 2) { + png_mmx_support(); + } if (mask == 0xff) { @@ -307,7 +300,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask) __int64 mask0=0x0102040810204080; - if (mmx_supported) + if ( mmx_supported ) { srcptr = png_ptr->row_buf + 1; dstptr = row; @@ -389,6 +382,8 @@ end8: incr1 = (disp)*pixel_bytes; for (i = initial_val; i < final_val; i += incr1) { + if (pixel_bytes > (png_size_t)(final_val-i)) + pixel_bytes = (png_size_t)(final_val-i); png_memcpy(dstptr, srcptr, pixel_bytes); srcptr += incr1; dstptr += incr1; @@ -407,7 +402,7 @@ end8: __int64 mask1=0x0101020204040808, mask0=0x1010202040408080; - if (mmx_supported) + if ( mmx_supported ) { srcptr = png_ptr->row_buf + 1; dstptr = row; @@ -500,6 +495,8 @@ end16: incr1 = (disp)*pixel_bytes; for (i = initial_val; i < final_val; i += incr1) { + if (pixel_bytes > (png_size_t)(final_val-i)) + pixel_bytes = (png_size_t)(final_val-i); png_memcpy(dstptr, srcptr, pixel_bytes); srcptr += incr1; dstptr += incr1; @@ -527,7 +524,7 @@ end16: len = (png_ptr->width)&~7; diff = (png_ptr->width)&7; - if (mmx_supported) + if ( mmx_supported ) { _asm { @@ -630,6 +627,8 @@ end24: incr1 = (disp)*pixel_bytes; for (i = initial_val; i < final_val; i += incr1) { + if (pixel_bytes > (png_size_t)(final_val-i)) + pixel_bytes = (png_size_t)(final_val-i); png_memcpy(dstptr, srcptr, pixel_bytes); srcptr += incr1; dstptr += incr1; @@ -658,7 +657,7 @@ end24: len = (png_ptr->width)&~7; diff = (png_ptr->width)&7; - if (mmx_supported) + if ( mmx_supported ) { _asm { @@ -769,6 +768,8 @@ end32: incr1 = (disp)*pixel_bytes; for (i = initial_val; i < final_val; i += incr1) { + if (pixel_bytes > (png_size_t)(final_val-i)) + pixel_bytes = (png_size_t)(final_val-i); png_memcpy(dstptr, srcptr, pixel_bytes); srcptr += incr1; dstptr += incr1; @@ -792,7 +793,7 @@ end32: mask1=0x2020202040404040, mask0=0x4040808080808080; - if (mmx_supported) + if ( mmx_supported ) { srcptr = png_ptr->row_buf + 1; dstptr = row; @@ -926,6 +927,8 @@ end48: incr1 = (disp)*pixel_bytes; for (i = initial_val; i < final_val; i += incr1) { + if (pixel_bytes > (png_size_t)(final_val-i)) + pixel_bytes = (png_size_t)(final_val-i); png_memcpy(dstptr, srcptr, pixel_bytes); srcptr += incr1; dstptr += incr1; @@ -954,6 +957,8 @@ end48: incr1 = (disp)*pixel_bytes; for (i = initial_val; i < final_val; i += incr1) { + if (pixel_bytes > (png_size_t)(final_val-i)) + pixel_bytes = (png_size_t)(final_val-i); png_memcpy(dp, sptr, pixel_bytes); sptr += incr1; dp += incr1; @@ -963,43 +968,27 @@ end48: } /* end switch (png_ptr->row_info.pixel_depth) */ } /* end if (non-trivial mask) */ -#ifdef DISABLE_PNGVCRD_COMBINE - mmx_supported = save_mmx_supported; -#endif - } /* end png_combine_row() */ #if defined(PNG_READ_INTERLACING_SUPPORTED) void /* PRIVATE */ -png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, - png_uint_32 transformations) +png_do_read_interlace(png_structp png_ptr) { + png_row_infop row_info = &(png_ptr->row_info); + png_bytep row = png_ptr->row_buf + 1; + int pass = png_ptr->pass; + png_uint_32 transformations = png_ptr->transformations; #ifdef PNG_USE_LOCAL_ARRAYS const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; #endif -#ifdef DISABLE_PNGVCRD_INTERLACE - int save_mmx_supported = mmx_supported; -#endif png_debug(1,"in png_do_read_interlace\n"); -#ifdef DISABLE_PNGVCRD_INTERLACE - /* In libpng versions 1.0.3a through 1.0.4d, - * a sign error in the post-MMX cleanup code for each pixel_depth resulted - * in bad pixels at the beginning of some rows of some images, and also - * (due to out-of-range memory reads and writes) caused heap corruption - * when compiled with MSVC 6.0. The error was fixed in version 1.0.4e, - * and the code appears to work completely correctly, so it is enabled - * by default. - */ - if (1) /* all passes caused a heap problem in the old code */ - mmx_supported = 0; - else -#endif - if (mmx_supported == 2) - mmx_supported = mmxsupport(); + if (mmx_supported == 2) { + png_mmx_support(); + } if (row != NULL && row_info != NULL) { @@ -1197,7 +1186,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, // sign fix by GRR // NOTE: there is NO MMX code for 48-bit and 64-bit images - if (mmx_supported) // use MMX routine if machine supports it + // use MMX routine if machine supports it + if ( mmx_supported ) { if (pixel_bytes == 3) { @@ -1787,7 +1777,7 @@ loop4_pass4: } /* end of mmx_supported */ else /* MMX not supported: use modified C code - takes advantage - * of inlining of memcpy for a constant */ + * of inlining of png_memcpy for a constant */ { if (pixel_bytes == 1) { @@ -1885,9 +1875,6 @@ loop4_pass4: (png_uint_32)row_info->pixel_depth + 7) >> 3); } -#ifdef DISABLE_PNGVCRD_INTERLACE - mmx_supported = save_mmx_supported; -#endif } #endif /* PNG_READ_INTERLACING_SUPPORTED */ @@ -3323,7 +3310,7 @@ dsub3lp: case 1: { // Placed here just in case this is a duplicate of the - // non-MMX code for the SUB filter in png_read_filter_row above + // non-MMX code for the SUB filter in png_read_filter_row below // // png_bytep rp; // png_bytep lp; @@ -3658,61 +3645,50 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter) { #ifdef PNG_DEBUG - char filnm[6]; + char filnm[10]; #endif -#define UseMMX 1 - if (mmx_supported == 2) - mmx_supported = mmxsupport(); - - if (!mmx_supported) - { - png_read_filter_row_c(png_ptr, row_info, row, prev_row, filter); - return ; + if (mmx_supported == 2) { + png_mmx_support(); } #ifdef PNG_DEBUG png_debug(1, "in png_read_filter_row\n"); -# if (UseMMX == 1) - png_debug1(0,"%s, ", "MMX"); -# else - png_debug1(0,"%s, ", "x86"); -# endif switch (filter) { - case 0: sprintf(filnm, "None "); + case 0: sprintf(filnm, "none"); break; - case 1: sprintf(filnm, "Sub "); + case 1: sprintf(filnm, "sub-%s", "MMX"); break; - case 2: sprintf(filnm, "Up "); + case 2: sprintf(filnm, "up-%s", "MMX"); break; - case 3: sprintf(filnm, "Avg "); + case 3: sprintf(filnm, "avg-%s", "MMX"); break; - case 4: sprintf(filnm, "Paeth"); + case 4: sprintf(filnm, "Paeth-%s", "MMX"); break; - default: sprintf(filnm, "Unknw"); + default: sprintf(filnm, "unknw"); break; } png_debug2(0,"row=%5d, %s, ", png_ptr->row_number, filnm); png_debug2(0, "pd=%2d, b=%d, ", (int)row_info->pixel_depth, (int)((row_info->pixel_depth + 7) >> 3)); png_debug1(0,"len=%8d, ", row_info->rowbytes); -#endif +#endif /* PNG_DEBUG */ switch (filter) { case PNG_FILTER_VALUE_NONE: break; + case PNG_FILTER_VALUE_SUB: { -#if (UseMMX == 1) - if ((row_info->pixel_depth > 8) && - (row_info->rowbytes >= 128) ) + if ( + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_sub(row_info, row); } else -#endif { png_uint_32 i; png_uint_32 istop = row_info->rowbytes; @@ -3725,41 +3701,43 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff); rp++; } - } //end !UseMMX + } break; } + case PNG_FILTER_VALUE_UP: { -#if (UseMMX == 1) - if ((row_info->pixel_depth > 8) && - (row_info->rowbytes >= 128) ) + if ( + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_up(row_info, row, prev_row); - } //end if UseMMX + } else -#endif { - png_bytep rp; - png_bytep pp; png_uint_32 i; - for (i = 0, rp = row, pp = prev_row; - i < row_info->rowbytes; i++, rp++, pp++) + png_uint_32 istop = row_info->rowbytes; + png_bytep rp = row; + png_bytep pp = prev_row; + + for (i = 0; i < istop; ++i) { - *rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff); + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; } - } //end !UseMMX + } break; } + case PNG_FILTER_VALUE_AVG: { -#if (UseMMX == 1) - if ((row_info->pixel_depth > 8) && - (row_info->rowbytes >= 128) ) + if ( + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_avg(row_info, row, prev_row); - } //end if UseMMX + } else -#endif { png_uint_32 i; png_bytep rp = row; @@ -3781,19 +3759,19 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep ((int)(*pp++ + *lp++) >> 1)) & 0xff); rp++; } - } //end !UseMMX + } break; } + case PNG_FILTER_VALUE_PAETH: { -#if (UseMMX == 1) - if ((row_info->pixel_depth > 8) && - (row_info->rowbytes >= 128) ) + if ( + (row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) && + (row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT)) { png_read_filter_row_mmx_paeth(row_info, row, prev_row); - } //end if UseMMX + } else -#endif { png_uint_32 i; png_bytep rp = row; @@ -3844,13 +3822,15 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep *rp = (png_byte)(((int)(*rp) + p) & 0xff); rp++; } - } //end !UseMMX + } break; } + default: - png_warning(png_ptr, "Ignoring bad adaptive filter type"); + png_warning(png_ptr, "Ignoring bad row filter type"); *row=0; break; } } -#endif + +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED && PNG_USE_PNGVCRD */ diff --git a/pngwio.c b/pngwio.c index ce9f45b92..a5bd4570a 100644 --- a/pngwio.c +++ b/pngwio.c @@ -1,9 +1,9 @@ /* pngwio.c - functions for data output * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) * @@ -17,6 +17,7 @@ #define PNG_INTERNAL #include "png.h" +#ifdef PNG_WRITE_SUPPORTED /* Write the data to whatever output you are using. The default routine writes to a file pointer. Note that this routine sometimes gets called @@ -224,3 +225,4 @@ void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check) } # endif # endif +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/pngwrite.c b/pngwrite.c index fd27da153..e0291d39d 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,9 +1,9 @@ /* pngwrite.c - general routines to write a PNG file * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) */ @@ -11,6 +11,7 @@ /* get internal access to png.h */ #define PNG_INTERNAL #include "png.h" +#ifdef PNG_WRITE_SUPPORTED /* Writes all the PNG information. This is the suggested way to use the * library. If you have a new chunk to add, make a function to write it, @@ -28,6 +29,13 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) { png_write_sig(png_ptr); /* write PNG signature */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) + if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) + { + png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n"); + png_ptr->mng_features_permitted=0; + } +#endif /* write IHDR information. */ png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, @@ -57,7 +65,7 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) #endif #if defined(PNG_WRITE_iCCP_SUPPORTED) if (info_ptr->valid & PNG_INFO_iCCP) - png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_TEXT_COMPRESSION_zTXt, + png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); #endif #if defined(PNG_WRITE_sBIT_SUPPORTED) @@ -774,6 +782,15 @@ png_write_row(png_structp png_ptr, png_bytep row) png_do_write_transformations(png_ptr); #if defined(PNG_MNG_FEATURES_SUPPORTED) + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) { @@ -908,7 +925,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) /* Free any memory used in png_ptr struct (old method) */ -void PNGAPI +void /* PRIVATE */ png_write_destroy(png_structp png_ptr) { #ifdef PNG_SETJMP_SUPPORTED @@ -977,6 +994,11 @@ void PNGAPI png_set_filter(png_structp png_ptr, int method, int filters) { png_debug(1, "in png_set_filter\n"); +#if defined(PNG_MNG_FEATURES_SUPPORTED) + if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (method == PNG_INTRAPIXEL_DIFFERENCING)) + method = PNG_FILTER_TYPE_BASE; +#endif if (method == PNG_FILTER_TYPE_BASE) { switch (filters & (PNG_ALL_FILTERS | 0x07)) @@ -1116,12 +1138,11 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, if (png_ptr->filter_weights == NULL) { - png_ptr->filter_weights = (png_uint_16p) png_malloc(png_ptr, + png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, (png_uint_32)(sizeof(png_uint_16) * num_weights)); - png_ptr->inv_filter_weights = (png_uint_16p) png_malloc(png_ptr, + png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, (png_uint_32)(sizeof(png_uint_16) * num_weights)); - for (i = 0; i < num_weights; i++) { png_ptr->inv_filter_weights[i] = @@ -1151,10 +1172,10 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, */ if (png_ptr->filter_costs == NULL) { - png_ptr->filter_costs = (png_uint_16p) png_malloc(png_ptr, + png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); - png_ptr->inv_filter_costs = (png_uint_16p) png_malloc(png_ptr, + png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) @@ -1338,7 +1359,8 @@ png_write_png(png_structp png_ptr, png_infop info_ptr, /* It is REQUIRED to call this to finish writing the rest of the file */ png_write_end(png_ptr, info_ptr); - if(transforms == 0 || params == (voidp)NULL) + if(transforms == 0 || params == NULL) /* quiet compiler warnings */ return; } #endif +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/pngwtran.c b/pngwtran.c index 5dd7007e9..fc18c6033 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -1,15 +1,16 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * libpng 1.0.9beta5 - December 15, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) */ #define PNG_INTERNAL #include "png.h" +#ifdef PNG_WRITE_SUPPORTED /* Transform the data according to the user's wishes. The order of * transformations is significant. @@ -559,3 +560,4 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row) } } #endif /* PNG_MNG_FEATURES_SUPPORTED */ +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/pngwutil.c b/pngwutil.c index 2dd462ecc..b8c822269 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,15 +1,16 @@ /* pngwutil.c - utilities to write a PNG file * - * libpng 1.0.9beta5 - December 14, 2000 + * libpng 1.0.11 - April 27, 2001 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson + * 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.) */ #define PNG_INTERNAL #include "png.h" +#ifdef PNG_WRITE_SUPPORTED /* Place a 32-bit number into a buffer in PNG byte order. We work * with unsigned numbers for convenience, although one supported @@ -131,6 +132,8 @@ png_write_sig(png_structp png_ptr) /* write the rest of the 8 byte signature */ png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], (png_size_t)8 - png_ptr->sig_bytes); + if(png_ptr->sig_bytes < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; } #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) @@ -232,8 +235,8 @@ png_text_compress(png_structp png_ptr, old_ptr = comp->output_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)); + png_memcpy(comp->output_ptr, old_ptr, old_max + * sizeof (png_charp)); png_free(png_ptr, old_ptr); } else @@ -282,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 @@ -419,9 +422,21 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, compression_type = PNG_COMPRESSION_TYPE_BASE; } + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ if ( #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_ALPHA) && (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && #endif filter_type != PNG_FILTER_TYPE_BASE) @@ -520,7 +535,8 @@ 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) +#if defined(PNG_MNG_FEATURES_SUPPORTED) || \ + defined (PNG_WRITE_EMPTY_PLTE_SUPPORTED) !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && #endif num_pal == 0) || num_pal > 256) @@ -663,7 +679,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, return; } - if (compression_type) + if (compression_type != PNG_COMPRESSION_TYPE_BASE) png_warning(png_ptr, "Unknown compression type in iCCP chunk"); if (profile == NULL) @@ -671,7 +687,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, if (profile_len) profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len, - PNG_TEXT_COMPRESSION_zTXt, &comp); + PNG_COMPRESSION_TYPE_BASE, &comp); /* make sure we include the NULL after the name and the compression type */ png_write_chunk_start(png_ptr, (png_bytep)png_iCCP, @@ -714,7 +730,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) } /* make sure we include the NULL after the name */ - png_write_chunk_start(png_ptr, (png_bytep) png_sPLT, + png_write_chunk_start(png_ptr, (png_bytep)png_sPLT, (png_uint_32)(name_len + 2 + palette_size)); png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1); png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1); @@ -1003,7 +1019,8 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) if (color_type == PNG_COLOR_TYPE_PALETTE) { if ( -#if defined(PNG_MNG_FEATURES_SUPPORTED) +#if defined(PNG_MNG_FEATURES_SUPPORTED) || \ + defined (PNG_WRITE_EMPTY_PLTE_SUPPORTED) (png_ptr->num_palette || (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && #endif @@ -1092,7 +1109,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++) { @@ -1472,8 +1489,8 @@ png_write_sCAL(png_structp png_ptr, int unit, double width,double height) png_debug1(3, "sCAL total length = %d\n", 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, strlen(wbuf)+1); - png_write_chunk_data(png_ptr, (png_bytep)hbuf, strlen(hbuf)); + png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1); + png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf)); png_write_chunk_end(png_ptr); } @@ -1491,15 +1508,15 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, png_debug(1, "in png_write_sCAL_s\n"); - strcpy(wbuf,(const char *)width); - strcpy(hbuf,(const char *)height); + png_strcpy(wbuf,(const char *)width); + png_strcpy(hbuf,(const char *)height); total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf); png_debug1(3, "sCAL total length = %d\n", 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, strlen(wbuf)+1); - png_write_chunk_data(png_ptr, (png_bytep)hbuf, strlen(hbuf)); + png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1); + png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf)); png_write_chunk_end(png_ptr); } @@ -2617,3 +2634,4 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) } #endif } +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/zlib.h b/zlib.h index fb310ea9e..c9764b504 100644 --- a/zlib.h +++ b/zlib.h @@ -32,6 +32,9 @@ * * The default value of TOO_FAR has been changed to 32767 in deflate.c * Glenn Randers-Pehrson, February 2000. + * + * The switch statement in inflate.c was rearranged so that case BLOCKS is + * checked first. Glenn Randers-Pehrson, April 2001. */ #ifndef _ZLIB_H