From 0cf9c7d63dbdc1c014366b6df96683792243a085 Mon Sep 17 00:00:00 2001 From: John Bowler Date: Sat, 15 Dec 2012 16:04:28 -0600 Subject: [PATCH] [libpng17] Removed some duplicated code from png.c and contrib/tools/scale.c and changed some png_warning() calls to png_app_error() calls in pngwutil.c --- contrib/tools/scale.c | 238 ------------------------------------------ png.c | 16 --- pngwutil.c | 13 +-- 3 files changed, 5 insertions(+), 262 deletions(-) diff --git a/contrib/tools/scale.c b/contrib/tools/scale.c index 6fe08675e..3b14c3114 100644 --- a/contrib/tools/scale.c +++ b/contrib/tools/scale.c @@ -205,244 +205,6 @@ main(int argc, const char **argv) } - if (argc < 2+firstsrc) - usage(argv[0]); - - target = strtoul(argv[firstsrc++], 0, 0); - if (target == 0) usage(argv[0]); - - for (i=firstsrc; i shift) shift = minshift; - } - - if (maxshift) for (i=firstsrc; i>16 - * - * The command arguments are: - * - * scale target source - * - * and the program works out a pair of numbers, mult and add, that evaluate: - * - * number * target - * round( --------------- ) - * source - * - * exactly for number in the range 0..source - */ -#define _ISOC99_SOURCE 1 - -#include -#include -#include -#include - -static double minerr; -static unsigned long minmult, minadd, minshift; -static long mindelta; - -static int -test(unsigned long target, unsigned long source, unsigned long mult, - long add, unsigned long shift, long delta) -{ - unsigned long i; - double maxerr = 0; - double rs = (double)target/source; - - for (i=0; i<=source; ++i) - { - unsigned long t = i*mult+add; - double err = fabs((t >> shift) - i*rs); - - if (err > minerr) - return 0; - - if (err > maxerr) - maxerr = err; - } - - if (maxerr < minerr) - { - minerr = maxerr; - minmult = mult; - minadd = add; - minshift = shift; - mindelta = delta; - } - - return maxerr < .5; -} - -static int -dotest(unsigned long target, unsigned long source, unsigned long mult, - long add, unsigned long shift, long delta, int print) -{ - if (test(target, source, mult, add, shift, delta)) - { - if (print & 4) - printf(" {%11lu,%6ld /* >>%lu */ }, /* %lu/%lu */\n", - mult, add, shift, target, source); - - else if (print & 2) - printf(" {%11lu,%6ld,%3lu }, /* %lu/%lu */\n", - mult, add, shift, target, source); - - else if (print) - printf("number * %lu/%lu = (number * %lu + %ld) >> %lu [delta %ld]\n", - target, source, mult, add, shift, delta); - - return 1; - } - - return 0; -} - -static int -find(unsigned long target, unsigned long source, int print, int fixshift) -{ - unsigned long shift = 0; - unsigned long shiftlim = 0; - - /* In the final math the sum is at most (source*mult+add) >> shift, so: - * - * source*mult+add < 1<<32 - * mult < (1<<32)/source - * - * but: - * - * mult = (target<>1)) / source; - long delta; - long limit = 1; /* seems to be sufficient */ - long add, start, end; - - end = 1<>%lu */ }, /* %lu/%lu ERROR: .5+%g*/\n", - minmult, minadd, minshift, target, source, minerr-.5); - - else if (print & 2) - printf(" {%11lu,%6ld,%3lu }, /* %lu/%lu ERROR: .5+%g*/\n", - minmult, minadd, minshift, target, source, minerr-.5); - - else if (print) - printf( - "number * %lu/%lu ~= (number * %lu + %ld) >> %lu +/-.5+%g [delta %ld]\n", - target, source, minmult, minadd, minshift, minerr-.5, mindelta); - - return 0; -} - -static void -usage(const char *prog) -{ - fprintf(stderr, - "usage: %s {--denominator|--maxshift|--code} target {source}\n" - " For each 'source' prints 'mult' and 'add' such that:\n\n" - " (number * mult + add) >> 16 = round(number*target/source)\n\n" - " for all integer values of number in the range 0..source.\n\n" - " --denominator: swap target and source (specify a single source first\n" - " and follow with multiple targets.)\n" - " --maxshift: find the lowest shift value that works for all the\n" - " repeated 'source' values\n" - " --code: output C code for array/structure initialization\n", - prog); - exit(1); -} - -int -main(int argc, const char **argv) -{ - int i, err = 0, maxshift = 0, firstsrc = 1, code = 0, denominator = 0; - unsigned long target, shift = 0; - - while (argc > 1) - { - if (strcmp(argv[firstsrc], "--maxshift") == 0) - { - maxshift = 1; - ++firstsrc; - } - - else if (strcmp(argv[firstsrc], "--code") == 0) - { - code = 1; - ++firstsrc; - } - - else if (strcmp(argv[firstsrc], "--denominator") == 0) - { - denominator = 1; - ++firstsrc; - } - - else - break; - } - - if (argc < 2+firstsrc) usage(argv[0]); diff --git a/png.c b/png.c index ef2ad418c..8a3cde597 100644 --- a/png.c +++ b/png.c @@ -253,22 +253,6 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; # endif - /* Added at libpng-1.2.6 */ -# ifdef PNG_USER_LIMITS_SUPPORTED - create_struct.user_width_max = PNG_USER_WIDTH_MAX; - create_struct.user_height_max = PNG_USER_HEIGHT_MAX; - -# ifdef PNG_USER_CHUNK_CACHE_MAX - /* Added at libpng-1.2.43 and 1.4.0 */ - create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; -# endif - -# ifdef PNG_USER_CHUNK_MALLOC_MAX - /* Added at libpng-1.2.43 and 1.4.1 */ - create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; -# endif -# endif - /* The following two API calls simply set fields in png_struct, so it is safe * to do them now even though error handling is not yet set up. */ diff --git a/pngwutil.c b/pngwutil.c index 68d572962..378ad6199 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1427,11 +1427,8 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, { if (num_trans <= 0 || num_trans > png_ptr->num_palette) { - /* This is an error which can only be reliably detected late, change to - * a png_app_warning here so that it will fail in debug. It should be - * a png_app_error. - */ - png_app_warning(png_ptr, + /* This is an error which can only be reliably detected late. */ + png_app_error(png_ptr, "Invalid number of transparent colors specified"); return; } @@ -1447,7 +1444,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, if (tran->gray >= (1 << png_ptr->bit_depth)) { /* This can no longer happen because it is checked in png_set_tRNS */ - png_warning(png_ptr, + png_app_error(png_ptr, "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); return; @@ -1470,7 +1467,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, #endif { /* Also checked in png_set_tRNS */ - png_warning(png_ptr, + png_app_error(png_ptr, "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); return; } @@ -1481,7 +1478,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, else { /* Checked in png_set_tRNS */ - png_warning(png_ptr, "Can't write tRNS with an alpha channel"); + png_app_error(png_ptr, "Can't write tRNS with an alpha channel"); } } #endif