diff -ru4NwbB libpng-1.5.0/Makefile.am libpng-1.5.1/Makefile.am --- libpng-1.5.0/Makefile.am 2011-01-22 16:39:30.152968768 -0600 +++ libpng-1.5.1/Makefile.am 2011-02-02 22:58:25.869490312 -0600 @@ -80,8 +80,15 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess config.h.in \ config.sub configure depcomp install-sh ltmain.sh missing +# DFNCPP is normally just CPP - the C preprocessor - but on Solaris and maybe +# other operating systems (NeXT?) the C preprocessor selected by configure +# checks input tokens for validity - effectively it performs part of the ANSI-C +# parsing - and therefore fails with the .df files. configure.ac has special +# checks for this and sets DFNCPP appropriately. +DFNCPP = @DFNCPP@ + SUFFIXES = .chk .dfn .out $(PNGLIB_BASENAME).pc: libpng.pc cp libpng.pc $@ @@ -110,17 +117,21 @@ # an installed one (this can happen immediately after on a clean system if # 'make test' is the first thing the user does.) pngvalid.o pngtest.o: pnglibconf.h +# We must use -DPNG_NO_USE_READ_MACROS here even when the library may actually +# be built with PNG_USE_READ_MACROS; this stops the read macros interfering +# with the symbol file format. SYMBOL_CFLAGS = -DPNGLIB_LIBNAME='PNG@PNGLIB_MAJOR@@PNGLIB_MINOR@_0'\ -DPNGLIB_VERSION='@PNGLIB_VERSION@'\ - -DSYMBOL_PREFIX='$(SYMBOL_PREFIX)' + -DSYMBOL_PREFIX='$(SYMBOL_PREFIX)'\ + -DPNG_NO_USE_READ_MACROS .dfn.out: rm -f $@ dfn.c dfn?.out test -d scripts || mkdir scripts echo '#include "$<"' >dfn.c - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) @LIBPNG_DEFINES@\ + $(DFNCPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) @LIBPNG_DEFINES@\ $(CPPFLAGS) $(SYMBOL_CFLAGS) dfn.c > dfn1.out $(SED) -n -e 's|^.*PNG_DEFN_MAGIC-\(.*\)-PNG_DEFN_END.*$$|\1|p'\ dfn1.out >dfn2.out $(SED) -e 's| *@@@ *||g' -e 's| *$$||' dfn2.out >dfn3.out diff -ru4NwbB libpng-1.5.0/configure.ac libpng-1.5.1/configure.ac --- libpng-1.5.0/configure.ac 2011-01-22 16:39:30.159759706 -0600 +++ libpng-1.5.1/configure.ac 2011-02-02 22:58:25.876640857 -0600 @@ -33,8 +33,9 @@ AC_CONFIG_SRCDIR([pngget.c]) AM_CONFIG_HEADER(config.h) # Checks for programs. +AC_LANG([C]) AC_PROG_CC AC_PROG_LD AC_PROG_CPP AC_CHECK_TOOL(SED, sed, :) @@ -43,8 +44,30 @@ AC_PROG_LN_S AC_PROG_MAKE_SET LT_INIT([win32-dll]) +# On Solaris 10 and 12 CPP gets set to cc -E, however this still +# does some input parsing. We need strict ANSI-C style tokenization, +# check this: +AC_REQUIRE_CPP +AC_MSG_CHECKING([for a C preprocessor that does not parse its input]) +AC_TRY_CPP([1.5.0 16BIT], + [DFNCPP="$CPP"], + [DFNCPP="" + sav_CPP="$CPP" + for CPP in "${CC-cc} -E" "${CC-cc} -E -traditional-cpp" "/lib/cpp" "cpp"; do + AC_TRY_CPP([1.5.0 16BIT], + [DFNCPP="$CPP"] + [break],,) + done + CPP="$sav_CPP"]) +if test -n "$DFNCPP"; then + AC_MSG_RESULT([$DFNCPP]) + AC_SUBST(DFNCPP) +else + AC_MSG_FAILURE([not found], 1) +fi + # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([malloc.h stdlib.h string.h strings.h]) @@ -75,9 +98,9 @@ # Special case for PE/COFF platforms: ld reports # support for version-script, but doesn't actually # DO anything with it. case $host in -*cygwin* | *mingw32* ) +*cygwin* | *mingw32* | *interix* ) have_ld_version_script=no AC_MSG_RESULT(no) ;; * ) diff -ru4NwbB libpng-1.5.0/png.c libpng-1.5.1/png.c --- libpng-1.5.0/png.c 2011-01-22 16:39:23.155029096 -0600 +++ libpng-1.5.1/png.c 2011-02-02 22:58:17.727227609 -0600 @@ -1,8 +1,8 @@ /* png.c - location for general purpose libpng functions * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -546,9 +546,9 @@ #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ png_const_charp PNGAPI -png_get_copyright(png_structp png_ptr) +png_get_copyright(png_const_structp png_ptr) { PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ #ifdef PNG_STRING_COPYRIGHT return PNG_STRING_COPYRIGHT @@ -577,24 +577,24 @@ * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, * it is guaranteed that png.c uses the correct version of png.h. */ png_const_charp PNGAPI -png_get_libpng_ver(png_structp png_ptr) +png_get_libpng_ver(png_const_structp png_ptr) { /* Version of *.c files used when building libpng */ return png_get_header_ver(png_ptr); } png_const_charp PNGAPI -png_get_header_ver(png_structp png_ptr) +png_get_header_ver(png_const_structp png_ptr) { /* Version of *.h files used when building libpng */ PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ return PNG_LIBPNG_VER_STRING; } png_const_charp PNGAPI -png_get_header_version(png_structp png_ptr) +png_get_header_version(png_const_structp png_ptr) { /* Returns longer string containing both version and date */ PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ #ifdef __STDC__ @@ -1030,12 +1030,12 @@ int png_check_fp_string(png_const_charp string, png_size_t size) { int state=0; - png_size_t index=0; + png_size_t char_index=0; - return png_check_fp_number(string, size, &state, &index) && - (index == size || string[index] == 0); + return png_check_fp_number(string, size, &state, &char_index) && + (char_index == size || string[char_index] == 0); } #endif /* pCAL or sCAL */ #ifdef PNG_READ_sCAL_SUPPORTED @@ -1107,48 +1107,48 @@ } if (fp >= DBL_MIN && fp <= DBL_MAX) { - int exp; /* A base 10 exponent */ - double base; /* 10^exp */ + int exp_b10; /* A base 10 exponent */ + double base; /* 10^exp_b10 */ /* First extract a base 10 exponent of the number, * the calculation below rounds down when converting * from base 2 to base 10 (multiply by log10(2) - - * 0.3010, but 77/256 is 0.3008, so exp needs to + * 0.3010, but 77/256 is 0.3008, so exp_b10 needs to * be increased. Note that the arithmetic shift * performs a floor() unlike C arithmetic - using a * C multiply would break the following for negative * exponents. */ - (void)frexp(fp, &exp); /* exponent to base 2 */ + (void)frexp(fp, &exp_b10); /* exponent to base 2 */ - exp = (exp * 77) >> 8; /* <= exponent to base 10 */ + exp_b10 = (exp_b10 * 77) >> 8; /* <= exponent to base 10 */ /* Avoid underflow here. */ - base = png_pow10(exp); /* May underflow */ + base = png_pow10(exp_b10); /* May underflow */ while (base < DBL_MIN || base < fp) { /* And this may overflow. */ - double test = png_pow10(exp+1); + double test = png_pow10(exp_b10+1); if (test <= DBL_MAX) - ++exp, base = test; + ++exp_b10, base = test; else break; } - /* Normalize fp and correct exp, after this fp is in the - * range [.1,1) and exp is both the exponent and the digit + /* Normalize fp and correct exp_b10, after this fp is in the + * range [.1,1) and exp_b10 is both the exponent and the digit * *before* which the decimal point should be inserted * (starting with 0 for the first digit). Note that this - * works even if 10^exp is out of range because of the + * works even if 10^exp_b10 is out of range because of the * test on DBL_MAX above. */ fp /= base; - while (fp >= 1) fp /= 10, ++exp; + while (fp >= 1) fp /= 10, ++exp_b10; /* Because of the code above fp may, at this point, be * less than .1, this is ok because the code below can * handle the leading zeros this generates, so no attempt @@ -1161,12 +1161,12 @@ /* Allow up to two leading zeros - this will not lengthen * the number compared to using E-n. */ - if (exp < 0 && exp > -3) /* PLUS 3 TOTAL 4 */ + if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */ { - czero = -exp; /* PLUS 2 digits: TOTAL 3 */ - exp = 0; /* Dot added below before first output. */ + czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */ + exp_b10 = 0; /* Dot added below before first output. */ } else czero = 0; /* No zeros to add */ @@ -1206,19 +1206,19 @@ while (cdigits > 0 && d > 9) { int ch = *--ascii; - if (exp != (-1)) - ++exp; + if (exp_b10 != (-1)) + ++exp_b10; else if (ch == 46) { ch = *--ascii, ++size; - /* Advance exp to '1', so that the + /* Advance exp_b10 to '1', so that the * decimal point happens after the * previous digit. */ - exp = 1; + exp_b10 = 1; } --cdigits; d = ch - 47; /* I.e. 1+(ch-48) */ @@ -1229,25 +1229,25 @@ * decimal point. */ if (d > 9) /* cdigits == 0 */ { - if (exp == (-1)) + if (exp_b10 == (-1)) { /* Leading decimal point (plus zeros?), if * we lose the decimal point here it must * be reentered below. */ int ch = *--ascii; if (ch == 46) - ++size, exp = 1; + ++size, exp_b10 = 1; - /* Else lost a leading zero, so 'exp' is + /* Else lost a leading zero, so 'exp_b10' is * still ok at (-1) */ } else - ++exp; + ++exp_b10; /* In all cases we output a '1' */ d = 1; } @@ -1268,25 +1268,26 @@ clead = 0; while (czero > 0) { - /* exp == (-1) means we just output the decimal - * place - after the DP don't adjust 'exp' any + /* exp_b10 == (-1) means we just output the decimal + * place - after the DP don't adjust 'exp_b10' any * more! */ - if (exp != (-1)) + if (exp_b10 != (-1)) { - if (exp == 0) *ascii++ = 46, --size; + if (exp_b10 == 0) *ascii++ = 46, --size; /* PLUS 1: TOTAL 4 */ - --exp; + --exp_b10; } *ascii++ = 48, --czero; } - if (exp != (-1)) + if (exp_b10 != (-1)) { - if (exp == 0) *ascii++ = 46, --size; /* counted above */ - --exp; + if (exp_b10 == 0) *ascii++ = 46, --size; /* counted + above */ + --exp_b10; } *ascii++ = (char)(48 + (int)d), ++cdigits; } } @@ -1295,23 +1296,23 @@ /* The total output count (max) is now 4+precision */ /* Check for an exponent, if we don't need one we are * done and just need to terminate the string. At - * this point exp==(-1) is effectively if flag - it got + * this point exp_b10==(-1) is effectively if flag - it got * to '-1' because of the decrement after outputing * the decimal point above (the exponent required is * *not* -1!) */ - if (exp >= (-1) && exp <= 2) + if (exp_b10 >= (-1) && exp_b10 <= 2) { /* The following only happens if we didn't output the * leading zeros above for negative exponent, so this * doest add to the digit requirement. Note that the * two zeros here can only be output if the two leading * zeros were *not* output, so this doesn't increase * the output count. */ - while (--exp >= 0) *ascii++ = 48; + while (--exp_b10 >= 0) *ascii++ = 48; *ascii = 0; /* Total buffer requirement (including the '\0') is @@ -1328,20 +1329,20 @@ */ size -= cdigits; *ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision*/ - if (exp < 0) + if (exp_b10 < 0) { *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ - exp = -exp; + exp_b10 = -exp_b10; } cdigits = 0; - while (exp > 0) + while (exp_b10 > 0) { - exponent[cdigits++] = (char)(48 + exp % 10); - exp /= 10; + exponent[cdigits++] = (char)(48 + exp_b10 % 10); + exp_b10 /= 10; } /* Need another size check here for the exponent digits, so * this need not be considered above. @@ -1458,13 +1459,12 @@ png_fixed(png_structp png_ptr, double fp, png_const_charp text) { double r = floor(100000 * fp + .5); - if (r <= 2147483647. && r >= -2147483648.) - return (png_fixed_point)r; - + if (r > 2147483647. || r < -2147483648.) png_fixed_error(png_ptr, text); - /*NOT REACHED*/ + + return (png_fixed_point)r; } #endif #if defined(PNG_READ_GAMMA_SUPPORTED) || \ @@ -1476,12 +1476,12 @@ * the result, a boolean - true on success, false on overflow. */ int png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, - png_int_32 div) + png_int_32 divisor) { - /* Return a * times / div, rounded. */ - if (div != 0) + /* Return a * times / divisor, rounded. */ + if (divisor != 0) { if (a == 0 || times == 0) { *res = 0; @@ -1491,9 +1491,9 @@ { #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED double r = a; r *= times; - r /= div; + r /= divisor; r = floor(r+.5); /* A png_fixed_point is a 32 bit integer. */ if (r <= 2147483647. && r >= -2147483648.) @@ -1515,12 +1515,12 @@ negative = !negative, T = -times; else T = times; - if (div < 0) - negative = !negative, D = -div; + if (divisor < 0) + negative = !negative, D = -divisor; else - D = div; + D = divisor; /* Following can't overflow because the arguments only * have 31 bits each, however the result may be 32 bits. */ @@ -1595,13 +1595,13 @@ * result. */ png_fixed_point png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times, - png_int_32 div) + png_int_32 divisor) { png_fixed_point result; - if (png_muldiv(&result, a, times, div)) + if (png_muldiv(&result, a, times, divisor)) return result; png_warning(png_ptr, "fixed point overflow ignored"); return 0; @@ -1790,9 +1790,9 @@ static png_int_32 png_log8bit(unsigned int x) { - unsigned int log = 0; + unsigned int lg2 = 0; /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log, * because the log is actually negate that means adding 1. The final * returned value thus has the range 0 (for 255 input) to 7.994 (for 1 * input), return 7.99998 for the overflow (log 0) case - so the result is @@ -1801,18 +1801,18 @@ if ((x &= 0xff) == 0) return 0xffffffff; if ((x & 0xf0) == 0) - log = 4, x <<= 4; + lg2 = 4, x <<= 4; if ((x & 0xc0) == 0) - log += 2, x <<= 2; + lg2 += 2, x <<= 2; if ((x & 0x80) == 0) - log += 1, x <<= 1; + lg2 += 1, x <<= 1; /* result is at most 19 bits, so this cast is safe: */ - return (png_int_32)((log << 16) + ((png_8bit_l2[x-128]+32768)>>16)); + return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16)); } /* The above gives exact (to 16 binary places) log2 values for 8 bit images, * for 16 bit images we use the most significant 8 bits of the 16 bit value to @@ -1846,31 +1846,31 @@ */ static png_int_32 png_log16bit(png_uint_32 x) { - unsigned int log = 0; + unsigned int lg2 = 0; /* As above, but now the input has 16 bits. */ if ((x &= 0xffff) == 0) return 0xffffffff; if ((x & 0xff00) == 0) - log = 8, x <<= 8; + lg2 = 8, x <<= 8; if ((x & 0xf000) == 0) - log += 4, x <<= 4; + lg2 += 4, x <<= 4; if ((x & 0xc000) == 0) - log += 2, x <<= 2; + lg2 += 2, x <<= 2; if ((x & 0x8000) == 0) - log += 1, x <<= 1; + lg2 += 1, x <<= 1; /* Calculate the base logarithm from the top 8 bits as a 28 bit fractional * value. */ - log <<= 28; - log += (png_8bit_l2[(x>>8)-128]+8) >> 4; + lg2 <<= 28; + lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4; /* Now we need to interpolate the factor, this requires a division by the top * 8 bits. Do this with maximum precision. */ @@ -1879,21 +1879,21 @@ /* Since we divided by the top 8 bits of 'x' there will be a '1' at 1<<24, * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly * 16 bits to interpolate to get the low bits of the result. Round the * answer. Note that the end point values are scaled by 64 to retain overall - * precision and that 'log' is current scaled by an extra 12 bits, so adjust + * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust * the overall scaling by 6-12. Round at every step. */ x -= 1U << 24; if (x <= 65536U) /* <= '257' */ - log += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12); + lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12); else - log -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12); + lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12); /* Safe, because the result can't have more than 20 bits: */ - return (png_int_32)((log + 2048) >> 12); + return (png_int_32)((lg2 + 2048) >> 12); } /* The 'exp()' case must invert the above, taking a 20 bit fixed point * logarithmic value and returning a 16 or 8 bit number as appropriate. In @@ -1986,12 +1986,12 @@ return 0; } static png_byte -png_exp8bit(png_fixed_point log) +png_exp8bit(png_fixed_point lg2) { /* Get a 32 bit value: */ - png_uint_32 x = png_exp(log); + png_uint_32 x = png_exp(lg2); /* Convert the 32 bit value to 0..255 by multiplying by 256-1, note that the * second, rounding, step can't overflow because of the first, subtraction, * step. @@ -2000,32 +2000,32 @@ return (png_byte)((x + 0x7fffffU) >> 24); } static png_uint_16 -png_exp16bit(png_fixed_point log) +png_exp16bit(png_fixed_point lg2) { /* Get a 32 bit value: */ - png_uint_32 x = png_exp(log); + png_uint_32 x = png_exp(lg2); /* Convert the 32 bit value to 0..65535 by multiplying by 65536-1: */ x -= x >> 16; return (png_uint_16)((x + 32767U) >> 16); } #endif /* FLOATING_ARITHMETIC */ png_byte -png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma) +png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val) { if (value > 0 && value < 255) { # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = floor(255*pow(value/255.,gamma*.00001)+.5); + double r = floor(255*pow(value/255.,gamma_val*.00001)+.5); return (png_byte)r; # else - png_int_32 log = png_log8bit(value); + png_int_32 lg2 = png_log8bit(value); png_fixed_point res; - if (png_muldiv(&res, gamma, log, PNG_FP_1)) + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) return png_exp8bit(res); /* Overflow. */ value = 0; @@ -2035,20 +2035,20 @@ return (png_byte)value; } png_uint_16 -png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma) +png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) { if (value > 0 && value < 65535) { # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = floor(65535*pow(value/65535.,gamma*.00001)+.5); + double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5); return (png_uint_16)r; # else - png_int_32 log = png_log16bit(value); + png_int_32 lg2 = png_log16bit(value); png_fixed_point res; - if (png_muldiv(&res, gamma, log, PNG_FP_1)) + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) return png_exp16bit(res); /* Overflow. */ value = 0; @@ -2064,25 +2064,25 @@ * 8 bit (as are the arguments.) */ png_uint_16 /* PRIVATE */ png_gamma_correct(png_structp png_ptr, unsigned int value, - png_fixed_point gamma) + png_fixed_point gamma_val) { if (png_ptr->bit_depth == 8) - return png_gamma_8bit_correct(value, gamma); + return png_gamma_8bit_correct(value, gamma_val); else - return png_gamma_16bit_correct(value, gamma); + return png_gamma_16bit_correct(value, gamma_val); } /* This is the shared test on whether a gamma value is 'significant' - whether * it is worth doing gamma correction. */ int /* PRIVATE */ -png_gamma_significant(png_fixed_point gamma) +png_gamma_significant(png_fixed_point gamma_val) { - return gamma < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED || - gamma > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED; + return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED || + gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED; } /* 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 @@ -2093,9 +2093,9 @@ * should be somewhere that will be cleaned. */ static void png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, - PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma) + 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; @@ -2112,9 +2112,9 @@ /* 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)) + 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 @@ -2128,15 +2128,15 @@ { 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*.00001)+.5); + 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); + sub_table[j] = png_gamma_16bit_correct(ig, gamma_val); # endif } } else @@ -2161,9 +2161,9 @@ * required. */ static void png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable, - PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma) + 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; @@ -2179,9 +2179,9 @@ for (i = 0; i < num; i++) table[i] = (png_uint_16p)png_malloc(png_ptr, 256 * png_sizeof(png_uint_16)); - /* 'gamma' is set to the reciprocal of the value calculated above, so + /* '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 @@ -2202,9 +2202,9 @@ /* 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); + png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val); /* Adjust (round) to (16-shift) bits: */ bound = (bound * max + 32768U)/65535U + 1U; @@ -2228,15 +2228,15 @@ * (apparently contrary to the spec) so a 256 entry table is always generated. */ static void png_build_8bit_table(png_structp png_ptr, png_bytepp ptable, - PNG_CONST png_fixed_point gamma) + 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)) for (i=0; i<256; i++) - table[i] = png_gamma_8bit_correct(i, gamma); + 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; } diff -ru4NwbB libpng-1.5.0/png.h libpng-1.5.1/png.h --- libpng-1.5.0/png.h 2011-01-22 16:39:23.104799847 -0600 +++ libpng-1.5.1/png.h 2011-02-02 22:58:17.679708709 -0600 @@ -143,8 +143,11 @@ * 1.4.4 14 10404 14.so.14.4[.0] * 1.5.0beta01-58 15 10500 15.so.15.0[.0] * 1.5.0rc01-07 15 10500 15.so.15.0[.0] * 1.5.0 15 10500 15.so.15.0[.0] + * 1.5.1beta01-11 15 10501 15.so.15.1[.0] + * 1.5.1rc01-02 15 10501 15.so.15.1[.0] + * 1.5.1 15 10501 15.so.15.1[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be * used for changes in backward compatibility, as it is intended. The @@ -661,8 +664,9 @@ #endif typedef struct png_info_def png_info; typedef png_info FAR * png_infop; +typedef PNG_CONST png_info FAR * png_const_infop; typedef png_info FAR * FAR * png_infopp; /* Maximum positive integer used in PNG is (2^31)-1 */ #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) @@ -788,8 +792,9 @@ * modify the buffer it is passed. The 'read' function, on the other hand, is * expected to return the read data in the buffer. */ typedef struct png_struct_def png_struct; +typedef PNG_CONST png_struct FAR * png_const_structp; typedef png_struct FAR * png_structp; typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp), ); typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t), ); @@ -943,9 +948,9 @@ png_error_ptr warn_fn), PNG_ALLOCATED); PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size, - (png_structp png_ptr)); + (png_const_structp png_ptr)); PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structp png_ptr, png_size_t size)); @@ -1063,16 +1068,19 @@ #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED /* Expand the grayscale to 24-bit RGB if necessary. */ PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structp png_ptr)); +#endif +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED /* Reduce RGB to grayscale. */ PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr, int error_action, double red, double green)); PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr, int error_action, png_fixed_point red, png_fixed_point green)); -PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_structp png_ptr)); +PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structp + png_ptr)); #endif PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, png_colorp palette)); @@ -1407,9 +1415,9 @@ (png_structp png_ptr, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); /* Return the user pointer associated with the error functions */ -PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_structp png_ptr)); +PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr)); /* Replace the default data output functions with a user supplied one(s). * If buffered output is not used, then output_flush_fn can be set to NULL. * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time @@ -1440,9 +1448,9 @@ /* Replace the default memory allocation functions with user supplied one(s). */ PNG_EXPORT(82, void, png_set_mem_fn, (png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)); /* Return the user pointer associated with the memory functions */ -PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_structp png_ptr)); +PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structp png_ptr)); #endif #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structp png_ptr, @@ -1453,21 +1461,33 @@ PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structp png_ptr, png_user_transform_ptr write_user_transform_fn)); #endif -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED PNG_EXPORT(86, void, png_set_user_transform_info, (png_structp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels)); /* Return the user pointer associated with the user transform functions */ -PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, (png_structp png_ptr)); +PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, + (png_const_structp png_ptr)); +#endif + +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED +/* Return information about the row currently being processed. Note that these + * APIs do not fail but will return unexpected results if called outside a user + * transform callback. Also note that when transforming an interlaced image the + * row number is still the row in the final, de-interlaced, image but the row + * only contains the data of the current pass - consult png_row_info for the + * actual width of the row! + */ +PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp)); +PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp)); #endif #ifdef PNG_USER_CHUNKS_SUPPORTED PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structp png_ptr, png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); -PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_structp png_ptr)); +PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structp png_ptr)); #endif #ifdef PNG_PROGRESSIVE_READ_SUPPORTED /* Sets the function callbacks for the push reader, and a pointer to a @@ -1477,15 +1497,32 @@ png_voidp progressive_ptr, png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn)); /* Returns the user pointer associated with the push read functions */ -PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_structp png_ptr)); +PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structp png_ptr)); /* Function to be called when data becomes available */ PNG_EXPORT(92, void, png_process_data, (png_structp png_ptr, png_infop info_ptr, png_bytep buffer, png_size_t buffer_size)); +/* A function which may be called *only* within png_process_data to stop the + * processing of any more data. The function returns the number of bytes + * remaining, excluding any that libpng has cached internally. A subsequent + * call to png_process_data must supply these bytes again. If the argument + * 'save' is set to true the routine will first save all the pending data and + * will always return 0. + */ +PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structp, int save)); + +/* A function which may be called *only* outside (after) a call to + * png_process_data. It returns the number of bytes of data to skip in the + * input. Normally it will return 0, but if it returns a non-zero value the + * application must skip than number of bytes of input data and pass the + * following data to the next call to png_process_data. + */ +PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structp)); + /* Function that combines rows. 'new_row' is a flag that should come from * the callback and be non-NULL if anything needs to be done; the library * stores its own version of the new data internally and ignores the passed * in value. @@ -1603,94 +1640,94 @@ * png_info_struct. */ /* Returns "flag" if chunk data is valid in info_ptr. */ PNG_EXPORT(110, png_uint_32, png_get_valid, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 flag)); /* Returns number of bytes needed to hold a transformed row. */ -PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr, + png_const_infop info_ptr)); #ifdef PNG_INFO_IMAGE_SUPPORTED /* Returns row_pointers, which is an array of pointers to scanlines that was * returned from png_read_png(). */ PNG_EXPORT(112, png_bytepp, png_get_rows, - (png_structp png_ptr, png_infop info_ptr)); + (png_const_structp png_ptr, png_const_infop info_ptr)); /* Set row_pointers, which is an array of pointers to scanlines for use * by png_write_png(). */ -PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr, png_infop info_ptr, - png_bytepp row_pointers)); +PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr, + png_infop info_ptr, png_bytepp row_pointers)); #endif /* Returns number of color channels in image. */ PNG_EXPORT(114, png_byte, png_get_channels, - (png_structp png_ptr, png_infop info_ptr)); + (png_const_structp png_ptr, png_const_infop info_ptr)); #ifdef PNG_EASY_ACCESS_SUPPORTED /* Returns image width in pixels. */ -PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structp png_ptr, + png_const_infop info_ptr)); /* Returns image height in pixels. */ -PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structp png_ptr, + png_const_infop info_ptr)); /* Returns image bit_depth. */ PNG_EXPORT(117, png_byte, png_get_bit_depth, - (png_structp png_ptr, png_infop info_ptr)); + (png_const_structp png_ptr, png_const_infop info_ptr)); /* Returns image color_type. */ -PNG_EXPORT(118, png_byte, png_get_color_type, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); /* Returns image filter_type. */ -PNG_EXPORT(119, png_byte, png_get_filter_type, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); /* Returns image interlace_type. */ -PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); /* Returns image compression_type. */ -PNG_EXPORT(121, png_byte, png_get_compression_type, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); /* Returns image resolution in pixels per meter, from pHYs chunk data. */ -PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter, (png_structp png_ptr, - png_infop info_ptr)); -PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter, (png_structp png_ptr, - png_infop info_ptr)); -PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter, + (png_const_structp png_ptr, png_const_infop info_ptr)); /* Returns pixel aspect ratio, computed from pHYs chunk data. */ -PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio, (png_structp png_ptr, - png_infop info_ptr)); +PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio, + (png_const_structp png_ptr, png_const_infop info_ptr)); PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed, - (png_structp png_ptr, png_infop info_ptr)); + (png_const_structp png_ptr, png_const_infop info_ptr)); /* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ -PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, (png_structp png_ptr, - png_infop info_ptr)); -PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, (png_structp png_ptr, - png_infop info_ptr)); -PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, (png_structp png_ptr, - png_infop info_ptr)); -PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, + (png_const_structp png_ptr, png_const_infop info_ptr)); #endif /* PNG_EASY_ACCESS_SUPPORTED */ /* Returns pointer to signature string read from PNG header */ -PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(130, png_const_bytep, png_get_signature, + (png_const_structp png_ptr, png_infop info_ptr)); #ifdef PNG_bKGD_SUPPORTED PNG_EXPORT(131, png_uint_32, png_get_bKGD, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_infop info_ptr, png_color_16p *background)); #endif #ifdef PNG_bKGD_SUPPORTED @@ -1698,15 +1735,16 @@ png_const_color_16p background)); #endif #ifdef PNG_cHRM_SUPPORTED -PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_structp png_ptr, - png_infop info_ptr, double *white_x, double *white_y, double *red_x, +PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structp png_ptr, + png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, double *blue_y)); #ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */ -PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, (png_structp png_ptr, - png_infop info_ptr, png_fixed_point *int_white_x, +PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, + (png_const_structp png_ptr, + png_const_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y, png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point *int_blue_x, png_fixed_point *int_blue_y)); @@ -1727,30 +1765,31 @@ #endif #ifdef PNG_gAMA_SUPPORTED PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, double *file_gamma)); -PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, (png_structp png_ptr, - png_infop info_ptr, png_fixed_point *int_file_gamma)); +PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_fixed_point *int_file_gamma)); #endif #ifdef PNG_gAMA_SUPPORTED -PNG_FP_EXPORT(139, void, png_set_gAMA, (png_structp png_ptr, png_infop info_ptr, - double file_gamma)); +PNG_FP_EXPORT(139, void, png_set_gAMA, (png_structp png_ptr, + png_infop info_ptr, double file_gamma)); PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_structp png_ptr, png_infop info_ptr, png_fixed_point int_file_gamma)); #endif #ifdef PNG_hIST_SUPPORTED PNG_EXPORT(141, png_uint_32, png_get_hIST, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_16p *hist)); #endif #ifdef PNG_hIST_SUPPORTED -PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr, png_infop info_ptr, - png_const_uint_16p hist)); +PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr, + png_infop info_ptr, png_const_uint_16p hist)); #endif PNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_structp png_ptr, png_infop info_ptr, @@ -1763,9 +1802,9 @@ int interlace_method, int compression_method, int filter_method)); #ifdef PNG_oFFs_SUPPORTED PNG_EXPORT(145, png_uint_32, png_get_oFFs, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)); #endif #ifdef PNG_oFFs_SUPPORTED @@ -1775,23 +1814,24 @@ #endif #ifdef PNG_pCAL_SUPPORTED PNG_EXPORT(147, png_uint_32, png_get_pCAL, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *units, png_charpp *params)); #endif #ifdef PNG_pCAL_SUPPORTED -PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr, png_infop info_ptr, +PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr, + png_infop info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params)); #endif #ifdef PNG_pHYs_SUPPORTED PNG_EXPORT(149, png_uint_32, png_get_pHYs, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); #endif #ifdef PNG_pHYs_SUPPORTED @@ -1800,18 +1840,18 @@ png_uint_32 res_x, png_uint_32 res_y, int unit_type)); #endif PNG_EXPORT(151, png_uint_32, png_get_PLTE, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_colorp *palette, int *num_palette)); PNG_EXPORT(152, void, png_set_PLTE, (png_structp png_ptr, png_infop info_ptr, png_const_colorp palette, int num_palette)); #ifdef PNG_sBIT_SUPPORTED PNG_EXPORT(153, png_uint_32, png_get_sBIT, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)); #endif #ifdef PNG_sBIT_SUPPORTED @@ -1819,22 +1859,22 @@ (png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit)); #endif #ifdef PNG_sRGB_SUPPORTED -PNG_EXPORT(155, png_uint_32, png_get_sRGB, - (png_structp png_ptr, png_infop info_ptr, int *intent)); +PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structp png_ptr, + png_const_infop info_ptr, int *file_srgb_intent)); #endif #ifdef PNG_sRGB_SUPPORTED PNG_EXPORT(156, void, png_set_sRGB, - (png_structp png_ptr, png_infop info_ptr, int intent)); + (png_structp png_ptr, png_infop info_ptr, int srgb_intent)); PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_structp png_ptr, - png_infop info_ptr, int intent)); + png_infop info_ptr, int srgb_intent)); #endif #ifdef PNG_iCCP_SUPPORTED PNG_EXPORT(158, png_uint_32, png_get_iCCP, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_charpp name, int *compression_type, png_bytepp profile, png_uint_32 *proflen)); #endif @@ -1846,9 +1886,9 @@ #endif #ifdef PNG_sPLT_SUPPORTED PNG_EXPORT(160, png_uint_32, png_get_sPLT, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_sPLT_tpp entries)); #endif #ifdef PNG_sPLT_SUPPORTED @@ -1859,9 +1899,9 @@ #ifdef PNG_TEXT_SUPPORTED /* png_get_text also returns the number of text chunks in *num_text */ PNG_EXPORT(162, png_uint_32, png_get_text, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, png_textp *text_ptr, int *num_text)); #endif /* Note while png_set_text() will accept a structure whose text, @@ -1878,9 +1918,9 @@ #endif #ifdef PNG_tIME_SUPPORTED PNG_EXPORT(164, png_uint_32, png_get_tIME, - (png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); + (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); #endif #ifdef PNG_tIME_SUPPORTED PNG_EXPORT(165, void, png_set_tIME, @@ -1888,9 +1928,9 @@ #endif #ifdef PNG_tRNS_SUPPORTED PNG_EXPORT(166, png_uint_32, png_get_tRNS, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_infop info_ptr, png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)); #endif #ifdef PNG_tRNS_SUPPORTED @@ -1901,23 +1941,24 @@ #endif #ifdef PNG_sCAL_SUPPORTED PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, - (png_structp png_ptr, png_infop info_ptr, + (png_const_structp png_ptr, png_const_infop info_ptr, int *unit, double *width, double *height)); #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED /* NOTE: this API is currently implemented using floating point arithmetic, * consequently it 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_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, (png_structp png_ptr, - png_infop info_ptr, int *unit, png_fixed_point *width, +PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, + (png_structp png_ptr, png_const_infop info_ptr, int *unit, + png_fixed_point *width, png_fixed_point *height)); #endif PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, - (png_structp png_ptr, - png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); + (png_const_structp png_ptr, png_const_infop info_ptr, + int *unit, png_charpp swidth, png_charpp sheight)); PNG_FP_EXPORT(170, void, png_set_sCAL, (png_structp png_ptr, png_infop info_ptr, int unit, double width, double height)); @@ -1946,13 +1987,14 @@ png_const_bytep chunk_name)); #endif #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structp png_ptr, - png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)); -PNG_EXPORT(175, void, png_set_unknown_chunk_location, (png_structp png_ptr, - png_infop info_ptr, int chunk, int location)); -PNG_EXPORT(176, int, png_get_unknown_chunks, (png_structp png_ptr, - png_infop info_ptr, png_unknown_chunkpp entries)); + png_infop info_ptr, png_const_unknown_chunkp unknowns, + int num_unknowns)); +PNG_EXPORT(175, void, png_set_unknown_chunk_location, + (png_structp png_ptr, png_infop info_ptr, int chunk, int location)); +PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr, + png_const_infop info_ptr, png_unknown_chunkpp entries)); #endif /* Png_free_data() will turn off the "valid" flag for anything it frees. * If you need to turn it off for a chunk that your application has freed, @@ -1968,12 +2010,16 @@ PNG_EXPORT(179, void, png_write_png, (png_structp png_ptr, png_infop info_ptr, int transforms, png_voidp params)); #endif -PNG_EXPORT(180, png_const_charp, png_get_copyright, (png_structp png_ptr)); -PNG_EXPORT(181, png_const_charp, png_get_header_ver, (png_structp png_ptr)); -PNG_EXPORT(182, png_const_charp, png_get_header_version, (png_structp png_ptr)); -PNG_EXPORT(183, png_const_charp, png_get_libpng_ver, (png_structp png_ptr)); +PNG_EXPORT(180, png_const_charp, png_get_copyright, + (png_const_structp png_ptr)); +PNG_EXPORT(181, png_const_charp, png_get_header_ver, + (png_const_structp png_ptr)); +PNG_EXPORT(182, png_const_charp, png_get_header_version, + (png_const_structp png_ptr)); +PNG_EXPORT(183, png_const_charp, png_get_libpng_ver, + (png_const_structp png_ptr)); #ifdef PNG_MNG_FEATURES_SUPPORTED PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr, png_uint_32 mng_features_permitted)); @@ -1997,57 +2043,63 @@ /* Added in libpng-1.2.6 */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED PNG_EXPORT(186, void, png_set_user_limits, (png_structp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max)); -PNG_EXPORT(187, png_uint_32, png_get_user_width_max, (png_structp png_ptr)); -PNG_EXPORT(188, png_uint_32, png_get_user_height_max, (png_structp png_ptr)); +PNG_EXPORT(187, png_uint_32, png_get_user_width_max, + (png_const_structp png_ptr)); +PNG_EXPORT(188, png_uint_32, png_get_user_height_max, + (png_const_structp png_ptr)); /* Added in libpng-1.4.0 */ PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structp png_ptr, png_uint_32 user_chunk_cache_max)); -PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max, (png_structp png_ptr)); +PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max, + (png_const_structp png_ptr)); /* Added in libpng-1.4.1 */ PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structp png_ptr, png_alloc_size_t user_chunk_cache_max)); PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max, - (png_structp png_ptr)); + (png_const_structp png_ptr)); #endif #if defined(PNG_INCH_CONVERSIONS_SUPPORTED) -PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch, + (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch, + (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch, (png_structp png_ptr, - png_infop info_ptr)); +PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch, + (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_FP_EXPORT(196, float, png_get_x_offset_inches, (png_structp png_ptr, - png_infop info_ptr)); +PNG_FP_EXPORT(196, float, png_get_x_offset_inches, + (png_const_structp png_ptr, png_const_infop info_ptr)); #ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed, - (png_structp png_ptr, png_infop info_ptr)); + (png_structp png_ptr, png_const_infop info_ptr)); #endif -PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_structp png_ptr, - png_infop info_ptr)); +PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structp png_ptr, + png_const_infop info_ptr)); #ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed, - (png_structp png_ptr, png_infop info_ptr)); + (png_structp png_ptr, png_const_infop info_ptr)); #endif # ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_structp png_ptr, - png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, +PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); # endif /* PNG_pHYs_SUPPORTED */ #endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ /* Added in libpng-1.4.0 */ #ifdef PNG_IO_STATE_SUPPORTED PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_structp png_ptr)); -PNG_EXPORT(200, png_const_bytep, png_get_io_chunk_name, (png_structp png_ptr)); +PNG_EXPORTA(200, png_const_bytep, png_get_io_chunk_name, + (png_structp png_ptr), PNG_DEPRECATED); +PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, + (png_const_structp png_ptr)); /* The flags returned by png_get_io_state() are the following: */ # define PNG_IO_NONE 0x0000 /* no I/O at this moment */ # define PNG_IO_READING 0x0001 /* currently reading */ @@ -2154,33 +2206,8 @@ (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \ (png_uint_32)32767) / (png_uint_32)65535L) #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ -#ifdef PNG_USE_READ_MACROS -/* Inline macros to do direct reads of bytes from the input buffer. - * The png_get_int_32() routine assumes we are using two's complement - * format for negative values, which is almost certainly true. - */ -# define png_get_uint_32(buf) \ - (((png_uint_32)(*(buf)) << 24) + \ - ((png_uint_32)(*((buf) + 1)) << 16) + \ - ((png_uint_32)(*((buf) + 2)) << 8) + \ - ((png_uint_32)(*((buf) + 3)))) - - /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the - * function) incorrectly returned a value of type png_uint_32. - */ -# define png_get_uint_16(buf) \ - ((png_uint_16) \ - (((unsigned int)(*(buf)) << 8) + \ - ((unsigned int)(*((buf) + 1))))) - -# define png_get_int_32(buf) \ - ((png_int_32)((*(buf) & 0x80) \ - ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \ - : (png_int_32)png_get_uint_32(buf))) -#endif - #ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf)); PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf)); PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf)); @@ -2206,17 +2233,43 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); /* No png_save_int_16 -- may be added if there's a real need for it. */ #endif +#ifdef PNG_USE_READ_MACROS +/* Inline macros to do direct reads of bytes from the input buffer. + * The png_get_int_32() routine assumes we are using two's complement + * format for negative values, which is almost certainly true. + */ +# define png_get_uint_32(buf) \ + (((png_uint_32)(*(buf)) << 24) + \ + ((png_uint_32)(*((buf) + 1)) << 16) + \ + ((png_uint_32)(*((buf) + 2)) << 8) + \ + ((png_uint_32)(*((buf) + 3)))) + + /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the + * function) incorrectly returned a value of type png_uint_32. + */ +# define png_get_uint_16(buf) \ + ((png_uint_16) \ + (((unsigned int)(*(buf)) << 8) + \ + ((unsigned int)(*((buf) + 1))))) + +# define png_get_int_32(buf) \ + ((png_int_32)((*(buf) & 0x80) \ + ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \ + : (png_int_32)png_get_uint_32(buf))) +#endif + /* Maintainer: Put new public prototypes here ^, in libpng.3, and project * defs */ /* The last ordinal number (this is the *last* one already used; the next - * one to use is one more than this.) + * one to use is one more than this.) Maintainer, remember to add an entry to + * scripts/symbols.def as well. */ #ifdef PNG_EXPORT_LAST_ORDINAL - PNG_EXPORT_LAST_ORDINAL(215); + PNG_EXPORT_LAST_ORDINAL(220); #endif #ifdef __cplusplus } diff -ru4NwbB libpng-1.5.0/pngerror.c libpng-1.5.1/pngerror.c --- libpng-1.5.0/pngerror.c 2011-01-22 16:39:23.161174716 -0600 +++ libpng-1.5.1/pngerror.c 2011-02-02 22:58:17.732911879 -0600 @@ -1,8 +1,8 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -422,9 +422,9 @@ * functions. The application should free any memory associated with this * pointer before png_write_destroy and png_read_destroy are called. */ png_voidp PNGAPI -png_get_error_ptr(png_structp png_ptr) +png_get_error_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return NULL; diff -ru4NwbB libpng-1.5.0/pngget.c libpng-1.5.1/pngget.c --- libpng-1.5.0/pngget.c 2011-01-22 16:39:23.168514822 -0600 +++ libpng-1.5.1/pngget.c 2011-02-02 22:58:17.740070723 -0600 @@ -1,8 +1,8 @@ /* pngget.c - retrieval of values from info struct * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -16,18 +16,19 @@ #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) png_uint_32 PNGAPI -png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) +png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_32 flag) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->valid & flag); return(0); } png_size_t PNGAPI -png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) +png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->rowbytes); @@ -35,9 +36,9 @@ } #ifdef PNG_INFO_IMAGE_SUPPORTED png_bytepp PNGAPI -png_get_rows(png_structp png_ptr, png_infop info_ptr) +png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->row_pointers); @@ -47,72 +48,72 @@ #ifdef PNG_EASY_ACCESS_SUPPORTED /* Easy access to info, added in libpng-0.99 */ png_uint_32 PNGAPI -png_get_image_width(png_structp png_ptr, png_infop info_ptr) +png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->width; return (0); } png_uint_32 PNGAPI -png_get_image_height(png_structp png_ptr, png_infop info_ptr) +png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->height; return (0); } png_byte PNGAPI -png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) +png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->bit_depth; return (0); } png_byte PNGAPI -png_get_color_type(png_structp png_ptr, png_infop info_ptr) +png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->color_type; return (0); } png_byte PNGAPI -png_get_filter_type(png_structp png_ptr, png_infop info_ptr) +png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->filter_type; return (0); } png_byte PNGAPI -png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) +png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->interlace_type; return (0); } png_byte PNGAPI -png_get_compression_type(png_structp png_ptr, png_infop info_ptr) +png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->compression_type; return (0); } png_uint_32 PNGAPI -png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_pHYs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) { @@ -127,9 +128,9 @@ return (0); } png_uint_32 PNGAPI -png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_pHYs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) { @@ -144,9 +145,9 @@ return (0); } png_uint_32 PNGAPI -png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_pHYs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) { @@ -162,9 +163,9 @@ } #ifdef PNG_FLOATING_POINT_SUPPORTED float PNGAPI -png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) +png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_READ_pHYs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) { @@ -181,9 +182,10 @@ #endif #ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point PNGAPI -png_get_pixel_aspect_ratio_fixed(png_structp png_ptr, png_infop info_ptr) +png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr, + png_const_infop info_ptr) { #ifdef PNG_READ_pHYs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 @@ -207,9 +209,9 @@ } #endif png_int_32 PNGAPI -png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) +png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_oFFs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) { @@ -223,9 +225,9 @@ return (0); } png_int_32 PNGAPI -png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) +png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_oFFs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) { @@ -239,9 +241,9 @@ return (0); } png_int_32 PNGAPI -png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) +png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_oFFs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) { @@ -255,9 +257,9 @@ return (0); } png_int_32 PNGAPI -png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) +png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) { #ifdef PNG_oFFs_SUPPORTED if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) { @@ -304,21 +306,21 @@ #endif } png_uint_32 PNGAPI -png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) { return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); } png_uint_32 PNGAPI -png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) { return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); } png_uint_32 PNGAPI -png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) { return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); } @@ -334,27 +336,29 @@ return png_muldiv_warn(png_ptr, microns, 500, 127); } png_fixed_point PNGAPI -png_get_x_offset_inches_fixed(png_structp png_ptr, png_infop info_ptr) +png_get_x_offset_inches_fixed(png_structp png_ptr, + png_const_infop info_ptr) { return png_fixed_inches_from_microns(png_ptr, png_get_x_offset_microns(png_ptr, info_ptr)); } #endif #ifdef PNG_FIXED_POINT_SUPPORTED png_fixed_point PNGAPI -png_get_y_offset_inches_fixed(png_structp png_ptr, png_infop info_ptr) +png_get_y_offset_inches_fixed(png_structp png_ptr, + png_const_infop info_ptr) { return png_fixed_inches_from_microns(png_ptr, png_get_y_offset_microns(png_ptr, info_ptr)); } #endif #ifdef PNG_FLOATING_POINT_SUPPORTED float PNGAPI -png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) +png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) { /* To avoid the overflow do the conversion directly in floating * point. */ @@ -363,9 +367,9 @@ #endif #ifdef PNG_FLOATING_POINT_SUPPORTED float PNGAPI -png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) +png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) { /* To avoid the overflow do the conversion directly in floating * point. */ @@ -374,9 +378,9 @@ #endif #ifdef PNG_pHYs_SUPPORTED png_uint_32 PNGAPI -png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, +png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) { png_uint_32 retval = 0; @@ -418,18 +422,18 @@ #endif /* PNG_EASY_ACCESS_SUPPORTED */ png_byte PNGAPI -png_get_channels(png_structp png_ptr, png_infop info_ptr) +png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->channels); return (0); } png_const_bytep PNGAPI -png_get_signature(png_structp png_ptr, png_infop info_ptr) +png_get_signature(png_const_structp png_ptr, png_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->signature); @@ -437,9 +441,9 @@ } #ifdef PNG_bKGD_SUPPORTED png_uint_32 PNGAPI -png_get_bKGD(png_structp png_ptr, png_infop info_ptr, +png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr, png_color_16p *background) { if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) && background != NULL) @@ -456,9 +460,9 @@ #ifdef PNG_cHRM_SUPPORTED # ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_cHRM(png_structp png_ptr, png_infop info_ptr, +png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, double *blue_y) { if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) @@ -489,9 +493,9 @@ # endif # ifdef PNG_FIXED_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, +png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr, png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, png_fixed_point *blue_x, png_fixed_point *blue_y) { @@ -524,9 +528,9 @@ #endif #ifdef PNG_gAMA_SUPPORTED png_uint_32 PNGFAPI -png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, +png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr, png_fixed_point *file_gamma) { png_debug1(1, "in %s retrieval function", "gAMA"); @@ -540,9 +544,10 @@ return (0); } # ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) +png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr, + double *file_gamma) { png_fixed_point igamma; png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma); @@ -556,9 +561,10 @@ #endif #ifdef PNG_sRGB_SUPPORTED png_uint_32 PNGAPI -png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) +png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr, + int *file_srgb_intent) { png_debug1(1, "in %s retrieval function", "sRGB"); if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) @@ -573,9 +579,9 @@ #endif #ifdef PNG_iCCP_SUPPORTED png_uint_32 PNGAPI -png_get_iCCP(png_structp png_ptr, png_infop info_ptr, +png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr, png_charpp name, int *compression_type, png_bytepp profile, png_uint_32 *proflen) { png_debug1(1, "in %s retrieval function", "iCCP"); @@ -598,9 +604,9 @@ #endif #ifdef PNG_sPLT_SUPPORTED png_uint_32 PNGAPI -png_get_sPLT(png_structp png_ptr, png_infop info_ptr, +png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr, png_sPLT_tpp spalettes) { if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) { @@ -613,9 +619,10 @@ #endif #ifdef PNG_hIST_SUPPORTED png_uint_32 PNGAPI -png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) +png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_16p *hist) { png_debug1(1, "in %s retrieval function", "hIST"); if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) @@ -669,9 +676,9 @@ } #ifdef PNG_oFFs_SUPPORTED png_uint_32 PNGAPI -png_get_oFFs(png_structp png_ptr, png_infop info_ptr, +png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) { png_debug1(1, "in %s retrieval function", "oFFs"); @@ -689,9 +696,9 @@ #endif #ifdef PNG_pCAL_SUPPORTED png_uint_32 PNGAPI -png_get_pCAL(png_structp png_ptr, png_infop info_ptr, +png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *units, png_charpp *params) { png_debug1(1, "in %s retrieval function", "pCAL"); @@ -717,9 +724,9 @@ #ifdef PNG_sCAL_SUPPORTED # ifdef PNG_FIXED_POINT_SUPPORTED # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED png_uint_32 PNGAPI -png_get_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, +png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr, int *unit, png_fixed_point *width, png_fixed_point *height) { if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) @@ -737,9 +744,9 @@ # endif /* FLOATING_ARITHMETIC */ # endif /* FIXED_POINT */ # ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_sCAL(png_structp png_ptr, png_infop info_ptr, +png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr, int *unit, double *width, double *height) { if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) @@ -753,9 +760,9 @@ return(0); } # endif /* FLOATING POINT */ png_uint_32 PNGAPI -png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, +png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr, int *unit, png_charpp width, png_charpp height) { if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) @@ -771,9 +778,9 @@ #endif /* sCAL */ #ifdef PNG_pHYs_SUPPORTED png_uint_32 PNGAPI -png_get_pHYs(png_structp png_ptr, png_infop info_ptr, +png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) { png_uint_32 retval = 0; @@ -805,10 +812,10 @@ } #endif /* pHYs */ png_uint_32 PNGAPI -png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, - int *num_palette) +png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr, + png_colorp *palette, int *num_palette) { png_debug1(1, "in %s retrieval function", "PLTE"); if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) @@ -824,9 +831,10 @@ } #ifdef PNG_sBIT_SUPPORTED png_uint_32 PNGAPI -png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) +png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr, + png_color_8p *sig_bit) { png_debug1(1, "in %s retrieval function", "sBIT"); if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) @@ -841,10 +849,10 @@ #endif #ifdef PNG_TEXT_SUPPORTED png_uint_32 PNGAPI -png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, - int *num_text) +png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, + png_textp *text_ptr, int *num_text) { if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) { png_debug1(1, "in %s retrieval function", @@ -868,9 +876,9 @@ #endif #ifdef PNG_tIME_SUPPORTED png_uint_32 PNGAPI -png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) +png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time) { png_debug1(1, "in %s retrieval function", "tIME"); if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) @@ -885,9 +893,9 @@ #endif #ifdef PNG_tRNS_SUPPORTED png_uint_32 PNGAPI -png_get_tRNS(png_structp png_ptr, png_infop info_ptr, +png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr, png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) { png_uint_32 retval = 0; if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) @@ -930,9 +938,9 @@ #endif #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED int PNGAPI -png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, +png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr, png_unknown_chunkpp unknowns) { if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) { @@ -945,24 +953,24 @@ #endif #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED png_byte PNGAPI -png_get_rgb_to_gray_status (png_structp png_ptr) +png_get_rgb_to_gray_status (png_const_structp png_ptr) { return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); } #endif #ifdef PNG_USER_CHUNKS_SUPPORTED png_voidp PNGAPI -png_get_user_chunk_ptr(png_structp png_ptr) +png_get_user_chunk_ptr(png_const_structp png_ptr) { return (png_ptr ? png_ptr->user_chunk_ptr : NULL); } #endif png_size_t PNGAPI -png_get_compression_buffer_size(png_structp png_ptr) +png_get_compression_buffer_size(png_const_structp png_ptr) { return (png_ptr ? png_ptr->zbuf_size : 0L); } @@ -970,29 +978,29 @@ #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* These functions were added to libpng 1.2.6 and were enabled * by default in libpng-1.4.0 */ png_uint_32 PNGAPI -png_get_user_width_max (png_structp png_ptr) +png_get_user_width_max (png_const_structp png_ptr) { return (png_ptr ? png_ptr->user_width_max : 0); } png_uint_32 PNGAPI -png_get_user_height_max (png_structp png_ptr) +png_get_user_height_max (png_const_structp png_ptr) { return (png_ptr ? png_ptr->user_height_max : 0); } /* This function was added to libpng 1.4.0 */ png_uint_32 PNGAPI -png_get_chunk_cache_max (png_structp png_ptr) +png_get_chunk_cache_max (png_const_structp png_ptr) { return (png_ptr ? png_ptr->user_chunk_cache_max : 0); } /* This function was added to libpng 1.4.1 */ png_alloc_size_t PNGAPI -png_get_chunk_malloc_max (png_structp png_ptr) +png_get_chunk_malloc_max (png_const_structp png_ptr) { return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); } #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ @@ -1004,8 +1012,17 @@ { return png_ptr->io_state; } +png_uint_32 PNGAPI +png_get_io_chunk_type (png_const_structp png_ptr) +{ + return ((png_ptr->chunk_name[0] << 24) + + (png_ptr->chunk_name[1] << 16) + + (png_ptr->chunk_name[2] << 8) + + (png_ptr->chunk_name[3])); +} + png_const_bytep PNGAPI png_get_io_chunk_name (png_structp png_ptr) { return png_ptr->chunk_name; diff -ru4NwbB libpng-1.5.0/pngmem.c libpng-1.5.1/pngmem.c --- libpng-1.5.0/pngmem.c 2011-01-22 16:39:23.174837039 -0600 +++ libpng-1.5.1/pngmem.c 2011-02-02 22:58:17.746290285 -0600 @@ -1,8 +1,8 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -646,9 +646,9 @@ * functions. The application should free any memory associated with this * pointer before png_write_destroy and png_read_destroy are called. */ png_voidp PNGAPI -png_get_mem_ptr(png_structp png_ptr) +png_get_mem_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return (NULL); diff -ru4NwbB libpng-1.5.0/pngpread.c libpng-1.5.1/pngpread.c --- libpng-1.5.0/pngpread.c 2011-01-22 16:39:23.183892689 -0600 +++ libpng-1.5.1/pngpread.c 2011-02-02 22:58:17.755135954 -0600 @@ -1,8 +1,8 @@ /* pngpread.c - read a png file in push mode * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -40,8 +40,66 @@ png_process_some_data(png_ptr, info_ptr); } } +png_size_t PNGAPI +png_process_data_pause(png_structp png_ptr, int save) +{ + if (png_ptr != NULL) + { + /* It's easiest for the caller if we do the save, then the caller doesn't + * have to supply the same data again: + */ + if (save) + png_push_save_buffer(png_ptr); + else + { + /* This includes any pending saved bytes: */ + png_size_t remaining = png_ptr->buffer_size; + png_ptr->buffer_size = 0; + + /* So subtract the saved buffer size, unless all the data + * is actually 'saved', in which case we just return 0 + */ + if (png_ptr->save_buffer_size < remaining) + return remaining - png_ptr->save_buffer_size; + } + } + + return 0; +} + +png_uint_32 PNGAPI +png_process_data_skip(png_structp png_ptr) +{ + png_uint_32 remaining = 0; + + if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE && + png_ptr->skip_length > 0) + { + /* At the end of png_process_data the buffer size must be 0 (see the loop + * above) so we can detect a broken call here: + */ + if (png_ptr->buffer_size != 0) + png_error(png_ptr, + "png_process_data_skip called inside png_process_data"); + + /* If is impossible for there to be a saved buffer at this point - + * otherwise we could not be in SKIP mode. This will also happen if + * png_process_skip is called inside png_process_data (but only very + * rarely.) + */ + if (png_ptr->save_buffer_size != 0) + png_error(png_ptr, "png_process_data_skip called with saved data"); + + remaining = png_ptr->skip_length; + png_ptr->skip_length = 0; + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } + + return remaining; +} + /* What we do with the incoming data depends on what we were previously * doing before we ran out of data... */ void /* PRIVATE */ @@ -581,12 +639,12 @@ png_push_crc_finish(png_structp png_ptr) { if (png_ptr->skip_length && png_ptr->save_buffer_size) { - png_size_t save_size = png_ptr->current_buffer_size; + png_size_t save_size = png_ptr->save_buffer_size; png_uint_32 skip_length = png_ptr->skip_length; - /* We want the smaller of 'skip_length' and 'current_buffer_size', but + /* We want the smaller of 'skip_length' and 'save_buffer_size', but * they are of different types and we don't know which variable has the * fewest bits. Carefully select the smaller and cast it to the type of * the larger - this cannot overflow. Do not cast in the following test * - it will break on either 16 or 64 bit platforms. @@ -608,12 +666,10 @@ { png_size_t save_size = png_ptr->current_buffer_size; png_uint_32 skip_length = png_ptr->skip_length; - /* We want the smaller of 'skip_length' and 'current_buffer_size', but - * they are of different types and we don't know which variable has the - * fewest bits. Carefully select the smaller and cast it to the type of - * the larger - this cannot overflow. + /* We want the smaller of 'skip_length' and 'current_buffer_size', here, + * the same problem exists as above and the same solution. */ if (skip_length < save_size) save_size = (png_size_t)skip_length; @@ -1787,9 +1843,9 @@ png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); } png_voidp PNGAPI -png_get_progressive_ptr(png_structp png_ptr) +png_get_progressive_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return (NULL); diff -ru4NwbB libpng-1.5.0/pngpriv.h libpng-1.5.1/pngpriv.h --- libpng-1.5.0/pngpriv.h 2011-01-22 16:39:23.120149242 -0600 +++ libpng-1.5.1/pngpriv.h 2011-02-02 22:58:17.694499401 -0600 @@ -82,16 +82,15 @@ #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) # define PNG_MAX_MALLOC_64K #endif -/* Unused formal parameter errors are removed using the following macro - * which is expected to have no bad effects on performance. Note that - * if you replace it with something other than whitespace, you must include - * the terminating semicolon. +/* Unused formal parameter warnings are silenced using the following macro + * which is expected to have no bad effects on performance (optimizing + * compilers will probably remove it entirely). Note that if you replace + * it with something other than whitespace, you must include the terminating + * semicolon. */ -#ifndef PNG_UNUSED -# define PNG_UNUSED(param) param = param; -#endif +#define PNG_UNUSED(param) (void)param; /* Just a little check that someone hasn't tried to define something * contradictory. */ diff -ru4NwbB libpng-1.5.0/pngread.c libpng-1.5.1/pngread.c --- libpng-1.5.0/pngread.c 2011-01-22 16:39:23.192040561 -0600 +++ libpng-1.5.1/pngread.c 2011-02-02 22:58:17.763092690 -0600 @@ -1,8 +1,8 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [$RDATE%] * Copyright (c) 1998-2011 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.) * @@ -840,9 +840,9 @@ png_start_read_image(png_ptr); } else { - if (!(png_ptr->transformations & PNG_INTERLACE)) + if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE)) { /* Caller called png_start_read_image or png_read_update_info without * first turning on the PNG_INTERLACE transform. We can fix this here, * but the caller should do it! diff -ru4NwbB libpng-1.5.0/pngrtran.c libpng-1.5.1/pngrtran.c --- libpng-1.5.0/pngrtran.c 2011-01-22 16:39:23.212597981 -0600 +++ libpng-1.5.1/pngrtran.c 2011-02-02 22:58:17.782646907 -0600 @@ -1,8 +1,8 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -691,11 +691,16 @@ png_set_gray_to_rgb(png_structp png_ptr) { png_debug(1, "in png_set_gray_to_rgb"); + if (png_ptr != NULL) + { + /* Because rgb must be 8 bits or more: */ + png_set_expand_gray_1_2_4_to_8(png_ptr); png_ptr->transformations |= PNG_GRAY_TO_RGB; png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } +} #endif #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED void PNGFAPI @@ -2426,9 +2431,9 @@ int rgb_error = 0; png_debug(1, "in png_do_rgb_to_gray"); - if ( + if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) && (row_info->color_type & PNG_COLOR_MASK_COLOR)) { png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; @@ -3777,9 +3782,9 @@ row_info->pixel_depth = 8; row_info->rowbytes = row_width; } - else if (row_info->bit_depth == 8) + if (row_info->bit_depth == 8) { { if (trans_alpha != NULL) { diff -ru4NwbB libpng-1.5.0/pngrutil.c libpng-1.5.1/pngrutil.c --- libpng-1.5.0/pngrutil.c 2011-01-22 16:39:23.226783299 -0600 +++ libpng-1.5.1/pngrutil.c 2011-02-02 22:58:17.796148619 -0600 @@ -1,8 +1,8 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -607,9 +607,9 @@ png_ptr->channels); png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); png_debug1(3, "channels = %d", png_ptr->channels); - png_debug1(3, "rowbytes = %u", png_ptr->rowbytes); + png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes); png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, interlace_type, compression_type, filter_type); } @@ -1247,9 +1247,11 @@ char umsg[80]; png_snprintf2(umsg, 80, "Ignoring iCCP chunk with declared size = %u " - "and actual length = %u", profile_size, profile_length); + "and actual length = %u", + (unsigned int) profile_size, + (unsigned int) profile_length); png_warning(png_ptr, umsg); } #else png_warning(png_ptr, @@ -1959,9 +1961,9 @@ /* Read the sCAL chunk */ void /* PRIVATE */ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { - png_size_t slength, index; + png_size_t slength, i; int state; png_debug(1, "in png_handle_sCAL"); @@ -2016,23 +2018,23 @@ /* Validate the ASCII numbers, need two ASCII numbers separated by * a '\0' and they need to fit exactly in the chunk data. */ - index = 0; + i = 0; state = 0; if (png_ptr->chunkdata[1] == 45 /* negative width */ || - !png_check_fp_number(png_ptr->chunkdata, slength, &state, &index) || - index >= slength || png_ptr->chunkdata[index++] != 0) + !png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || + i >= slength || png_ptr->chunkdata[i++] != 0) png_warning(png_ptr, "Invalid sCAL chunk ignored: bad width format"); else { - png_size_t heighti = index; + png_size_t heighti = i; - if (png_ptr->chunkdata[index] == 45 /* negative height */ || - !png_check_fp_number(png_ptr->chunkdata, slength, &state, &index) || - index != slength) + if (png_ptr->chunkdata[i] == 45 /* negative height */ || + !png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || + i != slength) png_warning(png_ptr, "Invalid sCAL chunk ignored: bad height format"); else /* This is the (only) success case. */ @@ -3604,11 +3606,11 @@ png_debug1(3, "width = %u,", png_ptr->width); png_debug1(3, "height = %u,", png_ptr->height); png_debug1(3, "iwidth = %u,", png_ptr->iwidth); png_debug1(3, "num_rows = %u,", png_ptr->num_rows); - png_debug1(3, "rowbytes = %u,", png_ptr->rowbytes); - png_debug1(3, "irowbytes = %u", - PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); + png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes); + png_debug1(3, "irowbytes = %lu", + (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); png_ptr->flags |= PNG_FLAG_ROW_INIT; } #endif /* PNG_READ_SUPPORTED */ diff -ru4NwbB libpng-1.5.0/pngset.c libpng-1.5.1/pngset.c --- libpng-1.5.0/pngset.c 2011-01-22 16:39:23.235075862 -0600 +++ libpng-1.5.1/pngset.c 2011-02-02 22:58:17.804187237 -0600 @@ -1,8 +1,8 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -86,9 +86,9 @@ #ifdef PNG_gAMA_SUPPORTED void PNGFAPI png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point - gamma) + file_gamma) { png_debug1(1, "in %s storage function", "gAMA"); if (png_ptr == NULL || info_ptr == NULL) @@ -97,17 +97,17 @@ /* Previously these values were limited, however they must be * wrong, therefore storing them (and setting PNG_INFO_gAMA) * must be wrong too. */ - if (gamma > (png_fixed_point)PNG_UINT_31_MAX) + if (file_gamma > (png_fixed_point)PNG_UINT_31_MAX) png_warning(png_ptr, "Gamma too large, ignored"); - else if (gamma <= 0) + else if (file_gamma <= 0) png_warning(png_ptr, "Negative or zero gamma ignored"); else { - info_ptr->gamma = gamma; + info_ptr->gamma = file_gamma; info_ptr->valid |= PNG_INFO_gAMA; } } @@ -351,9 +351,9 @@ info_ptr->scal_unit = (png_byte)unit; ++lengthw; - png_debug1(3, "allocating unit for info (%u bytes)", lengthw); + png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, lengthw); if (info_ptr->scal_s_width == NULL) @@ -365,9 +365,9 @@ png_memcpy(info_ptr->scal_s_width, swidth, lengthw); ++lengthh; - png_debug1(3, "allocating unit for info (%u bytes)", lengthh); + png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, lengthh); if (info_ptr->scal_s_height == NULL) @@ -521,29 +521,29 @@ #endif #ifdef PNG_sRGB_SUPPORTED void PNGAPI -png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) +png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int srgb_intent) { png_debug1(1, "in %s storage function", "sRGB"); if (png_ptr == NULL || info_ptr == NULL) return; - info_ptr->srgb_intent = (png_byte)intent; + info_ptr->srgb_intent = (png_byte)srgb_intent; info_ptr->valid |= PNG_INFO_sRGB; } void PNGAPI png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, - int intent) + int srgb_intent) { png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); if (png_ptr == NULL || info_ptr == NULL) return; - png_set_sRGB(png_ptr, info_ptr, intent); + png_set_sRGB(png_ptr, info_ptr, srgb_intent); # ifdef PNG_gAMA_SUPPORTED png_set_gAMA_fixed(png_ptr, info_ptr, 45455L); # endif @@ -750,12 +750,12 @@ if (textp->key == NULL) return(1); - png_debug2(2, "Allocated %lu bytes at %x in png_set_text", + png_debug2(2, "Allocated %lu bytes at %p in png_set_text", (unsigned long)(png_uint_32) (key_len + lang_len + lang_key_len + text_length + 4), - (int)textp->key); + textp->key); png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len)); *(textp->key + key_len) = '\0'; diff -ru4NwbB libpng-1.5.0/pngtrans.c libpng-1.5.1/pngtrans.c --- libpng-1.5.0/pngtrans.c 2011-01-22 16:39:23.251076592 -0600 +++ libpng-1.5.1/pngtrans.c 2011-02-02 22:58:17.819661451 -0600 @@ -1,8 +1,8 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -671,43 +671,53 @@ #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED void PNGAPI png_set_user_transform_info(png_structp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels) { png_debug(1, "in png_set_user_transform_info"); if (png_ptr == NULL) return; -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED png_ptr->user_transform_ptr = user_transform_ptr; png_ptr->user_transform_depth = (png_byte)user_transform_depth; png_ptr->user_transform_channels = (png_byte)user_transform_channels; -#else - if (user_transform_ptr || user_transform_depth || user_transform_channels) - png_warning(png_ptr, - "This version of libpng does not support user transform info"); -#endif } +#endif /* This function returns a pointer to the user_transform_ptr associated with * the user transform functions. The application should free any memory * associated with this pointer before png_write_destroy and png_read_destroy * are called. */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED png_voidp PNGAPI -png_get_user_transform_ptr(png_structp png_ptr) +png_get_user_transform_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return (NULL); -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED return ((png_voidp)png_ptr->user_transform_ptr); -#else - return (NULL); +} #endif + +png_uint_32 PNGAPI +png_get_current_row_number(png_const_structp png_ptr) +{ + if (png_ptr != NULL) + return png_ptr->row_number; + return PNG_UINT_32_MAX; /* help the app not to fail silently */ +} + +png_byte PNGAPI +png_get_current_pass_number(png_const_structp png_ptr) +{ + if (png_ptr != NULL) + return png_ptr->pass; + return 8; /* invalid */ } #endif /* PNG_READ_USER_TRANSFORM_SUPPORTED || PNG_WRITE_USER_TRANSFORM_SUPPORTED */ #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff -ru4NwbB libpng-1.5.0/pngvalid.c libpng-1.5.1/pngvalid.c --- libpng-1.5.0/pngvalid.c 2011-01-22 16:39:23.266763948 -0600 +++ libpng-1.5.1/pngvalid.c 2011-02-02 22:58:17.839843080 -0600 @@ -1,8 +1,8 @@ /* pngvalid.c - validate libpng by constructing then reading png files. * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 2011 Glenn Randers-Pehrson * Written by John Cunningham Bowler * * This code is released under the libpng license. @@ -19,19 +19,55 @@ * transformations performed by libpng. */ #include "png.h" +#if PNG_LIBPNG_VER < 10500 +/* This delibarately lacks the PNG_CONST. */ +typedef png_byte *png_const_bytep; + +/* This is copied from 1.5.1 png.h: */ +#define PNG_INTERLACE_ADAM7_PASSES 7 +#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7) +#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7) +#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3) +#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3) +#define PNG_PASS_ROWS(height, pass) (((height)+(((1<>PNG_PASS_ROW_SHIFT(pass)) +#define PNG_PASS_COLS(width, pass) (((width)+(((1<>PNG_PASS_COL_SHIFT(pass)) +#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \ + (((yIn)<>(((7-(off))-(pass))<<2)) & 0xFU) | \ + ((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U)) +#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \ + ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1) +#define PNG_COL_IN_INTERLACE_PASS(x, pass) \ + ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1) + +/* These are needed too for the defualt build: */ +#define PNG_WRITE_16BIT_SUPPORTED +#define PNG_READ_16BIT_SUPPORTED +#endif + #include "zlib.h" /* For crc32 */ +#include /* For floating point constants */ #include /* For malloc */ #include /* For memcpy, memset */ #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; +# if defined(__GNUC__) || defined(_MSC_VER) +# define UNUSED(param) (void)param; +# else +# define UNUSED(param) +# endif #endif /***************************** EXCEPTION HANDLING *****************************/ #include "contrib/visupng/cexcept.h" @@ -237,27 +273,30 @@ } static unsigned int sample(png_const_bytep row, png_byte colour_type, png_byte bit_depth, - png_uint_32 x, unsigned int sample) + png_uint_32 x, unsigned int sample_index) { - png_uint_32 index, result; + png_uint_32 bit_index, result; /* Find a sample index for the desired sample: */ x *= bit_depth; - index = x; + bit_index = x; if ((colour_type & 1) == 0) /* !palette */ { if (colour_type & 2) - index *= 3, index += sample; /* Colour channels; select one */ + bit_index *= 3; if (colour_type & 4) - index += x; /* Alpha channel */ + bit_index += x; /* Alpha channel */ + + if (colour_type & (2+4)) + bit_index += sample_index * bit_depth; /* Multiple channels: select one */ } /* Return the sample from the row as an integer. */ - row += index >> 3; + row += bit_index >> 3; result = *row; if (bit_depth == 8) return result; @@ -265,10 +304,10 @@ else if (bit_depth > 8) return (result << 8) + *++row; /* Less than 8 bits per sample. */ - index &= 7; - return (result >> (8-index-bit_depth)) & ((1U<> (8-bit_index-bit_depth)) & ((1U<maxout16 = pm->maxpc16 = pm->maxabs16 = 0; pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0; pm->error_gray_16 = pm->error_color_8 = pm->error_color_16 = 0; pm->interlace_type = PNG_INTERLACE_NONE; - pm->test_standard = 1; + pm->test_standard = 0; pm->test_size = 0; + pm->test_transform = 0; pm->use_input_precision = 0; pm->use_input_precision_sbit = 0; pm->use_input_precision_16to8 = 0; - pm->test_threshold = 1; - pm->test_transform = 1; - pm->test_sbit = 1; - pm->test_strip16 = 1; + pm->test_gamma_threshold = 0; + pm->test_gamma_transform = 0; + pm->test_gamma_sbit = 0; + pm->test_gamma_strip16 = 0; pm->log = 0; /* Rely on the memset for all the other fields - there are no pointers */ } @@ -1874,9 +1937,9 @@ static png_uint_32 standard_width(png_structp pp, png_uint_32 id) { png_uint_32 width = WIDTH_FROM_ID(id); - UNUSED(pp); + UNUSED(pp) if (width == 0) width = transform_width(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id)); @@ -2489,8 +2552,10 @@ /* Time for a few errors, these are in various optional chunks, the * standard tests test the standard chunks pretty well. */ +# define exception__prev exception_prev_1 +# define exception__env exception_env_1 Try { /* Expect this to throw: */ ps->expect_error = !error_test[test].warning; @@ -2512,8 +2577,10 @@ } Catch (fault) ps = fault; /* expected exit, make sure ps is not clobbered */ +#undef exception__prev +#undef exception__env /* And clear these flags */ ps->expect_error = 0; ps->expect_warning = 0; @@ -2636,13 +2703,25 @@ * same as the pointer to the structure. This allows us to reuse standard_ * functions in the gamma test code; something that could not be done with * nested funtions! */ +typedef struct standard_palette_entry /* pngvalid format palette! */ +{ + png_byte red; + png_byte green; + png_byte blue; + png_byte alpha; +} standard_palette[256]; + typedef struct standard_display { png_store* ps; /* Test parameters (passed to the function) */ png_byte colour_type; png_byte bit_depth; + png_byte red_sBIT; /* Input data sBIT values. */ + png_byte green_sBIT; + png_byte blue_sBIT; + png_byte alpha_sBIT; int interlace_type; png_uint_32 id; /* Calculated file ID */ png_uint_32 w; /* Width of image */ png_uint_32 h; /* Height of image */ @@ -2650,8 +2729,17 @@ png_uint_32 pixel_size; /* Width of one pixel in bits */ png_uint_32 bit_width; /* Width of output row in bits */ size_t cbRow; /* Bytes in a row of the output image */ int do_interlace; /* Do interlacing internally */ + int is_transparent; /* Transparecy information was present. */ + struct + { + png_uint_16 red; + png_uint_16 green; + png_uint_16 blue; + } transparent; /* The transparent color, if set. */ + standard_palette + palette; } standard_display; static void standard_display_init(standard_display *dp, png_store* ps, png_uint_32 id, @@ -2659,8 +2747,10 @@ { dp->ps = ps; dp->colour_type = COL_FROM_ID(id); dp->bit_depth = DEPTH_FROM_ID(id); + dp->alpha_sBIT = dp->blue_sBIT = dp->green_sBIT = dp->alpha_sBIT = + dp->bit_depth; dp->interlace_type = INTERLACE_FROM_ID(id); dp->id = id; /* All the rest are filled in after the read_info: */ dp->w = 0; @@ -2669,8 +2759,82 @@ dp->pixel_size = 0; dp->bit_width = 0; dp->cbRow = 0; dp->do_interlace = do_interlace; + dp->is_transparent = 0; + /* Preset the transparent color to black: */ + memset(&dp->transparent, 0, sizeof dp->transparent); + /* Preset the palette to full intensity/opaque througout: */ + memset(dp->palette, 0xff, sizeof dp->palette); + +} + +/* Call this only if the colour type is 3 - PNG_COLOR_TYPE_PALETTE - otherwise + * it will png_error out. The API returns true if tRNS information was + * present. + */ +static int +standard_palette_init(standard_palette palette, png_structp pp, png_infop pi) +{ + png_colorp pal; + png_bytep trans_alpha; + int num; + + pal = 0; + num = -1; + if (png_get_PLTE(pp, pi, &pal, &num) & PNG_INFO_PLTE) + { + int i; + + for (i=0; i 256) + png_error(pp, "validate: unexpected png_get_tRNS (palette) result"); + + for (i=0; ih != standard_height(pp, dp->id)) png_error(pp, "validate: image height changed"); + /* Record (but don't check at present) the input sBIT according to the colour + * type information. + */ + { + png_color_8p sBIT = 0; + + if (png_get_sBIT(pp, pi, &sBIT) & PNG_INFO_sBIT) + { + int sBIT_invalid = 0; + + if (sBIT == 0) + png_error(pp, "validate: unexpected png_get_sBIT result"); + + if (dp->colour_type & PNG_COLOR_MASK_COLOR) + { + if (sBIT->red == 0 || sBIT->red > dp->bit_depth) + sBIT_invalid = 1; + else + dp->red_sBIT = sBIT->red; + + if (sBIT->green == 0 || sBIT->green > dp->bit_depth) + sBIT_invalid = 1; + else + dp->green_sBIT = sBIT->green; + + if (sBIT->blue == 0 || sBIT->blue > dp->bit_depth) + sBIT_invalid = 1; + else + dp->blue_sBIT = sBIT->blue; + } + + else /* !COLOR */ + { + if (sBIT->gray == 0 || sBIT->gray > dp->bit_depth) + sBIT_invalid = 1; + else + dp->blue_sBIT = dp->green_sBIT = dp->red_sBIT = sBIT->gray; + } + + /* All 8 bits in tRNS for a palette image are significant - see the + * spec. + */ + if (dp->colour_type & PNG_COLOR_MASK_ALPHA) + { + if (sBIT->alpha == 0 || sBIT->alpha > dp->bit_depth) + sBIT_invalid = 1; + else + dp->alpha_sBIT = sBIT->alpha; + } + + if (sBIT_invalid) + png_error(pp, "validate: sBIT value out of range"); + } + } + /* Important: this is validating the value *before* any transforms have been * put in place. It doesn't matter for the standard tests, where there are * no transforms, but it does for other tests where rowbytes may change after * png_read_update_info. */ if (png_get_rowbytes(pp, pi) != standard_rowsize(pp, dp->id)) png_error(pp, "validate: row size changed"); - if (dp->colour_type == 3) /* palette */ - { - png_colorp pal; - int num; - - /* This could be passed in but isn't - the values set above when the - * standard images were made are just repeated here. + /* The palette is never read for non-palette images, even though it is valid + * - this could be changed. */ - if (png_get_PLTE(pp, pi, &pal, &num) & PNG_INFO_PLTE) + if (dp->colour_type == 3) /* palette */ { int i; - if (num != 256) - png_error(pp, "validate: color type 3 PLTE chunk size changed"); + dp->is_transparent = standard_palette_init(dp->palette, pp, pi); - for (i=0; ipalette[i].red != i || dp->palette[i].green != i || + dp->palette[i].blue != i) png_error(pp, "validate: color type 3 PLTE chunk changed"); } - else - png_error(pp, "validate: missing PLTE with color type 3"); + /* In any case always check for a tranparent color: */ + { + png_color_16p trans_color = 0; + + if (png_get_tRNS(pp, pi, 0, 0, &trans_color) & PNG_INFO_tRNS) + { + if (trans_color == 0) + png_error(pp, "validate: unexpected png_get_tRNS (color) result"); + + switch (dp->colour_type) + { + case 0: + dp->transparent.red = dp->transparent.green = dp->transparent.blue = + trans_color->gray; + dp->is_transparent = 1; + break; + + case 2: + dp->transparent.red = trans_color->red; + dp->transparent.green = trans_color->green; + dp->transparent.blue = trans_color->blue; + dp->is_transparent = 1; + break; + + case 3: + /* Not expected because it should result in the array case + * above. + */ + png_error(pp, "validate: unexpected png_get_tRNS result"); + break; + + default: + png_error(pp, "validate: invalid tRNS chunk with alpha image"); + } + } } /* Read the number of passes - expected to match the value used when * creating the image (interlaced or not). This has the side effect of @@ -2978,9 +3226,9 @@ standard_end(png_structp pp, png_infop pi) { standard_display *dp = png_get_progressive_ptr(pp); - UNUSED(pi); + UNUSED(pi) /* Validate the image - progressive reading only produces one variant for * interlaced images. */ @@ -3212,158 +3460,1719 @@ return; } -/********************************* GAMMA TESTS ********************************/ -/* Gamma test images. */ -typedef struct gamma_modification -{ - png_modification this; - png_fixed_point gamma; -} gamma_modification; +/******************************* TRANSFORM TESTS ******************************/ +/* A set of tests to validate libpng image transforms. The possibilities here + * are legion because the transforms can be combined in a combinatorial + * fashion. To deal with this some measure of restraint is required, otherwise + * the tests would take forever. + */ +typedef struct image_pixel +{ + /* A local (pngvalid) representation of a PNG pixel, in all its + * various forms. + */ + unsigned int red, green, blue, alpha; /* For non-palette images. */ + unsigned int palette_index; /* For a palette image. */ + png_byte colour_type; /* As in the spec. */ + png_byte bit_depth; /* Defines bit size in row */ + png_byte sample_depth; /* Scale of samples */ + int have_tRNS; /* tRNS chunk may need processing */ + + /* For checking the code calculates double precision floating point values + * along with an error value, accumulated from the transforms. Because an + * sBIT setting allows larger error bounds (indeed, by the spec, apparently + * up to just less than +/-1 in the scaled value) the *lowest* sBIT for each + * channel is stored. This sBIT value is folded in to the stored error value + * at the end of the application of the transforms to the pixel. + */ + double redf, greenf, bluef, alphaf; + double rede, greene, bluee, alphae; + png_byte red_sBIT, green_sBIT, blue_sBIT, alpha_sBIT; +} image_pixel; + +/* Shared utility function, see below. */ +static void +image_pixel_setf(image_pixel *this, unsigned int max) +{ + this->redf = this->red / (double)max; + this->greenf = this->green / (double)max; + this->bluef = this->blue / (double)max; + this->alphaf = this->alpha / (double)max; -static int -gamma_modify(png_modifier *pm, png_modification *me, int add) -{ - 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); - png_save_uint_32(pm->buffer+8, ((gamma_modification*)me)->gamma); - return 1; + if (this->red < max) + this->rede = this->redf * DBL_EPSILON; + else + this->rede = 0; + if (this->green < max) + this->greene = this->greenf * DBL_EPSILON; + else + this->greene = 0; + if (this->blue < max) + this->bluee = this->bluef * DBL_EPSILON; + else + this->bluee = 0; + if (this->alpha < max) + this->alphae = this->alphaf * DBL_EPSILON; + else + this->alphae = 0; } +/* Initialize the structure for the next pixel - call this before doing any + * transforms and call it for each pixel since all the fields may need to be + * reset. + */ static void -gamma_modification_init(gamma_modification *me, png_modifier *pm, double gamma) +image_pixel_init(image_pixel *this, png_const_bytep row, png_byte colour_type, + png_byte bit_depth, png_uint_32 x, standard_palette palette) { - double g; + PNG_CONST png_byte sample_depth = (png_byte)(colour_type == + PNG_COLOR_TYPE_PALETTE ? 8 : bit_depth); + PNG_CONST unsigned int max = (1U<this); - me->this.chunk = CHUNK_gAMA; - me->this.modify_fn = gamma_modify; - me->this.add = CHUNK_PLTE; - g = floor(gamma * 100000 + .5); - me->gamma = (png_fixed_point)g; - me->this.next = pm->modifications; - pm->modifications = &me->this; + /* Initially just set everything to the same number and the alpha to opaque. + * Note that this currently assumes a simple palette where entry x has colour + * rgb(x,x,x)! + */ + this->palette_index = this->red = this->green = this->blue = + sample(row, colour_type, bit_depth, x, 0); + this->alpha = max; + this->red_sBIT = this->green_sBIT = this->blue_sBIT = this->alpha_sBIT = + sample_depth; + + /* Then override as appropriate: */ + if (colour_type == 3) /* palette */ + { + /* This permits the caller to default to the sample value. */ + if (palette != 0) + { + PNG_CONST unsigned int i = this->palette_index; + + this->red = palette[i].red; + this->green = palette[i].green; + this->blue = palette[i].blue; + this->alpha = palette[i].alpha; + } } -typedef struct srgb_modification + else /* not palette */ { - png_modification this; - png_byte intent; -} srgb_modification; + unsigned int i = 0; -static int -srgb_modify(png_modifier *pm, png_modification *me, int add) + if (colour_type & 2) { - 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); - pm->buffer[8] = ((srgb_modification*)me)->intent; - return 1; + this->green = sample(row, colour_type, bit_depth, x, 1); + this->blue = sample(row, colour_type, bit_depth, x, 2); + i = 2; } + if (colour_type & 4) + this->alpha = sample(row, colour_type, bit_depth, x, ++i); + } + + /* Calculate the scaled values, these are simply the values divided by + * 'max' and the error is initialized to the double precision epsilon value + * from the header file. + */ + image_pixel_setf(this, max); + /* Store the input information for use in the transforms - these will + * modify the information. + */ + this->colour_type = colour_type; + this->bit_depth = bit_depth; + this->sample_depth = sample_depth; + this->have_tRNS = 0; +} + +/* Convert a palette image to an rgb image. This necessarily converts the tRNS + * chunk at the same time, because the tRNS will be in palette form. + */ static void -srgb_modification_init(srgb_modification *me, png_modifier *pm, png_byte intent) +image_pixel_convert_PLTE(image_pixel *this, const standard_display *display) { - modification_init(&me->this); - me->this.chunk = CHUNK_sBIT; + if (this->colour_type == PNG_COLOR_TYPE_PALETTE) + { + PNG_CONST unsigned int i = this->palette_index; - if (intent <= 3) /* if valid, else *delete* sRGB chunks */ + this->bit_depth = this->sample_depth; + this->red = display->palette[i].red; + this->green = display->palette[i].green; + this->blue = display->palette[i].blue; + this->red_sBIT = display->red_sBIT; + this->green_sBIT = display->green_sBIT; + this->blue_sBIT = display->blue_sBIT; + + if (this->have_tRNS) { - me->this.modify_fn = srgb_modify; - me->this.add = CHUNK_PLTE; - me->intent = intent; + this->alpha = display->palette[i].alpha; + this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA; + this->have_tRNS = 0; } - else { - me->this.modify_fn = 0; - me->this.add = 0; - me->intent = 0; + this->alpha = 255; + this->colour_type = PNG_COLOR_TYPE_RGB; } + this->alpha_sBIT = 8; - me->this.next = pm->modifications; - pm->modifications = &me->this; + /* And regenerate the scaled values and all the errors, which are now set + * back to the initial values. + */ + image_pixel_setf(this, 255); + } } -typedef struct sbit_modification +/* Add an alpha channel, this will glom in the tRNS information because tRNS is + * not valid in an alpha image. The bit depth will invariably be set to at + * least 8. Palette images will be converted to alpha (using the above API). + */ +static void +image_pixel_add_alpha(image_pixel *this, const standard_display *display) { - png_modification this; - png_byte sbit; -} sbit_modification; + if (this->colour_type == PNG_COLOR_TYPE_PALETTE) + image_pixel_convert_PLTE(this, display); -static int -sbit_modify(png_modifier *pm, png_modification *me, int add) -{ - png_byte sbit = ((sbit_modification*)me)->sbit; - if (pm->bit_depth > sbit) + if ((this->colour_type & PNG_COLOR_MASK_ALPHA) == 0) { - int cb = 0; - switch (pm->colour_type) + if (this->colour_type == PNG_COLOR_TYPE_GRAY) { - case 0: - cb = 1; - break; - - case 2: - case 3: - cb = 3; - break; + if (this->bit_depth < 8) + this->bit_depth = 8; - case 4: - cb = 2; - break; + if (this->have_tRNS) + { + this->have_tRNS = 0; - case 6: - cb = 4; - break; + /* Check the input, original, channel value here against the + * original tRNS gray chunk valie. + */ + if (this->red == display->transparent.red) + this->alphaf = 0; + else + this->alphaf = 1; + } + else + this->alphaf = 1; - default: - png_error(pm->this.pread, - "unexpected colour type in sBIT modification"); + this->colour_type = PNG_COLOR_TYPE_GRAY_ALPHA; } - png_save_uint_32(pm->buffer, cb); - png_save_uint_32(pm->buffer+4, CHUNK_sBIT); + else if (this->colour_type == PNG_COLOR_TYPE_RGB) + { + if (this->have_tRNS) + { + this->have_tRNS = 0; - while (cb > 0) - (pm->buffer+8)[--cb] = sbit; + /* Again, check the exact input values, not the current transformed + * value! + */ + if (this->red == display->transparent.red && + this->green == display->transparent.green && + this->blue == display->transparent.blue) + this->alphaf = 0; + else + this->alphaf = 1; - return 1; - } - else if (!add) - { - /* Remove the sBIT chunk */ - pm->buffer_count = pm->buffer_position = 0; - return 1; + this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA; } - else - return 0; /* do nothing */ } -static void -sbit_modification_init(sbit_modification *me, png_modifier *pm, png_byte sbit) -{ - modification_init(&me->this); - me->this.chunk = CHUNK_sBIT; - me->this.modify_fn = sbit_modify; - me->this.add = CHUNK_PLTE; - me->sbit = sbit; - me->this.next = pm->modifications; - pm->modifications = &me->this; + /* The error in the alpha is zero and the sBIT value comes from the + * original sBIT data (actually it will always be the original bit depth). + */ + this->alphae = 0; + this->alpha_sBIT = display->alpha_sBIT; + } } -/* Reader callbacks and implementations, where they differ from the standard - * ones. - */ -typedef struct gamma_display +struct transform_display; +typedef struct image_transform { - standard_display this; + /* The name of this transform: a string. */ + PNG_CONST char *name; - /* Parameters */ + /* Each transform can be disabled from the command line: */ + int enable; + + /* The global list of transforms; read only. */ + struct image_transform *PNG_CONST list; + + /* The global count of the number of times this transform has been set on an + * image. + */ + unsigned int global_use; + + /* The local count of the number of times this transform has been set. */ + unsigned int local_use; + + /* The next transform in the list, each transform must call its own next + * transform after it has processed the pixel successfully. + */ + PNG_CONST struct image_transform *next; + + /* A single transform for the image, expressed as a series of function + * callbacks and some space for values. + * + * First a callback to set the transform on the current png_read_struct: + */ + void (*set)(PNG_CONST struct image_transform *this, + struct transform_display *that, png_structp pp, png_infop pi); + + /* Then a transform that takes an input pixel in one PNG format or another + * and modifies it by a pngvalid implementation of the transform (thus + * duplicating the libpng intent without, we hope, duplicating the bugs + * in the libpng implementation!) The png_structp is solely to allow error + * reporting via png_error and png_warning. + */ + void (*mod)(PNG_CONST struct image_transform *this, image_pixel *that, + png_structp pp, PNG_CONST struct transform_display *display); + + /* Add this transform to the list and return true if the transform is + * meaningful for this colour type and bit depth - if false then the + * transform should have no effect on the image so there's not a lot of + * point running it. + */ + int (*add)(struct image_transform *this, + PNG_CONST struct image_transform **that, png_byte colour_type, + png_byte bit_depth); +} image_transform; + +typedef struct transform_display +{ + standard_display this; + + /* Parameters */ + png_modifier* pm; + PNG_CONST image_transform* transform_list; + + /* Local variables */ + png_byte output_colour_type; + png_byte output_bit_depth; +} transform_display; + +/* Two functions to end the list: */ +static void +image_transform_set_end(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + UNUSED(this) + UNUSED(that) + UNUSED(pp) + UNUSED(pi) +} + +/* At the end of the list recalculate the output image pixel value from the + * double precision values set up by the preceding 'mod' calls: + */ +static unsigned int +sample_scale(double sample_value, unsigned int scale) +{ + sample_value = floor(sample_value * scale + .5); + + /* Return NaN as 0: */ + if (!(sample_value > 0)) + sample_value = 0; + else if (sample_value > scale) + sample_value = scale; + + return (unsigned int)sample_value; +} + +static void +image_transform_mod_end(PNG_CONST image_transform *this, image_pixel *that, + png_structp pp, PNG_CONST transform_display *display) +{ + PNG_CONST unsigned int scale = (1U<sample_depth)-1; + + UNUSED(this) + UNUSED(pp) + UNUSED(display) + + /* At the end recalculate the digitized red green and blue values according + * to the current sample_depth of the pixel. + * + * The sample value is simply scaled to the maximum, checking for over + * and underflow (which can both happen for some image transforms, + * including simple size scaling, though libpng doesn't do that at present. + */ + that->red = sample_scale(that->redf, scale); + + /* The error value is increased, at the end, according to the lowest sBIT + * value seen. Common sense tells us that the intermediate integer + * representations are no more accurate than +/- 0.5 in the integral values, + * the sBIT allows the implementation to be worse than this. In addition the + * PNG specification actually permits any error within the range (-1..+1), + * but that is ignored here. Instead the final digitized value is compared, + * below to the digitized value of the error limits - this has the net effect + * of allowing (almost) +/-1 in the output value. It's difficult to see how + * any algorithm that digitizes intermediate results can be more accurate. + */ + that->rede += 1./(2*((1U<red_sBIT)-1)); + + if (that->colour_type & PNG_COLOR_MASK_COLOR) + { + that->green = sample_scale(that->greenf, scale); + that->blue = sample_scale(that->bluef, scale); + that->greene += 1./(2*((1U<green_sBIT)-1)); + that->bluee += 1./(2*((1U<blue_sBIT)-1)); + } + else + { + that->blue = that->green = that->red; + that->bluef = that->greenf = that->redf; + that->bluee = that->greene = that->rede; + } + + if ((that->colour_type & PNG_COLOR_MASK_ALPHA) || + that->colour_type == PNG_COLOR_TYPE_PALETTE) + { + that->alpha = sample_scale(that->alphaf, scale); + that->alphae += 1./(2*((1U<alpha_sBIT)-1)); + } + else + { + that->alpha = scale; /* opaque */ + that->alpha = 1; /* Override this. */ + that->alphae = 0; /* It's exact ;-) */ + } +} + +/* Static 'end' structure: */ +static image_transform image_transform_end = +{ + "(end)", /* name */ + 1, /* enable */ + 0, /* list */ + 0, /* global_use */ + 0, /* local_use */ + 0, /* next */ + image_transform_set_end, + image_transform_mod_end, + 0 /* never called, I want it to crash if it is! */ +}; + +/* Reader callbacks and implementations, where they differ from the standard + * ones. + */ +static void +transform_display_init(transform_display *dp, png_modifier *pm, png_uint_32 id, + PNG_CONST image_transform *transform_list) +{ + /* Standard fields */ + standard_display_init(&dp->this, &pm->this, id, 0/*do_interlace*/); + + /* Parameter fields */ + dp->pm = pm; + dp->transform_list = transform_list; + + /* Local variable fields */ + dp->output_colour_type = 255; /* invalid */ + dp->output_bit_depth = 255; /* invalid */ +} + +static void +transform_info_imp(transform_display *dp, png_structp pp, png_infop pi) +{ + /* Reuse the standard stuff as appropriate. */ + standard_info_part1(&dp->this, pp, pi); + + /* Now set the list of transforms. */ + dp->transform_list->set(dp->transform_list, dp, pp, pi); + + /* Update the info structure for these transforms: */ + png_read_update_info(pp, pi); + + /* And get the output information into the standard_display */ + standard_info_part2(&dp->this, pp, pi, 1/*images*/); + + /* Plus the extra stuff we need for the transform tests: */ + dp->output_colour_type = png_get_color_type(pp, pi); + dp->output_bit_depth = png_get_bit_depth(pp, pi); + + /* Validate the combination of colour type and bit depth that we are getting + * out of libpng; the semantics of something not in the PNG spec are, at + * best, unclear. + */ + switch (dp->output_colour_type) + { + case PNG_COLOR_TYPE_PALETTE: + if (dp->output_bit_depth > 8) goto error; + /*FALL THROUGH*/ + case PNG_COLOR_TYPE_GRAY: + if (dp->output_bit_depth == 1 || dp->output_bit_depth == 2 || + dp->output_bit_depth == 4) + break; + /*FALL THROUGH*/ + default: + if (dp->output_bit_depth == 8 || dp->output_bit_depth == 16) + break; + /*FALL THROUGH*/ + error: + { + char message[128]; + size_t pos; + + pos = safecat(message, sizeof message, 0, + "invalid final bit depth: colour type("); + pos = safecatn(message, sizeof message, pos, dp->output_colour_type); + pos = safecat(message, sizeof message, pos, ") with bit depth: "); + pos = safecatn(message, sizeof message, pos, dp->output_bit_depth); + + png_error(pp, message); + } + } + + /* Use a test pixel to check that the output agrees with what we expect - + * this avoids running the whole test if the output is unexpected. + */ + { + image_pixel test_pixel; + + memset(&test_pixel, 0, sizeof test_pixel); + test_pixel.colour_type = dp->this.colour_type; /* input */ + test_pixel.bit_depth = dp->this.bit_depth; + if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE) + test_pixel.sample_depth = 8; + else + test_pixel.sample_depth = test_pixel.bit_depth; + /* Don't need sBIT here */ + test_pixel.have_tRNS = dp->this.is_transparent; + + dp->transform_list->mod(dp->transform_list, &test_pixel, pp, dp); + + if (test_pixel.colour_type != dp->output_colour_type) + { + char message[128]; + size_t pos = safecat(message, sizeof message, 0, "colour type "); + + pos = safecatn(message, sizeof message, pos, dp->output_colour_type); + pos = safecat(message, sizeof message, pos, " expected "); + pos = safecatn(message, sizeof message, pos, test_pixel.colour_type); + + png_error(pp, message); + } + + if (test_pixel.bit_depth != dp->output_bit_depth) + { + char message[128]; + size_t pos = safecat(message, sizeof message, 0, "bit depth "); + + pos = safecatn(message, sizeof message, pos, dp->output_bit_depth); + pos = safecat(message, sizeof message, pos, " expected "); + pos = safecatn(message, sizeof message, pos, test_pixel.bit_depth); + + png_error(pp, message); + } + + /* If both bit depth and colour type are correct check the sample depth. + * I believe these are both internal errors. + */ + if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE) + { + if (test_pixel.sample_depth != 8) /* oops - internal error! */ + png_error(pp, "pngvalid: internal: palette sample depth not 8"); + } + else if (test_pixel.sample_depth != dp->output_bit_depth) + { + char message[128]; + size_t pos = safecat(message, sizeof message, 0, + "internal: sample depth "); + + pos = safecatn(message, sizeof message, pos, dp->output_bit_depth); + pos = safecat(message, sizeof message, pos, " expected "); + pos = safecatn(message, sizeof message, pos, test_pixel.sample_depth); + + png_error(pp, message); + } + } +} + +static void +transform_info(png_structp pp, png_infop pi) +{ + transform_info_imp(png_get_progressive_ptr(pp), pp, pi); +} + +static void +transform_range_check(png_structp pp, unsigned int r, unsigned int g, + unsigned int b, unsigned int a, unsigned int in_digitized, double in, + unsigned int out, png_byte sample_depth, double err, PNG_CONST char *name) +{ + /* Compare the scaled, digitzed, values of our local calculation (in+-err) + * with the digitized values libpng produced; 'sample_depth' is the actual + * digitization depth of the libpng output colors (the bit depth except for + * palette images where it is always 8.) + */ + unsigned int max = (1U<= in_min && out <= in_max)) + { + char message[256]; + size_t pos; + + pos = safecat(message, sizeof message, 0, name); + pos = safecat(message, sizeof message, pos, " output value error: rgba("); + pos = safecatn(message, sizeof message, pos, r); + pos = safecat(message, sizeof message, pos, ","); + pos = safecatn(message, sizeof message, pos, g); + pos = safecat(message, sizeof message, pos, ","); + pos = safecatn(message, sizeof message, pos, b); + pos = safecat(message, sizeof message, pos, ","); + pos = safecatn(message, sizeof message, pos, a); + pos = safecat(message, sizeof message, pos, "): "); + pos = safecatn(message, sizeof message, pos, out); + pos = safecat(message, sizeof message, pos, " expected: "); + pos = safecatn(message, sizeof message, pos, in_digitized); + pos = safecat(message, sizeof message, pos, " ("); + pos = safecatd(message, sizeof message, pos, (in-err)*max, 3); + pos = safecat(message, sizeof message, pos, ".."); + pos = safecatd(message, sizeof message, pos, (in+err)*max, 3); + pos = safecat(message, sizeof message, pos, ")"); + + png_error(pp, message); + } +} + +static void +transform_image_validate(transform_display *dp, png_structp pp, png_infop pi, + png_const_bytep pRow) +{ + /* Constants for the loop below: */ + PNG_CONST png_byte in_ct = dp->this.colour_type; + PNG_CONST png_byte in_bd = dp->this.bit_depth; + PNG_CONST png_uint_32 w = dp->this.w; + PNG_CONST png_uint_32 h = dp->this.h; + PNG_CONST size_t cbRow = dp->this.cbRow; + PNG_CONST png_byte out_ct = dp->output_colour_type; + PNG_CONST png_byte out_bd = dp->output_bit_depth; + PNG_CONST png_byte sample_depth = (png_byte)(out_ct == + PNG_COLOR_TYPE_PALETTE ? 8 : out_bd); + PNG_CONST png_byte red_sBIT = dp->this.red_sBIT; + PNG_CONST png_byte green_sBIT = dp->this.green_sBIT; + PNG_CONST png_byte blue_sBIT = dp->this.blue_sBIT; + PNG_CONST png_byte alpha_sBIT = dp->this.alpha_sBIT; + PNG_CONST int have_tRNS = dp->this.is_transparent; + + standard_palette out_palette; + png_uint_32 y; + + UNUSED(pi) + + /* Read the palette corresponding to the output if the output colour type + * indicates a palette, othewise set out_palette to garbage. + */ + if (out_ct == PNG_COLOR_TYPE_PALETTE) + (void)standard_palette_init(out_palette, pp, pi); + else + memset(out_palette, 0x5e, sizeof out_palette); + + for (y=0; ythis.palette); + + in_pixel.red_sBIT = red_sBIT; + in_pixel.green_sBIT = green_sBIT; + in_pixel.blue_sBIT = blue_sBIT; + in_pixel.alpha_sBIT = alpha_sBIT; + in_pixel.have_tRNS = have_tRNS; + + /* For error detection, below. */ + r = in_pixel.red; + g = in_pixel.green; + b = in_pixel.blue; + a = in_pixel.alpha; + + dp->transform_list->mod(dp->transform_list, &in_pixel, pp, dp); + + /* Read the output pixel and compare it to what we got, we don't + * use the error field here, so no need to update sBIT. + */ + image_pixel_init(&out_pixel, pRow, out_ct, out_bd, x, out_palette); + + /* We don't expect changes to the index here even if the bit depth is + * changed. + */ + if (in_ct == PNG_COLOR_TYPE_PALETTE && + out_ct == PNG_COLOR_TYPE_PALETTE) + { + if (in_pixel.palette_index != out_pixel.palette_index) + png_error(pp, "unexpected transformed palette index"); + } + + /* Check the colours for palette images too - in fact the palette could + * be separately verified itself in most cases. + */ + if (in_pixel.red != out_pixel.red) + transform_range_check(pp, r, g, b, a, in_pixel.red, in_pixel.redf, + out_pixel.red, sample_depth, in_pixel.rede, "red/gray"); + + if ((out_ct & PNG_COLOR_MASK_COLOR) != 0 && + in_pixel.green != out_pixel.green) + transform_range_check(pp, r, g, b, a, in_pixel.green, + in_pixel.greenf, out_pixel.green, sample_depth, in_pixel.greene, + "green"); + + if ((out_ct & PNG_COLOR_MASK_COLOR) != 0 && + in_pixel.blue != out_pixel.blue) + transform_range_check(pp, r, g, b, a, in_pixel.blue, in_pixel.bluef, + out_pixel.blue, sample_depth, in_pixel.bluee, "blue"); + + if ((out_ct & PNG_COLOR_MASK_ALPHA) != 0 && + in_pixel.alpha != out_pixel.alpha) + transform_range_check(pp, r, g, b, a, in_pixel.alpha, + in_pixel.alphaf, out_pixel.alpha, sample_depth, in_pixel.alphae, + "alpha"); + } /* pixel (x) loop */ + } /* row (y) loop */ + + /* Record that something was actually checked to avoid a false positive. */ + dp->this.ps->validated = 1; +} + +static void +transform_end(png_structp pp, png_infop pi) +{ + transform_display *dp = png_get_progressive_ptr(pp); + + transform_image_validate(dp, pp, pi, dp->this.ps->image); +} + +/* A single test run. */ +static void +transform_test(png_modifier *pmIn, PNG_CONST png_uint_32 idIn, + PNG_CONST image_transform* transform_listIn, PNG_CONST char *name) +{ + transform_display d; + context(&pmIn->this, fault); + + transform_display_init(&d, pmIn, idIn, transform_listIn); + + Try + { + png_structp pp; + png_infop pi; + + /* Get a png_struct for writing the image. */ + pp = set_modifier_for_read(d.pm, &pi, d.this.id, name); + +# if 0 + /* Logging (debugging only) */ + { + char buffer[256]; + + (void)store_message(&d.pm->this, pp, buffer, sizeof buffer, 0, + "running test"); + + fprintf(stderr, "%s\n", buffer); + } +# endif + + /* Introduce the correct read function. */ + if (d.pm->this.progressive) + { + /* Share the row function with the standard implementation. */ + png_set_progressive_read_fn(pp, &d, transform_info, progressive_row, + transform_end); + + /* Now feed data into the reader until we reach the end: */ + modifier_progressive_read(d.pm, pp, pi); + } + else + { + /* modifier_read expects a png_modifier* */ + png_set_read_fn(pp, d.pm, modifier_read); + + /* Check the header values: */ + png_read_info(pp, pi); + + /* Process the 'info' requirements. Only one image is generated */ + transform_info_imp(&d, pp, pi); + + sequential_row(&d.this, pp, pi, NULL, d.this.ps->image); + + transform_image_validate(&d, pp, pi, d.this.ps->image); + } + + modifier_reset(d.pm); + } + + Catch(fault) + modifier_reset((png_modifier*)fault); +} + +/* The transforms: */ +#define ITSTRUCT(name) image_transform_##name +#define IT(name,prev)\ +static image_transform ITSTRUCT(name) =\ +{\ + #name,\ + 1, /*enable*/\ + &ITSTRUCT(prev), /*list*/\ + 0, /*global_use*/\ + 0, /*local_use*/\ + 0, /*next*/\ + image_transform_png_set_##name##_set,\ + image_transform_png_set_##name##_mod,\ + image_transform_png_set_##name##_add\ +} + +/* To save code: */ +static int +image_transform_default_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(colour_type) + UNUSED(bit_depth) + + this->next = *that; + *that = this; + + return 1; +} + +/* png_set_palette_to_rgb */ +static void +image_transform_png_set_palette_to_rgb_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_palette_to_rgb(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_palette_to_rgb_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + if (that->colour_type == PNG_COLOR_TYPE_PALETTE) + image_pixel_convert_PLTE(that, &display->this); + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_palette_to_rgb_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(bit_depth) + + this->next = *that; + *that = this; + + return colour_type == PNG_COLOR_TYPE_PALETTE; +} + +IT(palette_to_rgb, end); + + +/* png_set_tRNS_to_alpha */ +static void +image_transform_png_set_tRNS_to_alpha_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_tRNS_to_alpha(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_tRNS_to_alpha_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + /* LIBPNG BUG: this always forces palette images to RGB. */ + if (that->colour_type == PNG_COLOR_TYPE_PALETTE) + image_pixel_convert_PLTE(that, &display->this); + + /* This effectively does an 'expand' only if there is some transparency to + * covert to an alpha channel. + */ + if (that->have_tRNS) + image_pixel_add_alpha(that, &display->this); + + /* LIBPNG BUG: otherwise libpng still expands to 8 bits! */ + else + { + if (that->bit_depth < 8) + that->bit_depth =8; + if (that->sample_depth < 8) + that->sample_depth = 8; + } + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_tRNS_to_alpha_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(bit_depth) + + this->next = *that; + *that = this; + + /* We don't know yet whether there will be a tRNS chunk, but we know that + * this transformation should do nothing if there already is an alpha + * channel. + */ + return (colour_type & PNG_COLOR_MASK_ALPHA) == 0; +} + +IT(tRNS_to_alpha,palette_to_rgb); + +/* png_set_gray_to_rgb */ +static void +image_transform_png_set_gray_to_rgb_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_gray_to_rgb(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_gray_to_rgb_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + /* NOTE: we can actually pend the tRNS processing at this point because we + * can correctly recognize the original pixel value even though we have + * mapped the one gray channel to the three RGB ones, but in fact libpng + * doesn't do this, so we don't either. + */ + if ((that->colour_type & PNG_COLOR_MASK_COLOR) == 0 && that->have_tRNS) + image_pixel_add_alpha(that, &display->this); + + /* Simply expand the bit depth and alter the colour type as required. */ + if (that->colour_type == PNG_COLOR_TYPE_GRAY) + { + /* RGB images have a bit depth at least equal to '8' */ + if (that->bit_depth < 8) + that->sample_depth = that->bit_depth = 8; + + /* And just changing the colour type works here because the green and blue + * channels are being maintained in lock-step with the red/gray: + */ + that->colour_type = PNG_COLOR_TYPE_RGB; + } + + else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA) + that->colour_type = PNG_COLOR_TYPE_RGB_ALPHA; + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_gray_to_rgb_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(bit_depth) + + this->next = *that; + *that = this; + + return (colour_type & PNG_COLOR_MASK_COLOR) == 0; +} + +IT(gray_to_rgb,tRNS_to_alpha); + +/* png_set_expand */ +static void +image_transform_png_set_expand_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_expand(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_expand_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + /* The general expand case depends on what the colour type is: */ + if (that->colour_type == PNG_COLOR_TYPE_PALETTE) + image_pixel_convert_PLTE(that, &display->this); + else if (that->bit_depth < 8) /* grayscale */ + that->sample_depth = that->bit_depth = 8; + + if (that->have_tRNS) + image_pixel_add_alpha(that, &display->this); + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_expand_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(bit_depth) + + this->next = *that; + *that = this; + + /* 'expand' should do nothing for RGBA or GA input - no tRNS and the bit + * depth is at least 8 already. + */ + return (colour_type & PNG_COLOR_MASK_ALPHA) == 0; +} + +IT(expand,gray_to_rgb); + +/* png_set_expand_gray_1_2_4_to_8 + * LIBPNG BUG: this just does an 'expand' + */ +static void +image_transform_png_set_expand_gray_1_2_4_to_8_set( + PNG_CONST image_transform *this, transform_display *that, png_structp pp, + png_infop pi) +{ + png_set_expand_gray_1_2_4_to_8(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_expand_gray_1_2_4_to_8_mod( + PNG_CONST image_transform *this, image_pixel *that, png_structp pp, + PNG_CONST transform_display *display) +{ + image_transform_png_set_expand_mod(this, that, pp, display); +} + +static int +image_transform_png_set_expand_gray_1_2_4_to_8_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + return image_transform_png_set_expand_add(this, that, colour_type, + bit_depth); +} + +IT(expand_gray_1_2_4_to_8, expand); + +/* png_set_strip_16 */ +static void +image_transform_png_set_strip_16_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_strip_16(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_strip_16_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + if (that->bit_depth == 16) + { + that->sample_depth = that->bit_depth = 8; + if (that->red_sBIT > 8) that->red_sBIT = 8; + if (that->green_sBIT > 8) that->green_sBIT = 8; + if (that->blue_sBIT > 8) that->blue_sBIT = 8; + if (that->alpha_sBIT > 8) that->alpha_sBIT = 8; + +# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED + /* The strip 16 algoirithm drops the low 8 bits rather than calculating + * 1/257, so we need to adjust the permitted errors appropriately: + */ + { + PNG_CONST double d = (255-128.5)/65535; + that->rede += d; + that->greene += d; + that->bluee += d; + that->alphae += d; + } +# endif + } + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_strip_16_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(colour_type) + + this->next = *that; + *that = this; + + return bit_depth > 8; +} + +IT(strip_16, expand_gray_1_2_4_to_8); + +/* png_set_strip_alpha */ +static void +image_transform_png_set_strip_alpha_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_strip_alpha(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_strip_alpha_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA) + that->colour_type = PNG_COLOR_TYPE_GRAY; + else if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA) + that->colour_type = PNG_COLOR_TYPE_RGB; + + that->have_tRNS = 0; + that->alphaf = 1; + that->alphae = 0; + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_strip_alpha_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(bit_depth) + + this->next = *that; + *that = this; + + return (colour_type & PNG_COLOR_MASK_ALPHA) != 0; +} + +IT(strip_alpha,strip_16); + +/* png_set_rgb_to_gray(png_structp, int err_action, double red, double green) + * png_set_rgb_to_gray_fixed(png_structp, int err_action, png_fixed_point red, + * png_fixed_point green) + * png_get_rgb_to_gray_status + * + * At present the APIs are simply tested using the 16.16 fixed point conversion + * values known to be used inside libpng: + * + * red: 6968 + * green: 23434 + * blue: 2366 + * + * NOTE: this currently ignores the gamma because no gamma is being set, the + * tests on gamma need to happen in the gamma test set. + */ +static void +image_transform_png_set_rgb_to_gray_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + PNG_CONST int error_action = 1; /* no error, no defines in png.h */ + +# ifdef PNG_FLOATING_POINT_SUPPORTED + png_set_rgb_to_gray(pp, error_action, -1, -1); +# else + png_set_rgb_to_gray_fixed(pp, error_action, -1, -1); +# endif + + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_rgb_to_gray_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + if ((that->colour_type & PNG_COLOR_MASK_COLOR) != 0) + { + if (that->colour_type == PNG_COLOR_TYPE_PALETTE) + image_pixel_convert_PLTE(that, &display->this); + + /* Image now has RGB channels... */ + that->bluef = that->greenf = that->redf = (that->redf * 6968 + + that->greenf * 23434 + that->bluef * 2366) / 32768; + that->bluee = that->greene = that->rede = (that->rede * 6968 + + that->greene * 23434 + that->bluee * 2366) / 32768 * + (1 + DBL_EPSILON * 6); + + /* The sBIT is the minium of the three colour channel sBITs. */ + if (that->red_sBIT > that->green_sBIT) + that->red_sBIT = that->green_sBIT; + if (that->red_sBIT > that->blue_sBIT) + that->red_sBIT = that->blue_sBIT; + that->blue_sBIT = that->green_sBIT = that->red_sBIT; + + /* And zap the colour bit in the type: */ + if (that->colour_type == PNG_COLOR_TYPE_RGB) + that->colour_type = PNG_COLOR_TYPE_GRAY; + else if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA) + that->colour_type = PNG_COLOR_TYPE_GRAY_ALPHA; + } + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_rgb_to_gray_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(bit_depth) + + this->next = *that; + *that = this; + + return (colour_type & PNG_COLOR_MASK_COLOR) != 0; +} + +IT(rgb_to_gray,strip_alpha); + +/* png_set_background(png_structp, png_const_color_16p background_color, + * int background_gamma_code, int need_expand, double background_gamma) + * png_set_background_fixed(png_structp, png_const_color_16p background_color, + * int background_gamma_code, int need_expand, + * png_fixed_point background_gamma) + * + * As with rgb_to_gray this ignores the gamma. +*/ +static void +image_transform_png_set_background_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_color_16 back; + + /* Since we don't know the output bit depth at this point we must use the + * input values and ask libpng to expand the chunk as required. + */ + back.index = 255; /* Should not be used */ + back.gray = back.blue = back.green = back.red = + (png_uint_16)((1U << that->this.bit_depth) >> 1); + +# ifdef PNG_FLOATING_POINT_SUPPORTED + png_set_background(pp, &back, PNG_BACKGROUND_GAMMA_FILE, 1, 0); +# else + png_set_background_fixed(pp, &back, PNG_BACKGROUND_GAMMA_FILE, 1, 0); +# endif + + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_background_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + /* Check for tRNS first: */ + if (that->have_tRNS && that->colour_type != PNG_COLOR_TYPE_PALETTE) + image_pixel_add_alpha(that, &display->this); + + /* This is only necessary if the alpha value is less than 1. */ + if (that->alphaf < 1) + { + /* Repeat the calculation above and scale the result: */ + unsigned int tmp = (1U << display->this.bit_depth); + double component = (tmp >> 1)/(double)(tmp-1); + + /* Now we do the background calculation without any gamma correction. */ + if (that->alphaf <= 0) + { + that->bluef = that->greenf = that->redf = component; + that->bluee = that->greene = that->rede = component * DBL_EPSILON; + that->blue_sBIT = that->green_sBIT = that->red_sBIT = that->bit_depth; + } + + else + { + component *= 1-that->alphaf; + that->redf = that->redf * that->alphaf + component; + that->rede = that->rede * that->alphaf + that->redf * 3 * DBL_EPSILON; + that->greenf = that->greenf * that->alphaf + component; + that->greene = that->greene * that->alphaf + that->greenf * 3 * + DBL_EPSILON; + that->bluef = that->bluef * that->alphaf + component; + that->bluee = that->bluee * that->alphaf + that->bluef * 3 * + DBL_EPSILON; + } + + /* Remove the alpha type and set the alpha. */ + that->alphaf = 1; + that->alphae = 0; + + if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA) + that->colour_type = PNG_COLOR_TYPE_RGB; + else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA) + that->colour_type = PNG_COLOR_TYPE_GRAY; + } + + this->next->mod(this->next, that, pp, display); +} + +#define image_transform_png_set_background_add image_transform_default_add + +IT(background,rgb_to_gray); + +static image_transform *PNG_CONST image_transform_first = &ITSTRUCT(background); + +static void +transform_enable(PNG_CONST char *name) +{ + /* Everything starts out enabled, so if we see an 'enable' disabled + * everything else the first time round. + */ + static int all_disabled = 0; + int found_it = 0; + image_transform *list = image_transform_first; + + while (list != &image_transform_end) + { + if (strcmp(list->name, name) == 0) + { + list->enable = 1; + found_it = 1; + } + else if (!all_disabled) + list->enable = 0; + + list = list->list; + } + + all_disabled = 1; + + if (!found_it) + { + fprintf(stderr, "pngvalid: --transform-enable=%s: unknown transform\n", + name); + exit(1); + } +} + +static void +transform_disable(PNG_CONST char *name) +{ + image_transform *list = image_transform_first; + + while (list != &image_transform_end) + { + if (strcmp(list->name, name) == 0) + { + list->enable = 0; + return; + } + + list = list->list; + } + + fprintf(stderr, "pngvalid: --transform-disable=%s: unknown transform\n", + name); + exit(1); +} + +static void +image_transform_reset_count(void) +{ + image_transform *next = image_transform_first; + int count = 0; + + while (next != &image_transform_end) + { + next->local_use = 0; + next->next = 0; + next = next->list; + ++count; + } + + /* This can only happen if we every have more than 32 transforms (excluding + * the end) in the list. + */ + if (count > 32) abort(); +} + +static int +image_transform_test_counter(png_uint_32 counter, unsigned int max) +{ + /* Test the list to see if there is any point contining, given a current + * counter and a 'max' value. + */ + image_transform *next = image_transform_first; + + while (next != &image_transform_end) + { + /* For max 0 or 1 continue until the counter overflows: */ + counter >>= 1; + + /* Continue if any entry hasn't reacked the max. */ + if (max > 1 && next->local_use < max) + return 1; + next = next->list; + } + + return max <= 1 && counter == 0; +} + +static png_uint_32 +image_transform_add(PNG_CONST image_transform **this, unsigned int max, + png_uint_32 counter, char *name, size_t sizeof_name, size_t *pos, + png_byte colour_type, png_byte bit_depth) +{ + for (;;) /* until we manage to add something */ + { + png_uint_32 mask; + image_transform *list; + + /* Find the next counter value, if the counter is zero this is the start + * of the list. This routine always returns the current counter (not the + * next) so it returns 0 at the end and expects 0 at the beginning. + */ + if (counter == 0) /* first time */ + { + image_transform_reset_count(); + if (max <= 1) + counter = 1; + else + counter = random_32(); + } + else /* advance the counter */ + { + switch (max) + { + case 0: ++counter; break; + case 1: counter <<= 1; break; + default: counter = random_32(); break; + } + } + + /* Now add all these items, if possible */ + *this = &image_transform_end; + list = image_transform_first; + mask = 1; + + /* Go through the whole list adding anything that the counter selects: */ + while (list != &image_transform_end) + { + if ((counter & mask) != 0 && list->enable && + (max == 0 || list->local_use < max)) + { + /* Candidate to add: */ + if (list->add(list, this, colour_type, bit_depth) || max == 0) + { + /* Added, so add to the name too. */ + *pos = safecat(name, sizeof_name, *pos, " +"); + *pos = safecat(name, sizeof_name, *pos, list->name); + } + + else + { + /* Not useful and max>0, so remvoe it from *this: */ + *this = list->next; + list->next = 0; + + /* And, since we know it isn't useful, stop it being added again + * in this run: + */ + list->local_use = max; + } + } + + mask <<= 1; + list = list->list; + } + + /* Now if anything was added we have something to do. */ + if (*this != &image_transform_end) + return counter; + + /* Nothing added, but was there anything in there to add? */ + if (!image_transform_test_counter(counter, max)) + return 0; + } +} + +#ifdef THIS_IS_THE_PROFORMA +static void +image_transform_png_set_@_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_@(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_@_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_@_add(image_transform *this, + PNG_CONST image_transform **that, char *name, size_t sizeof_name, + size_t *pos, png_byte colour_type, png_byte bit_depth) +{ + this->next = *that; + *that = this; + + *pos = safecat(name, sizeof_name, *pos, " +@"); + + return 1; +} + +IT(@); +#endif + +/* png_set_quantize(png_structp, png_colorp palette, int num_palette, + * int maximum_colors, png_const_uint_16p histogram, int full_quantize) + * + * Very difficult to validate this! + */ +/*NOTE: TBD NYI */ + +/* The data layout transforms are handled by swapping our own channel data, + * necessarily these need to happen at the end of the transform list because the + * semantic of the channels changes after these are executed. Some of these, + * like set_shift and set_packing, can't be done at present because they change + * the layout of the data at the sub-sample level so sample() won't get the + * right answer. + */ +/* png_set_invert_alpha */ +/*NOTE: TBD NYI */ + +/* png_set_bgr */ +/*NOTE: TBD NYI */ + +/* png_set_swap_alpha */ +/*NOTE: TBD NYI */ + +/* png_set_swap */ +/*NOTE: TBD NYI */ + +/* png_set_filler, (png_structp png_ptr, png_uint_32 filler, int flags)); */ +/*NOTE: TBD NYI */ + +/* png_set_add_alpha, (png_structp png_ptr, png_uint_32 filler, int flags)); */ +/*NOTE: TBD NYI */ + +/* png_set_packing */ +/*NOTE: TBD NYI */ + +/* png_set_packswap */ +/*NOTE: TBD NYI */ + +/* png_set_invert_mono */ +/*NOTE: TBD NYI */ + +/* png_set_shift(png_structp, png_const_color_8p true_bits) */ +/*NOTE: TBD NYI */ + +static int +test_transform(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type, + int bdlo, int PNG_CONST bdhi, png_uint_32 max) +{ + for (; bdlo <= bdhi; ++bdlo) + { + PNG_CONST png_byte bit_depth = DEPTH(bdlo); + png_uint_32 counter = 0; + size_t base_pos; + char name[64]; + + base_pos = safecat(name, sizeof name, 0, "transform:"); + + for (;;) + { + size_t pos = base_pos; + PNG_CONST image_transform *list = 0; + + counter = image_transform_add(&list, max, counter, name, sizeof name, + &pos, colour_type, bit_depth); + + if (counter == 0) + break; + + /* The command line can change this to checking interlaced images. */ + transform_test(pm, FILEID(colour_type, bit_depth, pm->interlace_type, + 0, 0, 0), list, name); + + if (fail(pm)) + return 0; + } + } + + return 1; /* keep going */ +} + +static void +perform_transform_test(png_modifier *pm) +{ + /* Test each colour type over the valid range of bit depths (expressed as + * log2(bit_depth) in turn, stop as soon as any error is detected. + */ + if (!test_transform(pm, 0, 0, READ_BDHI, 1)) + return; + + if (!test_transform(pm, 2, 3, READ_BDHI, 1)) + return; + + if (!test_transform(pm, 3, 0, 3, 1)) + return; + + if (!test_transform(pm, 4, 3, READ_BDHI, 1)) + return; + + if (!test_transform(pm, 6, 3, READ_BDHI, 1)) + return; +} + + +/********************************* GAMMA TESTS ********************************/ +/* Gamma test images. */ +typedef struct gamma_modification +{ + png_modification this; + png_fixed_point gamma; +} gamma_modification; + +static int +gamma_modify(png_modifier *pm, png_modification *me, int add) +{ + 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); + png_save_uint_32(pm->buffer+8, ((gamma_modification*)me)->gamma); + return 1; +} + +static void +gamma_modification_init(gamma_modification *me, png_modifier *pm, double gammad) +{ + double g; + + modification_init(&me->this); + me->this.chunk = CHUNK_gAMA; + me->this.modify_fn = gamma_modify; + me->this.add = CHUNK_PLTE; + g = floor(gammad * 100000 + .5); + me->gamma = (png_fixed_point)g; + me->this.next = pm->modifications; + pm->modifications = &me->this; +} + +typedef struct srgb_modification +{ + png_modification this; + png_byte intent; +} srgb_modification; + +static int +srgb_modify(png_modifier *pm, png_modification *me, int add) +{ + 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); + pm->buffer[8] = ((srgb_modification*)me)->intent; + return 1; +} + +static void +srgb_modification_init(srgb_modification *me, png_modifier *pm, png_byte intent) +{ + modification_init(&me->this); + me->this.chunk = CHUNK_sBIT; + + if (intent <= 3) /* if valid, else *delete* sRGB chunks */ + { + me->this.modify_fn = srgb_modify; + me->this.add = CHUNK_PLTE; + me->intent = intent; + } + + else + { + me->this.modify_fn = 0; + me->this.add = 0; + me->intent = 0; + } + + me->this.next = pm->modifications; + pm->modifications = &me->this; +} + +typedef struct sbit_modification +{ + png_modification this; + png_byte sbit; +} sbit_modification; + +static int +sbit_modify(png_modifier *pm, png_modification *me, int add) +{ + png_byte sbit = ((sbit_modification*)me)->sbit; + if (pm->bit_depth > sbit) + { + int cb = 0; + switch (pm->colour_type) + { + case 0: + cb = 1; + break; + + case 2: + case 3: + cb = 3; + break; + + case 4: + cb = 2; + break; + + case 6: + cb = 4; + break; + + default: + png_error(pm->this.pread, + "unexpected colour type in sBIT modification"); + } + + png_save_uint_32(pm->buffer, cb); + png_save_uint_32(pm->buffer+4, CHUNK_sBIT); + + while (cb > 0) + (pm->buffer+8)[--cb] = sbit; + + return 1; + } + else if (!add) + { + /* Remove the sBIT chunk */ + pm->buffer_count = pm->buffer_position = 0; + return 1; + } + else + return 0; /* do nothing */ +} + +static void +sbit_modification_init(sbit_modification *me, png_modifier *pm, png_byte sbit) +{ + modification_init(&me->this); + me->this.chunk = CHUNK_sBIT; + me->this.modify_fn = sbit_modify; + me->this.add = CHUNK_PLTE; + me->sbit = sbit; + me->this.next = pm->modifications; + pm->modifications = &me->this; +} + +/* Reader callbacks and implementations, where they differ from the standard + * ones. + */ +typedef struct gamma_display +{ + standard_display this; + + /* Parameters */ png_modifier* pm; double file_gamma; double screen_gamma; png_byte sbit; @@ -3497,9 +5306,9 @@ in_bd != out_bd; PNG_CONST unsigned int samples_per_pixel = (out_ct & 2U) ? 3U : 1U; - PNG_CONST double gamma = 1/(file_gamma*screen_gamma); /* Overall */ + PNG_CONST double gamma_correction = 1/(file_gamma*screen_gamma);/* Overall */ double maxerrout = 0, maxerrabs = 0, maxerrpc = 0; png_uint_32 y; @@ -3523,9 +5332,10 @@ PNG_CONST unsigned int isbit = id >> (in_bd-sbit); - double i, sample, encoded_sample, output, encoded_error, error; + double i, input_sample, encoded_sample, output; + double encoded_error, error; double es_lo, es_hi; /* First check on the 'perfect' result obtained from the * digitized input value, id, and compare this against the @@ -3542,9 +5352,9 @@ * quantization of the output value to the nearest digital * value (nevertheless the error is still recorded - it's * interesting ;-) */ - encoded_sample = pow(i, gamma) * outmax; + encoded_sample = pow(i, gamma_correction) * outmax; encoded_error = fabs(od-encoded_sample); if (encoded_error > maxerrout) maxerrout = encoded_error; @@ -3560,29 +5370,29 @@ * image. There's nothing we can do about this - we don't * know what it is - so assume the unencoded value is * perceptually linear. */ - sample = pow(i, 1/file_gamma); /* In range 0..1 */ + input_sample = pow(i, 1/file_gamma); /* In range 0..1 */ output = od; output /= outmax; output = pow(output, screen_gamma); /* Now we have the numbers for real errors, both absolute * values as as a percentage of the correct value (output): */ - error = fabs(sample-output); + error = fabs(input_sample-output); if (error > maxerrabs) maxerrabs = error; /* The following is an attempt to ignore the tendency of * quantization to dominate the percentage errors for low * output sample values: */ - if (sample*maxpc > .5+maxabs) + if (input_sample*maxpc > .5+maxabs) { - double pcerr = error/sample; - if (pcerr > maxerrpc) maxerrpc = pcerr; + double percentage_error = error/input_sample; + if (percentage_error > maxerrpc) maxerrpc = percentage_error; } /* Now calculate the digitization limits for * 'encoded_sample' using the 'max' values. Note that @@ -3592,29 +5402,31 @@ * First find the maximum error in linear light space, * range 0..1: */ { - double tmp = sample * maxpc; + double tmp = input_sample * maxpc; if (tmp < maxabs) tmp = maxabs; /* Low bound - the minimum of the three: */ es_lo = encoded_sample - maxout; - if (es_lo > 0 && sample-tmp > 0) + if (es_lo > 0 && input_sample-tmp > 0) { - double l = outmax * pow(sample-tmp, 1/screen_gamma); - if (l < es_lo) es_lo = l; + double low_value = outmax * pow(input_sample-tmp, + 1/screen_gamma); + if (low_value < es_lo) es_lo = low_value; } else es_lo = 0; es_hi = encoded_sample + maxout; - if (es_hi < outmax && sample+tmp < 1) + if (es_hi < outmax && input_sample+tmp < 1) { - double h = outmax * pow(sample+tmp, 1/screen_gamma); - if (h > es_hi) es_hi = h; + double high_value = outmax * pow(input_sample+tmp, + 1/screen_gamma); + if (high_value > es_hi) es_hi = high_value; } else es_hi = outmax; @@ -3641,9 +5453,9 @@ double tmp = (isbit - .5)/((1U< 0) { - is_lo = outmax * pow(tmp, gamma) - maxout; + is_lo = outmax * pow(tmp, gamma_correction) - maxout; if (is_lo < 0) is_lo = 0; } else @@ -3652,9 +5464,9 @@ tmp = (isbit + .5)/((1U< outmax) is_hi = outmax; } else @@ -3879,17 +5691,17 @@ png_byte bit_depth = 0; while (next_format(&colour_type, &bit_depth)) { - double gamma = 1.0; - while (gamma >= .4) + double test_gamma = 1.0; + while (test_gamma >= .4) { /* There's little point testing the interlacing vs non-interlacing, * but this can be set from the command line. */ gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type, - gamma, 1/gamma); - gamma *= .95; + test_gamma, 1/test_gamma); + test_gamma *= .95; } /* And a special test for sRGB */ gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type, @@ -4070,18 +5882,18 @@ static void perform_gamma_test(png_modifier *pm, int speed, int summary) { /* First some arbitrary no-transform tests: */ - if (!speed && pm->test_threshold) + if (!speed && pm->test_gamma_threshold) { perform_gamma_threshold_tests(pm); if (fail(pm)) return; } /* Now some real transforms. */ - if (pm->test_transform) + if (pm->test_gamma_transform) { perform_gamma_transform_tests(pm, speed); if (summary) @@ -4110,9 +5922,9 @@ } } /* The sbit tests produce much larger errors: */ - if (pm->test_sbit) + if (pm->test_gamma_sbit) { pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = pm->error_gray_16 = pm->error_color_8 = pm->error_color_16 = 0; perform_gamma_sbit_tests(pm, speed); @@ -4136,9 +5948,9 @@ } } #ifdef PNG_READ_16_TO_8_SUPPORTED - if (pm->test_strip16) + if (pm->test_gamma_strip16) { /* The 16 to 8 bit strip operations: */ pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = pm->error_gray_16 = pm->error_color_8 = pm->error_color_16 = 0; @@ -4539,9 +6351,9 @@ pm.this.treat_warnings_as_errors = 1; /* Store the test gammas */ pm.gammas = gammas; - pm.ngammas = 3U; /* for speed */ + pm.ngammas = 0; /* default to off */ 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). @@ -4578,11 +6390,8 @@ else if (strcmp(*argv, "-q") == 0) summary = pm.this.verbose = pm.log = 0; - else if (strcmp(*argv, "-g") == 0) - 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) @@ -4591,25 +6400,76 @@ else if (strcmp(*argv, "--size") == 0) pm.test_size = 1; + else if (strcmp(*argv, "--nosize") == 0) + pm.test_size = 0; + + else if (strcmp(*argv, "--standard") == 0) + pm.test_standard = 1; + else if (strcmp(*argv, "--nostandard") == 0) pm.test_standard = 0; + else if (strcmp(*argv, "--transform") == 0) + pm.test_transform = 1; + + else if (strcmp(*argv, "--notransform") == 0) + pm.test_transform = 0; + + else if (strncmp(*argv, "--transform-disable=", + sizeof "--transform-disable") == 0) + { + pm.test_transform = 1; + transform_disable(*argv + sizeof "--transform-disable"); + } + + else if (strncmp(*argv, "--transform-enable=", + sizeof "--transform-enable") == 0) + { + pm.test_transform = 1; + transform_enable(*argv + sizeof "--transform-enable"); + } + + else if (strcmp(*argv, "--gamma") == 0) + { + /* Just do two gamma tests here (2.2 and linear) for speed: */ + pm.ngammas = 2U; + pm.test_gamma_threshold = 1; + pm.test_gamma_transform = 1; + pm.test_gamma_sbit = 1; + pm.test_gamma_strip16 = 1; + } + else if (strcmp(*argv, "--nogamma") == 0) pm.ngammas = 0; + else if (strcmp(*argv, "--gamma-threshold") == 0) + pm.ngammas = 2U, pm.test_gamma_threshold = 1; + else if (strcmp(*argv, "--nogamma-threshold") == 0) - pm.test_threshold = 0; + pm.test_gamma_threshold = 0; + + else if (strcmp(*argv, "--gamma-transform") == 0) + pm.ngammas = 2U, pm.test_gamma_transform = 1; else if (strcmp(*argv, "--nogamma-transform") == 0) - pm.test_transform = 0; + pm.test_gamma_transform = 0; + + else if (strcmp(*argv, "--gamma-sbit") == 0) + pm.ngammas = 2U, pm.test_gamma_sbit = 1; else if (strcmp(*argv, "--nogamma-sbit") == 0) - pm.test_sbit = 0; + pm.test_gamma_sbit = 0; + + else if (strcmp(*argv, "--gamma-16-to-8") == 0) + pm.ngammas = 2U, pm.test_gamma_strip16 = 1; else if (strcmp(*argv, "--nogamma-16-to-8") == 0) - pm.test_strip16 = 0; + pm.test_gamma_strip16 = 0; + + else if (strcmp(*argv, "--all-gammas") == 0) + pm.ngammas = (sizeof gammas)/(sizeof gammas[0]); else if (strcmp(*argv, "--progressive-read") == 0) pm.this.progressive = 1; @@ -4657,8 +6517,39 @@ exit(1); } } + /* If pngvalid is run with no arguments default to a reasonable set of the + * tests. + */ + if (pm.test_standard == 0 && pm.test_size == 0 && pm.test_transform == 0 && + pm.ngammas == 0) + { + pm.test_standard = 1; + pm.test_size = 1; + pm.test_transform = 1; + pm.ngammas = 3U; + } + + if (pm.ngammas > 0 && + pm.test_gamma_threshold == 0 && pm.test_gamma_transform == 0 && + pm.test_gamma_sbit == 0 && pm.test_gamma_strip16 == 0) + { + pm.test_gamma_threshold = 1; + pm.test_gamma_transform = 1; + pm.test_gamma_sbit = 1; + pm.test_gamma_strip16 = 1; + } + + else if (pm.ngammas == 0) + { + /* Nothing to test so turn everything off: */ + pm.test_gamma_threshold = 0; + pm.test_gamma_transform = 0; + pm.test_gamma_sbit = 0; + pm.test_gamma_strip16 = 0; + } + Try { /* Make useful base images */ make_transform_images(&pm.this); @@ -4677,8 +6568,12 @@ make_size_images(&pm.this); perform_size_test(&pm); } + /* Combinatorial transforms: */ + if (pm.test_transform) + perform_transform_test(&pm); + if (pm.ngammas > 0) perform_gamma_test(&pm, pm.this.speed != 0, summary && !pm.this.speed); } diff -ru4NwbB libpng-1.5.0/pngwrite.c libpng-1.5.1/pngwrite.c --- libpng-1.5.0/pngwrite.c 2011-01-22 16:39:23.281181870 -0600 +++ libpng-1.5.1/pngwrite.c 2011-02-02 22:58:17.853713669 -0600 @@ -1,8 +1,8 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.1 [February 3, 2011] * Copyright (c) 1998-2011 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.) * @@ -782,9 +782,10 @@ png_debug1(3, "row_info->width = %u", png_ptr->row_info.width); png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels); png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth); png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth); - png_debug1(3, "row_info->rowbytes = %u", png_ptr->row_info.rowbytes); + png_debug1(3, "row_info->rowbytes = %lu", + (unsigned long)png_ptr->row_info.rowbytes); /* Copy user's row into buffer, leaving room for filter byte. */ png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes); diff -ru4NwbB libpng-1.5.0/scripts/list libpng-1.5.1/scripts/list --- libpng-1.5.0/scripts/list 1969-12-31 18:00:00.000000000 -0600 +++ libpng-1.5.1/scripts/list 2011-01-21 19:15:59.267949000 -0600 @@ -0,0 +1,23 @@ +vers.dfn +symbols.dfn +sym.dfn +pnglibconf.h.prebuilt +pnglibconf.dfa +options.awk +makefile.netbsd +makefile.solaris-x86 +makefile.solaris +makefile.so9 +makefile.sgi +makefile.sggcc +makefile.openbsd +makefile.sco +makefile.linux +makefile.hpux +makefile.hpgcc +makefile.elf +makefile.dec +makefile.beos +makefile.64sunu +makefile.32sunu +def.dfn diff -ru4NwbB libpng-1.5.0/scripts/makefile.32sunu libpng-1.5.1/scripts/makefile.32sunu --- libpng-1.5.0/scripts/makefile.32sunu 2011-01-22 16:39:25.237249495 -0600 +++ libpng-1.5.1/scripts/makefile.32sunu 2011-02-02 22:58:20.573240754 -0600 @@ -1,7 +1,7 @@ # makefile for libpng on Solaris 2.x with cc # Contributed by William L. Sebok, based on makefile.linux -# Copyright (C) 2002, 2006, 2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2006, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1998 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.64sunu libpng-1.5.1/scripts/makefile.64sunu --- libpng-1.5.0/scripts/makefile.64sunu 2011-01-22 16:39:25.248534094 -0600 +++ libpng-1.5.1/scripts/makefile.64sunu 2011-02-02 22:58:20.583478550 -0600 @@ -1,7 +1,7 @@ # makefile for libpng on Solaris 2.x with cc # Contributed by William L. Sebok, based on makefile.linux -# Copyright (C) 2002, 2006, 2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2006, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1998 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.beos libpng-1.5.1/scripts/makefile.beos --- libpng-1.5.0/scripts/makefile.beos 2011-01-22 16:39:25.279062342 -0600 +++ libpng-1.5.1/scripts/makefile.beos 2011-02-02 22:58:20.612177744 -0600 @@ -1,7 +1,7 @@ # makefile for libpng on BeOS x86 ELF with gcc # modified from makefile.linux by Sander Stoks -# Copyright (C) 2002, 2006, 2008, 2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2006, 2008, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1999 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger # # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.darwin libpng-1.5.1/scripts/makefile.darwin --- libpng-1.5.0/scripts/makefile.darwin 2011-01-22 16:39:25.309588796 -0600 +++ libpng-1.5.1/scripts/makefile.darwin 2011-02-02 22:58:20.641764764 -0600 @@ -1,6 +1,6 @@ # makefile for libpng on Darwin / Mac OS X -# Copyright (C) 2002, 2004, 2006, 2008, 2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2004, 2006, 2008, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 2001 Christoph Pfisterer # derived from makefile.linux: # Copyright (C) 1998, 1999 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger diff -ru4NwbB libpng-1.5.0/scripts/makefile.dec libpng-1.5.1/scripts/makefile.dec --- libpng-1.5.0/scripts/makefile.dec 2011-01-22 16:39:25.320129108 -0600 +++ libpng-1.5.1/scripts/makefile.dec 2011-02-02 22:58:20.652558141 -0600 @@ -1,6 +1,6 @@ # makefile for libpng on DEC Alpha Unix -# Copyright (C) 2000-2002, 2006, 2010 Glenn Randers-Pehrson +# Copyright (C) 2000-2002, 2006, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. # # This code is released under the libpng license. # For conditions of distribution and use, see the disclaimer diff -ru4NwbB libpng-1.5.0/scripts/makefile.dj2 libpng-1.5.1/scripts/makefile.dj2 --- libpng-1.5.0/scripts/makefile.dj2 2011-01-22 16:39:25.329615334 -0600 +++ libpng-1.5.1/scripts/makefile.dj2 2011-02-02 22:58:20.662676029 -0600 @@ -1,6 +1,6 @@ # DJGPP (DOS gcc) makefile for libpng -# Copyright (C) 2002, 2006, 2009-2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2006, 2009-2010-2011 Glenn Randers-Pehrson # Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. # # This code is released under the libpng license. # For conditions of distribution and use, see the disclaimer diff -ru4NwbB libpng-1.5.0/scripts/makefile.elf libpng-1.5.1/scripts/makefile.elf --- libpng-1.5.0/scripts/makefile.elf 2011-01-22 16:39:25.340558448 -0600 +++ libpng-1.5.1/scripts/makefile.elf 2011-02-02 22:58:20.674084442 -0600 @@ -1,6 +1,6 @@ # makefile for libpng.a and libpng%N%.so on Linux ELF with gcc -# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010 Greg Roelofs +# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010-2011 Greg Roelofs # and Glenn Randers-Pehrson # Copyright (C) 1996, 1997 Andreas Dilger # # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.hp64 libpng-1.5.1/scripts/makefile.hp64 --- libpng-1.5.0/scripts/makefile.hp64 2011-01-22 16:39:25.370160292 -0600 +++ libpng-1.5.1/scripts/makefile.hp64 2011-02-02 22:58:20.703236394 -0600 @@ -1,6 +1,6 @@ # makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product. -# Copyright (C) 1999-2002, 2006, 2009, 2010 Glenn Randers-Pehrson +# Copyright (C) 1999-2002, 2006, 2009, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1995 Guy Eric Schalnat, Group 42 # contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard # # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.hpgcc libpng-1.5.1/scripts/makefile.hpgcc --- libpng-1.5.0/scripts/makefile.hpgcc 2011-01-22 16:39:25.380908154 -0600 +++ libpng-1.5.1/scripts/makefile.hpgcc 2011-02-02 22:58:20.713729669 -0600 @@ -1,6 +1,6 @@ # makefile for libpng on HP-UX using GCC with the HP ANSI/C linker. -# Copyright (C) 2002, 2006-2008, 2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2006-2008, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 2001, Laurent faillie # Copyright (C) 1998, 1999 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger # diff -ru4NwbB libpng-1.5.0/scripts/makefile.hpux libpng-1.5.1/scripts/makefile.hpux --- libpng-1.5.0/scripts/makefile.hpux 2011-01-22 16:39:25.391393843 -0600 +++ libpng-1.5.1/scripts/makefile.hpux 2011-02-02 22:58:20.724463153 -0600 @@ -1,6 +1,6 @@ # makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product. -# Copyright (C) 1999-2002, 2006, 2010 Glenn Randers-Pehrson +# Copyright (C) 1999-2002, 2006, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1995 Guy Eric Schalnat, Group 42 # contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard # # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.linux libpng-1.5.1/scripts/makefile.linux --- libpng-1.5.0/scripts/makefile.linux 2011-01-22 16:39:25.430684028 -0600 +++ libpng-1.5.1/scripts/makefile.linux 2011-02-02 22:58:20.763263794 -0600 @@ -1,6 +1,6 @@ # makefile for libpng.a and libpng%N%.so on Linux ELF with gcc -# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010 Greg Roelofs and +# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010-2011 Greg Roelofs and # Glenn Randers-Pehrson # Copyright (C) 1996, 1997 Andreas Dilger # # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.sco libpng-1.5.1/scripts/makefile.sco --- libpng-1.5.0/scripts/makefile.sco 2011-01-22 16:39:25.488570529 -0600 +++ libpng-1.5.1/scripts/makefile.sco 2011-02-02 22:58:20.819145295 -0600 @@ -1,8 +1,8 @@ # makefile for SCO OSr5 ELF and Unixware 7 with Native cc # Contributed by Mike Hopkirk (hops@sco.com) modified from Makefile.lnx # force ELF build dynamic linking, SONAME setting in lib and RPATH in app -# Copyright (C) 2002, 2006, 2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2006, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1998 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger # # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.sggcc libpng-1.5.1/scripts/makefile.sggcc --- libpng-1.5.0/scripts/makefile.sggcc 2011-01-22 16:39:25.499590966 -0600 +++ libpng-1.5.1/scripts/makefile.sggcc 2011-02-02 22:58:20.829279297 -0600 @@ -1,6 +1,6 @@ # makefile for libpng.a and libpng%N%.so, SGI IRIX with 'cc' -# Copyright (C) 2001-2002, 2006, 2010 Glenn Randers-Pehrson +# Copyright (C) 2001-2002, 2006, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. # # This code is released under the libpng license. # For conditions of distribution and use, see the disclaimer diff -ru4NwbB libpng-1.5.0/scripts/makefile.sgi libpng-1.5.1/scripts/makefile.sgi --- libpng-1.5.0/scripts/makefile.sgi 2011-01-22 16:39:25.510589507 -0600 +++ libpng-1.5.1/scripts/makefile.sgi 2011-02-02 22:58:20.839669536 -0600 @@ -1,6 +1,6 @@ # makefile for libpng.a and libpng%N%.so, SGI IRIX with 'cc' -# Copyright (C) 2001-2002, 2006, 2007, 2010 Glenn Randers-Pehrson +# Copyright (C) 2001-2002, 2006, 2007, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. # # This code is released under the libpng license. # For conditions of distribution and use, see the disclaimer diff -ru4NwbB libpng-1.5.0/scripts/makefile.so9 libpng-1.5.1/scripts/makefile.so9 --- libpng-1.5.0/scripts/makefile.so9 2011-01-22 16:39:25.521470979 -0600 +++ libpng-1.5.1/scripts/makefile.so9 2011-02-02 22:58:20.850042813 -0600 @@ -1,8 +1,8 @@ # makefile for libpng on Solaris 9 (beta) with Forte cc # Updated by Chad Schrock for Solaris 9 # Contributed by William L. Sebok, based on makefile.linux -# Copyright (C) 2002, 2006, 2008, 2010 Glenn Randers-Pehrson +# Copyright (C) 2002, 2006, 2008, 2010-2011 Glenn Randers-Pehrson # Copyright (C) 1998-2001 Greg Roelofs # Copyright (C) 1996-1997 Andreas Dilger # # This code is released under the libpng license. diff -ru4NwbB libpng-1.5.0/scripts/makefile.solaris libpng-1.5.1/scripts/makefile.solaris --- libpng-1.5.0/scripts/makefile.solaris 2011-01-22 16:39:25.532506227 -0600 +++ libpng-1.5.1/scripts/makefile.solaris 2011-02-02 22:58:20.860326335 -0600 @@ -1,6 +1,6 @@ # makefile for libpng on Solaris 2.x with gcc -# Copyright (C) 2004, 2006-2008, 2010 Glenn Randers-Pehrson +# Copyright (C) 2004, 2006-2008, 2010-2011 Glenn Randers-Pehrson # Contributed by William L. Sebok, based on makefile.linux # Copyright (C) 1998 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger # diff -ru4NwbB libpng-1.5.0/scripts/makefile.solaris-x86 libpng-1.5.1/scripts/makefile.solaris-x86 --- libpng-1.5.0/scripts/makefile.solaris-x86 2011-01-22 16:39:25.543324227 -0600 +++ libpng-1.5.1/scripts/makefile.solaris-x86 2011-02-02 22:58:20.870776374 -0600 @@ -1,6 +1,6 @@ # makefile for libpng on Solaris 2.x with gcc -# Copyright (C) 2004, 2006-2008, 2010 Glenn Randers-Pehrson +# Copyright (C) 2004, 2006-2008, 2010-2011 Glenn Randers-Pehrson # Contributed by William L. Sebok, based on makefile.linux # Copyright (C) 1998 Greg Roelofs # Copyright (C) 1996, 1997 Andreas Dilger diff -ru4NwbB libpng-1.5.0/scripts/options.awk libpng-1.5.1/scripts/options.awk --- libpng-1.5.0/scripts/options.awk 2011-01-06 06:22:09.000000000 -0600 +++ libpng-1.5.1/scripts/options.awk 2011-01-21 19:19:11.118462000 -0600 @@ -2,9 +2,9 @@ # scripts/options.awk - library build configuration control # # last changed in libpng version 1.5.0 - January 6, 2011 # -# Copyright (c) 1998-2010 Glenn Randers-Pehrson +# Copyright (c) 1998-2011 Glenn Randers-Pehrson # # This code is released under the libpng license. # For conditions of distribution and use, see the disclaimer # and license in png.h diff -ru4NwbB libpng-1.5.0/scripts/pnglibconf.dfa libpng-1.5.1/scripts/pnglibconf.dfa --- libpng-1.5.0/scripts/pnglibconf.dfa 2011-01-06 06:22:21.000000000 -0600 +++ libpng-1.5.1/scripts/pnglibconf.dfa 2011-01-22 18:03:50.437008000 -0600 @@ -7,9 +7,9 @@ com pnglibconf.h - library build configuration com com libpng version 1.5.0 - January 6, 2011 com -com Copyright (c) 1998-2010 Glenn Randers-Pehrson +com Copyright (c) 1998-2011 Glenn Randers-Pehrson com com This code is released under the libpng license. com For conditions of distribution and use, see the disclaimer com and license in png.h @@ -379,10 +379,12 @@ option WRITE_WEIGHTED_FILTER requires WRITE option WRITE_FLUSH requires WRITE -# Note: this can be turned off explicitly, is this correct? +# Note: these can be turned off explicitly if not required by the +# apps implementing the user transforms option USER_TRANSFORM_PTR if READ_USER_TRANSFORM WRITE_USER_TRANSFORM +option USER_TRANSFORM_INFO if READ_USER_TRANSFORM WRITE_USER_TRANSFORM # Any chunks you are not interested in, you can undef here. The # ones that allocate memory may be expecially important (hIST, # tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info diff -ru4NwbB libpng-1.5.0/scripts/pnglibconf.h.prebuilt libpng-1.5.1/scripts/pnglibconf.h.prebuilt --- libpng-1.5.0/scripts/pnglibconf.h.prebuilt 2011-01-06 06:22:24.000000000 -0600 +++ libpng-1.5.1/scripts/pnglibconf.h.prebuilt 2011-01-22 18:03:50.445714000 -0600 @@ -4,9 +4,9 @@ /* pnglibconf.h - library build configuration */ /* libpng version 1.5.0 - last changed on January 6, 2011 */ -/* Copyright (c) 1998-2010 Glenn Randers-Pehrson */ +/* Copyright (c) 1998-2011 Glenn Randers-Pehrson */ /* This code is released under the libpng license. */ /* For conditions of distribution and use, see the disclaimer */ /* and license in png.h */ @@ -154,8 +154,9 @@ #define PNG_tRNS_SUPPORTED #define PNG_WRITE_iTXt_SUPPORTED #define PNG_oFFs_SUPPORTED #define PNG_USER_TRANSFORM_PTR_SUPPORTED +#define PNG_USER_TRANSFORM_INFO_SUPPORTED #define PNG_hIST_SUPPORTED #define PNG_iCCP_SUPPORTED #define PNG_sRGB_SUPPORTED #define PNG_READ_zTXt_SUPPORTED diff -ru4NwbB libpng-1.5.0/scripts/sym.dfn libpng-1.5.1/scripts/sym.dfn --- libpng-1.5.0/scripts/sym.dfn 2011-01-06 06:22:30.000000000 -0600 +++ libpng-1.5.1/scripts/sym.dfn 2011-01-21 19:20:38.137477000 -0600 @@ -1,9 +1,9 @@ /* sym.dfn - define format of libpng.sym * * Last changed in libpng version 1.5.0 [January 6, 2011] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer * and license in png.h diff -ru4NwbB libpng-1.5.0/scripts/symbols.def libpng-1.5.1/scripts/symbols.def --- libpng-1.5.0/scripts/symbols.def 2011-01-22 16:39:25.613428484 -0600 +++ libpng-1.5.1/scripts/symbols.def 2011-02-02 22:58:20.937934664 -0600 @@ -220,4 +220,9 @@ png_get_y_offset_inches_fixed @212 png_set_sCAL_fixed @213 png_get_sCAL_fixed @214 png_set_background_fixed @215 + png_get_io_chunk_type @216 + png_get_current_row_number @217 + png_get_current_pass_number @218 + png_process_data_pause @219 + png_process_data_skip @220 diff -ru4NwbB libpng-1.5.0/scripts/symbols.dfn libpng-1.5.1/scripts/symbols.dfn --- libpng-1.5.0/scripts/symbols.dfn 2011-01-06 06:22:36.000000000 -0600 +++ libpng-1.5.1/scripts/symbols.dfn 2011-01-21 19:20:45.009192000 -0600 @@ -1,9 +1,9 @@ /* symbols.dfn - find all exported symbols * * Last changed in libpng version 1.5.0 [January 6, 2011] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer * and license in png.h diff -ru4NwbB libpng-1.5.0/scripts/vers.dfn libpng-1.5.1/scripts/vers.dfn --- libpng-1.5.0/scripts/vers.dfn 2011-01-06 06:22:40.000000000 -0600 +++ libpng-1.5.1/scripts/vers.dfn 2011-01-21 19:20:50.137645000 -0600 @@ -1,9 +1,9 @@ /* vers.dfn - define format of libpng.vers * * Last changed in libpng version 1.5.0 [January 6, 2011] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer * and license in png.h