diff --git a/inflate.c b/inflate.c index 08e3025c6..1e4cf8bca 100644 --- a/inflate.c +++ b/inflate.c @@ -237,7 +237,6 @@ int f; break; } z->state->mode = CHECK4; - r=Z_DATA_ERROR; case CHECK4: NEEDBYTE z->state->sub.check.need = (uLong)NEXTBYTE << 24; diff --git a/png.c b/png.c index 7f8592b55..325e1d01f 100644 --- a/png.c +++ b/png.c @@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions * - * libpng version 1.0.7rc2 - June 28, 2000 + * libpng version 1.0.8rc1 - July 17, 2000 * Copyright (c) 1998, 1999, 2000 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.) @@ -10,18 +10,17 @@ #define PNG_INTERNAL #define PNG_NO_EXTERN -#include #include "png.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_0_7rc2 Your_png_h_is_not_version_1_0_7rc2; +typedef version_1_0_8rc1 Your_png_h_is_not_version_1_0_8rc1; /* 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 */ -char png_libpng_ver[12] = "1.0.7rc2"; +char png_libpng_ver[12] = "1.0.8rc1"; /* png_sig was changed to a function in version 1.0.5c */ /* Place to hold the signature string for a PNG file. */ @@ -141,6 +140,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size) png_uint_32 num_bytes = (png_uint_32)items * size; png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); +#ifndef PNG_NO_ZALLOC_ZERO if (num_bytes > (png_uint_32)0x8000L) { png_memset(ptr, 0, (png_size_t)0x8000L); @@ -151,6 +151,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size) { png_memset(ptr, 0, (png_size_t)num_bytes); } +#endif return ((voidpf)ptr); } @@ -362,7 +363,10 @@ if (mask & PNG_FREE_PCAL) { int i; for (i = 0; i < (int)info_ptr->pcal_nparams; i++) + { png_free(png_ptr, info_ptr->pcal_params[i]); + info_ptr->pcal_params[i]=NULL; + } png_free(png_ptr, info_ptr->pcal_params); info_ptr->pcal_params = NULL; } @@ -492,7 +496,10 @@ if (mask & PNG_FREE_ROWS) { int row; for (row = 0; row < (int)info_ptr->height; row++) + { png_free(png_ptr, info_ptr->row_pointers[row]); + info_ptr->row_pointers[row]=NULL; + } png_free(png_ptr, info_ptr->row_pointers); info_ptr->row_pointers=NULL; } @@ -523,6 +530,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr) if (png_ptr->num_chunk_list) { png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; png_ptr->num_chunk_list=0; } #endif @@ -548,7 +556,7 @@ png_get_io_ptr(png_structp png_ptr) * necessarily available. */ void PNGAPI -png_init_io(png_structp png_ptr, FILE *fp) +png_init_io(png_structp png_ptr, png_FILE_p fp) { png_debug(1, "in png_init_io\n"); png_ptr->io_ptr = (png_voidp)fp; @@ -572,6 +580,17 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) sizeof(char))); } +#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); + } +#else #ifdef USE_FAR_KEYWORD { char near_time_buf[29]; @@ -588,6 +607,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) ptime->year, ptime->hour % 24, ptime->minute % 60, ptime->second % 61); #endif +#endif /* _WIN32_WCE */ return ((png_charp)png_ptr->time_buffer); } #endif /* PNG_TIME_RFC1123_SUPPORTED */ @@ -605,11 +625,11 @@ png_charp PNGAPI png_get_copyright(png_structp png_ptr) { if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */ - return ("\n libpng version 1.0.7rc2 - June 28, 2000\n\ + return ((png_charp) "\n libpng version 1.0.8rc1 - July 17, 2000\n\ Copyright (c) 1998-2000 Glenn Randers-Pehrson\n\ Copyright (c) 1996, 1997 Andreas Dilger\n\ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n"); - return (""); + return ((png_charp) ""); } /* The following return the library version as a short string in the @@ -623,8 +643,8 @@ png_get_libpng_ver(png_structp png_ptr) { /* Version of *.c files used when building libpng */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return("1.0.7rc2"); - return("1.0.7rc2"); + return((png_charp) "1.0.8rc1"); + return((png_charp) "1.0.8rc1"); } png_charp PNGAPI @@ -632,8 +652,8 @@ png_get_header_ver(png_structp png_ptr) { /* Version of *.h files used when building libpng */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return(PNG_LIBPNG_VER_STRING); - return(PNG_LIBPNG_VER_STRING); + return((png_charp) PNG_LIBPNG_VER_STRING); + return((png_charp) PNG_LIBPNG_VER_STRING); } png_charp PNGAPI @@ -641,8 +661,8 @@ png_get_header_version(png_structp png_ptr) { /* Returns longer string containing both version and date */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ - return(PNG_HEADER_VERSION_STRING); - return(PNG_HEADER_VERSION_STRING); + return((png_charp) PNG_HEADER_VERSION_STRING); + return((png_charp) PNG_HEADER_VERSION_STRING); } #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED @@ -673,5 +693,5 @@ png_uint_32 PNGAPI png_access_version_number(void) { /* Version of *.c files used when building libpng */ - return((png_uint_32) 10007L); + return((png_uint_32) 10008L); } diff --git a/png.h b/png.h index b5bdc4efb..aeb86ef63 100644 --- a/png.h +++ b/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.0.7rc2 - June 28, 2000 + * libpng version 1.0.8rc1 - July 17, 2000 * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -9,7 +9,7 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.0.7rc2 - June 28, 2000: Glenn + * libpng versions 0.97, January 1998, through 1.0.8rc1 - July 17, 2000: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -54,9 +54,9 @@ * 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) - * planned: - * 1.0.6patch4 (w/4 patches) 10006 2.1.0.6 (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 * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -83,17 +83,26 @@ * If you modify libpng you may insert additional notices immediately following * this sentence. * - * libpng versions 1.0.6, March 20, 2000, through 1.0.7rc2, June 28, 2000, are + * libpng version 1.0.8rc1, July 17, 2000, is * Copyright (c) 2000 Glenn Randers-Pehrson - * Distributed according to the same disclaimer and license as libpng-1.0.5 - * with the following individuals added to the list of Contributing Authors: + * Distributed according to the same disclaimer and license as libpng-1.0.6 + * with the following individuals added to the list of Contributing Authors * * Simon-Pierre Cadieux * Eric S. Raymond * Gilles Vollant * - * libpng versions 0.97, January 1998, through 1.0.5, October 15, 1999, are - * Copyright (c) 1998, 1999 Glenn Randers-Pehrson + * and with the following additions to the disclaimer: + * + * There is no warranty against interference with your enjoyment of the + * library or against infringement. There is no warranty that our + * efforts or the library will fulfill any of your particular purposes + * or needs. This library is provided with all faults, and the entire + * risk of satisfactory quality, performance, accuracy, and effort is with + * the user. + * + * libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are + * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * Distributed according to the same disclaimer and license as libpng-0.96, * with the following individuals added to the list of Contributing Authors: * @@ -159,7 +168,7 @@ * printf("%s",png_get_copyright(NULL)); * * Also, the PNG logo (in PNG format, of course) is supplied in the - * file "pngnow.png". + * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). */ /* @@ -179,13 +188,13 @@ * Y2K compliance in libpng: * ========================= * - * June 28, 2000 + * July 17, 2000 * * 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.7rc2 are Y2K compliant. It is my belief that earlier + * upward through 1.0.8rc1 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 @@ -241,24 +250,24 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.0.7rc2" +#define PNG_LIBPNG_VER_STRING "1.0.8rc1" #define PNG_LIBPNG_VER_SONUM 2 /* 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 7 +#define PNG_LIBPNG_VER_RELEASE 8 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ -#define PNG_LIBPNG_VER_BUILD 2 +#define PNG_LIBPNG_VER_BUILD 1 /* 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 10007 /* 1.0.7 */ +#define PNG_LIBPNG_VER 10008 /* 1.0.8 */ /* Note to maintainer: update this number in scripts/pngdef.pas as well */ @@ -656,11 +665,10 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) * range given by [pcal_X0, pcal_X1], and are further transformed by a * (possibly non-linear) transformation function given by "pcal_type" * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_ - * defines below, and the PNG-Group's Scientific Visualization extension - * chunks document png-scivis-19970203 for a complete description of the - * transformations and how they should be implemented, as well as the - * png-extensions document for a description of the ASCII parameter - * strings. Data values are valid if (valid & PNG_INFO_pCAL) non-zero. + * defines below, and the PNG-Group's PNG extensions document for a + * complete description of the transformations and how they should be + * implemented, and for a description of the ASCII parameter strings. + * Data values are valid if (valid & PNG_INFO_pCAL) non-zero. */ png_charp pcal_purpose; /* pCAL chunk description string */ png_int_32 pcal_X0; /* minimum value */ @@ -1140,9 +1148,9 @@ struct png_struct_def }; /* This prevents a compiler error in png_get_copyright() in png.c if png.c -and png.h are both at * version 1.0.7rc2 +and png.h are both at * version 1.0.8rc1 */ -typedef png_structp version_1_0_7rc2; +typedef png_structp version_1_0_8rc1; typedef png_struct FAR * FAR * png_structpp; @@ -1241,6 +1249,8 @@ extern PNG_EXPORT(png_charp,png_convert_to_rfc1123) PNGARG((png_structp png_ptr, png_timep ptime)); #endif +#if !defined(_WIN32_WCE) +/* "time.h" functions are not supported on WindowsCE */ #if defined(PNG_WRITE_tIME_SUPPORTED) /* convert from a struct tm to png_time */ extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, @@ -1250,6 +1260,7 @@ extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime, time_t ttime)); #endif /* PNG_WRITE_tIME_SUPPORTED */ +#endif /* _WIN32_WCE */ #if defined(PNG_READ_EXPAND_SUPPORTED) /* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ @@ -1583,7 +1594,7 @@ extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr, #if !defined(PNG_NO_STDIO) /* Initialize the input/output for the PNG file to the default functions. */ -extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, FILE *fp)); +extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp)); #endif /* Replace the (error and abort), and warning functions with user @@ -2121,25 +2132,35 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, #if (PNG_DEBUG > 0) #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) #include -#define png_debug(l,m) if (PNG_DEBUG > l) _RPT0(_CRT_WARN,m) -#define png_debug1(l,m,p1) if (PNG_DEBUG > l) _RPT1(_CRT_WARN,m,p1) -#define png_debug2(l,m,p1,p2) if (PNG_DEBUG > l) _RPT2(_CRT_WARN,m,p1,p2) +#if (PNG_DEBUG > 1) +#define png_debug(l,m) _RPT0(_CRT_WARN,m) +#define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1) +#define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2) +#endif #else /* PNG_DEBUG_FILE || !_MSC_VER */ #ifndef PNG_DEBUG_FILE #define PNG_DEBUG_FILE stderr #endif /* PNG_DEBUG_FILE */ +#if (PNG_DEBUG > 1) #define png_debug(l,m) \ - if (PNG_DEBUG > l) \ - fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \ - (l==2 ? "\t\t":(l>2 ? "\t\t\t":"")))) +{ \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \ +} #define png_debug1(l,m,p1) \ - if (PNG_DEBUG > l) \ - fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \ - (l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1) +{ \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \ +} #define png_debug2(l,m,p1,p2) \ - if (PNG_DEBUG > l) \ - fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \ - (l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1,p2) +{ \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \ +} +#endif /* (PNG_DEBUG > 1) */ #endif /* _MSC_VER */ #endif /* (PNG_DEBUG > 0) */ #endif /* PNG_DEBUG */ @@ -2161,7 +2182,7 @@ extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr) extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr)); #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.0.7rc2 - June 28, 2000 (header)\n" + " libpng version 1.0.8rc1 - July 17, 2000 (header)\n" #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* With these routines we avoid an integer divide, which will be slower on diff --git a/pngasmrd.h b/pngasmrd.h index 7e72db409..3e08d6c94 100644 --- a/pngasmrd.h +++ b/pngasmrd.h @@ -1,6 +1,6 @@ /* pngasmrd.h - assembler version of utilities to read a PNG file * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1999, 2000 Glenn Randers-Pehrson * diff --git a/pngconf.h b/pngconf.h index 541d10199..ac5a96b95 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,6 +1,6 @@ /* pngconf.h - machine configurable file for libpng * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -51,6 +51,60 @@ #define PNG_MAX_MALLOC_64K #endif +/* Special munging to support doing things the 'cygwin' way: + * 'Normal' png-on-win32 defines/defaults: + * PNG_BUILD_DLL -- building dll + * PNG_USE_DLL -- building an application, linking to dll + * (no define) -- building static library, or building an + * application and linking to the static lib + * 'Cygwin' defines/defaults: + * 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. + * 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 + * that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but + * unnecessary. + */ +#if defined(__CYGWIN__) +# if defined(PNG_BUILD_DLL) +# if defined(PNG_USE_DLL) +# undef PNG_USE_DLL +# endif +# if !defined(PNG_DLL) +# define PNG_DLL +# endif +# if defined(PNG_STATIC) +# undef PNG_STATIC +# endif +# else +# if defined(PNG_STATIC) +# if defined(PNG_USE_DLL) +# undef PNG_USE_DLL +# endif +# if defined(PNG_DLL) +# undef PNG_DLL +# endif +# else +# if defined(PNG_USE_DLL) +# if !defined(PNG_DLL) +# define PNG_DLL +# endif +# else +# if defined(PNG_DLL) +# define PNG_USE_DLL +# else +# define PNG_USE_DLL +# define PNG_DLL +# endif +# endif +# endif +# endif +#endif + + /* This protects us against compilers that run on a windowing system * and thus don't have or would rather us not use the stdio types: * stdin, stdout, and stderr. The only one currently used is stderr @@ -64,6 +118,15 @@ * #define PNG_NO_STDIO */ +#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 +#endif + #ifdef PNG_BUILD_DLL # ifndef PNG_CONSOLE_IO_SUPPORTED # ifndef PNG_NO_CONSOLE_IO @@ -82,7 +145,10 @@ # endif # endif # else -# include +# if !defined(_WIN32_WCE) +/* "stdio.h" functions are not supported on WindowsCE */ +# include +# endif # endif /* This macro protects us against machines that don't have function @@ -120,7 +186,7 @@ #endif /* enough people need this for various reasons to include it here */ -#if !defined(MACOS) && !defined(RISCOS) +#if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE) #include #endif @@ -524,6 +590,9 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #ifndef PNG_NO_USER_MEM #define PNG_USER_MEM_SUPPORTED #endif +#ifndef PNG_NO_ZALLOC_ZERO +#define PNG_ZALLOC_ZERO +#endif */ /* This is only for PowerPC big-endian and 680x0 systems */ @@ -642,7 +711,7 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED # endif #endif -#if !defined (PNG_NO_READ_USER_CHUNKS) && \ +#if !defined(PNG_NO_READ_USER_CHUNKS) && \ defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) # define PNG_READ_USER_CHUNKS_SUPPORTED # define PNG_USER_CHUNKS_SUPPORTED @@ -801,7 +870,10 @@ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) /* need the time information for reading tIME chunks */ #if defined(PNG_tIME_SUPPORTED) -# include +# if !defined(_WIN32_WCE) + /* "time.h" functions are not supported on WindowsCE */ +# include +# endif #endif /* Some typedefs to get us started. These should be safe on most of the @@ -841,7 +913,7 @@ typedef size_t png_size_t; #define LDATA 0 #endif -#if !defined(__WIN32__) && !defined(__FLAT__) +#if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) #define PNG_MAX_MALLOC_64K #if (LDATA != 1) #ifndef FAR @@ -855,7 +927,7 @@ typedef size_t png_size_t; * const if your compiler supports it. (SJT) # define FARDATA FAR */ -#endif /* __WIN32__, __FLAT__ */ +#endif /* __WIN32__, __FLAT__, __CYGWIN__ */ #endif /* __BORLANDC__ */ @@ -898,6 +970,11 @@ 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; +#if defined(_WIN32_WCE) +typedef HANDLE png_FILE_p; +#else +typedef FILE * png_FILE_p; +#endif #ifdef PNG_FLOATING_POINT_SUPPORTED typedef double FAR * png_doublep; #endif @@ -934,12 +1011,43 @@ typedef z_stream FAR * png_zstreamp; * It is equivalent to Microsoft predefined macro _DLL which is * automatically defined when you compile using the share * version of the CRT (C Run-Time library) + * + * The cygwin mods make this behavior a little different: + * Define PNG_BUILD_DLL if you are building a dll for use with cygwin + * Define PNG_STATIC if you are building a static library for use with cygwin, + * -or- if you are building an application that you want to link to the + * static library. + * PNG_USE_DLL is defined by default (no user action needed) unless one of + * the other flags is defined. */ #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL)) # define PNG_DLL #endif - +/* If CYGWIN, then disallow GLOBAL ARRAYS unless building a static lib. + * When building a static lib, default to no GLOBAL ARRAYS, but allow + * command-line override + */ +#if defined(__CYGWIN__) +# if !defined(PNG_STATIC) +# if defined(PNG_USE_GLOBAL_ARRAYS) +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# if !defined(PNG_USE_LOCAL_ARRAYS) +# define PNG_USE_LOCAL_ARRAYS +# endif +# else +# if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS) +# if defined(PNG_USE_GLOBAL_ARRAYS) +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# endif +# endif +# if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) +# define PNG_USE_LOCAL_ARRAYS +# endif +#endif + /* Do not use global arrays (helps with building DLL's) * They are no longer used in libpng itself, since version 1.0.5c, * but might be required for some pre-1.0.5c applications. @@ -954,19 +1062,21 @@ typedef z_stream FAR * png_zstreamp; #ifndef PNGAPI -#if defined(__MINGW32__) || defined(__CYGWIN32__) && !defined(PNG_MODULEDEF) + +#if defined(__MINGW32__) || defined(__CYGWIN__) && !defined(PNG_MODULEDEF) # ifndef PNG_NO_MODULEDEF # define PNG_NO_MODULEDEF # endif -#endif - +#endif + #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF) # define PNG_IMPEXP #endif #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \ - defined(_Windows) || defined(_WINDOWS) || \ - defined(WIN32) || defined(_WIN32) || defined(__WIN32__) + (( defined(_Windows) || defined(_WINDOWS) || \ + defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \ + ) && !defined(__CYGWIN__)) # ifdef __GNUC__ # define PNGAPI __cdecl @@ -1008,11 +1118,18 @@ typedef z_stream FAR * png_zstreamp; # endif # endif # endif /* PNG_IMPEXP */ -#else /* !(DLL || WINDOWS) */ -# if 0 /* ... other platforms, with other meanings */ +#else /* !(DLL || non-cygwin WINDOWS) */ +# if defined(__CYGWIN__) && !defined(PNG_DLL) +# if !defined(PNG_IMPEXP) +# define PNG_IMPEXP +# endif +# define PNGAPI __cdecl # else -# define PNGAPI -# define PNG_IMPEXP +# if 0 /* ... other platforms, with other meanings */ +# else +# define PNGAPI +# define PNG_IMPEXP +# endif # endif #endif #endif @@ -1023,7 +1140,7 @@ typedef z_stream FAR * png_zstreamp; #ifdef PNG_USE_GLOBAL_ARRAYS #ifndef PNG_EXPORT_VAR -# define PNG_EXPORT_VAR(type) extern type +# define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type #endif #endif diff --git a/pngcrush.c b/pngcrush.c index 8cf3cc206..e4340a134 100644 --- a/pngcrush.c +++ b/pngcrush.c @@ -1,4 +1,4 @@ -/* pngcrush.c - a simple program to recompress png files +/* pngcrush.c - recompresses png files * Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) * * This program reads in a PNG image, and writes it out again, with the @@ -16,7 +16,7 @@ * occasionally creating Linux executables. */ -#define PNGCRUSH_VERSION "1.4.5" +#define PNGCRUSH_VERSION "1.4.6" /* #define PNGCRUSH_COUNT_COLORS @@ -57,6 +57,18 @@ */ /* Change log: + * + * Version 1.4.6 (built with libpng-1.0.8rc1) + * + * Fixed bug in color-counting of noninterlaced images. + * + * Added capability of processing multiple rows at a time (disabled by + * default because it turns out to be no faster). + * + * Replaced "return" statements in main() with "exit" statements. + * Force exit instead of return with "-exit" argument. + * + * Added the UCITA disclaimers to the help output. * * Version 1.4.5 (built with libpng-1.0.7rc2 and cexcept-1.0.0) * @@ -257,13 +269,15 @@ #endif #if PNGCRUSH_LIBPNG_VER != PNG_LIBPNG_VER +int main() { - printf("Sorry, but version numbers in pngcrush.h and png.h must match\n"); + printf("Version numbers in pngcrush.h and png.h do not match\n"); } #else #if PNG_LIBPNG_VER < 96 +int main() { printf("Sorry, but pngcrush needs libpng version 0.96 or later\n"); @@ -388,10 +402,16 @@ static PNG_CONST char *outname = "pngout" DOT "png"; static PNG_CONST char *directory_name = "pngcrush" DOT "bak"; static PNG_CONST char *extension = "_C" DOT "png"; +static png_uint_32 width, height; static png_uint_32 measured_idat_length; +static int pngcrush_must_exit=0; static int all_chunks_are_safe=0; static int number_of_open_files; static int do_pplt = 0; +#ifdef PNGCRUSH_MULTIPLE_ROWS +static png_uint_32 max_rows_at_a_time=1; +static png_uint_32 rows_at_a_time; +#endif char pplt_string[1024]; char *ip, *op, *dot; char in_string[256]; @@ -459,6 +479,9 @@ static int pauses=0; static int nosave=0; static int nointerlace=0; static png_bytep row_buf; +#ifdef PNGCRUSH_MULTIPLE_ROWS +static png_bytepp row_pointers; +#endif static int z_strategy; static int best_of_three; static int methods_specified=0; @@ -504,6 +527,7 @@ static FILE *fpin, *fpout; png_uint_32 measure_idats(FILE *fpin); #ifdef PNGCRUSH_COUNT_COLORS int count_colors(FILE *fpin); +static int reduce_to_gray, it_is_opaque; #endif png_uint_32 png_measure_idat(png_structp png_ptr); # define MAX_METHODS 200 @@ -515,6 +539,8 @@ 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 crushed_idat_size = 0x3ffffffL; +static int already_crushed = 0; int ia; /********* Functions to make direct access to the png_ptr. *************** @@ -778,7 +804,7 @@ int keep_chunk(png_const_charp name, char *argv[]) fprintf(STDERR, " Check for removal of the %s chunk.\n", name); for (i=1; i<=remove_chunks; i++) { - if(!strncmp(argv[i],"-r",2)) + if(!strncmp(argv[i],"-rem",4)) { int alla = 0; int allb = 0; @@ -871,9 +897,8 @@ int main(int argc, char *argv[]) { png_uint_32 y; - png_uint_32 width, height; - int num_pass, pass; int bit_depth, color_type; + int num_pass, pass; int try_method[MAX_METHODSP1]; int fm[MAX_METHODSP1]; int lv[MAX_METHODSP1]; @@ -970,6 +995,13 @@ main(int argc, char *argv[]) } } + else if( !strncmp(argv[i],"-already",8)) + { + names++; + BUMP_I; + crushed_idat_size = (png_uint_32)atoi(argv[i]); + } + else if( !strncmp(argv[i],"-bkgd",5) || !strncmp(argv[i],"-bKGD",5)) { @@ -1023,6 +1055,8 @@ main(int argc, char *argv[]) pngcrush_mode=DIRECTORY_MODE; directory_name= argv[names++]; } + else if(!strncmp(argv[i],"-exit",2)) + pngcrush_must_exit=1; else if(!strncmp(argv[i],"-e",2)) { BUMP_I; @@ -1191,6 +1225,8 @@ main(int argc, char *argv[]) { pauses++; } + else if(!strncmp(argv[i],"-q",2)) + verbose=0; #ifdef PNG_gAMA_SUPPORTED else if(!strncmp(argv[i],"-rep",4)) { @@ -1233,6 +1269,14 @@ main(int argc, char *argv[]) BUMP_I; resolution=atoi(argv[i]); } +#endif +#ifdef PNGCRUSH_MULTIPLE_ROWS + else if(!strncmp(argv[i],"-rows",5)) + { + names++; + BUMP_I; + max_rows_at_a_time=atoi(argv[i]); + } #endif else if(!strncmp(argv[i],"-r",2)) { @@ -1412,6 +1456,8 @@ main(int argc, char *argv[]) if(verbose > 0) { + /* 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", progname, PNGCRUSH_VERSION); @@ -1420,16 +1466,16 @@ main(int argc, char *argv[]) fprintf(STDERR, " | This program was built with libpng version %s,\n", PNG_LIBPNG_VER_STRING); - fprintf(STDERR, - " | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,\n"); -#if PNG_LIBPNG_VER > 89 - fprintf(STDERR, - " | Copyright (C) 1996, 1997 Andreas Dilger,\n"); -#endif #if PNG_LIBPNG_VER > 96 fprintf(STDERR, " | Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson,\n"); #endif +#if PNG_LIBPNG_VER > 89 + fprintf(STDERR, + " | Copyright (C) 1996, 1997 Andreas Dilger,\n"); +#endif + fprintf(STDERR, + " | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,\n"); fprintf(STDERR, " | and zlib version %s, Copyright (C) 1998,\n", ZLIB_VERSION); @@ -1437,11 +1483,13 @@ main(int argc, char *argv[]) " | Jean-loup Gailly and Mark Adler.\n"); #if defined(__DJGPP__) fprintf(STDERR, - " | It was compiled with gcc version %s and as version %s\n", - __VERSION__, "2.81"); + " | It was compiled with gcc version %s", __VERSION__); +# if defined(PNG_USE_PNGGCCRD) /* is there a macro for "as" versions? */ + fprintf(STDERR, "\n | and as version %s", "2.9.5"); +# endif fprintf(STDERR, - " | under DJGPP %d.%d, Copyright (C) 1995, D. J. Delorie\n", + "\n | under DJGPP %d.%d, Copyright (C) 1995, D. J. Delorie\n", __DJGPP__,__DJGPP_MINOR__); fprintf(STDERR, " | and loaded with PMODE/DJ, by Thomas Pytel and Matthias Grimrath\n"); @@ -1494,6 +1542,15 @@ main(int argc, char *argv[]) } else fprintf(STDERR, "options:\n"); + fprintf(STDERR, + " -already already_crushed_size [e.g., 8192])\n"); + if(verbose > 1) + { + fprintf(STDERR, + "\n If file has an IDAT greater than this size, it\n"); + fprintf(STDERR, + " will be considered to be already crushed.\n\n"); + } fprintf(STDERR, " -brute (Use brute-force, try 114 different methods [11-124])\n"); if(verbose > 1) @@ -1817,7 +1874,7 @@ main(int argc, char *argv[]) png_crush_pause(); } fprintf(STDERR, - " -h (help)\n"); + " -h (help and legal notices)\n"); if(verbose > 1) fprintf(STDERR, "\n Display this information.\n\n"); @@ -1832,6 +1889,51 @@ main(int argc, char *argv[]) fprintf(STDERR, " screen scrolls out of sight.\n\n"); } + /* 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"); + fprintf(STDERR, + "\nDISCLAIMER: The pngcrush computer program is supplied \"AS IS\".\n"); + fprintf(STDERR, + "The Author disclaims all warranties, expressed or implied, including,\n"); + fprintf(STDERR, + "without limitation, the warranties of merchantability and of fitness\n"); + fprintf(STDERR, + "for any purpose. The Author assumes no liability for direct, indirect,\n"); + fprintf(STDERR, + "incidental, special, exemplary, or consequential damages, which may\n"); + fprintf(STDERR, + "result from the use of the computer program, even if advised of the\n"); + fprintf(STDERR, + "possibility of such damage. There is no warranty against interference\n"); + fprintf(STDERR, + "with your enjoyment of the computer program or against infringement.\n"); + fprintf(STDERR, + "There is no warranty that my efforts or the computer program will\n"); + fprintf(STDERR, + "fulfill any of your particular purposes or needs. This computer\n"); + fprintf(STDERR, + "program is provided with all faults, and the entire risk of satisfactory\n"); + fprintf(STDERR, + "quality, performance, accuracy, and effort is with the user.\n"); + fprintf(STDERR, + + "\nLICENSE: Permission is hereby granted to anyone to use, copy, modify,\n"); + fprintf(STDERR, + "and distribute this computer program, or portions hereof, for any\n"); + fprintf(STDERR, + "purpose, without fee, subject to the following restrictions:\n\n"); + fprintf(STDERR, + "1. The origin of this binary or source code must not be misrepresented.\n\n"); + fprintf(STDERR, + "2. Altered versions must be plainly marked as such and must not be\n"); + fprintf(STDERR, + "misrepresented as being the original binary or source.\n\n"); + fprintf(STDERR, + "3. The Copyright notice, disclaimer, and license may not be removed\n"); + fprintf(STDERR, + "or altered from any source, binary, or altered source distribution.\n"); if(pngcrush_mode == DEFAULT_MODE && argc - names != 2 && nosave == 0) exit(1); @@ -1855,7 +1957,7 @@ main(int argc, char *argv[]) if(inname == NULL) { if(verbose > 0) show_result(); - return 0; + exit(0); } if(pngcrush_mode == EXTENSION_MODE) @@ -1905,7 +2007,7 @@ main(int argc, char *argv[]) #endif { fprintf(STDERR,"could not create directory %s\n",directory_name); - return 1; + exit(1); } } out_string[0] = '\0'; @@ -1930,8 +2032,6 @@ main(int argc, char *argv[]) outname=out_string; } - output_color_type=force_output_color_type; - output_bit_depth=force_output_bit_depth; if(nosave < 2) { @@ -1944,10 +2044,18 @@ main(int argc, char *argv[]) } number_of_open_files++; + already_crushed = 0; + idat_length[0]=measure_idats(fpin); FCLOSE(fpin); + if(already_crushed) + { + fprintf(STDERR, "File has already been crushed: %s\n", inname); + continue; + } + if(verbose > 0) { fprintf(STDERR," %s IDAT length in input file = %8lu\n", @@ -1962,7 +2070,9 @@ main(int argc, char *argv[]) idat_length[0]=1; #ifdef PNGCRUSH_COUNT_COLORS - if (input_color_type == 2 || input_color_type == 4 || input_color_type == 6) + output_color_type = input_color_type; + if (force_output_color_type == 8 && (input_color_type == 2 || + input_color_type == 4 || input_color_type == 6)) /* check for unused alpha channel or single transparent color */ { int alpha_status; @@ -1979,8 +2089,20 @@ main(int argc, char *argv[]) FCLOSE(fpin); - if(alpha_status) - /* TO DO */; + if (it_is_opaque) + { + if (output_color_type == 4) + output_color_type=0; + else if (output_color_type == 6) + output_color_type=2; + } + if (reduce_to_gray) + { + if (output_color_type == 2) + output_color_type=0; + else if (output_color_type == 6) + output_color_type=4; + } } #if 0 /* TO DO */ @@ -1996,8 +2118,16 @@ main(int argc, char *argv[]) /* TO DO */ } #endif + if(force_output_color_type == 8 && input_color_type != output_color_type) + { + P1 ("setting output color type to %d\n",output_color_type); + force_output_color_type = output_color_type; + } #endif /* PNGCRUSH_COUNT_COLORS */ + output_color_type=force_output_color_type; + output_bit_depth=force_output_bit_depth; + if(!methods_specified || try_method[0] == 0) { for (i=1; i<=DEFAULT_METHODS; i++) try_method[i]=0; @@ -2044,7 +2174,7 @@ main(int argc, char *argv[]) { fprintf(STDERR, "Could not open output file %s\n", outname); FCLOSE(fpin); - return 1; + exit(1); } number_of_open_files++; @@ -2152,14 +2282,14 @@ main(int argc, char *argv[]) P1(" st_ino=%d, st_size=%d\n\n", (int)stat_in.st_ino, (int)stat_in.st_size); FCLOSE(fpin); - return 1; + exit(1); } #endif if ((fpout = FOPEN(outname, "wb")) == NULL) { fprintf(STDERR, "Could not open output file %s\n", outname); FCLOSE(fpin); - return 1; + exit(1); } number_of_open_files++; @@ -2170,6 +2300,7 @@ main(int argc, char *argv[]) Try { + png_uint_32 row_length; png_debug(0, "Allocating read and write structures\n"); #ifdef PNG_USER_MEM_SUPPORTED read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, @@ -2962,23 +3093,23 @@ main(int argc, char *argv[]) #ifdef PNG_FLOATING_POINT_SUPPORTED { int unit; - double width, height; + double scal_width, scal_height; - if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &width, &height)) + if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, &scal_height)) { - png_set_sCAL(write_ptr, write_info_ptr, unit, width, height); + png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); } } #else #ifdef PNG_FIXED_POINT_SUPPORTED { int unit; - png_charp width, height; + png_charp scal_width, scal_height; - if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &width, &height)) + if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, &scal_height)) { if(keep_chunk("sCAL",argv)) - png_set_sCAL_s(write_ptr, write_info_ptr, unit, width, height); + png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, scal_height); } } #endif @@ -3177,6 +3308,12 @@ main(int argc, char *argv[]) #define LARGE_PNGCRUSH +#ifdef PNGCRUSH_MULTIPLE_ROWS + rows_at_a_time=max_rows_at_a_time; + if(rows_at_a_time == 0 || rows_at_a_time < height) + rows_at_a_time=height; +#endif + #ifndef LARGE_PNGCRUSH { png_uint_32 rowbytes_s; @@ -3186,7 +3323,11 @@ main(int argc, char *argv[]) rowbytes_s = (png_size_t)rowbytes; if(rowbytes == (png_uint_32)rowbytes_s) - row_buf = png_malloc(read_ptr, rowbytes+2 ); +#ifdef PNGCRUSH_MULTIPLE_ROWS + row_buf = png_malloc(read_ptr, rows_at_a_time*rowbytes+16); +#else + row_buf = png_malloc(read_ptr, rowbytes+16); +#endif else { fprintf(STDERR, "rowbytes= %d\n",rowbytes); @@ -3195,14 +3336,18 @@ main(int argc, char *argv[]) } #else { - png_uint_32 read_row_length, write_row_length, row_length; + png_uint_32 read_row_length, write_row_length; read_row_length= (png_uint_32)(png_get_rowbytes(read_ptr, read_info_ptr)); write_row_length= (png_uint_32)(png_get_rowbytes(write_ptr, write_info_ptr)); row_length = read_row_length > write_row_length ? read_row_length : write_row_length; +#ifdef PNGCRUSH_MULTIPLE_ROWS + row_buf = (png_bytep)png_malloc(read_ptr,rows_at_a_time*row_length+16); +#else row_buf = (png_bytep)png_malloc(read_ptr,row_length+16); +#endif } #endif @@ -3219,6 +3364,13 @@ main(int argc, char *argv[]) */ } +#ifdef PNGCRUSH_MULTIPLE_ROWS + row_pointers = (png_bytepp)png_malloc(read_ptr, + rows_at_a_time*sizeof(png_bytepp)); + for (i=0; i height) num_rows=height-y; + png_read_rows(read_ptr, row_pointers, (png_bytepp)NULL, num_rows); +#else png_read_row(read_ptr, row_buf, (png_bytep)NULL); +#endif if(nosave == 0) { t_stop = (TIME_T)clock(); t_decode += (t_stop - t_start); t_start = t_stop; +#ifdef PNGCRUSH_MULTIPLE_ROWS + png_write_rows(write_ptr, row_pointers, num_rows); +#else png_write_row(write_ptr, row_buf); +#endif t_stop = (TIME_T)clock(); t_encode += (t_stop - t_start); t_start = t_stop; @@ -3251,7 +3420,7 @@ main(int argc, char *argv[]) if(nosave) { t_stop = (TIME_T)clock(); - t_decode += (t_stop - t_start); + t_decode += (t_stop - t_start); t_start = t_stop; } @@ -3430,8 +3599,17 @@ main(int argc, char *argv[]) png_debug(0, "Destroying data structs\n"); if(row_buf != (png_bytep)NULL) + { png_free(read_ptr, row_buf); - row_buf = (png_bytep)NULL; + row_buf = (png_bytep)NULL; + } +#ifdef PNGCRUSH_MULTIPLE_ROWS + if(row_pointers != (png_bytepp)NULL) + { + png_free(read_ptr, row_pointers); + row_pointers = (png_bytepp)NULL; + } +#endif png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); if(nosave == 0) { @@ -3448,6 +3626,13 @@ main(int argc, char *argv[]) fprintf(stderr, " pngcrush caught libpng error:\n %s\n\n",msg); if(row_buf != NULL)png_free(read_ptr, row_buf); row_buf = (png_bytep)NULL; +#ifdef PNGCRUSH_MULTIPLE_ROWS + if(row_pointers != (png_bytepp)NULL) + { + png_free(read_ptr, row_pointers); + row_pointers = (png_bytepp)NULL; + } +#endif if(nosave == 0) { png_destroy_info_struct(write_ptr, &write_end_info_ptr); @@ -3484,7 +3669,7 @@ main(int argc, char *argv[]) { free(png_row_filters); png_row_filters=NULL; } - return 1; + exit(1); } number_of_open_files++; @@ -3555,7 +3740,9 @@ main(int argc, char *argv[]) free(png_row_filters); png_row_filters=NULL; } if(verbose > 0) show_result(); - return 0; + if(pngcrush_must_exit) + exit(0); + return(0); } } /* end of loop on input files */ } @@ -3652,7 +3839,11 @@ png_measure_idat(png_structp png_ptr) #else if (!png_memcmp(chunk_name, png_IDAT, 4)) #endif + { sum_idat_length += length; + if(length > crushed_idat_size) + already_crushed++; + } if(verbose > 1) { @@ -3714,7 +3905,6 @@ png_measure_idat(png_structp png_ptr) #ifdef PNGCRUSH_COUNT_COLORS #define USE_HASHCODE static int result, num_rgba; -static int it_is_gray, it_is_opaque; static int hashmiss, hashinserts; int count_colors(FILE *fpin) @@ -3722,7 +3912,7 @@ count_colors(FILE *fpin) /* Copyright (C) 2000 Glenn Randers-Pehrson (randeg@alum.rpi.edu) See notice in pngcrush.c for conditions of use and distribution */ int bit_depth, color_type, interlace_type, filter_type, compression_type; - png_uint_32 width, height, rowbytes, channels; + png_uint_32 rowbytes, channels; int i; int pass, num_pass; @@ -3749,7 +3939,7 @@ count_colors(FILE *fpin) int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; result=0; - it_is_gray=1; + reduce_to_gray=1; it_is_opaque=1; hashmiss=0; hashinserts=0; @@ -3808,6 +3998,9 @@ count_colors(FILE *fpin) else channels=1; + if(color_type == 0 || color_type == 3 || color_type == 4) + reduce_to_gray = 0; + if(bit_depth == 8) { if(interlace_type) @@ -3817,7 +4010,7 @@ count_colors(FILE *fpin) rowbytes = png_get_rowbytes(read_ptr, read_info_ptr); - row_buf = png_malloc(read_ptr, rowbytes+2); + row_buf = png_malloc(read_ptr, rowbytes+16); for (pass = 0; pass < num_pass; pass++) { @@ -3826,16 +4019,24 @@ count_colors(FILE *fpin) png_uint_32 pass_height, pass_width, y; png_debug(0, "\nBegin Pass\n"); - pass_height = (height - png_pass_ystart[pass] + if (interlace_type) + { + pass_height = (height - png_pass_ystart[pass] + png_pass_yinc[pass] - 1) / png_pass_yinc[pass]; - pass_width = (width - png_pass_start[pass] + pass_width = (width - png_pass_start[pass] + png_pass_inc[pass] - 1) / png_pass_inc[pass]; + } + else + { + pass_height=height; + pass_width=width; + } for (y = 0; y < pass_height; y++) { png_uint_32 x; png_read_row(read_ptr, row_buf, (png_bytep)NULL); - if(result < 2) + if(result < 2 || it_is_opaque || reduce_to_gray) { if(color_type==2) { @@ -3846,11 +4047,13 @@ count_colors(FILE *fpin) #endif png_uint_32 rgba_high = (255<<24)|(*(rp)<<16)|(*(rp+1)<<8)| *(rp+2); + assert(num_rgba < 258); rgba_hi[num_rgba]=rgba_high; -#ifdef USE_HASHCODE - if(it_is_gray && + + if(reduce_to_gray && ((*(rp)) != (*(rp+1)) || (*(rp)) != (*(rp+2)))) - it_is_gray=0; + reduce_to_gray=0; +#ifdef USE_HASHCODE /* * R G B mask * 11,111 0,0000, 0000 0x3e00 @@ -3862,6 +4065,7 @@ count_colors(FILE *fpin) hashcode=(int)(((rgba_high>>10)&0x3e00)| ((rgba_high>> 7)&0x01f0)| ((rgba_high>> 4)&0x000f)); + assert(hashcode < 16385); if (hash[hashcode] < 0) { hash[hashcode] = i = num_rgba; @@ -3889,6 +4093,7 @@ count_colors(FILE *fpin) rgba_hi[j]=rgba_hi[j-1]; rgba_frequency[j]=rgba_frequency[j-1]; } + assert(start+1 < 258); rgba_hi[start+1]=rgba_high; rgba_frequency[start+1]=0; for(j=0; j<16384; j++) @@ -3910,6 +4115,7 @@ count_colors(FILE *fpin) else if(i == num_rgba) num_rgba++; #endif + assert(i < 258); ++rgba_frequency[i]; } } @@ -3922,13 +4128,14 @@ count_colors(FILE *fpin) #endif png_uint_32 rgba_high = (*(rp+3)<<24)|(*(rp)<<16)| (*(rp+1)<<8)|*(rp+2); + assert(rp-row_buf+3 < rowbytes); rgba_hi[num_rgba]=rgba_high; -#ifdef USE_HASHCODE - if(it_is_gray && + if(reduce_to_gray && ((*(rp)) != (*(rp+1)) || (*(rp)) != (*(rp+2)))) - it_is_gray=0; + reduce_to_gray=0; if(it_is_opaque && (*(rp+3)) != 255) it_is_opaque=0; +#ifdef USE_HASHCODE /* * A R G B mask * 11,1 000,0 000,0 000 0x3800 @@ -3942,6 +4149,7 @@ count_colors(FILE *fpin) ((rgba_high>>12)&0x0780)| ((rgba_high>> 8)&0x0078)| ((rgba_high>> 4)&0x0007)); + assert(hashcode < 16385); if (hash[hashcode] < 0) { hash[hashcode] = i = num_rgba; @@ -3959,11 +4167,11 @@ count_colors(FILE *fpin) hashmiss += (i-start); if(i == num_rgba) { - int j; if (i > 256) result=2; else { + int j; for(j=num_rgba; j>start+1; j--) { rgba_hi[j]=rgba_hi[j-1]; @@ -4002,10 +4210,11 @@ count_colors(FILE *fpin) #endif png_uint_32 rgba_high = (*(rp+1)<<24)|(*(rp)<<16)| (*(rp)<<8)|(*rp); + assert(rp-row_buf+1 < rowbytes); rgba_hi[num_rgba]=rgba_high; -#ifdef USE_HASHCODE if(it_is_opaque && (*(rp+1)) != 255) it_is_opaque=0; +#ifdef USE_HASHCODE /* * A G mask * 11,1111, 0000,0000 0x3f00 @@ -4032,11 +4241,11 @@ count_colors(FILE *fpin) hashmiss += (i-start); if(i == num_rgba) { - int j; if (i > 256) result=2; else { + int j; for(j=num_rgba; j>start+1; j--) { rgba_hi[j]=rgba_hi[j-1]; @@ -4078,6 +4287,8 @@ count_colors(FILE *fpin) else { /* TO DO: 16-bit support */ + reduce_to_gray=0; + it_is_opaque=0; result=0; } @@ -4117,8 +4328,8 @@ count_colors(FILE *fpin) hashinserts); } P2 ("Finished checking alphas, result=%d\n",result); - if(it_is_gray) - P1 ("The image is all gray.\n"); + if(reduce_to_gray) + P1 ("The truecolor image is all gray and will be reduced.\n"); if(it_is_opaque) P1 ("The image is opaque.\n"); } diff --git a/pngcrush.h b/pngcrush.h index c35219e05..33b31e37e 100644 --- a/pngcrush.h +++ b/pngcrush.h @@ -6,6 +6,10 @@ #ifndef PNGCRUSH_H #define PNGCRUSH_H +/* +#include +*/ + #ifdef PNG_LIBPNG_VER #define PNGCRUSH_LIBPNG_VER PNG_LIBPNG_VER #else @@ -14,13 +18,21 @@ #define PNGCRUSH_LIBPNG_VER 10007 #endif +#ifndef PNG_NO_ZALLOC_ZERO +# define PNG_NO_ZALLOC_ZERO /* speeds it up a little */ +#endif + #ifndef PNG_USER_MEM_SUPPORTED # define PNG_USER_MEM_SUPPORTED #endif -#define PNG_NO_LEGACY_SUPPORTED +#ifndef PNG_NO_LEGACY_SUPPORTED +# define PNG_NO_LEGACY_SUPPORTED +#endif -#define PNG_SETJMP_NOT_SUPPORTED +#ifndef PNG_SETJMP_NOT_SUPPORTED +# define PNG_SETJMP_NOT_SUPPORTED +#endif #if PNGCRUSH_LIBPNG_VER > 10006 #define PNG_NO_FLOATING_POINT_SUPPORTED diff --git a/pngerror.c b/pngerror.c index 8b7eab395..cf7930812 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pnggccrd.c b/pnggccrd.c index 6a5ddf40c..24115aa66 100644 --- a/pnggccrd.c +++ b/pnggccrd.c @@ -6,7 +6,7 @@ * and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm * for Intel's performance analysis of the MMX vs. non-MMX code. * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng version 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * Copyright (c) 1998, Intel Corporation @@ -122,11 +122,33 @@ * - fixed up both versions of mmxsupport() (ORIG_THAT_USED_TO_CLOBBER_EBX * macro determines which is used); original not yet tested. * + * 20000213: + * - When compiling with gcc, be sure to use -fomit-frame-pointer + * * 20000319: * - fixed a register-name typo in png_do_read_interlace(), default (MMX) case, * pass == 4 or 5, that caused visible corruption of interlaced images * - * - When compiling with gcc, be sure to use -fomit-frame-pointer + * 20000623: + * - Various problems were reported with gcc 2.95.2 in the Cygwin environment, + * many of the form "forbidden register 0 (ax) was spilled for class AREG." + * This is explained at http://gcc.gnu.org/fom_serv/cache/23.html, and + * Chuck Wilson supplied a patch involving dummy output registers. See + * http://sourceforge.net/bugs/?func=detailbug&bug_id=108741&group_id=5624 + * for the original (anonymous) SourceForge bug report. + * + * 20000706: + * - Chuck Wilson passed along these remaining gcc 2.95.2 errors: + * pnggccrd.c: In function `png_combine_row': + * pnggccrd.c:525: more than 10 operands in `asm' + * pnggccrd.c:669: more than 10 operands in `asm' + * pnggccrd.c:828: more than 10 operands in `asm' + * pnggccrd.c:994: more than 10 operands in `asm' + * pnggccrd.c:1177: more than 10 operands in `asm' + * They are all the same problem and can be worked around by using the + * global _unmask variable unconditionally, not just in the -fPIC case. + * Apparently earlier versions of gcc also have the problem with more than + * 10 operands; they just don't report it. Much strangeness ensues, etc. */ #define PNG_INTERNAL @@ -144,9 +166,9 @@ static const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; static const int png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1}; #endif -// djgpp and Win32 add their own underscores to global variables, +// djgpp, Win32, and Cygwin add their own underscores to global variables, // so define them without: -#if (defined __DJGPP__) || defined (WIN32) +#if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) # define _unmask unmask # define _const4 const4 # define _const6 const6 @@ -174,9 +196,13 @@ static const int png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1}; /* These constants are used in the inlined MMX assembly code. Ignore gcc's "At top level: defined but not used" warnings. */ -#ifdef __PIC__ -static int _unmask; // not enough regs when compiling with -fPIC, so... -#endif +/* GRR 20000706: originally _unmask was needed only when compiling with -fPIC, + * since that case uses the %ebx register for indexing the Global Offset Table + * and there were no other registers available. But gcc 2.95 and later emit + * "more than 10 operands in `asm'" errors when %ebx is used to preload unmask + * in the non-PIC case, so we'll just use the global unconditionally now. + */ +static int _unmask; static unsigned long long _mask8_0 = 0x0102040810204080LL; @@ -430,23 +456,19 @@ fflush(stderr); { png_uint_32 len; int diff; -#ifndef __PIC__ - int unmask = ~mask; -#else + int dummy_value_a; // fix 'forbidden register spilled' error + int dummy_value_d; + int dummy_value_c; + int dummy_value_S; + int dummy_value_D; _unmask = ~mask; // global variable for -fPIC version -#endif 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 - __asm__ ( -#ifdef __PIC__ + __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern -#else -// preload "movd unmask, %%mm7 \n\t" // (unmask is in ebx) - "movd %%ebx, %%mm7 \n\t" // load bit pattern (unmask) -#endif "psubb %%mm6, %%mm6 \n\t" // zero mm6 "punpcklbw %%mm7, %%mm7 \n\t" "punpcklwd %%mm7, %%mm7 \n\t" @@ -498,21 +520,22 @@ fflush(stderr); "end8: \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=a" (dummy_value_a), // output regs (dummy) + "=d" (dummy_value_d), + "=c" (dummy_value_c), + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (srcptr), // esi // input regs - "D" (dstptr), // edi - "a" (diff), // eax -#ifndef __PIC__ - "b" (unmask), // ebx // Global Offset Table idx -#endif - "c" (len), // ecx - "d" (mask) // edx + : "3" (srcptr), // esi // input regs + "4" (dstptr), // edi + "0" (diff), // eax +// was (unmask) "b" RESERVED // ebx // Global Offset Table idx + "2" (len), // ecx + "1" (mask) // edx - : "%esi", "%edi", "%eax", // clobber list - "%ecx", "%edx" +// : // clobber list #if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm4", "%mm6", "%mm7" + : "%mm0", "%mm4", "%mm6", "%mm7" #endif ); } @@ -550,23 +573,19 @@ fflush(stderr); { png_uint_32 len; int diff; -#ifndef __PIC__ - int unmask = ~mask; -#else + int dummy_value_a; // fix 'forbidden register spilled' error + int dummy_value_d; + int dummy_value_c; + int dummy_value_S; + int dummy_value_D; _unmask = ~mask; // global variable for -fPIC version -#endif 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 - __asm__ ( -#ifdef __PIC__ + __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern -#else -// preload "movd unmask, %%mm7 \n\t" // (unmask is in ebx) - "movd %%ebx, %%mm7 \n\t" // load bit pattern (unmask) -#endif "psubb %%mm6, %%mm6 \n\t" // zero mm6 "punpcklbw %%mm7, %%mm7 \n\t" "punpcklwd %%mm7, %%mm7 \n\t" @@ -633,21 +652,22 @@ fflush(stderr); "end16: \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=a" (dummy_value_a), // output regs (dummy) + "=d" (dummy_value_d), + "=c" (dummy_value_c), + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (srcptr), // esi // input regs - "D" (dstptr), // edi - "a" (diff), // eax -#ifndef __PIC__ - "b" (unmask), // ebx // Global Offset Table idx -#endif - "c" (len), // ecx - "d" (mask) // edx + : "3" (srcptr), // esi // input regs + "4" (dstptr), // edi + "0" (diff), // eax +// was (unmask) "b" RESERVED // ebx // Global Offset Table idx + "2" (len), // ecx + "1" (mask) // edx - : "%esi", "%edi", "%eax", // clobber list - "%ecx", "%edx" +// : // clobber list #if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", + : "%mm0", "%mm1", "%mm4", "%mm5", "%mm6", "%mm7" #endif ); @@ -686,23 +706,19 @@ fflush(stderr); { png_uint_32 len; int diff; -#ifndef __PIC__ - int unmask = ~mask; -#else + int dummy_value_a; // fix 'forbidden register spilled' error + int dummy_value_d; + int dummy_value_c; + int dummy_value_S; + int dummy_value_D; _unmask = ~mask; // global variable for -fPIC version -#endif 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 - __asm__ ( -#ifdef __PIC__ + __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern -#else -// preload "movd unmask, %%mm7 \n\t" // (unmask is in ebx) - "movd %%ebx, %%mm7 \n\t" // load bit pattern (unmask) -#endif "psubb %%mm6, %%mm6 \n\t" // zero mm6 "punpcklbw %%mm7, %%mm7 \n\t" "punpcklwd %%mm7, %%mm7 \n\t" @@ -784,21 +800,22 @@ fflush(stderr); "end24: \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=a" (dummy_value_a), // output regs (dummy) + "=d" (dummy_value_d), + "=c" (dummy_value_c), + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (srcptr), // esi // input regs - "D" (dstptr), // edi - "a" (diff), // eax -#ifndef __PIC__ - "b" (unmask), // ebx // Global Offset Table idx -#endif - "c" (len), // ecx - "d" (mask) // edx + : "3" (srcptr), // esi // input regs + "4" (dstptr), // edi + "0" (diff), // eax +// was (unmask) "b" RESERVED // ebx // Global Offset Table idx + "2" (len), // ecx + "1" (mask) // edx - : "%esi", "%edi", "%eax", // clobber list - "%ecx", "%edx" +// : // clobber list #if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", "%mm2", + : "%mm0", "%mm1", "%mm2", "%mm4", "%mm5", "%mm6", "%mm7" #endif ); @@ -837,23 +854,19 @@ fflush(stderr); { png_uint_32 len; int diff; -#ifndef __PIC__ - int unmask = ~mask; -#else + int dummy_value_a; // fix 'forbidden register spilled' error + int dummy_value_d; + int dummy_value_c; + int dummy_value_S; + int dummy_value_D; _unmask = ~mask; // global variable for -fPIC version -#endif 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 - __asm__ ( -#ifdef __PIC__ + __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern -#else -// preload "movd unmask, %%mm7 \n\t" // (unmask is in ebx) - "movd %%ebx, %%mm7 \n\t" // load bit pattern (unmask) -#endif "psubb %%mm6, %%mm6 \n\t" // zero mm6 "punpcklbw %%mm7, %%mm7 \n\t" "punpcklwd %%mm7, %%mm7 \n\t" @@ -942,21 +955,22 @@ fflush(stderr); "end32: \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=a" (dummy_value_a), // output regs (dummy) + "=d" (dummy_value_d), + "=c" (dummy_value_c), + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (srcptr), // esi // input regs - "D" (dstptr), // edi - "a" (diff), // eax -#ifndef __PIC__ - "b" (unmask), // ebx // Global Offset Table idx -#endif - "c" (len), // ecx - "d" (mask) // edx + : "3" (srcptr), // esi // input regs + "4" (dstptr), // edi + "0" (diff), // eax +// was (unmask) "b" RESERVED // ebx // Global Offset Table idx + "2" (len), // ecx + "1" (mask) // edx - : "%esi", "%edi", "%eax", // clobber list - "%ecx", "%edx" +// : // clobber list #if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", "%mm2", "%mm3", + : "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7" #endif ); @@ -995,23 +1009,19 @@ fflush(stderr); { png_uint_32 len; int diff; -#ifndef __PIC__ - int unmask = ~mask; -#else + int dummy_value_a; // fix 'forbidden register spilled' error + int dummy_value_d; + int dummy_value_c; + int dummy_value_S; + int dummy_value_D; _unmask = ~mask; // global variable for -fPIC version -#endif 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 - __asm__ ( -#ifdef __PIC__ + __asm__ __volatile__ ( "movd _unmask, %%mm7 \n\t" // load bit pattern -#else -// preload "movd unmask, %%mm7 \n\t" // (unmask is in ebx) - "movd %%ebx, %%mm7 \n\t" // load bit pattern (unmask) -#endif "psubb %%mm6, %%mm6 \n\t" // zero mm6 "punpcklbw %%mm7, %%mm7 \n\t" "punpcklwd %%mm7, %%mm7 \n\t" @@ -1117,21 +1127,22 @@ fflush(stderr); "end48: \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=a" (dummy_value_a), // output regs (dummy) + "=d" (dummy_value_d), + "=c" (dummy_value_c), + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (srcptr), // esi // input regs - "D" (dstptr), // edi - "a" (diff), // eax -#ifndef __PIC__ - "b" (unmask), // ebx // Global Offset Table idx -#endif - "c" (len), // ecx - "d" (mask) // edx + : "3" (srcptr), // esi // input regs + "4" (dstptr), // edi + "0" (diff), // eax +// was (unmask) "b" RESERVED // ebx // Global Offset Table idx + "2" (len), // ecx + "1" (mask) // edx - : "%esi", "%edi", "%eax", // clobber list - "%ecx", "%edx" +// : // clobber list #if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", "%mm2", "%mm3", + : "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7" #endif ); @@ -1453,7 +1464,10 @@ fflush(stderr); { if (((pass == 0) || (pass == 1)) && width) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $21, %%edi \n\t" // (png_pass_inc[pass] - 1)*pixel_bytes @@ -1482,22 +1496,27 @@ fflush(stderr); "jnz .loop3_pass0 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width) // ecx // doesn't work "i" (0x0000000000FFFFFFLL) // %1 (a.k.a. _const4) - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", "%mm2", "%mm3", "%mm4" + : "%mm0", "%mm1", "%mm2", "%mm3", "%mm4" #endif ); } else if (((pass == 2) || (pass == 3)) && width) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $9, %%edi \n\t" // (png_pass_inc[pass] - 1)*pixel_bytes @@ -1520,15 +1539,17 @@ fflush(stderr); "jnz .loop3_pass2 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, ..., %mm2 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", "%mm2" + : "%mm0", "%mm1", "%mm2" #endif ); } @@ -1543,7 +1564,10 @@ fflush(stderr); // png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; // sptr points at last pixel in pre-expanded row // dp points at last pixel position in expanded row - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $3, %%esi \n\t" "subl $9, %%edi \n\t" // (png_pass_inc[pass] + 1)*pixel_bytes @@ -1569,15 +1593,17 @@ fflush(stderr); "jnz .loop3_pass4 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, ..., %mm3 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", "%mm2", "%mm3" + : "%mm0", "%mm1", "%mm2", "%mm3" #endif ); } @@ -1609,7 +1635,10 @@ fflush(stderr); width -= width_mmx; // 0-3 pixels => 0-3 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $3, %%esi \n\t" "subl $31, %%edi \n\t" @@ -1636,15 +1665,17 @@ fflush(stderr); "jnz .loop1_pass0 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1", "%mm2", "%mm3", "%mm4" + : "%mm0", "%mm1", "%mm2", "%mm3", "%mm4" #endif ); } @@ -1684,7 +1715,10 @@ fflush(stderr); width -= width_mmx; // 0-3 pixels => 0-3 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $3, %%esi \n\t" "subl $15, %%edi \n\t" @@ -1702,15 +1736,17 @@ fflush(stderr); "jnz .loop1_pass2 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1" + : "%mm0", "%mm1" #endif ); } @@ -1732,7 +1768,10 @@ fflush(stderr); width -= width_mmx; // 0-3 pixels => 0-3 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $7, %%esi \n\t" "subl $15, %%edi \n\t" @@ -1749,15 +1788,17 @@ fflush(stderr); "jnz .loop1_pass4 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (none) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1" + : "%mm0", "%mm1" #endif ); } @@ -1784,7 +1825,10 @@ fflush(stderr); width -= width_mmx; // 0,1 pixels => 0,2 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $2, %%esi \n\t" "subl $30, %%edi \n\t" @@ -1804,15 +1848,17 @@ fflush(stderr); "jnz .loop2_pass0 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1" + : "%mm0", "%mm1" #endif ); } @@ -1838,7 +1884,10 @@ fflush(stderr); width -= width_mmx; // 0,1 pixels => 0,2 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $2, %%esi \n\t" "subl $14, %%edi \n\t" @@ -1856,15 +1905,17 @@ fflush(stderr); "jnz .loop2_pass2 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1" + : "%mm0", "%mm1" #endif ); } @@ -1890,7 +1941,10 @@ fflush(stderr); width -= width_mmx; // 0,1 pixels => 0,2 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $2, %%esi \n\t" "subl $6, %%edi \n\t" @@ -1904,15 +1958,17 @@ fflush(stderr); "jnz .loop2_pass4 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0" + : "%mm0" #endif ); } @@ -1948,12 +2004,15 @@ fflush(stderr); */ if (width_mmx) { + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; #ifdef GRR_DEBUG FILE *junk = fopen("junk.4bytes", "wb"); if (junk) fclose(junk); #endif /* GRR_DEBUG */ - __asm__ ( + __asm__ __volatile__ ( "subl $4, %%esi \n\t" "subl $60, %%edi \n\t" @@ -1976,15 +2035,17 @@ fflush(stderr); "jnz .loop4_pass0 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) + + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx - - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1" + : "%mm0", "%mm1" #endif ); } @@ -2010,7 +2071,10 @@ fflush(stderr); width -= width_mmx; // 0,1 pixels => 0,4 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $4, %%esi \n\t" "subl $28, %%edi \n\t" @@ -2029,15 +2093,17 @@ fflush(stderr); "jnz .loop4_pass2 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) + + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx - - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1" + : "%mm0", "%mm1" #endif ); } @@ -2063,7 +2129,10 @@ fflush(stderr); width -= width_mmx; // 0,1 pixels => 0,4 bytes if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $4, %%esi \n\t" "subl $12, %%edi \n\t" @@ -2080,15 +2149,17 @@ fflush(stderr); "jnz .loop4_pass4 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width_mmx) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width_mmx) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0", "%mm1" + : "%mm0", "%mm1" #endif ); } @@ -2122,12 +2193,15 @@ fflush(stderr); { // source is 8-byte RRGGBBAA // dest is 64-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA ... + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; #ifdef GRR_DEBUG FILE *junk = fopen("junk.8bytes", "wb"); if (junk) fclose(junk); #endif /* GRR_DEBUG */ - __asm__ ( + __asm__ __volatile__ ( "subl $56, %%edi \n\t" // start of last block ".loop8_pass0: \n\t" @@ -2146,15 +2220,17 @@ fflush(stderr); "jnz .loop8_pass0 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0" + : "%mm0" #endif ); } @@ -2166,7 +2242,10 @@ fflush(stderr); width -= width_mmx; if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $24, %%edi \n\t" // start of last block ".loop8_pass2: \n\t" @@ -2181,15 +2260,17 @@ fflush(stderr); "jnz .loop8_pass2 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0" + : "%mm0" #endif ); } @@ -2202,7 +2283,10 @@ fflush(stderr); width -= width_mmx; if (width_mmx) { - __asm__ ( + int dummy_value_c; // fix 'forbidden register spilled' + int dummy_value_S; + int dummy_value_D; + __asm__ __volatile__ ( "subl $8, %%edi \n\t" // start of last block ".loop8_pass4: \n\t" @@ -2215,15 +2299,17 @@ fflush(stderr); "jnz .loop8_pass4 \n\t" "EMMS \n\t" // DONE - : // output regs (none) + : "=c" (dummy_value_c), // output regs (dummy) + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (sptr), // esi // input regs - "D" (dp), // edi - "c" (width) // ecx + : "1" (sptr), // esi // input regs + "2" (dp), // edi + "0" (width) // ecx - : "%esi", "%edi", "%ecx" // clobber list +// : // clobber list #if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */ - , "%mm0" + : "%mm0" #endif ); } @@ -2408,11 +2494,14 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row, png_bytep prev_row) { int bpp; + int dummy_value_c; // fix 'forbidden register 2 (cx) was spilled' error + int dummy_value_S; + int dummy_value_D; // int diff; GRR: global now (shortened to dif/_dif) bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel _FullLength = row_info->rowbytes; // # of bytes to filter - __asm__ ( + __asm__ __volatile__ ( // Init address pointers and offset //GRR "movl row, %%edi \n\t" // edi ==> Avg(x) "xorl %%ebx, %%ebx \n\t" // ebx ==> x @@ -2467,14 +2556,16 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row, "subl %%eax, %%ecx \n\t" // drop over bytes from original length "movl %%ecx, _MMXLength \n\t" - : // output regs/vars here, e.g., "=m" (_MMXLength) instead of final instr + : "=c" (dummy_value_c), // output regs/vars here, e.g., "=m" (_MMXLength) instead of final instr + "=S" (dummy_value_S), + "=D" (dummy_value_D) - : "S" (prev_row), // esi // input regs - "D" (row), // edi - "c" (bpp) // ecx + : "1" (prev_row), // esi // input regs + "2" (row), // edi + "0" (bpp) // ecx - : "%eax", "%ebx", "%ecx", // clobber list - "%edx", "%edi", "%esi" + : "%eax", "%ebx", // clobber list + "%edx" // GRR: INCLUDE "memory" as clobbered? (_dif, _MMXLength) PROBABLY ); diff --git a/pngget.c b/pngget.c index 3102dd37e..ef63066f5 100644 --- a/pngget.c +++ b/pngget.c @@ -1,7 +1,7 @@ /* pngget.c - retrieval of values from info struct * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngmem.c b/pngmem.c index d4a29460c..12126bc42 100644 --- a/pngmem.c +++ b/pngmem.c @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngpread.c b/pngpread.c index 24e27f4c4..e621cc8b5 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,7 +1,7 @@ /* pngpread.c - read a png file in push mode * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -1036,6 +1036,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) png_set_text(png_ptr, info_ptr, text_ptr, 1); + png_free(png_ptr, key); png_free(png_ptr, text_ptr); } } @@ -1219,6 +1220,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) png_set_text(png_ptr, info_ptr, text_ptr, 1); + png_free(png_ptr, key); png_free(png_ptr, text_ptr); } } diff --git a/pngread.c b/pngread.c index aa34ff47a..ac652085a 100644 --- a/pngread.c +++ b/pngread.c @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -62,6 +62,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, #endif { png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf=NULL; png_destroy_struct(png_ptr); return (png_structp)NULL; } @@ -315,7 +316,7 @@ png_read_info(png_structp png_ptr, png_infop info_ptr) png_reset_crc(png_ptr); png_crc_read(png_ptr, png_ptr->chunk_name, 4); - png_debug2(0, "Reading %s chunk, length=%d.\n", png_ptr->chunk_name, + png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name, length); /* This should be a binary subdivision search or a hash for @@ -465,7 +466,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; #endif int ret; - png_debug2(1, "in png_read_row (row %d, pass %d)\n", + png_debug2(1, "in png_read_row (row %lu, pass %d)\n", png_ptr->row_number, png_ptr->pass); /* save jump buffer and error functions */ if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) @@ -697,7 +698,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.7rc2 + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.8rc1 */ void PNGAPI @@ -746,7 +747,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.7rc2 + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.8rc1 */ void PNGAPI png_read_image(png_structp png_ptr, png_bytepp image) diff --git a/pngrio.c b/pngrio.c index 390319312..8e9a6b36b 100644 --- a/pngrio.c +++ b/pngrio.c @@ -1,7 +1,7 @@ /* pngrio.c - functions for data input * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -47,13 +47,16 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) /* fread() returns 0 on error, so it is OK to store this in a png_size_t * instead of an int, which is what fread() actually returns. */ +#if defined(_WIN32_WCE) + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else check = (png_size_t)fread(data, (png_size_t)1, length, - (FILE *)png_ptr->io_ptr); + (png_FILE_p)png_ptr->io_ptr); +#endif if (check != length) - { png_error(png_ptr, "Read Error"); - } } #else /* this is the model-independent version. Since the standard I/O library @@ -69,14 +72,19 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { int check; png_byte *n_data; - FILE *io_ptr; + png_FILE_p io_ptr; /* Check if data really is near. If so, use usual code. */ n_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); if ((png_bytep)n_data == data) { +#if defined(_WIN32_WCE) + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else check = fread(n_data, 1, length, io_ptr); +#endif } else { @@ -87,7 +95,12 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) do { read = MIN(NEAR_BUF_SIZE, remaining); +#if defined(_WIN32_WCE) + if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) + err = 0; +#else err = fread(buf, (png_size_t)1, read, io_ptr); +#endif png_memcpy(data, buf, read); /* copy far buffer to near buffer */ if(err != read) break; @@ -99,9 +112,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) while (remaining != 0); } if ((png_uint_32)check != (png_uint_32)length) - { png_error(png_ptr, "read Error"); - } } #endif #endif diff --git a/pngrtran.c b/pngrtran.c index 5489d232e..d84c6a2bc 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,7 +1,7 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -1125,7 +1125,7 @@ png_do_read_transformations(png_structp png_ptr) #if !defined(PNG_USELESS_TESTS_SUPPORTED) if (png_ptr->row_buf == NULL) { -#if !defined(PNG_NO_STDIO) +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) char msg[50]; sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number, diff --git a/pngrutil.c b/pngrutil.c index 7619fa2f9..2be3c87b8 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -14,6 +14,30 @@ #define PNG_INTERNAL #include "png.h" +#if defined(_WIN32_WCE) +/* strtod() function is not supported on WindowsCE */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +__inline double strtod(const char *nptr, char **endptr) +{ + double result = 0; + int len; + wchar_t *str, *end; + + len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); + str = (wchar_t *)malloc(len * sizeof(wchar_t)); + if ( NULL != str ) + { + 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); + free(str); + } + return result; +} +# endif +#endif + #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED /* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ png_uint_32 /* PRIVATE */ @@ -225,11 +249,18 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, } if (ret != Z_STREAM_END) { -#if !defined(PNG_NO_STDIO) +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) char umsg[50]; - sprintf(umsg,"Incomplete compressed datastream in %s chunk", - png_ptr->chunk_name); + if (ret == Z_BUF_ERROR) + sprintf(umsg,"Buffer error in compressed datastream in %s chunk", + png_ptr->chunk_name); + else if (ret == Z_DATA_ERROR) + sprintf(umsg,"Data error in compressed datastream in %s chunk", + png_ptr->chunk_name); + else + sprintf(umsg,"Incomplete compressed datastream in %s chunk", + png_ptr->chunk_name); png_warning(png_ptr, umsg); #else png_warning(png_ptr, @@ -246,7 +277,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, } else /* if (comp_type != PNG_TEXT_COMPRESSION_zTXt) */ { -#if !defined(PNG_NO_STDIO) +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) char umsg[50]; sprintf(umsg, "Unknown zTXt compression type %d", comp_type); @@ -357,7 +388,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) (png_uint_32)png_ptr->pixel_depth + 7) >> 3); png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth); png_debug1(3,"channels = %d\n", png_ptr->channels); - png_debug1(3,"rowbytes = %d\n", png_ptr->rowbytes); + png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes); png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, interlace_type, compression_type, filter_type); } @@ -585,7 +616,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_warning(png_ptr, "Ignoring incorrect gAMA value when sRGB is also present"); -#ifndef PNG_NO_STDIO +#ifndef PNG_NO_CONSOLE_IO fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma); #endif return; @@ -795,7 +826,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_warning(png_ptr, "Ignoring incorrect cHRM value when sRGB is also present"); -#ifndef PNG_NO_STDIO +#ifndef PNG_NO_CONSOLE_IO #ifdef PNG_FLOATING_POINT_SUPPORTED fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n", white_x, white_y, red_x, red_y); @@ -807,7 +838,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n", int_x_green, int_y_green, int_x_blue, int_y_blue); #endif -#endif /* PNG_NO_STDIO */ +#endif /* PNG_NO_CONSOLE_IO */ } png_crc_finish(png_ptr, 0); return; @@ -901,7 +932,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_warning(png_ptr, "Ignoring incorrect gAMA value when sRGB is also present"); -#ifndef PNG_NO_STDIO +#ifndef PNG_NO_CONSOLE_IO # ifdef PNG_FIXED_POINT_SUPPORTED fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma); # else @@ -1233,9 +1264,11 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #ifdef PNG_FREE_ME_SUPPORTED png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); - png_ptr->free_me |= PNG_FREE_TRNS; + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_ptr->free_me |= PNG_FREE_TRNS; #else - png_ptr->flags |= PNG_FLAG_FREE_TRNS; + 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_ptr->trans_values)); @@ -1479,7 +1512,7 @@ png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #endif #if defined(PNG_READ_pCAL_SUPPORTED) -/* read the pCAL chunk (png-scivis-19970203) */ +/* read the pCAL chunk (described in the PNG Extensions document) */ void /* PRIVATE */ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { @@ -1508,7 +1541,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; } - png_debug1(2, "Allocating and reading pCAL chunk data (%d bytes)\n", + png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n", length + 1); purpose = (png_charp)png_malloc(png_ptr, length + 1); slength = (png_size_t)length; @@ -1628,7 +1661,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; } - png_debug1(2, "Allocating and reading sCAL chunk data (%d bytes)\n", + png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n", length + 1); buffer = (png_charp)png_malloc(png_ptr, length + 1); slength = (png_size_t)length; @@ -2543,7 +2576,7 @@ png_read_filter_row png_bytep prev_row, int filter) { png_debug(1, "in png_read_filter_row\n"); - png_debug2(2,"row = %d, filter = %d\n", png_ptr->row_number, filter); + png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter); switch (filter) { case PNG_FILTER_VALUE_NONE: @@ -2957,12 +2990,12 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); - png_debug1(3, "width = %d,\n", png_ptr->width); - png_debug1(3, "height = %d,\n", png_ptr->height); - png_debug1(3, "iwidth = %d,\n", png_ptr->iwidth); - png_debug1(3, "num_rows = %d\n", png_ptr->num_rows); - png_debug1(3, "rowbytes = %d,\n", png_ptr->rowbytes); - png_debug1(3, "irowbytes = %d,\n", png_ptr->irowbytes); + png_debug1(3, "width = %lu,\n", png_ptr->width); + png_debug1(3, "height = %lu,\n", png_ptr->height); + png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth); + png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows); + png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes); + png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes); png_ptr->flags |= PNG_FLAG_ROW_INIT; } diff --git a/pngset.c b/pngset.c index 0c9b4c63e..eb6fb9e40 100644 --- a/pngset.c +++ b/pngset.c @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -212,7 +212,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, return; length = png_strlen(purpose) + 1; - png_debug1(3, "allocating purpose for info (%d bytes)\n", length); + png_debug1(3, "allocating purpose for info (%lu bytes)\n", length); info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length); png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); @@ -223,7 +223,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_nparams = (png_byte)nparams; length = png_strlen(units) + 1; - png_debug1(3, "allocating units for info (%d bytes)\n", length); + png_debug1(3, "allocating units for info (%lu bytes)\n", length); info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length); png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); @@ -234,7 +234,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, for (i = 0; i < nparams; i++) { length = png_strlen(params[i]) + 1; - png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length); + png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length); info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length); png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); } @@ -556,7 +556,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, textp->key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4)); png_debug2(2, "Allocated %d bytes at %x in png_set_text\n", - key_len + lang_len + lang_key_len + text_length + 4, textp->key); + key_len + lang_len + lang_key_len + text_length + 4, (int)textp->key); png_memcpy(textp->key, text_ptr[i].key, (png_size_t)(key_len)); @@ -659,6 +659,7 @@ png_set_sPLT(png_structp png_ptr, png_memcpy(np, info_ptr->splt_palettes, info_ptr->splt_palettes_num * sizeof(png_sPLT_t)); png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes=NULL; for (i = 0; i < nentries; i++) { @@ -703,6 +704,7 @@ png_set_unknown_chunks(png_structp png_ptr, png_memcpy(np, info_ptr->unknown_chunks, info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk)); png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks=NULL; for (i = 0; i < num_unknowns; i++) { @@ -739,7 +741,7 @@ png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, void PNGAPI png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) { - png_debug1(1, "in png_permit_empty_plte\n", ""); + png_debug(1, "in png_permit_empty_plte\n"); if (png_ptr == NULL) return; png_ptr->empty_plte_permitted=(png_byte)empty_plte_permitted; @@ -774,6 +776,7 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep { png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; } png_memcpy(new_list+5*old_num_chunks, chunk_list, 5*num_chunks); for (p=new_list+5*old_num_chunks+4, i=0; iio_ptr)); +#if defined(_WIN32_WCE) + if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else + check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); +#endif if (check != length) - { png_error(png_ptr, "Write Error"); - } } #else /* this is the model-independent version. Since the standard I/O library @@ -64,14 +67,19 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { png_uint_32 check; png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ - FILE *io_ptr; + png_FILE_p io_ptr; /* Check if data really is near. If so, use usual code. */ near_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); if ((png_bytep)near_data == data) { +#if defined(_WIN32_WCE) + if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) + check = 0; +#else check = fwrite(near_data, 1, length, io_ptr); +#endif } else { @@ -83,7 +91,12 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { written = MIN(NEAR_BUF_SIZE, remaining); png_memcpy(buf, data, written); /* copy far buffer to near buffer */ +#if defined(_WIN32_WCE) + if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) + err = 0; +#else err = fwrite(buf, 1, written, io_ptr); +#endif if (err != written) break; else @@ -94,9 +107,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) while (remaining != 0); } if (check != length) - { png_error(png_ptr, "Write Error"); - } } #endif @@ -117,10 +128,12 @@ png_flush(png_structp png_ptr) static void /* PRIVATE */ png_default_flush(png_structp png_ptr) { - FILE *io_ptr; - io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr)); +#if !defined(_WIN32_WCE) + png_FILE_p io_ptr; + io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); if (io_ptr != NULL) fflush(io_ptr); +#endif } #endif #endif diff --git a/pngwrite.c b/pngwrite.c index 1c7cd0ee1..ad83cdf9f 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,7 +1,7 @@ /* pngwrite.c - general routines to write a PNG file * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -375,9 +375,12 @@ png_write_end(png_structp png_ptr, png_infop info_ptr) /* write end of PNG file */ png_write_IEND(png_ptr); + png_flush(png_ptr); } #if defined(PNG_WRITE_tIME_SUPPORTED) +#if !defined(_WIN32_WCE) +/* "time.h" functions are not supported on WindowsCE */ void PNGAPI png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) { @@ -400,6 +403,7 @@ png_convert_from_time_t(png_timep ptime, time_t ttime) png_convert_from_struct_tm(ptime, tbuf); } #endif +#endif /* Initialize png_ptr structure, and allocate any memory needed */ png_structp PNGAPI @@ -444,6 +448,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, #endif { png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf=NULL; png_destroy_struct(png_ptr); return ((png_structp)NULL); } @@ -734,11 +739,11 @@ png_write_row(png_structp png_ptr, png_bytep row) (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3); png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type); - png_debug1(3, "row_info->width = %d\n", png_ptr->row_info.width); + png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width); png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels); png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth); png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth); - png_debug1(3, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes); + png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes); /* Copy user's row into buffer, leaving room for filter byte. */ png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, @@ -863,6 +868,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) if (png_ptr->num_chunk_list) { png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; png_ptr->num_chunk_list=0; } #endif diff --git a/pngwtran.c b/pngwtran.c index d066e3602..78999eafb 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -1,7 +1,7 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngwutil.c b/pngwutil.c index 78ba9f7aa..b41447407 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,7 +1,7 @@ /* pngwutil.c - utilities to write a PNG file * - * libpng 1.0.7rc2 - June 28, 2000 + * libpng 1.0.8rc1 - July 17, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -77,7 +77,7 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, png_uint_32 length) { png_byte buf[4]; - png_debug2(0, "Writing %s chunk (%d bytes)\n", chunk_name, length); + png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length); /* write the length */ png_save_uint_32(buf, length); @@ -172,7 +172,7 @@ png_text_compress(png_structp png_ptr, if (compression >= PNG_TEXT_COMPRESSION_LAST) { -#if !defined(PNG_NO_STDIO) +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) char msg[50]; sprintf(msg, "Unknown compression type %d", compression); png_warning(png_ptr, msg); @@ -339,9 +339,11 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i], png_ptr->zbuf_size); png_free(png_ptr, comp->output_ptr[i]); + comp->output_ptr[i]=NULL; } if (comp->max_output_ptr != 0) png_free(png_ptr, comp->output_ptr); + comp->output_ptr=NULL; /* write anything left in zbuf */ if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) png_write_chunk_data(png_ptr, png_ptr->zbuf, @@ -837,8 +839,8 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y, white_x + white_y > 1.0) { png_warning(png_ptr, "Invalid cHRM white point specified"); -#if !defined(PNG_NO_STDIO) - printf("white_x=%f, white_y=%f\n",white_x, white_y); +#if !defined(PNG_NO_CONSOLE_IO) + fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y); #endif return; } @@ -900,8 +902,8 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L) { png_warning(png_ptr, "Invalid fixed cHRM white point specified"); -#if !defined(PNG_NO_STDIO) - printf("white_x=%ld, white_y=%ld\n",white_x, white_y); +#if !defined(PNG_NO_CONSOLE_IO) + fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y); #endif return; } @@ -1088,7 +1090,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key) { if (*kp < 0x20 || (*kp > 0x7E && (png_byte)*kp < 0xA1)) { -#if !defined(PNG_NO_STDIO) +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) char msg[40]; sprintf(msg, "invalid keyword character 0x%02X", *kp); @@ -1368,7 +1370,7 @@ png_write_oFFs(png_structp png_ptr, png_uint_32 x_offset, #endif #if defined(PNG_WRITE_pCAL_SUPPORTED) -/* write the pCAL chunk (png-scivis-19970203) */ +/* write the pCAL chunk (described in the PNG extensions document) */ void /* PRIVATE */ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) @@ -1400,7 +1402,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, for (i = 0; i < nparams; i++) { params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); - png_debug2(3, "pCAL parameter %d length = %d\n", i, params_len[i]); + png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]); total_len += (png_size_t)params_len[i]; } @@ -1441,8 +1443,19 @@ png_write_sCAL(png_structp png_ptr, int unit, double width,double height) png_debug(1, "in png_write_sCAL\n"); +#if defined(_WIN32_WCE) +/* sprintf() function is not supported on WindowsCE */ + { + wchar_t wc_buf[32]; + swprintf(wc_buf, TEXT("%12.12e"), width); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, wbuf, 32, NULL, NULL); + swprintf(wc_buf, TEXT("%12.12e"), height); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, hbuf, 32, NULL, NULL); + } +#else sprintf(wbuf, "%12.12e", width); sprintf(hbuf, "%12.12e", height); +#endif total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf); png_debug1(3, "sCAL total length = %d\n", total_len); diff --git a/zutil.c b/zutil.c index b3de4e883..d0a9da58f 100644 --- a/zutil.c +++ b/zutil.c @@ -202,6 +202,7 @@ void zcfree (voidpf opaque, voidpf ptr) #ifndef STDC extern voidp calloc OF((uInt items, uInt size)); +extern voidp malloc OF((uInt items)); extern void free OF((voidpf ptr)); #endif @@ -214,6 +215,16 @@ voidpf zcalloc (opaque, items, size) return (voidpf)calloc(items, size); } +/* added to version 1.1.3pc -- glennrp */ +voidpf zmalloc (opaque, items, size) + voidpf opaque; + unsigned items; + unsigned size; +{ + if (opaque) items += size - size; /* make compiler happy */ + return (voidpf)malloc(items * size); +} + void zcfree (opaque, ptr) voidpf opaque; voidpf ptr;