From 77396b63f97b7d15ed6fcdb6d1016213d5d3bd55 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Mon, 2 Aug 2010 08:00:10 -0500 Subject: [PATCH] [devel] VisualC/GCC warning fixes, VisualC build fixes The changes include support for function attributes in VC in addition to those already present in GCC - necessary because without these some warnings are unavoidable. Fixes include signed/unsigned fixes in pngvalid and checks with gcc -Wall -Wextra -Wunused. VC requires function attributes on function definitions as well as declarations, PNG_FUNCTION has been added to enable this and the relevant function definitions changed. --- ANNOUNCE | 15 +- CHANGES | 14 +- png.c | 26 +-- png.h | 19 +- pngconf.h | 61 +++++- pngerror.c | 38 ++-- pngmem.c | 50 ++--- pngpriv.h | 17 +- pngread.c | 14 +- pngvalid.c | 215 ++++++++++++-------- pngwrite.c | 14 +- projects/vstudio/libpng/libpng.vcxproj | 20 +- projects/vstudio/pngtest/pngtest.vcxproj | 28 +-- projects/vstudio/pngvalid/pngvalid.vcxproj | 219 +++++++++++++++++++++ projects/vstudio/readme.txt | 63 ++---- projects/vstudio/vstudio.sln | 36 +++- projects/vstudio/zlib.props | 37 ++-- projects/vstudio/zlib/zlib.vcxproj | 105 ++++++---- 18 files changed, 678 insertions(+), 313 deletions(-) create mode 100644 projects/vstudio/pngvalid/pngvalid.vcxproj diff --git a/ANNOUNCE b/ANNOUNCE index 419d8b4f0..6ef35afe9 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.5.0beta39 - July 31, 2010 +Libpng 1.5.0beta39 - August 2, 2010 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -226,7 +226,7 @@ version 1.5.0beta24 [May 7, 2010] offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf. Added more blank lines for readability. -version 1.5.0beta25 [July 31, 2010] +version 1.5.0beta25 [August 2, 2010] In pngpread.c: png_push_have_row() add check for new_row > height Removed the now-redundant check for out-of-bounds new_row from example.c @@ -324,7 +324,16 @@ version 1.5.0beta38 [July 31, 2010] Revised png_get_int_16() to be similar to png_get_int_32(). Restored projects/visualc71. -version 1.5.0beta39 [July 31, 2010] +version 1.5.0beta39 [August 2, 2010] + VisualC/GCC warning fixes, VisualC build fixes + The changes include support for function attributes in VC in addition to + those already present in GCC - necessary because without these some + warnings are unavoidable. Fixes include signed/unsigned fixes in + pngvalid and checks with gcc -Wall -Wextra -Wunused. + VC requires function attributes on function definitions as well as + declarations, PNG_FUNCTION has been added to enable this and the + relevant function definitions changed. + Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit diff --git a/CHANGES b/CHANGES index f71aeb8f6..acc253f14 100644 --- a/CHANGES +++ b/CHANGES @@ -2806,7 +2806,19 @@ version 1.5.0beta38 [July 31, 2010] Revised png_get_int_16() to be similar to png_get_int_32(). Restored projects/visualc71. -version 1.5.0beta39 [July 31, 2010] +version 1.5.0beta39 [August 2, 2010] + VisualC/GCC warning fixes, VisualC build fixes + The changes include support for function attributes in VC in addition to + those already present in GCC - necessary because without these some + warnings are unavoidable. Fixes include signed/unsigned fixes in + pngvalid and checks with gcc -Wall -Wextra -Wunused. + VC requires function attributes on function definitions as well as + declarations, PNG_FUNCTION has been added to enable this and the + relevant function definitions changed. + +projects/vstudio now builds and runs all tests (pngvalid added), +however the DLL builds are probably not useful as there seems to be no +way to avoid dependency on the VC runtime in the DLL case. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/png.c b/png.c index 948bd4632..5469f3d4f 100644 --- a/png.c +++ b/png.c @@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions * - * Last changed in libpng 1.5.0 [July 31, 2010] + * Last changed in libpng 1.5.0 [August 2, 2010] * Copyright (c) 1998-2010 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.) @@ -73,8 +73,8 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) /* Function to allocate memory for zlib and clear it to 0. */ -voidpf /* PRIVATE */ -png_zalloc(voidpf png_ptr, uInt items, uInt size) +PNG_FUNCTION(voidpf /* PRIVATE */, +png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED) { png_voidp ptr; png_structp p=(png_structp)png_ptr; @@ -147,8 +147,8 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length) * and png_info_init() so that applications that want to use a shared * libpng don't have to be recompiled if png_info changes size. */ -png_infop PNGAPI -png_create_info_struct(png_structp png_ptr) +PNG_FUNCTION(png_infop,PNGAPI +png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED) { png_infop info_ptr; @@ -560,13 +560,13 @@ png_get_copyright(png_structp png_ptr) #else # ifdef __STDC__ return ((png_charp) PNG_STRING_NEWLINE \ - "libpng version 1.5.0beta39 - July 31, 2010" PNG_STRING_NEWLINE \ + "libpng version 1.5.0beta39 - August 2, 2010" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE); # else - return ((png_charp) "libpng version 1.5.0beta39 - July 31, 2010\ + return ((png_charp) "libpng version 1.5.0beta39 - August 2, 2010\ Copyright (c) 1998-2010 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); @@ -1430,9 +1430,9 @@ png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, { unsigned i; *ascii++ = 46; /* decimal point */ - /* ndigits may be <5 for small numbers, output leading zeros then - * ndigits digits to first: - */ + /* ndigits may be <5 for small numbers, output leading zeros + * then ndigits digits to first: + */ i = 5; while (ndigits < i) *ascii++ = 48, --i; while (ndigits >= first) *ascii++ = digits[--ndigits]; @@ -1454,7 +1454,7 @@ png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, # endif /* FIXED_POINT */ #endif /* READ_SCAL */ -#if defined(PNG_FLOATING_POINT_SUPPORTED) &&\ +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) png_fixed_point png_fixed(png_structp png_ptr, double fp, png_const_charp text) @@ -1465,11 +1465,11 @@ png_fixed(png_structp png_ptr, double fp, png_const_charp text) return (png_fixed_point)r; png_fixed_error(png_ptr, text); - return 0; /*NOT REACHED*/ + /*NOT REACHED*/ } #endif -#if defined(PNG_READ_GAMMA_SUPPORTED) ||\ +#if defined(PNG_READ_GAMMA_SUPPORTED) || \ defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG__READ_pHYs_SUPPORTED) /* muldiv functions */ /* This API takes signed arguments and rounds the result to the nearest diff --git a/png.h b/png.h index 107075f8e..8605907f6 100644 --- a/png.h +++ b/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.5.0beta39 - July 31, 2010 + * libpng version 1.5.0beta39 - August 2, 2010 * Copyright (c) 1998-2010 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -11,7 +11,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.5.0beta39 - July 31, 2010: Glenn + * libpng versions 0.97, January 1998, through 1.5.0beta39 - August 2, 2010: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -172,7 +172,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.5.0beta39, July 31, 2010, are + * libpng versions 1.2.6, August 15, 2004, through 1.5.0beta39, August 2, 2010, are * Copyright (c) 2004, 2006-2010 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.2.5 * with the following individual added to the list of Contributing Authors: @@ -284,7 +284,7 @@ * Y2K compliance in libpng: * ========================= * - * July 31, 2010 + * August 2, 2010 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. @@ -348,7 +348,7 @@ /* Version information for png.h - this should match the version in png.c */ #define PNG_LIBPNG_VER_STRING "1.5.0beta39" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.5.0beta39 - July 31, 2010\n" + " libpng version 1.5.0beta39 - August 2, 2010\n" #define PNG_LIBPNG_VER_SONUM 15 #define PNG_LIBPNG_VER_DLLNUM 15 @@ -801,7 +801,9 @@ typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp),); #ifdef PNG_SETJMP_SUPPORTED /* This must match the function definition in , and the * application must include this before png.h to obtain the definition - * of jmp_buf. The function is required to be PNG_NORETURN. + * of jmp_buf. The function is required to be PNG_NORETURN. (Note that + * PNG_PTR_NORETURN is used here because current versions of the Microsoft + * C compiler do not support the PNG_NORETURN attribute on a pointer.) * * If you get a type warning from the compiler when linking against this line * then your compiler has 'longjmp' that does not match the requirements of the @@ -814,7 +816,8 @@ typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp),); * your compiler. This may be very difficult - try using a different compiler * to build the library! */ -typedef void (PNGCAPI *png_longjmp_ptr) PNGARG((jmp_buf, int)) PNG_NORETURN; +typedef PNG_FUNCTION(void,(PNGCAPI *png_longjmp_ptr),PNGARG((jmp_buf, int)), + PNG_PTR_NORETURN); #endif /* Transform masks for the high-level interface */ @@ -1833,7 +1836,7 @@ PNG_FP_EXPORT(void,png_set_sCAL,(png_structp png_ptr, png_infop info_ptr, int unit, double width, double height),,170); PNG_FIXED_EXPORT(void,png_set_sCAL_fixed,(png_structp png_ptr, png_infop info_ptr, int unit, png_fixed_point width, - png_fixed_point height), ,213); + png_fixed_point height),,213); PNG_EXPORT(void,png_set_sCAL_s,(png_structp png_ptr, png_infop info_ptr, int unit, png_charp swidth, png_charp sheight),,171); #endif /* PNG_sCAL_SUPPORTED */ diff --git a/pngconf.h b/pngconf.h index 68414e923..080bb34a7 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.5.0beta39 - July 31, 2010 + * libpng version 1.5.0beta39 - August 2, 2010 * * Copyright (c) 1998-2010 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -281,12 +281,36 @@ # endif #endif +/* THe following complexity is concerned with getting the 'attributes' of the + * declared function in the correct place. This potentially requires a separate + * PNG_EXPORT function for every compiler. + */ +#ifndef PNG_FUNCTION +# ifdef __GNUC__ +# define PNG_FUNCTION(type, name, args, attributes)\ + attributes type name args +# else /* !GNUC */ +# ifdef _MSC_VER +# define PNG_FUNCTION(type, name, args, attributes)\ + attributes type name args +# else /* !MSC */ +# define PNG_FUNCTION(type, name, args, attributes)\ + type name args +# endif +# endif +#endif + #ifndef PNG_EXPORT_TYPE # define PNG_EXPORT_TYPE(type) PNG_IMPEXP type #endif + #ifndef PNG_EXPORT + /* The ordinal value is only relevant when preprocessing png.h for symbol + * table entries. + */ # define PNG_EXPORT(type, name, args, attributes, ordinal)\ - extern PNG_EXPORT_TYPE(type) (PNGAPI name) PNGARG(args) attributes + extern PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args),\ + attributes) #endif /* Use PNG_REMOVED to comment out a removed interface. */ @@ -325,6 +349,9 @@ # ifndef PNG_NORETURN # define PNG_NORETURN __attribute__((__noreturn__)) # endif +# ifndef PNG_PTR_NORETURN +# define PNG_PTR_NORETURN __attribute__((__noreturn__)) +# endif # ifndef PNG_ALLOCATED # define PNG_ALLOCATED __attribute__((__malloc__)) # endif @@ -351,6 +378,36 @@ # endif /* PNG_PRIVATE */ # endif /* PNGLIB_BUILD */ # endif /* __GNUC__ */ +# ifdef _MSC_VER /* may need to check value */ +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /*not supported*/ +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __declspec(noreturn) +# endif +# ifndef PNG_PTR_NORETURN +# define PNG_PTR_NORETURN /*not supported*/ +# endif +# ifndef PNG_ALLOCATED +# define PNG_ALLOCATED __declspec(restrict) +# endif + + /* This specifically protects structure members that should only be + * accessed from within the library, therefore should be empty during + * a library build. + */ +# ifndef PNGLIB_BUILD +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __declspec(deprecated) +# endif +# ifndef PNG_DEPSTRUCT +# define PNG_DEPSTRUCT __declspec(deprecated) +# endif +# ifndef PNG_PRIVATE +# define PNG_PRIVATE __declspec(deprecated) +# endif /* PNG_PRIVATE */ +# endif /* PNGLIB_BUILD */ +# endif /* __GNUC__ */ #endif /* PNG_PEDANTIC_WARNINGS */ #ifndef PNG_DEPRECATED diff --git a/pngerror.c b/pngerror.c index 7b40d4865..70c7be607 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * Last changed in libpng 1.5.0 [July 31, 2010] + * Last changed in libpng 1.5.0 [August 2, 2010] * Copyright (c) 1998-2010 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.) @@ -20,13 +20,13 @@ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -static void /* PRIVATE */ -png_default_error PNGARG((png_structp png_ptr, - png_const_charp error_message)) PNG_NORETURN; +static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr, + png_const_charp error_message)),PNG_NORETURN); + #ifdef PNG_WARNINGS_SUPPORTED static void /* PRIVATE */ png_default_warning PNGARG((png_structp png_ptr, - png_const_charp warning_message)); + png_const_charp warning_message)); #endif /* PNG_WARNINGS_SUPPORTED */ /* This function is called whenever there is a fatal error. This function @@ -35,8 +35,8 @@ png_default_warning PNGARG((png_structp png_ptr, * to replace the error function at run-time. */ #ifdef PNG_ERROR_TEXT_SUPPORTED -void PNGAPI -png_error(png_structp png_ptr, png_const_charp error_message) +PNG_FUNCTION(void,PNGAPI +png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) { #ifdef PNG_ERROR_NUMBERS_SUPPORTED char msg[16]; @@ -86,8 +86,8 @@ png_error(png_structp png_ptr, png_const_charp error_message) png_default_error(png_ptr, error_message); } #else -void PNGAPI -png_err(png_structp png_ptr) +PNG_FUNCTION(void,PNGAPI +png_err,(png_structp png_ptr),PNG_NORETURN) { if (png_ptr != NULL && png_ptr->error_fn != NULL) (*(png_ptr->error_fn))(png_ptr, '\0'); @@ -192,8 +192,9 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp #endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */ #if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) -void PNGAPI -png_chunk_error(png_structp png_ptr, png_const_charp error_message) +PNG_FUNCTION(void,PNGAPI +png_chunk_error,(png_structp png_ptr, png_const_charp error_message), + PNG_NORETURN) { char msg[18+PNG_MAX_ERROR_TEXT]; if (png_ptr == NULL) @@ -239,8 +240,8 @@ png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message) #ifdef PNG_ERROR_TEXT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED -void -png_fixed_error(png_structp png_ptr, png_const_charp name) +PNG_FUNCTION(void, +png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN) { # define fixed_message "fixed point overflow in " # define fixed_message_ln ((sizeof fixed_message)-1) @@ -280,8 +281,9 @@ png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn, * function is used by default, or if the program supplies NULL for the * error function pointer in png_set_error_fn(). */ -static void /* PRIVATE */ -png_default_error(png_structp png_ptr, png_const_charp error_message) +static PNG_FUNCTION(void /* PRIVATE */, +png_default_error,(png_structp png_ptr, png_const_charp error_message), + PNG_NORETURN) { #ifdef PNG_CONSOLE_IO_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED @@ -319,14 +321,14 @@ png_default_error(png_structp png_ptr, png_const_charp error_message) fprintf(stderr, PNG_STRING_NEWLINE); } #endif - png_longjmp(png_ptr, 1); #ifndef PNG_CONSOLE_IO_SUPPORTED error_message = error_message; /* Make compiler happy */ #endif + png_longjmp(png_ptr, 1); } -void PNGAPI -png_longjmp(png_structp png_ptr, int val) +PNG_FUNCTION(void,PNGAPI +png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN) { #ifdef PNG_SETJMP_SUPPORTED if (png_ptr && png_ptr->longjmp_fn) diff --git a/pngmem.c b/pngmem.c index e50ab9fb2..019453071 100644 --- a/pngmem.c +++ b/pngmem.c @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.5.0 [July 31, 2010] + * Last changed in libpng 1.5.0 [August 2, 2010] * Copyright (c) 1998-2010 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.) @@ -27,16 +27,17 @@ /* Allocate memory for a png_struct. The malloc and memset can be replaced by a single call to calloc() if this is thought to improve performance. */ -png_voidp /* PRIVATE */ -png_create_struct(int type) +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct,(int type),PNG_ALLOCATED) { # ifdef PNG_USER_MEM_SUPPORTED return (png_create_struct_2(type, NULL, NULL)); } /* Alternate version of png_create_struct, for use with user-defined malloc. */ -png_voidp /* PRIVATE */ -png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), + PNG_ALLOCATED) { # endif /* PNG_USER_MEM_SUPPORTED */ png_size_t size; @@ -119,8 +120,8 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, * result, we would be truncating potentially larger memory requests * (which should cause a fatal error) and introducing major problems. */ -png_voidp PNGAPI -png_calloc(png_structp png_ptr, png_alloc_size_t size) +PNG_FUNCTION(png_voidp,PNGAPI +png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ret; @@ -132,8 +133,8 @@ png_calloc(png_structp png_ptr, png_alloc_size_t size) return (ret); } -png_voidp PNGAPI -png_malloc(png_structp png_ptr, png_alloc_size_t size) +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ret; @@ -153,8 +154,8 @@ png_malloc(png_structp png_ptr, png_alloc_size_t size) return (ret); } -png_voidp PNGAPI -png_malloc_default(png_structp png_ptr, png_alloc_size_t size) +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ret; # endif /* PNG_USER_MEM_SUPPORTED */ @@ -364,8 +365,8 @@ png_free_default(png_structp png_ptr, png_voidp ptr) /* Allocate memory for a png_struct or a png_info. The malloc and memset can be replaced by a single call to calloc() if this is thought to improve performance noticably. */ -png_voidp /* PRIVATE */ -png_create_struct(int type) +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct,(int type),PNG_ALLOCATED) { # ifdef PNG_USER_MEM_SUPPORTED return (png_create_struct_2(type, NULL, NULL)); @@ -374,8 +375,9 @@ png_create_struct(int type) /* Allocate memory for a png_struct or a png_info. The malloc and memset can be replaced by a single call to calloc() if this is thought to improve performance noticably. */ -png_voidp /* PRIVATE */ -png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), + PNG_ALLOCATED) { # endif /* PNG_USER_MEM_SUPPORTED */ png_size_t size; @@ -470,8 +472,8 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, * have the ability to do that. */ -png_voidp PNGAPI -png_calloc(png_structp png_ptr, png_alloc_size_t size) +PNG_FUNCTION(png_voidp,PNGAPI +png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ret; @@ -483,8 +485,8 @@ png_calloc(png_structp png_ptr, png_alloc_size_t size) return (ret); } -png_voidp PNGAPI -png_malloc(png_structp png_ptr, png_alloc_size_t size) +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ret; @@ -504,8 +506,8 @@ png_malloc(png_structp png_ptr, png_alloc_size_t size) return (ret); } -png_voidp PNGAPI -png_malloc_default(png_structp png_ptr, png_alloc_size_t size) +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ret; # endif /* PNG_USER_MEM_SUPPORTED */ @@ -579,6 +581,7 @@ png_free(png_structp png_ptr, png_voidp ptr) else png_free_default(png_ptr, ptr); } + void PNGAPI png_free_default(png_structp png_ptr, png_voidp ptr) { @@ -600,7 +603,6 @@ png_free_default(png_structp png_ptr, png_voidp ptr) # endif # endif } - #endif /* Not Borland DOS special memory handler */ /* This function was added at libpng version 1.2.3. The png_malloc_warn() @@ -608,8 +610,8 @@ png_free_default(png_structp png_ptr, png_voidp ptr) * instead of issuing a png_error, if it fails to allocate the requested * memory. */ -png_voidp PNGAPI -png_malloc_warn(png_structp png_ptr, png_alloc_size_t size) +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) { png_voidp ptr; png_uint_32 save_flags; diff --git a/pngpriv.h b/pngpriv.h index e268c96c3..e50faf809 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -1,7 +1,7 @@ /* pngpriv.h - private declarations for use inside libpng * - * libpng version 1.5.0beta39 - July 31, 2010 + * libpng version 1.5.0beta39 - August 2, 2010 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2010 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -439,13 +439,15 @@ extern "C" { */ /* Allocate memory for an internal libpng struct */ -PNG_EXTERN png_voidp png_create_struct PNGARG((int type)); +PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)), + PNG_ALLOCATED); /* Free memory from internal libpng struct */ PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); -PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr - malloc_fn, png_voidp mem_ptr)); +PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2, + PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)), + PNG_ALLOCATED); PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, png_free_ptr free_fn, png_voidp mem_ptr)); @@ -454,7 +456,8 @@ PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, png_infop info_ptr)); /* Function to allocate memory for zlib. PNGAPI is disallowed. */ -PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size)); +PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items, + uInt size)),PNG_ALLOCATED); /* Function to free memory for zlib. PNGAPI is disallowed. */ PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); @@ -1028,8 +1031,8 @@ PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr, #endif /* USE_FAR_KEYWORD */ #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) -PNG_EXTERN void png_fixed_error PNGARG((png_structp png_ptr, - png_const_charp name)) PNG_NORETURN; +PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, + png_const_charp name),PNG_NORETURN); #endif /* ASCII to FP interfaces, currently only implemented if sCAL diff --git a/pngread.c b/pngread.c index a542457b6..8095b819c 100644 --- a/pngread.c +++ b/pngread.c @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.5.0 [July 31, 2010] + * Last changed in libpng 1.5.0 [August 2, 2010] * Copyright (c) 1998-2010 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.) @@ -19,9 +19,9 @@ #ifdef PNG_READ_SUPPORTED /* Create a PNG structure for reading, and allocate any memory needed. */ -png_structp PNGAPI -png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn) +PNG_FUNCTION(png_structp,PNGAPI +png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) { #ifdef PNG_USER_MEM_SUPPORTED @@ -32,10 +32,10 @@ png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, /* Alternate create PNG structure for reading, and allocate any memory * needed. */ -png_structp PNGAPI -png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, +PNG_FUNCTION(png_structp,PNGAPI +png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, - png_malloc_ptr malloc_fn, png_free_ptr free_fn) + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) { #endif /* PNG_USER_MEM_SUPPORTED */ diff --git a/pngvalid.c b/pngvalid.c index 1eaefb740..bddb50050 100644 --- a/pngvalid.c +++ b/pngvalid.c @@ -26,8 +26,16 @@ #include /* For jmp_buf, setjmp, longjmp */ #include /* For floor */ +/* Unused formal parameter errors are removed using the following macro which is + * expected to have no bad effects on performance. + */ +#ifndef UNUSED +#define UNUSED(param) param = param; +#endif + /******************************* ERROR UTILITIES ******************************/ -static size_t safecat(char *buffer, size_t bufsize, size_t pos, const char *cat) +static size_t safecat(char *buffer, size_t bufsize, size_t pos, + PNG_CONST char *cat) { while (pos < bufsize && cat != NULL && *cat != 0) buffer[pos++] = *cat++; if (pos >= bufsize) pos = bufsize-1; @@ -50,16 +58,16 @@ static size_t safecatd(char *buffer, size_t bufsize, size_t pos, double d, return safecat(buffer, bufsize, pos, number); } -static const char invalid[] = "invalid"; -static const char sep[] = ": "; +static PNG_CONST char invalid[] = "invalid"; +static PNG_CONST char sep[] = ": "; /* NOTE: this is indexed by ln2(bit_depth)! */ -static const char *bit_depths[8] = +static PNG_CONST char *bit_depths[8] = { "1", "2", "4", "8", "16", invalid, invalid, invalid }; -static const char *colour_types[8] = +static PNG_CONST char *colour_types[8] = { "greyscale", invalid, "truecolour", "indexed-colour", "greyscale with alpha", invalid, "truecolour with alpha", invalid @@ -110,7 +118,7 @@ next_format(png_bytep colour_type, png_bytep bit_depth) return 0; } -static inline unsigned +static unsigned sample(png_byte *row, png_byte colour_type, png_byte bit_depth, png_uint_32 x, unsigned sample) { @@ -235,6 +243,8 @@ store_storenew(png_store *ps) ps->writepos = 0; } +/* Currently unused: */ +#if 0 static void store_freefile(png_store_file *pf) { @@ -245,6 +255,7 @@ store_freefile(png_store_file *pf) pf->datacount = 0; free(pf); } +#endif /* Main interface to file storeage, after writing a new PNG file (see the API * below) call store_storefile to store the result with the given name and id. @@ -269,7 +280,7 @@ store_storefile(png_store *ps, png_uint_32 id) /* Generate an error message (in the given buffer) */ static size_t -store_message(png_structp pp, char *buffer, size_t bufsize, const char *msg) +store_message(png_structp pp, char *buffer, size_t bufsize, PNG_CONST char *msg) { size_t pos = 0; png_store *ps = png_get_error_ptr(pp); @@ -365,6 +376,7 @@ store_write(png_structp pp, png_bytep pb, png_size_t st) static void store_flush(png_structp pp) { + pp = pp; /*DOES NOTHING*/ } @@ -444,7 +456,8 @@ store_write_reset(png_store *ps) * returned libpng structures as destroyed by store_write_reset above. */ static png_structp -set_store_for_write(png_store *ps, png_infopp ppi, const char name[64]) +set_store_for_write(png_store *ps, png_infopp ppi, + PNG_CONST char * volatile name) { if (setjmp(ps->jmpbuf) != 0) return NULL; @@ -510,7 +523,7 @@ store_read_set(png_store *ps, png_uint_32 id) */ static png_structp set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id, - const char *name) + PNG_CONST char *name) { safecat(ps->test, sizeof ps->test, 0, name); @@ -568,7 +581,7 @@ typedef struct png_modifier unsigned ngammas; /* Lowest sbit to test (libpng fails for sbit < 8) */ - unsigned sbitlow; + png_byte sbitlow; /* Error control - these are the limits on errors accepted by the gamma tests * below. @@ -590,10 +603,10 @@ typedef struct png_modifier /* Flags: */ /* When to use the use_input_precision option: */ - int use_input_precision :1; - int use_input_precision_sbit :1; - int use_input_precision_16to8 :1; - int log :1; /* Log max error */ + unsigned use_input_precision :1; + unsigned use_input_precision_sbit :1; + unsigned use_input_precision_16to8 :1; + unsigned log :1; /* Log max error */ /* Buffer information, the buffer size limits the size of the chunks that can * be modified - they must fit (including header and CRC) into the buffer! @@ -633,7 +646,7 @@ static double outerr(png_modifier *pm, png_byte bit_depth) static int fail(png_modifier *pm) { return !pm->log && !pm->this.verbose && (pm->this.nerrors > 0 || - pm->this.treat_warnings_as_errors && pm->this.nwarnings > 0); + (pm->this.treat_warnings_as_errors && pm->this.nwarnings > 0)); } static void @@ -643,7 +656,7 @@ modifier_init(png_modifier *pm) store_init(&pm->this); pm->modifications = NULL; pm->state = modifier_start; - pm->sbitlow = 1; + pm->sbitlow = 1U; pm->maxout8 = pm->maxpc8 = pm->maxabs8 = 0; pm->maxout16 = pm->maxpc16 = pm->maxabs16 = 0; pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0; @@ -846,7 +859,7 @@ modifier_read(png_structp pp, png_bytep pb, png_size_t st) while (mod != NULL) { if ((mod->add == chunk || - mod->add == CHUNK_PLTE && chunk == CHUNK_IDAT) && + (mod->add == CHUNK_PLTE && chunk == CHUNK_IDAT)) && mod->modify_fn != NULL && !mod->modified && !mod->added) { /* Regardless of what the modify function does do not run this @@ -946,15 +959,15 @@ modifier_read(png_structp pp, png_bytep pb, png_size_t st) /* Set up a modifier. */ static png_structp set_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id, - const char *name) + PNG_CONST char *name) { - png_structp pp = set_store_for_read(&pm->this, ppi, id, name); + volatile png_structp ppSafe = set_store_for_read(&pm->this, ppi, id, name); - if (pp != NULL) + if (ppSafe != NULL) { if (setjmp(pm->this.jmpbuf) == 0) { - png_set_read_fn(pp, pm, modifier_read); + png_set_read_fn(ppSafe, pm, modifier_read); pm->state = modifier_start; pm->bit_depth = 0; @@ -969,11 +982,11 @@ set_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id, else { store_read_reset(&pm->this); - pp = NULL; + ppSafe = NULL; } } - return pp; + return ppSafe; } /***************************** STANDARD PNG FILES *****************************/ @@ -986,11 +999,11 @@ set_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id, * and with an ID derived from the colour type and bit depth as follows: */ #define FILEID(col, depth) ((png_uint_32)((col) + ((depth)<<3))) -#define COL_FROM_ID(id) ((id)& 0x7) -#define DEPTH_FROM_ID(id) (((id) >> 3) & 0x1f) +#define COL_FROM_ID(id) ((id)& 0x7U) +#define DEPTH_FROM_ID(id) (((id) >> 3) & 0x1fU) -#define STD_WIDTH 128 -#define STD_ROWMAX (STD_WIDTH*8) +#define STD_WIDTH 128U +#define STD_ROWMAX (STD_WIDTH*8U) static unsigned bit_size(png_structp pp, png_byte colour_type, png_byte bit_depth) @@ -1012,11 +1025,10 @@ standard_rowsize(png_structp pp, png_byte colour_type, png_byte bit_depth) return (STD_WIDTH * bit_size(pp, colour_type, bit_depth)) / 8; } -static png_uint_32 -standard_width(png_structp pp, png_byte colour_type, png_byte bit_depth) -{ - return STD_WIDTH; -} +/* standard_wdith(pp, colour_type, bit_depth) current returns the same number + * every time, so just use a macro: + */ +#define standard_width(pp, colour_type, bit_depth) STD_WIDTH static png_uint_32 standard_height(png_structp pp, png_byte colour_type, png_byte bit_depth) @@ -1026,6 +1038,7 @@ standard_height(png_structp pp, png_byte colour_type, png_byte bit_depth) case 1: case 2: case 4: + default: return 1; /* Total of 128 pixels */ case 8: return 2; /* Total of 256 pixels/bytes */ @@ -1134,11 +1147,14 @@ standard_row(png_structp pp, png_byte buffer[STD_ROWMAX], png_byte colour_type, } static void -make_standard(png_store* ps, png_byte colour_type, int bdlo, int bdhi) +make_standard(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, + int PNG_CONST bdloIn, int PNG_CONST bdhi) { + volatile int bdlo = bdloIn; + for (; bdlo <= bdhi; ++bdlo) { - png_byte bit_depth = 1U << bdlo; + png_byte bit_depth; png_uint_32 h, y; png_structp pp; png_infop pi; @@ -1164,6 +1180,7 @@ make_standard(png_store* ps, png_byte colour_type, int bdlo, int bdhi) continue; } + bit_depth = 1U << bdlo; h = standard_height(pp, colour_type, bit_depth), png_set_IHDR(pp, pi, standard_width(pp, colour_type, bit_depth), h, bit_depth, colour_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, @@ -1171,9 +1188,11 @@ make_standard(png_store* ps, png_byte colour_type, int bdlo, int bdhi) if (colour_type == 3) /* palette */ { - int i; + unsigned i = 0; png_color pal[256]; - for (i=0; i<256; ++i) pal[i].red = pal[i].green = pal[i].blue = i; + do + pal[i].red = pal[i].green = pal[i].blue = (png_byte)i; + while(++i < 256U); png_set_PLTE(pp, pi, pal, 256); } @@ -1212,8 +1231,11 @@ make_standard_images(png_store *ps) /* Tests - individual test cases */ static void -test_standard(png_store* ps, png_byte colour_type, int bdlo, int bdhi) +test_standard(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, + int PNG_CONST bdloIn, int PNG_CONST bdhi) { + volatile int bdlo = bdloIn; + for (; bdlo <= bdhi; ++bdlo) { png_byte bit_depth = 1U << bdlo; @@ -1327,12 +1349,6 @@ perform_standard_test(png_modifier *pm) /********************************* GAMMA TESTS ********************************/ /* Gamma test images. */ -static void -make_gamma_images(png_store *ps) -{ - /* Do nothing - the standard greyscale images are used. */ -} - typedef struct gamma_modification { png_modification this; @@ -1343,6 +1359,8 @@ gamma_modification; static int gamma_modify(png_structp pp, png_modifier *pm, png_modification *me, int add) { + UNUSED(pp); + UNUSED(add); /* This simply dumps the given gamma value into the buffer. */ png_save_uint_32(pm->buffer, 4); png_save_uint_32(pm->buffer+4, CHUNK_gAMA); @@ -1357,7 +1375,7 @@ gamma_modification_init(gamma_modification *me, png_modifier *pm, double gamma) me->this.chunk = CHUNK_gAMA; me->this.modify_fn = gamma_modify; me->this.add = CHUNK_PLTE; - me->gamma = floor(gamma * 100000 + .5); + me->gamma = (png_fixed_point)floor(gamma * 100000 + .5); me->this.next = pm->modifications; pm->modifications = &me->this; } @@ -1372,6 +1390,8 @@ srgb_modification; static int srgb_modify(png_structp pp, png_modifier *pm, png_modification *me, int add) { + UNUSED(pp); + UNUSED(add); /* As above, ignore add and just make a new chunk */ png_save_uint_32(pm->buffer, 1); png_save_uint_32(pm->buffer+4, CHUNK_sRGB); @@ -1459,10 +1479,11 @@ sbit_modification_init(sbit_modification *me, png_modifier *pm, png_byte sbit) * maxpc: maximum percentage error (as a percentage) */ static void -gamma_test(png_modifier *pm, const png_byte colour_type, - const png_byte bit_depth, const double file_gamma, const double screen_gamma, - const png_byte sbit, const int threshold_test, const char *name, - const int speed, const int use_input_precision, const int strip16) +gamma_test(png_modifier *pm, PNG_CONST png_byte colour_type, + PNG_CONST png_byte bit_depth, PNG_CONST double file_gamma, + PNG_CONST double screen_gamma, PNG_CONST png_byte sbit, + PNG_CONST int threshold_test, PNG_CONST char *name, PNG_CONST int speed, + PNG_CONST int use_input_precision, PNG_CONST int strip16) { png_structp pp; png_infop pi; @@ -1513,15 +1534,15 @@ gamma_test(png_modifier *pm, const png_byte colour_type, png_read_update_info(pp, pi); { - const png_byte out_ct = png_get_color_type(pp, pi); - const png_byte out_bd = png_get_bit_depth(pp, pi); - const unsigned outmax = (1U<= + PNG_CONST int processing = (fabs(screen_gamma*file_gamma-1) >= PNG_GAMMA_THRESHOLD && !threshold_test && !speed && colour_type != 3) || bit_depth != out_bd; - const int samples_per_pixel = (out_ct & 2) ? 3 : 1; - const double gamma = 1/(file_gamma*screen_gamma); /* Overall correction */ + PNG_CONST unsigned samples_per_pixel = (out_ct & 2U) ? 3U : 1U; + PNG_CONST double gamma = 1/(file_gamma*screen_gamma); /* Overall */ for (y=0; y> (bit_depth-sbit); + PNG_CONST unsigned id = sample(std, colour_type, bit_depth, x, s); + PNG_CONST unsigned od = sample(display, out_ct, out_bd, x, s); + PNG_CONST unsigned isbit = id >> (bit_depth-sbit); double i, sample, encoded_sample, output, encoded_error, error; double es_lo, es_hi; @@ -1788,10 +1809,11 @@ perform_gamma_threshold_tests(png_modifier *pm) } } -static void gamma_transform_test(png_modifier *pm, const png_byte colour_type, - const png_byte bit_depth, const double file_gamma, const double screen_gamma, - const png_byte sbit, const int speed, const int use_input_precision, - const int strip16) +static void gamma_transform_test(png_modifier *pm, + PNG_CONST png_byte colour_type, PNG_CONST png_byte bit_depth, + PNG_CONST double file_gamma, PNG_CONST double screen_gamma, + PNG_CONST png_byte sbit, PNG_CONST int speed, + PNG_CONST int use_input_precision, PNG_CONST int strip16) { size_t pos = 0; char name[64]; @@ -1823,7 +1845,7 @@ static void perform_gamma_transform_tests(png_modifier *pm, int speed) */ while (next_format(&colour_type, &bit_depth)) if (colour_type != 3) { - int i, j; + unsigned i, j; for (i=0; ingammas; ++i) for (j=0; jngammas; ++j) if (i != j) { @@ -1844,7 +1866,7 @@ static void perform_gamma_sbit_tests(png_modifier *pm, int speed) */ for (sbit=pm->sbitlow; sbit<16; ++sbit) { - int i, j; + unsigned i, j; for (i=0; ingammas; ++i) for (j=0; jngammas; ++j) if (i != j) { @@ -1880,7 +1902,7 @@ static void perform_gamma_strip16_tests(png_modifier *pm, int speed) * proceed *without* gamma correction, and the tests above will fail (but not * by much) - this could be fixed, it only appears with the -g option. */ - int i, j; + unsigned i, j; for (i=0; ingammas; ++i) for (j=0; jngammas; ++j) if (i != j && fabs(pm->gammas[j]/pm->gammas[i]-1) >= PNG_GAMMA_THRESHOLD) { @@ -1929,14 +1951,14 @@ perform_gamma_test(png_modifier *pm, int speed, int summary) if (summary) { printf("Gamma correction with sBIT:\n"); - if (pm->sbitlow < 8) + if (pm->sbitlow < 8U) { printf(" 2 bit gray: %.5f\n", pm->error_gray_2); printf(" 4 bit gray: %.5f\n", pm->error_gray_4); printf(" 8 bit gray: %.5f\n", pm->error_gray_8); } printf(" 16 bit gray: %.5f\n", pm->error_gray_16); - if (pm->sbitlow < 8) + if (pm->sbitlow < 8U) printf(" 8 bit color: %.5f\n", pm->error_color_8); printf(" 16 bit color: %.5f\n", pm->error_color_16); } @@ -1954,10 +1976,11 @@ perform_gamma_test(png_modifier *pm, int speed, int summary) } /* main program */ -int main(int argc, const char **argv) +int main(int argc, PNG_CONST char **argv) { - int summary = 1; /* Print the error sumamry at the end */ - int speed = 0; /* Speed test only (for gamma stuff) */ + int summary = 1; /* Print the error sumamry at the end */ + int speed = 0; /* Speed test only (for gamma stuff) */ + PNG_CONST char *touch = NULL; /* Create the given output file on success. */ /* This is an array of standard gamma values (believe it or not I've seen * every one of these mentioned somewhere.) @@ -1974,9 +1997,9 @@ int main(int argc, const char **argv) /* Store the test gammas */ pm.gammas = gammas; - pm.ngammas = 3; /* for speed */ - pm.sbitlow = 8; /* because libpng doesn't do sbit below 8! */ - pm.use_input_precision_16to8 = 1; /* Because of the way libpng does it */ + pm.ngammas = 3U; /* for speed */ + pm.sbitlow = 8U; /* because libpng doesn't do sbit below 8! */ + pm.use_input_precision_16to8 = 1U; /* Because of the way libpng does it */ /* Some default values (set the behavior for 'make check' here) */ pm.maxout8 = .1; /* Arithmetic error in *encoded* value */ @@ -2006,11 +2029,13 @@ int main(int argc, const char **argv) pm.ngammas = (sizeof gammas)/(sizeof gammas[0]); else if (strcmp(*argv, "-w") == 0) pm.this.treat_warnings_as_errors = 0; - else if (strcmp(*argv, "-speed") == 0) + else if (strcmp(*argv, "--speed") == 0) speed = 1, pm.ngammas = (sizeof gammas)/(sizeof gammas[0]); - else if (argc >= 1 && strcmp(*argv, "-sbitlow") == 0) - --argc, pm.sbitlow = atol(*++argv); - else if (argc >= 1 && strncmp(*argv, "-max", 4) == 0) + else if (argc >= 1 && strcmp(*argv, "--sbitlow") == 0) + --argc, pm.sbitlow = (png_byte)atoi(*++argv); + else if (argc >= 1 && strcmp(*argv, "--touch") == 0) + --argc, touch = *++argv; + else if (argc >= 1 && strncmp(*argv, "--max", 4) == 0) { --argc; if (strcmp(4+*argv, "abs8") == 0) @@ -2039,7 +2064,6 @@ int main(int argc, const char **argv) /* Make useful base images */ make_standard_images(&pm.this); - make_gamma_images(&pm.this); /* Perform the standard and gamma tests. */ if (!speed) @@ -2052,15 +2076,16 @@ int main(int argc, const char **argv) #else "fixed", #endif - (pm.this.nerrors || pm.this.treat_warnings_as_errors && - pm.this.nwarnings) ? "(errors)" : (pm.this.nwarnings ? + (pm.this.nerrors || (pm.this.treat_warnings_as_errors && + pm.this.nwarnings)) ? "(errors)" : (pm.this.nwarnings ? "(warnings)" : "(no errors or warnings)") ); /* Error exit if there are any errors, and maybe if there are any * warnings. */ - if (pm.this.nerrors || pm.this.treat_warnings_as_errors && pm.this.nwarnings) + if (pm.this.nerrors || (pm.this.treat_warnings_as_errors && + pm.this.nwarnings)) { if (!pm.this.verbose) fprintf(stderr, "pngvalid: %s\n", pm.this.error); @@ -2069,6 +2094,24 @@ int main(int argc, const char **argv) exit(1); } + /* Success case. */ + if (touch != NULL) + { + FILE *fsuccess = fopen(touch, "wt"); + if (fsuccess != NULL) + { + int error = 0; + fprintf(fsuccess, "PNG validation succeeded\n"); + fflush(fsuccess); + error = ferror(fsuccess); + if (fclose(fsuccess) || error) + { + fprintf(stderr, "%s: write failed\n", touch); + exit(1); + } + } + } + return 0; } diff --git a/pngwrite.c b/pngwrite.c index 0f1cd4677..87f39c17c 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,7 +1,7 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.5.0 [July 31, 2010] + * Last changed in libpng 1.5.0 [August 2, 2010] * Copyright (c) 1998-2010 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.) @@ -437,9 +437,9 @@ png_convert_from_time_t(png_timep ptime, time_t ttime) #endif /* Initialize png_ptr structure, and allocate any memory needed */ -png_structp PNGAPI -png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn) +PNG_FUNCTION(png_structp,PNGAPI +png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) { #ifdef PNG_USER_MEM_SUPPORTED return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, @@ -449,10 +449,10 @@ png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, /* Alternate initialize png_ptr structure, and allocate any memory needed */ static void png_reset_filter_heuristics(png_structp png_ptr); /* forward decl */ -png_structp PNGAPI -png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, +PNG_FUNCTION(png_structp,PNGAPI +png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, - png_malloc_ptr malloc_fn, png_free_ptr free_fn) + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) { #endif /* PNG_USER_MEM_SUPPORTED */ volatile int png_cleanup_needed = 0; diff --git a/projects/vstudio/libpng/libpng.vcxproj b/projects/vstudio/libpng/libpng.vcxproj index 619fd882a..a25bad09f 100644 --- a/projects/vstudio/libpng/libpng.vcxproj +++ b/projects/vstudio/libpng/libpng.vcxproj @@ -88,7 +88,6 @@ false ProgramDatabase EnableFastChecks - MultiThreadedDebugDLL WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true true @@ -106,8 +105,7 @@ Windows true - zlib.lib;msvcrtd.lib;kernel32.lib - true + zlib.lib 15 $(OutDir) @@ -120,7 +118,6 @@ ProgramDatabase Disabled EnableFastChecks - MultiThreadedDebug WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true true @@ -133,6 +130,7 @@ 4996;4127 $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) true + MultiThreadedDebug Windows @@ -144,7 +142,6 @@ Level4 Use ProgramDatabase - MultiThreadedDLL true true WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) @@ -156,7 +153,7 @@ true false 4996;4127 - $(ZLib1Dir);..\..\..\scripts;%(AdditionalIncludeDirectories) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) true Full @@ -165,10 +162,9 @@ true true true - zdll.lib;msvcrt.lib;kernel32.lib - true + zlib.lib 15 - $(ZLib1Dir) + $(OutDir) @@ -188,9 +184,10 @@ true false 4996;4127 - $(ZLib1Dir);..\..\..\scripts;%(AdditionalIncludeDirectories) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) true Full + true Windows @@ -198,6 +195,9 @@ true true + + true + diff --git a/projects/vstudio/pngtest/pngtest.vcxproj b/projects/vstudio/pngtest/pngtest.vcxproj index d73d51484..a03dca565 100644 --- a/projects/vstudio/pngtest/pngtest.vcxproj +++ b/projects/vstudio/pngtest/pngtest.vcxproj @@ -81,7 +81,6 @@ ProgramDatabase Disabled EnableFastChecks - MultiThreadedDebugDLL WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) 4996 @@ -91,12 +90,12 @@ true false true + false Console true - libpng15.lib;zlib.lib;msvcrtd.lib;kernel32.lib - true + libpng15.lib $(OutDir) @@ -124,12 +123,12 @@ true false true + false Console true - libpng15.lib;zlib.lib;msvcrtd.lib;kernel32.lib - true + libpng15.lib;zlib.lib $(OutDir) @@ -145,25 +144,26 @@ NotUsing ProgramDatabase Full - MultiThreadedDLL false true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ZLib1Dir);..\..\..\scripts;%(AdditionalIncludeDirectories) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) 4996 false true true false true + true + false Console true true true - libpng15.lib;msvcrt.lib;kernel32.lib - true + UseLinkTimeCodeGeneration + libpng15.lib $(OutDir) @@ -183,22 +183,24 @@ false true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ZLib1Dir);..\..\..\scripts;%(AdditionalIncludeDirectories) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) 4996 false true true false true + true + false Console true true true - libpng15.lib;zlib.lib;msvcrt.lib;kernel32.lib - true - $(OutDir);$(ZLib1Dir) + libpng15.lib;zlib.lib + UseLinkTimeCodeGeneration + $(OutDir) Executing PNG test program diff --git a/projects/vstudio/pngvalid/pngvalid.vcxproj b/projects/vstudio/pngvalid/pngvalid.vcxproj new file mode 100644 index 000000000..f6478578f --- /dev/null +++ b/projects/vstudio/pngvalid/pngvalid.vcxproj @@ -0,0 +1,219 @@ + + + + + Debug Library + Win32 + + + Debug + Win32 + + + Release Library + Win32 + + + Release + Win32 + + + + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8} + Win32Proj + pngvalid + + + + + Application + Unicode + + + Application + Unicode + + + Application + Unicode + + + Application + Unicode + + + + + + + + + + + + + + + + + + + false + + + + false + + + + false + + + + false + + + + + NotUsing + Level4 + false + ProgramDatabase + Disabled + EnableFastChecks + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) + 4996 + false + true + true + true + false + true + false + + + Console + true + libpng15.lib;zlib.lib + $(OutDir) + + + Executing PNG validation program + "$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out" + $(IntDir)pngvalid.out + $(OutDir)pngvalid.exe + + + + + NotUsing + Level4 + false + ProgramDatabase + Disabled + EnableFastChecks + MultiThreadedDebug + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) + 4996 + false + true + true + true + false + true + false + + + Console + true + libpng15.lib;zlib.lib + $(OutDir) + + + Executing PNG validation program + "$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out" + $(IntDir)pngvalid.out + $(OutDir)pngvalid.exe + + + + + Level4 + NotUsing + ProgramDatabase + Full + false + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) + 4996 + false + true + true + false + true + true + false + + + Console + true + true + true + libpng15.lib;zlib.lib + $(OutDir) + UseLinkTimeCodeGeneration + + + Executing PNG validation program + "$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out" + $(IntDir)pngvalid.out + $(OutDir)pngvalid.exe + + + + + Level4 + NotUsing + ProgramDatabase + Full + MultiThreaded + false + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories) + 4996 + false + true + true + false + true + true + false + + + Console + true + true + true + libpng15.lib;zlib.lib + $(OutDir) + UseLinkTimeCodeGeneration + + + Executing PNG validation program + $(OutDir)pngvalid.exe ..\..\..\pngvalid.png $(IntDir)pngout.png + "$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out" + $(IntDir)pngvalid.out + $(OutDir)pngvalid.exe + + + + + + + + + diff --git a/projects/vstudio/readme.txt b/projects/vstudio/readme.txt index da0606bcb..d97ae2677 100644 --- a/projects/vstudio/readme.txt +++ b/projects/vstudio/readme.txt @@ -1,7 +1,7 @@ VisualStudio instructions -libpng version 1.5.0beta39 - July 31, 2010 +libpng version 1.5.0beta39 - August 2, 2010 Copyright (c) 1998-2010 Glenn Randers-Pehrson @@ -15,21 +15,11 @@ You should be familiar with VisualStudio before using this directory. Initial preparations ==================== -You should install the 'official' build of zlib on your system - follow the -instructions provided on http://www.zlib.net. When a new release is being -made of zlib the instructions disappear for a while until the new official -build is available. You will have to wait. - You must enter some information in zlib.props before attempting to build with this 'solution'. Please read and edit zlib.props first. You will probably not be familiar with the contents of zlib.props - do not worry, it is mostly harmless. -Make sure that your official build layout matches the requirements listed -in zlib.props. Prior to zlib-1.2.4 the official build (1.2.3) placed -include and library files in different directories - if you find this -has happened just put them all in the same directory. - This is all you need to do to build the 'release' and 'release library' configurations. @@ -40,6 +30,25 @@ information is produced (in the .pdb), but if you encounter a problem the optimization may make it difficult to debug. Simply rebuild with a lower optimization level (e.g. /Od.) +Linking your application +======================== +Normally you should link against the 'release' configuration. This builds a +DLL for libpng 1.5 with the default runtime options used by Visual Studio +2010. In particular the runtime library is the "MultiThreaded DLL" version. +If you use Visual Studio defaults to build your application you will have no +problems. + +If you don't use the Visual Studio defaults your application must still be built +with the default runtime option (/MD). If, for some reason, it is not then your +application will crash inside libpng15.dll as soon as libpng tries to read +from a file handle you pass in. + +If you do not want to use the DLL, for example for a very small application, +the 'release library' configuration may be more appropriate. This is built +with a non-standard runtime library - the "MultiThreaded" version. When you +build your application it must be compiled with this option (/MT), otherwise +it will not build (if you are lucky) or crash (if you are not.) + Stop reading here ================= You have enough information to build a working application. @@ -51,37 +60,5 @@ do not need these unless your own solution itself uses debug builds (it is far more effective to debug on the release builds, there is no point building a special debug build.) -If, despite the previous paragraph, you still feel you need a debug build you -will have to download the zlib source as well (http://www.zlib.net) and include -the directory where you unpack it in zlib.props. This solution will then be -able to build a minimal zlib sufficient for libpng. This build is only -suitable for making a debug libpng. - The debug build of libpng is minimally supported. Support for debug builds of zlib is also minimal. You really don't want to do this. - -This solution only supports the Multi-Threaded DLL C Runtime -============================================================ -If you examine the solution you will find that it very deliberately lists -exactly which MicroSoft DLLs it is linking against. It explicitly links -against msvcrt.lib. The debug version links against msvcrtd.lib (this is -why it is a debug version - it's nothing to do with having any special -debug support, it doesn't). - -These versions of the MicroSoft C runtime correspond to the compiler flags -/MD (release) and /MDd (debug) - the "Multi-Threaded DLL" implementation of the -C runtime library. - -If you need to change this then you will have to make sure that both the -compiler flags and the ".lib" in the linker dependences match up. Fortunately -neither zlib nor libpng require libraries other than a C runtime and -kernel32. - -You cannot pass (FILE*) objects from a different runtime (including msvcrtd -to msvcrt) to libpng. If you do then your program will crash within libpng -when it first makes a file read or write call. - -It is likely if you have read this far that you have found you can't avoid -having multiple C runtimes in your program. This is OK, it does work, but -you will have to implement the libpng file read/write callbacks rather than -using the internal libpng default. This is easy. diff --git a/projects/vstudio/vstudio.sln b/projects/vstudio/vstudio.sln index b288ab6bb..abf59de31 100644 --- a/projects/vstudio/vstudio.sln +++ b/projects/vstudio/vstudio.sln @@ -1,17 +1,23 @@ - Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual C++ Express 2010 +# Visual Studio 2010 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libpng\libpng.vcxproj", "{D6973076-9317-4EF2-A0B8-B7A18AC0713E}" ProjectSection(ProjectDependencies) = postProject - {E5A897B8-320E-6490-784B-11B374DD242A} = {E5A897B8-320E-6490-784B-11B374DD242A} + {64CE4900-97EA-2DD5-4226-F2E36FFF2867} = {64CE4900-97EA-2DD5-4226-F2E36FFF2867} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngtest", "pngtest\pngtest.vcxproj", "{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}" ProjectSection(ProjectDependencies) = postProject + {64CE4900-97EA-2DD5-4226-F2E36FFF2867} = {64CE4900-97EA-2DD5-4226-F2E36FFF2867} {D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib.vcxproj", "{E5A897B8-320E-6490-784B-11B374DD242A}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib.vcxproj", "{64CE4900-97EA-2DD5-4226-F2E36FFF2867}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngvalid", "pngvalid\pngvalid.vcxproj", "{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}" + ProjectSection(ProjectDependencies) = postProject + {64CE4900-97EA-2DD5-4226-F2E36FFF2867} = {64CE4900-97EA-2DD5-4226-F2E36FFF2867} + {D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,12 +43,22 @@ Global {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release Library|Win32.Build.0 = Release Library|Win32 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release|Win32.ActiveCfg = Release|Win32 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release|Win32.Build.0 = Release|Win32 - {E5A897B8-320E-6490-784B-11B374DD242A}.Debug Library|Win32.ActiveCfg = Debug Library|Win32 - {E5A897B8-320E-6490-784B-11B374DD242A}.Debug Library|Win32.Build.0 = Debug Library|Win32 - {E5A897B8-320E-6490-784B-11B374DD242A}.Debug|Win32.ActiveCfg = Debug|Win32 - {E5A897B8-320E-6490-784B-11B374DD242A}.Debug|Win32.Build.0 = Debug|Win32 - {E5A897B8-320E-6490-784B-11B374DD242A}.Release Library|Win32.ActiveCfg = Debug|Win32 - {E5A897B8-320E-6490-784B-11B374DD242A}.Release|Win32.ActiveCfg = Debug|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Debug Library|Win32.ActiveCfg = Debug Library|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Debug Library|Win32.Build.0 = Debug Library|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Debug|Win32.ActiveCfg = Debug|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Debug|Win32.Build.0 = Debug|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Release Library|Win32.ActiveCfg = Release Library|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Release Library|Win32.Build.0 = Release Library|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Release|Win32.ActiveCfg = Release|Win32 + {64CE4900-97EA-2DD5-4226-F2E36FFF2867}.Release|Win32.Build.0 = Release|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug Library|Win32.ActiveCfg = Debug Library|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug Library|Win32.Build.0 = Debug Library|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug|Win32.ActiveCfg = Debug|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug|Win32.Build.0 = Debug|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release Library|Win32.ActiveCfg = Release Library|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release Library|Win32.Build.0 = Release Library|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release|Win32.ActiveCfg = Release|Win32 + {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props index e36f2fca3..0df5ddcc9 100644 --- a/projects/vstudio/zlib.props +++ b/projects/vstudio/zlib.props @@ -1,8 +1,8 @@ - + - - ..\..\..\..\zlib124-dll\zlib-1.2.4 - - ..\..\..\..\zlib-1.2.4 diff --git a/projects/vstudio/zlib/zlib.vcxproj b/projects/vstudio/zlib/zlib.vcxproj index 76b744787..c16fd8223 100644 --- a/projects/vstudio/zlib/zlib.vcxproj +++ b/projects/vstudio/zlib/zlib.vcxproj @@ -13,6 +13,10 @@ Release Library Win32 + + Release + Win32 + @@ -32,65 +36,55 @@ - - DynamicLibrary - true - StaticLibrary + + StaticLibrary + StaticLibrary - DynamicLibrary + StaticLibrary + + + StaticLibrary - - - + + + + + + - - false - true + + true + true true - - - WIN32;ZLIB_DLL;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - TurnOffAllWarnings - ProgramDatabase - Disabled - true - true - - - true - Windows - 1 - msvcrtd.lib;kernel32.lib - true - - + + true + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) @@ -106,15 +100,12 @@ Windows - + - MultiThreaded + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) TurnOffAllWarnings ProgramDatabase - Full - true - true - false + Disabled true @@ -123,10 +114,52 @@ Windows + + + Level3 + ProgramDatabase + Full + true + true + false + true + true + true + MultiThreaded + + + MachineX86 + true + Windows + + + true + + + + + Level3 + ProgramDatabase + Full + true + true + false + true + true + true + + + MachineX86 + true + Windows + + + true + + WIN32;NDEBUG;_WINDOWS;_USRDLL;DEBUGZLIB_EXPORTS;%(PreprocessorDefinitions) - MultiThreadedDLL Level3 ProgramDatabase