X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..000eea7a2ef45e4053b66bdcc8fd57bfb2e907de:/src/png/pngtest.c?ds=inline diff --git a/src/png/pngtest.c b/src/png/pngtest.c index 1430f0f395..3981a4902d 100644 --- a/src/png/pngtest.c +++ b/src/png/pngtest.c @@ -1,9 +1,9 @@ /* pngtest.c - a simple test program to test libpng * - * libpng 1.2.5rc3 - September 18, 2002 + * Last changed in libpng 1.2.6 - August 15, 2004 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2002 Glenn Randers-Pehrson + * Copyright (c) 1998-2004 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.) * @@ -28,6 +28,8 @@ * of files at once by typing "pngtest -m file1.png file2.png ..." */ +#include "png.h" + #if defined(_WIN32_WCE) # if _WIN32_WCE < 211 __error__ (f|w)printf functions are not supported on old WindowsCE.; @@ -42,7 +44,6 @@ #else # include # include -# include # define READFILE(file, data, length, check) \ check=(png_size_t)fread(data,(png_size_t)1,length,file) # define WRITEFILE(file, data, length, check) \ @@ -80,20 +81,6 @@ static float t_start, t_stop, t_decode, t_encode, t_misc; #include #endif -#include "png.h" - -/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ -#ifndef png_jmpbuf -# define png_jmpbuf(png_ptr) png_ptr->jmpbuf -#endif - -#ifdef PNGTEST_TIMING -static float t_start, t_stop, t_decode, t_encode, t_misc; -#if !defined(PNG_tIME_SUPPORTED) -#include -#endif -#endif - #if defined(PNG_TIME_RFC1123_SUPPORTED) static int tIME_chunk_present=0; static char tIME_string[30] = "no tIME chunk present in file"; @@ -116,18 +103,28 @@ static int status_pass=1; static int status_dots_requested=0; static int status_dots=1; +/* In case a system header (e.g., on AIX) defined jmpbuf */ +#ifdef jmpbuf +# undef jmpbuf +#endif + +/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) png_ptr->jmpbuf +#endif + void #ifdef PNG_1_0_X PNGAPI #endif read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); +void #ifdef PNG_1_0_X PNGAPI #endif -void read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) { - if(png_ptr == NULL || row_number > PNG_MAX_UINT) return; + if(png_ptr == NULL || row_number > PNG_UINT_31_MAX) return; if(status_pass != pass) { fprintf(stdout,"\n Pass %d: ",pass); @@ -143,18 +140,18 @@ read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) fprintf(stdout, "r"); } +void #ifdef PNG_1_0_X PNGAPI #endif -void write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); +void #ifdef PNG_1_0_X PNGAPI #endif -void write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) { - if(png_ptr == NULL || row_number > PNG_MAX_UINT || pass > 7) return; + if(png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return; fprintf(stdout, "w"); } @@ -437,8 +434,9 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_error(png_ptr, "Write Error"); } } - #endif /* USE_FAR_KEYWORD */ +#endif /* PNG_NO_STDIO */ +/* END of code to validate stdio-free compilation */ /* This function is called when there is a warning, but the library thinks * it can continue anyway. Replacement functions don't have to do anything @@ -466,11 +464,9 @@ pngtest_error(png_structp png_ptr, png_const_charp message) /* We can return because png_error calls the default handler, which is * actually OK in this case. */ } -#endif /* PNG_NO_STDIO */ -/* END of code to validate stdio-free compilation */ /* START of code to validate memory allocation and deallocation */ -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG /* Allocate memory. For reasonable files, size should never exceed 64K. However, zlib may allocate more then 64K if you don't tell @@ -510,24 +506,35 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size) /* This calls the library allocator twice, once to get the requested buffer and once to get a new free list entry. */ { - memory_infop pinfo = (memory_infop)png_malloc_default(png_ptr, - (png_uint_32)sizeof *pinfo); + /* Disable malloc_fn and free_fn */ + memory_infop pinfo; + png_set_mem_fn(png_ptr, NULL, NULL, NULL); + pinfo = (memory_infop)png_malloc(png_ptr, + (png_uint_32)png_sizeof (*pinfo)); pinfo->size = size; current_allocation += size; total_allocation += size; num_allocations ++; if (current_allocation > maximum_allocation) maximum_allocation = current_allocation; - pinfo->pointer = (png_voidp)png_malloc_default(png_ptr, size); + pinfo->pointer = (png_voidp)png_malloc(png_ptr, size); + /* Restore malloc_fn and free_fn */ + png_set_mem_fn(png_ptr, png_voidp_NULL, (png_malloc_ptr)png_debug_malloc, + (png_free_ptr)png_debug_free); + if (size != 0 && pinfo->pointer == NULL) + { + current_allocation -= size; + total_allocation -= size; + png_error(png_ptr, + "out of memory in pngtest->png_debug_malloc."); + } pinfo->next = pinformation; pinformation = pinfo; /* Make sure the caller isn't assuming zeroed memory. */ png_memset(pinfo->pointer, 0xdd, pinfo->size); -#if PNG_DEBUG if(verbose) - printf("png_malloc %lu bytes at %x\n",size,pinfo->pointer); -#endif - assert(pinfo->size != 12345678); + printf("png_malloc %lu bytes at %x\n",(unsigned long)size, + pinfo->pointer); return (png_voidp)(pinfo->pointer); } } @@ -575,14 +582,12 @@ png_debug_free(png_structp png_ptr, png_voidp ptr) } /* Finally free the data. */ -#if PNG_DEBUG if(verbose) printf("Freeing %x\n",ptr); -#endif png_free_default(png_ptr, ptr); ptr=NULL; } -#endif /* PNG_USER_MEM_SUPPORTED */ +#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */ /* END of code to test memory allocation/deallocation */ /* Test one file */ @@ -644,7 +649,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) } png_debug(0, "Allocating read and write structures\n"); -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); @@ -652,12 +657,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, png_error_ptr_NULL, png_error_ptr_NULL); #endif -#if defined(PNG_NO_STDIO) png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, pngtest_warning); -#endif #ifdef PNG_WRITE_SUPPORTED -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); @@ -665,10 +668,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, png_error_ptr_NULL, png_error_ptr_NULL); #endif -#if defined(PNG_NO_STDIO) png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, pngtest_warning); -#endif #endif png_debug(0, "Allocating read_info, write_info and end_info structures\n"); read_info_ptr = png_create_info_struct(read_ptr); @@ -699,7 +700,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) return (1); } #ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(read_ptr),jmpbuf,sizeof(jmp_buf)); + png_memcpy(png_jmpbuf(read_ptr),jmpbuf,png_sizeof(jmp_buf)); #endif #ifdef PNG_WRITE_SUPPORTED @@ -721,7 +722,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) return (1); } #ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(write_ptr),jmpbuf,sizeof(jmp_buf)); + png_memcpy(png_jmpbuf(write_ptr),jmpbuf,png_sizeof(jmp_buf)); #endif #endif #endif @@ -771,14 +772,18 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) png_set_write_user_transform_fn(write_ptr, count_zero_samples); #endif -#define HANDLE_CHUNK_IF_SAFE 2 -#define HANDLE_CHUNK_ALWAYS 3 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) - png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS, +# ifndef PNG_HANDLE_CHUNK_ALWAYS +# define PNG_HANDLE_CHUNK_ALWAYS 3 +# endif + png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, png_bytep_NULL, 0); #endif #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) - png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, +# ifndef PNG_HANDLE_CHUNK_IF_SAFE +# define PNG_HANDLE_CHUNK_IF_SAFE 2 +# endif + png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, png_bytep_NULL, 0); #endif @@ -997,10 +1002,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { png_set_tIME(write_ptr, write_info_ptr, mod_time); #if defined(PNG_TIME_RFC1123_SUPPORTED) - /* we have to use png_strcpy instead of "=" because the string + /* we have to use png_strncpy instead of "=" because the string pointed to by png_convert_to_rfc1123() gets free'ed before we use it */ - png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); + png_strncpy(tIME_string,png_convert_to_rfc1123(read_ptr, + mod_time),30); tIME_chunk_present++; #endif /* PNG_TIME_RFC1123_SUPPORTED */ } @@ -1137,10 +1143,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) { png_set_tIME(write_ptr, write_end_info_ptr, mod_time); #if defined(PNG_TIME_RFC1123_SUPPORTED) - /* we have to use png_strcpy instead of "=" because the string + /* we have to use png_strncpy instead of "=" because the string pointed to by png_convert_to_rfc1123() gets free'ed before we use it */ - png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); + png_strncpy(tIME_string,png_convert_to_rfc1123(read_ptr, + mod_time),30); tIME_chunk_present++; #endif /* PNG_TIME_RFC1123_SUPPORTED */ } @@ -1177,7 +1184,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) iwidth = png_get_image_width(write_ptr, write_info_ptr); iheight = png_get_image_height(write_ptr, write_info_ptr); fprintf(STDERR, "Image width = %lu, height = %lu\n", - iwidth, iheight); + (unsigned long)iwidth, (unsigned long)iheight); } #endif @@ -1301,13 +1308,14 @@ main(int argc, char *argv[]) fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); fprintf(STDERR,"%s",png_get_copyright(NULL)); /* Show the version of libpng used in building the library */ - fprintf(STDERR," library (%lu):%s", png_access_version_number(), + fprintf(STDERR," library (%lu):%s", + (unsigned long)png_access_version_number(), png_get_header_version(NULL)); /* Show the version of libpng used in building the application */ fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, PNG_HEADER_VERSION_STRING); - fprintf(STDERR," sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n", - (long)sizeof(png_struct), (long)sizeof(png_info)); + fprintf(STDERR," png_sizeof(png_struct)=%ld, png_sizeof(png_info)=%ld\n", + (long)png_sizeof(png_struct), (long)png_sizeof(png_info)); /* Do some consistency checking on the memory allocation settings, I'm not sure this matters, but it is nice to know, the first of these @@ -1375,7 +1383,7 @@ main(int argc, char *argv[]) if (multiple) { int i; -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG int allocation_now = current_allocation; #endif for (i=2; isize, + fprintf(STDERR, " %lu bytes at %x\n", (unsigned long)pinfo->size, (unsigned int) pinfo->pointer); pinfo = pinfo->next; } } #endif } -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG fprintf(STDERR, " Current memory allocation: %10d bytes\n", current_allocation); fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", @@ -1446,7 +1455,7 @@ main(int argc, char *argv[]) for (i=0; i<3; ++i) { int kerror; -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG int allocation_now = current_allocation; #endif if (i == 1) status_dots_requested = 1; @@ -1462,7 +1471,8 @@ main(int argc, char *argv[]) int k; #endif #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) - fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples); + fprintf(STDERR, "\n PASS (%lu zero samples)\n", + (unsigned long)zero_samples); #else fprintf(STDERR, " PASS\n"); #endif @@ -1470,7 +1480,7 @@ main(int argc, char *argv[]) for (k=0; k<256; k++) if(filters_used[k]) fprintf(STDERR, " Filter %d was used %lu times\n", - k,filters_used[k]); + k,(unsigned long)filters_used[k]); #endif #if defined(PNG_TIME_RFC1123_SUPPORTED) if(tIME_chunk_present != 0) @@ -1485,7 +1495,7 @@ main(int argc, char *argv[]) fprintf(STDERR, " FAIL\n"); ierror += kerror; } -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG if (allocation_now != current_allocation) fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", current_allocation-allocation_now); @@ -1498,13 +1508,13 @@ main(int argc, char *argv[]) while (pinfo != NULL) { fprintf(STDERR," %lu bytes at %x\n", - pinfo->size, (unsigned int)pinfo->pointer); + (unsigned long)pinfo->size, (unsigned int)pinfo->pointer); pinfo = pinfo->next; } } #endif } -#ifdef PNG_USER_MEM_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG fprintf(STDERR, " Current memory allocation: %10d bytes\n", current_allocation); fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", @@ -1538,4 +1548,4 @@ main(int argc, char *argv[]) } /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_2_5rc3 your_png_h_is_not_version_1_2_5rc3; +typedef version_1_2_20 your_png_h_is_not_version_1_2_20;