From fbbbc620b80eb54fe469901f92b62785358f4ce4 Mon Sep 17 00:00:00 2001 From: John Bowler Date: Mon, 17 Dec 2012 21:07:30 -0600 Subject: [PATCH] [libpng16] Fixed previous support for Z_PREFIX in configure builds, corrected sCAL APIs; some of these use floating point arithmetic so they need to be disabled if floating point arithmetic is switched off. This is a quiet API change - previously it appeared that the APIs were supported if fixed point arithmetic was used internally, however they required certain APIs (floor, modf, frexp, atof) that are part of C floating point support. Changed png_fixed and the gamma code specific version of the same to avoid floor(), which may be a library function (not an intrinsic). Removed unused #if 0 code. --- ANNOUNCE | 9 ++ CHANGES | 9 ++ configure.ac | 21 +-- png.c | 356 +++------------------------------------------------ png.h | 26 ++-- pngerror.c | 10 +- pngget.c | 14 +- pngrtran.c | 12 +- pngset.c | 3 +- pngtest.c | 3 +- 10 files changed, 81 insertions(+), 382 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 87cb8a2cf..183c8e7c5 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -78,6 +78,15 @@ Version 1.7.0alpha03 [December 18, 2012] been removed. Documented new PNG_ABORT behavior in the manual and commentary in pngerror.c Cleaned up whitespace in the synopsis portion of the manpage "libpng.3" + Fixed previous support for Z_PREFIX in configure builds, corrected sCAL APIs; + some of these use floating point arithmetic so they need to be disabled if + floating point arithmetic is switched off. This is a quiet API change - + previously it appeared that the APIs were supported if fixed point + arithmetic was used internally, however they required certain APIs (floor, + modf, frexp, atof) that are part of C floating point support. Changed + png_fixed and the gamma code specific version of the same to avoid floor(), + which may be a library function (not an intrinsic). Removed unused #if 0 + code. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index c8008cfe6..8ec03dfe3 100644 --- a/CHANGES +++ b/CHANGES @@ -4363,6 +4363,15 @@ Version 1.7.0alpha03 [December 18, 2012] been removed. Documented new PNG_ABORT behavior in the manual and commentary in pngerror.c Cleaned up whitespace in the synopsis portion of the manpage "libpng.3" + Fixed previous support for Z_PREFIX in configure builds, corrected sCAL APIs; + some of these use floating point arithmetic so they need to be disabled if + floating point arithmetic is switched off. This is a quiet API change - + previously it appeared that the APIs were supported if fixed point + arithmetic was used internally, however they required certain APIs (floor, + modf, frexp, atof) that are part of C floating point support. Changed + png_fixed and the gamma code specific version of the same to avoid floor(), + which may be a library function (not an intrinsic). Removed unused #if 0 + code. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/configure.ac b/configure.ac index 3b79e411a..e97f9735b 100644 --- a/configure.ac +++ b/configure.ac @@ -152,23 +152,24 @@ AC_ARG_ENABLE([fixed-point],[Enable fixed point APIs],, AC_ARG_ENABLE([floating-arithmetic],[Use floating point arithmetic internally],, [enable_floating_arithmetic=yes]) -# But if there is no floor/ceil turn both options off: -if test "$enable_floating_point" = yes -o "$enable_floating_arithmetic" = yes +# Check for a requirement for math library support +if test "$enable_floating_arithmetic" = yes then AC_SEARCH_LIBS([floor],[m],, [AC_MSG_WARN([not found]) - enable_floating_point=no enable_floating_arithmetic=no]) AC_SEARCH_LIBS([frexp],[m],, [AC_MSG_WARN([not found]) - enable_floating_point=no enable_floating_arithmetic=no]) -fi -if test "$enable_floating_arithmetic" = yes -then + AC_SEARCH_LIBS([modf],[m],, + [AC_MSG_WARN([not found]) + enable_floating_arithmetic=no]) + AC_SEARCH_LIBS([atof],[m],, + [AC_MSG_WARN([not found]) + enable_floating_arithmetic=no]) AC_SEARCH_LIBS([pow],[m],, [AC_MSG_WARN([not found]) - enable_floating_arithmetic="no"]) + enable_floating_arithmetic=no]) fi # Set the relevant defines if required (only if required), this will override @@ -209,6 +210,7 @@ AC_ARG_WITH([zlib], [base name of the zlib implementation (e.g. 'z')]),, [with_zlib='z']) +z_prefix= AC_ARG_WITH([zlib-prefix], AS_HELP_STRING([[[--with-zlib-prefix=]]], [prefix for zlib API functions]), @@ -223,6 +225,7 @@ AC_ARG_WITH([zlib-prefix], fi if test "$with_zlib_prefix" != ""; then AC_DEFINE([Z_PREFIX],[1],[Tell zlib.h to prefix function names]) + z_prefix="#define Z_PREFIX 1" fi]) AC_ARG_WITH([zlib-header], @@ -240,7 +243,7 @@ AC_MSG_CHECKING( AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[ -#define Z_PREFIX 1 +${z_prefix} #include ${with_zlib_header} ]], [[(void)${with_zlib_prefix}zlibVersion();]])], diff --git a/png.c b/png.c index 6f7b84ed0..a0d63f0e6 100644 --- a/png.c +++ b/png.c @@ -691,13 +691,13 @@ png_get_copyright(png_const_structrp png_ptr) #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ - "libpng version 1.7.0alpha03 - December 17, 2012" PNG_STRING_NEWLINE \ + "libpng version 1.7.0alpha03 - December 18, 2012" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2012 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 "libpng version 1.7.0alpha03 - December 17, 2012\ + return "libpng version 1.7.0alpha03 - December 18, 2012\ Copyright (c) 1998-2012 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; @@ -2978,22 +2978,30 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, # endif /* FIXED_POINT */ #endif /* SCAL */ -#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ - !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \ +#if !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && (\ + defined(PNG_FLOATING_POINT_SUPPORTED) && \ (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \ defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \ - (defined(PNG_sCAL_SUPPORTED) && \ - defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)) + (defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) &&\ + defined(PNG_sCAL_SUPPORTED))) png_fixed_point png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text) { - double r = floor(100000 * fp + .5); + if (fp < 0) + { + if (fp > -21474.836485) + return (png_fixed_point)(100000*fp - .5); + } - if (r > 2147483647. || r < -2147483648.) - png_fixed_error(png_ptr, text); + else + { + if (fp < 21474.836475) + return (png_fixed_point)(100000*fp + .5); + } - return (png_fixed_point)r; + /* Overflow */ + png_fixed_error(png_ptr, text); } #endif @@ -3571,334 +3579,6 @@ png_gamma_correct(png_structrp png_ptr, unsigned int value, return png_gamma_16bit_correct(value, gamma_val); } -#if 0 -/* Internal function to build a single 16-bit table - the table consists of - * 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount - * to shift the input values right (or 16-number_of_signifiant_bits). - * - * The caller is responsible for ensuring that the table gets cleaned up on - * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument - * should be somewhere that will be cleaned. - */ -static void -png_build_16bit_table(png_structrp png_ptr, png_uint_16p *ptable, - PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) -{ - /* Various values derived from 'shift': */ - PNG_CONST unsigned int num = 1U << (8U - shift); - PNG_CONST unsigned int max = (1U << (16U - shift))-1U; - PNG_CONST unsigned int max_by_2 = 1U << (15U-shift); - unsigned int i; - - png_uint_16pp table = *ptable = - (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p))); - - for (i = 0; i < num; i++) - { - png_uint_16p sub_table = table[i] = - (png_uint_16p)png_malloc(png_ptr, 256 * (sizeof (png_uint_16))); - - /* The 'threshold' test is repeated here because it can arise for one of - * the 16-bit tables even if the others don't hit it. - */ - if (png_gamma_significant(gamma_val)) - { - /* The old code would overflow at the end and this would cause the - * 'pow' function to return a result >1, resulting in an - * arithmetic error. This code follows the spec exactly; ig is - * the recovered input sample, it always has 8-16 bits. - * - * We want input * 65535/max, rounded, the arithmetic fits in 32 - * bits (unsigned) so long as max <= 32767. - */ - unsigned int j; - for (j = 0; j < 256; j++) - { - png_uint_32 ig = (j << (8-shift)) + i; -# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - /* Inline the 'max' scaling operation: */ - double d = floor(65535*pow(ig/(double)max, gamma_val*.00001)+.5); - sub_table[j] = (png_uint_16)d; -# else - if (shift) - ig = (ig * 65535U + max_by_2)/max; - - sub_table[j] = png_gamma_16bit_correct(ig, gamma_val); -# endif - } - } - else - { - /* We must still build a table, but do it the fast way. */ - unsigned int j; - - for (j = 0; j < 256; j++) - { - png_uint_32 ig = (j << (8-shift)) + i; - - if (shift) - ig = (ig * 65535U + max_by_2)/max; - - sub_table[j] = (png_uint_16)ig; - } - } - } -} - -/* NOTE: this function expects the *inverse* of the overall gamma transformation - * required. - */ -static void -png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable, - PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) -{ - PNG_CONST unsigned int num = 1U << (8U - shift); - PNG_CONST unsigned int max = (1U << (16U - shift))-1U; - unsigned int i; - png_uint_32 last; - - png_uint_16pp table = *ptable = - (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p))); - - /* 'num' is the number of tables and also the number of low bits of low - * bits of the input 16-bit value used to select a table. Each table is - * itself indexed by the high 8 bits of the value. - */ - for (i = 0; i < num; i++) - table[i] = (png_uint_16p)png_malloc(png_ptr, - 256 * (sizeof (png_uint_16))); - - /* 'gamma_val' is set to the reciprocal of the value calculated above, so - * pow(out,g) is an *input* value. 'last' is the last input value set. - * - * In the loop 'i' is used to find output values. Since the output is - * 8-bit there are only 256 possible values. The tables are set up to - * select the closest possible output value for each input by finding - * the input value at the boundary between each pair of output values - * and filling the table up to that boundary with the lower output - * value. - * - * The boundary values are 0.5,1.5..253.5,254.5. Since these are 9-bit - * values the code below uses a 16-bit value in i; the values start at - * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last - * entries are filled with 255). Start i at 128 and fill all 'last' - * table entries <= 'max' - */ - last = 0; - for (i = 0; i < 255; ++i) /* 8-bit output value */ - { - /* Find the corresponding maximum input value */ - png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */ - - /* Find the boundary value in 16 bits: */ - png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val); - - /* Adjust (round) to (16-shift) bits: */ - bound = (bound * max + 32768U)/65535U + 1U; - - while (last < bound) - { - table[last & (0xffU >> shift)][last >> (8U - shift)] = out; - last++; - } - } - - /* And fill in the final entries. */ - while (last < (num << 8)) - { - table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U; - last++; - } -} - -/* Build a single 8-bit table: same as the 16-bit case but much simpler (and - * typically much faster). Note that libpng currently does no sBIT processing - * (apparently contrary to the spec) so a 256 entry table is always generated. - */ -static void -png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable, - PNG_CONST png_fixed_point gamma_val) -{ - unsigned int i; - png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256); - - if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++) - table[i] = png_gamma_8bit_correct(i, gamma_val); - - else for (i=0; i<256; ++i) - table[i] = (png_byte)i; -} - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ - defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) -static void -png_build_8to16_table(png_structrp png_ptr, png_uint_16pp ptable, - PNG_CONST png_fixed_point gamma_val) -{ - unsigned int i; - png_uint_16p table = *ptable = (png_uint_16p)png_malloc(png_ptr, - sizeof (png_uint_16[256])); - - if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++) - table[i] = png_gamma_16bit_correct(i*257, gamma_val); - - else for (i=0; i<256; ++i) - table[i] = (png_uint_16)(i*257); -} - -static void -png_build_16to8_table(png_structrp png_ptr, png_bytepp ptable8, - png_uint_16pp ptable16, png_fixed_point gamma_val, int gamma_shift) - /* Build a table of (1<<(16-gamma_shift))+1 entries to find 8-bit values - * encoded by gamma_val. The table is to be indexed with a 16-bit value - * scaled down by gamma_shift: - * - * table[(value + (1<<(gamma_shift-1)) >> gamma_shift] - * - * Because of the rounding the table is 2^(16-gamma_shift)+1 entries. - * Each table entry must contain value^gamma_val, rounded to 8 bits. - */ -{ - unsigned int size = 1U << (16-gamma_shift); - unsigned int add = (gamma_shift > 0 ? 1U<<(gamma_shift-1) : 0U); - png_bytep table8; - png_uint_16p table16; - unsigned int i; - - /* If 'table8' it gets the output values as 8-bit bytes, if 'table16' is set - * the same values are scaled by 257 to give 16-bit values. - */ - if (ptable8) - { - table8 = png_voidcast(png_bytep, png_malloc(png_ptr, size+1)); - *ptable8 = table8; - table8[0] = 0; - } - - else - table8 = NULL; - - if (ptable16) - { - table16 = png_voidcast(png_uint_16p, png_malloc(png_ptr, - sizeof (png_uint_16) * (size+1))); - *ptable16 = table16; - table16[0] = 0; - } - - else - table16 = NULL; - - i = 1; - -# define FILL(val) do {\ - if (table8) table8[i] = (val);\ - if (table16) table16[i] = (png_uint_16)((val)*257U);\ - ++i; - } while (0) - - if (gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED) - { - /* gamma < 1; the output values will jump by more than one for each table - * entry initially. - */ - png_byte last_out = 0; - - while (i < size) - { - png_byte out = (png_byte)PNG_DIV257(png_gamma_16bit_correct( - i << gamma_shift, gamma_val)); - - FILL(out); - - if (out <= last_out) - { - /* The table values are no longer advancing at each step, swap to - * finding the *last* table index corresponding to this value - * of 'out' - this is the one that corresponds to out+.5, below this - * is calculated as out*257+128; the exact value would be - * out*257+128.5, so we get a lower value, rounding ensures that we - * fill all the table entries corresponding to 'out' (with some very - * small chance of error at the boundaries.) - */ - png_fixed_point gamma_inv = png_reciprocal(gamma_val); - - while (out < 255 && i < size) - { - unsigned int next_index = (png_gamma_16bit_correct(out*257+128, - gamma_inv) + add) >> gamma_shift; - - while (i <= next_index && i < size) - FILL(out); - - ++out; - } - - break; /* fill remaining entries with 255 */ - } - } - } - - else if (gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED) - { - /* gamma > 1; initially multiple table entries will correspond to the same - * value, invert the above loops. - */ - png_fixed_point gamma_inv = png_reciprocal(gamma_val); - png_byte out = 0; - - while (out < 255) - { - unsigned int next_index = (png_gamma_16bit_correct(out*257+128, - gamma_inv) + add) >> gamma_shift; - - /* If this 'out' value falls in the same slot as the last one - * recalculate the value for this slot. - */ - if (next_index <= i) - { - i = next_index; - break; - } - - while (i <= next_index && i < size) - FILL(out); - - ++out; - } - - while (i < size && out < 255) - { - out = (png_byte)PNG_DIV257(png_gamma_16bit_correct(i << gamma_shift, - gamma_val)); - FILL(out); - } - } - - else /* gamma_val not significant */ - { - png_byte out = 0; /* current output value */ - - add += 128; - - while (out < 255 && i < size) { - unsigned int next_index = (out*257+add) >> gamma_shift; - - while (i <= next_index && i < size) - FILL(out); - - ++out; - } - } - - /* Fill in the remainder of the table */ - while (i <= size) - FILL(255); -} -#endif /* BACKGROUND || ALPHA_MODE || RGB_TO_GRAY */ -#endif /* UNUSED */ - #define PNG_GAMMA_TABLE_8 0 /* 8-bit entries in png_byte */ #define PNG_GAMMA_TABLE_8_IN_16 1 /* 8-bit entries * 257 in png_uint_16 */ #define PNG_GAMMA_TABLE_16 2 /* 16-bit entries in png_uint_16 */ diff --git a/png.h b/png.h index 989cba930..0522dd86e 100644 --- a/png.h +++ b/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.7.0alpha03 - December 17, 2012 + * libpng version 1.7.0alpha03 - December 18, 2012 * Copyright (c) 1998-2012 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.7.0alpha03 - December 17, 2012: Glenn + * libpng versions 0.97, January 1998, through 1.7.0alpha03 - December 18, 2012: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -199,7 +199,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.7.0alpha03, December 17, 2012, are + * libpng versions 1.2.6, August 15, 2004, through 1.7.0alpha03, December 18, 2012, are * Copyright (c) 2004, 2006-2012 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: @@ -311,7 +311,7 @@ * Y2K compliance in libpng: * ========================= * - * December 17, 2012 + * December 18, 2012 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. @@ -379,7 +379,7 @@ /* Version information for png.h - this should match the version in png.c */ #define PNG_LIBPNG_VER_STRING "1.7.0alpha03" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.7.0alpha03 - December 17, 2012\n" + " libpng version 1.7.0alpha03 - December 18, 2012\n" #define PNG_LIBPNG_VER_SONUM 17 #define PNG_LIBPNG_VER_DLLNUM 17 @@ -2329,15 +2329,14 @@ PNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr, #endif #ifdef PNG_sCAL_SUPPORTED -PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr, - png_const_inforp info_ptr, int *unit, double *width, double *height)) -#if (defined PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ - (defined PNG_FLOATING_POINT_SUPPORTED) -/* NOTE: this API is currently implemented using floating point arithmetic, - * consequently it can only be used on systems with floating point support. +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +/* NOTE: these API are currently implemented using floating point arithmetic, + * consequently they can only be used on systems with floating point support. * In any case the range of values supported by png_fixed_point is small and it * is highly recommended that png_get_sCAL_s be used instead. */ +PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr, + png_const_inforp info_ptr, int *unit, double *width, double *height)) PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, png_fixed_point *width, png_fixed_point *height)) @@ -2346,8 +2345,13 @@ PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +/* This also requires internal floating point arithmetic support - i.e. it + * requires a full math library, not just floating point handling. + */ PNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr, png_inforp info_ptr, int unit, double width, double height)) +#endif PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr, png_inforp info_ptr, int unit, png_fixed_point width, png_fixed_point height)) diff --git a/pngerror.c b/pngerror.c index 9e904d449..e42c6eec6 100644 --- a/pngerror.c +++ b/pngerror.c @@ -546,15 +546,13 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error) } #ifdef PNG_ERROR_TEXT_SUPPORTED + #if defined(PNG_FLOATING_POINT_SUPPORTED) && \ - (!defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \ (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \ defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \ - defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) ||\ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) ||\ - defined(PNG_READ_GAMMA_SUPPORTED)) || \ - (defined(PNG_sCAL_SUPPORTED) && \ - defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)) + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \ + (defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) &&\ + defined(PNG_sCAL_SUPPORTED)) PNG_FUNCTION(void, png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN) { diff --git a/pngget.c b/pngget.c index b7e977780..2d60be859 100644 --- a/pngget.c +++ b/pngget.c @@ -843,9 +843,8 @@ png_get_pCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, #endif #ifdef PNG_sCAL_SUPPORTED -# ifdef PNG_FIXED_POINT_SUPPORTED -# if (defined PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ - (defined PNG_FLOATING_POINT_SUPPORTED) +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +# ifdef PNG_FIXED_POINT_SUPPORTED png_uint_32 PNGAPI png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, png_fixed_point *width, png_fixed_point *height) @@ -866,9 +865,8 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, return(0); } -# endif /* FLOATING_ARITHMETIC */ -# endif /* FIXED_POINT */ -# ifdef PNG_FLOATING_POINT_SUPPORTED +# endif /* FIXED_POINT */ +# ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, double *width, double *height) @@ -884,7 +882,9 @@ png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, return(0); } -# endif /* FLOATING POINT */ +# endif /* FLOATING POINT */ +# endif /* FLOATING_ARITHMETIC */ + png_uint_32 PNGAPI png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, png_charpp width, png_charpp height) diff --git a/pngrtran.c b/pngrtran.c index 32d19ec0a..93a6d5598 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -257,16 +257,10 @@ convert_gamma_value(png_structrp png_ptr, double output_gamma) * bug reports. Negative values fail inside the _fixed API unless they * correspond to the flag values. */ - if (output_gamma > 0 && output_gamma < 128) - output_gamma *= PNG_FP_1; + if (output_gamma < 0 || output_gamma > 128) + output_gamma *= .00001; - /* This preserves -1 and -2 exactly: */ - output_gamma = floor(output_gamma + .5); - - if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN) - png_fixed_error(png_ptr, "gamma value"); - - return (png_fixed_point)output_gamma; + return png_fixed(png_ptr, output_gamma, "gamma value"); } # endif #endif /* READ_ALPHA_MODE || READ_GAMMA */ diff --git a/pngset.c b/pngset.c index 01cc581a8..c0c2d9664 100644 --- a/pngset.c +++ b/pngset.c @@ -431,7 +431,8 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr, info_ptr->free_me |= PNG_FREE_SCAL; } -# ifdef PNG_FLOATING_POINT_SUPPORTED +# if defined PNG_FLOATING_POINT_SUPPORTED &&\ + defined PNG_FLOATING_ARITHMETIC_SUPPORTED void PNGAPI png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit, double width, double height) diff --git a/pngtest.c b/pngtest.c index 8630ca436..dd541299f 100644 --- a/pngtest.c +++ b/pngtest.c @@ -1169,7 +1169,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) } #endif #ifdef PNG_sCAL_SUPPORTED -#ifdef PNG_FLOATING_POINT_SUPPORTED +#if defined PNG_FLOATING_POINT_SUPPORTED && \ + defined PNG_FLOATING_ARITHMETIC_SUPPORTED { int unit; double scal_width, scal_height;