Changeset 1165


Ignore:
Timestamp:
Sep 15, 2015, 12:22:09 PM (10 years ago)
Author:
Silvan Scherrer
Message:

libpng: update vendor to 1.6.18, add removed files from 1.6.16 commit again

Location:
libpng/vendor/current
Files:
16 added
66 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified libpng/vendor/current/ANNOUNCE

    r1059 r1165  
    1 Libpng 1.6.16 - December 22, 2014
     1Libpng 1.6.18 - July 23, 2015
    22
    33This is a public release of libpng, intended for use in production codes.
     
    88"configure" script
    99
    10    libpng-1.6.16.tar.xz (LZMA-compressed, recommended)
    11    libpng-1.6.16.tar.gz
     10   libpng-1.6.18.tar.xz (LZMA-compressed, recommended)
     11   libpng-1.6.18.tar.gz
    1212
    1313Source files with CRLF line endings (for Windows), without the
    1414"configure" script
    1515
    16    lpng1616.7z  (LZMA-compressed, recommended)
    17    lpng1616.zip
     16   lpng1618.7z  (LZMA-compressed, recommended)
     17   lpng1618.zip
    1818
    1919Other information:
    2020
    21    libpng-1.6.16-README.txt
    22    libpng-1.6.16-LICENSE.txt
    23    libpng-1.6.16-*.asc (armored detached GPG signatures)
     21   libpng-1.6.18-README.txt
     22   libpng-1.6.18-LICENSE.txt
     23   libpng-1.6.18-*.asc (armored detached GPG signatures)
    2424
    25 Changes since the last public release (1.6.15):
    26   Added ".align 2" to arm/filter_neon.S to support old GAS assemblers that
    27     don't do alignment correctly.
    28   Revised Makefile.am and scripts/*.dfn to work with MinGW/MSYS;
    29     renamed scripts/*.dfn to scripts/*.c (Bob Friesenhahn and John Bowler).
    30   Quiet a "comparison always true" warning in pngstest.c (John Bowler).
    31   Restored a test on width that was removed from png.c at libpng-1.6.9
    32     (Bug report by Alex Eubanks).
    33   Fixed an overflow in png_combine_row with very wide interlaced images.
     25Changes since the last public release (1.6.17):
     26  Removed PNG_SET_CHUNK_[CACHE|MALLOC]_LIMIT_SUPPORTED macros.  They
     27    have been combined with PNG_SET_USER_LIMITS_SUPPORTED (resolves
     28    bug report by Andrew Church).
     29  Fixed rgb_to_gray checks and added tRNS checks to pngvalid.c.  This
     30    fixes some arithmetic errors that caused some tests to fail on
     31    some 32-bit platforms (Bug reports by Peter Breitenlohner [i686]
     32    and Petr Gajdos [i586]).
     33  Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler
     34    (Bug report by Viktor Szaka'ts).
     35  Replaced "unexpected" with an integer (0xabadca11) in pngset.c
     36    where a long was expected, to avoid a compiler warning when PNG_DEBUG > 1.
     37  Added contrib/examples/simpleover.c, to demonstrate how to handle
     38    alpha compositing of multiple images, using the "simplified API"
     39    and an example PNG generation tool, contrib/examples/genpng.c
     40    (John Bowler).
     41  PNG_RELEASE_BUILD replaces tests where the code depended on the build base
     42    type and can be defined on the command line, allowing testing in beta
     43    builds (John Bowler).
     44  Avoid Coverity issue 80858 (REVERSE NULL) in pngtest.c
     45  Avoid a harmless potential integer overflow in png_XYZ_from_xy() (Bug
     46    report from Christopher Ferris).
     47  Backport filter selection code from libpng-1.7.0beta51, to combine
     48    sub_row, up_row, avg_row, and paeth_row into try_row and tst_row.
     49  Changed png_voidcast(), etc., to voidcast(), etc., in contrib/tools/pngfix.c
     50    to avoid confusion with the libpng private macros.
     51  Fixed old cut&paste bug in the weighted filter selection code in
     52    pngwutil.c, introduced in libpng-0.95, March 1997.
     53  Removed WRITE_WEIGHTED_FILTERED code, to save a few kbytes of the
     54    compiled library size. It never worked properly and as far as we can
     55    tell, no one uses it. The png_set_filter_heuristics() and
     56    png_set_filter_heuristics_fixed() APIs are retained but deprecated
     57    and do nothing.
     58  Quieted some Coverity issues in pngfix.c, png-fix-itxt.c, pngvalid.c,
     59    pngstest.c, and pngimage.c. Most seem harmless, but png-fix-itxt
     60    would only work with iTXt chunks with length 255 or less.
     61  Removed non-working progressive reader 'skip' function. This
     62    function has apparently never been used. It was implemented
     63    to support back-door modification of png_struct in libpng-1.4.x
     64    but (because it does nothing and cannot do anything) was apparently
     65    never tested (John Bowler).
     66  Fixed cexcept.h in which GCC 5 now reports that one of the auto
     67    variables in the Try macro needs to be volatile to prevent value
     68    being lost over the setjmp (John Bowler).
     69  Added #ifdef's to contrib/examples programs so people don't try
     70    to compile them without the minimum required support enabled
     71    (suggested by Flavio Medeiros).
     72  Eliminated the final two Coverity defects (insecure temporary file
     73    handling in contrib/libtests/pngstest.c; possible overflow of
     74    unsigned char in contrib/tools/png-fix-itxt.c). To use the "secure"
     75    file handling, define PNG_USE_MKSTEMP, otherwise "tmpfile()" will
     76    be used.
     77  Removed some unused WEIGHTED_FILTER macros from pngstruct.h
     78  Replaced arbitrary use of 'extern' with #define PNG_LINKAGE_*.  To
     79    preserve API compatibility, the new defines all default to "extern"
     80    (requested by Jan Nijtmans).
     81  Belatedly added Mans Rullgard and James Yu to the list of Contributing
     82    Authors.
    3483
    3584Send comments/corrections/commendations to png-mng-implement at lists.sf.net
  • TabularUnified libpng/vendor/current/CHANGES

    r1059 r1165  
    1 
     1#if 0
    22CHANGES - changes for libpng
    33
    4 Version 0.2
     4version 0.1 [March 29, 1995]
     5  initial work-in-progress release
     6
     7version 0.2 [April 1, 1995]
    58  added reader into png.h
    69  fixed small problems in stub file
    710
    8 Version 0.3
     11version 0.3 [April 8, 1995]
    912  added pull reader
    1013  split up pngwrite.c to several files
     
    1518  interfaced with zlib 0.5
    1619  added K&R support
    17   added check for 64 KB blocks for 16-bit machines
    18 
    19 Version 0.4
     20  added check for 64 KB blocks for 16 bit machines
     21
     22version 0.4 [April 26, 1995]
    2023  cleaned up code and commented code
    2124  simplified time handling into png_time
     
    2831  split transformations into pngrtran.c and pngwtran.c
    2932
    30 Version 0.5
     33version 0.5 [April 30, 1995]
    3134  interfaced with zlib 0.8
    3235  fixed many reading and writing bugs
    3336  saved using 3 spaces instead of tabs
    3437
    35 Version 0.6
     38version 0.6 [May 1, 1995]
     39  first beta release
    3640  added png_large_malloc() and png_large_free()
    3741  added png_size_t
     
    3943  added png_start_read_image()
    4044
    41 Version 0.7
     45version 0.7 [June 24, 1995]
    4246  cleaned up lots of bugs
    4347  finished dithering and other stuff
     
    4549  changed name from pnglib to libpng
    4650
    47 Version 0.71 [June, 1995]
     51version 0.71 [June 26, 1995]
    4852  changed pngtest.png for zlib 0.93
    4953  fixed error in libpng.txt and example.c
    5054
    51 Version 0.8
     55version 0.8 [August 20, 1995]
    5256  cleaned up some bugs
    5357  added png_set_filler()
     
    9296  added callbacks for read/write and warning/error functions
    9397
    94 Version 0.89 [July, 1996]
     98Version 0.89 [June 5, 1996]
    9599  Added new initialization API to make libpng work better with shared libs
    96100    we now have png_create_read_struct(), png_create_write_struct(),
     
    119123  Updated documentation to reflect new API
    120124
     125Version 0.89c [June 17, 1996]
     126  Bug fixes.
     127
    121128Version 0.90 [January, 1997]
    122129  Made CRC errors/warnings on critical and ancillary chunks configurable
     
    159166  Added experimental filter selection weighting (Greg Roelofs)
    160167  Removed old png_set_rgbx() and png_set_xrgb() functions that have been
    161      obsolete for about 2 years now (use png_set_filler() instead)
     168    obsolete for about 2 years now (use png_set_filler() instead)
    162169  Added macros to read 16- and 32-bit ints directly from buffer, to be
    163170    used only on those systems that support it (namely PowerPC and 680x0)
     
    441448Version 1.0.3a [August 12, 1999]
    442449  Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
    443      if an attempt is made to read an interlaced image when it's not supported.
     450    if an attempt is made to read an interlaced image when it's not supported.
    444451  Added check if png_ptr->trans is defined before freeing it in pngread.c
    445452  Modified the Y2K statement to include versions back to version 0.71
     
    449456  Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents.
    450457  Changed (float)red and (float)green to (double)red, (double)green
    451      in png_set_rgb_to_gray() to avoid "promotion" problems in AIX.
     458    in png_set_rgb_to_gray() to avoid "promotion" problems in AIX.
    452459  Fixed a bug in pngconf.h that omitted <stdio.h> when PNG_DEBUG==0 (K Bracey).
    453460  Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt).
     
    492499  Added a demo read_user_transform_fn that examines the row filters in pngtest.c
    493500
    494 Version 1.0.4 [September 24, 1999]
     501Version 1.0.4 [September 24, 1999, not distributed publicly]
    495502  Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined
    496503  Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h
     
    519526    a helpful compiler error if an old png.h is found in the search path.
    520527  Changed type of png_user_transform_depth|channels from int to png_byte.
     528  Added "Libpng is OSI Certified Open Source Software" statement to png.h
    521529
    522530Version 1.0.4d [October 6, 1999]
     
    905913  Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks.
    906914  Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and
    907      pngwutil.c.
     915    pngwutil.c.
    908916  Changed PNG_EXPORT_VAR to use PNG_IMPEXP, in pngconf.h.
    909917  Removed unused "#include <assert.h>" from png.c
     
    913921Version 1.0.8beta2 [July 10, 2000]
    914922  Added project files to the wince directory and made further revisions
    915      of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE.
     923    of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE.
    916924
    917925Version 1.0.8beta3 [July 11, 2000]
    918926  Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS()
    919      for indexed-color input files to avoid potential double-freeing trans array
    920      under some unusual conditions; problem was introduced in version 1.0.6f.
     927    for indexed-color input files to avoid potential double-freeing trans array
     928    under some unusual conditions; problem was introduced in version 1.0.6f.
    921929  Further revisions to pngtest.c and files in the wince subdirectory.
    922930
     
    10901098Version 1.2.0beta4 [June 23, 2001]
    10911099  Check for missing profile length field in iCCP chunk and free chunk_data
    1092      in case of truncated iCCP chunk.
     1100    in case of truncated iCCP chunk.
    10931101  Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc
    10941102  Bumped dll-number from 2 to 3 in makefile.cygwin
    10951103  Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly
    1096      if user attempts to run it on an 8-bit display.
     1104    if user attempts to run it on an 8-bit display.
    10971105  Updated contrib/gregbook
    10981106  Use png_malloc instead of png_zalloc to allocate palette in pngset.c
    10991107  Updated makefile.ibmc
    11001108  Added some typecasts to eliminate gcc 3.0 warnings.  Changed prototypes
    1101      of png_write_oFFS width and height from png_uint_32 to png_int_32.
     1109    of png_write_oFFS width and height from png_uint_32 to png_int_32.
    11021110  Updated example.c
    11031111  Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c
     
    11071115  Revised makefile.gcmmx
    11081116  Revised pnggccrd.c to conditionally compile some thread-unsafe code only
    1109      when PNG_THREAD_UNSAFE_OK is defined.
     1117    when PNG_THREAD_UNSAFE_OK is defined.
    11101118  Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with
    1111      value exceeding 2^bit_depth-1
     1119    value exceeding 2^bit_depth-1
    11121120  Revised makefile.sgi and makefile.sggcc
    11131121  Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c
     
    14501458
    14511459Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004]
    1452   Fixed buffer overflow vulnerability in png_handle_tRNS()
    1453   Fixed integer arithmetic overflow vulnerability in png_read_png().
     1460  Fixed buffer overflow vulnerability (CVE-2004-0597) in png_handle_tRNS().
     1461  Fixed NULL dereference vulnerability (CVE-2004-0598) in png_handle_iCCP().
     1462  Fixed integer overflow vulnerability (CVE-2004-0599) in png_read_png().
    14541463  Fixed some harmless bugs in png_handle_sBIT, etc, that would cause
    14551464    duplicate chunk types to go undetected.
     
    14941503Version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004]
    14951504  Moved  "PNG_HANDLE_CHUNK_*" macros out of PNG_ASSEMBLER_CODE_SUPPORTED
    1496      section of png.h where they were inadvertently placed in version rc3.
     1505    section of png.h where they were inadvertently placed in version rc3.
    14971506
    14981507Version 1.2.6 and 1.0.16 [August 15, 2004]
     
    21032112  Put a call to png_check_chunk_name() in png_read_chunk_header().
    21042113  Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte.
    2105   Removed two calls to png_check_chunk_name() occuring later in the process.
     2114  Removed two calls to png_check_chunk_name() occurring later in the process.
    21062115  Define PNG_NO_ERROR_NUMBERS by default in pngconf.h
    21072116
     
    23262335  Eliminated PNG_LEGACY_SUPPORTED code.
    23272336  Moved the various unknown chunk macro definitions outside of the
    2328      PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks.
     2337    PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks.
    23292338
    23302339Version 1.4.0beta65 [June 26, 2009]
     
    45264535    the need to call png_set_keep_unknown_chunks() when writing them.
    45274536  Avoid dereferencing NULL pointer possibly returned from
    4528      png_create_write_struct() (Andrew Church).
     4537    png_create_write_struct() (Andrew Church).
    45294538
    45304539Version 1.6.3beta05 [May 9, 2013]
     
    51155124Version 1.6.16rc01 [December 21, 2014]
    51165125  Restored a test on width that was removed from png.c at libpng-1.6.9
    5117     (Bug report by Alex Eubanks).
     5126    (Bug report by Alex Eubanks, CVE-2015-0973).
    51185127
    51195128Version 1.6.16rc02 [December 21, 2014]
     
    51215130
    51225131Version 1.6.16rc03 [December 21, 2014]
    5123   Fixed an overflow in png_combine_row with very wide interlaced images.
     5132  Fixed an overflow in png_combine_row() with very wide interlaced images
     5133    (Bug report and fix by John Bowler, CVE-2014-9495).
    51245134
    51255135Version 1.6.16 [December 22, 2014]
     5136  No changes.
     5137
     5138Version 1.6.17beta01 [January 29, 2015]
     5139  Removed duplicate PNG_SAFE_LIMITS_SUPPORTED handling from pngconf.h
     5140  Corrected the width limit calculation in png_check_IHDR().
     5141  Removed user limits from pngfix. Also pass NULL pointers to
     5142    png_read_row to skip the unnecessary row de-interlace stuff.
     5143  Added testing of png_set_packing() to pngvalid.c
     5144  Regenerated configure scripts in the *.tar distributions with libtool-2.4.4
     5145  Implement previously untested cases of libpng transforms in pngvalid.c
     5146  Fixed byte order in 2-byte filler, in png_do_read_filler().
     5147  Made the check for out-of-range values in png_set_tRNS() detect
     5148    values that are exactly 2^bit_depth, and work on 16-bit platforms.
     5149  Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47.
     5150  Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
     5151    pngset.c to avoid warnings about dead code.
     5152  Added "& 0xff" to many instances of expressions that are typecast
     5153    to (png_byte), to avoid Coverity warnings.
     5154
     5155Version 1.6.17beta02 [February 7, 2015]
     5156  Work around one more Coverity-scan dead-code warning.
     5157  Do not build png_product2() when it is unused.
     5158
     5159Version 1.6.17beta03 [February 17, 2015]
     5160  Display user limits in the output from pngtest.
     5161  Eliminated the PNG_SAFE_LIMITS macro and restored the 1-million-column
     5162    and 1-million-row default limits in pnglibconf.dfa, that can be reset
     5163    by the user at build time or run time.  This provides a more robust
     5164    defense against DOS and as-yet undiscovered overflows.
     5165
     5166Version 1.6.17beta04 [February 21, 2015]
     5167  Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default.
     5168  Allow user to call png_get_IHDR() with NULL arguments (Reuben Hawkins).
     5169  Rebuilt configure scripts with automake-1.15 and libtool-2.4.6
     5170
     5171Version 1.6.17beta05 [February 25, 2015]
     5172  Restored compiling of png_reciprocal2 with PNG_NO_16BIT.
     5173
     5174Version 1.6.17beta06 [February 27, 2015]
     5175  Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block
     5176    of png.h.
     5177  Avoid runtime checks when converting integer to png_byte with
     5178    Visual Studio (Sergey Kosarevsky)
     5179
     5180Version 1.6.17rc01 [March 4, 2015]
     5181  No changes.
     5182
     5183Version 1.6.17rc02 [March 9, 2015]
     5184  Removed some comments that the configure script did not handle
     5185    properly from scripts/pnglibconf.dfa and pnglibconf.h.prebuilt.
     5186  Free the unknown_chunks structure even when it contains no data.
     5187
     5188Version 1.6.17rc03 [March 12, 2015]
     5189  Updated CMakeLists.txt to add OSX framework, change YES/NO to ON/OFF
     5190    for consistency, and remove some useless tests (Alexey Petruchik).
     5191
     5192Version 1.6.17rc04 [March 16, 2015]
     5193  Remove pnglibconf.h, pnglibconf.c, and pnglibconf.out instead of
     5194    pnglibconf.* in "make clean" (Cosmin).
     5195  Fix bug in calculation of maxbits, in png_write_sBIT, introduced
     5196    in libpng-1.6.17beta01 (John Bowler).
     5197
     5198Version 1.6.17rc05 [March 21, 2015]
     5199  Define PNG_FILTER_* and PNG_FILTER_VALUE_* in png.h even when WRITE
     5200    is not supported (John Bowler).  This fixes an error introduced in
     5201    libpng-1.6.17beta06.
     5202  Reverted "& 0xff" additions of version 1.6.17beta01. Libpng passes
     5203    the Coverity scan without them.
     5204
     5205Version 1.6.17rc06 [March 23, 2015]
     5206  Remove pnglibconf.dfn and pnglibconf.pre with "make clean".
     5207  Reformatted some "&0xff" instances to "& 0xff".
     5208  Fixed simplified 8-bit-linear to sRGB alpha. The calculated alpha
     5209    value was wrong.  It's not clear if this affected the final stored
     5210    value; in the obvious code path the upper and lower 8-bits of the
     5211    alpha value were identical and the alpha was truncated to 8-bits
     5212    rather than dividing by 257 (John Bowler).
     5213
     5214Version 1.6.17 [March 26, 2015]
     5215  No changes.
     5216
     5217Version 1.6.18beta01 [April 1, 2015]
     5218  Removed PNG_SET_CHUNK_[CACHE|MALLOC]_LIMIT_SUPPORTED macros.  They
     5219    have been combined with PNG_SET_USER_LIMITS_SUPPORTED (resolves
     5220    bug report by Andrew Church).
     5221  Fixed rgb_to_gray checks and added tRNS checks to pngvalid.c.  This
     5222    fixes some arithmetic errors that caused some tests to fail on
     5223    some 32-bit platforms (Bug reports by Peter Breitenlohner [i686]
     5224    and Petr Gajdos [i586]).
     5225
     5226Version 1.6.18beta02 [April 26, 2015]
     5227  Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler
     5228    (Bug report by Viktor Szaka'ts).
     5229
     5230Version 1.6.18beta03 [May 6, 2015]
     5231  Replaced "unexpected" with an integer (0xabadca11) in pngset.c
     5232    where a long was expected, to avoid a compiler warning when PNG_DEBUG > 1.
     5233  Added contrib/examples/simpleover.c, to demonstrate how to handle
     5234    alpha compositing of multiple images, using the "simplified API"
     5235    and an example PNG generation tool, contrib/examples/genpng.c
     5236    (John Bowler).
     5237
     5238Version 1.6.18beta04 [May 20, 2015]
     5239  PNG_RELEASE_BUILD replaces tests where the code depended on the build base
     5240    type and can be defined on the command line, allowing testing in beta
     5241    builds (John Bowler).
     5242  Avoid Coverity issue 80858 (REVERSE NULL) in pngtest.c PNG_DEBUG builds.
     5243  Avoid a harmless potential integer overflow in png_XYZ_from_xy() (Bug
     5244    report from Christopher Ferris).
     5245
     5246Version 1.6.18beta05 [May 31, 2015]
     5247  Backport filter selection code from libpng-1.7.0beta51, to combine
     5248    sub_row, up_row, avg_row, and paeth_row into try_row and tst_row.
     5249  Changed png_voidcast(), etc., to voidcast(), etc., in contrib/tools/pngfix.c
     5250    to avoid confusion with the libpng private macros.
     5251  Fixed old cut&paste bug in the weighted filter selection code in
     5252    pngwutil.c, introduced in libpng-0.95, March 1997.
     5253
     5254Version 1.6.18beta06 [June 1, 2015]
     5255  Removed WRITE_WEIGHTED_FILTERED code, to save a few kbytes of the
     5256    compiled library size. It never worked properly and as far as we can
     5257    tell, no one uses it. The png_set_filter_heuristics() and
     5258    png_set_filter_heuristics_fixed() APIs are retained but deprecated
     5259    and do nothing.
     5260
     5261Version 1.6.18beta07 [June 6, 2015]
     5262  Removed non-working progressive reader 'skip' function. This
     5263    function has apparently never been used. It was implemented
     5264    to support back-door modification of png_struct in libpng-1.4.x
     5265    but (because it does nothing and cannot do anything) was apparently
     5266    never tested (John Bowler).
     5267  Fixed cexcept.h in which GCC 5 now reports that one of the auto
     5268    variables in the Try macro needs to be volatile to prevent value
     5269    being lost over the setjmp (John Bowler).
     5270  Fixed NO_WRITE_FILTER and -Wconversion build breaks (John Bowler).
     5271  Fix g++ build breaks (John Bowler).
     5272  Quieted some Coverity issues in pngfix.c, png-fix-itxt.c, pngvalid.c,
     5273    pngstest.c, and pngimage.c. Most seem harmless, but png-fix-itxt
     5274    would only work with iTXt chunks with length 255 or less.
     5275  Added #ifdef's to contrib/examples programs so people don't try
     5276    to compile them without the minimum required support enabled
     5277    (suggested by Flavio Medeiros).
     5278
     5279Version 1.6.18beta08 [June 30, 2015]
     5280  Eliminated the final two Coverity defects (insecure temporary file
     5281    handling in contrib/libtests/pngstest.c; possible overflow of
     5282    unsigned char in contrib/tools/png-fix-itxt.c). To use the "secure"
     5283    file handling, define PNG_USE_MKSTEMP, otherwise "tmpfile()" will
     5284    be used.
     5285  Removed some unused WEIGHTED_FILTER macros from png.h and pngstruct.h
     5286
     5287Version 1.6.18beta09 [July 5, 2015]
     5288  Removed some useless typecasts from contrib/tools/png-fix-itxt.c
     5289  Fixed a new signed-unsigned comparison in pngrtran.c (Max Stepin).
     5290  Replaced arbitrary use of 'extern' with #define PNG_LINKAGE_*.  To
     5291    preserve API compatibility, the new defines all default to "extern"
     5292    (requested by Jan Nijtmans).
     5293
     5294Version 1.6.18rc01 [July 9, 2015]
     5295  Belatedly added Mans Rullgard and James Yu to the list of Contributing
     5296    Authors.
     5297
     5298Version 1.6.18rc02 [July 12, 2015]
     5299  Restored unused FILTER_HEURISTIC macros removed at libpng-1.6.18beta08
     5300    to png.h to avoid compatibility warnings.
     5301
     5302Version 1.6.18rc03 [July 15, 2015]
     5303  Minor changes to the man page
     5304
     5305Version 1.6.18 [July 23, 2015]
    51265306  No changes.
    51275307
     
    51335313
    51345314Glenn R-P
     5315#endif
  • TabularUnified libpng/vendor/current/CMakeLists.txt

    r1059 r1165  
    11# CMakeLists.txt
    22
    3 # Copyright (C) 2007-2014 Glenn Randers-Pehrson
     3# Copyright (C) 2007-2015 Glenn Randers-Pehrson
    44
    55# This code is released under the libpng license.
     
    1717set(PNGLIB_MAJOR 1)
    1818set(PNGLIB_MINOR 6)
    19 set(PNGLIB_RELEASE 16)
     19set(PNGLIB_RELEASE 18)
    2020set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
    2121set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
     
    3131  )
    3232  if(NOT M_LIBRARY)
    33     message(STATUS
    34       "math library 'libm' not found - floating point support disabled")
     33    message(STATUS "math lib 'libm' not found; floating point support disabled")
    3534  endif()
    3635else()
     
    4039
    4140# COMMAND LINE OPTIONS
    42 if(DEFINED PNG_SHARED)
    43   option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
    44 else()
    45   option(PNG_SHARED "Build shared lib" ON)
    46 endif()
    47 if(DEFINED PNG_STATIC)
    48   option(PNG_STATIC "Build static lib" ${PNG_STATIC})
    49 else()
    50   option(PNG_STATIC "Build static lib" ON)
    51 endif()
    52 
    53 option(PNG_TESTS  "Build libpng tests" YES)
     41option(PNG_SHARED "Build shared lib" ON)
     42option(PNG_STATIC "Build static lib" ON)
     43option(PNG_TESTS  "Build libpng tests" ON)
    5444
    5545# Many more configuration options could be added here
    56 option(PNG_DEBUG         "Build with debug output" NO)
    57 option(PNGARG            "Disable ANSI-C prototypes" NO)
     46option(PNG_FRAMEWORK "Build OS X framework" OFF)
     47option(PNG_DEBUG     "Build with debug output" OFF)
     48option(PNGARG        "Disable ANSI-C prototypes" OFF)
    5849
    5950# SET LIBNAME
     
    135126
    136127if(PNG_STATIC)
    137 # does not work without changing name
     128  # does not work without changing name
    138129  set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
    139130  add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
     
    146137endif()
    147138
     139if(PNG_FRAMEWORK)
     140  set(PNG_LIB_NAME_FRAMEWORK ${PNG_LIB_NAME}_framework)
     141  add_library(${PNG_LIB_NAME_FRAMEWORK} SHARED ${libpng_sources})
     142  list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_FRAMEWORK})
     143  set_target_properties(${PNG_LIB_NAME_FRAMEWORK} PROPERTIES
     144    FRAMEWORK TRUE
     145    FRAMEWORK_VERSION ${PNGLIB_VERSION}
     146    MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR}
     147    MACOSX_FRAMEWORK_BUNDLE_VERSION ${PNGLIB_VERSION}
     148    MACOSX_FRAMEWORK_IDENTIFIER org.libpng.libpng
     149    XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
     150    PUBLIC_HEADER "${libpng_public_hdrs}"
     151    OUTPUT_NAME png)
     152  target_link_libraries(${PNG_LIB_NAME_FRAMEWORK} ${ZLIB_LIBRARY} ${M_LIBRARY})
     153endif()
     154
    148155if(NOT PNG_LIB_TARGETS)
    149156  message(SEND_ERROR
    150157    "No library variant selected to build. "
    151     "Please enable at least one of the following options: PNG_STATIC, PNG_SHARED")
     158    "Please enable at least one of the following options: "
     159    " PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK")
    152160endif()
    153161
     
    254262if(PNG_SHARED)
    255263  set_target_properties(${PNG_LIB_NAME} PROPERTIES
    256 #   VERSION 16.${PNGLIB_RELEASE}.1.6.16
     264#   VERSION 16.${PNGLIB_RELEASE}.1.6.18
    257265    VERSION 16.${PNGLIB_RELEASE}.0
    258266    SOVERSION 16
     
    285293      RUNTIME DESTINATION bin
    286294      LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    287       ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
     295      ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
     296      FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
    288297
    289298  if(PNG_SHARED)
  • TabularUnified libpng/vendor/current/INSTALL

    r1059 r1165  
    1818XIII. Removing unwanted object code
    1919 XIV. Changes to the build and configuration of libpng in libpng-1.5.x
    20   XV. Configuring libpng for multiprocessing
     20  XV. Setjmp/longjmp issues
    2121 XVI. Other sources of information about libpng
    2222
     
    190190
    191191You will want to look into zconf.h to tell zlib (and thus libpng) that
    192 it cannot allocate more then 64K at a time.  Even if you can, the memory
     192it cannot allocate more than 64K at a time.  Even if you can, the memory
    193193won't be accessible.  So limit zlib and libpng to 64K by defining MAXSEG_64K.
    194194
     
    363363that were used to build libpng.
    364364
    365 XV. Configuring libpng for multiprocessing
     365XV. Setjmp/longjmp issues
    366366
    367367Libpng uses setjmp()/longjmp() for error handling.  Unfortunately setjmp()
     
    376376in your pnglibconf.h or pngusr.h.
    377377
     378Starting with libpng-1.6.0, the library included a "simplified API".
     379This requires setjmp/longjmp, so you must either build the library
     380with PNG_SETJMP_SUPPORTED defined, or with PNG_SIMPLIFIED_READ_SUPPORTED
     381and PNG_SIMPLIFIED_WRITE_SUPPORTED undefined.
     382
    378383XVI. Other sources of information about libpng:
    379384
  • TabularUnified libpng/vendor/current/LICENSE

    r1059 r1165  
    1111This code is released under the libpng license.
    1212
    13 libpng versions 1.2.6, August 15, 2004, through 1.6.16, December 22, 2014, are
    14 Copyright (c) 2004, 2006-2014 Glenn Randers-Pehrson, and are
    15 distributed according to the same disclaimer and license as libpng-1.2.5
    16 with the following individual added to the list of Contributing Authors
    17 
    18    Cosmin Truta
    19 
    20 libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
    21 Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
     13libpng versions 1.0.7, July 1, 2000, through 1.6.18, July 23, 2015, are
     14Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, and are
    2215distributed according to the same disclaimer and license as libpng-1.0.6
    23 with the following individuals added to the list of Contributing Authors
     16with the following individuals added to the list of Contributing Authors:
    2417
    2518   Simon-Pierre Cadieux
    2619   Eric S. Raymond
     20   Mans Rullgard
     21   Cosmin Truta
    2722   Gilles Vollant
     23   James Yu
    2824
    2925and with the following additions to the disclaimer:
     
    3733
    3834libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
    39 Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
    40 distributed according to the same disclaimer and license as libpng-0.96,
    41 with the following individuals added to the list of Contributing Authors:
     35Copyright (c) 1998-2000 Glenn Randers-Pehrson, and are distributed according
     36to the same disclaimer and license as libpng-0.96, with the following
     37individuals added to the list of Contributing Authors:
    4238
    4339   Tom Lane
     
    4642
    4743libpng versions 0.89, June 1996, through 0.96, May 1997, are
    48 Copyright (c) 1996, 1997 Andreas Dilger
    49 Distributed according to the same disclaimer and license as libpng-0.88,
     44Copyright (c) 1996-1997 Andreas Dilger, and are
     45distributed according to the same disclaimer and license as libpng-0.88,
    5046with the following individuals added to the list of Contributing Authors:
    5147
     
    5854
    5955libpng versions 0.5, May 1995, through 0.88, January 1996, are
    60 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
     56Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
    6157
    6258For the purposes of this copyright and license, "Contributing Authors"
     
    8177to the following restrictions:
    8278
    83 1. The origin of this source code must not be misrepresented.
     79  1. The origin of this source code must not be misrepresented.
    8480
    85 2. Altered versions must be plainly marked as such and must not
    86    be misrepresented as being the original source.
     81  2. Altered versions must be plainly marked as such and must not
     82     be misrepresented as being the original source.
    8783
    88 3. This Copyright notice may not be removed or altered from any
    89    source or altered source distribution.
     84  3. This Copyright notice may not be removed or altered from any
     85     source or altered source distribution.
    9086
    9187The Contributing Authors and Group 42, Inc. specifically permit, without
     
    9591appreciated.
    9692
    97 
    9893A "png_get_copyright" function is available, for convenient use in "about"
    9994boxes and the like:
    10095
    101    printf("%s",png_get_copyright(NULL));
     96   printf("%s", png_get_copyright(NULL));
    10297
    10398Also, the PNG logo (in PNG format, of course) is supplied in the
    10499files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
    105100
    106 Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is a
    107 certification mark of the Open Source Initiative.
     101Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is
     102a certification mark of the Open Source Initiative. OSI has not addressed
     103the additional disclaimers inserted at version 1.0.7.
    108104
    109105Glenn Randers-Pehrson
    110106glennrp at users.sourceforge.net
    111 December 22, 2014
     107July 23, 2015
  • TabularUnified libpng/vendor/current/Makefile.am

    r1059 r1165  
    130130        CMakeLists.txt example.c libpng-manual.txt
    131131
    132 SCRIPT_CLEANFILES=scripts/*.out scripts/*.chk scripts/pnglibconf.c
     132SCRIPT_CLEANFILES=scripts/*.out scripts/*.chk
    133133
    134134CLEANFILES= *.tf? pngout.png libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.pc \
    135135        libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@-config libpng.vers libpng.sym \
    136         check.new pnglibconf.* pngprefix.h symbols.new pngtest-log.txt \
     136        check.new pnglibconf.h pngprefix.h symbols.new pngtest-log.txt \
     137        pnglibconf.out pnglibconf.c pnglibconf.pre pnglibconf.dfn \
    137138        $(SCRIPT_CLEANFILES)
    138139
  • TabularUnified libpng/vendor/current/README

    r1059 r1165  
    1 README for libpng version 1.6.16 - December 22, 2014 (shared library 16.0)
     1README for libpng version 1.6.18 - July 23, 2015 (shared library 16.0)
    22See the note about version numbers near the top of png.h
    33
     
    135135
    136136Please do not send suggestions on how to change PNG.  We have
    137 been discussing PNG for nineteen years now, and it is official and
     137been discussing PNG for twenty years now, and it is official and
    138138finished.  If you have suggestions for libpng, however, I'll
    139139gladly listen.  Even if your suggestion is not used immediately,
  • TabularUnified libpng/vendor/current/autogen.sh

    r922 r1165  
    7474#
    7575# The autotools generated files:
    76 libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in\
    77    config.sub configure depcomp install-sh ltmain.sh missing test-driver"
     76libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in
     77   config.h.in~ config.sub configure depcomp install-sh ltmain.sh missing\
     78   test-driver"
    7879#
    7980# Files generated by versions of configue >2.68 or automake >1.13 (i.e. later
  • TabularUnified libpng/vendor/current/compile

    r922 r1165  
    44scriptversion=2012-10-14.11; # UTC
    55
    6 # Copyright (C) 1999-2013 Free Software Foundation, Inc.
     6# Copyright (C) 1999-2014 Free Software Foundation, Inc.
    77# Written by Tom Tromey <tromey@cygnus.com>.
    88#
  • TabularUnified libpng/vendor/current/configure.ac

    r1059 r1165  
    1919dnl Version number stuff here:
    2020
    21 AC_INIT([libpng],[1.6.16],[png-mng-implement@lists.sourceforge.net])
     21AC_INIT([libpng],[1.6.18],[png-mng-implement@lists.sourceforge.net])
    2222AC_CONFIG_MACRO_DIR([scripts])
    2323
     
    4040dnl stop configure from automagically running automake
    4141
    42 PNGLIB_VERSION=1.6.16
     42PNGLIB_VERSION=1.6.18
    4343PNGLIB_MAJOR=1
    4444PNGLIB_MINOR=6
    45 PNGLIB_RELEASE=16
     45PNGLIB_RELEASE=18
    4646
    4747dnl End of version number stuff
  • TabularUnified libpng/vendor/current/contrib/arm-neon/README

    r922 r1165  
    22--------------------------------------------
    33
    4 Detection of the ability to exexcute ARM NEON on an ARM processor requires
     4Detection of the ability to execute ARM NEON on an ARM processor requires
    55operating system support.  (The information is not available in user mode.)
    66
  • TabularUnified libpng/vendor/current/contrib/examples/iccfrompng.c

    r922 r1165  
    2626
    2727#include <png.h>
     28
     29#if defined(PNG_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) && \
     30    defined (PNG_iCCP_SUPPORTED)
     31
    2832
    2933static int verbose = 1;
     
    179183   return extracted == 0;
    180184}
     185#endif /* READ && STDIO && iCCP */
  • TabularUnified libpng/vendor/current/contrib/examples/pngpixel.c

    r922 r1165  
    2828#include "../../png.h"
    2929
     30#if defined(PNG_READ_SUPPORTED) && defined(PNG_SEQUENTIAL_READ_SUPPORTED)
     31
    3032/* Return component 'c' of pixel 'x' from the given row. */
    3133static unsigned int
     
    367369   return result;
    368370}
     371#endif /* READ && SEQUENTIAL_READ */
  • TabularUnified libpng/vendor/current/contrib/examples/pngtopng.c

    r922 r1165  
    2121 */
    2222#include "../../png.h"
     23#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && \
     24    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
    2325
    2426int main(int argc, const char **argv)
     
    9193   return result;
    9294}
     95#endif /* READ && WRITE */
  • TabularUnified libpng/vendor/current/contrib/libtests/pngimage.c

    r1059 r1165  
    11/* pngimage.c
    22 *
    3  * Copyright (c) 2014 John Cunningham Bowler
     3 * Copyright (c) 2015 John Cunningham Bowler
    44 *
    5  * Last changed in libpng 1.6.10 [March 6, 2014]
     5 * Last changed in libpng 1.6.18 [July 23, 2015]
    66 *
    77 * This code is released under the libpng license.
     
    11211121            int b;
    11221122
    1123             case 16: /* Two bytes per component, bit-endian */
    1124                for (b = (bpp >> 4); b > 0; )
     1123            case 16: /* Two bytes per component, big-endian */
     1124               for (b = (bpp >> 4); b > 0; --b)
    11251125               {
    11261126                  unsigned int sig = (unsigned int)(0xffff0000 >> sig_bits[b]);
  • TabularUnified libpng/vendor/current/contrib/libtests/pngstest.c

    r1059 r1165  
    22 * pngstest.c
    33 *
    4  * Copyright (c) 2013-2014 John Cunningham Bowler
     4 * Copyright (c) 2013-2015 John Cunningham Bowler
    55 *
    6  * Last changed in libpng 1.6.16 [December 22, 2014]
     6 * Last changed in libpng 1.6.18 [July 23, 2015]
    77 *
    88 * This code is released under the libpng license.
     
    616616   if (image->tmpfile_name[0] != 0 && (image->opts & KEEP_TMPFILES) == 0)
    617617   {
    618       remove(image->tmpfile_name);
     618      (void)remove(image->tmpfile_name);
    619619      image->tmpfile_name[0] = 0;
    620620   }
     
    28292829            else if (y >= b->image.colormap_entries)
    28302830            {
    2831                if ((a->opts & ACCUMULATE) == 0)
     2831               if ((b->opts & ACCUMULATE) == 0)
    28322832                  {
    28332833                  char pindex[9];
     
    31763176               if (cb > 0)
    31773177               {
     3178#ifndef __COVERITY__
    31783179                  if ((unsigned long int)cb <= (size_t)~(size_t)0)
     3180#endif
    31793181                  {
    31803182                     png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
     
    32443246   if (image->opts & USE_STDIO)
    32453247   {
     3248#ifndef PNG_USE_MKSTEMP
    32463249      FILE *f = tmpfile();
    3247 
     3250#else
     3251      /* Experimental. Coverity says tmpfile() is insecure because it
     3252       * generates predictable names.
     3253       *
     3254       * It is possible to satisfy Coverity by using mkstemp(); however,
     3255       * any platform supporting mkstemp() undoubtedly has a secure tmpfile()
     3256       * implementation as well, and doesn't need the fix.  Note that
     3257       * the fix won't work on platforms that don't support mkstemp().
     3258       *
     3259       * https://www.securecoding.cert.org/confluence/display/c/
     3260       * FIO21-C.+Do+not+create+temporary+files+in+shared+directories
     3261       * says that most historic implementations of tmpfile() provide
     3262       * only a limited number of possible temporary file names
     3263       * (usually 26) before file names are recycled. That article also
     3264       * provides a secure solution that unfortunately depends upon mkstemp().
     3265       */
     3266      char tmpfile[] = "pngstest-XXXXXX";
     3267      int filedes;
     3268      FILE *f;
     3269      umask(0177);
     3270      filedes = mkstemp(tmpfile);
     3271      if (filedes < 0)
     3272        f = NULL;
     3273      else
     3274      {
     3275        f = fdopen(filedes,"w+");
     3276        /* Hide the filename immediately and ensure that the file does
     3277         * not exist after the program ends
     3278         */
     3279        (void) unlink(tmpfile);
     3280      }
     3281#endif
     3282     
    32483283      if (f != NULL)
    32493284      {
     
    35893624
    35903625            /* Safe: checked above */
    3591             strcpy(tmpf, argv[c]);
     3626            strncpy(tmpf, argv[c], sizeof (tmpf)-1);
    35923627         }
    35933628
  • TabularUnified libpng/vendor/current/contrib/libtests/pngunknown.c

    r922 r1165  
    12431243   return 77;
    12441244}
    1245 #endif /* SET_UNKNOWN_CHUNKS && READ*/
     1245#endif /* SET_UNKNOWN_CHUNKS && READ */
  • TabularUnified libpng/vendor/current/contrib/libtests/pngvalid.c

    r1059 r1165  
    22/* pngvalid.c - validate libpng by constructing then reading png files.
    33 *
    4  * Last changed in libpng 1.6.14 [October 23, 2014]
    5  * Copyright (c) 2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 2014-2015 Glenn Randers-Pehrson
    66 * Written by John Cunningham Bowler
    77 *
     
    259259}
    260260
    261 #ifdef PNG_READ_SUPPORTED
     261#if defined PNG_READ_SUPPORTED || defined PNG_WRITE_tRNS_SUPPORTED
    262262static void
    263263randomize(void *pv, size_t size)
     
    268268
    269269#define RANDOMIZE(this) randomize(&(this), sizeof (this))
    270 
     270#endif /* READ || WRITE_tRNS */
     271
     272#ifdef PNG_READ_SUPPORTED
    271273static unsigned int
    272274random_mod(unsigned int max)
     
    279281}
    280282
    281 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
     283#if (defined PNG_READ_RGB_TO_GRAY_SUPPORTED) ||\
     284    (defined PNG_READ_FILLER_SUPPORTED)
    282285static int
    283286random_choice(void)
     
    295298 * simply records whether pngvalid did the interlace itself or whether it
    296299 * was done by libpng.  Width and height must be less than 256.  'palette' is an
    297  * index of the palette to use for formats with a palette (0 otherwise.)
     300 * index of the palette to use for formats with a palette otherwise a boolean
     301 * indicating if a tRNS chunk was generated.
    298302 */
    299303#define FILEID(col, depth, palette, interlace, width, height, do_interlace) \
     
    304308#define DEPTH_FROM_ID(id) ((png_byte)(((id) >> 3) & 0x1fU))
    305309#define PALETTE_FROM_ID(id) (((id) >> 8) & 0x1f)
    306 #define INTERLACE_FROM_ID(id) ((int)(((id) >> 13) & 0x3))
     310#define INTERLACE_FROM_ID(id) ((png_byte)(((id) >> 13) & 0x3))
    307311#define DO_INTERLACE_FROM_ID(id) ((int)(((id)>>15) & 1))
    308312#define WIDTH_FROM_ID(id) (((id)>>16) & 0xff)
     
    316320{
    317321   pos = safecat(buffer, bufsize, pos, colour_types[colour_type]);
    318    if (npalette > 0)
     322   if (colour_type == 3) /* must have a palette */
    319323   {
    320324      pos = safecat(buffer, bufsize, pos, "[");
     
    322326      pos = safecat(buffer, bufsize, pos, "]");
    323327   }
     328
     329   else if (npalette != 0)
     330      pos = safecat(buffer, bufsize, pos, "+tRNS");
     331
    324332   pos = safecat(buffer, bufsize, pos, " ");
    325333   pos = safecatn(buffer, bufsize, pos, bit_depth);
     
    378386static int
    379387next_format(png_bytep colour_type, png_bytep bit_depth,
    380    unsigned int* palette_number, int no_low_depth_gray)
     388   unsigned int* palette_number, int low_depth_gray, int tRNS)
    381389{
    382390   if (*bit_depth == 0)
    383391   {
    384392      *colour_type = 0;
    385       if (no_low_depth_gray)
     393      if (low_depth_gray)
     394         *bit_depth = 1;
     395      else
    386396         *bit_depth = 8;
    387       else
    388          *bit_depth = 1;
    389397      *palette_number = 0;
    390398      return 1;
    391399   }
    392400
    393    if (*colour_type == 3)
    394    {
    395       /* Add multiple palettes for colour type 3. */
    396       if (++*palette_number < PALETTE_COUNT(*bit_depth))
     401   if  (*colour_type < 4/*no alpha channel*/)
     402   {
     403      /* Add multiple palettes for colour type 3, one image with tRNS
     404       * and one without for other non-alpha formats:
     405       */
     406      unsigned int pn = ++*palette_number;
     407      png_byte ct = *colour_type;
     408
     409      if (((ct == 0/*GRAY*/ || ct/*RGB*/ == 2) && tRNS && pn < 2) ||
     410          (ct == 3/*PALETTE*/ && pn < PALETTE_COUNT(*bit_depth)))
    397411         return 1;
    398412
     413      /* No: next bit depth */
    399414      *palette_number = 0;
    400415   }
     
    441456static unsigned int
    442457sample(png_const_bytep row, png_byte colour_type, png_byte bit_depth,
    443     png_uint_32 x, unsigned int sample_index)
     458    png_uint_32 x, unsigned int sample_index, int swap16, int littleendian)
    444459{
    445460   png_uint_32 bit_index, result;
     
    470485
    471486   else if (bit_depth > 8)
    472       return (result << 8) + *++row;
    473 
    474    /* Less than 8 bits per sample. */
     487   {
     488      if (swap16)
     489         return (*++row << 8) + result;
     490      else
     491         return (result << 8) + *++row;
     492   }
     493
     494   /* Less than 8 bits per sample.  By default PNG has the big end of
     495    * the egg on the left of the screen, but if littleendian is set
     496    * then the big end is on the right.
     497    */
    475498   bit_index &= 7;
    476    return (result >> (8-bit_index-bit_depth)) & ((1U<<bit_depth)-1);
     499
     500   if (!littleendian)
     501      bit_index = 8-bit_index-bit_depth;
     502
     503   return (result >> bit_index) & ((1U<<bit_depth)-1);
    477504}
    478505#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
     
    12931320    */
    12941321   if (ps->current == NULL)
     1322   {
    12951323      store_log(ps, ps->pread, "no current stream for palette", 1);
     1324      return NULL;
     1325   }
    12961326
    12971327   /* The result may be null if there is no palette. */
     
    15661596         else
    15671597#     endif
    1568          ps->pwrite = png_create_write_struct(png_get_libpng_ver(NULL),
     1598         ps->pwrite = png_create_write_struct(PNG_LIBPNG_VER_STRING,
    15691599            ps, store_error, store_warning);
    15701600
     
    19471977   /* Run tests on reading with a combination of transforms, */
    19481978   unsigned int             test_transform :1;
     1979   unsigned int             test_tRNS :1; /* Includes tRNS images */
    19491980
    19501981   /* When to use the use_input_precision option, this controls the gamma
     
    19772008   unsigned int             test_gamma_expand16 :1;
    19782009   unsigned int             test_exhaustive :1;
     2010
     2011   /* Whether or not to run the low-bit-depth grayscale tests.  This fail on
     2012    * gamma images in some cases because of gross inaccuracies in the grayscale
     2013    * gamma handling for low bit depth.
     2014    */
     2015   unsigned int             test_lbg :1;
     2016   unsigned int             test_lbg_gamma_threshold :1;
     2017   unsigned int             test_lbg_gamma_transform :1;
     2018   unsigned int             test_lbg_gamma_sbit :1;
     2019   unsigned int             test_lbg_gamma_composition :1;
    19792020
    19802021   unsigned int             log :1;   /* Log max error */
     
    20302071   pm->test_size = 0;
    20312072   pm->test_transform = 0;
     2073#  ifdef PNG_WRITE_tRNS_SUPPORTED
     2074      pm->test_tRNS = 1;
     2075#  else
     2076      pm->test_tRNS = 0;
     2077#  endif
    20322078   pm->use_input_precision = 0;
    20332079   pm->use_input_precision_sbit = 0;
     
    20422088   pm->test_gamma_alpha_mode = 0;
    20432089   pm->test_gamma_expand16 = 0;
     2090   pm->test_lbg = 1;
     2091   pm->test_lbg_gamma_threshold = 1;
     2092   pm->test_lbg_gamma_transform = 1;
     2093   pm->test_lbg_gamma_sbit = 1;
     2094   pm->test_lbg_gamma_composition = 1;
    20442095   pm->test_exhaustive = 0;
    20452096   pm->log = 0;
     
    31733224         tRNS[i] = 24;
    31743225
    3175 ifdef PNG_WRITE_tRNS_SUPPORTED
     3226   ifdef PNG_WRITE_tRNS_SUPPORTED
    31763227         if (j > 0)
    31773228            png_set_tRNS(pp, pi, tRNS, j, 0/*color*/);
    3178 #  endif
    3179    }
    3180 }
     3229#     endif
     3230   }
     3231}
     3232
     3233#ifdef PNG_WRITE_tRNS_SUPPORTED
     3234static void
     3235set_random_tRNS(png_structp pp, png_infop pi, PNG_CONST png_byte colour_type,
     3236   PNG_CONST int bit_depth)
     3237{
     3238   /* To make this useful the tRNS color needs to match at least one pixel.
     3239    * Random values are fine for gray, including the 16-bit case where we know
     3240    * that the test image contains all the gray values.  For RGB we need more
     3241    * method as only 65536 different RGB values are generated.
     3242    */
     3243   png_color_16 tRNS;
     3244   const png_uint_16 mask = (png_uint_16)((1U << bit_depth)-1);
     3245
     3246   RANDOMIZE(tRNS);
     3247
     3248   if (colour_type & 2/*RGB*/)
     3249   {
     3250      if (bit_depth == 8)
     3251      {
     3252         tRNS.blue = tRNS.red ^ tRNS.green;
     3253         tRNS.red &= mask;
     3254         tRNS.green &= mask;
     3255         tRNS.blue &= mask;
     3256      }
     3257
     3258      else /* bit_depth == 16 */
     3259      {
     3260         tRNS.green = (png_uint_16)(tRNS.red * 257);
     3261         tRNS.blue = (png_uint_16)(tRNS.green * 17);
     3262      }
     3263   }
     3264
     3265   else
     3266      tRNS.gray &= mask;
     3267
     3268   png_set_tRNS(pp, pi, NULL, 0, &tRNS);
     3269}
     3270#endif
    31813271
    31823272/* The number of passes is related to the interlace type. There was no libpng
     
    35133603         init_standard_palette(ps, pp, pi, 1U << bit_depth, 1/*do tRNS*/);
    35143604
     3605#     ifdef PNG_WRITE_tRNS_SUPPORTED
     3606         else if (palette_number)
     3607            set_random_tRNS(pp, pi, colour_type, bit_depth);
     3608#     endif
     3609
    35153610      png_write_info(pp, pi);
    35163611
     
    35863681
    35873682static void
    3588 make_transform_images(png_store *ps)
     3683make_transform_images(png_modifier *pm)
    35893684{
    35903685   png_byte colour_type = 0;
     
    35933688
    35943689   /* This is in case of errors. */
    3595    safecat(ps->test, sizeof ps->test, 0, "make standard images");
     3690   safecat(pm->this.test, sizeof pm->this.test, 0, "make standard images");
    35963691
    35973692   /* Use next_format to enumerate all the combinations we test, including
    3598     * generating multiple low bit depth palette images.
    3599     */
    3600    while (next_format(&colour_type, &bit_depth, &palette_number, 0))
     3693    * generating multiple low bit depth palette images. Non-A images (palette
     3694    * and direct) are created with and without tRNS chunks.
     3695    */
     3696   while (next_format(&colour_type, &bit_depth, &palette_number, 1, 1))
    36013697   {
    36023698      int interlace_type;
     
    36093705         standard_name(name, sizeof name, 0, colour_type, bit_depth,
    36103706            palette_number, interlace_type, 0, 0, 0);
    3611          make_transform_image(ps, colour_type, bit_depth, palette_number,
     3707         make_transform_image(&pm->this, colour_type, bit_depth, palette_number,
    36123708            interlace_type, name);
    36133709      }
     
    40054101   Try
    40064102   {
    4007       png_structp pp;
     4103      volatile png_structp pp;
    40084104      png_infop pi;
    40094105
     
    42644360   png_byte    blue_sBIT;
    42654361   png_byte    alpha_sBIT;
    4266    int         interlace_type;
     4362   png_byte    interlace_type;
     4363   png_byte    filler;         /* Output has a filler */
    42674364   png_uint_32 id;             /* Calculated file ID */
    42684365   png_uint_32 w;              /* Width of image */
     
    42744371   int         do_interlace;   /* Do interlacing internally */
    42754372   int         is_transparent; /* Transparency information was present. */
     4373   int         has_tRNS;       /* color type GRAY or RGB with a tRNS chunk. */
    42764374   int         speed;          /* Doing a speed test */
    42774375   int         use_update_info;/* Call update_info, not start_image */
     
    46064704            dp->transparent.red = dp->transparent.green = dp->transparent.blue =
    46074705               trans_color->gray;
    4608             dp->is_transparent = 1;
     4706            dp->has_tRNS = 1;
    46094707            break;
    46104708
     
    46134711            dp->transparent.green = trans_color->green;
    46144712            dp->transparent.blue = trans_color->blue;
    4615             dp->is_transparent = 1;
     4713            dp->has_tRNS = 1;
    46164714            break;
    46174715
     
    46514749{
    46524750   /* Record cbRow now that it can be found. */
    4653    dp->pixel_size = bit_size(pp, png_get_color_type(pp, pi),
    4654       png_get_bit_depth(pp, pi));
     4751   {
     4752      png_byte ct = png_get_color_type(pp, pi);
     4753      png_byte bd = png_get_bit_depth(pp, pi);
     4754
     4755      if (bd >= 8 && (ct == PNG_COLOR_TYPE_RGB || ct == PNG_COLOR_TYPE_GRAY) &&
     4756          dp->filler)
     4757          ct |= 4; /* handle filler as faked alpha channel */
     4758
     4759      dp->pixel_size = bit_size(pp, ct, bd);
     4760   }
    46554761   dp->bit_width = png_get_image_width(pp, pi) * dp->pixel_size;
    46564762   dp->cbRow = png_get_rowbytes(pp, pi);
     
    52925398   unsigned int red, green, blue, alpha; /* For non-palette images. */
    52935399   unsigned int palette_index;           /* For a palette image. */
    5294    png_byte colour_type;                 /* As in the spec. */
    5295    png_byte bit_depth;                   /* Defines bit size in row */
    5296    png_byte sample_depth;                /* Scale of samples */
    5297    int      have_tRNS;                   /* tRNS chunk may need processing */
     5400   png_byte     colour_type;             /* As in the spec. */
     5401   png_byte     bit_depth;               /* Defines bit size in row */
     5402   png_byte     sample_depth;            /* Scale of samples */
     5403   unsigned int have_tRNS :1;            /* tRNS chunk may need processing */
     5404   unsigned int swap_rgb :1;             /* RGB swapped to BGR */
     5405   unsigned int alpha_first :1;          /* Alpha at start, not end */
     5406   unsigned int alpha_inverted :1;       /* Alpha channel inverted */
     5407   unsigned int mono_inverted :1;        /* Gray channel inverted */
     5408   unsigned int swap16 :1;               /* Byte swap 16-bit components */
     5409   unsigned int littleendian :1;         /* High bits on right */
     5410   unsigned int sig_bits :1;             /* Pixel shifted (sig bits only) */
    52985411
    52995412   /* For checking the code calculates double precision floating point values
     
    53035416    * channel is stored.  This sBIT value is folded in to the stored error value
    53045417    * at the end of the application of the transforms to the pixel.
     5418    *
     5419    * If sig_bits is set above the red, green, blue and alpha values have been
     5420    * scaled so they only contain the significant bits of the component values.
    53055421    */
    53065422   double   redf, greenf, bluef, alphaf;
     
    53115427/* Shared utility function, see below. */
    53125428static void
    5313 image_pixel_setf(image_pixel *this, unsigned int max)
    5314 {
    5315    this->redf = this->red / (double)max;
    5316    this->greenf = this->green / (double)max;
    5317    this->bluef = this->blue / (double)max;
    5318    this->alphaf = this->alpha / (double)max;
    5319 
    5320    if (this->red < max)
     5429image_pixel_setf(image_pixel *this, unsigned int rMax, unsigned int gMax,
     5430        unsigned int bMax, unsigned int aMax)
     5431{
     5432   this->redf = this->red / (double)rMax;
     5433   this->greenf = this->green / (double)gMax;
     5434   this->bluef = this->blue / (double)bMax;
     5435   this->alphaf = this->alpha / (double)aMax;
     5436
     5437   if (this->red < rMax)
    53215438      this->rede = this->redf * DBL_EPSILON;
    53225439   else
    53235440      this->rede = 0;
    5324    if (this->green < max)
     5441   if (this->green < gMax)
    53255442      this->greene = this->greenf * DBL_EPSILON;
    53265443   else
    53275444      this->greene = 0;
    5328    if (this->blue < max)
     5445   if (this->blue < bMax)
    53295446      this->bluee = this->bluef * DBL_EPSILON;
    53305447   else
    53315448      this->bluee = 0;
    5332    if (this->alpha < max)
     5449   if (this->alpha < aMax)
    53335450      this->alphae = this->alphaf * DBL_EPSILON;
    53345451   else
     
    53425459static void
    53435460image_pixel_init(image_pixel *this, png_const_bytep row, png_byte colour_type,
    5344     png_byte bit_depth, png_uint_32 x, store_palette palette)
     5461    png_byte bit_depth, png_uint_32 x, store_palette palette,
     5462    PNG_CONST image_pixel *format /*from pngvalid transform of input*/)
    53455463{
    53465464   PNG_CONST png_byte sample_depth = (png_byte)(colour_type ==
    53475465      PNG_COLOR_TYPE_PALETTE ? 8 : bit_depth);
    53485466   PNG_CONST unsigned int max = (1U<<sample_depth)-1;
     5467   PNG_CONST int swap16 = (format != 0 && format->swap16);
     5468   PNG_CONST int littleendian = (format != 0 && format->littleendian);
     5469   PNG_CONST int sig_bits = (format != 0 && format->sig_bits);
    53495470
    53505471   /* Initially just set everything to the same number and the alpha to opaque.
     
    53535474    */
    53545475   this->palette_index = this->red = this->green = this->blue =
    5355       sample(row, colour_type, bit_depth, x, 0);
     5476      sample(row, colour_type, bit_depth, x, 0, swap16, littleendian);
    53565477   this->alpha = max;
    53575478   this->red_sBIT = this->green_sBIT = this->blue_sBIT = this->alpha_sBIT =
     
    53775498      unsigned int i = 0;
    53785499
     5500      if ((colour_type & 4) != 0 && format != 0 && format->alpha_first)
     5501      {
     5502         this->alpha = this->red;
     5503         /* This handles the gray case for 'AG' pixels */
     5504         this->palette_index = this->red = this->green = this->blue =
     5505            sample(row, colour_type, bit_depth, x, 1, swap16, littleendian);
     5506         i = 1;
     5507      }
     5508
    53795509      if (colour_type & 2)
    53805510      {
    5381          this->green = sample(row, colour_type, bit_depth, x, 1);
    5382          this->blue = sample(row, colour_type, bit_depth, x, 2);
    5383          i = 2;
    5384       }
    5385       if (colour_type & 4)
    5386          this->alpha = sample(row, colour_type, bit_depth, x, ++i);
     5511         /* Green is second for both BGR and RGB: */
     5512         this->green = sample(row, colour_type, bit_depth, x, ++i, swap16,
     5513                 littleendian);
     5514
     5515         if (format != 0 && format->swap_rgb) /* BGR */
     5516             this->red = sample(row, colour_type, bit_depth, x, ++i, swap16,
     5517                     littleendian);
     5518         else
     5519             this->blue = sample(row, colour_type, bit_depth, x, ++i, swap16,
     5520                     littleendian);
     5521      }
     5522
     5523      else /* grayscale */ if (format != 0 && format->mono_inverted)
     5524         this->red = this->green = this->blue = this->red ^ max;
     5525
     5526      if ((colour_type & 4) != 0) /* alpha */
     5527      {
     5528         if (format == 0 || !format->alpha_first)
     5529             this->alpha = sample(row, colour_type, bit_depth, x, ++i, swap16,
     5530                     littleendian);
     5531
     5532         if (format != 0 && format->alpha_inverted)
     5533            this->alpha ^= max;
     5534      }
    53875535   }
    53885536
     
    53915539    * from the header file.
    53925540    */
    5393    image_pixel_setf(this, max);
     5541   image_pixel_setf(this,
     5542      sig_bits ? (1U << format->red_sBIT)-1 : max,
     5543      sig_bits ? (1U << format->green_sBIT)-1 : max,
     5544      sig_bits ? (1U << format->blue_sBIT)-1 : max,
     5545      sig_bits ? (1U << format->alpha_sBIT)-1 : max);
    53945546
    53955547   /* Store the input information for use in the transforms - these will
     
    54005552   this->sample_depth = sample_depth;
    54015553   this->have_tRNS = 0;
     5554   this->swap_rgb = 0;
     5555   this->alpha_first = 0;
     5556   this->alpha_inverted = 0;
     5557   this->mono_inverted = 0;
     5558   this->swap16 = 0;
     5559   this->littleendian = 0;
     5560   this->sig_bits = 0;
    54025561}
    54035562
     
    54445603      {
    54455604         if (this->bit_depth < 8)
    5446             this->bit_depth = 8;
     5605            this->bit_depth = this->sample_depth = 8;
    54475606
    54485607         if (this->have_tRNS)
     
    54795638            else
    54805639               this->alphaf = 1;
    5481 
    5482             this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;
    54835640         }
     5641         else
     5642            this->alphaf = 1;
     5643
     5644         this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;
    54845645      }
    54855646
     
    55615722   png_byte output_colour_type;
    55625723   png_byte output_bit_depth;
     5724   png_byte unpacked;
    55635725
    55645726   /* Modifications (not necessarily used.) */
     
    56365798{
    56375799   PNG_CONST unsigned int scale = (1U<<that->sample_depth)-1;
     5800   PNG_CONST int sig_bits = that->sig_bits;
    56385801
    56395802   UNUSED(this)
     
    56495812    */
    56505813   that->red = sample_scale(that->redf, scale);
     5814
     5815   /* This is a bit bogus; really the above calculation should use the red_sBIT
     5816    * value, not sample_depth, but because libpng does png_set_shift by just
     5817    * shifting the bits we get errors if we don't do it the same way.
     5818    */
     5819   if (sig_bits && that->red_sBIT < that->sample_depth)
     5820      that->red >>= that->sample_depth - that->red_sBIT;
    56515821
    56525822   /* The error value is increased, at the end, according to the lowest sBIT
     
    56655835   {
    56665836      that->green = sample_scale(that->greenf, scale);
     5837      if (sig_bits && that->green_sBIT < that->sample_depth)
     5838         that->green >>= that->sample_depth - that->green_sBIT;
     5839
    56675840      that->blue = sample_scale(that->bluef, scale);
     5841      if (sig_bits && that->blue_sBIT < that->sample_depth)
     5842         that->blue >>= that->sample_depth - that->blue_sBIT;
     5843
    56685844      that->greene += 1./(2*((1U<<that->green_sBIT)-1));
    56695845      that->bluee += 1./(2*((1U<<that->blue_sBIT)-1));
     
    56855861   {
    56865862      that->alpha = scale; /* opaque */
    5687       that->alpha = 1;     /* Override this. */
     5863      that->alphaf = 1;    /* Override this. */
    56885864      that->alphae = 0;    /* It's exact ;-) */
    56895865   }
     5866
     5867   if (sig_bits && that->alpha_sBIT < that->sample_depth)
     5868      that->alpha >>= that->sample_depth - that->alpha_sBIT;
    56905869}
    56915870
     
    57255904   dp->output_colour_type = 255; /* invalid */
    57265905   dp->output_bit_depth = 255;  /* invalid */
     5906   dp->unpacked = 0; /* not unpacked */
    57275907}
    57285908
     
    57515931   dp->output_colour_type = png_get_color_type(pp, pi);
    57525932   dp->output_bit_depth = png_get_bit_depth(pp, pi);
     5933
     5934   /* If png_set_filler is in action then fake the output color type to include
     5935    * an alpha channel where appropriate.
     5936    */
     5937   if (dp->output_bit_depth >= 8 &&
     5938       (dp->output_colour_type == PNG_COLOR_TYPE_RGB ||
     5939        dp->output_colour_type == PNG_COLOR_TYPE_GRAY) && dp->this.filler)
     5940       dp->output_colour_type |= 4;
    57535941
    57545942   /* Validate the combination of colour type and bit depth that we are getting
     
    57865974
    57875975   /* Use a test pixel to check that the output agrees with what we expect -
    5788     * this avoids running the whole test if the output is unexpected.
     5976    * this avoids running the whole test if the output is unexpected.  This also
     5977    * checks for internal errors.
    57895978    */
    57905979   {
     
    58015990       * arithmetic overflows.
    58025991       */
    5803       test_pixel.have_tRNS = dp->this.is_transparent;
     5992      test_pixel.have_tRNS = dp->this.is_transparent != 0;
    58045993      test_pixel.red_sBIT = test_pixel.green_sBIT = test_pixel.blue_sBIT =
    58055994         test_pixel.alpha_sBIT = test_pixel.sample_depth;
     
    58326021
    58336022      /* If both bit depth and colour type are correct check the sample depth.
    5834        * I believe these are both internal errors.
    58356023       */
    5836       if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE)
    5837       {
    5838          if (test_pixel.sample_depth != 8) /* oops - internal error! */
    5839             png_error(pp, "pngvalid: internal: palette sample depth not 8");
    5840       }
    5841       else if (test_pixel.sample_depth != dp->output_bit_depth)
     6024      if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE &&
     6025          test_pixel.sample_depth != 8) /* oops - internal error! */
     6026         png_error(pp, "pngvalid: internal: palette sample depth not 8");
     6027      else if (dp->unpacked && test_pixel.bit_depth != 8)
     6028         png_error(pp, "pngvalid: internal: bad unpacked pixel depth");
     6029      else if (!dp->unpacked && test_pixel.colour_type != PNG_COLOR_TYPE_PALETTE
     6030              && test_pixel.bit_depth != test_pixel.sample_depth)
    58426031      {
    58436032         char message[128];
     
    58456034            "internal: sample depth ");
    58466035
     6036         /* Because unless something has set 'unpacked' or the image is palette
     6037          * mapped we expect the transform to keep sample depth and bit depth
     6038          * the same.
     6039          */
     6040         pos = safecatn(message, sizeof message, pos, test_pixel.sample_depth);
     6041         pos = safecat(message, sizeof message, pos, " expected ");
     6042         pos = safecatn(message, sizeof message, pos, test_pixel.bit_depth);
     6043
     6044         png_error(pp, message);
     6045      }
     6046      else if (test_pixel.bit_depth != dp->output_bit_depth)
     6047      {
     6048         /* This could be a libpng error too; libpng has not produced what we
     6049          * expect for the output bit depth.
     6050          */
     6051         char message[128];
     6052         size_t pos = safecat(message, sizeof message, 0,
     6053            "internal: bit depth ");
     6054
    58476055         pos = safecatn(message, sizeof message, pos, dp->output_bit_depth);
    58486056         pos = safecat(message, sizeof message, pos, " expected ");
    5849          pos = safecatn(message, sizeof message, pos, test_pixel.sample_depth);
     6057         pos = safecatn(message, sizeof message, pos, test_pixel.bit_depth);
    58506058
    58516059         png_error(pp, message);
     
    59946202
    59956203         /* Find out what we think the pixel should be: */
    5996          image_pixel_init(&in_pixel, std, in_ct, in_bd, x, dp->this.palette);
     6204         image_pixel_init(&in_pixel, std, in_ct, in_bd, x, dp->this.palette,
     6205                 NULL);
    59976206
    59986207         in_pixel.red_sBIT = red_sBIT;
     
    60006209         in_pixel.blue_sBIT = blue_sBIT;
    60016210         in_pixel.alpha_sBIT = alpha_sBIT;
    6002          in_pixel.have_tRNS = have_tRNS;
     6211         in_pixel.have_tRNS = have_tRNS != 0;
    60036212
    60046213         /* For error detection, below. */
     
    60086217         a = in_pixel.alpha;
    60096218
     6219         /* This applies the transforms to the input date, including output
     6220          * format operations which must be used when reading the output
     6221          * pixel that libpng produces.
     6222          */
    60106223         dp->transform_list->mod(dp->transform_list, &in_pixel, pp, dp);
    60116224
    60126225         /* Read the output pixel and compare it to what we got, we don't
    6013           * use the error field here, so no need to update sBIT.
     6226          * use the error field here, so no need to update sBIT.  in_pixel
     6227          * says whether we expect libpng to change the output format.
    60146228          */
    6015          image_pixel_init(&out_pixel, pRow, out_ct, out_bd, x, out_palette);
     6229         image_pixel_init(&out_pixel, pRow, out_ct, out_bd, x, out_palette,
     6230                 &in_pixel);
    60166231
    60176232         /* We don't expect changes to the index here even if the bit depth is
     
    62456460{
    62466461   png_set_tRNS_to_alpha(pp);
     6462
     6463   /* If there was a tRNS chunk that would get expanded and add an alpha
     6464    * channel is_transparent must be updated:
     6465    */
     6466   if (that->this.has_tRNS)
     6467      that->this.is_transparent = 1;
     6468
    62476469   this->next->set(this->next, that, pp, pi);
    62486470}
     
    63036525{
    63046526   png_set_gray_to_rgb(pp);
     6527   /* NOTE: this doesn't result in tRNS expansion. */
    63056528   this->next->set(this->next, that, pp, pi);
    63066529}
     
    63626585{
    63636586   png_set_expand(pp);
     6587
     6588   if (that->this.has_tRNS)
     6589      that->this.is_transparent = 1;
     6590
    63646591   this->next->set(this->next, that, pp, pi);
    63656592}
     
    64126639{
    64136640   png_set_expand_gray_1_2_4_to_8(pp);
     6641   /* NOTE: don't expect this to expand tRNS */
    64146642   this->next->set(this->next, that, pp, pi);
    64156643}
     
    64436671{
    64446672   png_set_expand_16(pp);
     6673
     6674   /* NOTE: at present libpng does SET_EXPAND as well, so tRNS is expanded. */
     6675   if (that->this.has_tRNS)
     6676      that->this.is_transparent = 1;
     6677
    64456678   this->next->set(this->next, that, pp, pi);
    64466679}
     
    67947027          *  +/-(1<<(15-PNG_MAX_GAMMA_8)) in the 8-bit case.
    67957028          */
    6796          that->pm->limit +=
    6797 #        if PNG_MAX_GAMMA_8 < 14
    6798                pow((that->this.bit_depth == 16 ?
    6799                   8. : 6. + (1<<(15-PNG_MAX_GAMMA_8)))/65535, data.gamma);
    6800 #        else
    6801                pow((that->this.bit_depth == 16 ?
    6802                   8. : 8. + (1<<(15-PNG_MAX_GAMMA_8)))/65535, data.gamma);
    6803 #        endif
     7029         that->pm->limit += pow(
     7030#           if PNG_MAX_GAMMA_8 < 14
     7031               (that->this.bit_depth == 16 ? 8. :
     7032                  6. + (1<<(15-PNG_MAX_GAMMA_8)))
     7033#           else
     7034               8.
     7035#           endif
     7036               /65535, data.gamma);
    68047037      }
    68057038
     
    68137046          * tested allow a bigger slack.
    68147047          *
    6815           * NOTE: this magic number was determined by experiment to be 1.1 (when
    6816           * using fixed point arithmetic).  There's no great merit to the value
    6817           * below, however it only affects the limit used for checking for
    6818           * internal calculation errors, not the actual limit imposed by
    6819           * pngvalid on the output errors.
     7048          * NOTE: this magic number was determined by experiment to be about
     7049          * 1.263.  There's no great merit to the value below, however it only
     7050          * affects the limit used for checking for internal calculation errors,
     7051          * not the actual limit imposed by pngvalid on the output errors.
    68207052          */
    6821          that->pm->limit +=
     7053         that->pm->limit += pow(
    68227054#        if DIGITIZE
    6823              pow(1.1 /255, data.gamma);
     7055            1.3
    68247056#        else
    6825              pow(1.0 /255, data.gamma);
     7057            1.0
    68267058#        endif
     7059            /255, data.gamma);
    68277060      }
    68287061   }
     
    69847217         const unsigned int calc_depth = (pm->assume_16_bit_calculations ? 16 :
    69857218            sample_depth);
    6986          const unsigned int gamma_depth = (sample_depth == 16 ? 16 :
     7219         const unsigned int gamma_depth = (sample_depth == 16 ?
     7220            PNG_MAX_GAMMA_8 :
    69877221            (pm->assume_16_bit_calculations ? PNG_MAX_GAMMA_8 : sample_depth));
    69887222         int isgray;
     
    69987232          * transform, feel free to delete the png_error checks on this below in
    69997233          * the future (this is just me trying to ensure it works!)
     7234          *
     7235          * Interval arithmetic is exact, but to implement it it must be
     7236          * possible to control the floating point implementation rounding mode.
     7237          * This cannot be done in ANSI-C, so instead I reduce the 'lo' values
     7238          * by DBL_EPSILON and increase the 'hi' values by the same.
    70007239          */
     7240#        define DD(v,d,r) (digitize(v*(1-DBL_EPSILON), d, r) * (1-DBL_EPSILON))
     7241#        define DU(v,d,r) (digitize(v*(1+DBL_EPSILON), d, r) * (1+DBL_EPSILON))
     7242
    70017243         r = rlo = rhi = that->redf;
    70027244         rlo -= that->rede;
    7003          rlo = digitize(rlo, calc_depth, 1/*round*/);
     7245         rlo = DD(rlo, calc_depth, 1/*round*/);
    70047246         rhi += that->rede;
    7005          rhi = digitize(rhi, calc_depth, 1/*round*/);
     7247         rhi = DU(rhi, calc_depth, 1/*round*/);
    70067248
    70077249         g = glo = ghi = that->greenf;
    70087250         glo -= that->greene;
    7009          glo = digitize(glo, calc_depth, 1/*round*/);
     7251         glo = DD(glo, calc_depth, 1/*round*/);
    70107252         ghi += that->greene;
    7011          ghi = digitize(ghi, calc_depth, 1/*round*/);
     7253         ghi = DU(ghi, calc_depth, 1/*round*/);
    70127254
    70137255         b = blo = bhi = that->bluef;
    70147256         blo -= that->bluee;
    7015          blo = digitize(blo, calc_depth, 1/*round*/);
     7257         blo = DD(blo, calc_depth, 1/*round*/);
    70167258         bhi += that->greene;
    7017          bhi = digitize(bhi, calc_depth, 1/*round*/);
     7259         bhi = DU(bhi, calc_depth, 1/*round*/);
    70187260
    70197261         isgray = r==g && g==b;
     
    70227264         {
    70237265            PNG_CONST double power = 1/data.gamma;
    7024             PNG_CONST double abse = calc_depth == 16 ? .5/65535 : .5/255;
    7025 
    7026             /* 'abse' is the absolute error permitted in linear calculations. It
    7027              * is used here to capture the error permitted in the handling
    7028              * (undoing) of the gamma encoding.  Once again digitization occurs
    7029              * to handle the upper and lower bounds of the values.  This is
    7030              * where the real errors are introduced.
     7266            PNG_CONST double abse = .5/(sample_depth == 16 ? 65535 : 255);
     7267
     7268            /* If a gamma calculation is done it is done using lookup tables of
     7269             * precision gamma_depth, so the already digitized value above may
     7270             * need to be further digitized here.
    70317271             */
     7272            if (gamma_depth != calc_depth)
     7273            {
     7274               rlo = DD(rlo, gamma_depth, 0/*truncate*/);
     7275               rhi = DU(rhi, gamma_depth, 0/*truncate*/);
     7276               glo = DD(glo, gamma_depth, 0/*truncate*/);
     7277               ghi = DU(ghi, gamma_depth, 0/*truncate*/);
     7278               blo = DD(blo, gamma_depth, 0/*truncate*/);
     7279               bhi = DU(bhi, gamma_depth, 0/*truncate*/);
     7280            }
     7281
     7282            /* 'abse' is the error in the gamma table calculation itself. */
    70327283            r = pow(r, power);
    7033             rlo = digitize(pow(rlo, power)-abse, calc_depth, 1);
    7034             rhi = digitize(pow(rhi, power)+abse, calc_depth, 1);
     7284            rlo = DD(pow(rlo, power)-abse, calc_depth, 1);
     7285            rhi = DU(pow(rhi, power)+abse, calc_depth, 1);
    70357286
    70367287            g = pow(g, power);
    7037             glo = digitize(pow(glo, power)-abse, calc_depth, 1);
    7038             ghi = digitize(pow(ghi, power)+abse, calc_depth, 1);
     7288            glo = DD(pow(glo, power)-abse, calc_depth, 1);
     7289            ghi = DU(pow(ghi, power)+abse, calc_depth, 1);
    70397290
    70407291            b = pow(b, power);
    7041             blo = digitize(pow(blo, power)-abse, calc_depth, 1);
    7042             bhi = digitize(pow(bhi, power)+abse, calc_depth, 1);
     7292            blo = DD(pow(blo, power)-abse, calc_depth, 1);
     7293            bhi = DU(pow(bhi, power)+abse, calc_depth, 1);
    70437294         }
    70447295
     
    70477298          * line (in which case truncation to 15 bits happened) or not (rounding
    70487299          * was used) the maxium error in an individual coefficient is always
    7049           * 1/32768, because even in the rounding case the requirement that
     7300          * 2/32768, because even in the rounding case the requirement that
    70507301          * coefficients add up to 32768 can cause a larger rounding error.
    70517302          *
     
    70587309         {
    70597310            PNG_CONST int do_round = data.gamma != 1 || calc_depth == 16;
    7060             PNG_CONST double ce = 1. / 32768;
    7061 
    7062             graylo = digitize(rlo * (data.red_coefficient-ce) +
     7311            PNG_CONST double ce = 2. / 32768;
     7312
     7313            graylo = DD(rlo * (data.red_coefficient-ce) +
    70637314               glo * (data.green_coefficient-ce) +
    7064                blo * (data.blue_coefficient-ce), gamma_depth, do_round);
    7065             if (graylo <= 0)
    7066                graylo = 0;
    7067 
    7068             grayhi = digitize(rhi * (data.red_coefficient+ce) +
     7315               blo * (data.blue_coefficient-ce), calc_depth, do_round);
     7316            if (graylo > gray) /* always accept the right answer */
     7317               graylo = gray;
     7318
     7319            grayhi = DU(rhi * (data.red_coefficient+ce) +
    70697320               ghi * (data.green_coefficient+ce) +
    7070                bhi * (data.blue_coefficient+ce), gamma_depth, do_round);
    7071             if (grayhi >= 1)
    7072                grayhi = 1;
     7321               bhi * (data.blue_coefficient+ce), calc_depth, do_round);
     7322            if (grayhi < gray)
     7323               grayhi = gray;
    70737324         }
    70747325
     
    70787329            PNG_CONST double power = data.gamma;
    70797330
     7331            /* And this happens yet again, shifting the values once more. */
     7332            if (gamma_depth != sample_depth)
     7333            {
     7334               rlo = DD(rlo, gamma_depth, 0/*truncate*/);
     7335               rhi = DU(rhi, gamma_depth, 0/*truncate*/);
     7336               glo = DD(glo, gamma_depth, 0/*truncate*/);
     7337               ghi = DU(ghi, gamma_depth, 0/*truncate*/);
     7338               blo = DD(blo, gamma_depth, 0/*truncate*/);
     7339               bhi = DU(bhi, gamma_depth, 0/*truncate*/);
     7340            }
     7341
    70807342            gray = pow(gray, power);
    7081             graylo = digitize(pow(graylo, power), sample_depth, 1);
    7082             grayhi = digitize(pow(grayhi, power), sample_depth, 1);
     7343            graylo = DD(pow(graylo, power), sample_depth, 1);
     7344            grayhi = DU(pow(grayhi, power), sample_depth, 1);
    70837345         }
     7346
     7347#        undef DD
     7348#        undef DU
    70847349
    70857350         /* Now the error can be calculated.
     
    71337398            /* There is no need to do the conversions to and from linear space,
    71347399             * so the calculation should be a lot more accurate.  There is a
    7135              * built in 1/32768 error in the coefficients because they only have
    7136              * 15 bits and are adjusted to make sure they add up to 32768, so
    7137              * the result may have an additional error up to 1/32768.  (Note
    7138              * that adding the 1/32768 here avoids needing to increase the
    7139              * global error limits to take this into account.)
     7400             * built in error in the coefficients because they only have 15 bits
     7401             * and are adjusted to make sure they add up to 32768.  This
     7402             * involves a integer calculation with truncation of the form:
     7403             *
     7404             *     ((int)(coefficient * 100000) * 32768)/100000
     7405             *
     7406             * This is done to the red and green coefficients (the ones
     7407             * provided to the API) then blue is calculated from them so the
     7408             * result adds up to 32768.  In the worst case this can result in
     7409             * a -1 error in red and green and a +2 error in blue.  Consequently
     7410             * the worst case in the calculation below is 2/32768 error.
     7411             *
     7412             * TODO: consider fixing this in libpng by rounding the calculation
     7413             * limiting the error to 1/32768.
     7414             *
     7415             * Handling this by adding 2/32768 here avoids needing to increase
     7416             * the global error limits to take this into account.)
    71407417             */
    71417418            gray = r * data.red_coefficient + g * data.green_coefficient +
    71427419               b * data.blue_coefficient;
    71437420            err = re * data.red_coefficient + ge * data.green_coefficient +
    7144                be * data.blue_coefficient + 1./32768 + gray * 5 * DBL_EPSILON;
     7421               be * data.blue_coefficient + 2./32768 + gray * 5 * DBL_EPSILON;
    71457422         }
    71467423
     
    71777454             */
    71787455            gray = r * data.red_coefficient + g * data.green_coefficient +
    7179                b * data.blue_coefficient - 1./32768 - out_qe;
     7456               b * data.blue_coefficient - 2./32768 - out_qe;
    71807457            if (gray <= 0)
    71817458               gray = 0;
     
    71877464
    71887465            grayhi = rhi * data.red_coefficient + ghi * data.green_coefficient +
    7189                bhi * data.blue_coefficient + 1./32768 + out_qe;
     7466               bhi * data.blue_coefficient + 2./32768 + out_qe;
    71907467            grayhi *= (1 + 6 * DBL_EPSILON);
    71917468            if (grayhi >= 1)
     
    73027579   else
    73037580   {
     7581      if (that->this.has_tRNS)
     7582         that->this.is_transparent = 1;
     7583
    73047584      bit_depth = that->this.bit_depth;
    73057585      expand = 1;
     
    73077587
    73087588   image_pixel_init(&data, random_bytes, colour_type,
    7309       bit_depth, 0/*x*/, 0/*unused: palette*/);
     7589      bit_depth, 0/*x*/, 0/*unused: palette*/, NULL/*format*/);
    73107590
    73117591   /* Extract the background colour from this image_pixel, but make sure the
     
    73797659      that->alphaf = 1;
    73807660      that->alphae = 0;
    7381 
    7382       if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)
    7383          that->colour_type = PNG_COLOR_TYPE_RGB;
    7384       else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)
    7385          that->colour_type = PNG_COLOR_TYPE_GRAY;
    7386       /* PNG_COLOR_TYPE_PALETTE is not changed */
    7387    }
     7661   }
     7662
     7663   if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)
     7664      that->colour_type = PNG_COLOR_TYPE_RGB;
     7665   else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)
     7666      that->colour_type = PNG_COLOR_TYPE_GRAY;
     7667   /* PNG_COLOR_TYPE_PALETTE is not changed */
    73887668
    73897669   this->next->mod(this->next, that, pp, display);
     
    73977677#define PT ITSTRUCT(background)
    73987678#endif /* PNG_READ_BACKGROUND_SUPPORTED */
     7679
     7680/* png_set_quantize(png_structp, png_colorp palette, int num_palette,
     7681 *    int maximum_colors, png_const_uint_16p histogram, int full_quantize)
     7682 *
     7683 * Very difficult to validate this!
     7684 */
     7685/*NOTE: TBD NYI */
     7686
     7687/* The data layout transforms are handled by swapping our own channel data,
     7688 * necessarily these need to happen at the end of the transform list because the
     7689 * semantic of the channels changes after these are executed.  Some of these,
     7690 * like set_shift and set_packing, can't be done at present because they change
     7691 * the layout of the data at the sub-sample level so sample() won't get the
     7692 * right answer.
     7693 */
     7694/* png_set_invert_alpha */
     7695#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
     7696/* Invert the alpha channel
     7697 *
     7698 *  png_set_invert_alpha(png_structrp png_ptr)
     7699 */
     7700static void
     7701image_transform_png_set_invert_alpha_set(PNG_CONST image_transform *this,
     7702    transform_display *that, png_structp pp, png_infop pi)
     7703{
     7704   png_set_invert_alpha(pp);
     7705   this->next->set(this->next, that, pp, pi);
     7706}
     7707
     7708static void
     7709image_transform_png_set_invert_alpha_mod(PNG_CONST image_transform *this,
     7710    image_pixel *that, png_const_structp pp,
     7711    PNG_CONST transform_display *display)
     7712{
     7713   if (that->colour_type & 4)
     7714      that->alpha_inverted = 1;
     7715
     7716   this->next->mod(this->next, that, pp, display);
     7717}
     7718
     7719static int
     7720image_transform_png_set_invert_alpha_add(image_transform *this,
     7721    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     7722{
     7723   UNUSED(bit_depth)
     7724
     7725   this->next = *that;
     7726   *that = this;
     7727
     7728   /* Only has an effect on pixels with alpha: */
     7729   return (colour_type & 4) != 0;
     7730}
     7731
     7732IT(invert_alpha);
     7733#undef PT
     7734#define PT ITSTRUCT(invert_alpha)
     7735
     7736#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */
     7737
     7738/* png_set_bgr */
     7739#ifdef PNG_READ_BGR_SUPPORTED
     7740/* Swap R,G,B channels to order B,G,R.
     7741 *
     7742 *  png_set_bgr(png_structrp png_ptr)
     7743 *
     7744 * This only has an effect on RGB and RGBA pixels.
     7745 */
     7746static void
     7747image_transform_png_set_bgr_set(PNG_CONST image_transform *this,
     7748    transform_display *that, png_structp pp, png_infop pi)
     7749{
     7750   png_set_bgr(pp);
     7751   this->next->set(this->next, that, pp, pi);
     7752}
     7753
     7754static void
     7755image_transform_png_set_bgr_mod(PNG_CONST image_transform *this,
     7756    image_pixel *that, png_const_structp pp,
     7757    PNG_CONST transform_display *display)
     7758{
     7759   if (that->colour_type == PNG_COLOR_TYPE_RGB ||
     7760       that->colour_type == PNG_COLOR_TYPE_RGBA)
     7761       that->swap_rgb = 1;
     7762
     7763   this->next->mod(this->next, that, pp, display);
     7764}
     7765
     7766static int
     7767image_transform_png_set_bgr_add(image_transform *this,
     7768    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     7769{
     7770   UNUSED(bit_depth)
     7771
     7772   this->next = *that;
     7773   *that = this;
     7774
     7775   return colour_type == PNG_COLOR_TYPE_RGB ||
     7776       colour_type == PNG_COLOR_TYPE_RGBA;
     7777}
     7778
     7779IT(bgr);
     7780#undef PT
     7781#define PT ITSTRUCT(bgr)
     7782
     7783#endif /* PNG_READ_BGR_SUPPORTED */
     7784
     7785/* png_set_swap_alpha */
     7786#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
     7787/* Put the alpha channel first.
     7788 *
     7789 *  png_set_swap_alpha(png_structrp png_ptr)
     7790 *
     7791 * This only has an effect on GA and RGBA pixels.
     7792 */
     7793static void
     7794image_transform_png_set_swap_alpha_set(PNG_CONST image_transform *this,
     7795    transform_display *that, png_structp pp, png_infop pi)
     7796{
     7797   png_set_swap_alpha(pp);
     7798   this->next->set(this->next, that, pp, pi);
     7799}
     7800
     7801static void
     7802image_transform_png_set_swap_alpha_mod(PNG_CONST image_transform *this,
     7803    image_pixel *that, png_const_structp pp,
     7804    PNG_CONST transform_display *display)
     7805{
     7806   if (that->colour_type == PNG_COLOR_TYPE_GA ||
     7807       that->colour_type == PNG_COLOR_TYPE_RGBA)
     7808      that->alpha_first = 1;
     7809
     7810   this->next->mod(this->next, that, pp, display);
     7811}
     7812
     7813static int
     7814image_transform_png_set_swap_alpha_add(image_transform *this,
     7815    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     7816{
     7817   UNUSED(bit_depth)
     7818
     7819   this->next = *that;
     7820   *that = this;
     7821
     7822   return colour_type == PNG_COLOR_TYPE_GA ||
     7823       colour_type == PNG_COLOR_TYPE_RGBA;
     7824}
     7825
     7826IT(swap_alpha);
     7827#undef PT
     7828#define PT ITSTRUCT(swap_alpha)
     7829
     7830#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED */
     7831
     7832/* png_set_swap */
     7833#ifdef PNG_READ_SWAP_SUPPORTED
     7834/* Byte swap 16-bit components.
     7835 *
     7836 *  png_set_swap(png_structrp png_ptr)
     7837 */
     7838static void
     7839image_transform_png_set_swap_set(PNG_CONST image_transform *this,
     7840    transform_display *that, png_structp pp, png_infop pi)
     7841{
     7842   png_set_swap(pp);
     7843   this->next->set(this->next, that, pp, pi);
     7844}
     7845
     7846static void
     7847image_transform_png_set_swap_mod(PNG_CONST image_transform *this,
     7848    image_pixel *that, png_const_structp pp,
     7849    PNG_CONST transform_display *display)
     7850{
     7851   if (that->bit_depth == 16)
     7852      that->swap16 = 1;
     7853
     7854   this->next->mod(this->next, that, pp, display);
     7855}
     7856
     7857static int
     7858image_transform_png_set_swap_add(image_transform *this,
     7859    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     7860{
     7861   UNUSED(colour_type)
     7862
     7863   this->next = *that;
     7864   *that = this;
     7865
     7866   return bit_depth == 16;
     7867}
     7868
     7869IT(swap);
     7870#undef PT
     7871#define PT ITSTRUCT(swap)
     7872
     7873#endif /* PNG_READ_SWAP_SUPPORTED */
     7874
     7875#ifdef PNG_READ_FILLER_SUPPORTED
     7876/* Add a filler byte to 8-bit Gray or 24-bit RGB images.
     7877 *
     7878 *  png_set_filler, (png_structp png_ptr, png_uint_32 filler, int flags));
     7879 *
     7880 * Flags:
     7881 *
     7882 *  PNG_FILLER_BEFORE
     7883 *  PNG_FILLER_AFTER
     7884 */
     7885#define data ITDATA(filler)
     7886static struct
     7887{
     7888   png_uint_32 filler;
     7889   int         flags;
     7890} data;
     7891
     7892static void
     7893image_transform_png_set_filler_set(PNG_CONST image_transform *this,
     7894    transform_display *that, png_structp pp, png_infop pi)
     7895{
     7896   /* Need a random choice for 'before' and 'after' as well as for the
     7897    * filler.  The 'filler' value has all 32 bits set, but only bit_depth
     7898    * will be used.  At this point we don't know bit_depth.
     7899    */
     7900   RANDOMIZE(data.filler);
     7901   data.flags = random_choice();
     7902
     7903   png_set_filler(pp, data.filler, data.flags);
     7904
     7905   /* The standard display handling stuff also needs to know that
     7906    * there is a filler, so set that here.
     7907    */
     7908   that->this.filler = 1;
     7909
     7910   this->next->set(this->next, that, pp, pi);
     7911}
     7912
     7913static void
     7914image_transform_png_set_filler_mod(PNG_CONST image_transform *this,
     7915    image_pixel *that, png_const_structp pp,
     7916    PNG_CONST transform_display *display)
     7917{
     7918   if (that->bit_depth >= 8 &&
     7919       (that->colour_type == PNG_COLOR_TYPE_RGB ||
     7920        that->colour_type == PNG_COLOR_TYPE_GRAY))
     7921   {
     7922      PNG_CONST unsigned int max = (1U << that->bit_depth)-1;
     7923      that->alpha = data.filler & max;
     7924      that->alphaf = ((double)that->alpha) / max;
     7925      that->alphae = 0;
     7926
     7927      /* The filler has been stored in the alpha channel, we must record
     7928       * that this has been done for the checking later on, the color
     7929       * type is faked to have an alpha channel, but libpng won't report
     7930       * this; the app has to know the extra channel is there and this
     7931       * was recording in standard_display::filler above.
     7932       */
     7933      that->colour_type |= 4; /* alpha added */
     7934      that->alpha_first = data.flags == PNG_FILLER_BEFORE;
     7935   }
     7936
     7937   this->next->mod(this->next, that, pp, display);
     7938}
     7939
     7940static int
     7941image_transform_png_set_filler_add(image_transform *this,
     7942    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     7943{
     7944   this->next = *that;
     7945   *that = this;
     7946
     7947   return bit_depth >= 8 && (colour_type == PNG_COLOR_TYPE_RGB ||
     7948           colour_type == PNG_COLOR_TYPE_GRAY);
     7949}
     7950
     7951#undef data
     7952IT(filler);
     7953#undef PT
     7954#define PT ITSTRUCT(filler)
     7955
     7956/* png_set_add_alpha, (png_structp png_ptr, png_uint_32 filler, int flags)); */
     7957/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */
     7958#define data ITDATA(add_alpha)
     7959static struct
     7960{
     7961   png_uint_32 filler;
     7962   int         flags;
     7963} data;
     7964
     7965static void
     7966image_transform_png_set_add_alpha_set(PNG_CONST image_transform *this,
     7967    transform_display *that, png_structp pp, png_infop pi)
     7968{
     7969   /* Need a random choice for 'before' and 'after' as well as for the
     7970    * filler.  The 'filler' value has all 32 bits set, but only bit_depth
     7971    * will be used.  At this point we don't know bit_depth.
     7972    */
     7973   RANDOMIZE(data.filler);
     7974   data.flags = random_choice();
     7975
     7976   png_set_add_alpha(pp, data.filler, data.flags);
     7977   this->next->set(this->next, that, pp, pi);
     7978}
     7979
     7980static void
     7981image_transform_png_set_add_alpha_mod(PNG_CONST image_transform *this,
     7982    image_pixel *that, png_const_structp pp,
     7983    PNG_CONST transform_display *display)
     7984{
     7985   if (that->bit_depth >= 8 &&
     7986       (that->colour_type == PNG_COLOR_TYPE_RGB ||
     7987        that->colour_type == PNG_COLOR_TYPE_GRAY))
     7988   {
     7989      PNG_CONST unsigned int max = (1U << that->bit_depth)-1;
     7990      that->alpha = data.filler & max;
     7991      that->alphaf = ((double)that->alpha) / max;
     7992      that->alphae = 0;
     7993
     7994      that->colour_type |= 4; /* alpha added */
     7995      that->alpha_first = data.flags == PNG_FILLER_BEFORE;
     7996   }
     7997
     7998   this->next->mod(this->next, that, pp, display);
     7999}
     8000
     8001static int
     8002image_transform_png_set_add_alpha_add(image_transform *this,
     8003    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     8004{
     8005   this->next = *that;
     8006   *that = this;
     8007
     8008   return bit_depth >= 8 && (colour_type == PNG_COLOR_TYPE_RGB ||
     8009           colour_type == PNG_COLOR_TYPE_GRAY);
     8010}
     8011
     8012#undef data
     8013IT(add_alpha);
     8014#undef PT
     8015#define PT ITSTRUCT(add_alpha)
     8016
     8017#endif /* PNG_READ_FILLER_SUPPORTED */
     8018
     8019/* png_set_packing */
     8020#ifdef PNG_READ_PACK_SUPPORTED
     8021/* Use 1 byte per pixel in 1, 2, or 4-bit depth files.
     8022 *
     8023 *  png_set_packing(png_structrp png_ptr)
     8024 *
     8025 * This should only affect grayscale and palette images with less than 8 bits
     8026 * per pixel.
     8027 */
     8028static void
     8029image_transform_png_set_packing_set(PNG_CONST image_transform *this,
     8030    transform_display *that, png_structp pp, png_infop pi)
     8031{
     8032   png_set_packing(pp);
     8033   that->unpacked = 1;
     8034   this->next->set(this->next, that, pp, pi);
     8035}
     8036
     8037static void
     8038image_transform_png_set_packing_mod(PNG_CONST image_transform *this,
     8039    image_pixel *that, png_const_structp pp,
     8040    PNG_CONST transform_display *display)
     8041{
     8042   /* The general expand case depends on what the colour type is,
     8043    * low bit-depth pixel values are unpacked into bytes without
     8044    * scaling, so sample_depth is not changed.
     8045    */
     8046   if (that->bit_depth < 8) /* grayscale or palette */
     8047      that->bit_depth = 8;
     8048
     8049   this->next->mod(this->next, that, pp, display);
     8050}
     8051
     8052static int
     8053image_transform_png_set_packing_add(image_transform *this,
     8054    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     8055{
     8056   UNUSED(colour_type)
     8057
     8058   this->next = *that;
     8059   *that = this;
     8060
     8061   /* Nothing should happen unless the bit depth is less than 8: */
     8062   return bit_depth < 8;
     8063}
     8064
     8065IT(packing);
     8066#undef PT
     8067#define PT ITSTRUCT(packing)
     8068
     8069#endif /* PNG_READ_PACK_SUPPORTED */
     8070
     8071/* png_set_packswap */
     8072#ifdef PNG_READ_PACKSWAP_SUPPORTED
     8073/* Swap pixels packed into bytes; reverses the order on screen so that
     8074 * the high order bits correspond to the rightmost pixels.
     8075 *
     8076 *  png_set_packswap(png_structrp png_ptr)
     8077 */
     8078static void
     8079image_transform_png_set_packswap_set(PNG_CONST image_transform *this,
     8080    transform_display *that, png_structp pp, png_infop pi)
     8081{
     8082   png_set_packswap(pp);
     8083   this->next->set(this->next, that, pp, pi);
     8084}
     8085
     8086static void
     8087image_transform_png_set_packswap_mod(PNG_CONST image_transform *this,
     8088    image_pixel *that, png_const_structp pp,
     8089    PNG_CONST transform_display *display)
     8090{
     8091   if (that->bit_depth < 8)
     8092      that->littleendian = 1;
     8093
     8094   this->next->mod(this->next, that, pp, display);
     8095}
     8096
     8097static int
     8098image_transform_png_set_packswap_add(image_transform *this,
     8099    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     8100{
     8101   UNUSED(colour_type)
     8102
     8103   this->next = *that;
     8104   *that = this;
     8105
     8106   return bit_depth < 8;
     8107}
     8108
     8109IT(packswap);
     8110#undef PT
     8111#define PT ITSTRUCT(packswap)
     8112
     8113#endif /* PNG_READ_PACKSWAP_SUPPORTED */
     8114
     8115
     8116/* png_set_invert_mono */
     8117#ifdef PNG_READ_INVERT_MONO_SUPPORTED
     8118/* Invert the gray channel
     8119 *
     8120 *  png_set_invert_mono(png_structrp png_ptr)
     8121 */
     8122static void
     8123image_transform_png_set_invert_mono_set(PNG_CONST image_transform *this,
     8124    transform_display *that, png_structp pp, png_infop pi)
     8125{
     8126   png_set_invert_mono(pp);
     8127   this->next->set(this->next, that, pp, pi);
     8128}
     8129
     8130static void
     8131image_transform_png_set_invert_mono_mod(PNG_CONST image_transform *this,
     8132    image_pixel *that, png_const_structp pp,
     8133    PNG_CONST transform_display *display)
     8134{
     8135   if (that->colour_type & 4)
     8136      that->mono_inverted = 1;
     8137
     8138   this->next->mod(this->next, that, pp, display);
     8139}
     8140
     8141static int
     8142image_transform_png_set_invert_mono_add(image_transform *this,
     8143    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     8144{
     8145   UNUSED(bit_depth)
     8146
     8147   this->next = *that;
     8148   *that = this;
     8149
     8150   /* Only has an effect on pixels with no colour: */
     8151   return (colour_type & 2) == 0;
     8152}
     8153
     8154IT(invert_mono);
     8155#undef PT
     8156#define PT ITSTRUCT(invert_mono)
     8157
     8158#endif /* PNG_READ_INVERT_MONO_SUPPORTED */
     8159
     8160#ifdef PNG_READ_SHIFT_SUPPORTED
     8161/* png_set_shift(png_structp, png_const_color_8p true_bits)
     8162 *
     8163 * The output pixels will be shifted by the given true_bits
     8164 * values.
     8165 */
     8166#define data ITDATA(shift)
     8167static png_color_8 data;
     8168
     8169static void
     8170image_transform_png_set_shift_set(PNG_CONST image_transform *this,
     8171    transform_display *that, png_structp pp, png_infop pi)
     8172{
     8173   /* Get a random set of shifts.  The shifts need to do something
     8174    * to test the transform, so they are limited to the bit depth
     8175    * of the input image.  Notice that in the following the 'gray'
     8176    * field is randomized independently.  This acts as a check that
     8177    * libpng does use the correct field.
     8178    */
     8179   PNG_CONST unsigned int depth = that->this.bit_depth;
     8180
     8181   data.red = (png_byte)/*SAFE*/(random_mod(depth)+1);
     8182   data.green = (png_byte)/*SAFE*/(random_mod(depth)+1);
     8183   data.blue = (png_byte)/*SAFE*/(random_mod(depth)+1);
     8184   data.gray = (png_byte)/*SAFE*/(random_mod(depth)+1);
     8185   data.alpha = (png_byte)/*SAFE*/(random_mod(depth)+1);
     8186
     8187   png_set_shift(pp, &data);
     8188   this->next->set(this->next, that, pp, pi);
     8189}
     8190
     8191static void
     8192image_transform_png_set_shift_mod(PNG_CONST image_transform *this,
     8193    image_pixel *that, png_const_structp pp,
     8194    PNG_CONST transform_display *display)
     8195{
     8196   /* Copy the correct values into the sBIT fields, libpng does not do
     8197    * anything to palette data:
     8198    */
     8199   if (that->colour_type != PNG_COLOR_TYPE_PALETTE)
     8200   {
     8201       that->sig_bits = 1;
     8202
     8203       /* The sBIT fields are reset to the values previously sent to
     8204        * png_set_shift according to the colour type.
     8205        * does.
     8206        */
     8207       if (that->colour_type & 2) /* RGB channels */
     8208       {
     8209          that->red_sBIT = data.red;
     8210          that->green_sBIT = data.green;
     8211          that->blue_sBIT = data.blue;
     8212       }
     8213
     8214       else /* One grey channel */
     8215          that->red_sBIT = that->green_sBIT = that->blue_sBIT = data.gray;
     8216
     8217       that->alpha_sBIT = data.alpha;
     8218   }
     8219
     8220   this->next->mod(this->next, that, pp, display);
     8221}
     8222
     8223static int
     8224image_transform_png_set_shift_add(image_transform *this,
     8225    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     8226{
     8227   UNUSED(bit_depth)
     8228
     8229   this->next = *that;
     8230   *that = this;
     8231
     8232   return colour_type != PNG_COLOR_TYPE_PALETTE;
     8233}
     8234
     8235IT(shift);
     8236#undef PT
     8237#define PT ITSTRUCT(shift)
     8238
     8239#endif /* PNG_READ_SHIFT_SUPPORTED */
     8240
     8241#ifdef THIS_IS_THE_PROFORMA
     8242static void
     8243image_transform_png_set_@_set(PNG_CONST image_transform *this,
     8244    transform_display *that, png_structp pp, png_infop pi)
     8245{
     8246   png_set_@(pp);
     8247   this->next->set(this->next, that, pp, pi);
     8248}
     8249
     8250static void
     8251image_transform_png_set_@_mod(PNG_CONST image_transform *this,
     8252    image_pixel *that, png_const_structp pp,
     8253    PNG_CONST transform_display *display)
     8254{
     8255   this->next->mod(this->next, that, pp, display);
     8256}
     8257
     8258static int
     8259image_transform_png_set_@_add(image_transform *this,
     8260    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
     8261{
     8262   this->next = *that;
     8263   *that = this;
     8264
     8265   return 1;
     8266}
     8267
     8268IT(@);
     8269#endif
     8270
    73998271
    74008272/* This may just be 'end' if all the transforms are disabled! */
     
    75758447}
    75768448
    7577 #ifdef THIS_IS_THE_PROFORMA
    7578 static void
    7579 image_transform_png_set_@_set(PNG_CONST image_transform *this,
    7580     transform_display *that, png_structp pp, png_infop pi)
    7581 {
    7582    png_set_@(pp);
    7583    this->next->set(this->next, that, pp, pi);
    7584 }
    7585 
    7586 static void
    7587 image_transform_png_set_@_mod(PNG_CONST image_transform *this,
    7588     image_pixel *that, png_const_structp pp,
    7589     PNG_CONST transform_display *display)
    7590 {
    7591    this->next->mod(this->next, that, pp, display);
    7592 }
    7593 
    7594 static int
    7595 image_transform_png_set_@_add(image_transform *this,
    7596     PNG_CONST image_transform **that, char *name, size_t sizeof_name,
    7597     size_t *pos, png_byte colour_type, png_byte bit_depth)
    7598 {
    7599    this->next = *that;
    7600    *that = this;
    7601 
    7602    *pos = safecat(name, sizeof_name, *pos, " +@");
    7603 
    7604    return 1;
    7605 }
    7606 
    7607 IT(@);
    7608 #endif
    7609 
    7610 /* png_set_quantize(png_structp, png_colorp palette, int num_palette,
    7611  *    int maximum_colors, png_const_uint_16p histogram, int full_quantize)
    7612  *
    7613  * Very difficult to validate this!
    7614  */
    7615 /*NOTE: TBD NYI */
    7616 
    7617 /* The data layout transforms are handled by swapping our own channel data,
    7618  * necessarily these need to happen at the end of the transform list because the
    7619  * semantic of the channels changes after these are executed.  Some of these,
    7620  * like set_shift and set_packing, can't be done at present because they change
    7621  * the layout of the data at the sub-sample level so sample() won't get the
    7622  * right answer.
    7623  */
    7624 /* png_set_invert_alpha */
    7625 /*NOTE: TBD NYI */
    7626 
    7627 /* png_set_bgr */
    7628 /*NOTE: TBD NYI */
    7629 
    7630 /* png_set_swap_alpha */
    7631 /*NOTE: TBD NYI */
    7632 
    7633 /* png_set_swap */
    7634 /*NOTE: TBD NYI */
    7635 
    7636 /* png_set_filler, (png_structp png_ptr, png_uint_32 filler, int flags)); */
    7637 /*NOTE: TBD NYI */
    7638 
    7639 /* png_set_add_alpha, (png_structp png_ptr, png_uint_32 filler, int flags)); */
    7640 /*NOTE: TBD NYI */
    7641 
    7642 /* png_set_packing */
    7643 /*NOTE: TBD NYI */
    7644 
    7645 /* png_set_packswap */
    7646 /*NOTE: TBD NYI */
    7647 
    7648 /* png_set_invert_mono */
    7649 /*NOTE: TBD NYI */
    7650 
    7651 /* png_set_shift(png_structp, png_const_color_8p true_bits) */
    7652 /*NOTE: TBD NYI */
    7653 
    76548449static void
    76558450perform_transform_test(png_modifier *pm)
     
    76598454   unsigned int palette_number = 0;
    76608455
    7661    while (next_format(&colour_type, &bit_depth, &palette_number, 0))
     8456   while (next_format(&colour_type, &bit_depth, &palette_number, pm->test_lbg,
     8457            pm->test_tRNS))
    76628458   {
    76638459      png_uint_32 counter = 0;
     
    79628758
    79638759   if ((dp->this.colour_type & PNG_COLOR_MASK_ALPHA) != 0 ||
    7964       (dp->this.colour_type == 3 && dp->this.is_transparent))
     8760      (dp->this.colour_type == 3 && dp->this.is_transparent) ||
     8761      ((dp->this.colour_type == 0 || dp->this.colour_type == 2) &&
     8762       dp->this.has_tRNS))
    79658763   {
    79668764      vi->do_background = dp->do_background;
     
    79928790      }
    79938791   }
    7994    else
     8792   else /* Do not expect any background processing */
    79958793      vi->do_background = 0;
    79968794
     
    87089506   PNG_CONST store_palette_entry *in_palette = dp->this.palette;
    87099507   PNG_CONST int in_is_transparent = dp->this.is_transparent;
     9508   int process_tRNS;
    87109509   int out_npalette = -1;
    87119510   int out_is_transparent = 0; /* Just refers to the palette case */
     
    87239522   processing = (vi.gamma_correction > 0 && !dp->threshold_test)
    87249523      || in_bd != out_bd || in_ct != out_ct || vi.do_background;
     9524   process_tRNS = dp->this.has_tRNS && vi.do_background;
    87259525
    87269526   /* TODO: FIX THIS: MAJOR BUG!  If the transformations all happen inside
     
    87549554            /* Record the palette index for index images. */
    87559555            PNG_CONST unsigned int in_index =
    8756                in_ct == 3 ? sample(std, 3, in_bd, x, 0) : 256;
     9556               in_ct == 3 ? sample(std, 3, in_bd, x, 0, 0, 0) : 256;
    87579557            PNG_CONST unsigned int out_index =
    8758                out_ct == 3 ? sample(std, 3, out_bd, x, 0) : 256;
     9558               out_ct == 3 ? sample(std, 3, out_bd, x, 0, 0, 0) : 256;
    87599559
    87609560            /* Handle input alpha - png_set_background will cause the output
    87619561             * alpha to disappear so there is nothing to check.
    87629562             */
    8763             if ((in_ct & PNG_COLOR_MASK_ALPHA) != 0 || (in_ct == 3 &&
    8764                in_is_transparent))
     9563            if ((in_ct & PNG_COLOR_MASK_ALPHA) != 0 ||
     9564                (in_ct == 3 && in_is_transparent))
    87659565            {
    87669566               PNG_CONST unsigned int input_alpha = in_ct == 3 ?
    87679567                  dp->this.palette[in_index].alpha :
    8768                   sample(std, in_ct, in_bd, x, samples_per_pixel);
     9568                  sample(std, in_ct, in_bd, x, samples_per_pixel, 0, 0);
    87699569
    87709570               unsigned int output_alpha = 65536 /* as a flag value */;
     
    87789578               else if ((out_ct & PNG_COLOR_MASK_ALPHA) != 0)
    87799579                  output_alpha = sample(pRow, out_ct, out_bd, x,
    8780                      samples_per_pixel);
     9580                     samples_per_pixel, 0, 0);
    87819581
    87829582               if (output_alpha != 65536)
     
    87949594            }
    87959595
     9596            else if (process_tRNS)
     9597            {
     9598               /* alpha needs to be set appropriately for this pixel, it is
     9599                * currently 1 and needs to be 0 for an input pixel which matches
     9600                * the values in tRNS.
     9601                */
     9602               switch (in_ct)
     9603               {
     9604                  case 0: /* gray */
     9605                     if (sample(std, in_ct, in_bd, x, 0, 0, 0) ==
     9606                           dp->this.transparent.red)
     9607                        alpha = 0;
     9608                     break;
     9609
     9610                  case 2: /* RGB */
     9611                     if (sample(std, in_ct, in_bd, x, 0, 0, 0) ==
     9612                           dp->this.transparent.red &&
     9613                         sample(std, in_ct, in_bd, x, 1, 0, 0) ==
     9614                           dp->this.transparent.green &&
     9615                         sample(std, in_ct, in_bd, x, 2, 0, 0) ==
     9616                           dp->this.transparent.blue)
     9617                        alpha = 0;
     9618                     break;
     9619
     9620                  default:
     9621                     break;
     9622               }
     9623            }
     9624
    87969625            /* Handle grayscale or RGB components. */
    87979626            if ((in_ct & PNG_COLOR_MASK_COLOR) == 0) /* grayscale */
    87989627               (void)gamma_component_validate("gray", &vi,
    8799                   sample(std, in_ct, in_bd, x, 0),
    8800                   sample(pRow, out_ct, out_bd, x, 0), alpha/*component*/,
    8801                   vi.background_red);
     9628                  sample(std, in_ct, in_bd, x, 0, 0, 0),
     9629                  sample(pRow, out_ct, out_bd, x, 0, 0, 0),
     9630                  alpha/*component*/, vi.background_red);
    88029631            else /* RGB or palette */
    88039632            {
    88049633               (void)gamma_component_validate("red", &vi,
    88059634                  in_ct == 3 ? in_palette[in_index].red :
    8806                      sample(std, in_ct, in_bd, x, 0),
     9635                     sample(std, in_ct, in_bd, x, 0, 0, 0),
    88079636                  out_ct == 3 ? out_palette[out_index].red :
    8808                      sample(pRow, out_ct, out_bd, x, 0),
     9637                     sample(pRow, out_ct, out_bd, x, 0, 0, 0),
    88099638                  alpha/*component*/, vi.background_red);
    88109639
    88119640               (void)gamma_component_validate("green", &vi,
    88129641                  in_ct == 3 ? in_palette[in_index].green :
    8813                      sample(std, in_ct, in_bd, x, 1),
     9642                     sample(std, in_ct, in_bd, x, 1, 0, 0),
    88149643                  out_ct == 3 ? out_palette[out_index].green :
    8815                      sample(pRow, out_ct, out_bd, x, 1),
     9644                     sample(pRow, out_ct, out_bd, x, 1, 0, 0),
    88169645                  alpha/*component*/, vi.background_green);
    88179646
    88189647               (void)gamma_component_validate("blue", &vi,
    88199648                  in_ct == 3 ? in_palette[in_index].blue :
    8820                      sample(std, in_ct, in_bd, x, 2),
     9649                     sample(std, in_ct, in_bd, x, 2, 0, 0),
    88219650                  out_ct == 3 ? out_palette[out_index].blue :
    8822                      sample(pRow, out_ct, out_bd, x, 2),
     9651                     sample(pRow, out_ct, out_bd, x, 2, 0, 0),
    88239652                  alpha/*component*/, vi.background_blue);
    88249653            }
     
    89039732      modification_reset(d.pm->modifications);
    89049733
    8905       /* Get a png_struct for writing the image. */
     9734      /* Get a png_struct for reading the image. */
    89069735      pp = set_modifier_for_read(d.pm, &pi, d.this.id, name);
    89079736      standard_palette_init(&d.this);
     
    90429871    * fact this test is somewhat excessive since libpng doesn't make this
    90439872    * decision based on colour type or bit depth!
    9044     */
    9045    while (next_format(&colour_type, &bit_depth, &palette_number, 1/*gamma*/))
    9046       if (palette_number == 0)
     9873    *
     9874    * CHANGED: now test two palettes and, as a side effect, images with and
     9875    * without tRNS.
     9876    */
     9877   while (next_format(&colour_type, &bit_depth, &palette_number,
     9878                      pm->test_lbg_gamma_threshold, pm->test_tRNS))
     9879      if (palette_number < 2)
    90479880   {
    90489881      double test_gamma = 1.0;
     
    91049937   unsigned int palette_number = 0;
    91059938
    9106    while (next_format(&colour_type, &bit_depth, &palette_number, 1/*gamma*/))
     9939   while (next_format(&colour_type, &bit_depth, &palette_number,
     9940                      pm->test_lbg_gamma_transform, pm->test_tRNS))
    91079941   {
    91089942      unsigned int i, j;
     
    91349968      unsigned int npalette = 0;
    91359969
    9136       while (next_format(&colour_type, &bit_depth, &npalette, 1/*gamma*/))
     9970      while (next_format(&colour_type, &bit_depth, &npalette,
     9971                         pm->test_lbg_gamma_sbit, pm->test_tRNS))
    91379972         if ((colour_type & PNG_COLOR_MASK_ALPHA) == 0 &&
    91389973            ((colour_type == 3 && sbit < 8) ||
     
    932510160
    932610161   background.index = 193; /* rgb(193,193,193) to detect errors */
     10162
    932710163   if (!(colour_type & PNG_COLOR_MASK_COLOR))
    932810164   {
     10165      /* Because, currently, png_set_background is always called with
     10166       * 'need_expand' false in this case and because the gamma test itself
     10167       * doesn't cause an expand to 8-bit for lower bit depths the colour must
     10168       * be reduced to the correct range.
     10169       */
     10170      if (bit_depth < 8)
     10171         background.gray &= (png_uint_16)((1U << bit_depth)-1);
     10172
    932910173      /* Grayscale input, we do not convert to RGB (TBD), so we must set the
    933010174       * background to gray - else libpng seems to fail.
     
    937510219   /* Skip the non-alpha cases - there is no setting of a transparency colour at
    937610220    * present.
    9377     */
    9378    while (next_format(&colour_type, &bit_depth, &palette_number, 1/*gamma*/))
    9379       if ((colour_type & PNG_COLOR_MASK_ALPHA) != 0)
     10221    *
     10222    * TODO: incorrect; the palette case sets tRNS and, now RGB and gray do,
     10223    * however the palette case fails miserably so is commented out below.
     10224    */
     10225   while (next_format(&colour_type, &bit_depth, &palette_number,
     10226                      pm->test_lbg_gamma_composition, pm->test_tRNS))
     10227      if ((colour_type & PNG_COLOR_MASK_ALPHA) != 0
     10228#if 0 /* TODO: FIXME */
     10229          /*TODO: FIXME: this should work */
     10230          || colour_type == 3
     10231#endif
     10232          || (colour_type != 3 && palette_number != 0))
    938010233   {
    938110234      unsigned int i, j;
     
    1010910962   pm.ngamma_tests = 0; /* default to off */
    1011010963
     10964   /* Low bit depth gray images don't do well in the gamma tests, until
     10965    * this is fixed turn them off for some gamma cases:
     10966    */
     10967#  ifdef PNG_WRITE_tRNS_SUPPORTED
     10968      pm.test_tRNS = 1;
     10969#  endif
     10970   pm.test_lbg = 0;
     10971   pm.test_lbg_gamma_threshold = 1;
     10972   pm.test_lbg_gamma_transform = 0/*PNG_LIBPNG_VER >= 10700*/;
     10973   pm.test_lbg_gamma_sbit = 1;
     10974   pm.test_lbg_gamma_composition = 0;
     10975
    1011110976   /* And the test encodings */
    1011210977   pm.encodings = test_encodings;
     
    1022111086         pm.test_gamma_sbit = 1;
    1022211087         pm.test_gamma_scale16 = 1;
    10223          pm.test_gamma_background = 1;
     11088         pm.test_gamma_background = 1; /* composition */
    1022411089         pm.test_gamma_alpha_mode = 1;
    1022511090         }
     
    1026911134      else if (strcmp(*argv, "--noexpand16") == 0)
    1027011135         pm.test_gamma_expand16 = 0;
     11136
     11137      else if (strcmp(*argv, "--low-depth-gray") == 0)
     11138         pm.test_lbg = pm.test_lbg_gamma_threshold =
     11139            pm.test_lbg_gamma_transform = pm.test_lbg_gamma_sbit =
     11140            pm.test_lbg_gamma_composition = 1;
     11141
     11142      else if (strcmp(*argv, "--nolow-depth-gray") == 0)
     11143         pm.test_lbg = pm.test_lbg_gamma_threshold =
     11144            pm.test_lbg_gamma_transform = pm.test_lbg_gamma_sbit =
     11145            pm.test_lbg_gamma_composition = 0;
     11146
     11147#     ifdef PNG_WRITE_tRNS_SUPPORTED
     11148         else if (strcmp(*argv, "--tRNS") == 0)
     11149            pm.test_tRNS = 1;
     11150#     endif
     11151
     11152      else if (strcmp(*argv, "--notRNS") == 0)
     11153         pm.test_tRNS = 0;
    1027111154
    1027211155      else if (strcmp(*argv, "--more-gammas") == 0)
     
    1046011343   {
    1046111344      /* Make useful base images */
    10462       make_transform_images(&pm.this);
     11345      make_transform_images(&pm);
    1046311346
    1046411347      /* Perform the standard and gamma tests. */
  • TabularUnified libpng/vendor/current/contrib/tools/png-fix-itxt.c

    r922 r1165  
    22/* png-fix-itxt version 1.0.0
    33 *
    4  * Copyright 2013 Glenn Randers-Pehrson
    5  * Last changed in libpng 1.6.3 [July 18, 2013]
     4 * Copyright 2015 Glenn Randers-Pehrson
     5 * Last changed in libpng 1.6.18 [July 23, 2015]
    66 *
    77 * This code is released under the libpng license.
     
    3535#define MAX_LENGTH 500000
    3636
    37 #define GETBREAK ((unsigned char)(inchar=getchar())); if (inchar == EOF) break
    38 
     37/* Read one character (inchar), also return octet (c), break if EOF */
     38#define GETBREAK inchar=getchar(); \
     39                 c=(inchar & 0xffU);\
     40                 if (inchar != c) break
    3941int
    4042main(void)
     
    4951   for (i=8; i; i--)
    5052   {
    51       c=GETBREAK;
     53      GETBREAK;
    5254      putchar(c);
    5355   }
    5456
    55 if (inchar != EOF)
     57if (inchar == c) /* !EOF */
    5658for (;;)
    5759 {
    5860   /* Read the length */
    5961   unsigned long length; /* must be 32 bits! */
    60    c=GETBREAK; buf[0] = c; length  = c; length <<= 8;
    61    c=GETBREAK; buf[1] = c; length += c; length <<= 8;
    62    c=GETBREAK; buf[2] = c; length += c; length <<= 8;
    63    c=GETBREAK; buf[3] = c; length += c;
     62   GETBREAK; buf[0] = c; length  = c; length <<= 8;
     63   GETBREAK; buf[1] = c; length += c; length <<= 8;
     64   GETBREAK; buf[2] = c; length += c; length <<= 8;
     65   GETBREAK; buf[3] = c; length += c;
    6466
    6567   /* Read the chunkname */
    66    c=GETBREAK; buf[4] = c;
    67    c=GETBREAK; buf[5] = c;
    68    c=GETBREAK; buf[6] = c;
    69    c=GETBREAK; buf[7] = c;
     68   GETBREAK; buf[4] = c;
     69   GETBREAK; buf[5] = c;
     70   GETBREAK; buf[6] = c;
     71   GETBREAK; buf[7] = c;
    7072
    7173
     
    8284      for (i=8; i < length + 12; i++)
    8385      {
    84          c=GETBREAK; buf[i] = c;
     86         GETBREAK; buf[i] = c;
    8587      }
     88
     89      if (inchar != c) /* EOF */
     90         break;
    8691
    8792      /* Calculate the CRC */
     
    9196      {
    9297        /* Check the CRC */
    93         if (((crc >> 24) & 0xff) == buf[length+8] &&
    94             ((crc >> 16) & 0xff) == buf[length+9] &&
    95             ((crc >>  8) & 0xff) == buf[length+10] &&
    96             ((crc      ) & 0xff) == buf[length+11])
     98        if (((crc >> 24) & 0xffU) == buf[length+8] &&
     99            ((crc >> 16) & 0xffU) == buf[length+9] &&
     100            ((crc >>  8) & 0xffU) == buf[length+10] &&
     101            ((crc      ) & 0xffU) == buf[length+11])
    97102           break;
    98103
     
    102107           break;
    103108
    104         c=GETBREAK;
    105         buf[length+11]=c;
     109        GETBREAK;
     110        buf[length+11] = c;
    106111
    107112        /* Update the CRC */
     
    109114      }
    110115
     116      if (inchar != c) /* EOF */
     117         break;
     118
    111119      /* Update length bytes */
    112       buf[0] = (unsigned char)((length << 24) & 0xff);
    113       buf[1] = (unsigned char)((length << 16) & 0xff);
    114       buf[2] = (unsigned char)((length <<  8) & 0xff);
    115       buf[3] = (unsigned char)((length      ) & 0xff);
     120      buf[0] = (unsigned char)((length >> 24) & 0xffU);
     121      buf[1] = (unsigned char)((length >> 16) & 0xffU);
     122      buf[2] = (unsigned char)((length >>  8) & 0xffU);
     123      buf[3] = (unsigned char)((length      ) & 0xffU);
    116124
    117125      /* Write the fixed iTXt chunk (length, name, data, crc) */
     
    122130   else
    123131   {
     132      if (inchar != c) /* EOF */
     133         break;
     134
    124135      /* Copy bytes that were already read (length and chunk name) */
    125136      for (i=0; i<8; i++)
     
    129140      for (i=8; i< length+12; i++)
    130141      {
    131          c=GETBREAK;
     142         GETBREAK;
    132143         putchar(c);
    133144      }
    134145
    135       if (inchar == EOF)
     146      if (inchar != c) /* EOF */
    136147      {
    137148         break;
     
    143154   }
    144155
    145    if (inchar == EOF)
     156   if (inchar != c) /* EOF */
    146157      break;
    147158
  • TabularUnified libpng/vendor/current/contrib/tools/pngfix.c

    r1059 r1165  
    11/* pngfix.c
    22 *
    3  * Copyright (c) 2014 John Cunningham Bowler
     3 * Copyright (c) 2014-2015 John Cunningham Bowler
    44 *
    5  * Last changed in libpng 1.6.14 [October 23, 2014]
     5 * Last changed in libpng 1.6.18 [July 23, 2015]
    66 *
    77 * This code is released under the libpng license.
     
    7272 */
    7373#if ZLIB_VERNUM < 0x1260
    74 #  define PNGZ_MSG_CAST(s) png_constcast(char*,s)
    75 #  define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)
     74#  define PNGZ_MSG_CAST(s) constcast(char*,s)
     75#  define PNGZ_INPUT_CAST(b) constcast(png_bytep,b)
    7676#else
    7777#  define PNGZ_MSG_CAST(s) (s)
     
    8787/* Copied from pngpriv.h */
    8888#ifdef __cplusplus
    89 #  define png_voidcast(type, value) static_cast<type>(value)
    90 #  define png_constcast(type, value) const_cast<type>(value)
    91 #  define png_aligncast(type, value) \
     89#  define voidcast(type, value) static_cast<type>(value)
     90#  define constcast(type, value) const_cast<type>(value)
     91#  define aligncast(type, value) \
    9292   static_cast<type>(static_cast<void*>(value))
    93 #  define png_aligncastconst(type, value) \
     93#  define aligncastconst(type, value) \
    9494   static_cast<type>(static_cast<const void*>(value))
    9595#else
    96 #  define png_voidcast(type, value) (value)
    97 #  define png_constcast(type, value) ((type)(value))
    98 #  define png_aligncast(type, value) ((void*)(value))
    99 #  define png_aligncastconst(type, value) ((const void*)(value))
     96#  define voidcast(type, value) (value)
     97#  define constcast(type, value) ((type)(value))
     98#  define aligncast(type, value) ((void*)(value))
     99#  define aligncastconst(type, value) ((const void*)(value))
    100100#endif /* __cplusplus */
    101101
     
    447447{
    448448   png_uint_32 u0 = seed[0], u1 = seed[1];
    449    png_bytep bytes = png_voidcast(png_bytep, pv);
     449   png_bytep bytes = voidcast(png_bytep, pv);
    450450
    451451   /* There are thirty-three bits; the next bit in the sequence is bit-33 XOR
     
    669669         length = tail->length;
    670670           
    671       next = png_voidcast(IDAT_list*, malloc(IDAT_list_size(NULL, length)));
     671      next = voidcast(IDAT_list*, malloc(IDAT_list_size(NULL, length)));
    672672      CLEAR(*next);
    673673
     
    21392139          * z-rc is the zlib failure code; message is the error message with
    21402140          * spaces replaced by '-'.  The compressed byte count indicates where
    2141           * in the zlib stream the error occured.
     2141          * in the zlib stream the error occurred.
    21422142          */
    21432143         type_name(zlib->chunk->chunk_type, stdout);
     
    35363536    * don't always exist.
    35373537    */
    3538    struct control *control = png_voidcast(struct control*,
     3538   struct control *control = voidcast(struct control*,
    35393539      png_get_error_ptr(png_ptr));
    35403540   return &control->file;
     
    35443544allocate(struct file *file, int allocate_idat)
    35453545{
    3546    struct control *control = png_voidcast(struct control*, file->alloc_ptr);
     3546   struct control *control = voidcast(struct control*, file->alloc_ptr);
    35473547
    35483548   if (allocate_idat)
     
    35783578   png_structp png_ptr;
    35793579   png_infop info_ptr = NULL;
    3580    volatile png_bytep row = NULL, display = NULL;
    35813580   volatile int rc;
    35823581
    3583    png_ptr = png_create_read_struct(png_get_libpng_ver(NULL), control,
     3582   png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, control,
    35843583      error_handler, warning_handler);
    35853584
     
    35953594   if (rc == 0)
    35963595   {
     3596#     ifdef PNG_SET_USER_LIMITS_SUPPORTED
     3597         /* Remove any limits on the size of PNG files that can be read,
     3598          * without this we may reject files based on built-in safety
     3599          * limits.
     3600          */
     3601         png_set_user_limits(png_ptr, 0x7fffffff, 0x7fffffff);
     3602         png_set_chunk_cache_max(png_ptr, 0);
     3603         png_set_chunk_malloc_max(png_ptr, 0);
     3604#     endif
     3605
    35973606      png_set_read_fn(png_ptr, control, read_callback);
    35983607
     
    36073616
    36083617      {
    3609          png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
    3610 
    3611          row = png_voidcast(png_byte*, malloc(rowbytes));
    3612          display = png_voidcast(png_byte*, malloc(rowbytes));
    3613 
    3614          if (row == NULL || display == NULL)
    3615             png_error(png_ptr, "OOM allocating row buffers");
    3616 
    3617          {
    3618             png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
    3619             int passes = png_set_interlace_handling(png_ptr);
    3620             int pass;
    3621 
    3622             png_start_read_image(png_ptr);
    3623 
    3624             for (pass = 0; pass < passes; ++pass)
    3625             {
    3626                png_uint_32 y = height;
    3627 
    3628                /* NOTE: this trashes the row each time; interlace handling won't
    3629                 * work, but this avoids memory thrashing for speed testing.
    3630                 */
    3631                while (y-- > 0)
    3632                   png_read_row(png_ptr, row, display);
    3633             }
    3634          }
     3618        png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
     3619        int passes = png_set_interlace_handling(png_ptr);
     3620        int pass;
     3621
     3622        png_start_read_image(png_ptr);
     3623
     3624        for (pass = 0; pass < passes; ++pass)
     3625        {
     3626           png_uint_32 y = height;
     3627
     3628           /* NOTE: this skips asking libpng to return either version of
     3629            * the image row, but libpng still reads the rows.
     3630            */
     3631           while (y-- > 0)
     3632              png_read_row(png_ptr, NULL, NULL);
     3633        }
    36353634      }
    36363635
     
    36433642
    36443643   png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
    3645    if (row != NULL) free(row);
    3646    if (display != NULL) free(display);
    36473644   return rc;
    36483645}
     
    37063703"            values.",
    37073704"        cHRM, iCCP [color]: These specify how colors are encoded.  iCCP also",
    3708 "            specifies the exact encoding of a pixel value however in practice",
    3709 "            most programs will ignore it.",
     3705"            specifies the exact encoding of a pixel value; however, in",
     3706"            practice most programs will ignore it.",
    37103707"        bKGD [transform]: This is used by libpng transforms."
    37113708"    --max=<number>:",
     
    37133710"      chunks will be the maximum size permitted; 2^31-1 bytes.  If the option",
    37143711"      is omitted the original chunk sizes will not be changed.  When the",
    3715 "      option is given --strip=unsafe is set automatically, this may be",
     3712"      option is given --strip=unsafe is set automatically. This may be",
    37163713"      cancelled if you know that all unknown unsafe-to-copy chunks really are",
    37173714"      safe to copy across an IDAT size change.  This is true of all chunks",
     
    37203717"      By default the program only outputs summaries for each file.",
    37213718"    --quiet (-q):",
    3722 "      Do not output the summaries except for files which cannot be read. With",
     3719"      Do not output the summaries except for files that cannot be read. With",
    37233720"      two --quiets these are not output either.",
    37243721"    --errors (-e):",
     
    37533750"  together - check one file at a time to get a meaningful error code!",
    37543751"    0x01: The zlib too-far-back error existed in at least one chunk.",
    3755 "    0x02: At least once chunk had a CRC error.",
     3752"    0x02: At least one chunk had a CRC error.",
    37563753"    0x04: A chunk length was incorrect.",
    37573754"    0x08: The file was truncated.",
     
    37613758"    0x10: The file could not be read, even with corrections.",
    37623759"    0x20: The output file could not be written.",
    3763 "    0x40: An unexpected, potentially internal, error occured.",
     3760"    0x40: An unexpected, potentially internal, error occurred.",
    37643761"  If the command line arguments are incorrect the program exits with exit",
    37653762"  255.  Some older operating systems only support 7-bit exit codes, on those",
     
    38213818"               explanation 'message'",
    38223819"          ERR: The read of the file was aborted.  The parameters explain why.",
    3823 "$3 status:     For 'ERR' the accumulate status code from 'EXIT CODES' above.",
     3820"$3 status:     For 'ERR' the accumulated status code from 'EXIT CODES' above.",
    38243821"               This is printed as a 2 digit hexadecimal value",
    38253822"   comp-level: The recorded compression level (FLEVEL) of a zlib stream",
     
    38573854main(int argc, const char **argv)
    38583855{
     3856   char temp_name[FILENAME_MAX+1];
    38593857   const char *  prog = *argv;
    38603858   const char *  outfile = NULL;
     
    39593957      {
    39603958         size_t outlen = strlen(*argv);
    3961          char temp_name[FILENAME_MAX+1];
    39623959
    39633960         if (outfile == NULL) /* else this takes precedence */
  • TabularUnified libpng/vendor/current/contrib/visupng/cexcept.h

    r922 r1165  
    11/*===
    2 cexcept.h 2.0.1 (2008-Jul-19-Sat)
     2cexcept.h 2.0.1 (2008-Jul-19-Sat, modified 2015-Jun-03-Mon)
    33http://www.nicemice.net/cexcept/
    44Adam M. Costello
     
    66
    77An interface for exception-handling in ANSI C (C89 and subsequent ISO
    8 standards), developed jointly with Cosmin Truta.
     8standards), developed jointly with Cosmin Truta.  Revised by John Bowler,
     9June 2015, to declare exception_env and exception_prev "volatile".
    910
    1011    Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.
     
    211212#define Try \
    212213  { \
    213     jmp_buf *exception__prev, exception__env; \
     214    jmp_buf * volatile exception__prev, exception__env; \
    214215    exception__prev = the_exception_context->penv; \
    215216    the_exception_context->penv = &exception__env; \
  • TabularUnified libpng/vendor/current/depcomp

    r922 r1165  
    44scriptversion=2013-05-30.07; # UTC
    55
    6 # Copyright (C) 1999-2013 Free Software Foundation, Inc.
     6# Copyright (C) 1999-2014 Free Software Foundation, Inc.
    77
    88# This program is free software; you can redistribute it and/or modify
  • TabularUnified libpng/vendor/current/libpng-manual.txt

    r1059 r1165  
    11libpng-manual.txt - A description on how to use and modify libpng
    22
    3  libpng version 1.6.16 - December 22, 2014
     3 libpng version 1.6.18 - July 23, 2015
    44 Updated and distributed by Glenn Randers-Pehrson
    55 <glennrp at users.sourceforge.net>
    6  Copyright (c) 1998-2014 Glenn Randers-Pehrson
     6 Copyright (c) 1998-2015 Glenn Randers-Pehrson
    77
    88 This document is released under the libpng license.
     
    1212 Based on:
    1313
    14  libpng versions 0.97, January 1998, through 1.6.16 - December 22, 2014
     14 libpng versions 0.97, January 1998, through 1.6.18 - July 23, 2015
    1515 Updated and distributed by Glenn Randers-Pehrson
    16  Copyright (c) 1998-2014 Glenn Randers-Pehrson
     16 Copyright (c) 1998-2015 Glenn Randers-Pehrson
    1717
    1818 libpng 1.0 beta 6 - version 0.96 - May 28, 1997
     
    337337If you are intending to keep the file pointer open for use in libpng,
    338338you must ensure you don't read more than 8 bytes from the beginning
    339 of the file, and you also have to make a call to png_set_sig_bytes_read()
     339of the file, and you also have to make a call to png_set_sig_bytes()
    340340with the number of bytes you read from the beginning.  Libpng will
    341341then only check the bytes (if any) that your program didn't read.
     
    344344to replace them with custom functions.  See the discussion under
    345345Customizing libpng.
    346 
    347346
    348347    FILE *fp = fopen(file_name, "rb");
     
    352351    }
    353352
    354     fread(header, 1, number, fp);
     353    if (fread(header, 1, number, fp) != number)
     354    {
     355       return (ERROR);
     356    }
     357
    355358    is_png = !png_sig_cmp(header, 0, number);
    356 
    357359    if (!is_png)
    358360    {
    359361       return (NOT_PNG);
    360362    }
    361 
    362363
    363364Next, png_struct and png_info need to be allocated and initialized.  In
     
    650651large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
    651652Larger images will be rejected immediately with a png_error() call. If
    652 you wish to reduce these limits, you can use
     653you wish to change these limits, you can use
    653654
    654655   png_set_user_limits(png_ptr, width_max, height_max);
     
    12651266                     a MNG-1.0 datastream)
    12661267
    1267     Any or all of interlace_type, compression_type, or
    1268     filter_method can be NULL if you are
    1269     not interested in their values.
     1268    Any of width, height, color_type, bit_depth,
     1269    interlace_type, compression_type, or filter_method can
     1270    be NULL if you are not interested in their values.
    12701271
    12711272    Note that png_get_IHDR() returns 32-bit data into
    12721273    the application's width and height variables.
    1273     This is an unsafe situation if these are 16-bit
     1274    This is an unsafe situation if these are not png_uint_32
    12741275    variables.  In such situations, the
    12751276    png_get_image_width() and png_get_image_height()
     
    19941995
    19951996If you need to reduce an RGB file to a paletted file, or if a paletted
    1996 file has more entries then will fit on your screen, png_set_quantize()
     1997file has more entries than will fit on your screen, png_set_quantize()
    19971998will do that.  Note that this is a simple match quantization that merely
    19981999finds the closest color available.  This should work fairly well with
     
    25472548       of 4K. Although you can give it much less if
    25482549       necessary (I assume you can give it chunks of
    2549        1 byte, I haven't tried less then 256 bytes
     2550       1 byte, I haven't tried less than 256 bytes
    25502551       yet).  When this function returns, you may
    25512552       want to display any rows that were generated
     
    40654066With all APIs row_stride is handled as in the read APIs - it is the spacing
    40664067from one row to the next in component sized units (float) and if negative
    4067 indicates a bottom-up row layout in the buffer.
     4068indicates a bottom-up row layout in the buffer.  If you pass zero, libpng will
     4069calculate the row_stride for you from the width and number of channels.
    40684070
    40694071Note that the write API does not support interlacing, sub-8-bit pixels,
    4070 and indexed (paletted) images.
     4072indexed (paletted) images, or most ancillary chunks.
    40714073
    40724074VI. Modifying/Customizing libpng
     
    43554357              same as the value of filter_method used
    43564358              in png_set_IHDR().
    4357 
    4358 It is also possible to influence how libpng chooses from among the
    4359 available filters.  This is done in one or both of two ways - by
    4360 telling it how important it is to keep the same filter for successive
    4361 rows, and by telling it the relative computational costs of the filters.
    4362 
    4363     double weights[3] = {1.5, 1.3, 1.1},
    4364        costs[PNG_FILTER_VALUE_LAST] =
    4365        {1.0, 1.3, 1.3, 1.5, 1.7};
    4366 
    4367     png_set_filter_heuristics(png_ptr,
    4368        PNG_FILTER_HEURISTIC_WEIGHTED, 3,
    4369        weights, costs);
    4370 
    4371 The weights are multiplying factors that indicate to libpng that the
    4372 row filter should be the same for successive rows unless another row filter
    4373 is that many times better than the previous filter.  In the above example,
    4374 if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
    4375 "sum of absolute differences" 1.5 x 1.3 times higher than other filters
    4376 and still be chosen, while the NONE filter could have a sum 1.1 times
    4377 higher than other filters and still be chosen.  Unspecified weights are
    4378 taken to be 1.0, and the specified weights should probably be declining
    4379 like those above in order to emphasize recent filters over older filters.
    4380 
    4381 The filter costs specify for each filter type a relative decoding cost
    4382 to be considered when selecting row filters.  This means that filters
    4383 with higher costs are less likely to be chosen over filters with lower
    4384 costs, unless their "sum of absolute differences" is that much smaller.
    4385 The costs do not necessarily reflect the exact computational speeds of
    4386 the various filters, since this would unduly influence the final image
    4387 size.
    4388 
    4389 Note that the numbers above were invented purely for this example and
    4390 are given only to help explain the function usage.  Little testing has
    4391 been done to find optimum values for either the costs or the weights.
    43924359
    43934360Requesting debug printout
     
    50324999where "rp" indicates a "restricted pointer".
    50335000
     5001The support for FAR/far types has been eliminated and the definition of
     5002png_alloc_size_t is now controlled by a flag so that 'small size_t' systems
     5003can select it if necessary.
     5004
    50345005Error detection in some chunks has improved; in particular the iCCP chunk
    50355006reader now does pretty complete validation of the basic format.  Some bad
     
    50465017    #endif
    50475018
    5048 It's not a good idea to do this if you are using the new "simplified API",
     5019It's not a good idea to do this if you are using the "simplified API",
    50495020which needs to be able to recognize sRGB profiles conveyed via the iCCP
    50505021chunk.
     
    51055076contrib/tools/png-fix-itxt) has been added to the libpng distribution.
    51065077
     5078Starting with libpng-1.6.17, the PNG_SAFE_LIMITS macro was eliminated
     5079and safe limits are used by default (users who need larger limits
     5080can still override them at compile time or run time, as described above).
     5081
     5082The new limits are
     5083                                default   spec limit
     5084   png_user_width_max         1,000,000  2,147,483,647
     5085   png_user_height_max        1,000,000  2,147,483,647
     5086   png_user_chunk_cache_max         128  unlimited
     5087   png_user_chunk_malloc_max  8,000,000  unlimited
     5088
     5089Starting with libpng-1.6.18, a PNG_RELEASE_BUILD macro was added, which allows
     5090library builders to control compilation for an installed system (a release build).
     5091It can be set for testing debug or beta builds to ensure that they will compile
     5092when the build type is switched to RC or STABLE. In essence this overrides the
     5093PNG_LIBPNG_BUILD_BASE_TYPE definition which is not directly user controllable.
     5094
    51075095XIII.  Detecting libpng
    51085096
     
    52755263XVI. Y2K Compliance in libpng
    52765264
    5277 December 22, 2014
     5265July 23, 2015
    52785266
    52795267Since the PNG Development group is an ad-hoc body, we can't make
     
    52815269
    52825270This is your unofficial assurance that libpng from version 0.71 and
    5283 upward through 1.6.16 are Y2K compliant.  It is my belief that earlier
     5271upward through 1.6.18 are Y2K compliant.  It is my belief that earlier
    52845272versions were also Y2K compliant.
    52855273
  • TabularUnified libpng/vendor/current/libpng.3

    r1059 r1165  
    1 .TH LIBPNG 3 "December 22, 2014"
     1.TH LIBPNG 3 "July 23, 2015"
    22.SH NAME
    3 libpng \- Portable Network Graphics (PNG) Reference Library 1.6.16
     3libpng \- Portable Network Graphics (PNG) Reference Library 1.6.18
    44.SH SYNOPSIS
    55\fB
     
    120120\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
    121121
     122\fBint png_get_palette_max(png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
     123
    122124\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
    123125
     
    369371
    370372\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP
     373
     374\fBint png_set_option(png_structrp \fP\fIpng_ptr\fP\fB, int \fP\fIoption\fP\fB, int \fIonoff\fP\fB);\fP
    371375
    372376\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
     
    505509libpng-manual.txt - A description on how to use and modify libpng
    506510
    507  libpng version 1.6.16 - December 22, 2014
     511 libpng version 1.6.18 - July 23, 2015
    508512 Updated and distributed by Glenn Randers-Pehrson
    509513 <glennrp at users.sourceforge.net>
    510  Copyright (c) 1998-2014 Glenn Randers-Pehrson
     514 Copyright (c) 1998-2015 Glenn Randers-Pehrson
    511515
    512516 This document is released under the libpng license.
     
    516520 Based on:
    517521
    518  libpng versions 0.97, January 1998, through 1.6.16 - December 22, 2014
     522 libpng versions 0.97, January 1998, through 1.6.18 - July 23, 2015
    519523 Updated and distributed by Glenn Randers-Pehrson
    520  Copyright (c) 1998-2014 Glenn Randers-Pehrson
     524 Copyright (c) 1998-2015 Glenn Randers-Pehrson
    521525
    522526 libpng 1.0 beta 6 - version 0.96 - May 28, 1997
     
    841845If you are intending to keep the file pointer open for use in libpng,
    842846you must ensure you don't read more than 8 bytes from the beginning
    843 of the file, and you also have to make a call to png_set_sig_bytes_read()
     847of the file, and you also have to make a call to png_set_sig_bytes()
    844848with the number of bytes you read from the beginning.  Libpng will
    845849then only check the bytes (if any) that your program didn't read.
     
    848852to replace them with custom functions.  See the discussion under
    849853Customizing libpng.
    850 
    851854
    852855    FILE *fp = fopen(file_name, "rb");
     
    856859    }
    857860
    858     fread(header, 1, number, fp);
     861    if (fread(header, 1, number, fp) != number)
     862    {
     863       return (ERROR);
     864    }
     865
    859866    is_png = !png_sig_cmp(header, 0, number);
    860 
    861867    if (!is_png)
    862868    {
    863869       return (NOT_PNG);
    864870    }
    865 
    866871
    867872Next, png_struct and png_info need to be allocated and initialized.  In
     
    11541159large as 2^(31\-1 (0x7fffffff), or about 2.147 billion rows and columns.
    11551160Larger images will be rejected immediately with a png_error() call. If
    1156 you wish to reduce these limits, you can use
     1161you wish to change these limits, you can use
    11571162
    11581163   png_set_user_limits(png_ptr, width_max, height_max);
     
    17691774                     a MNG-1.0 datastream)
    17701775
    1771     Any or all of interlace_type, compression_type, or
    1772     filter_method can be NULL if you are
    1773     not interested in their values.
     1776    Any of width, height, color_type, bit_depth,
     1777    interlace_type, compression_type, or filter_method can
     1778    be NULL if you are not interested in their values.
    17741779
    17751780    Note that png_get_IHDR() returns 32-bit data into
    17761781    the application's width and height variables.
    1777     This is an unsafe situation if these are 16-bit
     1782    This is an unsafe situation if these are not png_uint_32
    17781783    variables.  In such situations, the
    17791784    png_get_image_width() and png_get_image_height()
     
    24982503
    24992504If you need to reduce an RGB file to a paletted file, or if a paletted
    2500 file has more entries then will fit on your screen, png_set_quantize()
     2505file has more entries than will fit on your screen, png_set_quantize()
    25012506will do that.  Note that this is a simple match quantization that merely
    25022507finds the closest color available.  This should work fairly well with
     
    30513056       of 4K. Although you can give it much less if
    30523057       necessary (I assume you can give it chunks of
    3053        1 byte, I haven't tried less then 256 bytes
     3058       1 byte, I haven't tried less than 256 bytes
    30543059       yet).  When this function returns, you may
    30553060       want to display any rows that were generated
     
    45694574With all APIs row_stride is handled as in the read APIs - it is the spacing
    45704575from one row to the next in component sized units (float) and if negative
    4571 indicates a bottom-up row layout in the buffer.
     4576indicates a bottom-up row layout in the buffer.  If you pass zero, libpng will
     4577calculate the row_stride for you from the width and number of channels.
    45724578
    45734579Note that the write API does not support interlacing, sub-8-bit pixels,
    4574 and indexed (paletted) images.
     4580indexed (paletted) images, or most ancillary chunks.
    45754581
    45764582.SH VI. Modifying/Customizing libpng
     
    48594865              same as the value of filter_method used
    48604866              in png_set_IHDR().
    4861 
    4862 It is also possible to influence how libpng chooses from among the
    4863 available filters.  This is done in one or both of two ways - by
    4864 telling it how important it is to keep the same filter for successive
    4865 rows, and by telling it the relative computational costs of the filters.
    4866 
    4867     double weights[3] = {1.5, 1.3, 1.1},
    4868        costs[PNG_FILTER_VALUE_LAST] =
    4869        {1.0, 1.3, 1.3, 1.5, 1.7};
    4870 
    4871     png_set_filter_heuristics(png_ptr,
    4872        PNG_FILTER_HEURISTIC_WEIGHTED, 3,
    4873        weights, costs);
    4874 
    4875 The weights are multiplying factors that indicate to libpng that the
    4876 row filter should be the same for successive rows unless another row filter
    4877 is that many times better than the previous filter.  In the above example,
    4878 if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
    4879 "sum of absolute differences" 1.5 x 1.3 times higher than other filters
    4880 and still be chosen, while the NONE filter could have a sum 1.1 times
    4881 higher than other filters and still be chosen.  Unspecified weights are
    4882 taken to be 1.0, and the specified weights should probably be declining
    4883 like those above in order to emphasize recent filters over older filters.
    4884 
    4885 The filter costs specify for each filter type a relative decoding cost
    4886 to be considered when selecting row filters.  This means that filters
    4887 with higher costs are less likely to be chosen over filters with lower
    4888 costs, unless their "sum of absolute differences" is that much smaller.
    4889 The costs do not necessarily reflect the exact computational speeds of
    4890 the various filters, since this would unduly influence the final image
    4891 size.
    4892 
    4893 Note that the numbers above were invented purely for this example and
    4894 are given only to help explain the function usage.  Little testing has
    4895 been done to find optimum values for either the costs or the weights.
    48964867
    48974868.SS Requesting debug printout
     
    55365507where "rp" indicates a "restricted pointer".
    55375508
     5509The support for FAR/far types has been eliminated and the definition of
     5510png_alloc_size_t is now controlled by a flag so that 'small size_t' systems
     5511can select it if necessary.
     5512
    55385513Error detection in some chunks has improved; in particular the iCCP chunk
    55395514reader now does pretty complete validation of the basic format.  Some bad
     
    55505525    #endif
    55515526
    5552 It's not a good idea to do this if you are using the new "simplified API",
     5527It's not a good idea to do this if you are using the "simplified API",
    55535528which needs to be able to recognize sRGB profiles conveyed via the iCCP
    55545529chunk.
     
    56095584contrib/tools/png-fix-itxt) has been added to the libpng distribution.
    56105585
     5586Starting with libpng-1.6.17, the PNG_SAFE_LIMITS macro was eliminated
     5587and safe limits are used by default (users who need larger limits
     5588can still override them at compile time or run time, as described above).
     5589
     5590The new limits are
     5591                                default   spec limit
     5592   png_user_width_max         1,000,000  2,147,483,647
     5593   png_user_height_max        1,000,000  2,147,483,647
     5594   png_user_chunk_cache_max         128  unlimited
     5595   png_user_chunk_malloc_max  8,000,000  unlimited
     5596
     5597Starting with libpng-1.6.18, a PNG_RELEASE_BUILD macro was added, which allows
     5598library builders to control compilation for an installed system (a release build).
     5599It can be set for testing debug or beta builds to ensure that they will compile
     5600when the build type is switched to RC or STABLE. In essence this overrides the
     5601PNG_LIBPNG_BUILD_BASE_TYPE definition which is not directly user controllable.
     5602
    56115603.SH XIII.  Detecting libpng
    56125604
     
    57795771.SH XVI. Y2K Compliance in libpng
    57805772
    5781 December 22, 2014
     5773July 23, 2015
    57825774
    57835775Since the PNG Development group is an ad-hoc body, we can't make
     
    57855777
    57865778This is your unofficial assurance that libpng from version 0.71 and
    5787 upward through 1.6.16 are Y2K compliant.  It is my belief that earlier
     5779upward through 1.6.18 are Y2K compliant.  It is my belief that earlier
    57885780versions were also Y2K compliant.
    57895781
     
    60376029 1.6.16rc01-02       16    10616  16.so.16.16[.0]
    60386030 1.6.16              16    10616  16.so.16.16[.0]
     6031 1.6.17beta01-06     16    10617  16.so.16.17[.0]
     6032 1.6.17rc01-06       16    10617  16.so.16.17[.0]
     6033 1.6.17              16    10617  16.so.16.17[.0]
     6034 1.6.18beta01-09     16    10618  16.so.16.18[.0]
     6035 1.6.18rc01-03       16    10618  16.so.16.18[.0]
     6036 1.6.18              16    10618  16.so.16.18[.0]
    60396037
    60406038Henceforth the source version will match the shared-library minor
     
    60936091Thanks to Frank J. T. Wojcik for helping with the documentation.
    60946092
    6095 Libpng version 1.6.16 - December 22, 2014:
     6093Libpng version 1.6.18 - July 23, 2015:
    60966094Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
    60976095Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
     
    61166114This code is released under the libpng license.
    61176115
    6118 libpng versions 1.2.6, August 15, 2004, through 1.6.16, December 22, 2014, are
    6119 Copyright (c) 2004,2006-2014 Glenn Randers-Pehrson, and are
    6120 distributed according to the same disclaimer and license as libpng-1.2.5
    6121 with the following individual added to the list of Contributing Authors
    6122 
    6123    Cosmin Truta
    6124 
    6125 libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
    6126 Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
     6116libpng versions 1.0.7, July 1, 2000, through 1.6.18, July 23, 2015, are
     6117Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, and are
    61276118distributed according to the same disclaimer and license as libpng-1.0.6
    6128 with the following individuals added to the list of Contributing Authors
     6119with the following individuals added to the list of Contributing Authors:
    61296120
    61306121   Simon-Pierre Cadieux
    61316122   Eric S. Raymond
     6123   Mans Rullgard
     6124   Cosmin Truta
    61326125   Gilles Vollant
     6126   James Yu
    61336127
    61346128and with the following additions to the disclaimer:
    61356129
    6136    There is no warranty against interference with your
    6137    enjoyment of the library or against infringement.
    6138    There is no warranty that our efforts or the library
    6139    will fulfill any of your particular purposes or needs.
    6140    This library is provided with all faults, and the entire
    6141    risk of satisfactory quality, performance, accuracy, and
    6142    effort is with the user.
     6130   There is no warranty against interference with your enjoyment of the
     6131   library or against infringement.  There is no warranty that our
     6132   efforts or the library will fulfill any of your particular purposes
     6133   or needs.  This library is provided with all faults, and the entire
     6134   risk of satisfactory quality, performance, accuracy, and effort is with
     6135   the user.
    61436136
    61446137libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
    6145 Copyright (c) 1998, 1999 Glenn Randers-Pehrson
    6146 Distributed according to the same disclaimer and license as libpng-0.96,
    6147 with the following individuals added to the list of Contributing Authors:
     6138Copyright (c) 1998-2000 Glenn Randers-Pehrson, and are distributed according
     6139to the same disclaimer and license as libpng-0.96, with the following
     6140individuals added to the list of Contributing Authors:
    61486141
    61496142   Tom Lane
     
    61526145
    61536146libpng versions 0.89, June 1996, through 0.96, May 1997, are
    6154 Copyright (c) 1996, 1997 Andreas Dilger
    6155 Distributed according to the same disclaimer and license as libpng-0.88,
     6147Copyright (c) 1996-1997 Andreas Dilger, and are
     6148distributed according to the same disclaimer and license as libpng-0.88,
    61566149with the following individuals added to the list of Contributing Authors:
    61576150
     
    61646157
    61656158libpng versions 0.5, May 1995, through 0.88, January 1996, are
    6166 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
     6159Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
    61676160
    61686161For the purposes of this copyright and license, "Contributing Authors"
     
    61876180to the following restrictions:
    61886181
    6189 1. The origin of this source code must not be misrepresented.
    6190 
    6191 2. Altered versions must be plainly marked as such and
    6192    must not be misrepresented as being the original source.
    6193 
    6194 3. This Copyright notice may not be removed or altered from
    6195    any source or altered source distribution.
     6182  1. The origin of this source code must not be misrepresented.
     6183
     6184  2. Altered versions must be plainly marked as such and must not
     6185     be misrepresented as being the original source.
     6186
     6187  3. This Copyright notice may not be removed or altered from any
     6188     source or altered source distribution.
    61966189
    61976190The Contributing Authors and Group 42, Inc. specifically permit, without
     
    62016194appreciated.
    62026195
    6203 
    62046196A "png_get_copyright" function is available, for convenient use in "about"
    62056197boxes and the like:
    62066198
    6207    printf("%s",png_get_copyright(NULL));
     6199   printf("%s", png_get_copyright(NULL));
    62086200
    62096201Also, the PNG logo (in PNG format, of course) is supplied in the
    62106202files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
    62116203
    6212 Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is a
    6213 certification mark of the Open Source Initiative.
     6204Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is
     6205a certification mark of the Open Source Initiative. OSI has not addressed
     6206the additional disclaimers inserted at version 1.0.7.
    62146207
    62156208Glenn Randers-Pehrson
    62166209glennrp at users.sourceforge.net
    6217 December 22, 2014
     6210July 23, 2015
    62186211
    62196212.\" end of man page
  • TabularUnified libpng/vendor/current/libpngpf.3

    r1059 r1165  
    1 .TH LIBPNGPF 3 "December 22, 2014"
     1.TH LIBPNGPF 3 "July 23, 2015"
    22.SH NAME
    3 libpng \- Portable Network Graphics (PNG) Reference Library 1.6.16
     3libpng \- Portable Network Graphics (PNG) Reference Library 1.6.18
    44(private functions)
    55.SH SYNOPSIS
  • TabularUnified libpng/vendor/current/png.5

    r1059 r1165  
    1 .TH PNG 5 "December 22, 2014"
     1.TH PNG 5 "July 23, 2015"
    22.SH NAME
    33png \- Portable Network Graphics (PNG) format
  • TabularUnified libpng/vendor/current/png.c

    r1059 r1165  
    22/* png.c - location for general purpose libpng functions
    33 *
    4  * Last changed in libpng 1.6.16 [December 22, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    1515
    1616/* Generate a compiler error if there is an old png.h in the search path. */
    17 typedef png_libpng_version_1_6_16 Your_png_h_is_not_version_1_6_16;
     17typedef png_libpng_version_1_6_18 Your_png_h_is_not_version_1_6_18;
    1818
    1919/* Tells libpng that we have already handled the first "num_bytes" bytes
     
    3535      png_error(png_ptr, "Too many bytes for PNG signature");
    3636
    37    png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
     37   png_ptr->sig_bytes = (png_byte)((num_bytes < 0 ? 0 : num_bytes) & 0xff);
    3838}
    3939
     
    102102png_reset_crc(png_structrp png_ptr)
    103103{
    104    /* The cast is safe because the crc is a 32 bit value. */
     104   /* The cast is safe because the crc is a 32-bit value. */
    105105   png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0);
    106106}
     
    130130
    131131   /* 'uLong' is defined in zlib.h as unsigned long; this means that on some
    132     * systems it is a 64 bit value.  crc32, however, returns 32 bits so the
     132    * systems it is a 64-bit value.  crc32, however, returns 32 bits so the
    133133    * following cast is safe.  'uInt' may be no more than 16 bits, so it is
    134134    * necessary to perform a loop here.
     
    141141      {
    142142         uInt safe_length = (uInt)length;
     143#ifndef __COVERITY__
    143144         if (safe_length == 0)
    144145            safe_length = (uInt)-1; /* evil, but safe */
     146#endif
    145147
    146148         crc = crc32(crc, ptr, safe_length);
     
    242244
    243245#     ifdef PNG_USER_CHUNK_CACHE_MAX
    244          /* Added at libpng-1.2.43 and 1.4.0 */
    245          create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
     246      /* Added at libpng-1.2.43 and 1.4.0 */
     247      create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
    246248#     endif
    247249
    248250#     ifdef PNG_USER_CHUNK_MALLOC_MAX
    249          /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists
    250           * in png_struct regardless.
    251           */
    252          create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
     251      /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists
     252       * in png_struct regardless.
     253       */
     254      create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
    253255#     endif
    254256#  endif
     
    274276#  ifdef PNG_SETJMP_SUPPORTED
    275277      if (!setjmp(create_jmp_buf))
     278#  endif
    276279      {
     280#  ifdef PNG_SETJMP_SUPPORTED
    277281         /* Temporarily fake out the longjmp information until we have
    278282          * successfully completed this function.  This only works if we have
     
    283287         create_struct.jmp_buf_size = 0; /*stack allocation*/
    284288         create_struct.longjmp_fn = longjmp;
    285 #  else
    286       {
    287289#  endif
    288290         /* Call the general version checker (shared with read and write code):
     
    303305
    304306#              ifdef PNG_SETJMP_SUPPORTED
    305                   /* Eliminate the local error handling: */
    306                   create_struct.jmp_buf_ptr = NULL;
    307                   create_struct.jmp_buf_size = 0;
    308                   create_struct.longjmp_fn = 0;
     307               /* Eliminate the local error handling: */
     308               create_struct.jmp_buf_ptr = NULL;
     309               create_struct.jmp_buf_size = 0;
     310               create_struct.longjmp_fn = 0;
    309311#              endif
    310312
     
    477479   if (((mask & PNG_FREE_TRNS) & info_ptr->free_me) != 0)
    478480   {
     481      info_ptr->valid &= ~PNG_INFO_tRNS;
    479482      png_free(png_ptr, info_ptr->trans_alpha);
    480483      info_ptr->trans_alpha = NULL;
    481       info_ptr->valid &= ~PNG_INFO_tRNS;
     484      info_ptr->num_trans = 0;
    482485   }
    483486#endif
     
    545548      else
    546549      {
    547          if (info_ptr->splt_palettes_num != 0)
     550         int i;
     551
     552         for (i = 0; i < info_ptr->splt_palettes_num; i++)
    548553         {
    549             int i;
    550 
    551             for (i = 0; i < info_ptr->splt_palettes_num; i++)
    552             {
    553                png_free(png_ptr, info_ptr->splt_palettes[i].name);
    554                png_free(png_ptr, info_ptr->splt_palettes[i].entries);
    555             }
    556 
    557             png_free(png_ptr, info_ptr->splt_palettes);
    558             info_ptr->splt_palettes = NULL;
    559             info_ptr->splt_palettes_num = 0;
     554            png_free(png_ptr, info_ptr->splt_palettes[i].name);
     555            png_free(png_ptr, info_ptr->splt_palettes[i].entries);
    560556         }
     557
     558         png_free(png_ptr, info_ptr->splt_palettes);
     559         info_ptr->splt_palettes = NULL;
     560         info_ptr->splt_palettes_num = 0;
    561561         info_ptr->valid &= ~PNG_INFO_sPLT;
    562562      }
     
    578578         int i;
    579579
    580          if (info_ptr->unknown_chunks_num != 0)
    581          {
    582             for (i = 0; i < info_ptr->unknown_chunks_num; i++)
    583                png_free(png_ptr, info_ptr->unknown_chunks[i].data);
    584 
    585             png_free(png_ptr, info_ptr->unknown_chunks);
    586             info_ptr->unknown_chunks = NULL;
    587             info_ptr->unknown_chunks_num = 0;
    588          }
     580         for (i = 0; i < info_ptr->unknown_chunks_num; i++)
     581            png_free(png_ptr, info_ptr->unknown_chunks[i].data);
     582
     583         png_free(png_ptr, info_ptr->unknown_chunks);
     584         info_ptr->unknown_chunks = NULL;
     585         info_ptr->unknown_chunks_num = 0;
    589586      }
    590587   }
     
    667664#  endif
    668665
    669 #ifdef PNG_SAVE_INT_32_SUPPORTED
     666#  ifdef PNG_SAVE_INT_32_SUPPORTED
    670667/* The png_save_int_32 function assumes integers are stored in two's
    671668 * complement format.  If this isn't the case, then this routine needs to
     
    682679   buf[3] = (png_byte)(i & 0xff);
    683680}
    684 #endif
     681#  endif
    685682
    686683#  ifdef PNG_TIME_RFC1123_SUPPORTED
     
    735732}
    736733
    737 #     if PNG_LIBPNG_VER < 10700
     734#    if PNG_LIBPNG_VER < 10700
    738735/* To do: remove the following from libpng-1.7 */
    739736/* Original API that uses a private buffer in png_struct.
     
    756753   return NULL;
    757754}
    758 #     endif
     755#    endif /* LIBPNG_VER < 10700 */
    759756#  endif /* TIME_RFC1123 */
    760757
     
    770767#  ifdef __STDC__
    771768   return PNG_STRING_NEWLINE \
    772      "libpng version 1.6.16 - December 22, 2014" PNG_STRING_NEWLINE \
    773      "Copyright (c) 1998-2014 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
    774      "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
    775      "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
    776      PNG_STRING_NEWLINE;
     769      "libpng version 1.6.18 - July 23, 2015" PNG_STRING_NEWLINE \
     770      "Copyright (c) 1998-2015 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
     771      "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
     772      "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
     773      PNG_STRING_NEWLINE;
    777774#  else
    778       return "libpng version 1.6.16 - December 22, 2014\
    779       Copyright (c) 1998-2014 Glenn Randers-Pehrson\
     775   return "libpng version 1.6.18 - July 23, 2015\
     776      Copyright (c) 1998-2015 Glenn Randers-Pehrson\
    780777      Copyright (c) 1996-1997 Andreas Dilger\
    781778      Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
     
    815812   return PNG_HEADER_VERSION_STRING
    816813#  ifndef PNG_READ_SUPPORTED
    817    "    (NO READ SUPPORT)"
     814      " (NO READ SUPPORT)"
    818815#  endif
    819    PNG_STRING_NEWLINE;
     816      PNG_STRING_NEWLINE;
    820817#else
    821818   return PNG_HEADER_VERSION_STRING;
     
    873870   for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
    874871   {
    875       palette[i].red = (png_byte)v;
    876       palette[i].green = (png_byte)v;
    877       palette[i].blue = (png_byte)v;
     872      palette[i].red = (png_byte)(v & 0xff);
     873      palette[i].green = (png_byte)(v & 0xff);
     874      palette[i].blue = (png_byte)(v & 0xff);
    878875   }
    879876}
     
    947944   return((png_uint_32)PNG_LIBPNG_VER);
    948945}
    949 
    950 
    951946
    952947#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
     
    10921087
    10931088#  ifdef PNG_READ_gAMA_SUPPORTED
    1094       /* Allow the application to set the gamma value more than once */
    1095       else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
    1096          (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0)
    1097          errmsg = "duplicate";
     1089   /* Allow the application to set the gamma value more than once */
     1090   else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
     1091      (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0)
     1092      errmsg = "duplicate";
    10981093#  endif
    10991094
     
    11361131
    11371132#     ifdef PNG_COLORSPACE_SUPPORTED
    1138          /* Clean up the iCCP profile now if it won't be used. */
    1139          png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/);
     1133      /* Clean up the iCCP profile now if it won't be used. */
     1134      png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/);
    11401135#     else
    1141          PNG_UNUSED(png_ptr)
     1136      PNG_UNUSED(png_ptr)
    11421137#     endif
    11431138   }
     
    11461141   {
    11471142#     ifdef PNG_COLORSPACE_SUPPORTED
    1148          /* Leave the INFO_iCCP flag set if the pngset.c code has already set
    1149           * it; this allows a PNG to contain a profile which matches sRGB and
    1150           * yet still have that profile retrievable by the application.
    1151           */
    1152          if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0)
    1153             info_ptr->valid |= PNG_INFO_sRGB;
    1154 
    1155          else
    1156             info_ptr->valid &= ~PNG_INFO_sRGB;
    1157 
    1158          if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
    1159             info_ptr->valid |= PNG_INFO_cHRM;
    1160 
    1161          else
    1162             info_ptr->valid &= ~PNG_INFO_cHRM;
     1143      /* Leave the INFO_iCCP flag set if the pngset.c code has already set
     1144       * it; this allows a PNG to contain a profile which matches sRGB and
     1145       * yet still have that profile retrievable by the application.
     1146       */
     1147      if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0)
     1148         info_ptr->valid |= PNG_INFO_sRGB;
     1149
     1150      else
     1151         info_ptr->valid &= ~PNG_INFO_sRGB;
     1152
     1153      if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
     1154         info_ptr->valid |= PNG_INFO_cHRM;
     1155
     1156      else
     1157         info_ptr->valid &= ~PNG_INFO_cHRM;
    11631158#     endif
    11641159
     
    11821177}
    11831178#endif
    1184 #endif
     1179#endif /* GAMMA */
    11851180
    11861181#ifdef PNG_COLORSPACE_SUPPORTED
     
    12411236   /* Check xy and, implicitly, z.  Note that wide gamut color spaces typically
    12421237    * have end points with 0 tristimulus values (these are impossible end
    1243     * points, but they are used to cover the possible colors.)
    1244     */
    1245    if (xy->redx < 0 || xy->redx > PNG_FP_1) return 1;
    1246    if (xy->redy < 0 || xy->redy > PNG_FP_1-xy->redx) return 1;
     1238    * points, but they are used to cover the possible colors).  We check
     1239    * xy->whitey against 5, not 0, to avoid a possible integer overflow.
     1240    */
     1241   if (xy->redx   < 0 || xy->redx > PNG_FP_1) return 1;
     1242   if (xy->redy   < 0 || xy->redy > PNG_FP_1-xy->redx) return 1;
    12471243   if (xy->greenx < 0 || xy->greenx > PNG_FP_1) return 1;
    12481244   if (xy->greeny < 0 || xy->greeny > PNG_FP_1-xy->greenx) return 1;
    1249    if (xy->bluex < 0 || xy->bluex > PNG_FP_1) return 1;
    1250    if (xy->bluey < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1;
     1245   if (xy->bluex  < 0 || xy->bluex > PNG_FP_1) return 1;
     1246   if (xy->bluey  < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1;
    12511247   if (xy->whitex < 0 || xy->whitex > PNG_FP_1) return 1;
    1252    if (xy->whitey < 0 || xy->whitey > PNG_FP_1-xy->whitex) return 1;
     1248   if (xy->whitey < 5 || xy->whitey > PNG_FP_1-xy->whitex) return 1;
    12531249
    12541250   /* The reverse calculation is more difficult because the original tristimulus
     
    21672163}
    21682164
    2169 #if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
     2165#ifdef PNG_sRGB_SUPPORTED
     2166#if PNG_sRGB_PROFILE_CHECKS >= 0
    21702167/* Information about the known ICC sRGB profiles */
    21712168static const struct
     
    22812278         /* Length *and* intent must match */
    22822279         if (length == png_sRGB_checks[i].length &&
    2283             intent == png_sRGB_checks[i].intent)
     2280            intent == (png_uint_32) png_sRGB_checks[i].intent)
    22842281         {
    22852282            /* Now calculate the adler32 if not done already. */
     
    23252322                  else if (png_sRGB_checks[i].have_md5 == 0)
    23262323                  {
    2327                      png_chunk_report(png_ptr, "out-of-date sRGB profile with"
    2328                         " no signature",
     2324                     png_chunk_report(png_ptr,
     2325                        "out-of-date sRGB profile with no signature",
    23292326                        PNG_CHUNK_WARNING);
    23302327                  }
     
    23392336          * Fall through to "no match".
    23402337          */
    2341          png_chunk_report(png_ptr, "Not recognizing known sRGB profile that"
    2342              " has been edited",
     2338         png_chunk_report(png_ptr,
     2339             "Not recognizing known sRGB profile that has been edited",
    23432340             PNG_CHUNK_WARNING);
    23442341         break;
     
    23502347   return 0; /* no match */
    23512348}
    2352 #endif
    2353 
    2354 #ifdef PNG_sRGB_SUPPORTED
     2349#endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */
     2350
    23552351void /* PRIVATE */
    23562352png_icc_set_sRGB(png_const_structrp png_ptr,
     
    23662362         (int)/*already checked*/png_get_uint_32(profile+64));
    23672363}
    2368 #endif /* READ_sRGB */
     2364#endif /* sRGB */
    23692365
    23702366int /* PRIVATE */
     
    24582454   }
    24592455}
    2460 #endif
     2456#endif /* READ_RGB_TO_GRAY */
    24612457
    24622458#endif /* COLORSPACE */
     
    24872483      error = 1;
    24882484   }
    2489    else if (width > PNG_UINT_31_MAX)
     2485
     2486   if (width > PNG_UINT_31_MAX)
    24902487   {
    24912488      png_warning(png_ptr, "Invalid image width in IHDR");
     
    24932490   }
    24942491
    2495    else if (png_gt(width,
    2496                    (PNG_SIZE_MAX >> 3) /* 8-byte RGBA pixels */
    2497                    - 48                /* big_row_buf hack */
    2498                    - 1                 /* filter byte */
    2499                    - 7*8               /* rounding width to multiple of 8 pix */
    2500                    - 8))               /* extra max_pixel_depth pad */
     2492   if (png_gt(((width + 7) & (~7)),
     2493       ((PNG_SIZE_MAX
     2494           - 48        /* big_row_buf hack */
     2495           - 1)        /* filter byte */
     2496           / 8)        /* 8-byte RGBA pixels */
     2497           - 1))       /* extra max_pixel_depth pad */
    25012498   {
    25022499      /* The size of the row must be within the limits of this architecture.
     
    25142511      error = 1;
    25152512   }
    2516    else
    2517    {
    2518 #     ifdef PNG_SET_USER_LIMITS_SUPPORTED
    2519       if (width > png_ptr->user_width_max)
    2520 #     else
    2521       if (width > PNG_USER_WIDTH_MAX)
    2522 #     endif
    2523       {
    2524          png_warning(png_ptr, "Image width exceeds user limit in IHDR");
    2525          error = 1;
    2526       }
     2513
     2514#ifdef PNG_SET_USER_LIMITS_SUPPORTED
     2515   if (width > png_ptr->user_width_max)
     2516#else
     2517   if (width > PNG_USER_WIDTH_MAX)
     2518#endif
     2519   {
     2520      png_warning(png_ptr, "Image width exceeds user limit in IHDR");
     2521      error = 1;
    25272522   }
    25282523
     
    25322527      error = 1;
    25332528   }
    2534    else if (height > PNG_UINT_31_MAX)
     2529
     2530   if (height > PNG_UINT_31_MAX)
    25352531   {
    25362532      png_warning(png_ptr, "Invalid image height in IHDR");
    25372533      error = 1;
    25382534   }
    2539    else
    2540    {
    2541 #     ifdef PNG_SET_USER_LIMITS_SUPPORTED
    2542       if (height > png_ptr->user_height_max)
    2543 #     else
    2544       if (height > PNG_USER_HEIGHT_MAX)
    2545 #     endif
    2546       {
    2547          png_warning(png_ptr, "Image height exceeds user limit in IHDR");
    2548          error = 1;
    2549       }
     2535
     2536#ifdef PNG_SET_USER_LIMITS_SUPPORTED
     2537   if (height > png_ptr->user_height_max)
     2538#else
     2539   if (height > PNG_USER_HEIGHT_MAX)
     2540#endif
     2541   {
     2542      png_warning(png_ptr, "Image height exceeds user limit in IHDR");
     2543      error = 1;
    25502544   }
    25512545
     
    25862580   }
    25872581
    2588 #  ifdef PNG_MNG_FEATURES_SUPPORTED
     2582#ifdef PNG_MNG_FEATURES_SUPPORTED
    25892583   /* Accept filter_method 64 (intrapixel differencing) only if
    25902584    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
     
    26192613   }
    26202614
    2621 #  else
     2615#else
    26222616   if (filter_type != PNG_FILTER_TYPE_BASE)
    26232617   {
     
    26252619      error = 1;
    26262620   }
    2627 #  endif
     2621#endif
    26282622
    26292623   if (error == 1)
     
    28512845      if (fp >= DBL_MIN && fp <= DBL_MAX)
    28522846      {
    2853          int exp_b10;       /* A base 10 exponent */
     2847         int exp_b10;   /* A base 10 exponent */
    28542848         double base;   /* 10^exp_b10 */
    28552849
     
    28992893
    29002894         {
    2901             int czero, clead, cdigits;
     2895            unsigned int czero, clead, cdigits;
    29022896            char exponent[10];
    29032897
     
    29292923                * that the final digit is rounded.
    29302924                */
    2931                if (cdigits+czero-clead+1 < (int)precision)
     2925               if (cdigits+czero+1 < precision+clead)
    29322926                  fp = modf(fp, &d);
    29332927
     
    30353029               }
    30363030            }
    3037             while (cdigits+czero-clead < (int)precision && fp > DBL_MIN);
     3031            while (cdigits+czero < precision+clead && fp > DBL_MIN);
    30383032
    30393033            /* The total output count (max) is now 4+precision */
     
    30423036             * done and just need to terminate the string.  At
    30433037             * this point exp_b10==(-1) is effectively if flag - it got
    3044              * to '-1' because of the decrement after outputing
     3038             * to '-1' because of the decrement after outputting
    30453039             * the decimal point above (the exponent required is
    30463040             * *not* -1!)
     
    30503044               /* The following only happens if we didn't output the
    30513045                * leading zeros above for negative exponent, so this
    3052                 * doest add to the digit requirement.  Note that the
     3046                * doesn't add to the digit requirement.  Note that the
    30533047                * two zeros here can only be output if the two leading
    30543048                * zeros were *not* output, so this doesn't increase
     
    31033097             * this need not be considered above.
    31043098             */
    3105             if ((int)size > cdigits)
     3099            if (size > cdigits)
    31063100            {
    31073101               while (cdigits > 0) *ascii++ = exponent[--cdigits];
     
    32073201}
    32083202#   endif /* FIXED_POINT */
    3209 #endif /* READ_SCAL */
     3203#endif /* SCAL */
    32103204
    32113205#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
     
    32253219
    32263220#  ifndef PNG_ERROR_TEXT_SUPPORTED
    3227       PNG_UNUSED(text)
     3221   PNG_UNUSED(text)
    32283222#  endif
    32293223
     
    34063400
    34073401#ifdef PNG_READ_GAMMA_SUPPORTED
    3408 #if defined(PNG_16BIT_SUPPORTED) || !defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
     3402#ifdef PNG_16BIT_SUPPORTED
    34093403/* A local convenience routine. */
    34103404static png_fixed_point
     
    34123406{
    34133407   /* The required result is 1/a * 1/b; the following preserves accuracy. */
    3414 #    ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
     3408#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
    34153409   double r = a * 1E-5;
    34163410   r *= b;
     
    34193413   if (r <= 2147483647. && r >= -2147483648.)
    34203414      return (png_fixed_point)r;
    3421 #    else
     3415#else
    34223416   png_fixed_point res;
    34233417
    34243418   if (png_muldiv(&res, a, b, 100000) != 0)
    34253419      return res;
    3426 #    endif
     3420#endif
    34273421
    34283422   return 0; /* overflow */
    34293423}
    3430 #endif /* 16BIT || !FLOATING_ARITHMETIC */
     3424#endif /* 16BIT */
    34313425
    34323426/* The inverse of the above. */
     
    34363430   /* The required result is 1/a * 1/b; the following preserves accuracy. */
    34373431#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
    3438    double r = 1E15/a;
    3439    r /= b;
    3440    r = floor(r+.5);
    3441 
    3442    if (r <= 2147483647. && r >= -2147483648.)
    3443       return (png_fixed_point)r;
     3432   if (a != 0 && b != 0)
     3433   {
     3434      double r = 1E15/a;
     3435      r /= b;
     3436      r = floor(r+.5);
     3437
     3438      if (r <= 2147483647. && r >= -2147483648.)
     3439         return (png_fixed_point)r;
     3440   }
    34443441#else
    34453442   /* This may overflow because the range of png_fixed_point isn't symmetric,
     
    37323729    */
    37333730   x -= x >> 8;
    3734    return (png_byte)((x + 0x7fffffU) >> 24);
     3731   return (png_byte)(((x + 0x7fffffU) >> 24) & 0xff);
    37353732}
    37363733
     
    37933790   }
    37943791
    3795    return (png_byte)value;
     3792   return (png_byte)(value & 0xff);
    37963793}
    37973794
     
    40154012   else
    40164013      for (i=0; i<256; ++i)
    4017          table[i] = (png_byte)i;
     4014         table[i] = (png_byte)(i & 0xff);
    40184015}
    40194016
     
    41554152      */
    41564153     if (sig_bit > 0 && sig_bit < 16U)
    4157         shift = (png_byte)(16U - sig_bit); /* shift == insignificant bits */
     4154        /* shift == insignificant bits */
     4155        shift = (png_byte)((16U - sig_bit) & 0xff);
    41584156
    41594157     else
     
    42244222      int current = png_ptr->options;
    42254223
    4226       png_ptr->options = (png_byte)((current & ~mask) | setting);
     4224      png_ptr->options = (png_byte)(((current & ~mask) | setting) & 0xff);
    42274225
    42284226      return (current & mask) >> option;
     
    42404238 * specification (see the article at http://en.wikipedia.org/wiki/SRGB)
    42414239 * is used, not the gamma=1/2.2 approximation use elsewhere in libpng.
    4242  * The sRGB to linear table is exact (to the nearest 16 bit linear fraction).
     4240 * The sRGB to linear table is exact (to the nearest 16-bit linear fraction).
    42434241 * The inverse (linear to sRGB) table has accuracies as follows:
    42444242 *
  • TabularUnified libpng/vendor/current/png.h

    r1059 r1165  
    22/* png.h - header file for PNG reference library
    33 *
    4  * libpng version 1.6.16, December 22, 2014
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * libpng version 1.6.18, July 23, 2015
     5 *
     6 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    67 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    78 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    1112 * Authors and maintainers:
    1213 *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
    13  *   libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
    14  *   libpng versions 0.97, January 1998, through 1.6.16, December 22, 2014: Glenn
     14 *   libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
     15 *   libpng versions 0.97, January 1998, through 1.6.18, July 23, 2015: Glenn
    1516 *   See also "Contributing Authors", below.
    1617 *
     
    213214 *    1.6.16rc01-02           16    10616  16.so.16.16[.0]
    214215 *    1.6.16                  16    10616  16.so.16.16[.0]
     216 *    1.6.17beta01-06         16    10617  16.so.16.17[.0]
     217 *    1.6.17rc01-06           16    10617  16.so.16.17[.0]
     218 *    1.6.17                  16    10617  16.so.16.17[.0]
     219 *    1.6.18beta01-09         16    10618  16.so.16.18[.0]
     220 *    1.6.18rc01-03           16    10618  16.so.16.18[.0]
     221 *    1.6.18                  16    10618  16.so.16.18[.0]
    215222 *
    216223 *   Henceforth the source version will match the shared-library major
     
    244251 * This code is released under the libpng license.
    245252 *
    246  * libpng versions 1.2.6, August 15, 2004, through 1.6.16, December 22, 2014, are
    247  * Copyright (c) 2004, 2006-2014 Glenn Randers-Pehrson, and are
    248  * distributed according to the same disclaimer and license as libpng-1.2.5
    249  * with the following individual added to the list of Contributing Authors:
    250  *
    251  *    Cosmin Truta
    252  *
    253  * libpng versions 1.0.7, July 1, 2000, through 1.2.5, October 3, 2002, are
    254  * Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
     253 * libpng versions 1.0.7, July 1, 2000, through 1.6.18, July 23, 2015, are
     254 * Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, and are
    255255 * distributed according to the same disclaimer and license as libpng-1.0.6
    256256 * with the following individuals added to the list of Contributing Authors:
    257257 *
    258258 *    Simon-Pierre Cadieux
    259  *    Eric S. Raymond
     259 *    Mans Rullgard
     260 *    Cosmin Truta
    260261 *    Gilles Vollant
     262 *    James Yu
    261263 *
    262264 * and with the following additions to the disclaimer:
     
    270272 *
    271273 * libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
    272  * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson, and are
    273  * distributed according to the same disclaimer and license as libpng-0.96,
    274  * with the following individuals added to the list of Contributing Authors:
     274 * Copyright (c) 1998-2000 Glenn Randers-Pehrson, and are distributed according
     275 * to the same disclaimer and license as libpng-0.96, with the following
     276 * individuals added to the list of Contributing Authors:
    275277 *
    276278 *    Tom Lane
    277279 *    Glenn Randers-Pehrson
     280 *    Eric S. Raymond
    278281 *    Willem van Schaik
    279282 *
    280283 * libpng versions 0.89, June 1996, through 0.96, May 1997, are
    281  * Copyright (c) 1996, 1997 Andreas Dilger
    282  * Distributed according to the same disclaimer and license as libpng-0.88,
     284 * Copyright (c) 1996-1997 Andreas Dilger, and are
     285 * distributed according to the same disclaimer and license as libpng-0.88,
    283286 * with the following individuals added to the list of Contributing Authors:
    284287 *
     
    291294 *
    292295 * libpng versions 0.5, May 1995, through 0.88, January 1996, are
    293  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
     296 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
    294297 *
    295298 * For the purposes of this copyright and license, "Contributing Authors"
     
    319322 *      be misrepresented as being the original source.
    320323 *
    321  *   3. This Copyright notice may not be removed or altered from
    322  *      any source or altered source distribution.
     324 *   3. This Copyright notice may not be removed or altered from any
     325 *      source or altered source distribution.
    323326 *
    324327 * The Contributing Authors and Group 42, Inc. specifically permit, without
     
    333336 * boxes and the like:
    334337 *
    335  *     printf("%s", png_get_copyright(NULL));
     338 *    printf("%s", png_get_copyright(NULL));
    336339 *
    337340 * Also, the PNG logo (in PNG format, of course) is supplied in the
     
    340343
    341344/*
    342  * Libpng is OSI Certified Open Source Software.  OSI Certified is a
    343  * certification mark of the Open Source Initiative.
     345 * Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is
     346 * a certification mark of the Open Source Initiative. OSI has not addressed
     347 * the additional disclaimers inserted at version 1.0.7.
    344348 */
    345349
     
    356360 * =========================
    357361 *
    358  *    December 22, 2014
     362 *    July 23, 2015
    359363 *
    360364 *    Since the PNG Development group is an ad-hoc body, we can't make
     
    362366 *
    363367 *    This is your unofficial assurance that libpng from version 0.71 and
    364  *    upward through 1.6.16 are Y2K compliant.  It is my belief that
     368 *    upward through 1.6.18 are Y2K compliant.  It is my belief that
    365369 *    earlier versions were also Y2K compliant.
    366370 *
     
    424428
    425429/* Version information for png.h - this should match the version in png.c */
    426 #define PNG_LIBPNG_VER_STRING "1.6.16"
     430#define PNG_LIBPNG_VER_STRING "1.6.18"
    427431#define PNG_HEADER_VERSION_STRING \
    428      " libpng version 1.6.16 - December 22, 2014\n"
     432     " libpng version 1.6.18 - July 23, 2015\n"
    429433
    430434#define PNG_LIBPNG_VER_SONUM   16
     
    434438#define PNG_LIBPNG_VER_MAJOR   1
    435439#define PNG_LIBPNG_VER_MINOR   6
    436 #define PNG_LIBPNG_VER_RELEASE 16
     440#define PNG_LIBPNG_VER_RELEASE 18
    437441
    438442/* This should match the numeric part of the final component of
     
    465469 * version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=release
    466470 */
    467 #define PNG_LIBPNG_VER 10616 /* 1.6.16 */
     471#define PNG_LIBPNG_VER 10618 /* 1.6.18 */
    468472
    469473/* Library configuration: these options cannot be changed after
     
    570574 * do not agree upon the version number.
    571575 */
    572 typedef char* png_libpng_version_1_6_16;
     576typedef char* png_libpng_version_1_6_18;
    573577
    574578/* Basic control structions.  Read libpng-manual.txt or libpng.3 for more info.
     
    15791583#define PNG_CRC_NO_CHANGE     5  /* use current value   use current value */
    15801584
     1585#ifdef PNG_WRITE_SUPPORTED
    15811586/* These functions give the user control over the scan-line filtering in
    15821587 * libpng and the compression methods used by zlib.  These functions are
     
    15921597PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method,
    15931598    int filters));
     1599#endif /* WRITE */
    15941600
    15951601/* Flags for png_set_filter() to say which filters to use.  The flags
     
    16171623#define PNG_FILTER_VALUE_LAST  5
    16181624
    1619 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */
    1620 /* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
    1621  * defines, either the default (minimum-sum-of-absolute-differences), or
    1622  * the experimental method (weighted-minimum-sum-of-absolute-differences).
    1623  *
    1624  * Weights are factors >= 1.0, indicating how important it is to keep the
    1625  * filter type consistent between rows.  Larger numbers mean the current
    1626  * filter is that many times as likely to be the same as the "num_weights"
    1627  * previous filters.  This is cumulative for each previous row with a weight.
    1628  * There needs to be "num_weights" values in "filter_weights", or it can be
    1629  * NULL if the weights aren't being specified.  Weights have no influence on
    1630  * the selection of the first row filter.  Well chosen weights can (in theory)
    1631  * improve the compression for a given image.
    1632  *
    1633  * Costs are factors >= 1.0 indicating the relative decoding costs of a
    1634  * filter type.  Higher costs indicate more decoding expense, and are
    1635  * therefore less likely to be selected over a filter with lower computational
    1636  * costs.  There needs to be a value in "filter_costs" for each valid filter
    1637  * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't
    1638  * setting the costs.  Costs try to improve the speed of decompression without
    1639  * unduly increasing the compressed image size.
    1640  *
    1641  * A negative weight or cost indicates the default value is to be used, and
    1642  * values in the range [0.0, 1.0) indicate the value is to remain unchanged.
    1643  * The default values for both weights and costs are currently 1.0, but may
    1644  * change if good general weighting/cost heuristics can be found.  If both
    1645  * the weights and costs are set to 1.0, this degenerates the WEIGHTED method
    1646  * to the UNWEIGHTED method, but with added encoding time/computation.
    1647  */
     1625#ifdef PNG_WRITE_SUPPORTED
     1626#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */
    16481627PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structrp png_ptr,
    16491628    int heuristic_method, int num_weights, png_const_doublep filter_weights,
     
    16551634#endif /* WRITE_WEIGHTED_FILTER */
    16561635
    1657 /* Heuristic used for row filter selection.  These defines should NOT be
    1658  * changed.
    1659  */
     1636/* The following are no longer used and will be removed from libpng-1.7: */
    16601637#define PNG_FILTER_HEURISTIC_DEFAULT    0  /* Currently "UNWEIGHTED" */
    16611638#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1  /* Used by libpng < 0.95 */
     
    16631640#define PNG_FILTER_HEURISTIC_LAST       3  /* Not a valid value */
    16641641
    1665 #ifdef PNG_WRITE_SUPPORTED
    16661642/* Set the library compression level.  Currently, valid values range from
    16671643 * 0 - 9, corresponding directly to the zlib compression levels 0 - 9
     
    16711647 * these values may not correspond directly to the zlib compression levels.
    16721648 */
     1649#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
    16731650PNG_EXPORT(69, void, png_set_compression_level, (png_structrp png_ptr,
    16741651    int level));
     
    16881665PNG_EXPORT(73, void, png_set_compression_method, (png_structrp png_ptr,
    16891666    int method));
    1690 #endif
     1667#endif /* WRITE_CUSTOMIZE_COMPRESSION */
    16911668
    16921669#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
     
    17101687    int method));
    17111688#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */
     1689#endif /* WRITE */
    17121690
    17131691/* These next functions are called for input/output, memory, and error
     
    18201798 * The integer return from the callback function is interpreted thus:
    18211799 *
    1822  * negative: An error occured, png_chunk_error will be called.
     1800 * negative: An error occurred; png_chunk_error will be called.
    18231801 *     zero: The chunk was not handled, the chunk will be saved. A critical
    18241802 *           chunk will cause an error at this point unless it is to be saved.
     
    26652643           + (png_uint_16)(bg)*(png_uint_16)(255          \
    26662644           - (png_uint_16)(alpha)) + 128);                \
    2667        (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
     2645       (composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); }
    26682646
    26692647#  define png_composite_16(composite, fg, alpha, bg)       \
     
    26722650           + (png_uint_32)(bg)*(65535                      \
    26732651           - (png_uint_32)(alpha)) + 32768);               \
    2674        (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
     2652       (composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); }
    26752653
    26762654#else  /* Standard method using integer division */
    26772655
    2678 #  define png_composite(composite, fg, alpha, bg)                          \
    2679      (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) +  \
    2680      (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) +       \
    2681      127) / 255)
     2656#  define png_composite(composite, fg, alpha, bg)                        \
     2657     (composite) =                                                       \
     2658         (png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) +  \
     2659         (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
     2660         127) / 255))
    26822661
    26832662#  define png_composite_16(composite, fg, alpha, bg)                         \
    2684      (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
    2685      (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) +         \
    2686      32767) / 65535)
     2663     (composite) =                                                           \
     2664         (png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \
     2665         (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) +     \
     2666         32767) / 65535))
    26872667#endif /* READ_COMPOSITE_NODIV */
    26882668
     
    27742754 * To read a PNG file using the simplified API:
    27752755 *
    2776  * 1) Declare a 'png_image' structure (see below) on the stack and set the
    2777  *    version field to PNG_IMAGE_VERSION.
     2756 * 1) Declare a 'png_image' structure (see below) on the stack, set the
     2757 *    version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL
     2758 *    (this is REQUIRED, your program may crash if you don't do it.)
    27782759 * 2) Call the appropriate png_image_begin_read... function.
    27792760 * 3) Set the png_image 'format' member to the required sample format.
     
    32003181 * With all APIs row_stride is handled as in the read APIs - it is the spacing
    32013182 * from one row to the next in component sized units (1 or 2 bytes) and if
    3202  * negative indicates a bottom-up row layout in the buffer.
    3203  *
    3204  * Note that the write API does not support interlacing or sub-8-bit pixels.
     3183 * negative indicates a bottom-up row layout in the buffer.  If row_stride is zero,
     3184 * libpng will calculate it for you from the image width and number of channels.
     3185 *
     3186 * Note that the write API does not support interlacing, sub-8-bit pixels, indexed
     3187 * PNG (color_type 3) or most ancillary chunks.
    32053188 */
    32063189#endif /* STDIO */
  • TabularUnified libpng/vendor/current/pngconf.h

    r1059 r1165  
    22/* pngconf.h - machine configurable file for libpng
    33 *
    4  * libpng version 1.6.16,December 22, 2014
    5  *
    6  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * libpng version 1.6.18, July 23, 2015
     5 *
     6 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    77 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    88 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    1212 * and license in png.h
    1313 *
    14  */
    15 
    16 /* Any machine specific code is near the front of this file, so if you
     14 * Any machine specific code is near the front of this file, so if you
    1715 * are configuring libpng for a machine, you may want to read the section
    1816 * starting here down to where it starts to typedef png_color, png_text,
     
    2220#ifndef PNGCONF_H
    2321#define PNGCONF_H
    24 
    25 /* To do: Do all of this in scripts/pnglibconf.dfa */
    26 #ifdef PNG_SAFE_LIMITS_SUPPORTED
    27 #  ifdef PNG_USER_WIDTH_MAX
    28 #    undef PNG_USER_WIDTH_MAX
    29 #    define PNG_USER_WIDTH_MAX 1000000L
    30 #  endif
    31 #  ifdef PNG_USER_HEIGHT_MAX
    32 #    undef PNG_USER_HEIGHT_MAX
    33 #    define PNG_USER_HEIGHT_MAX 1000000L
    34 #  endif
    35 #  ifdef PNG_USER_CHUNK_MALLOC_MAX
    36 #    undef PNG_USER_CHUNK_MALLOC_MAX
    37 #    define PNG_USER_CHUNK_MALLOC_MAX 4000000L
    38 #  endif
    39 #  ifdef PNG_USER_CHUNK_CACHE_MAX
    40 #    undef PNG_USER_CHUNK_CACHE_MAX
    41 #    define PNG_USER_CHUNK_CACHE_MAX 128
    42 #  endif
    43 #endif
    4422
    4523#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */
     
    318296    * scripts directory.
    319297    */
     298
    320299#ifndef PNG_EXPORTA
    321 
    322 #  define PNG_EXPORTA(ordinal, type, name, args, attributes)\
    323       PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \
    324         extern attributes)
     300#  define PNG_EXPORTA(ordinal, type, name, args, attributes) \
     301      PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \
     302      PNG_LINKAGE_API attributes)
    325303#endif
    326304
     
    330308#define PNG_EMPTY /*empty list*/
    331309
    332 #define PNG_EXPORT(ordinal, type, name, args)\
     310#define PNG_EXPORT(ordinal, type, name, args) \
    333311   PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
    334312
  • TabularUnified libpng/vendor/current/pngdebug.h

    r922 r1165  
    22/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
    33 *
     4 * Last changed in libpng 1.6.8 [December 19, 2013]
    45 * Copyright (c) 1998-2013 Glenn Randers-Pehrson
    56 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    67 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    7  *
    8  * Last changed in libpng 1.6.8 [December 19, 2013]
    98 *
    109 * This code is released under the libpng license.
  • TabularUnified libpng/vendor/current/pngget.c

    r1059 r1165  
    22/* pngget.c - retrieval of values from info struct
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.17 [March 26, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    800800   png_debug1(1, "in %s retrieval function", "IHDR");
    801801
    802    if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
    803        height == NULL || bit_depth == NULL || color_type == NULL)
     802   if (png_ptr == NULL || info_ptr == NULL)
    804803      return (0);
    805804
    806    *width = info_ptr->width;
    807    *height = info_ptr->height;
    808    *bit_depth = info_ptr->bit_depth;
    809    *color_type = info_ptr->color_type;
     805   if (width != NULL)
     806       *width = info_ptr->width;
     807
     808   if (height != NULL)
     809       *height = info_ptr->height;
     810
     811   if (bit_depth != NULL)
     812       *bit_depth = info_ptr->bit_depth;
     813
     814   if (color_type != NULL)
     815       *color_type = info_ptr->color_type;
    810816
    811817   if (compression_type != NULL)
     
    11361142      return 0;
    11371143
    1138 #  ifdef PNG_WRITE_SUPPORTED
     1144#ifdef PNG_WRITE_SUPPORTED
    11391145      if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
    1140 #  endif
    1141    {
    1142 #     ifdef PNG_SEQUENTIAL_READ_SUPPORTED
     1146#endif
     1147   {
     1148#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
    11431149         return png_ptr->IDAT_read_size;
    1144 #     else
     1150#else
    11451151         return PNG_IDAT_READ_SIZE;
    1146 #     endif
    1147    }
    1148 
    1149 #  ifdef PNG_WRITE_SUPPORTED
     1152#endif
     1153   }
     1154
     1155#ifdef PNG_WRITE_SUPPORTED
    11501156      else
    11511157         return png_ptr->zbuffer_size;
    1152 #  endif
     1158#endif
    11531159}
    11541160
  • TabularUnified libpng/vendor/current/pnginfo.h

    r1059 r1165  
    22/* pnginfo.h - header file for PNG reference library
    33 *
     4 * Last changed in libpng 1.6.1 [March 28, 2013]
    45 * Copyright (c) 1998-2013 Glenn Randers-Pehrson
    56 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    67 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    7  *
    8  * Last changed in libpng 1.6.1 [March 28, 2013]
    98 *
    109 * This code is released under the libpng license.
  • TabularUnified libpng/vendor/current/pngmem.c

    r1059 r1165  
    4242
    4343/* Allocate memory.  For reasonable files, size should never exceed
    44  * 64K.  However, zlib may allocate more then 64K if you don't tell
     44 * 64K.  However, zlib may allocate more than 64K if you don't tell
    4545 * it not to.  See zconf.h and png.h for more information.  zlib does
    4646 * need to allocate exactly 64K, so whatever you call here must
     
    7878#endif
    7979
     80   /* Some compilers complain that this is always true.  However, it
     81    * can be false when integer overflow happens.
     82    */
    8083   if (size > 0 && size <= PNG_SIZE_MAX
    8184#     ifdef PNG_MAX_MALLOC_64K
  • TabularUnified libpng/vendor/current/pngpread.c

    r1059 r1165  
    22/* pngpread.c - read a png file in push mode
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    2020#define PNG_READ_CHUNK_MODE 1
    2121#define PNG_READ_IDAT_MODE  2
    22 #define PNG_SKIP_MODE       3
    2322#define PNG_READ_tEXt_MODE  4
    2423#define PNG_READ_zTXt_MODE  5
     
    7978png_process_data_skip(png_structrp png_ptr)
    8079{
    81    png_uint_32 remaining = 0;
    82 
    83    if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE &&
    84       png_ptr->skip_length > 0)
    85    {
    86       /* At the end of png_process_data the buffer size must be 0 (see the loop
    87        * above) so we can detect a broken call here:
    88        */
    89       if (png_ptr->buffer_size != 0)
    90          png_error(png_ptr,
    91             "png_process_data_skip called inside png_process_data");
    92 
    93       /* If is impossible for there to be a saved buffer at this point -
    94        * otherwise we could not be in SKIP mode.  This will also happen if
    95        * png_process_skip is called inside png_process_data (but only very
    96        * rarely.)
    97        */
    98       if (png_ptr->save_buffer_size != 0)
    99          png_error(png_ptr, "png_process_data_skip called with saved data");
    100 
    101       remaining = png_ptr->skip_length;
    102       png_ptr->skip_length = 0;
    103       png_ptr->process_mode = PNG_READ_CHUNK_MODE;
    104    }
    105 
    106    return remaining;
     80  /* TODO: Deprecate and remove this API.
     81   * Somewhere the implementation of this seems to have been lost,
     82   * or abandoned.  It was only to support some internal back-door access
     83   * to png_struct) in libpng-1.4.x.
     84   */
     85   png_app_warning(png_ptr,
     86"png_process_data_skip is not implemented in any current version of libpng");
     87   return 0;
    10788}
    10889
     
    133114      {
    134115         png_push_read_IDAT(png_ptr);
    135          break;
    136       }
    137 
    138       case PNG_SKIP_MODE:
    139       {
    140          png_push_crc_finish(png_ptr);
    141116         break;
    142117      }
     
    160135{
    161136   png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */
    162              num_to_check = 8 - num_checked;
     137       num_to_check = 8 - num_checked;
    163138
    164139   if (png_ptr->buffer_size < num_to_check)
     
    440415}
    441416
    442 void /* PRIVATE */
    443 png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip)
    444 {
    445    png_ptr->process_mode = PNG_SKIP_MODE;
    446    png_ptr->skip_length = skip;
    447 }
    448 
    449 void /* PRIVATE */
    450 png_push_crc_finish(png_structrp png_ptr)
    451 {
    452    if (png_ptr->skip_length != 0 && png_ptr->save_buffer_size != 0)
    453    {
    454       png_size_t save_size = png_ptr->save_buffer_size;
    455       png_uint_32 skip_length = png_ptr->skip_length;
    456 
    457       /* We want the smaller of 'skip_length' and 'save_buffer_size', but
    458        * they are of different types and we don't know which variable has the
    459        * fewest bits.  Carefully select the smaller and cast it to the type of
    460        * the larger - this cannot overflow.  Do not cast in the following test
    461        * - it will break on either 16 or 64 bit platforms.
    462        */
    463       if (skip_length < save_size)
    464          save_size = (png_size_t)skip_length;
    465 
    466       else
    467          skip_length = (png_uint_32)save_size;
    468 
    469       png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
    470 
    471       png_ptr->skip_length -= skip_length;
    472       png_ptr->buffer_size -= save_size;
    473       png_ptr->save_buffer_size -= save_size;
    474       png_ptr->save_buffer_ptr += save_size;
    475    }
    476    if (png_ptr->skip_length != 0 && png_ptr->current_buffer_size != 0)
    477    {
    478       png_size_t save_size = png_ptr->current_buffer_size;
    479       png_uint_32 skip_length = png_ptr->skip_length;
    480 
    481       /* We want the smaller of 'skip_length' and 'current_buffer_size', here,
    482        * the same problem exists as above and the same solution.
    483        */
    484       if (skip_length < save_size)
    485          save_size = (png_size_t)skip_length;
    486 
    487       else
    488          skip_length = (png_uint_32)save_size;
    489 
    490       png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
    491 
    492       png_ptr->skip_length -= skip_length;
    493       png_ptr->buffer_size -= save_size;
    494       png_ptr->current_buffer_size -= save_size;
    495       png_ptr->current_buffer_ptr += save_size;
    496    }
    497    if (png_ptr->skip_length == 0)
    498    {
    499       PNG_PUSH_SAVE_BUFFER_IF_LT(4)
    500       png_crc_finish(png_ptr, 0);
    501       png_ptr->process_mode = PNG_READ_CHUNK_MODE;
    502    }
    503 }
    504 
    505417void PNGCBAPI
    506418png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
     
    585497      {
    586498         png_free(png_ptr, old_buffer);
    587          old_buffer = NULL;
    588499         png_error(png_ptr, "Insufficient memory for save_buffer");
    589500      }
     
    591502      memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
    592503      png_free(png_ptr, old_buffer);
    593       old_buffer = NULL;
    594504      png_ptr->save_buffer_max = new_max;
    595505   }
     
    697607      png_ptr->current_buffer_ptr += save_size;
    698608   }
     609
    699610   if (png_ptr->idat_size == 0)
    700611   {
     
    727638    */
    728639   while (png_ptr->zstream.avail_in > 0 &&
    729       !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
     640      (png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
    730641   {
    731642      int ret;
     
    1037948   }
    1038949   else
     950#endif
    1039951   {
    1040952      png_push_have_row(png_ptr, png_ptr->row_buf + 1);
     
    1046958png_read_push_finish_row(png_structrp png_ptr)
    1047959{
     960#ifdef PNG_READ_INTERLACING_SUPPORTED
    1048961   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
    1049962
     
    1070983      return;
    1071984
     985#ifdef PNG_READ_INTERLACING_SUPPORTED
    1072986   if (png_ptr->interlaced != 0)
    1073987   {
     
    11041018      } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
    11051019   }
     1020#endif /* READ_INTERLACING */
    11061021}
    11071022
     
    11281043}
    11291044
     1045#ifdef PNG_READ_INTERLACING_SUPPORTED
    11301046void PNGAPI
    11311047png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row,
     
    11421058      png_combine_row(png_ptr, old_row, 1/*blocky display*/);
    11431059}
     1060#endif /* READ_INTERLACING */
    11441061
    11451062void PNGAPI
  • TabularUnified libpng/vendor/current/pngpriv.h

    r1059 r1165  
    22/* pngpriv.h - private declarations for use inside libpng
    33 *
    4  * For conditions of distribution and use, see copyright notice in png.h
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    8  *
    9  * Last changed in libpng 1.6.10 [March 6, 1014]]
    108 *
    119 * This code is released under the libpng license.
     
    121119    * off.
    122120    *
    123     * Note that gcc-4.9 defines __ARM_NEON instead of __ARM_NEON__, so we
    124     * check both variants.
     121    * Note that gcc-4.9 defines __ARM_NEON instead of the deprecated
     122    * __ARM_NEON__, so we check both variants.
     123    *
     124    * To disable ARM_NEON optimizations entirely, and skip compiling the
     125    * associated assembler code, pass --enable-arm-neon=no to configure
     126    * or put -DPNG_ARM_NEON_OPT=0 in CPPFLAGS.
    125127    */
    126128#  if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \
     
    251253 */
    252254#ifndef PNG_INTERNAL_DATA
    253 #  define PNG_INTERNAL_DATA(type, name, array) extern type name array
     255#  define PNG_INTERNAL_DATA(type, name, array) PNG_LINKAGE_DATA type name array
    254256#endif
    255257
    256258#ifndef PNG_INTERNAL_FUNCTION
    257259#  define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\
    258       extern PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)
     260      PNG_LINKAGE_FUNCTION PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)
    259261#endif
    260262
    261263#ifndef PNG_INTERNAL_CALLBACK
    262264#  define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\
    263       extern PNG_FUNCTION(type, (PNGCBAPI name), args, PNG_EMPTY attributes)
     265      PNG_LINKAGE_CALLBACK PNG_FUNCTION(type, (PNGCBAPI name), args,\
     266         PNG_EMPTY attributes)
    264267#endif
    265268
     
    299302#endif
    300303
     304/* This is a global switch to set the compilation for an installed system
     305 * (a release build).  It can be set for testing debug builds to ensure that
     306 * they will compile when the build type is switched to RC or STABLE, the
     307 * default is just to use PNG_LIBPNG_BUILD_BASE_TYPE.  Set this in CPPFLAGS
     308 * with either:
     309 *
     310 *   -DPNG_RELEASE_BUILD Turns on the release compile path
     311 *   -DPNG_RELEASE_BUILD=0 Turns it off
     312 * or in your pngusr.h with
     313 *   #define PNG_RELEASE_BUILD=1 Turns on the release compile path
     314 *   #define PNG_RELEASE_BUILD=0 Turns it off
     315 */
     316#ifndef PNG_RELEASE_BUILD
     317#  define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC)
     318#endif
     319
    301320/* SECURITY and SAFETY:
    302321 *
    303  * By default libpng is built without any internal limits on image size,
    304  * individual heap (png_malloc) allocations or the total amount of memory used.
    305  * If PNG_SAFE_LIMITS_SUPPORTED is defined, however, the limits below are used
    306  * (unless individually overridden).  These limits are believed to be fairly
    307  * safe, but builders of secure systems should verify the values against the
    308  * real system capabilities.
    309  */
    310 #ifdef PNG_SAFE_LIMITS_SUPPORTED
    311    /* 'safe' limits */
    312 #  ifndef PNG_USER_WIDTH_MAX
    313 #     define PNG_USER_WIDTH_MAX 1000000
    314 #  endif
    315 #  ifndef PNG_USER_HEIGHT_MAX
    316 #     define PNG_USER_HEIGHT_MAX 1000000
    317 #  endif
    318 #  ifndef PNG_USER_CHUNK_CACHE_MAX
    319 #     define PNG_USER_CHUNK_CACHE_MAX 128
    320 #  endif
    321 #  ifndef PNG_USER_CHUNK_MALLOC_MAX
    322 #     define PNG_USER_CHUNK_MALLOC_MAX 8000000
    323 #  endif
    324 #else
    325    /* values for no limits */
    326 #  ifndef PNG_USER_WIDTH_MAX
    327 #     define PNG_USER_WIDTH_MAX 0x7fffffff
    328 #  endif
    329 #  ifndef PNG_USER_HEIGHT_MAX
    330 #     define PNG_USER_HEIGHT_MAX 0x7fffffff
    331 #  endif
    332 #  ifndef PNG_USER_CHUNK_CACHE_MAX
    333 #     define PNG_USER_CHUNK_CACHE_MAX 0
    334 #  endif
    335 #  ifndef PNG_USER_CHUNK_MALLOC_MAX
    336 #     define PNG_USER_CHUNK_MALLOC_MAX 0
    337 #  endif
    338 #endif
    339 
    340 /* Moved to pngpriv.h at libpng-1.5.0 */
    341 /* NOTE: some of these may have been used in external applications as
    342  * these definitions were exposed in pngconf.h prior to 1.5.
     322 * libpng is built with support for internal limits on image dimensions and
     323 * memory usage.  These are documented in scripts/pnglibconf.dfa of the
     324 * source and recorded in the machine generated header file pnglibconf.h.
    343325 */
    344326
     
    583565#define PNG_RGB_TO_GRAY       0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */
    584566#define PNG_ENCODE_ALPHA      0x800000 /* Added to libpng-1.5.4 */
    585 #define PNG_ADD_ALPHA         0x1000000 /* Added to libpng-1.2.7 */
    586 #define PNG_EXPAND_tRNS       0x2000000 /* Added to libpng-1.2.9 */
    587 #define PNG_SCALE_16_TO_8     0x4000000 /* Added to libpng-1.5.4 */
    588                        /*   0x8000000 unused */
    589                        /*  0x10000000 unused */
    590                        /*  0x20000000 unused */
    591                        /*  0x40000000 unused */
     567#define PNG_ADD_ALPHA        0x1000000 /* Added to libpng-1.2.7 */
     568#define PNG_EXPAND_tRNS      0x2000000 /* Added to libpng-1.2.9 */
     569#define PNG_SCALE_16_TO_8    0x4000000 /* Added to libpng-1.5.4 */
     570                       /*    0x8000000 unused */
     571                       /*   0x10000000 unused */
     572                       /*   0x20000000 unused */
     573                       /*   0x40000000 unused */
    592574/* Flags for png_create_struct */
    593575#define PNG_STRUCT_PNG   0x0001
     
    781763 */
    782764#define PNG_CHUNK_FROM_STRING(s)\
    783    PNG_U32(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3])
     765   PNG_U32(0xff & (s)[0], 0xff & (s)[1], 0xff & (s)[2], 0xff & (s)[3])
    784766
    785767/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is
     
    788770 */
    789771#define PNG_STRING_FROM_CHUNK(s,c)\
    790    (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\
    791    ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c)))
     772   (void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \
     773   ((char*)(s))[1]=(char)(((c)>>16) & 0xff),\
     774   ((char*)(s))[2]=(char)(((c)>>8) & 0xff), \
     775   ((char*)(s))[3]=(char)((c & 0xff)))
    792776
    793777/* Do the same but terminate with a null character. */
     
    851835PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]);
    852836
    853 #define PNG_sRGB_FROM_LINEAR(linear) ((png_byte)((png_sRGB_base[(linear)>>15] +\
    854    ((((linear)&0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8))
     837#define PNG_sRGB_FROM_LINEAR(linear) \
     838  ((png_byte)(0xff & ((png_sRGB_base[(linear)>>15] \
     839   + ((((linear) & 0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8)))
    855840   /* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB
    856841    * encoded value with maximum error 0.646365.  Note that the input is not a
     
    911896   defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)
    912897/* Internal array allocator, outputs no error or warning messages on failure,
    913  * just returns NULL. 
     898 * just returns NULL.
    914899 */
    915900PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_array,(png_const_structrp png_ptr,
     
    14091394    png_inforp info_ptr),PNG_EMPTY);
    14101395PNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY);
    1411 PNG_INTERNAL_FUNCTION(void,png_push_crc_skip,(png_structrp png_ptr,
    1412     png_uint_32 length),PNG_EMPTY);
    1413 PNG_INTERNAL_FUNCTION(void,png_push_crc_finish,(png_structrp png_ptr),
    1414     PNG_EMPTY);
    14151396PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr),
    14161397    PNG_EMPTY);
  • TabularUnified libpng/vendor/current/pngread.c

    r1059 r1165  
    22/* pngread.c - read a PNG file
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.17 [March 26, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    6464          * handled.
    6565          */
    66 #        if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
     66#        if PNG_RELEASE_BUILD
    6767            png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;
    6868#        endif
     
    815815          * read, but not after other chunks have been read.
    816816          */
    817          if ((length > 0) ||
    818              (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0)
     817         if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0)
    819818            png_benign_error(png_ptr, "Too many IDATs found");
    820819
     
    10451044    */
    10461045   if ((transforms & PNG_TRANSFORM_SCALE_16) != 0)
    1047      /* Added at libpng-1.5.4. "strip_16" produces the same result that it
    1048       * did in earlier versions, while "scale_16" is now more accurate.
    1049       */
     1046      /* Added at libpng-1.5.4. "strip_16" produces the same result that it
     1047       * did in earlier versions, while "scale_16" is now more accurate.
     1048       */
    10501049#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
    10511050      png_set_scale_16(png_ptr);
     
    12111210      for (iptr = 0; iptr < info_ptr->height; iptr++)
    12121211         info_ptr->row_pointers[iptr] = png_voidcast(png_bytep,
    1213             png_malloc(png_ptr, info_ptr->rowbytes));
     1212             png_malloc(png_ptr, info_ptr->rowbytes));
    12141213   }
    12151214
     
    18251824            y *= 255;
    18261825            y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7);
     1826            alpha = PNG_DIV257(alpha);
    18271827            encoding = P_sRGB;
    18281828         }
     
    22872287                     break;
    22882288                  }
    2289 
     2289#ifdef __COVERITY__
     2290                 /* Coverity claims that output_encoding cannot be 2 (P_LINEAR)
     2291                  * here.
     2292                  */
     2293                  back_alpha = 255;
     2294#else
    22902295                  back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
     2296#endif
    22912297               }
    22922298
     
    24132419               background_index = i;
    24142420               png_create_colormap_entry(display, i++, back_r, back_g, back_b,
    2415                   output_encoding == P_LINEAR ? 65535U : 255U, output_encoding);
     2421#ifdef __COVERITY__
     2422                 /* Coverity claims that output_encoding cannot be 2 (P_LINEAR)
     2423                  * here.
     2424                  */ 255U,
     2425#else
     2426                  output_encoding == P_LINEAR ? 65535U : 255U,
     2427#endif
     2428                  output_encoding);
    24162429
    24172430               /* For non-opaque input composite on the sRGB background - this
     
    32473260      ptrdiff_t    step_row = display->row_bytes;
    32483261      unsigned int channels =
    3249          (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
     3262          (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
    32503263      int pass;
    32513264
  • TabularUnified libpng/vendor/current/pngrio.c

    r1059 r1165  
    22/* pngrio.c - functions for data input
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.17 [March 26, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    2727 * with very small lengths, so you should implement some kind of simple
    2828 * buffering if you are using unbuffered reads.  This should never be asked
    29  * to read more then 64K on a 16 bit machine.
     29 * to read more than 64K on a 16 bit machine.
    3030 */
    3131void /* PRIVATE */
  • TabularUnified libpng/vendor/current/pngrtran.c

    r1059 r1165  
    22/* pngrtran.c - transforms the data in a row for PNG readers
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    395395 * of elements in the palette, the maximum number of elements
    396396 * allowed, and a histogram if possible.  If the current number
    397  * of colors is greater then the maximum number, the palette will be
     397 * of colors is greater than the maximum number, the palette will be
    398398 * modified to fit in the maximum number.  "full_quantize" indicates
    399399 * whether we need a quantizing cube set up for RGB images, or if we
     
    23582358                  channel = 0;
    23592359               *bp++ = (png_byte)(value >> 8);
    2360                *bp++ = (png_byte)(value & 0xff);
     2360               *bp++ = (png_byte)value;
    23612361            }
    23622362            break;
     
    26632663
    26642664#ifdef PNG_READ_16BIT_SUPPORTED
    2665    png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
    2666 #endif
    2667    png_byte lo_filler = (png_byte)(filler & 0xff);
     2665   png_byte hi_filler = (png_byte)(filler>>8);
     2666#endif
     2667   png_byte lo_filler = (png_byte)filler;
    26682668
    26692669   png_debug(1, "in png_do_read_filler");
     
    27162716            for (i = 1; i < row_width; i++)
    27172717            {
     2718               *(--dp) = lo_filler;
    27182719               *(--dp) = hi_filler;
    2719                *(--dp) = lo_filler;
    27202720               *(--dp) = *(--sp);
    27212721               *(--dp) = *(--sp);
    27222722            }
     2723            *(--dp) = lo_filler;
    27232724            *(--dp) = hi_filler;
    2724             *(--dp) = lo_filler;
    27252725            row_info->channels = 2;
    27262726            row_info->pixel_depth = 32;
     
    27372737               *(--dp) = *(--sp);
    27382738               *(--dp) = *(--sp);
     2739               *(--dp) = lo_filler;
    27392740               *(--dp) = hi_filler;
    2740                *(--dp) = lo_filler;
    27412741            }
    27422742            row_info->channels = 2;
     
    27972797            for (i = 1; i < row_width; i++)
    27982798            {
     2799               *(--dp) = lo_filler;
    27992800               *(--dp) = hi_filler;
    2800                *(--dp) = lo_filler;
    28012801               *(--dp) = *(--sp);
    28022802               *(--dp) = *(--sp);
     
    28062806               *(--dp) = *(--sp);
    28072807            }
     2808            *(--dp) = lo_filler;
    28082809            *(--dp) = hi_filler;
    2809             *(--dp) = lo_filler;
    28102810            row_info->channels = 4;
    28112811            row_info->pixel_depth = 64;
     
    28262826               *(--dp) = *(--sp);
    28272827               *(--dp) = *(--sp);
     2828               *(--dp) = lo_filler;
    28282829               *(--dp) = hi_filler;
    2829                *(--dp) = lo_filler;
    28302830            }
    28312831
     
    30883088            {
    30893089               png_uint_16 red, green, blue, w;
    3090 
    3091                red   = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
    3092                green = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
    3093                blue  = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
     3090               png_byte hi,lo;
     3091
     3092               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
     3093               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
     3094               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
    30943095
    30953096               if (red == green && red == blue)
     
    31053106               else
    31063107               {
    3107                   png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red&0xff)
     3108                  png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red & 0xff)
    31083109                      >> png_ptr->gamma_shift][red>>8];
    31093110                  png_uint_16 green_1 =
    3110                       png_ptr->gamma_16_to_1[(green&0xff) >>
     3111                      png_ptr->gamma_16_to_1[(green & 0xff) >>
    31113112                      png_ptr->gamma_shift][green>>8];
    3112                   png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue&0xff)
     3113                  png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue & 0xff)
    31133114                      >> png_ptr->gamma_shift][blue>>8];
    31143115                  png_uint_16 gray16  = (png_uint_16)((rc*red_1 + gc*green_1
    31153116                      + bc*blue_1 + 16384)>>15);
    3116                   w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
     3117                  w = png_ptr->gamma_16_from_1[(gray16 & 0xff) >>
    31173118                      png_ptr->gamma_shift][gray16 >> 8];
    31183119                  rgb_error |= 1;
     
    31393140            {
    31403141               png_uint_16 red, green, blue, gray16;
    3141 
    3142                red   = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
    3143                green = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
    3144                blue  = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2;
     3142               png_byte hi,lo;
     3143
     3144               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
     3145               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
     3146               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
    31453147
    31463148               if (red != green || red != blue)
     
    36683670                           w = v;
    36693671                        else
    3670                            w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
     3672                           w = gamma_16_from_1[(v & 0xff) >>
     3673                               gamma_shift][v >> 8];
    36713674                        *sp = (png_byte)((w >> 8) & 0xff);
    36723675                        *(sp + 1) = (png_byte)(w & 0xff);
     
    38323835                        png_composite_16(w, v, a, png_ptr->background_1.red);
    38333836                        if (optimize == 0)
    3834                            w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >>
     3837                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
    38353838                                8];
    38363839                        *sp = (png_byte)((w >> 8) & 0xff);
     
    38403843                        png_composite_16(w, v, a, png_ptr->background_1.green);
    38413844                        if (optimize == 0)
    3842                            w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >>
     3845                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
    38433846                                8];
    38443847
     
    38493852                        png_composite_16(w, v, a, png_ptr->background_1.blue);
    38503853                        if (optimize == 0)
    3851                            w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >>
     3854                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
    38523855                                8];
    38533856
     
    44584461               for (i = 0; i < row_width; i++)
    44594462               {
    4460                   if (*sp == gray)
     4463                  if ((*sp & 0xffU) == gray)
    44614464                     *dp-- = 0;
    44624465
     
    44764479               for (i = 0; i < row_width; i++)
    44774480               {
    4478                   if (*(sp - 1) == gray_high && *(sp) == gray_low)
     4481                  if ((*(sp - 1) & 0xffU) == gray_high &&
     4482                      (*(sp) & 0xffU) == gray_low)
    44794483                  {
    44804484                     *dp-- = 0;
     
    48384842       * do (if there is an alpha channel or transparency.)
    48394843       */
    4840        !((png_ptr->transformations & PNG_COMPOSE) &&
     4844       !((png_ptr->transformations & PNG_COMPOSE) != 0 &&
    48414845       ((png_ptr->num_trans != 0) ||
    48424846       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) &&
  • TabularUnified libpng/vendor/current/pngrutil.c

    r1059 r1165  
    22/* pngrutil.c - utilities to read a PNG file
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    342342       */
    343343      (void)png_safecat(msg, (sizeof msg), 4, " using zstream");
    344 #if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
     344#if PNG_RELEASE_BUILD
    345345      png_chunk_warning(png_ptr, msg);
    346346      png_ptr->zowner = 0;
     
    576576   png_alloc_size_t limit = PNG_SIZE_MAX;
    577577
    578 # ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
     578# ifdef PNG_SET_USER_LIMITS_SUPPORTED
    579579   if (png_ptr->user_chunk_malloc_max > 0 &&
    580580       png_ptr->user_chunk_malloc_max < limit)
     
    671671                   */
    672672                  png_free(png_ptr, text);
    673                   text = NULL;
    674673
    675674                  /* This really is very benign, but it's still an error because
     
    11481147
    11491148   for (i=0; i<truelen; ++i)
     1149   {
    11501150      if (buf[i] == 0 || buf[i] > sample_depth)
    11511151      {
     
    11531153         return;
    11541154      }
     1155   }
    11551156
    11561157   if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
     
    14631464
    14641465#                                   ifdef PNG_sRGB_SUPPORTED
    1465                                        /* Check for a match against sRGB */
    1466                                        png_icc_set_sRGB(png_ptr,
    1467                                           &png_ptr->colorspace, profile,
    1468                                           png_ptr->zstream.adler);
     1466                                    /* Check for a match against sRGB */
     1467                                    png_icc_set_sRGB(png_ptr,
     1468                                       &png_ptr->colorspace, profile,
     1469                                       png_ptr->zstream.adler);
    14691470#                                   endif
    14701471
     
    15161517                                    errmsg = "truncated";
    15171518
     1519#ifndef __COVERITY__
    15181520                                 else
    15191521                                    errmsg = png_ptr->zstream.msg;
     1522#endif
    15201523                              }
    15211524
     
    16741677   if (dl > max_dl)
    16751678   {
    1676        png_warning(png_ptr, "sPLT chunk too long");
    1677        return;
     1679      png_warning(png_ptr, "sPLT chunk too long");
     1680      return;
    16781681   }
    16791682
     
    16851688   if (new_palette.entries == NULL)
    16861689   {
    1687        png_warning(png_ptr, "sPLT chunk requires too much memory");
    1688        return;
     1690      png_warning(png_ptr, "sPLT chunk requires too much memory");
     1691      return;
    16891692   }
    16901693
     
    18161819      }
    18171820
    1818       if (length > png_ptr->num_palette || length > PNG_MAX_PALETTE_LENGTH ||
     1821      if (length > png_ptr->num_palette ||
     1822         length > (unsigned int) PNG_MAX_PALETTE_LENGTH ||
    18191823         length == 0)
    18201824      {
     
    19791983   num = length / 2 ;
    19801984
    1981    if (num != png_ptr->num_palette || num > PNG_MAX_PALETTE_LENGTH)
     1985   if (num != png_ptr->num_palette || num > (unsigned int) PNG_MAX_PALETTE_LENGTH)
    19821986   {
    19831987      png_crc_finish(png_ptr, length);
     
    27142718   }
    27152719
    2716 #  ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
    2717       if (png_ptr->user_chunk_malloc_max > 0 &&
    2718           png_ptr->user_chunk_malloc_max < limit)
    2719          limit = png_ptr->user_chunk_malloc_max;
     2720#  ifdef PNG_SET_USER_LIMITS_SUPPORTED
     2721   if (png_ptr->user_chunk_malloc_max > 0 &&
     2722       png_ptr->user_chunk_malloc_max < limit)
     2723      limit = png_ptr->user_chunk_malloc_max;
    27202724
    27212725#  elif PNG_USER_CHUNK_MALLOC_MAX > 0
    2722       if (PNG_USER_CHUNK_MALLOC_MAX < limit)
    2723          limit = PNG_USER_CHUNK_MALLOC_MAX;
     2726   if (PNG_USER_CHUNK_MALLOC_MAX < limit)
     2727      limit = PNG_USER_CHUNK_MALLOC_MAX;
    27242728#  endif
    27252729
     
    27842788#  ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
    27852789#     ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
    2786          keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name);
     2790   keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name);
    27872791#     endif
    27882792#  endif
     
    27932797    */
    27942798#  ifdef PNG_READ_USER_CHUNKS_SUPPORTED
    2795       /* The user callback takes precedence over the chunk keep value, but the
    2796        * keep value is still required to validate a save of a critical chunk.
    2797        */
    2798       if (png_ptr->read_user_chunk_fn != NULL)
    2799       {
    2800          if (png_cache_unknown_chunk(png_ptr, length) != 0)
     2799   /* The user callback takes precedence over the chunk keep value, but the
     2800    * keep value is still required to validate a save of a critical chunk.
     2801    */
     2802   if (png_ptr->read_user_chunk_fn != NULL)
     2803   {
     2804      if (png_cache_unknown_chunk(png_ptr, length) != 0)
     2805      {
     2806         /* Callback to user unknown chunk handler */
     2807         int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
     2808            &png_ptr->unknown_chunk);
     2809
     2810         /* ret is:
     2811          * negative: An error occurred; png_chunk_error will be called.
     2812          *     zero: The chunk was not handled, the chunk will be discarded
     2813          *           unless png_set_keep_unknown_chunks has been used to set
     2814          *           a 'keep' behavior for this particular chunk, in which
     2815          *           case that will be used.  A critical chunk will cause an
     2816          *           error at this point unless it is to be saved.
     2817          * positive: The chunk was handled, libpng will ignore/discard it.
     2818          */
     2819         if (ret < 0)
     2820            png_chunk_error(png_ptr, "error in user chunk");
     2821
     2822         else if (ret == 0)
    28012823         {
    2802             /* Callback to user unknown chunk handler */
    2803             int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
    2804                &png_ptr->unknown_chunk);
    2805 
    2806             /* ret is:
    2807              * negative: An error occured, png_chunk_error will be called.
    2808              *     zero: The chunk was not handled, the chunk will be discarded
    2809              *           unless png_set_keep_unknown_chunks has been used to set
    2810              *           a 'keep' behavior for this particular chunk, in which
    2811              *           case that will be used.  A critical chunk will cause an
    2812              *           error at this point unless it is to be saved.
    2813              * positive: The chunk was handled, libpng will ignore/discard it.
     2824            /* If the keep value is 'default' or 'never' override it, but
     2825             * still error out on critical chunks unless the keep value is
     2826             * 'always'  While this is weird it is the behavior in 1.4.12.
     2827             * A possible improvement would be to obey the value set for the
     2828             * chunk, but this would be an API change that would probably
     2829             * damage some applications.
     2830             *
     2831             * The png_app_warning below catches the case that matters, where
     2832             * the application has not set specific save or ignore for this
     2833             * chunk or global save or ignore.
    28142834             */
    2815             if (ret < 0)
    2816                png_chunk_error(png_ptr, "error in user chunk");
    2817 
    2818             else if (ret == 0)
     2835            if (keep < PNG_HANDLE_CHUNK_IF_SAFE)
    28192836            {
    2820                /* If the keep value is 'default' or 'never' override it, but
    2821                 * still error out on critical chunks unless the keep value is
    2822                 * 'always'  While this is weird it is the behavior in 1.4.12.
    2823                 * A possible improvement would be to obey the value set for the
    2824                 * chunk, but this would be an API change that would probably
    2825                 * damage some applications.
    2826                 *
    2827                 * The png_app_warning below catches the case that matters, where
    2828                 * the application has not set specific save or ignore for this
    2829                 * chunk or global save or ignore.
    2830                 */
    2831                if (keep < PNG_HANDLE_CHUNK_IF_SAFE)
     2837#              ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
     2838               if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE)
    28322839               {
    2833 #                 ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
    2834                      if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE)
    2835                      {
    2836                         png_chunk_warning(png_ptr, "Saving unknown chunk:");
    2837                         png_app_warning(png_ptr,
    2838                            "forcing save of an unhandled chunk;"
    2839                            " please call png_set_keep_unknown_chunks");
    2840                            /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
    2841                      }
    2842 #                 endif
    2843                   keep = PNG_HANDLE_CHUNK_IF_SAFE;
     2840                  png_chunk_warning(png_ptr, "Saving unknown chunk:");
     2841                  png_app_warning(png_ptr,
     2842                     "forcing save of an unhandled chunk;"
     2843                     " please call png_set_keep_unknown_chunks");
     2844                     /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
    28442845               }
    2845             }
    2846 
    2847             else /* chunk was handled */
    2848             {
    2849                handled = 1;
    2850                /* Critical chunks can be safely discarded at this point. */
    2851                keep = PNG_HANDLE_CHUNK_NEVER;
     2846#              endif
     2847               keep = PNG_HANDLE_CHUNK_IF_SAFE;
    28522848            }
    28532849         }
    28542850
    2855          else
    2856             keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */
     2851         else /* chunk was handled */
     2852         {
     2853            handled = 1;
     2854            /* Critical chunks can be safely discarded at this point. */
     2855            keep = PNG_HANDLE_CHUNK_NEVER;
     2856         }
    28572857      }
    28582858
    28592859      else
    2860          /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */
     2860         keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */
     2861   }
     2862
     2863   else
     2864   /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */
    28612865#  endif /* READ_USER_CHUNKS */
    28622866
    28632867#  ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
    2864       {
    2865          /* keep is currently just the per-chunk setting, if there was no
    2866           * setting change it to the global default now (not that this may
    2867           * still be AS_DEFAULT) then obtain the cache of the chunk if required,
    2868           * if not simply skip the chunk.
    2869           */
    2870          if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
    2871             keep = png_ptr->unknown_default;
    2872 
    2873          if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
    2874             (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
    2875              PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
    2876          {
    2877             if (png_cache_unknown_chunk(png_ptr, length) == 0)
    2878                keep = PNG_HANDLE_CHUNK_NEVER;
    2879          }
    2880 
    2881          else
    2882             png_crc_finish(png_ptr, length);
    2883       }
     2868   {
     2869      /* keep is currently just the per-chunk setting, if there was no
     2870       * setting change it to the global default now (not that this may
     2871       * still be AS_DEFAULT) then obtain the cache of the chunk if required,
     2872       * if not simply skip the chunk.
     2873       */
     2874      if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
     2875         keep = png_ptr->unknown_default;
     2876
     2877      if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
     2878         (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
     2879          PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
     2880      {
     2881         if (png_cache_unknown_chunk(png_ptr, length) == 0)
     2882            keep = PNG_HANDLE_CHUNK_NEVER;
     2883      }
     2884
     2885      else
     2886         png_crc_finish(png_ptr, length);
     2887   }
    28842888#  else
    28852889#     ifndef PNG_READ_USER_CHUNKS_SUPPORTED
     
    28872891#     endif
    28882892
    2889       {
    2890          /* If here there is no read callback pointer set and no support is
    2891           * compiled in to just save the unknown chunks, so simply skip this
    2892           * chunk.  If 'keep' is something other than AS_DEFAULT or NEVER then
    2893           * the app has erroneously asked for unknown chunk saving when there
    2894           * is no support.
    2895           */
    2896          if (keep > PNG_HANDLE_CHUNK_NEVER)
    2897             png_app_error(png_ptr, "no unknown chunk support available");
    2898 
    2899          png_crc_finish(png_ptr, length);
    2900       }
     2893   {
     2894      /* If here there is no read callback pointer set and no support is
     2895       * compiled in to just save the unknown chunks, so simply skip this
     2896       * chunk.  If 'keep' is something other than AS_DEFAULT or NEVER then
     2897       * the app has erroneously asked for unknown chunk saving when there
     2898       * is no support.
     2899       */
     2900      if (keep > PNG_HANDLE_CHUNK_NEVER)
     2901         png_app_error(png_ptr, "no unknown chunk support available");
     2902
     2903      png_crc_finish(png_ptr, length);
     2904   }
    29012905#  endif
    29022906
    29032907#  ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
    2904       /* Now store the chunk in the chunk list if appropriate, and if the limits
    2905        * permit it.
    2906        */
    2907       if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
    2908          (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
    2909           PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
    2910       {
     2908   /* Now store the chunk in the chunk list if appropriate, and if the limits
     2909    * permit it.
     2910    */
     2911   if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
     2912      (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
     2913       PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
     2914   {
    29112915#     ifdef PNG_USER_LIMITS_SUPPORTED
    2912          switch (png_ptr->user_chunk_cache_max)
    2913          {
    2914             case 2:
    2915                png_ptr->user_chunk_cache_max = 1;
    2916                png_chunk_benign_error(png_ptr, "no space in chunk cache");
    2917                /* FALL THROUGH */
    2918             case 1:
    2919                /* NOTE: prior to 1.6.0 this case resulted in an unknown critical
    2920                 * chunk being skipped, now there will be a hard error below.
    2921                 */
    2922                break;
    2923 
    2924             default: /* not at limit */
    2925                --(png_ptr->user_chunk_cache_max);
    2926                /* FALL THROUGH */
    2927             case 0: /* no limit */
    2928    endif /* USER_LIMITS */
    2929                /* Here when the limit isn't reached or when limits are compiled
    2930                 * out; store the chunk.
    2931                 */
    2932                png_set_unknown_chunks(png_ptr, info_ptr,
    2933                   &png_ptr->unknown_chunk, 1);
    2934                handled = 1;
    2935    ifdef PNG_USER_LIMITS_SUPPORTED
    2936                break;
    2937          }
    2938    endif
    2939       }
     2916      switch (png_ptr->user_chunk_cache_max)
     2917      {
     2918         case 2:
     2919            png_ptr->user_chunk_cache_max = 1;
     2920            png_chunk_benign_error(png_ptr, "no space in chunk cache");
     2921            /* FALL THROUGH */
     2922         case 1:
     2923            /* NOTE: prior to 1.6.0 this case resulted in an unknown critical
     2924             * chunk being skipped, now there will be a hard error below.
     2925             */
     2926            break;
     2927
     2928         default: /* not at limit */
     2929            --(png_ptr->user_chunk_cache_max);
     2930            /* FALL THROUGH */
     2931         case 0: /* no limit */
     2932endif /* USER_LIMITS */
     2933            /* Here when the limit isn't reached or when limits are compiled
     2934             * out; store the chunk.
     2935             */
     2936            png_set_unknown_chunks(png_ptr, info_ptr,
     2937               &png_ptr->unknown_chunk, 1);
     2938            handled = 1;
     2939ifdef PNG_USER_LIMITS_SUPPORTED
     2940            break;
     2941      }
     2942endif
     2943   }
    29402944#  else /* no store support: the chunk must be handled by the user callback */
    2941       PNG_UNUSED(info_ptr)
     2945   PNG_UNUSED(info_ptr)
    29422946#  endif
    29432947
     
    30413045      end_byte = *end_ptr;
    30423046#     ifdef PNG_READ_PACKSWAP_SUPPORTED
    3043          if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
    3044             /* little-endian byte */
    3045             end_mask = 0xff << end_mask;
    3046 
    3047          else /* big-endian byte */
     3047      if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
     3048         /* little-endian byte */
     3049         end_mask = 0xff << end_mask;
     3050
     3051      else /* big-endian byte */
    30483052#     endif
    3049          end_mask = 0xff >> end_mask;
     3053      end_mask = 0xff >> end_mask;
    30503054      /* end_mask is now the bits to *keep* from the destination row */
    30513055   }
     
    32053209
    32063210#        ifdef PNG_READ_PACKSWAP_SUPPORTED
    3207             if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
    3208                mask = MASK(pass, pixel_depth, display, 0);
    3209 
    3210             else
     3211         if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
     3212            mask = MASK(pass, pixel_depth, display, 0);
     3213
     3214         else
    32113215#        endif
    3212             mask = MASK(pass, pixel_depth, display, 1);
     3216         mask = MASK(pass, pixel_depth, display, 1);
    32133217
    32143218         for (;;)
     
    38113815      pc = a - c;
    38123816
    3813 #     ifdef PNG_USE_ABS
    3814          pa = abs(p);
    3815          pb = abs(pc);
    3816          pc = abs(p + pc);
    3817 #     else
    3818          pa = p < 0 ? -p : p;
    3819          pb = pc < 0 ? -pc : pc;
    3820          pc = (p + pc) < 0 ? -(p + pc) : p + pc;
    3821 #     endif
     3817#ifdef PNG_USE_ABS
     3818      pa = abs(p);
     3819      pb = abs(pc);
     3820      pc = abs(p + pc);
     3821#else
     3822      pa = p < 0 ? -p : p;
     3823      pb = pc < 0 ? -pc : pc;
     3824      pc = (p + pc) < 0 ? -(p + pc) : p + pc;
     3825#endif
    38223826
    38233827      /* Find the best predictor, the least of pa, pb, pc favoring the earlier
     
    38663870      pc = a - c;
    38673871
    3868 #     ifdef PNG_USE_ABS
    3869          pa = abs(p);
    3870          pb = abs(pc);
    3871          pc = abs(p + pc);
    3872 #     else
    3873          pa = p < 0 ? -p : p;
    3874          pb = pc < 0 ? -pc : pc;
    3875          pc = (p + pc) < 0 ? -(p + pc) : p + pc;
    3876 #     endif
     3872#ifdef PNG_USE_ABS
     3873      pa = abs(p);
     3874      pb = abs(pc);
     3875      pc = abs(p + pc);
     3876#else
     3877      pa = p < 0 ? -p : p;
     3878      pb = pc < 0 ? -pc : pc;
     3879      pc = (p + pc) < 0 ? -(p + pc) : p + pc;
     3880#endif
    38773881
    38783882      if (pb < pa) pa = pb, a = b;
     
    42794283   if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
    42804284   {
    4281    ifdef PNG_READ_EXPAND_SUPPORTED
    4282          /* In fact it is an error if it isn't supported, but checking is
    4283           * the safe way.
    4284           */
    4285          if ((png_ptr->transformations & PNG_EXPAND) != 0)
    4286          {
    4287             if (png_ptr->bit_depth < 16)
    4288                max_pixel_depth *= 2;
    4289          }
    4290          else
    4291    endif
    4292          png_ptr->transformations &= ~PNG_EXPAND_16;
     4285ifdef PNG_READ_EXPAND_SUPPORTED
     4286      /* In fact it is an error if it isn't supported, but checking is
     4287       * the safe way.
     4288       */
     4289      if ((png_ptr->transformations & PNG_EXPAND) != 0)
     4290      {
     4291         if (png_ptr->bit_depth < 16)
     4292            max_pixel_depth *= 2;
     4293      }
     4294      else
     4295endif
     4296      png_ptr->transformations &= ~PNG_EXPAND_16;
    42934297   }
    42944298#endif
  • TabularUnified libpng/vendor/current/pngset.c

    r1059 r1165  
    22/* pngset.c - storage of image information into info struct
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    191191   {
    192192      png_warning(png_ptr, "Insufficient memory for hIST chunk data");
     193
    193194      return;
    194195   }
     
    272273
    273274   if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL
    274       || (nparams > 0 && params == NULL))
     275       || (nparams > 0 && params == NULL))
    275276      return;
    276277
     
    302303   {
    303304      png_warning(png_ptr, "Insufficient memory for pCAL purpose");
     305
    304306      return;
    305307   }
     
    323325   {
    324326      png_warning(png_ptr, "Insufficient memory for pCAL units");
     327
    325328      return;
    326329   }
     
    334337   {
    335338      png_warning(png_ptr, "Insufficient memory for pCAL params");
     339
    336340      return;
    337341   }
     
    350354      {
    351355         png_warning(png_ptr, "Insufficient memory for pCAL parameter");
     356
    352357         return;
    353358      }
     
    399404   {
    400405      png_warning(png_ptr, "Memory allocation failed while processing sCAL");
     406
    401407      return;
    402408   }
     
    417423
    418424      png_warning(png_ptr, "Memory allocation failed while processing sCAL");
     425
    419426      return;
    420427   }
     
    520527      {
    521528         png_warning(png_ptr, "Invalid palette length");
     529
    522530         return;
    523531      }
     
    532540   {
    533541      png_error(png_ptr, "Invalid palette");
    534       return;
    535542   }
    536543
     
    656663   {
    657664      png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk");
     665
    658666      return;
    659667   }
     
    666674   {
    667675      png_free(png_ptr, new_iccp_name);
    668       new_iccp_name = NULL;
    669676      png_benign_error(png_ptr,
    670677          "Insufficient memory to process iCCP profile");
     678
    671679      return;
    672680   }
     
    702710   int i;
    703711
    704    png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" :
     712   png_debug1(1, "in %lx storage function", png_ptr == NULL ? 0xabadca11 :
    705713      (unsigned long)png_ptr->chunk_name);
    706714
     
    744752         png_chunk_report(png_ptr, "too many text chunks",
    745753            PNG_CHUNK_WRITE_ERROR);
     754
    746755         return 1;
    747756      }
     
    799808            lang_key_len = 0;
    800809      }
    801 #  else /* PNG_iTXt_SUPPORTED */
     810#  else /* iTXt */
    802811      {
    803812         png_chunk_report(png_ptr, "iTXt chunk not supported",
     
    832841         png_chunk_report(png_ptr, "text chunk: out of memory",
    833842               PNG_CHUNK_WRITE_ERROR);
     843
    834844         return 1;
    835845      }
     
    905915   {
    906916      png_warning(png_ptr, "Ignoring invalid time value");
     917
    907918      return;
    908919   }
     
    921932
    922933   if (png_ptr == NULL || info_ptr == NULL)
     934
    923935      return;
    924936
     
    946958   if (trans_color != NULL)
    947959   {
    948       int sample_max = (1 << info_ptr->bit_depth);
    949 
    950       if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
    951           trans_color->gray > sample_max) ||
    952           (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
    953           (trans_color->red > sample_max ||
    954           trans_color->green > sample_max ||
    955           trans_color->blue > sample_max)))
    956          png_warning(png_ptr,
    957             "tRNS chunk has out-of-range samples for bit_depth");
     960#ifdef PNG_WARNINGS_SUPPORTED
     961      if (info_ptr->bit_depth < 16)
     962      {
     963         int sample_max = (1 << info_ptr->bit_depth) - 1;
     964
     965         if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
     966             trans_color->gray > sample_max) ||
     967             (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
     968             (trans_color->red > sample_max ||
     969             trans_color->green > sample_max ||
     970             trans_color->blue > sample_max)))
     971            png_warning(png_ptr,
     972               "tRNS chunk has out-of-range samples for bit_depth");
     973      }
     974#endif
    958975
    959976      info_ptr->trans_color = *trans_color;
     
    10021019      /* Out of memory or too many chunks */
    10031020      png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR);
     1021
    10041022      return;
    10051023   }
     
    11171135
    11181136   if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 ||
    1119       unknowns == NULL)
     1137       unknowns == NULL)
    11201138      return;
    11211139
     
    11311149      {
    11321150         png_app_error(png_ptr, "no unknown chunk support on read");
     1151
    11331152         return;
    11341153      }
     
    11391158      {
    11401159         png_app_error(png_ptr, "no unknown chunk support on write");
     1160
    11411161         return;
    11421162      }
     
    11561176      png_chunk_report(png_ptr, "too many unknown chunks",
    11571177         PNG_CHUNK_WRITE_ERROR);
     1178
    11581179      return;
    11591180   }
     
    12331254   }
    12341255}
    1235 #endif
    1236 
     1256#endif /* STORE_UNKNOWN_CHUNKS */
    12371257
    12381258#ifdef PNG_MNG_FEATURES_SUPPORTED
     
    12651285      {
    12661286         list[4] = (png_byte)keep;
     1287
    12671288         return count;
    12681289      }
     
    12921313   {
    12931314      png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep");
     1315
    12941316      return;
    12951317   }
     
    13411363          */
    13421364         png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list");
     1365
    13431366         return;
    13441367      }
     
    13561379   {
    13571380      png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks");
     1381
    13581382      return;
    13591383   }
     
    14931517            png_warning(png_ptr,
    14941518              "Compression buffer size cannot be changed because it is in use");
     1519
    14951520            return;
    14961521         }
    14971522
     1523#ifndef __COVERITY__
     1524         /* Some compilers complain that this is always false.  However, it
     1525          * can be true when integer overflow happens.
     1526          */
    14981527         if (size > ZLIB_IO_MAX)
    14991528         {
     
    15021531            size = ZLIB_IO_MAX; /* must fit */
    15031532         }
    1504 
    1505          else if (size < 6)
     1533#endif
     1534
     1535         if (size < 6)
    15061536         {
    15071537            /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
     
    15101540            png_warning(png_ptr,
    15111541               "Compression buffer size cannot be reduced below 6");
     1542
    15121543            return;
    15131544         }
     
    15511582png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max)
    15521583{
    1553     if (png_ptr != NULL)
    1554        png_ptr->user_chunk_cache_max = user_chunk_cache_max;
     1584   if (png_ptr != NULL)
     1585      png_ptr->user_chunk_cache_max = user_chunk_cache_max;
    15551586}
    15561587
  • TabularUnified libpng/vendor/current/pngstruct.h

    r1059 r1165  
    22/* pngstruct.h - header file for PNG reference library
    33 *
    4  * Copyright (c) 1998-2013 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    56 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    67 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    7  *
    8  * Last changed in libpng 1.6.1 [March 28, 2013]
    98 *
    109 * This code is released under the libpng license.
     
    102101
    103102#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
    104 /* A colorspace is all the above plus, potentially, profile information,
     103/* A colorspace is all the above plus, potentially, profile information;
    105104 * however at present libpng does not use the profile internally so it is only
    106105 * stored in the png_info struct (if iCCP is supported.)  The rendering intent
     
    221220   png_uint_32 chunk_name;    /* PNG_CHUNK() id of current chunk */
    222221   png_bytep prev_row;        /* buffer to save previous (unfiltered) row.
    223                                * This is a pointer into big_prev_row
     222                               * While reading this is a pointer into
     223                               * big_prev_row; while writing it is separately
     224                               * allocated if needed.
    224225                               */
    225226   png_bytep row_buf;         /* buffer to save current (unfiltered) row.
    226                                * This is a pointer into big_row_buf
     227                               * While reading, this is a pointer into
     228                               * big_row_buf; while writing it is separately
     229                               * allocated.
    227230                               */
    228 #ifdef PNG_WRITE_SUPPORTED
    229    png_bytep sub_row;         /* buffer to save "sub" row when filtering */
    230    png_bytep up_row;          /* buffer to save "up" row when filtering */
    231    png_bytep avg_row;         /* buffer to save "avg" row when filtering */
    232    png_bytep paeth_row;       /* buffer to save "Paeth" row when filtering */
     231#ifdef PNG_WRITE_FILTER_SUPPORTED
     232   png_bytep try_row;    /* buffer to save trial row when filtering */
     233   png_bytep tst_row;    /* buffer to save best trial row when filtering */
    233234#endif
    234235   png_size_t info_rowbytes;  /* Added in 1.5.4: cache of updated row bytes */
     
    348349#endif
    349350
    350 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    351    png_byte heuristic_method;        /* heuristic for row filter selection */
    352    png_byte num_prev_filters;        /* number of weights for previous rows */
    353    png_bytep prev_filters;           /* filter type(s) of previous row(s) */
    354    png_uint_16p filter_weights;      /* weight(s) for previous line(s) */
    355    png_uint_16p inv_filter_weights;  /* 1/weight(s) for previous line(s) */
    356    png_uint_16p filter_costs;        /* relative filter calculation cost */
    357    png_uint_16p inv_filter_costs;    /* 1/relative filter calculation cost */
    358 #endif
    359 
    360    /* Options */
     351/* Options */
    361352#ifdef PNG_SET_OPTION_SUPPORTED
    362353   png_byte options;           /* On/off state (up to 4 options) */
  • TabularUnified libpng/vendor/current/pngtest.c

    r1059 r1165  
    22/* pngtest.c - a simple test program to test libpng
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    470470
    471471/* Allocate memory.  For reasonable files, size should never exceed
    472  * 64K.  However, zlib may allocate more then 64K if you don't tell
     472 * 64K.  However, zlib may allocate more than 64K if you don't tell
    473473 * it not to.  See zconf.h and png.h for more information.  zlib does
    474474 * need to allocate exactly 64K, so whatever you call here must
     
    566566
    567567   /* Unlink the element from the list. */
     568   if (pinformation != NULL)
    568569   {
    569570      memory_infop *ppinfo = &pinformation;
     
    582583               the memory that is to be freed. */
    583584            memset(ptr, 0x55, pinfo->size);
    584             if (pinfo != NULL)
    585                free(pinfo);
     585            free(pinfo);
    586586            pinfo = NULL;
    587587            break;
     
    17021702   int ierror = 0;
    17031703
     1704   png_structp dummy_ptr;
     1705
    17041706   fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
    17051707   fprintf(STDERR, "   with zlib   version %s\n", ZLIB_VERSION);
     
    18321834#endif
    18331835#ifdef PNG_TIME_RFC1123_SUPPORTED
    1834          if (tIME_chunk_present != 0)
    1835             fprintf(STDERR, " tIME = %s\n", tIME_string);
    1836 
    1837          tIME_chunk_present = 0;
     1836            if (tIME_chunk_present != 0)
     1837               fprintf(STDERR, " tIME = %s\n", tIME_string);
     1838
     1839            tIME_chunk_present = 0;
    18381840#endif /* TIME_RFC1123 */
    18391841         }
     
    19951997      fprintf(STDERR, " libpng FAILS test\n");
    19961998
     1999   dummy_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
     2000   fprintf(STDERR, " Default limits:\n");
     2001   fprintf(STDERR, "  width_max  = %lu\n",
     2002      (unsigned long) png_get_user_width_max(dummy_ptr));
     2003   fprintf(STDERR, "  height_max = %lu\n",
     2004      (unsigned long) png_get_user_height_max(dummy_ptr));
     2005   if (png_get_chunk_cache_max(dummy_ptr) == 0)
     2006      fprintf(STDERR, "  cache_max  = unlimited\n");
     2007   else
     2008      fprintf(STDERR, "  cache_max  = %lu\n",
     2009         (unsigned long) png_get_chunk_cache_max(dummy_ptr));
     2010   if (png_get_chunk_malloc_max(dummy_ptr) == 0)
     2011      fprintf(STDERR, "  malloc_max = unlimited\n");
     2012   else
     2013      fprintf(STDERR, "  malloc_max = %lu\n",
     2014         (unsigned long) png_get_chunk_malloc_max(dummy_ptr));
     2015   png_destroy_read_struct(&dummy_ptr, NULL, NULL);
     2016
    19972017   return (int)(ierror != 0);
    19982018}
     
    20092029
    20102030/* Generate a compiler error if there is an old png.h in the search path. */
    2011 typedef png_libpng_version_1_6_16 Your_png_h_is_not_version_1_6_16;
     2031typedef png_libpng_version_1_6_18 Your_png_h_is_not_version_1_6_18;
  • TabularUnified libpng/vendor/current/pngtrans.c

    r1059 r1165  
    22/* pngtrans.c - transforms the data in a row (used by both readers and writers)
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    705705            for (; rp > png_ptr->row_buf; rp--)
    706706            {
    707               if (*rp >> padding != 0)
     707              if ((*rp >> padding) != 0)
    708708                 png_ptr->num_palette_max = 1;
    709709              padding = 0;
  • TabularUnified libpng/vendor/current/pngusr.dfa

    r922 r1165  
    99# them to be passed through to the build of pnglibconf.h), for example:
    1010#
    11 # @# define PNG_USER_WIDTH_MAX 1000000
    12 # @# define PNG_USER_HEIGHT_MAX 1000000
    13 # @# define PNG_USER_CHUNK_CACHE_MAX 128
    14 # @# define PNG_USER_CHUNK_MALLOC_MAX 8000000
     11# @# define PNG_USER_WIDTH_MAX 65535
     12# @# define PNG_USER_HEIGHT_MAX 65535
     13# @# define PNG_USER_CHUNK_CACHE_MAX 256
     14# @# define PNG_USER_CHUNK_MALLOC_MAX 640000
  • TabularUnified libpng/vendor/current/pngwrite.c

    r1059 r1165  
    22/* pngwrite.c - general routines to write a PNG file
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    9191   if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0)
    9292   {
    93    /* Write PNG signature */
    94    png_write_sig(png_ptr);
     93      /* Write PNG signature */
     94      png_write_sig(png_ptr);
    9595
    9696#ifdef PNG_MNG_FEATURES_SUPPORTED
    97    if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \
    98        png_ptr->mng_features_permitted != 0)
    99    {
    100       png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
    101       png_ptr->mng_features_permitted = 0;
    102    }
    103 #endif
    104 
    105    /* Write IHDR information. */
    106    png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
    107        info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
    108        info_ptr->filter_type,
     97      if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \
     98          png_ptr->mng_features_permitted != 0)
     99      {
     100         png_warning(png_ptr,
     101             "MNG features are not allowed in a PNG datastream");
     102         png_ptr->mng_features_permitted = 0;
     103      }
     104#endif
     105
     106      /* Write IHDR information. */
     107      png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
     108          info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
     109          info_ptr->filter_type,
    109110#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    110        info_ptr->interlace_type
     111          info_ptr->interlace_type
    111112#else
    112        0
    113 #endif
    114       );
    115 
    116    /* The rest of these check to see if the valid field has the appropriate
    117     * flag set, and if it does, writes the chunk.
    118     *
    119     * 1.6.0: COLORSPACE support controls the writing of these chunks too, and
    120     * the chunks will be written if the WRITE routine is there and information
    121     * is available in the COLORSPACE.  (See png_colorspace_sync_info in png.c
    122     * for where the valid flags get set.)
    123     *
    124     * Under certain circumstances the colorspace can be invalidated without
    125     * syncing the info_struct 'valid' flags; this happens if libpng detects and
    126     * error and calls png_error while the color space is being set, yet the
    127     * application continues writing the PNG.  So check the 'invalid' flag here
    128     * too.
    129     */
     113          0
     114#endif
     115         );
     116
     117      /* The rest of these check to see if the valid field has the appropriate
     118       * flag set, and if it does, writes the chunk.
     119       *
     120       * 1.6.0: COLORSPACE support controls the writing of these chunks too, and
     121       * the chunks will be written if the WRITE routine is there and
     122       * information * is available in the COLORSPACE. (See
     123       * png_colorspace_sync_info in png.c for where the valid flags get set.)
     124       *
     125       * Under certain circumstances the colorspace can be invalidated without
     126       * syncing the info_struct 'valid' flags; this happens if libpng detects
     127       * an error and calls png_error while the color space is being set, yet
     128       * the application continues writing the PNG.  So check the 'invalid'
     129       * flag here too.
     130       */
    130131#ifdef PNG_GAMMA_SUPPORTED
    131132#  ifdef PNG_WRITE_gAMA_SUPPORTED
     
    138139
    139140#ifdef PNG_COLORSPACE_SUPPORTED
    140    /* Write only one of sRGB or an ICC profile.  If a profile was supplied
    141     * and it matches one of the known sRGB ones issue a warning.
    142     */
     141      /* Write only one of sRGB or an ICC profile.  If a profile was supplied
     142       * and it matches one of the known sRGB ones issue a warning.
     143       */
    143144#  ifdef PNG_WRITE_iCCP_SUPPORTED
    144       if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
    145           (info_ptr->valid & PNG_INFO_iCCP) != 0)
    146       {
    147 #        ifdef PNG_WRITE_sRGB_SUPPORTED
    148             if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
    149                png_app_warning(png_ptr,
    150                   "profile matches sRGB but writing iCCP instead");
    151 #        endif
    152 
    153          png_write_iCCP(png_ptr, info_ptr->iccp_name,
    154             info_ptr->iccp_profile);
    155       }
     145         if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
     146             (info_ptr->valid & PNG_INFO_iCCP) != 0)
     147         {
     148#    ifdef PNG_WRITE_sRGB_SUPPORTED
     149               if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
     150                  png_app_warning(png_ptr,
     151                     "profile matches sRGB but writing iCCP instead");
     152#     endif
     153
     154            png_write_iCCP(png_ptr, info_ptr->iccp_name,
     155               info_ptr->iccp_profile);
     156         }
    156157#     ifdef PNG_WRITE_sRGB_SUPPORTED
    157158         else
     
    160161
    161162#  ifdef PNG_WRITE_sRGB_SUPPORTED
    162       if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
    163           (info_ptr->valid & PNG_INFO_sRGB) != 0)
    164          png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent);
     163         if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
     164             (info_ptr->valid & PNG_INFO_sRGB) != 0)
     165            png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent);
    165166#  endif /* WRITE_sRGB */
    166167#endif /* COLORSPACE */
    167168
    168169#ifdef PNG_WRITE_sBIT_SUPPORTED
    169    if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
    170       png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
     170         if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
     171            png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
    171172#endif
    172173
    173174#ifdef PNG_COLORSPACE_SUPPORTED
    174175#  ifdef PNG_WRITE_cHRM_SUPPORTED
    175       if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
    176          (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 &&
    177          (info_ptr->valid & PNG_INFO_cHRM) != 0)
    178          png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy);
     176         if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
     177             (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 &&
     178             (info_ptr->valid & PNG_INFO_cHRM) != 0)
     179            png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy);
    179180#  endif
    180181#endif
    181182
    182183#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
    183       write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR);
     184         write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR);
    184185#endif
    185186
     
    217218          info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
    218219      {
    219          int j;
    220          for (j = 0; j<(int)info_ptr->num_trans; j++)
     220         int j, jend;
     221
     222         jend = info_ptr->num_trans;
     223         if (jend > PNG_MAX_PALETTE_LENGTH)
     224            jend = PNG_MAX_PALETTE_LENGTH;
     225
     226         for (j = 0; j<jend; ++j)
    221227            info_ptr->trans_alpha[j] =
    222228               (png_byte)(255 - info_ptr->trans_alpha[j]);
     
    539545       * are errors during development.
    540546       */
    541 #if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
     547#if PNG_RELEASE_BUILD
    542548      png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;
    543549#endif
     
    639645         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
    640646         {
    641             *(rp)     = (png_byte)((*rp       - *(rp + 1)) & 0xff);
    642             *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff);
     647            *(rp)     = (png_byte)(*rp       - *(rp + 1));
     648            *(rp + 2) = (png_byte)(*(rp + 2) - *(rp + 1));
    643649         }
    644650      }
     
    666672            png_uint_32 red  = (png_uint_32)((s0 - s1) & 0xffffL);
    667673            png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
    668             *(rp    ) = (png_byte)((red >> 8) & 0xff);
    669             *(rp + 1) = (png_byte)(red & 0xff);
    670             *(rp + 4) = (png_byte)((blue >> 8) & 0xff);
    671             *(rp + 5) = (png_byte)(blue & 0xff);
     674            *(rp    ) = (png_byte)(red >> 8);
     675            *(rp + 1) = (png_byte)red;
     676            *(rp + 4) = (png_byte)(blue >> 8);
     677            *(rp + 5) = (png_byte)blue;
    672678         }
    673679      }
     
    850856    */
    851857   if (row_info.pixel_depth != png_ptr->pixel_depth ||
    852       row_info.pixel_depth != png_ptr->transformed_pixel_depth)
     858       row_info.pixel_depth != png_ptr->transformed_pixel_depth)
    853859      png_error(png_ptr, "internal write transform logic error");
    854860
     
    918924#endif /* WRITE_FLUSH */
    919925
    920 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    921 static void png_reset_filter_heuristics(png_structrp png_ptr);/* forward decl */
    922 #endif
    923 
    924926/* Free any memory used in png_ptr struct without freeing the struct itself. */
    925927static void
     
    938940#ifdef PNG_WRITE_FILTER_SUPPORTED
    939941   png_free(png_ptr, png_ptr->prev_row);
    940    png_free(png_ptr, png_ptr->sub_row);
    941    png_free(png_ptr, png_ptr->up_row);
    942    png_free(png_ptr, png_ptr->avg_row);
    943    png_free(png_ptr, png_ptr->paeth_row);
     942   png_free(png_ptr, png_ptr->try_row);
     943   png_free(png_ptr, png_ptr->tst_row);
    944944   png_ptr->prev_row = NULL;
    945    png_ptr->sub_row = NULL;
    946    png_ptr->up_row = NULL;
    947    png_ptr->avg_row = NULL;
    948    png_ptr->paeth_row = NULL;
    949 #endif
    950 
    951 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    952    /* Use this to save a little code space, it doesn't free the filter_costs */
    953    png_reset_filter_heuristics(png_ptr);
    954    png_free(png_ptr, png_ptr->filter_costs);
    955    png_free(png_ptr, png_ptr->inv_filter_costs);
    956    png_ptr->filter_costs = NULL;
    957    png_ptr->inv_filter_costs = NULL;
     945   png_ptr->try_row = NULL;
     946   png_ptr->tst_row = NULL;
    958947#endif
    959948
     
    10451034      }
    10461035
     1036#ifdef PNG_WRITE_FILTER_SUPPORTED
    10471037      /* If we have allocated the row_buf, this means we have already started
    10481038       * with the image and we should have allocated all of the filter buffers
     
    10511041       * will be missing the data in the previous row.  If an application
    10521042       * wants to start and stop using particular filters during compression,
    1053        * it should start out with all of the filters, and then add and
    1054        * remove them after the start of compression.
     1043       * it should start out with all of the filters, and then remove them
     1044       * or add them back after the start of compression.
     1045       *
     1046       * NOTE: this is a nasty constraint on the code, because it means that the
     1047       * prev_row buffer must be maintained even if there are currently no
     1048       * 'prev_row' requiring filters active.
    10551049       */
    10561050      if (png_ptr->row_buf != NULL)
    10571051      {
    1058 #ifdef PNG_WRITE_FILTER_SUPPORTED
    1059          if ((png_ptr->do_filter & PNG_FILTER_SUB) != 0 &&
    1060              png_ptr->sub_row == NULL)
     1052         int num_filters;
     1053         png_alloc_size_t buf_size;
     1054
     1055         /* Repeat the checks in png_write_start_row; 1 pixel high or wide
     1056          * images cannot benefit from certain filters.  If this isn't done here
     1057          * the check below will fire on 1 pixel high images.
     1058          */
     1059         if (png_ptr->height == 1)
     1060            filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
     1061
     1062         if (png_ptr->width == 1)
     1063            filters &= ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH);
     1064
     1065         if ((filters & (PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH)) != 0
     1066            && png_ptr->prev_row == NULL)
    10611067         {
    1062             png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
    1063                 (png_ptr->rowbytes + 1));
    1064             png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
     1068            /* This is the error case, however it is benign - the previous row
     1069             * is not available so the filter can't be used.  Just warn here.
     1070             */
     1071            png_app_warning(png_ptr,
     1072               "png_set_filter: UP/AVG/PAETH cannot be added after start");
     1073            filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
    10651074         }
    10661075
    1067          if ((png_ptr->do_filter & PNG_FILTER_UP) != 0 &&
    1068               png_ptr->up_row == NULL)
     1076         num_filters = 0;
     1077
     1078         if (filters & PNG_FILTER_SUB)
     1079            num_filters++;
     1080
     1081         if (filters & PNG_FILTER_UP)
     1082            num_filters++;
     1083
     1084         if (filters & PNG_FILTER_AVG)
     1085            num_filters++;
     1086
     1087         if (filters & PNG_FILTER_PAETH)
     1088            num_filters++;
     1089
     1090         /* Allocate needed row buffers if they have not already been
     1091          * allocated.
     1092          */
     1093         buf_size = PNG_ROWBYTES(png_ptr->usr_channels * png_ptr->usr_bit_depth,
     1094             png_ptr->width) + 1;
     1095
     1096         if (png_ptr->try_row == NULL)
     1097            png_ptr->try_row = png_voidcast(png_bytep,
     1098               png_malloc(png_ptr, buf_size));
     1099
     1100         if (num_filters > 1)
    10691101         {
    1070             if (png_ptr->prev_row == NULL)
    1071             {
    1072                png_warning(png_ptr, "Can't add Up filter after starting");
    1073                png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
    1074                    ~PNG_FILTER_UP);
    1075             }
    1076 
    1077             else
    1078             {
    1079                png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
    1080                    (png_ptr->rowbytes + 1));
    1081                png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
    1082             }
     1102            if (png_ptr->tst_row == NULL)
     1103               png_ptr->tst_row = png_voidcast(png_bytep,
     1104                  png_malloc(png_ptr, buf_size));
    10831105         }
    1084 
    1085          if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0 &&
    1086               png_ptr->avg_row == NULL)
    1087          {
    1088             if (png_ptr->prev_row == NULL)
    1089             {
    1090                png_warning(png_ptr, "Can't add Average filter after starting");
    1091                png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
    1092                    ~PNG_FILTER_AVG);
    1093             }
    1094 
    1095             else
    1096             {
    1097                png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
    1098                    (png_ptr->rowbytes + 1));
    1099                png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
    1100             }
    1101          }
    1102 
    1103          if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0 &&
    1104              png_ptr->paeth_row == NULL)
    1105          {
    1106             if (png_ptr->prev_row == NULL)
    1107             {
    1108                png_warning(png_ptr, "Can't add Paeth filter after starting");
    1109                png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
    1110             }
    1111 
    1112             else
    1113             {
    1114                png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
    1115                    (png_ptr->rowbytes + 1));
    1116                png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
    1117             }
    1118          }
    1119 
    1120          if (png_ptr->do_filter == PNG_NO_FILTERS)
    1121 #endif /* WRITE_FILTER */
    1122             png_ptr->do_filter = PNG_FILTER_NONE;
    1123       }
     1106      }
     1107      png_ptr->do_filter = (png_byte)filters;
     1108#endif
    11241109   }
    11251110   else
     
    11271112}
    11281113
    1129 /* This allows us to influence the way in which libpng chooses the "best"
    1130  * filter for the current scanline.  While the "minimum-sum-of-absolute-
    1131  * differences metric is relatively fast and effective, there is some
    1132  * question as to whether it can be improved upon by trying to keep the
    1133  * filtered data going to zlib more consistent, hopefully resulting in
    1134  * better compression.
    1135  */
    1136 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED      /* GRR 970116 */
    1137 /* Convenience reset API. */
    1138 static void
    1139 png_reset_filter_heuristics(png_structrp png_ptr)
    1140 {
    1141    /* Clear out any old values in the 'weights' - this must be done because if
    1142     * the app calls set_filter_heuristics multiple times with different
    1143     * 'num_weights' values we would otherwise potentially have wrong sized
    1144     * arrays.
    1145     */
    1146    png_ptr->num_prev_filters = 0;
    1147    png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
    1148    if (png_ptr->prev_filters != NULL)
    1149    {
    1150       png_bytep old = png_ptr->prev_filters;
    1151       png_ptr->prev_filters = NULL;
    1152       png_free(png_ptr, old);
    1153    }
    1154    if (png_ptr->filter_weights != NULL)
    1155    {
    1156       png_uint_16p old = png_ptr->filter_weights;
    1157       png_ptr->filter_weights = NULL;
    1158       png_free(png_ptr, old);
    1159    }
    1160 
    1161    if (png_ptr->inv_filter_weights != NULL)
    1162    {
    1163       png_uint_16p old = png_ptr->inv_filter_weights;
    1164       png_ptr->inv_filter_weights = NULL;
    1165       png_free(png_ptr, old);
    1166    }
    1167 
    1168    /* Leave the filter_costs - this array is fixed size. */
    1169 }
    1170 
    1171 static int
    1172 png_init_filter_heuristics(png_structrp png_ptr, int heuristic_method,
    1173    int num_weights)
    1174 {
    1175    if (png_ptr == NULL)
    1176       return 0;
    1177 
    1178    /* Clear out the arrays */
    1179    png_reset_filter_heuristics(png_ptr);
    1180 
    1181    /* Check arguments; the 'reset' function makes the correct settings for the
    1182     * unweighted case, but we must handle the weight case by initializing the
    1183     * arrays for the caller.
    1184     */
    1185    if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    1186    {
    1187       int i;
    1188 
    1189       if (num_weights > 0)
    1190       {
    1191          png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
    1192              (png_uint_32)((sizeof (png_byte)) * num_weights));
    1193 
    1194          /* To make sure that the weighting starts out fairly */
    1195          for (i = 0; i < num_weights; i++)
    1196          {
    1197             png_ptr->prev_filters[i] = 255;
    1198          }
    1199 
    1200          png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
    1201              (png_uint_32)((sizeof (png_uint_16)) * num_weights));
    1202 
    1203          png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
    1204              (png_uint_32)((sizeof (png_uint_16)) * num_weights));
    1205 
    1206          for (i = 0; i < num_weights; i++)
    1207          {
    1208             png_ptr->inv_filter_weights[i] =
    1209             png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
    1210          }
    1211 
    1212          /* Safe to set this now */
    1213          png_ptr->num_prev_filters = (png_byte)num_weights;
    1214       }
    1215 
    1216       /* If, in the future, there are other filter methods, this would
    1217        * need to be based on png_ptr->filter.
    1218        */
    1219       if (png_ptr->filter_costs == NULL)
    1220       {
    1221          png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
    1222              (png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST));
    1223 
    1224          png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
    1225              (png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST));
    1226       }
    1227 
    1228       for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
    1229       {
    1230          png_ptr->inv_filter_costs[i] =
    1231          png_ptr->filter_costs[i] = PNG_COST_FACTOR;
    1232       }
    1233 
    1234       /* All the arrays are inited, safe to set this: */
    1235       png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_WEIGHTED;
    1236 
    1237       /* Return the 'ok' code. */
    1238       return 1;
    1239    }
    1240    else if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT ||
    1241       heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
    1242    {
    1243       return 1;
    1244    }
    1245    else
    1246    {
    1247       png_warning(png_ptr, "Unknown filter heuristic method");
    1248       return 0;
    1249    }
    1250 }
    1251 
     1114#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */
    12521115/* Provide floating and fixed point APIs */
    12531116#ifdef PNG_FLOATING_POINT_SUPPORTED
     
    12571120    png_const_doublep filter_costs)
    12581121{
    1259    png_debug(1, "in png_set_filter_heuristics");
    1260 
    1261    /* The internal API allocates all the arrays and ensures that the elements of
    1262     * those arrays are set to the default value.
    1263     */
    1264    if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0)
    1265       return;
    1266 
    1267    /* If using the weighted method copy in the weights. */
    1268    if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    1269    {
    1270       int i;
    1271       for (i = 0; i < num_weights; i++)
    1272       {
    1273          if (filter_weights[i] <= 0.0)
    1274          {
    1275             png_ptr->inv_filter_weights[i] =
    1276             png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
    1277          }
    1278 
    1279          else
    1280          {
    1281             png_ptr->inv_filter_weights[i] =
    1282                 (png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5);
    1283 
    1284             png_ptr->filter_weights[i] =
    1285                 (png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5);
    1286          }
    1287       }
    1288 
    1289       /* Here is where we set the relative costs of the different filters.  We
    1290        * should take the desired compression level into account when setting
    1291        * the costs, so that Paeth, for instance, has a high relative cost at low
    1292        * compression levels, while it has a lower relative cost at higher
    1293        * compression settings.  The filter types are in order of increasing
    1294        * relative cost, so it would be possible to do this with an algorithm.
    1295        */
    1296       for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0)
    1297       {
    1298          png_ptr->inv_filter_costs[i] =
    1299              (png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5);
    1300 
    1301          png_ptr->filter_costs[i] =
    1302              (png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5);
    1303       }
    1304    }
     1122   PNG_UNUSED(png_ptr)
     1123   PNG_UNUSED(heuristic_method)
     1124   PNG_UNUSED(num_weights)
     1125   PNG_UNUSED(filter_weights)
     1126   PNG_UNUSED(filter_costs)
    13051127}
    13061128#endif /* FLOATING_POINT */
     
    13121134    png_const_fixed_point_p filter_costs)
    13131135{
    1314    png_debug(1, "in png_set_filter_heuristics_fixed");
    1315 
    1316    /* The internal API allocates all the arrays and ensures that the elements of
    1317     * those arrays are set to the default value.
    1318     */
    1319    if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0)
    1320       return;
    1321 
    1322    /* If using the weighted method copy in the weights. */
    1323    if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    1324    {
    1325       int i;
    1326       for (i = 0; i < num_weights; i++)
    1327       {
    1328          if (filter_weights[i] <= 0)
    1329          {
    1330             png_ptr->inv_filter_weights[i] =
    1331             png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
    1332          }
    1333 
    1334          else
    1335          {
    1336             png_ptr->inv_filter_weights[i] = (png_uint_16)
    1337                ((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1);
    1338 
    1339             png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR*
    1340                PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]);
    1341          }
    1342       }
    1343 
    1344       /* Here is where we set the relative costs of the different filters.  We
    1345        * should take the desired compression level into account when setting
    1346        * the costs, so that Paeth, for instance, has a high relative cost at low
    1347        * compression levels, while it has a lower relative cost at higher
    1348        * compression settings.  The filter types are in order of increasing
    1349        * relative cost, so it would be possible to do this with an algorithm.
    1350        */
    1351       for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
    1352          if (filter_costs[i] >= PNG_FP_1)
    1353       {
    1354          png_uint_32 tmp;
    1355 
    1356          /* Use a 32 bit unsigned temporary here because otherwise the
    1357           * intermediate value will be a 32 bit *signed* integer (ANSI rules)
    1358           * and this will get the wrong answer on division.
    1359           */
    1360          tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2);
    1361          tmp /= filter_costs[i];
    1362 
    1363          png_ptr->inv_filter_costs[i] = (png_uint_16)tmp;
    1364 
    1365          tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF;
    1366          tmp /= PNG_FP_1;
    1367 
    1368          png_ptr->filter_costs[i] = (png_uint_16)tmp;
    1369       }
    1370    }
     1136   PNG_UNUSED(png_ptr)
     1137   PNG_UNUSED(heuristic_method)
     1138   PNG_UNUSED(num_weights)
     1139   PNG_UNUSED(filter_weights)
     1140   PNG_UNUSED(filter_costs)
    13711141}
    13721142#endif /* FIXED_POINT */
    13731143#endif /* WRITE_WEIGHTED_FILTER */
    13741144
     1145#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
    13751146void PNGAPI
    13761147png_set_compression_level(png_structrp png_ptr, int level)
     
    14181189      return;
    14191190
    1420    /* Prior to 1.6.0 this would warn but then set the window_bits value, this
    1421     * meant that negative window bits values could be selected which would cause
     1191   /* Prior to 1.6.0 this would warn but then set the window_bits value. This
     1192    * meant that negative window bits values could be selected that would cause
    14221193    * libpng to write a non-standard PNG file with raw deflate or gzip
    14231194    * compressed IDAT or ancillary chunks.  Such files can be read and there is
     
    14551226   png_ptr->zlib_method = method;
    14561227}
     1228#endif /* WRITE_CUSTOMIZE_COMPRESSION */
    14571229
    14581230/* The following were added to libpng-1.5.4 */
     
    16151387    */
    16161388   if ((transforms & (PNG_TRANSFORM_STRIP_FILLER_AFTER|
    1617       PNG_TRANSFORM_STRIP_FILLER_BEFORE)) != 0)
     1389       PNG_TRANSFORM_STRIP_FILLER_BEFORE)) != 0)
    16181390   {
    16191391#ifdef PNG_WRITE_FILLER_SUPPORTED
     
    16221394         if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)
    16231395            png_app_error(png_ptr,
    1624                "PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported");
     1396                "PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported");
    16251397
    16261398         /* Continue if ignored - this is the pre-1.6.10 behavior */
     
    16811453
    16821454#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
    1683 #ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */
     1455# ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */
    16841456/* Initialize the write structure - general purpose utility. */
    16851457static int
     
    16871459{
    16881460   png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image,
    1689           png_safe_error, png_safe_warning);
     1461       png_safe_error, png_safe_warning);
    16901462
    16911463   if (png_ptr != NULL)
     
    16961468      {
    16971469         png_controlp control = png_voidcast(png_controlp,
    1698             png_malloc_warn(png_ptr, (sizeof *control)));
     1470             png_malloc_warn(png_ptr, (sizeof *control)));
    16991471
    17001472         if (control != NULL)
     
    17431515{
    17441516   png_image_write_control *display = png_voidcast(png_image_write_control*,
    1745       argument);
     1517       argument);
    17461518   png_imagep image = display->image;
    17471519   png_structrp png_ptr = image->opaque->png_ptr;
    17481520
    17491521   png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,
    1750       display->first_row);
     1522       display->first_row);
    17511523   png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
    17521524   png_uint_16p row_end;
     
    17571529   if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
    17581530   {
    1759 #     ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
    1760          if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
    1761          {
    1762             aindex = -1;
    1763             ++input_row; /* To point to the first component */
    1764             ++output_row;
    1765          }
    1766 
     1531#   ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
     1532      if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
     1533      {
     1534         aindex = -1;
     1535         ++input_row; /* To point to the first component */
     1536         ++output_row;
     1537      }
    17671538         else
     1539            aindex = channels;
     1540#     else
     1541         aindex = channels;
    17681542#     endif
    1769          aindex = channels;
    17701543   }
    17711544
     
    18491622 * be scaled in the range 0..255*65535, so include that scaling here.
    18501623 */
    1851 #define UNP_RECIPROCAL(alpha) ((((0xffff*0xff)<<7)+(alpha>>1))/alpha)
     1624#   define UNP_RECIPROCAL(alpha) ((((0xffff*0xff)<<7)+(alpha>>1))/alpha)
    18521625
    18531626static png_byte
     
    19001673{
    19011674   png_image_write_control *display = png_voidcast(png_image_write_control*,
    1902       argument);
     1675       argument);
    19031676   png_imagep image = display->image;
    19041677   png_structrp png_ptr = image->opaque->png_ptr;
    19051678
    19061679   png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,
    1907       display->first_row);
     1680       display->first_row);
    19081681   png_bytep output_row = png_voidcast(png_bytep, display->local_row);
    19091682   png_uint_32 y = image->height;
     
    19151688      int aindex;
    19161689
    1917 #     ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
    1918          if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
    1919          {
    1920             aindex = -1;
    1921             ++input_row; /* To point to the first component */
    1922             ++output_row;
    1923          }
    1924 
    1925          else
    1926 #     endif
    1927          aindex = channels;
     1690#   ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
     1691      if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
     1692      {
     1693         aindex = -1;
     1694         ++input_row; /* To point to the first component */
     1695         ++output_row;
     1696      }
     1697
     1698      else
     1699#   endif
     1700      aindex = channels;
    19281701
    19291702      /* Use row_end in place of a loop counter: */
     
    19591732
    19601733         png_write_row(png_ptr, png_voidcast(png_const_bytep,
    1961             display->local_row));
     1734             display->local_row));
    19621735         input_row += display->row_bytes/(sizeof (png_uint_16));
    19631736      } /* while y */
     
    19981771   const void *cmap = display->colormap;
    19991772   const int entries = image->colormap_entries > 256 ? 256 :
    2000       (int)image->colormap_entries;
     1773       (int)image->colormap_entries;
    20011774
    20021775   /* NOTE: the caller must check for cmap != NULL and entries != 0 */
     
    20041777   const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
    20051778
    2006 if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
     1779 if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
    20071780      defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
    20081781      const int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
    2009          (format & PNG_FORMAT_FLAG_ALPHA) != 0;
    2010 else
     1782          (format & PNG_FORMAT_FLAG_ALPHA) != 0;
     1783 else
    20111784#     define afirst 0
    2012 endif
    2013 
    2014 ifdef PNG_FORMAT_BGR_SUPPORTED
     1785 endif
     1786
     1787 ifdef PNG_FORMAT_BGR_SUPPORTED
    20151788      const int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;
    2016 else
     1789 else
    20171790#     define bgr 0
    2018 endif
     1791 endif
    20191792
    20201793   int i, num_trans;
     
    20411814            {
    20421815               palette[i].blue = (png_byte)PNG_sRGB_FROM_LINEAR(255 *
    2043                   entry[(2 ^ bgr)]);
     1816                   entry[(2 ^ bgr)]);
    20441817               palette[i].green = (png_byte)PNG_sRGB_FROM_LINEAR(255 *
    2045                   entry[1]);
     1818                   entry[1]);
    20461819               palette[i].red = (png_byte)PNG_sRGB_FROM_LINEAR(255 *
    2047                   entry[bgr]);
     1820                   entry[bgr]);
    20481821            }
    20491822
     
    21211894   }
    21221895
    2123 ifdef afirst
     1896 ifdef afirst
    21241897#     undef afirst
    2125 endif
    2126 ifdef bgr
     1898 endif
     1899 ifdef bgr
    21271900#     undef bgr
    2128 endif
     1901 endif
    21291902
    21301903   png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette,
     
    21541927   int write_16bit = linear && !colormap && (display->convert_to_8bit == 0);
    21551928
    2156 ifdef PNG_BENIGN_ERRORS_SUPPORTED
     1929 ifdef PNG_BENIGN_ERRORS_SUPPORTED
    21571930      /* Make sure we error out on any bad situation */
    21581931      png_set_benign_errors(png_ptr, 0/*error*/);
    2159 endif
     1932 endif
    21601933
    21611934   /* Default the 'row_stride' parameter if required. */
     
    22362009   }
    22372010
    2238 ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
     2011 ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
    22392012      if ((format & PNG_FORMAT_FLAG_BGR) != 0)
    22402013      {
     
    22432016         format &= ~PNG_FORMAT_FLAG_BGR;
    22442017      }
    2245 endif
    2246 
    2247 ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
     2018 endif
     2019
     2020 ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
    22482021      if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)
    22492022      {
     
    22522025         format &= ~PNG_FORMAT_FLAG_AFIRST;
    22532026      }
    2254 endif
     2027 endif
    22552028
    22562029   /* If there are 16 or fewer color-map entries we wrote a lower bit depth
     
    22882061       * total (user) time on a heavily loaded system.
    22892062       */
     2063#   ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
    22902064      png_set_compression_level(png_ptr, 3);
     2065#   endif
    22912066   }
    22922067
     
    24512226      return 0;
    24522227}
    2453 #endif /* STDIO */
     2228# endif /* STDIO */
    24542229#endif /* SIMPLIFIED_WRITE */
    24552230#endif /* WRITE */
  • TabularUnified libpng/vendor/current/pngwtran.c

    r1059 r1165  
    22/* pngwtran.c - transforms the data in a row for PNG writers
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    7272         {
    7373            png_bytep sp, dp;
    74             int shift, v;
     74            unsigned int shift;
     75            int v;
    7576            png_uint_32 i;
    7677            png_uint_32 row_width = row_info->width;
     
    111112         {
    112113            png_bytep sp, dp;
    113             int shift, v;
     114            unsigned int shift;
     115            int v;
    114116            png_uint_32 i;
    115117            png_uint_32 row_width = row_info->width;
     
    423425               */
    424426               sp+=3; dp = sp;
    425                *(dp++) = (png_byte)(255 - *(sp++));
     427               *dp = (png_byte)(255 - *(sp++));
    426428            }
    427429         }
     
    447449               sp+=6; dp = sp;
    448450               *(dp++) = (png_byte)(255 - *(sp++));
    449                *(dp++) = (png_byte)(255 - *(sp++));
     451               *dp    = (png_byte)(255 - *(sp++));
    450452            }
    451453         }
     
    485487               sp+=2; dp = sp;
    486488               *(dp++) = (png_byte)(255 - *(sp++));
    487                *(dp++) = (png_byte)(255 - *(sp++));
     489               *dp    = (png_byte)(255 - *(sp++));
    488490            }
    489491         }
  • TabularUnified libpng/vendor/current/pngwutil.c

    r1059 r1165  
    22/* pngwutil.c - utilities to write a PNG file
    33 *
    4  * Last changed in libpng 1.6.15 [November 20, 2014]
    5  * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.6.18 [July 23, 2015]
     5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    2424png_save_uint_32(png_bytep buf, png_uint_32 i)
    2525{
    26    buf[0] = (png_byte)((i >> 24) & 0xff);
    27    buf[1] = (png_byte)((i >> 16) & 0xff);
    28    buf[2] = (png_byte)((i >> 8) & 0xff);
    29    buf[3] = (png_byte)(i & 0xff);
     26   buf[0] = (png_byte)(i >> 24);
     27   buf[1] = (png_byte)(i >> 16);
     28   buf[2] = (png_byte)(i >> 8);
     29   buf[3] = (png_byte)(i     );
    3030}
    3131
     
    3737png_save_uint_16(png_bytep buf, unsigned int i)
    3838{
    39    buf[0] = (png_byte)((i >> 8) & 0xff);
    40    buf[1] = (png_byte)(i & 0xff);
     39   buf[0] = (png_byte)(i >> 8);
     40   buf[1] = (png_byte)(i     );
    4141}
    4242#endif
     
    309309      (void)png_safecat(msg, (sizeof msg), 10, " using zstream");
    310310#endif
    311 #if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
     311#if PNG_RELEASE_BUILD
    312312         png_warning(png_ptr, msg);
    313313
     
    696696   while (*key && key_len < 79)
    697697   {
    698       png_byte ch = (png_byte)(0xff & *key++);
     698      png_byte ch = (png_byte)*key++;
    699699
    700700      if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))
     
    872872#endif
    873873
    874    /* Save the relevent information */
     874   /* Save the relevant information */
    875875   png_ptr->bit_depth = (png_byte)bit_depth;
    876876   png_ptr->color_type = (png_byte)color_type;
     
    17661766
    17671767   else
    1768       png_write_chunk_data(png_ptr, (png_const_bytep)text, comp.input_len);
     1768      png_write_chunk_data(png_ptr, (png_const_bytep)text, comp.output_len);
    17691769
    17701770   png_write_chunk_end(png_ptr);
     
    19621962   int usr_pixel_depth;
    19631963
     1964#ifdef PNG_WRITE_FILTER_SUPPORTED
     1965   png_byte filters;
     1966#endif
     1967
    19641968   png_debug(1, "in png_write_start_row");
    19651969
     
    19721976
    19731977   /* Set up row buffer */
    1974    png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size);
     1978   png_ptr->row_buf = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));
    19751979
    19761980   png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
    19771981
    19781982#ifdef PNG_WRITE_FILTER_SUPPORTED
    1979    /* Set up filtering buffer, if using this filter */
    1980    if (png_ptr->do_filter & PNG_FILTER_SUB)
    1981    {
    1982       png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
    1983 
    1984       png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
    1985    }
    1986 
    1987    /* We only need to keep the previous row if we are using one of these. */
    1988    if ((png_ptr->do_filter &
    1989       (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0)
    1990    {
    1991       /* Set up previous row buffer */
    1992       png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size);
    1993 
    1994       if ((png_ptr->do_filter & PNG_FILTER_UP) != 0)
    1995       {
    1996          png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
    1997             png_ptr->rowbytes + 1);
    1998 
    1999          png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
    2000       }
    2001 
    2002       if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0)
    2003       {
    2004          png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
    2005              png_ptr->rowbytes + 1);
    2006 
    2007          png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
    2008       }
    2009 
    2010       if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0)
    2011       {
    2012          png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
    2013              png_ptr->rowbytes + 1);
    2014 
    2015          png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
    2016       }
    2017    }
     1983   filters = png_ptr->do_filter;
     1984
     1985   if (png_ptr->height == 1)
     1986      filters &= 0xff & ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
     1987
     1988   if (png_ptr->width == 1)
     1989      filters &= 0xff & ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH);
     1990
     1991   if (filters == 0)
     1992      filters = PNG_FILTER_NONE;
     1993
     1994   png_ptr->do_filter = filters;
     1995
     1996   if (((filters & (PNG_FILTER_SUB | PNG_FILTER_UP | PNG_FILTER_AVG |
     1997       PNG_FILTER_PAETH)) != 0) && png_ptr->try_row == NULL)
     1998   {
     1999      int num_filters = 0;
     2000
     2001      png_ptr->try_row = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));
     2002
     2003      if (filters & PNG_FILTER_SUB)
     2004         num_filters++;
     2005
     2006      if (filters & PNG_FILTER_UP)
     2007         num_filters++;
     2008
     2009      if (filters & PNG_FILTER_AVG)
     2010         num_filters++;
     2011
     2012      if (filters & PNG_FILTER_PAETH)
     2013         num_filters++;
     2014
     2015      if (num_filters > 1)
     2016         png_ptr->tst_row = png_voidcast(png_bytep, png_malloc(png_ptr,
     2017             buf_size));
     2018   }
     2019
     2020   /* We only need to keep the previous row if we are using one of the following
     2021    * filters.
     2022    */
     2023   if ((filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0)
     2024      png_ptr->prev_row = png_voidcast(png_bytep,
     2025         png_calloc(png_ptr, buf_size));
    20182026#endif /* WRITE_FILTER */
    20192027
     
    21612169            png_bytep sp;
    21622170            png_bytep dp;
    2163             int shift;
     2171            unsigned int shift;
    21642172            int d;
    21652173            int value;
     
    21992207            png_bytep sp;
    22002208            png_bytep dp;
    2201             int shift;
     2209            unsigned int shift;
    22022210            int d;
    22032211            int value;
     
    22362244            png_bytep sp;
    22372245            png_bytep dp;
    2238             int shift;
     2246            unsigned int shift;
    22392247            int d;
    22402248            int value;
     
    23112319#endif
    23122320
     2321
    23132322/* This filters the row, chooses which filter to use, if it has not already
    23142323 * been specified by the application, and then writes the row out with the
    23152324 * chosen filter.
    23162325 */
    2317 static void
     2326static void /* PRIVATE */
    23182327png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,
    23192328   png_size_t row_bytes);
    23202329
    2321 #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
    2322 #define PNG_HISHIFT 10
    2323 #define PNG_LOMASK ((png_uint_32)0xffffL)
    2324 #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
     2330#ifdef PNG_WRITE_FILTER_SUPPORTED
     2331static png_size_t /* PRIVATE */
     2332png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
     2333    const png_size_t row_bytes, const png_size_t lmins)
     2334{
     2335   png_bytep rp, dp, lp;
     2336   png_size_t i;
     2337   png_size_t sum = 0;
     2338   int v;
     2339
     2340   png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;
     2341
     2342   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp;
     2343        i++, rp++, dp++)
     2344   {
     2345      v = *dp = *rp;
     2346      sum += (v < 128) ? v : 256 - v;
     2347   }
     2348
     2349   for (lp = png_ptr->row_buf + 1; i < row_bytes;
     2350      i++, rp++, lp++, dp++)
     2351   {
     2352      v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
     2353      sum += (v < 128) ? v : 256 - v;
     2354
     2355      if (sum > lmins)  /* We are already worse, don't continue. */
     2356        break;
     2357   }
     2358
     2359   return (sum);
     2360}
     2361
     2362static png_size_t /* PRIVATE */
     2363png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
     2364    const png_size_t lmins)
     2365{
     2366   png_bytep rp, dp, pp;
     2367   png_size_t i;
     2368   png_size_t sum = 0;
     2369   int v;
     2370
     2371   png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;
     2372
     2373   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
     2374       pp = png_ptr->prev_row + 1; i < row_bytes;
     2375       i++, rp++, pp++, dp++)
     2376   {
     2377      v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
     2378      sum += (v < 128) ? v : 256 - v;
     2379
     2380      if (sum > lmins)  /* We are already worse, don't continue. */
     2381        break;
     2382   }
     2383
     2384   return (sum);
     2385}
     2386
     2387static png_size_t /* PRIVATE */
     2388png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
     2389      const png_size_t row_bytes, const png_size_t lmins)
     2390{
     2391   png_bytep rp, dp, pp, lp;
     2392   png_uint_32 i;
     2393   png_size_t sum = 0;
     2394   int v;
     2395
     2396   png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG;
     2397
     2398   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
     2399        pp = png_ptr->prev_row + 1; i < bpp; i++)
     2400   {
     2401      v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
     2402
     2403      sum += (v < 128) ? v : 256 - v;
     2404   }
     2405
     2406   for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)
     2407   {
     2408      v = *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
     2409          & 0xff);
     2410
     2411      sum += (v < 128) ? v : 256 - v;
     2412
     2413      if (sum > lmins)  /* We are already worse, don't continue. */
     2414        break;
     2415   }
     2416
     2417   return (sum);
     2418}
     2419
     2420static png_size_t /* PRIVATE */
     2421png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
     2422    const png_size_t row_bytes, const png_size_t lmins)
     2423{
     2424   png_bytep rp, dp, pp, cp, lp;
     2425   png_size_t i;
     2426   png_size_t sum = 0;
     2427   int v;
     2428
     2429   png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;
     2430
     2431   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
     2432       pp = png_ptr->prev_row + 1; i < bpp; i++)
     2433   {
     2434      v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
     2435
     2436      sum += (v < 128) ? v : 256 - v;
     2437   }
     2438
     2439   for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;
     2440        i++)
     2441   {
     2442      int a, b, c, pa, pb, pc, p;
     2443
     2444      b = *pp++;
     2445      c = *cp++;
     2446      a = *lp++;
     2447
     2448      p = b - c;
     2449      pc = a - c;
     2450
     2451#ifdef PNG_USE_ABS
     2452      pa = abs(p);
     2453      pb = abs(pc);
     2454      pc = abs(p + pc);
     2455#else
     2456      pa = p < 0 ? -p : p;
     2457      pb = pc < 0 ? -pc : pc;
     2458      pc = (p + pc) < 0 ? -(p + pc) : p + pc;
     2459#endif
     2460
     2461      p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
     2462
     2463      v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
     2464
     2465      sum += (v < 128) ? v : 256 - v;
     2466
     2467      if (sum > lmins)  /* We are already worse, don't continue. */
     2468        break;
     2469   }
     2470
     2471   return (sum);
     2472}
     2473#endif /* WRITE_FILTER */
     2474
    23252475void /* PRIVATE */
    23262476png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
    23272477{
     2478#ifndef PNG_WRITE_FILTER_SUPPORTED
     2479   png_write_filtered_row(png_ptr, png_ptr->row_buf, row_info->rowbytes+1);
     2480#else
     2481   png_byte filter_to_do = png_ptr->do_filter;
     2482   png_bytep row_buf;
    23282483   png_bytep best_row;
    2329 #ifdef PNG_WRITE_FILTER_SUPPORTED
    2330    png_bytep prev_row, row_buf;
    2331    png_uint_32 mins, bpp;
    2332    png_byte filter_to_do = png_ptr->do_filter;
     2484   png_uint_32 bpp;
     2485   png_size_t mins;
    23332486   png_size_t row_bytes = row_info->rowbytes;
    2334 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2335    int num_p_filters = png_ptr->num_prev_filters;
    2336 #endif
    23372487
    23382488   png_debug(1, "in png_write_find_filter");
    2339 
    2340 #ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2341   if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
    2342   {
    2343      /* These will never be selected so we need not test them. */
    2344      filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH);
    2345   }
    2346 #endif
    23472489
    23482490   /* Find out how many bytes offset each pixel is */
    23492491   bpp = (row_info->pixel_depth + 7) >> 3;
    23502492
    2351    prev_row = png_ptr->prev_row;
    2352 #endif
    2353    best_row = png_ptr->row_buf;
    2354 #ifdef PNG_WRITE_FILTER_SUPPORTED
    2355    row_buf = best_row;
    2356    mins = PNG_MAXSUM;
     2493   row_buf = png_ptr->row_buf;
     2494   mins = PNG_SIZE_MAX - 256/* so we can detect potential overflow of the
     2495                               running sum */;
    23572496
    23582497   /* The prediction method we use is to find which method provides the
     
    23842523    * that has been chosen, as it doesn't actually do anything to the data.
    23852524    */
     2525   best_row = png_ptr->row_buf;
     2526
     2527
    23862528   if ((filter_to_do & PNG_FILTER_NONE) != 0 && filter_to_do != PNG_FILTER_NONE)
    23872529   {
    23882530      png_bytep rp;
    2389       png_uint_32 sum = 0;
     2531      png_size_t sum = 0;
    23902532      png_size_t i;
    23912533      int v;
    23922534
    2393       for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
    2394       {
    2395          v = *rp;
    2396          sum += (v < 128) ? v : 256 - v;
    2397       }
    2398 
    2399 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2400       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2401       {
    2402          png_uint_32 sumhi, sumlo;
    2403          int j;
    2404          sumlo = sum & PNG_LOMASK;
    2405          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
    2406 
    2407          /* Reduce the sum if we match any of the previous rows */
    2408          for (j = 0; j < num_p_filters; j++)
     2535      if (PNG_SIZE_MAX/128 <= row_bytes)
     2536      {
     2537         for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
    24092538         {
    2410             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
    2411             {
    2412                sumlo = (sumlo * png_ptr->filter_weights[j]) >>
    2413                    PNG_WEIGHT_SHIFT;
    2414 
    2415                sumhi = (sumhi * png_ptr->filter_weights[j]) >>
    2416                    PNG_WEIGHT_SHIFT;
    2417             }
     2539            /* Check for overflow */
     2540            if (sum > PNG_SIZE_MAX/128 - 256)
     2541               break;
     2542
     2543            v = *rp;
     2544            sum += (v < 128) ? v : 256 - v;
    24182545         }
    2419 
    2420          /* Factor in the cost of this filter (this is here for completeness,
    2421           * but it makes no sense to have a "cost" for the NONE filter, as
    2422           * it has the minimum possible computational cost - none).
    2423           */
    2424          sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
    2425              PNG_COST_SHIFT;
    2426 
    2427          sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
    2428              PNG_COST_SHIFT;
    2429 
    2430          if (sumhi > PNG_HIMASK)
    2431             sum = PNG_MAXSUM;
    2432 
    2433          else
    2434             sum = (sumhi << PNG_HISHIFT) + sumlo;
    2435       }
    2436 #endif
     2546      }
     2547      else /* Overflow is not possible */
     2548      {
     2549         for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
     2550         {
     2551            v = *rp;
     2552            sum += (v < 128) ? v : 256 - v;
     2553         }
     2554      }
     2555
    24372556      mins = sum;
    24382557   }
     
    24422561   /* It's the only filter so no testing is needed */
    24432562   {
    2444       png_bytep rp, lp, dp;
    2445       png_size_t i;
    2446 
    2447       for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
    2448            i++, rp++, dp++)
    2449       {
    2450          *dp = *rp;
    2451       }
    2452 
    2453       for (lp = row_buf + 1; i < row_bytes;
    2454          i++, rp++, lp++, dp++)
    2455       {
    2456          *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
    2457       }
    2458 
    2459       best_row = png_ptr->sub_row;
     2563      (void) png_setup_sub_row(png_ptr, bpp, row_bytes, mins);
     2564      best_row = png_ptr->try_row;
    24602565   }
    24612566
    24622567   else if ((filter_to_do & PNG_FILTER_SUB) != 0)
    24632568   {
    2464       png_bytep rp, dp, lp;
    2465       png_uint_32 sum = 0, lmins = mins;
    2466       png_size_t i;
    2467       int v;
    2468 
    2469 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2470       /* We temporarily increase the "minimum sum" by the factor we
    2471        * would reduce the sum of this filter, so that we can do the
    2472        * early exit comparison without scaling the sum each time.
    2473        */
    2474       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2475       {
    2476          int j;
    2477          png_uint_32 lmhi, lmlo;
    2478          lmlo = lmins & PNG_LOMASK;
    2479          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
    2480 
    2481          for (j = 0; j < num_p_filters; j++)
     2569      png_size_t sum;
     2570      png_size_t lmins = mins;
     2571
     2572      sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins);
     2573
     2574      if (sum < mins)
     2575      {
     2576         mins = sum;
     2577         best_row = png_ptr->try_row;
     2578         if (png_ptr->tst_row != NULL)
    24822579         {
    2483             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
    2484             {
    2485                lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
    2486                    PNG_WEIGHT_SHIFT;
    2487 
    2488                lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
    2489                    PNG_WEIGHT_SHIFT;
    2490             }
     2580            png_ptr->try_row = png_ptr->tst_row;
     2581            png_ptr->tst_row = best_row;
    24912582         }
    2492 
    2493          lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
    2494              PNG_COST_SHIFT;
    2495 
    2496          lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
    2497              PNG_COST_SHIFT;
    2498 
    2499          if (lmhi > PNG_HIMASK)
    2500             lmins = PNG_MAXSUM;
    2501 
    2502          else
    2503             lmins = (lmhi << PNG_HISHIFT) + lmlo;
    2504       }
    2505 #endif
    2506 
    2507       for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
    2508            i++, rp++, dp++)
    2509       {
    2510          v = *dp = *rp;
    2511 
    2512          sum += (v < 128) ? v : 256 - v;
    2513       }
    2514 
    2515       for (lp = row_buf + 1; i < row_bytes;
    2516          i++, rp++, lp++, dp++)
    2517       {
    2518          v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
    2519 
    2520          sum += (v < 128) ? v : 256 - v;
    2521 
    2522          if (sum > lmins)  /* We are already worse, don't continue. */
    2523             break;
    2524       }
    2525 
    2526 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2527       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2528       {
    2529          int j;
    2530          png_uint_32 sumhi, sumlo;
    2531          sumlo = sum & PNG_LOMASK;
    2532          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
    2533 
    2534          for (j = 0; j < num_p_filters; j++)
    2535          {
    2536             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
    2537             {
    2538                sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
    2539                    PNG_WEIGHT_SHIFT;
    2540 
    2541                sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
    2542                    PNG_WEIGHT_SHIFT;
    2543             }
    2544          }
    2545 
    2546          sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
    2547              PNG_COST_SHIFT;
    2548 
    2549          sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
    2550              PNG_COST_SHIFT;
    2551 
    2552          if (sumhi > PNG_HIMASK)
    2553             sum = PNG_MAXSUM;
    2554 
    2555          else
    2556             sum = (sumhi << PNG_HISHIFT) + sumlo;
    2557       }
    2558 #endif
    2559 
    2560       if (sum < mins)
    2561       {
    2562          mins = sum;
    2563          best_row = png_ptr->sub_row;
    25642583      }
    25652584   }
     
    25682587   if (filter_to_do == PNG_FILTER_UP)
    25692588   {
    2570       png_bytep rp, dp, pp;
    2571       png_size_t i;
    2572 
    2573       for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
    2574           pp = prev_row + 1; i < row_bytes;
    2575           i++, rp++, pp++, dp++)
    2576       {
    2577          *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
    2578       }
    2579 
    2580       best_row = png_ptr->up_row;
     2589      (void) png_setup_up_row(png_ptr, row_bytes, mins);
     2590      best_row = png_ptr->try_row;
    25812591   }
    25822592
    25832593   else if ((filter_to_do & PNG_FILTER_UP) != 0)
    25842594   {
    2585       png_bytep rp, dp, pp;
    2586       png_uint_32 sum = 0, lmins = mins;
    2587       png_size_t i;
    2588       int v;
    2589 
    2590 
    2591 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2592       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2593       {
    2594          int j;
    2595          png_uint_32 lmhi, lmlo;
    2596          lmlo = lmins & PNG_LOMASK;
    2597          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
    2598 
    2599          for (j = 0; j < num_p_filters; j++)
     2595      png_size_t sum;
     2596      png_size_t lmins = mins;
     2597
     2598      sum = png_setup_up_row(png_ptr, row_bytes, lmins);
     2599
     2600      if (sum < mins)
     2601      {
     2602         mins = sum;
     2603         best_row = png_ptr->try_row;
     2604         if (png_ptr->tst_row != NULL)
    26002605         {
    2601             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
    2602             {
    2603                lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
    2604                    PNG_WEIGHT_SHIFT;
    2605 
    2606                lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
    2607                    PNG_WEIGHT_SHIFT;
    2608             }
     2606            png_ptr->try_row = png_ptr->tst_row;
     2607            png_ptr->tst_row = best_row;
    26092608         }
    2610 
    2611          lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
    2612              PNG_COST_SHIFT;
    2613 
    2614          lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
    2615              PNG_COST_SHIFT;
    2616 
    2617          if (lmhi > PNG_HIMASK)
    2618             lmins = PNG_MAXSUM;
    2619 
    2620          else
    2621             lmins = (lmhi << PNG_HISHIFT) + lmlo;
    2622       }
    2623 #endif
    2624 
    2625       for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
    2626           pp = prev_row + 1; i < row_bytes; i++)
    2627       {
    2628          v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
    2629 
    2630          sum += (v < 128) ? v : 256 - v;
    2631 
    2632          if (sum > lmins)  /* We are already worse, don't continue. */
    2633             break;
    2634       }
    2635 
    2636 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2637       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2638       {
    2639          int j;
    2640          png_uint_32 sumhi, sumlo;
    2641          sumlo = sum & PNG_LOMASK;
    2642          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
    2643 
    2644          for (j = 0; j < num_p_filters; j++)
    2645          {
    2646             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
    2647             {
    2648                sumlo = (sumlo * png_ptr->filter_weights[j]) >>
    2649                    PNG_WEIGHT_SHIFT;
    2650 
    2651                sumhi = (sumhi * png_ptr->filter_weights[j]) >>
    2652                    PNG_WEIGHT_SHIFT;
    2653             }
    2654          }
    2655 
    2656          sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
    2657              PNG_COST_SHIFT;
    2658 
    2659          sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
    2660              PNG_COST_SHIFT;
    2661 
    2662          if (sumhi > PNG_HIMASK)
    2663             sum = PNG_MAXSUM;
    2664 
    2665          else
    2666             sum = (sumhi << PNG_HISHIFT) + sumlo;
    2667       }
    2668 #endif
    2669 
    2670       if (sum < mins)
    2671       {
    2672          mins = sum;
    2673          best_row = png_ptr->up_row;
    26742609      }
    26752610   }
     
    26782613   if (filter_to_do == PNG_FILTER_AVG)
    26792614   {
    2680       png_bytep rp, dp, pp, lp;
    2681       png_uint_32 i;
    2682 
    2683       for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
    2684            pp = prev_row + 1; i < bpp; i++)
    2685       {
    2686          *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
    2687       }
    2688 
    2689       for (lp = row_buf + 1; i < row_bytes; i++)
    2690       {
    2691          *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
    2692                  & 0xff);
    2693       }
    2694       best_row = png_ptr->avg_row;
     2615      (void) png_setup_avg_row(png_ptr, bpp, row_bytes, mins);
     2616      best_row = png_ptr->try_row;
    26952617   }
    26962618
    26972619   else if ((filter_to_do & PNG_FILTER_AVG) != 0)
    26982620   {
    2699       png_bytep rp, dp, pp, lp;
    2700       png_uint_32 sum = 0, lmins = mins;
    2701       png_size_t i;
    2702       int v;
    2703 
    2704 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2705       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2706       {
    2707          int j;
    2708          png_uint_32 lmhi, lmlo;
    2709          lmlo = lmins & PNG_LOMASK;
    2710          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
    2711 
    2712          for (j = 0; j < num_p_filters; j++)
     2621      png_size_t sum;
     2622      png_size_t lmins = mins;
     2623
     2624      sum= png_setup_avg_row(png_ptr, bpp, row_bytes, lmins);
     2625
     2626      if (sum < mins)
     2627      {
     2628         mins = sum;
     2629         best_row = png_ptr->try_row;
     2630         if (png_ptr->tst_row != NULL)
    27132631         {
    2714             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
    2715             {
    2716                lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
    2717                    PNG_WEIGHT_SHIFT;
    2718 
    2719                lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
    2720                    PNG_WEIGHT_SHIFT;
    2721             }
     2632            png_ptr->try_row = png_ptr->tst_row;
     2633            png_ptr->tst_row = best_row;
    27222634         }
    2723 
    2724          lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
    2725              PNG_COST_SHIFT;
    2726 
    2727          lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
    2728              PNG_COST_SHIFT;
    2729 
    2730          if (lmhi > PNG_HIMASK)
    2731             lmins = PNG_MAXSUM;
    2732 
    2733          else
    2734             lmins = (lmhi << PNG_HISHIFT) + lmlo;
    2735       }
    2736 #endif
    2737 
    2738       for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
    2739            pp = prev_row + 1; i < bpp; i++)
    2740       {
    2741          v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
    2742 
    2743          sum += (v < 128) ? v : 256 - v;
    2744       }
    2745 
    2746       for (lp = row_buf + 1; i < row_bytes; i++)
    2747       {
    2748          v = *dp++ =
    2749              (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
    2750 
    2751          sum += (v < 128) ? v : 256 - v;
    2752 
    2753          if (sum > lmins)  /* We are already worse, don't continue. */
    2754             break;
    2755       }
    2756 
    2757 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2758       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2759       {
    2760          int j;
    2761          png_uint_32 sumhi, sumlo;
    2762          sumlo = sum & PNG_LOMASK;
    2763          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
    2764 
    2765          for (j = 0; j < num_p_filters; j++)
    2766          {
    2767             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
    2768             {
    2769                sumlo = (sumlo * png_ptr->filter_weights[j]) >>
    2770                    PNG_WEIGHT_SHIFT;
    2771 
    2772                sumhi = (sumhi * png_ptr->filter_weights[j]) >>
    2773                    PNG_WEIGHT_SHIFT;
    2774             }
    2775          }
    2776 
    2777          sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
    2778              PNG_COST_SHIFT;
    2779 
    2780          sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
    2781              PNG_COST_SHIFT;
    2782 
    2783          if (sumhi > PNG_HIMASK)
    2784             sum = PNG_MAXSUM;
    2785 
    2786          else
    2787             sum = (sumhi << PNG_HISHIFT) + sumlo;
    2788       }
    2789 #endif
    2790 
    2791       if (sum < mins)
    2792       {
    2793          mins = sum;
    2794          best_row = png_ptr->avg_row;
    27952635      }
    27962636   }
     
    27992639   if ((filter_to_do == PNG_FILTER_PAETH) != 0)
    28002640   {
    2801       png_bytep rp, dp, pp, cp, lp;
    2802       png_size_t i;
    2803 
    2804       for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
    2805           pp = prev_row + 1; i < bpp; i++)
    2806       {
    2807          *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
    2808       }
    2809 
    2810       for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
    2811       {
    2812          int a, b, c, pa, pb, pc, p;
    2813 
    2814          b = *pp++;
    2815          c = *cp++;
    2816          a = *lp++;
    2817 
    2818          p = b - c;
    2819          pc = a - c;
    2820 
    2821 #ifdef PNG_USE_ABS
    2822          pa = abs(p);
    2823          pb = abs(pc);
    2824          pc = abs(p + pc);
    2825 #else
    2826          pa = p < 0 ? -p : p;
    2827          pb = pc < 0 ? -pc : pc;
    2828          pc = (p + pc) < 0 ? -(p + pc) : p + pc;
    2829 #endif
    2830 
    2831          p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
    2832 
    2833          *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
    2834       }
    2835       best_row = png_ptr->paeth_row;
     2641      (void) png_setup_paeth_row(png_ptr, bpp, row_bytes, mins);
     2642      best_row = png_ptr->try_row;
    28362643   }
    28372644
    28382645   else if ((filter_to_do & PNG_FILTER_PAETH) != 0)
    28392646   {
    2840       png_bytep rp, dp, pp, cp, lp;
    2841       png_uint_32 sum = 0, lmins = mins;
    2842       png_size_t i;
    2843       int v;
    2844 
    2845 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2846       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2847       {
    2848          int j;
    2849          png_uint_32 lmhi, lmlo;
    2850          lmlo = lmins & PNG_LOMASK;
    2851          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
    2852 
    2853          for (j = 0; j < num_p_filters; j++)
     2647      png_size_t sum;
     2648      png_size_t lmins = mins;
     2649
     2650      sum = png_setup_paeth_row(png_ptr, bpp, row_bytes, lmins);
     2651
     2652      if (sum < mins)
     2653      {
     2654         mins = sum;
     2655         best_row = png_ptr->try_row;
     2656         if (png_ptr->tst_row != NULL)
    28542657         {
    2855             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
    2856             {
    2857                lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
    2858                    PNG_WEIGHT_SHIFT;
    2859 
    2860                lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
    2861                    PNG_WEIGHT_SHIFT;
    2862             }
     2658            png_ptr->try_row = png_ptr->tst_row;
     2659            png_ptr->tst_row = best_row;
    28632660         }
    2864 
    2865          lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
    2866              PNG_COST_SHIFT;
    2867 
    2868          lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
    2869              PNG_COST_SHIFT;
    2870 
    2871          if (lmhi > PNG_HIMASK)
    2872             lmins = PNG_MAXSUM;
    2873 
    2874          else
    2875             lmins = (lmhi << PNG_HISHIFT) + lmlo;
    2876       }
    2877 #endif
    2878 
    2879       for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
    2880           pp = prev_row + 1; i < bpp; i++)
    2881       {
    2882          v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
    2883 
    2884          sum += (v < 128) ? v : 256 - v;
    2885       }
    2886 
    2887       for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
    2888       {
    2889          int a, b, c, pa, pb, pc, p;
    2890 
    2891          b = *pp++;
    2892          c = *cp++;
    2893          a = *lp++;
    2894 
    2895 #ifndef PNG_SLOW_PAETH
    2896          p = b - c;
    2897          pc = a - c;
    2898 #ifdef PNG_USE_ABS
    2899          pa = abs(p);
    2900          pb = abs(pc);
    2901          pc = abs(p + pc);
    2902 #else
    2903          pa = p < 0 ? -p : p;
    2904          pb = pc < 0 ? -pc : pc;
    2905          pc = (p + pc) < 0 ? -(p + pc) : p + pc;
    2906 #endif
    2907          p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
    2908 #else /* SLOW_PAETH */
    2909          p = a + b - c;
    2910          pa = abs(p - a);
    2911          pb = abs(p - b);
    2912          pc = abs(p - c);
    2913 
    2914          if (pa <= pb && pa <= pc)
    2915             p = a;
    2916 
    2917          else if (pb <= pc)
    2918             p = b;
    2919 
    2920          else
    2921             p = c;
    2922 #endif /* SLOW_PAETH */
    2923 
    2924          v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
    2925 
    2926          sum += (v < 128) ? v : 256 - v;
    2927 
    2928          if (sum > lmins)  /* We are already worse, don't continue. */
    2929             break;
    2930       }
    2931 
    2932 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2933       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
    2934       {
    2935          int j;
    2936          png_uint_32 sumhi, sumlo;
    2937          sumlo = sum & PNG_LOMASK;
    2938          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
    2939 
    2940          for (j = 0; j < num_p_filters; j++)
    2941          {
    2942             if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
    2943             {
    2944                sumlo = (sumlo * png_ptr->filter_weights[j]) >>
    2945                    PNG_WEIGHT_SHIFT;
    2946 
    2947                sumhi = (sumhi * png_ptr->filter_weights[j]) >>
    2948                    PNG_WEIGHT_SHIFT;
    2949             }
    2950          }
    2951 
    2952          sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
    2953              PNG_COST_SHIFT;
    2954 
    2955          sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
    2956              PNG_COST_SHIFT;
    2957 
    2958          if (sumhi > PNG_HIMASK)
    2959             sum = PNG_MAXSUM;
    2960 
    2961          else
    2962             sum = (sumhi << PNG_HISHIFT) + sumlo;
    2963       }
    2964 #endif
    2965 
    2966       if (sum < mins)
    2967       {
    2968          best_row = png_ptr->paeth_row;
    2969       }
    2970    }
    2971 #endif /* WRITE_FILTER */
     2661      }
     2662   }
    29722663
    29732664   /* Do the actual writing of the filtered row data from the chosen filter. */
    29742665   png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1);
    29752666
    2976 #ifdef PNG_WRITE_FILTER_SUPPORTED
    2977 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    2978    /* Save the type of filter we picked this time for future calculations */
    2979    if (png_ptr->num_prev_filters > 0)
    2980    {
    2981       int j;
    2982 
    2983       for (j = 1; j < num_p_filters; j++)
    2984       {
    2985          png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
    2986       }
    2987 
    2988       png_ptr->prev_filters[j] = best_row[0];
    2989    }
    2990 #endif
    29912667#endif /* WRITE_FILTER */
    29922668}
     
    30042680   png_compress_IDAT(png_ptr, filtered_row, full_row_length, Z_NO_FLUSH);
    30052681
     2682#ifdef PNG_WRITE_FILTER_SUPPORTED
    30062683   /* Swap the current and previous rows */
    30072684   if (png_ptr->prev_row != NULL)
     
    30132690      png_ptr->row_buf = tptr;
    30142691   }
     2692#endif /* WRITE_FILTER */
    30152693
    30162694   /* Finish row - updates counters and flushes zlib if last row */
  • TabularUnified libpng/vendor/current/projects/vstudio/readme.txt

    r1059 r1165  
    22VisualStudio instructions
    33
    4 libpng version 1.6.16 - December 22, 2014
     4libpng version 1.6.18 - July 23, 2015
    55
    66Copyright (c) 1998-2010 Glenn Randers-Pehrson
  • TabularUnified libpng/vendor/current/projects/vstudio/zlib.props

    r1059 r1165  
    33 * zlib.props - location of zlib source
    44 *
    5  * libpng version 1.6.16 - December 22, 2014
     5 * libpng version 1.6.18 - July 23, 2015
    66 *
    77 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  • TabularUnified libpng/vendor/current/scripts/README.txt

    r1059 r1165  
    11
    2 Makefiles for  libpng version 1.6.16 - December 22, 2014
     2Makefiles for  libpng version 1.6.18 - July 23, 2015
    33
    44pnglibconf.h.prebuilt       =>  Stores configuration settings
    55 makefile.linux    =>  Linux/ELF makefile
    6                        (gcc, creates libpng16.so.16.1.6.16)
     6                       (gcc, creates libpng16.so.16.1.6.18)
    77 makefile.gcc      =>  Generic makefile (gcc, creates static libpng.a)
    88 makefile.knr      =>  Archaic UNIX Makefile that converts files with
     
    3434 makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc
    3535 makefile.sggcc    =>  Silicon Graphics (gcc,
    36                        creates libpng16.so.16.1.6.16)
     36                       creates libpng16.so.16.1.6.18)
    3737 makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)
    3838 makefile.solaris  =>  Solaris 2.X makefile (gcc,
    39                        creates libpng16.so.16.1.6.16)
     39                       creates libpng16.so.16.1.6.18)
    4040 makefile.so9      =>  Solaris 9 makefile (gcc,
    41                        creates libpng16.so.16.1.6.16)
     41                       creates libpng16.so.16.1.6.18)
    4242 makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)
    4343 makefile.sunos    =>  Sun makefile
  • TabularUnified libpng/vendor/current/scripts/def.c

    r1059 r1165  
    2222PNG_DFN ""
    2323PNG_DFN "EXPORTS"
    24 PNG_DFN ";Version 1.6.16"
     24PNG_DFN ";Version 1.6.18"
    2525
    2626#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
  • TabularUnified libpng/vendor/current/scripts/dfn.awk

    r922 r1165  
    1818   out="/dev/null"       # as a flag
    1919   out_count=0           # count of output lines
    20    err=0                 # set if an error occured
     20   err=0                 # set if an error occurred
    2121   sort=0                # sort the output
    2222   array[""]=""
  • TabularUnified libpng/vendor/current/scripts/libpng-config-head.in

    r1059 r1165  
    1212# Modeled after libxml-config.
    1313
    14 version=1.6.16
     14version=1.6.18
    1515prefix=""
    1616libdir=""
  • TabularUnified libpng/vendor/current/scripts/libpng.pc.in

    r1059 r1165  
    66Name: libpng
    77Description: Loads and saves PNG files
    8 Version: 1.6.16
     8Version: 1.6.18
    99Libs: -L${libdir} -lpng16
    1010Cflags: -I${includedir}
  • TabularUnified libpng/vendor/current/scripts/makefile.cegcc

    r1059 r1165  
    2424VERMAJ = 1
    2525VERMIN = 6
    26 VERMIC = 16
     26VERMIC = 18
    2727VER = $(VERMAJ).$(VERMIN).$(VERMIC)
    2828NAME = libpng
  • TabularUnified libpng/vendor/current/scripts/makefile.linux

    r1059 r1165  
    1111LIBNAME = libpng16
    1212PNGMAJ = 16
    13 RELEASE = 16
     13RELEASE = 18
    1414
    1515# Shared library names:
  • TabularUnified libpng/vendor/current/scripts/makefile.msys

    r1059 r1165  
    1919LIBNAME = libpng16
    2020PNGMAJ = 16
    21 RELEASE = 16
     21RELEASE = 18
    2222
    2323# Shared library names:
  • TabularUnified libpng/vendor/current/scripts/makefile.ne12bsd

    r1059 r1165  
    1818LIB=    png16
    1919SHLIB_MAJOR=    0
    20 SHLIB_MINOR=    1.6.16
     20SHLIB_MINOR=    1.6.18
    2121SRCS=   png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
    2222        pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
  • TabularUnified libpng/vendor/current/scripts/makefile.netbsd

    r1059 r1165  
    1818LIB=    png
    1919SHLIB_MAJOR=    16
    20 SHLIB_MINOR=    1.6.16
     20SHLIB_MINOR=    1.6.18
    2121SRCS=   png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
    2222        pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
  • TabularUnified libpng/vendor/current/scripts/makefile.openbsd

    r1059 r1165  
    1212
    1313SHLIB_MAJOR=    16
    14 SHLIB_MINOR=    1.6.16
     14SHLIB_MINOR=    1.6.18
    1515
    1616LIB=    png
  • TabularUnified libpng/vendor/current/scripts/makefile.std

    r922 r1165  
    107107
    108108clean:
    109         $(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.*
     109        $(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.h pnglibconf.c \
     110        pnglibconf.out
    110111
    111112DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
  • TabularUnified libpng/vendor/current/scripts/pnglibconf.dfa

    r1059 r1165  
    223223# ARM_NEON_CHECK: (PNG_ARM_NEON == 1) compile a run-time check to see if Neon
    224224#                 extensions are supported. This is poorly supported and
    225 #                 deprectated - use the png_set_option API.
     225#                 deprecated - use the png_set_option API.
    226226setting ARM_NEON_OPT
    227227option ARM_NEON_API disabled requires ALIGNED_MEMORY enables SET_OPTION,
     
    249249setting Z_DEFAULT_NOFILTER_STRATEGY default @Z_DEFAULT_STRATEGY
    250250setting ZLIB_VERNUM default @ZLIB_VERNUM
     251
     252# Linkage of:
     253#
     254#  API:      libpng API functions
     255#  CALLBACK: internal non-file-local callbacks
     256#  FUNCTION: internal non-file-local functions
     257#  DATA:     internal non-file-local (const) data
     258setting LINKAGE_API default extern
     259setting LINKAGE_CALLBACK default extern
     260setting LINKAGE_FUNCTION default extern
     261setting LINKAGE_DATA default extern
    251262
    252263setting TEXT_Z_DEFAULT_COMPRESSION default @Z_DEFAULT_COMPRESSION
     
    351362option IO_STATE
    352363
    353 # This is only for PowerPC big-endian and 680x0 systems
    354 # some testing, not enabled by default.
    355 # NO LONGER USED
    356 
    357 #option READ_BIG_ENDIAN disabled
    358 
    359 # Allow users to control limits on what the READ code will
    360 # read:
    361 
    362 # Added at libpng-1.2.43; adds limit fields to png_struct,
    363 # allows some usages of these fields
    364 
    365 option USER_LIMITS
    366 
    367 # Added at libpng-1.2.6; adds setting APIs, allows additional
    368 # usage of this field (UTSL)
    369 
    370 option SET_USER_LIMITS requires USER_LIMITS
    371 
    372 # Feature added at libpng-1.4.0, this flag added at 1.4.1
    373 option SET_USER_LIMITS enables SET_CHUNK_CACHE_LIMIT
    374 # Feature added at libpng-1.4.1, this flag added at 1.4.1
    375 
    376 option SET_USER_LIMITS enables SET_CHUNK_MALLOC_LIMIT
    377 
    378 # Libpng limits.
    379 #
    380 # If these settings are *not* set libpng will not limit the size of
    381 # images or the size of data in ancilliary chunks.  This does lead to
    382 # security issues if PNG files come from untrusted sources.  Settings have the
     364# Libpng limits: limit the size of images and data on read.
     365#
     366# If this option is disabled all the limit checking code will be disabled:
     367
     368option USER_LIMITS requires READ
     369
     370# The default settings given below for the limits mean that libpng will
     371# limit the size of images or the size of data in ancilliary chunks to less
     372# than the specification or implementation limits. Settings have the
    383373# following interpretations:
    384374#
     
    389379#
    390380# Only chunks that are variable in number are counted towards the
    391 # USER_CHUNK_CACHE_MAX limit
    392 setting USER_WIDTH_MAX
    393 setting USER_HEIGHT_MAX
    394 setting USER_CHUNK_CACHE_MAX
    395 setting USER_CHUNK_MALLOC_MAX
    396 
    397 # To default all these settings to values that are large but probably
    398 # safe turn the SAFE_LIMITS option on; this will cause the value in
    399 # pngpriv.h to be used.  Individual values can also be set, simply set
    400 # them in pngusr.dfa with '@#define PNG_setting value' lines.
    401 option SAFE_LIMITS enables USER_LIMITS disabled
    402 = SAFE_LIMITS SAFE_LIMITS
     381
     382# Use 0x7fffffff for unlimited
     383setting USER_WIDTH_MAX default        1000000
     384setting USER_HEIGHT_MAX default       1000000
     385
     386# Use 0 for unlimited
     387setting USER_CHUNK_CACHE_MAX default     1000
     388setting USER_CHUNK_MALLOC_MAX default 8000000
     389
     390# If this option is enabled APIs to set the above limits at run time are added;
     391# without this the hardwired (compile time) limits will be used.
     392option SET_USER_LIMITS requires USER_LIMITS
    403393
    404394# All of the following options relate to code capabilities for
     
    542532# was added at libpng-1.5.3.
    543533option WRITE_CUSTOMIZE_ZTXT_COMPRESSION requires WRITE
     534option WRITE_CUSTOMIZE_COMPRESSION requires WRITE
    544535
    545536# Any chunks you are not interested in, you can undef here.  The
     
    667658# results in more memory being used, and more pow() functions
    668659# being called to fill in the gamma tables.  Don't set this value
    669 # less then 8, and even that may not work (I haven't tested it).
     660# less than 8, and even that may not work (I haven't tested it).
    670661
    671662setting MAX_GAMMA_8 default 11
  • TabularUnified libpng/vendor/current/scripts/pnglibconf.h.prebuilt

    r1059 r1165  
    1 /* libpng 1.6.16 STANDARD API DEFINITION */
     1/* libpng 1.6.18 STANDARD API DEFINITION */
    22
    33/* pnglibconf.h - library build configuration */
    44
    5 /* Libpng version 1.6.16 - December 22, 2014 */
     5/* Libpng version 1.6.18 - July 23, 2015 */
    66
    77/* Copyright (c) 1998-2014 Glenn Randers-Pehrson */
     
    9898#define PNG_READ_tRNS_SUPPORTED
    9999#define PNG_READ_zTXt_SUPPORTED
    100 /*#undef PNG_SAFE_LIMITS_SUPPORTED*/
    101100#define PNG_SAVE_INT_32_SUPPORTED
    102101#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
    103102#define PNG_SEQUENTIAL_READ_SUPPORTED
    104103#define PNG_SETJMP_SUPPORTED
    105 #define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
    106 #define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
    107104#define PNG_SET_OPTION_SUPPORTED
    108105#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
     
    130127#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
    131128#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
     129#define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
    132130#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
    133131#define PNG_WRITE_FILLER_SUPPORTED
     
    193191#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE
    194192#define PNG_INFLATE_BUF_SIZE 1024
     193#define PNG_LINKAGE_API extern
     194#define PNG_LINKAGE_CALLBACK extern
     195#define PNG_LINKAGE_DATA extern
     196#define PNG_LINKAGE_FUNCTION extern
    195197#define PNG_MAX_GAMMA_8 11
    196198#define PNG_QUANTIZE_BLUE_BITS 5
     
    199201#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)
    200202#define PNG_TEXT_Z_DEFAULT_STRATEGY 0
     203#define PNG_USER_CHUNK_CACHE_MAX 1000
     204#define PNG_USER_CHUNK_MALLOC_MAX 8000000
     205#define PNG_USER_HEIGHT_MAX 1000000
     206#define PNG_USER_WIDTH_MAX 1000000
    201207#define PNG_WEIGHT_SHIFT 8
    202208#define PNG_ZBUF_SIZE 8192
  • TabularUnified libpng/vendor/current/scripts/pnglibconf.mak

    r922 r1165  
    5050
    5151clean-pnglibconf:
    52         $(DELETE) pnglibconf.*
     52        $(DELETE) pnglibconf.h pnglibconf.c pnglibconf.out pnglibconf.pre \
     53        pnglibconf.dfn
    5354
    5455clean: clean-pnglibconf
  • TabularUnified libpng/vendor/current/scripts/symbols.def

    r1059 r1165  
    1 ;Version 1.6.16
     1;Version 1.6.18
    22;--------------------------------------------------------------
    33; LIBPNG symbol list as a Win32 DEF file
  • TabularUnified libpng/vendor/current/test-driver

    r922 r1165  
    44scriptversion=2013-07-13.22; # UTC
    55
    6 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
     6# Copyright (C) 2011-2014 Free Software Foundation, Inc.
    77#
    88# This program is free software; you can redistribute it and/or modify
     
    107107"$@" >$log_file 2>&1
    108108estatus=$?
     109
    109110if test $enable_hard_errors = no && test $estatus -eq 99; then
    110   estatus=1
     111  tweaked_estatus=1
     112else
     113  tweaked_estatus=$estatus
    111114fi
    112115
    113 case $estatus:$expect_failure in
     116case $tweaked_estatus:$expect_failure in
    114117  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
    115118  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
     
    119122  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
    120123esac
     124
     125# Report the test outcome and exit status in the logs, so that one can
     126# know whether the test passed or failed simply by looking at the '.log'
     127# file, without the need of also peaking into the corresponding '.trs'
     128# file (automake bug#11814).
     129echo "$res $test_name (exit status: $estatus)" >>$log_file
    121130
    122131# Report outcome to console.
Note: See TracChangeset for help on using the changeset viewer.