[libpng17] Imported from libpng-1.7.0beta55.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index d26e49f..a893dbd 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,4 +1,5 @@
-Libpng 1.6.17rc02 - March 9, 2015
+
+Libpng 1.7.0beta55 - March 9, 2015
 
 This is not intended to be a public release.  It will be replaced
 within a few weeks by a public version or by another test version.
@@ -8,70 +9,742 @@
 Source files with LF line endings (for Unix/Linux) and with a
 "configure" script
 
-   1.6.17rc02.tar.xz (LZMA-compressed, recommended)
-   1.6.17rc02.tar.gz
+   1.7.0beta55.tar.xz (LZMA-compressed, recommended)
+   1.7.0beta55.tar.gz
 
 Source files with CRLF line endings (for Windows), without the
 "configure" script
 
-   lp1617r02.7z  (LZMA-compressed, recommended)
-   lp1617r02.zip
+   lp170b55.7z  (LZMA-compressed, recommended)
+   lp170b55.zip
 
 Other information:
 
-   1.6.17rc02-README.txt
-   1.6.17rc02-LICENSE.txt
-   libpng-1.6.17rc02-*.asc (armored detached GPG signatures)
+   1.7.0beta55-README.txt
+   1.7.0beta55-LICENSE.txt
+   libpng-1.7.0beta55-*.asc (armored detached GPG signatures)
 
-Changes since the last public release (1.6.16):
+Changes since the last public release (1.6.0):
 
-Version 1.6.17beta01 [January 29, 2015]
-  Removed duplicate PNG_SAFE_LIMITS_SUPPORTED handling from pngconf.h
+Version 1.7.0alpha01 [December 15, 2012]
+  Started 1.7.0 branch from libpng-1.6.0beta33.
+  Made 8-bit compose and rgb_to_grayscale accuracy improvements.  These
+    changes cause 16-bit arithmetic to be used for 8-bit data in the gamma
+    corrected compose and grayscale operations.  The arithmetic errors have
+    three sources all of which are fixed in this commit:
+    1) 8-bit linear calculations produce massive errors for lower intensity
+       values.
+    2) The old 16-bit "16 to 8" gamma table code erroneously wrote the lowest
+       output value into a table entry which corresponded to multiple output
+       values (so where the value written should have been the closest to the
+       transformed input value.)
+    3) In a number of cases the code to access the 16-bit table did not round;
+       it did a simple shift, which was wrong and made the side effects of (2)
+       even worse.
+  The new gamma code does not have the 16-to-8 problem at the cost of slightly
+    more calculations and the algorithm used to minimize the number of
+    calculations has been extended to all the 16-bit tables; it has advantages
+    for any significant gamma correction.
+  Rearranged png_struct, remove unused members, change png_set_filter handling
+    png_struct members rearranged - partly to reorder to avoid packing, partly
+    to put frequently accessed members at the start and partly to make
+    the grouping more clear. png_set_filter code has been rewritten and the
+    code shared with png_write_start_row moved to a common function.  Comments
+    in png.h have been made more clear. Minor fixes to
+    contrib/libtests/timepng.c and some of the png_*_tRNS logic, including
+    more error detection in png_set_tRNS.
+  Cleaned up USER_LIMITS feature, removing members from png_struct when not
+    required.
+  Rearranged ARM-NEON optimizations to isolate the machine specific code to
+    the hardware subdirectory, and add comments to pngrutil.c so that
+    implementors of other optimizations will know what to do.
+  Fixed cases of unquoted DESTDIR in Makefile.am.
+  Rebuilt Makefile.in, configure, etc., with autoconf-2.69 and automake-1.12.5.
+
+Version 1.7.0alpha02 [December 17, 2012]
+  Removed functions that were deprecated in libpng-1.6.0:
+    png_reset_zstream(), png_info_init_3(), and png_data_freer() and its
+    associated flags.
+  Removed some duplicated lines from contrib/tools/scale.c and png.c.
+  Changed some instances of png_warning() to png_app_error().
+  Updated some left over "1.6.0beta32" in code sources.
+  Fixed a "png_structp" prototype (should be png_structrp) in arm_init.c
+  Updated the version-number hack in pngvalid.c
+
+Version 1.7.0alpha03 [December 19, 2012]
+  Cleaned up and enhanced the configure option; libpng now correctly
+    links and tests against zlib with a prefix; tests have been clarified; and
+    irrelevant or obsolete things (as defined by the autotools man page) have
+    been removed.
+  Documented new PNG_ABORT behavior in the manual and commentary in pngerror.c
+  Cleaned up whitespace in the synopsis portion of the manpage "libpng.3"
+  Fixed previous support for Z_PREFIX in configure builds, corrected sCAL APIs;
+    some of these use floating point arithmetic so they need to be disabled if
+    floating point arithmetic is switched off.  This is a quiet API change -
+    previously it appeared that the APIs were supported if fixed point
+    arithmetic was used internally, however they required certain APIs (floor,
+    modf, frexp, atof) that are part of C floating point support. Changed
+    png_fixed and the gamma code specific version of the same to avoid floor(),
+    which may be a library function (not an intrinsic). Removed unused #if 0
+    code.
+  Disassembled the version number in scripts/options.awk (necessary for
+    building on SunOs).
+
+Version 1.7.0alpha04 [December 23, 2012]
+  Added scripts/makefile.msys contributed by Christopher M. Wheeler
+  Made default Zlib compression settings be configurable. This adds #defines to
+    pnglibconf.h to control the defaults.
+  Fixed Windows build issues, enabled ARM compilation. Various warnings issued
+    by earlier versions of GCC fixed for Cygwin and Min/GW (which both use old
+    GCCs.) ARM support is enabled by default in zlib.props (unsupported by
+    Microsoft) and ARM compilation is made possible by deleting the check for
+    x86. The test programs cannot be run because they are not signed.
+
+Version 1.7.0alpha05 [December 24, 2012]
+  Discontinued distributing libpng-1.x.x.tar.bz2.
+  Discontinued distributing libpng-1.7.0-1.6.0-diff.txt and similar.
+
+Version 1.7.0alpha06 [January 1, 2013]
+  Fixed 'make distcheck' on SUN OS - libpng.so was not being removed
+
+Version 1.7.0alpha07 [January 10, 2013]
+  Fixed conceivable but difficult to repro overflow. Also added two test
+    programs to generate and test a PNG which should have the problem.
+
+Version 1.7.0alpha08 [January 17, 2013]
+  Corrected previous attempt at overflow detection in png_set_unknown_chunks()
+  (CVE-2013-7353).  Added overflow detection in png_set_sPLT() and
+  png_set_text_2() (CVE-2013-7354).
+
+Version 1.7.0alpha09 [January 21, 2013]
+  Pulled changes to multi-chunk handling from libpng-1.6.0beta40.
+
+Version 1.7.0alpha10 [February 5, 2013]
+  Make symbol prefixing work with the ARM neon optimizations. Also
+    allow pngpriv.h to be included for preprocessor definitions only, so
+    it can be used in non-C/C++ files.
+  Added png_get_palette_max() function.
+  Changed png_size_t to size_t throughout headers, make sRGB check numbers
+    consistent.
+  Fixed ARM support (Mans Rullgard).
+  Removed stray out-of-order #endif and #ifdef (Mans Rullgard).
+  Ported libpng 1.5 options.awk/dfn file handling to 1.7, fixed one bug.
+  Rebuilt Makefile.in, configure, etc., with autoconf-2.69 and automake-1.13.
+  Minor fixes to assembler changes, verified with a dummy .S file
+  Removed cc -E workround, corrected png_get_palette_max API. Tested on
+    SUN OS cc 5.9, which demonstrates the tokenization problem previously
+    avoided by using /lib/cpp.  Since all .dfn output is now protected
+    in double quotes unless it is to be macro substituted the fix should work
+    everywhere.
+
+Version 1.7.0beta01 [February 15, 2013]
+  Enable parallel tests and rearrange TESTS order to take advantage of
+    the massive speed improvements use a make capable of parallel builds
+    on a multi-CPU machine and pass the right arguments to make (-j10000
+    for GNU make) to get the build to run in parallel.
+  Fixed previous support for Z_PREFIX in configure builds, corrected
+    sCAL APIs; some of these use floating point arithmetic so need to be
+    disabled if floating point arithmetic is switched off.  This is a quiet API
+    change - previously it appeared that the APIs were supported if fixed point
+    arithmetic was used internally, however they required certain APIs (floor,
+    modf, frexp, atof) that are part of C floating point support. Changed
+    png_fixed and the gamma code specific version of the same to avoid floor(),
+    which may be a library function (not an intrinsic). Removed unused #if 0
+    code.
+  Fixed make distcheck to skip over the test result files. They were
+    being included because the whole of the 'tests' directory is included,
+    fixed to just include the actual test files and tests/pngstest.  Also
+    reverted the previous erroneous change to remove the ${srcdir} from the
+    front of contrib, scripts, projects and added an explanation of what is
+    going on to Makefile.am
+  Fixed missing dependency in --prefix builds. The intermediate
+    internal 'prefix.h' file can only be generated correctly after pnglibconf.h,
+    however the dependency was not in Makefile.am.  The symptoms are
+    unpredictable depending on the order make chooses to build pngprefix.h and
+    pnglibconf.h, often the error goes unnoticed because there is a system
+    pnglibconf.h to use instead.
+  Accept "," as a separator in pnglibconf.dfa and allow for
+    continuation lines. This adds to the syntax of "option" and "chunk" lines,
+    allowing the elements to be separated by a "," at the end of an element and
+    interpreting a "," at end of line as a continuation - so the following line
+    is read.  The new syntax is optional and solely provided for readability.
+  Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
+    block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
+
+Version 1.7.0beta02 [February 18, 2013]
+  Fixed a race condition in the creation of the build 'scripts' directory
+    while building with a parallel make.
+  Use approved/supported Android method to check for NEON, use Linux/POSIX
+    1003.1 API to check /proc/self/auxv avoiding buffer allocation and other
+    library calls (ported from libpng15).
+  Use parentheses more consistently in "#if defined(MACRO)" tests.
+  Folded long lines.
+
+Version 1.7.0beta03 [February 22, 2013]
+  Reenabled code to allow zero length PLTE chunks for MNG.
+  Fixed ALIGNED_MEMORY support.
+  Allow run-time ARM NEON checking to be disabled. A new configure option:
+    --enable-arm-neon=always will stop the run-time checks. New checks
+    within arm/arm_init.c will cause the code not to be compiled unless
+    __ARM_NEON__ is set. This should make it fail safe (if someone asks
+    for it on then the build will fail if it can't be done.)
+  Updated the INSTALL document.
+
+Version 1.7.0beta04 [February 27, 2013]
+  Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES.
+  Revised scripts/makefile.freebsd to respect ZLIBLIB and ZLIBINC.
+  Revised scripts/dfn.awk to work with the buggy MSYS awk that has trouble
+    with CRLF line endings.
+
+Version 1.7.0beta05 [March 5, 2013]
+  Avoid a possible memory leak in contrib/gregbook/readpng.c
+  Changed user chunk callback API to respect global and per chunk defaults.
+    Previously a return of 0 from a user chunk callback would result in the
+    chunk being saved (if this was safe, even if the chunk was unsafe-to-copy);
+    this change respects the defaults set by the application, so unknown chunks
+    can be discarded by default and known-safe ones preserved.
+  Corrected Android builds and corrected libpng.vers with symbol
+    prefixing. This adds an API to set optimization options externally,
+    providing an alternative and general solution for the non-portable
+    run-time tests used by the ARM Neon code.  It also makes those tests
+    compile and link on Android.  The order of settings vs options in
+    pnglibconf.h is reversed to allow settings to depend on options and
+    options can now set (or override) the defaults for settings.
+
+Version 1.7.0beta06 [March 13, 2013]
+  Corrected simplified API default gamma for color-mapped output, added
+    a flag to change default. In 1.6.0 when the simplified API was used
+    to produce color-mapped output from an input image with no gamma
+    information the gamma assumed for the input could be different from
+    that assumed for non-color-mapped output.  In particular 16-bit depth
+    input files were assumed to be sRGB encoded, whereas in the 'direct'
+    case they were assumed to have linear data.  This was an error.  The
+    fix makes the simplified API treat all input files the same way and
+    adds a new flag to the png_image::flags member to allow the
+    application/user to specify that 16-bit files contain sRGB data
+    rather than the default linear.
+  Fixed bugs in the pngpixel and makepng test programs.
+  Fixed CMakelists.txt to allow building a single variant of the library
+    (Claudio Bley):
+  Introduced a PNG_LIB_TARGETS variable that lists all activated library
+    targets.  It is an error if this variable ends up empty, ie. you have
+    to build at least one library variant.
+  Made the *_COPY targets only depend on library targets actually being build.
+  Use PNG_LIB_TARGETS to unify a code path.
+  Changed the CREATE_SYMLINK macro to expect the full path to a file as the
+    first argument. When symlinking the filename component of that path is
+    determined and used as the link target.
+  Use copy_if_different in the CREATE_SYMLINK macro.
+  Eliminated two warnings from the Intel C compiler. The warnings are
+    technically valid, although a reasonable treatment of division would
+    show it to be incorrect.
+
+Version 1.7.0beta07 [April 14, 2013]
+  Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling.
+  Fixed incorrect warning of excess deflate data. End condition - the
+    warning would be produced if the end of the deflate stream wasn't read
+    in the last row.  The warning is harmless.
+  Corrected the test on user transform changes on read. It was in the
+    png_set of the transform function, but that doesn't matter unless the
+    transform function changes the rowbuf size, and that is only valid if
+    transform_info is called.
+  Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c
+    (Flavio Medeiros).
+  Corrected length written to uncompressed iTXt chunks (Samuli Suominen).
+
+Version 1.7.0beta08 [April 18, 2013]
+  Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length
+    written by libpng-1.6.0 and 1.6.1.
+  Disallow storing sRGB information when the sRGB is not supported.
+
+Version 1.7.0beta09 [April 24, 2013]
+  Exposed PNG chunk types in png.h
+  Modified png_uint_32 macros/code to make as few assumptions as possible
+  Revised stack marking in arm/filter_neon.S and configure.ac
+  Ensure that NEON filter stuff is completely disabled when switched 'off'.
+    Previously the ARM NEON specific files were still built if the option
+    was switched 'off' as opposed to being explicitly disabled.
+
+Version 1.7.0beta10 [April 24, 2013]
+  Attempt to fix the PNG_ARM_NEON configuration mess.
+
+Version 1.7.0beta11 [April 26, 2013]
+  Test for 'arm*', not just 'arm' in the host_cpu configure variable.
+
+Version 1.7.0beta12 [April 30, 2013]
+  Added png_app_warning for out-of-range unknown chunk index in
+    png_set_unknown_chunk_location().
+  Expanded manual paragraph about writing private chunks.
+  Avoid dereferencing NULL pointer possibly returned from
+     png_create_write_struct() (Andrew Church).
+
+Version 1.7.0beta13 [May 12, 2013]
+  Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the
+    right zlib header files.
+  Separated CPPFLAGS and CFLAGS in contrib/pngminim/*/makefile
+  Updated contrib/pngminus/pnm2png.c (Paul Stewart):
+    Check for EOF
+    Ignore "#" delimited comments in input file to pnm2png.c.
+    Fixed whitespace handling
+    Added a call to png_set_packing()
+    Initialize dimension values so if sscanf fails at least we have known
+      invalid values.
+  Calculate our own zlib windowBits when decoding rather than trusting the
+    CMF bytes in the PNG datastream.
+  Added an option to force maximum window size for inflating, which was
+    the behavior of libpng15 and earlier.
+  Added png-fix-itxt and png-fix-too-far-back to the built programs and
+    removed warnings from the source code and timepng that are revealed as
+    a result.
+  Detect wrong libpng versions linked to png-fix-too-far-back, which currently
+    only works with libpng versions that can be made to reliably fail when
+    the deflate data contains an out-of-window reference.  This means only
+    1.6 and later.
+  Attempt to detect configuration issues with png-fix-too-far-back, which
+    requires both the correct libpng and the correct zlib to function
+    correctly.
+  Check ZLIB_VERNUM for mismatches, enclose #error in quotes
+  Added information in the documentation about problems with and fixes for
+    the bad CRC and bad iTXt chunk situations.
+
+Version 1.7.0beta14 [June 8, 2013]
+  Removed a redundant test in png_set_IHDR().
+  Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt)
+  Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt
+  Enclose the prototypes for the simplified write API in #ifdef STDIO/#endif
+  Make ARM NEON support work at compile time (not just configure time).
+    This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when
+    using a compiler that compiles for multiple architectures at one time.
+  Removed PNG_FILTER_OPTIMIZATIONS and PNG_ARM_NEON_SUPPORTED from
+    pnglibconf.h, allowing more of the decisions to be made internally
+    (pngpriv.h) during the compile.  Without this, symbol prefixing is broken
+    under certain circumstances on ARM platforms.  Now only the API parts of
+    the optimizations ('check' vs 'api') are exposed in the public header files
+    except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the
+    decision about whether or not to use the optimizations.
+  Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage.
+    Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test
+    on __ARM_NEON__ from configure time to compile time.  This breaks symbol
+    prefixing because the definition of the special png_init_filter_functions
+    call was hidden at configure time if the relevant compiler arguments are
+    passed in CFLAGS as opposed to CC.  This change attempts to avoid all
+    the confusion that would result by declaring the init function even when
+    it is not used, so that it will always get prefixed.
+
+Version 1.7.0beta15 [June 18, 2013]
+  Revised libpng.3 so that "doclifter" can process it.
+
+Version 1.7.0beta16 [July 5, 2013]
+  Revised example.c to illustrate use of PNG_DEFAULT_sRGB and PNG_GAMMA_MAC_18
+    as parameters for png_set_gamma().  These have been available since
+    libpng-1.5.4.
+  Renamed contrib/tools/png-fix-too-far-back.c to pngfix.c and revised it
+    to check all compressed chunks known to libpng.
+  Updated documentation to show default behavior of benign errors correctly.
+  Added perfect hash code generation for lists of PNG chunks. This is
+    a work in progress; checked in for use in pngfix.c
+  Ported ARM no-read patch from libpng16.
+  Ported pngfix.c patches from libpng16.
+
+Version 1.7.0beta17 [August 21, 2013]
+  Revised manual about changes in iTXt chunk handling made in libpng-1.6.0.
+  Added "/* SAFE */" comments in pngrutil.c and pngrtran.c where warnings
+    may be erroneously issued by code-checking applications.
+  Added information about png_set_options() to the manual.
+  Delay calling png_init_filter_functions() until a row with nonzero filter
+    is found.
+
+Version 1.7.0beta18 [September 16, 2013]
+  Fixed inconsistent conditional compilation of png_chunk_unknown_handling()
+    prototype, definition, and usage.  Made it depend on
+    PNG_HANDLE_AS_UNKNOWN_SUPPORTED everywhere.
+
+Version 1.7.0beta19 [September 30, 2013]
+  Reverted the change to unknown handling #defines; the change breaks 'NOREAD'
+    builds.
+  Fixed default behavior of ARM_NEON_API. If the ARM NEON API option is
+    compiled without the CHECK option it defaulted to on, not off.
+  Catch up with recent libpng16 changes; unknown handling and spelling
+    corrections
+  Avoid up-cast warnings in pngvalid.c. On ARM the alignment requirements of
+    png_modifier are greater than that of png_store and as a consequence
+    compilation of pngvalid.c results in a warning about increased alignment
+    requirements because of the bare cast to (png_modifier*).  The code is
+    safe, because the pointer is known to point to a stack allocated
+    png_modifier, but this change avoids the warning.
+  Fixed some grammatical changes and updated the png chunks list.
+
+Version 1.7.0beta20 [October 13, 2013]
+  Made changes for compatibility with automake 1.14:
+    1) Added the 'compile' program to the list of programs that must be cleaned
+       in autogen.sh
+    2) Added 'subdir-objects' which causes .c files in sub-directories to be
+       compiled such that the corresponding .o files are also in the
+       sub-directory.  This is because automake 1.14 warns that the
+       current behavior of compiling to the top level directory may be removed
+       in the future.
+    3) Updated dependencies on pnglibconf.h to match the new .o locations and
+       added all the files in contrib/libtests and contrib/tools that depend
+       on pnglibconf.h
+    4) Added 'BUILD_SOURCES = pnglibconf.h'; this is the automake recommended
+       way of handling the dependencies of sources that are machine generated;
+       unfortunately it only works if the user does 'make all' or 'make check',
+       so the dependencies (3) are still required.
+  Cleaned up (char*) casts of zlib messages. The latest version of the Intel C
+    compiler complains about casting a string literal as (char*), so copied the
+    treatment of z_const from the library code into pngfix.c
+  Simplified error message code in pngunknown. The simplification has the
+    useful side effect of avoiding a bogus warning generated by the latest
+    version of the Intel C compiler (it objects to
+    condition ? string-literal : string-literal).
+  Make autogen.sh work with automake 1.13 as well as 1.14. Do this by always
+    removing the 1.14 'compile' script but never checking for it.
+
+Version 1.7.0beta21 [November 2, 2013]
+  Added ARMv8 support (James Yu <james.yu at linaro.org>).  Added file
+    arm/filter_neon_intrinsics.c; enable with -mfpu=neon.
+  Revised pngvalid to generate size images with as many filters as it can
+    manage, limited by the number of rows.
+  Cleaned up ARM NEON compilation handling. The tests are now in pngpriv.h
+    and detect the broken GCC compilers.
+  Allow clang derived from older GCC versions to use ARM intrinsics. This
+    causes all clang builds that use -mfpu=neon to use the intrinsics code,
+    not the assembler code.  This has only been tested on iOS 7. It may be
+    necessary to exclude some earlier clang versions but this seems unlikely.
+  Changed NEON implementation selection mechanism. This allows assembler
+    or intrinsics to be turned on at compile time during the build by defining
+    PNG_ARM_NEON_IMPLEMENTATION to the correct value (2 or 1).  This macro
+    is undefined by default and the build type is selected in pngpriv.h.
+
+Version 1.7.0beta22 [November 7, 2013]
+  Fixed #include in filter_neon_intrinsics.c and ctype macros. The ctype char
+    checking macros take an unsigned char argument, not a signed char.
+
+Version 1.7.0beta23 [November 24, 2013]
+  Changed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED in pngpread.c to
+    #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED to be consistent with
+    what is in pngpriv.h.
+  Moved prototype for png_handle_unknown() in pngpriv.h outside of
+    the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block.
+  Added "-Wall" to CFLAGS in contrib/pngminim/*/makefile
+  Conditionally compile some unused functions reported by -Wall in
+    pngminim.
+  Fixed 'minimal' builds. Various obviously useful minimal configurations
+    don't build because of missing contrib/libtests test programs and
+    overly complex dependencies in scripts/pnglibconf.dfa. This change
+    adds contrib/conftest/*.dfa files that can be used in automatic build
+    scripts to ensure that these configurations continue to build.
+  Enabled WRITE_INVERT and WRITE_PACK in contrib/pngminim/encoder.
+  Fixed pngvalid 'fail' function declaration on the Intel C Compiler.
+    This reverts to the previous 'static' implementation and works round
+    the 'unused static function' warning by using PNG_UNUSED().
+
+Version 1.7.0beta24 [December 15, 2013]
+  Removed or marked PNG_UNUSED some harmless "dead assignments" reported
+    by clang scan-build.
+  Changed tabs to 3 spaces in png_debug macros and changed '"%s"m'
+    to '"%s" m' to improve portability among compilers.
+  Changed png_free_default() to free() in pngtest.c
+  Tidied up pngfix inits and fixed pngtest no-write builds.
+  Bookkeeping: Moved functions around (no changes). Moved transform
+    function definitions before the place where they are called so that
+    they can be made static. Move the intrapixel functions and the
+    grayscale palette builder out of the png?tran.c files. The latter
+    isn't a transform function and is no longer used internally, and the
+    former MNG specific functions are better placed in pngread/pngwrite.c
+  Made transform implementation functions static. This makes the internal
+    functions called by png_do_{read|write}_transformations static. On an
+    x86-64 DLL build (Gentoo Linux) this reduces the size of the text
+    segment of the DLL by 1208 bytes, about 0.6%. It also simplifies
+    maintenance by removing the declarations from pngpriv.h and allowing
+    easier changes to the internal interfaces.
+  Handle zero-length PLTE chunk or NULL palette with png_error()
+    instead of png_chunk_report(), which by default issues a warning
+    rather than an error, leading to later reading from a NULL pointer
+    (png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954
+    and VU#650142.  Libpng-1.6.1 through 1.6.7 and libpng-1.7.0beta03
+    through 1.7.0beta23 are vulnerable.  Libpng-1.6.0 and earlier do not
+    have the bug.
+
+Version 1.7.0beta25 [December 26, 2013]
+  Merged files with version 1.6.8 that have not changed since then.
+  Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69
+
+Version 1.7.0beta26 [January 1, 2014]
+  Added libpng 1.5 checks to pngvalid.c
+  Merged with 1.5 and 1.6 changes to create a single pngvalid.c
+  Added dSIG to chunk list in png.h
+  Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner).
+  Merged pngrio.c, pngtrans.c, and pngwio.c with libpng-1.6.9
+  Fixed test programs for interlace options. Made pngvalid.c and
+    pngtest.c work correctly when READ_INTERLACING and/or WRITE_INTERLACING
+    are switched off.
+  Changed pngvalid.c to support libpng 1.5, which does not support
+    the PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when
+    appropriate in pngvalid.c
+  Allow unversioned links created on install to be disabled in configure.
+    In configure builds 'make install' changes/adds links like png.h
+    and libpng.a to point to the newly installed, versioned, files (e.g.
+    libpng17/png.h and libpng17.a). Three new configure options and some
+    rearrangement of Makefile.am allow creation of these links to be disabled.
+
+Version 1.7.0beta27 [January 10, 2014]
+  Removed potentially misleading warning from png_check_IHDR().
+
+Version 1.7.0beta28 [January 20, 2014]
+  Updated scripts/makefile.* to use CPPFLAGS (Cosmin).
+  Added clang attribute support (Cosmin).
+
+Version 1.7.0beta29 [January 30, 2014]
+  Quiet an uninitialized memory warning from VS2013 in png_get_png().
+
+Version 1.7.0beta30 [February 2, 2014]
+  Fixed a large number of instances where PNGCBAPI was omitted from
+    function definitions.
+  Added pngimage test program for png_read_png and png_write_png. This
+    is a work-in-progress; no tests are run automatically at present and
+    the program by virtue of exhaustively testing all the transforms is
+    very slow.
+
+Version 1.7.0beta31 [February 6, 2014]
+  Make png_read_png() and png_write_png() prototypes in png.h depend
+    upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
+  Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
+    png_set_packing() in png_read_png().
+  Completed full working pngimage test program and added two test scripts.
+  Fixed combination of ~alpha with shift. On read invert alpha, processing
+    occurred after shift processing, which causes the final values to be
+    outside the range that should be produced by the shift. Reversing the
+    order on read makes the two transforms work together correctly and mirrors
+    the order used on write.
+  Do not read invalid sBIT chunks. Previously libpng only checked sBIT
+    values on write, so a malicious PNG writer could therefore cause
+    the read code to return an invalid sBIT chunk, which might lead to
+    application errors or crashes.  Such chunks are now skipped (with
+    chunk_benign_error).
+  Restored a line, "c = b;", that was inadvertently deleted from the
+    PAETH filtering code from libpng-1.7.0beta24/pngrutil.c. Deleted
+    the other instance of "c = b;" which is the one that triggered a
+    scan-build warning.
+  Support builds with unsupported PNG_TRANSFORM_* values.  All of the
+    PNG_TRANSFORM_* values are always defined in png.h and, because they
+    are used for both read and write in some cases, it is not reliable
+    to #if out ones that are totally unsupported. This change adds error
+    detection in png_read_image() and png_write_image() to do a
+    png_app_error() if the app requests something that cannot be done
+    and it adds corresponding code to pngimage.c to handle such options
+    by not attempting to test them.
+
+Version 1.7.0beta32 [February 26, 2014]
+  Moved redefines of png_error(), png_warning(), png_chunk_error(),
+    and png_chunk_warning() from pngpriv.h to png.h to make them visible
+    to libpng-calling applications.
+  Moved OS dependent code from arm/arm_init.c, to allow the included
+    implementation of the ARM NEON discovery function to be set at
+    build-time and provide sample implementations from the current code in the
+    contrib/arm-neon subdirectory. The __linux__ code has also been changed to
+    compile and link on Android by using /proc/cpuinfo, and the old linux code
+    is in contrib/arm-neon/linux-auxv.c.  The new code avoids POSIX and Linux
+    dependencies apart from opening /proc/cpuinfo and is C90 compliant.
+  Check for info_ptr == NULL early in png_read_end() so we don't need to
+    run all the png_handle_*() and depend on them to return if info_ptr == NULL.
+    This improves the performance of png_read_end(png_ptr, NULL) and makes
+    it more robust against future programming errors.
+  Check for __has_extension before using it in pngconf.h, to
+    support older Clang versions (Jeremy Sequoia).
+  Use a user warning handler in contrib/gregbook/readpng2.c instead of default,
+    so warnings will be put on stderr even if libpng has CONSOLE_IO disabled.
+  Added png_ptr->process_mode = PNG_READ_IDAT_MODE in png_push_read_chunk
+    after recognizing the IDAT chunk, which avoids an infinite loop while
+    reading a datastream whose first IDAT chunk is of zero-length.
+    This fixes CERT VU#684412 and CVE-2014-0333.
+  Don't recognize known sRGB profiles as sRGB if they have been hacked,
+    but don't reject them and don't issue a copyright violation warning.
+  Minor editing of contrib/arm-neon/README and contrib/examples/*.c
+  Moved some documentation from png.h to libpng.3 and libpng-manual.txt
+
+Version 1.7.0beta33 [February 27, 2014]
+  Fixed typos in the manual and in scripts/pnglibconf.dfa (CFLAGS -> CPPFLAGS
+    and PNG_USR_CONFIG -> PNG_USER_CONFIG).
+
+Version 1.7.0beta34 [March 17, 2014]
+  Treat CRC error handling with png_set_crc_action(), instead of with
+    png_set_benign_errors(), which has been the case since libpng-1.6.0beta18.
+  Use "if (value != 0)" instead of "if (value)" consistently.
+  Changed ZlibSrcDir from 1.2.5 to 1.2.8 in projects/vstudio.
+  Moved configuration information from the manual to the INSTALL file.
+
+Version 1.7.0beta35 [August 6, 2014]
+  Removed #if/#else/#endif from inside two pow() calls in pngvalid.c because
+    they were handled improperly by Portland Group's PGI-14.1 - PGI-14.3
+    when using its "__builtin_pow()" function.
+  Silence 'unused parameter' build warnings (Cosmin).
+  $(CP) is now used alongside $(RM_F).  Also, use 'copy' instead
+    of 'cp' where applicable, and applied other minor makefile changes.
+  Don't warn about invalid dimensions exceeding user limits.
+  Allow an easy replacement of the default pre-built configuration
+    header with a custom header, via the make PNGLIBCONF_H_PREBUILT
+    macro.
+  Fixed a typo in pngrutil.c, introduced in libpng-1.5.6, that interferes
+    with "blocky" expansion of sub-8-bit interlaced PNG files (Eric Huss).
+  Removed scripts/makefile.elf. It has not worked since libpng-1.5.0beta14
+    due to elimination of the PNG_FUNCTION_EXPORT and PNG_DATA_EXPORT
+    definitions from pngconf.h.
+  Ensure that CMakeLists.txt makes the target "lib" directory before making
+    symbolic link into it (SourceForge bug report #226 by Rolf Timmermans).
+  Added opinion that the ECCN (Export Control Classification Number) for
+    libpng is EAR99 to the README file.
+
+Version 1.7.0beta36 [September 27, 2014]
+  Updated scripts/makefiles from libpng-1.6.13beta04.
+  Minor updates to the manual from libpng-1.6.14beta04.
+  Fixed incorrect handling of the iTXt compression flag in pngrutil.c
+    (bug report by Shunsaku Hirata).  Bug was introduced in libpng-1.6.0.
+
+Version 1.7.0beta37 [September 28, 2014]
+  Merged scripts/*, pngvalid.c and pngfix.c with libpng-1.6.14beta04.
+
+Version 1.7.0beta38 [October 17, 2014]
+  Added "option READ_iCCP enables READ_COMPRESSED_TEXT" to pnglibconf.dfa
+  Removed unused "text_len" parameter from private function png_write_zTXt().
+  Conditionally compile some code in png_deflate_claim(), when
+    PNG_WARNINGS_SUPPORTED and PNG_ERROR_TEXT_SUPPORTED are disabled.
+  Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL.
+  Added "chunk iTXt enables TEXT" and "chunk zTXt enables TEXT"
+    to pnglibconf.dfa.
+  Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa,
+    to make it possible to configure a libpng that supports iCCP but not TEXT.
+  Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa
+  Only mark text chunks as written after successfully writing them.
+
+Version 1.7.0beta39 [November 1, 2014]
+  Ported cosmetic changes from libpng-1.6.15beta02.
+
+Version 1.7.0beta40 [November 6, 2014]
+  Made a one-line revision to configure.ac to support ARM on aarch64
+    (bug report by Marcin Juszkiewicz, fix by John Bowler).
+  Use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING in
+    example.c, pngtest.c, and applications in the contrib directory.
+  Avoid out-of-bounds memory access in png_user_version_check().
+  Simplified and future-proofed png_user_version_check().
+  Fixed GCC unsigned int->float warnings. Various versions of GCC
+    seem to generate warnings when an unsigned value is implicitly
+    converted to double. This is probably a GCC bug but this change
+    avoids the issue by explicitly converting to (int) where safe.
+  Free all allocated memory in pngimage. The file buffer cache was left
+    allocated at the end of the program, harmless but it causes memory
+    leak reports from clang.
+  Fixed array size calculations to avoid warnings. At various points
+    in the code the number of elements in an array is calculated using
+    sizeof.  This generates a compile time constant of type (size_t) which
+    is then typically assigned to an (unsigned int) or (int). Some versions
+    of GCC on 64-bit systems warn about the apparent narrowing, even though
+    the same compiler does apparently generate the correct, in-range,
+    numeric constant.  This adds appropriate, safe, casts to make the
+    warnings go away.
+
+Version 1.7.0beta41 [November 7, 2014]
+  Added #ifdef PNG_16BIT_SUPPORTED/#endif around png_log16bit() and
+    png_do_swap().
+  Changed all "#endif /* PNG_FEATURE_SUPPORTED */" to "#endif /* FEATURE */"
+
+Version 1.7.0beta42 [November 20, 2014]
+  The macros passed in the command line to Borland make were ignored if
+    similarly-named macros were already defined in makefiles. This behavior
+    is different from POSIX make and other make programs.  Surround the
+    macro definitions with ifndef guards (Cosmin).
+  Added "-D_CRT_SECURE_NO_WARNINGS" to CFLAGS in scripts/makefile.vcwin32.
+  Removed the obsolete $ARCH variable from scripts/makefile.darwin.
+  Merged clang no-warning fix from libpng-1.6.13: png_digit was defined
+    but never used in pngerror.c.
+
+Version 1.7.0beta43 [December 18, 2014]
+  Added ".align 2" to arm/filter_neon.S to support old GAS assemblers that
+    don't do alignment correctly.
+  Revised Makefile.am and scripts/*.dfn to work with MinGW/MSYS;
+    renamed scripts/*.dfn to scripts/*.c (Bob Friesenhahn and John Bowler).
+  Quiet a "comparison always true" warning in pngstest.c (John Bowler).
+
+Version 1.7.0beta44 [December 23, 2014]
+  Restored a test on width that was removed from png.c at libpng-1.6.9
+    (Bug report by Alex Eubanks, CVE-2015-0973).
+  Fixed an overflow in png_combine_row() with very wide interlaced images
+    (Bug report and fix by John Bowler, CVE-2014-9495).
   Corrected the width limit calculation in png_check_IHDR().
-  Removed user limits from pngfix. Also pass NULL pointers to
-    png_read_row to skip the unnecessary row de-interlace stuff.
-  Added testing of png_set_packing() to pngvalid.c
-  Regenerated configure scripts in the *.tar distributions with libtool-2.4.4
-  Implement previously untested cases of libpng transforms in pngvalid.c
-  Fixed byte order in 2-byte filler, in png_do_read_filler().
-  Made the check for out-of-range values in png_set_tRNS() detect
-    values that are exactly 2^bit_depth, and work on 16-bit platforms.
-  Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47.
-  Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
-    pngset.c to avoid warnings about dead code.
+  Removed extraneous handling of PNG_SAFE_LIMITS_SUPPORTED from pngconf.h
 
-Version 1.6.17beta02 [February 7, 2015]
-  Work around one more Coverity-scan dead-code warning.
-  Do not build png_product2() when it is unused.
-
-Version 1.6.17beta03 [February 17, 2015]
-  Display user limits in the output from pngtest.
+Version 1.7.0beta45 [December 28, 2014]
   Eliminated the PNG_SAFE_LIMITS macro and restored the 1-million-column
     and 1-million-row default limits in pnglibconf.dfa, that can be reset
     by the user at build time or run time.  This provides a more robust
     defense against DOS and as-yet undiscovered overflows.
+  Removed user limits from pngfix. Also pass NULL pointers to
+    png_read_row to skip the unnecessary row de-interlace stuff.
+  Added testing of png_set_packing() to pngvalid.c
 
-Version 1.6.17beta04 [February 21, 2015]
-  Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default.
+Version 1.7.0beta46 [January 2, 2015]
+  Regenerated configure scripts in the tar distributions with libtool-2.4.4
+  Implement previously untested cases of libpng transforms in pngvalid.c
+  Fixed byte order in 2-byte filler, in png_do_read_filler().
   Allow user to call png_get_IHDR() with NULL arguments (Reuben Hawkins).
+
+Version 1.7.0beta47 [January 29, 2015]
+  Made the check for out-of-range values in png_set_tRNS() detect
+    values that are exactly 2^bit_depth, and work on 16-bit platforms.
+  Added PNG_SKIP_sRGB_CHECK_PROFILE choice for png_set_option().
+  Report all IHDR errors before exiting png_check_IHDR().
+  Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47.
+  Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
+    pngset.c to avoid warnings about dead code.
+
+Version 1.7.0beta48 [February 7, 2015]
+  Work around one more Coverity-scan dead-code warning.
+  Do not build png_product2() when it is unused.
+
+Version 1.7.0beta49 [February 11, 2015]
+  Combined sub_row, up_row, avg_row, and paeth_row buffers into a
+    single try_row buffer.
+  Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default.
+  Consolidated redundant code in pngwutil.c
+  Deal with integer overflow of sum in pngwutil.c
+
+Version 1.7.0beta50 [February 15, 2015]
+  Combined sub_row, up_row, avg_row, and paeth_row buffers into a
+    single try_row buffer and in cases where two or more of those are
+    being tested, a second tst_row buffer.  This improves CPU speed
+    over that achieved by libpng-1.7.0beta49.
+
+Version 1.7.0beta51 [February 17, 2015]
+  Combined similar parts of png_write_find_filter() into a png_increase_lmins()
+    function.
+  Display user limits in the output from pngtest.
+  Replaced test for harmless integer overflow (wraparound) in pngwutil.c
+    with a method that prevents overflow and does not increase cpu usage
+    significantly.
+
+Version 1.7.0beta52 [February 21, 2015]
+  Added information about setjmp/simplified API interaction in the
+    manual page and INSTALL file. Added information about using
+    row_pointers with a single height*width*bpp allocated block
   Rebuilt configure scripts with automake-1.15 and libtool-2.4.6
 
-Version 1.6.17beta05 [February 25, 2015]
+Version 1.7.0beta53 [February 23, 2015]
   Restored compiling of png_reciprocal2 with PNG_NO_16BIT.
 
-Version 1.6.17beta06 [February 27, 2015]
+Version 1.7.0beta54 [March 4, 2015]
   Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block
     of png.h.
+  Conditionally compile a small amount of code in pngwutil.c
   Avoid runtime checks when converting integer to png_byte with
     Visual Studio (Sergey Kosarevsky)
+  Merged pngwrite.c with libpng-1.6.17beta06/pngwrite.c
 
-Version 1.6.17rc01 [March 4, 2015]
-  No changes.
-
-Version 1.6.17rc02 [March 9, 2015]
+Version 1.7.0beta55 [March 9, 2015]
   Removed some comments that the configure script did not handle
     properly from scripts/pnglibconf.dfa and pnglibconf.h.prebuilt.
-  Free the unknown_chunks structure even when it contains no data.
+  Spelling fixes ("then", "occured") reported by Lauri Nurmi.
+  Added more error reporting in png_default_read_data().
+  Merged png_free_data() with libpng-1.6.17rc02.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/CHANGES b/CHANGES
index 076c28c..1b24cf4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,4 @@
-
+#if 0
 CHANGES - changes for libpng
 
 Version 0.2
@@ -2102,7 +2102,7 @@
     png_decompress_chunk(), and remove "chunkdata" from parameter list.
   Put a call to png_check_chunk_name() in png_read_chunk_header().
   Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte.
-  Removed two calls to png_check_chunk_name() occurring later in the process.
+  Removed two calls to png_check_chunk_name() occuring later in the process.
   Define PNG_NO_ERROR_NUMBERS by default in pngconf.h
 
 Version 1.4.0beta25 [July 30, 2008]
@@ -3780,8 +3780,7 @@
 
 Version 1.6.0beta01 [December 15, 2011]
   Removed machine-generated configure files from the GIT repository (they will
-    continue to appear in the tarball distributions and in the libpng15 and
-    earlier GIT branches).
+    continue to appear in the tarball distributions).
   Restored the new 'simplified' API, which was started in libpng-1.5.7beta02
     but later deleted from libpng-1.5.7beta05.
   Added example programs for the new 'simplified' API.
@@ -4308,24 +4307,79 @@
   Fixed error checking in the simplified write API (Olaf van der Spek)
   Made png_user_version_check() ok to use with libpng version 1.10.x and later.
 
-Version 1.6.0beta33 [December 15, 2012]
+Version 1.6.0beta33 [December 10, 2012]
   Fixed typo in png.c (PNG_SET_CHUNK_MALLOC_MAX should be PNG_CHUNK_MALLOC_MAX)
     that causes the MALLOC_MAX limit not to work (John Bowler)
   Change png_warning() to png_app_error() in pngwrite.c and comment the
     fall-through condition.
   Change png_warning() to png_app_warning() in png_write_tRNS().
-  Rearranged the ARM-NEON optimizations: Isolated the machine specific code
-    to the hardware subdirectory and added comments to pngrutil.c so that
-    implementors of other optimizations know what to do.
-  Fixed cases of unquoted DESTDIR in Makefile.am
-  Rebuilt Makefile.in, etc., with autoconf-2.69 and automake-1.12.5.
 
-Version 1.6.0beta34 [December 19, 2012]
+Version 1.7.0alpha01 [December 15, 2012]
+  Started 1.7.0 branch from libpng-1.6.0beta33.
+  Made 8-bit compose and rgb_to_grayscale accuracy improvements.  These
+    changes cause 16-bit arithmetic to be used for 8-bit data in the gamma
+    corrected compose and grayscale operations.  The arithmetic errors have
+    three sources all of which are fixed in this commit:
+    1) 8-bit linear calculations produce massive errors for lower intensity
+       values.
+    2) The old 16-bit "16 to 8" gamma table code erroneously wrote the lowest
+       output value into a table entry which corresponded to multiple output
+       values (so where the value written should have been the closest to the
+       transformed input value.)
+    3) In a number of cases the code to access the 16-bit table did not round;
+       it did a simple shift, which was wrong and made the side effects of (2)
+       even worse.
+  The new gamma code does not have the 16-to-8 problem at the cost of slightly
+    more calculations and the algorithm used to minimize the number of
+    calculations has been extended to all the 16-bit tables; it has advantages
+    for any significant gamma correction.
+  Rearranged png_struct, remove unused members, change png_set_filter handling
+    png_struct members rearranged - partly to reorder to avoid packing, partly
+    to put frequently accessed members at the start and partly to make
+    the grouping more clear. png_set_filter code has been rewritten and the
+    code shared with png_write_start_row moved to a common function.  Comments
+    in png.h have been made more clear. Minor fixes to
+    contrib/libtests/timepng.c and some of the png_*_tRNS logic, including
+    more error detection in png_set_tRNS.
+  Cleaned up USER_LIMITS feature, removing members from png_struct when not
+    required.
+  Rearranged ARM-NEON optimizations to isolate the machine specific code to
+    the hardware subdirectory, and add comments to pngrutil.c so that
+    implementors of other optimizations will know what to do.
+  Fixed cases of unquoted DESTDIR in Makefile.am.
+  Rebuilt Makefile.in, configure, etc., with autoconf-2.69 and automake-1.12.5.
+
+Version 1.7.0alpha02 [December 17, 2012]
+  Removed functions that were deprecated in libpng-1.6.0:
+    png_reset_zstream(), png_info_init_3(), png_data_freer() and its
+    associated flags, png_malloc_default, and png_free_default.
+  Removed some duplicated lines from contrib/tools/scale.c and png.c.
+  Changed some instances of png_warning() to png_app_error().
+  Updated some left over "1.6.0beta32" in code sources.
+  Fixed a "png_structp" prototype (should be png_structrp) in arm_init.c
+  Updated the version-number hack in pngvalid.c
+  
+Version 1.7.0alpha03 [December 19, 2012]
+  Cleaned up and enhanced the configure option; libpng now correctly
+    links and tests against zlib with a prefix; tests have been clarified; and
+    irrelevant or obsolete things (as defined by the autotools man page) have
+    been removed.
+  Documented new PNG_ABORT behavior in the manual and commentary in pngerror.c
   Cleaned up whitespace in the synopsis portion of the manpage "libpng.3"
+  Fixed previous support for Z_PREFIX in configure builds, corrected sCAL APIs;
+    some of these use floating point arithmetic so they need to be disabled if
+    floating point arithmetic is switched off.  This is a quiet API change -
+    previously it appeared that the APIs were supported if fixed point
+    arithmetic was used internally, however they required certain APIs (floor,
+    modf, frexp, atof) that are part of C floating point support. Changed
+    png_fixed and the gamma code specific version of the same to avoid floor(),
+    which may be a library function (not an intrinsic). Removed unused #if 0
+    code.
   Disassembled the version number in scripts/options.awk (necessary for
     building on SunOs).
 
-Version 1.6.0beta35 [December 23, 2012]
+Version 1.7.0alpha04 [December 23, 2012]
+  Added scripts/makefile.msys contributed by Christopher M. Wheeler
   Made default Zlib compression settings be configurable. This adds #defines to
     pnglibconf.h to control the defaults.
   Fixed Windows build issues, enabled ARM compilation. Various warnings issued
@@ -4334,82 +4388,88 @@
     Microsoft) and ARM compilation is made possible by deleting the check for
     x86. The test programs cannot be run because they are not signed.
 
-Version 1.6.0beta36 [January 2, 2013]
+Version 1.7.0alpha05 [December 24, 2012]
   Discontinued distributing libpng-1.x.x.tar.bz2.
   Discontinued distributing libpng-1.7.0-1.6.0-diff.txt and similar.
-  Rebuilt configure with autoconf-2.69 (inadvertently not done in beta33)
+
+Version 1.7.0alpha06 [January 1, 2013]
   Fixed 'make distcheck' on SUN OS - libpng.so was not being removed
 
-Version 1.6.0beta37 [January 10, 2013]
+Version 1.7.0alpha07 [January 10, 2013]
   Fixed conceivable but difficult to repro overflow. Also added two test
     programs to generate and test a PNG which should have the problem.
 
-Version 1.6.0beta39 [January 19, 2013]
-  Again corrected attempt at overflow detection in png_set_unknown_chunks()
+Version 1.7.0alpha08 [January 17, 2013]
+  Corrected previous attempt at overflow detection in png_set_unknown_chunks()
   (CVE-2013-7353).  Added overflow detection in png_set_sPLT() and
   png_set_text_2() (CVE-2013-7354).
 
-Version 1.6.0beta40 [January 20, 2013]
-  Use consistent handling of overflows in text, sPLT and unknown png_set_* APIs
+Version 1.7.0alpha09 [January 21, 2013]
+  Pulled changes to multi-chunk handling from libpng-1.6.0beta40.
 
-Version 1.6.0rc01 [January 26, 2013]
-  No changes.
-
-Version 1.6.0rc02 [February 4, 2013]
+Version 1.7.0alpha10 [February 5, 2013]
+  Make symbol prefixing work with the ARM neon optimizations. Also
+    allow pngpriv.h to be included for preprocessor definitions only, so
+    it can be used in non-C/C++ files.
   Added png_get_palette_max() function.
+  Changed png_size_t to size_t throughout headers, make sRGB check numbers
+    consistent.
+  Fixed ARM support (Mans Rullgard).
+  Removed stray out-of-order #endif and #ifdef (Mans Rullgard).
+  Ported libpng 1.5 options.awk/dfn file handling to 1.7, fixed one bug.
+  Rebuilt Makefile.in, configure, etc., with autoconf-2.69 and automake-1.13.
+  Minor fixes to assembler changes, verified with a dummy .S file
+  Removed cc -E workround, corrected png_get_palette_max API. Tested on
+    SUN OS cc 5.9, which demonstrates the tokenization problem previously
+    avoided by using /lib/cpp.  Since all .dfn output is now protected
+    in double quotes unless it is to be macro substituted the fix should work
+    everywhere.
 
-Version 1.6.0rc03 [February 5, 2013]
-  Fixed the png_get_palette_max API.
-
-Version 1.6.0rc04 [February 7, 2013]
-  Turn serial tests back on (recently turned off by autotools upgrade).
-
-Version 1.6.0rc05 [February 8, 2013]
-  Update manual about png_get_palette_max().
-
-Version 1.6.0rc06 [February 9, 2013]
-  Fixed missing dependency in --prefix builds The intermediate
-    internal 'prefix.h' file can only be generated correctly after
-    pnglibconf.h, however the dependency was not in Makefile.am.  The
-    symptoms are unpredictable depending on the order make chooses to
-    build pngprefix.h and pnglibconf.h, often the error goes unnoticed
-    because there is a system pnglibconf.h to use instead.
-
-Version 1.6.0rc07 [February 10, 2013]
+Version 1.7.0beta01 [February 15, 2013]
+  Enable parallel tests and rearrange TESTS order to take advantage of
+    the massive speed improvements use a make capable of parallel builds
+    on a multi-CPU machine and pass the right arguments to make (-j10000
+    for GNU make) to get the build to run in parallel.
+  Fixed previous support for Z_PREFIX in configure builds, corrected
+    sCAL APIs; some of these use floating point arithmetic so need to be
+    disabled if floating point arithmetic is switched off.  This is a quiet API
+    change - previously it appeared that the APIs were supported if fixed point
+    arithmetic was used internally, however they required certain APIs (floor,
+    modf, frexp, atof) that are part of C floating point support. Changed
+    png_fixed and the gamma code specific version of the same to avoid floor(),
+    which may be a library function (not an intrinsic). Removed unused #if 0
+    code.
+  Fixed make distcheck to skip over the test result files. They were
+    being included because the whole of the 'tests' directory is included,
+    fixed to just include the actual test files and tests/pngstest.  Also
+    reverted the previous erroneous change to remove the ${srcdir} from the
+    front of contrib, scripts, projects and added an explanation of what is
+    going on to Makefile.am
+  Fixed missing dependency in --prefix builds. The intermediate
+    internal 'prefix.h' file can only be generated correctly after pnglibconf.h,
+    however the dependency was not in Makefile.am.  The symptoms are
+    unpredictable depending on the order make chooses to build pngprefix.h and
+    pnglibconf.h, often the error goes unnoticed because there is a system
+    pnglibconf.h to use instead.
+  Accept "," as a separator in pnglibconf.dfa and allow for
+    continuation lines. This adds to the syntax of "option" and "chunk" lines,
+    allowing the elements to be separated by a "," at the end of an element and
+    interpreting a "," at end of line as a continuation - so the following line
+    is read.  The new syntax is optional and solely provided for readability.
   Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
     block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
 
-Version 1.6.0rc08 [February 10, 2013]
-  Fix typo in png.h #ifdef
-
-Version 1.6.0 [February 14, 2013]
-  No changes.
-
-Version 1.6.1beta01 [February 16, 2013]
-  Made symbol prefixing work with the ARM neon optimizations. Also allow
-    pngpriv.h to be included for preprocessor definitions only, so it can
-    be used in non-C/C++ files. Back ported from libpng 1.7.
-  Made sRGB check numbers consistent.
-  Ported libpng 1.5 options.awk/dfn file handling to 1.6, fixed one bug.
-  Removed cc -E workround, corrected png_get_palette_max API Tested on
-    SUN OS cc 5.9, which demonstrates the tokenization problem previously
-    avoided by using /lib/cpp.  Since all .dfn output is now protected in
-    double quotes unless it is to be macro substituted the fix should
-    work everywhere.
-  Enabled parallel tests - back ported from libpng-1.7.
-  scripts/pnglibconf.dfa formatting improvements back ported from libpng17.
+Version 1.7.0beta02 [February 18, 2013]
   Fixed a race condition in the creation of the build 'scripts' directory
     while building with a parallel make.
   Use approved/supported Android method to check for NEON, use Linux/POSIX
     1003.1 API to check /proc/self/auxv avoiding buffer allocation and other
     library calls (ported from libpng15).
-
-Version 1.6.1beta02 [February 19, 2013]
   Use parentheses more consistently in "#if defined(MACRO)" tests.
   Folded long lines.
-  Reenabled code to allow zero length PLTE chunks for MNG.
 
-Version 1.6.1beta03 [February 22, 2013]
+Version 1.7.0beta03 [February 22, 2013]
+  Reenabled code to allow zero length PLTE chunks for MNG.
   Fixed ALIGNED_MEMORY support.
   Allow run-time ARM NEON checking to be disabled. A new configure option:
     --enable-arm-neon=always will stop the run-time checks. New checks
@@ -4418,27 +4478,28 @@
     for it on then the build will fail if it can't be done.)
   Updated the INSTALL document.
 
-Version 1.6.1beta04 [February 27, 2013]
+Version 1.7.0beta04 [February 27, 2013]
   Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES.
   Revised scripts/makefile.freebsd to respect ZLIBLIB and ZLIBINC.
   Revised scripts/dfn.awk to work with the buggy MSYS awk that has trouble
     with CRLF line endings.
 
-Version 1.6.1beta05 [March 1, 2013]
+Version 1.7.0beta05 [March 5, 2013]
   Avoid a possible memory leak in contrib/gregbook/readpng.c
-
-Version 1.6.1beta06 [March 4, 2013]
-  Better documentation of unknown handling API interactions.
+  Changed user chunk callback API to respect global and per chunk defaults.
+    Previously a return of 0 from a user chunk callback would result in the
+    chunk being saved (if this was safe, even if the chunk was unsafe-to-copy);
+    this change respects the defaults set by the application, so unknown chunks
+    can be discarded by default and known-safe ones preserved.
   Corrected Android builds and corrected libpng.vers with symbol
     prefixing. This adds an API to set optimization options externally,
     providing an alternative and general solution for the non-portable
     run-time tests used by the ARM Neon code.  It also makes those tests
-    compile and link on Android.
-  The order of settings vs options in pnglibconf.h is reversed to allow
-    settings to depend on options and options can now set (or override) the
-    defaults for settings.
+    compile and link on Android.  The order of settings vs options in
+    pnglibconf.h is reversed to allow settings to depend on options and
+    options can now set (or override) the defaults for settings.
 
-Version 1.6.1beta07 [March 7, 2013]
+Version 1.7.0beta06 [March 13, 2013]
   Corrected simplified API default gamma for color-mapped output, added
     a flag to change default. In 1.6.0 when the simplified API was used
     to produce color-mapped output from an input image with no gamma
@@ -4451,8 +4512,6 @@
     application/user to specify that 16-bit files contain sRGB data
     rather than the default linear.
   Fixed bugs in the pngpixel and makepng test programs.
-
-Version 1.6.1beta08 [March 7, 2013]
   Fixed CMakelists.txt to allow building a single variant of the library
     (Claudio Bley):
   Introduced a PNG_LIB_TARGETS variable that lists all activated library
@@ -4464,19 +4523,11 @@
     first argument. When symlinking the filename component of that path is
     determined and used as the link target.
   Use copy_if_different in the CREATE_SYMLINK macro.
-
-Version 1.6.1beta09 [March 13, 2013]
   Eliminated two warnings from the Intel C compiler. The warnings are
     technically valid, although a reasonable treatment of division would
     show it to be incorrect.
 
-Version 1.6.1rc01 [March 21, 2013]
-  No changes.
-
-Version 1.6.1 [March 28, 2013]
-  No changes.
-
-Version 1.6.2beta01 [April 14, 2013]
+Version 1.7.0beta07 [April 14, 2013]
   Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling.
   Fixed incorrect warning of excess deflate data. End condition - the
     warning would be produced if the end of the deflate stream wasn't read
@@ -4488,46 +4539,45 @@
   Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c
     (Flavio Medeiros).
   Corrected length written to uncompressed iTXt chunks (Samuli Suominen).
-    Bug was introduced in libpng-1.6.0.
 
-Version 1.6.2rc01 [April 18, 2013]
+Version 1.7.0beta08 [April 18, 2013]
   Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length
     written by libpng-1.6.0 and 1.6.1.
   Disallow storing sRGB information when the sRGB is not supported.
 
-Version 1.6.2rc02 [April 18, 2013]
-  Merge pngtest.c with libpng-1.7.0
-
-Version 1.6.2rc03 [April 22, 2013]
-  Trivial spelling cleanup.
-
-Version 1.6.2rc04 and 1.6.2rc05 [omitted]
-
-Version 1.6.2rc06 [April 24, 2013]
-  Reverted to version 1.6.2rc03.  Recent changes to arm/neon support
-    have been ported to libpng-1.7.0beta09 and will reappear in version
-    1.6.3beta01.
-
-Version 1.6.2 [April 25, 2013]
-  No changes.
-
-Version 1.6.3beta01 [April 25, 2013]
+Version 1.7.0beta09 [April 24, 2013]
+  Exposed PNG chunk types in png.h
+  Modified png_uint_32 macros/code to make as few assumptions as possible
+    about the hardware.
   Revised stack marking in arm/filter_neon.S and configure.ac.
   Ensure that NEON filter stuff is completely disabled when switched 'off'.
     Previously the ARM NEON specific files were still built if the option
     was switched 'off' as opposed to being explicitly disabled.
 
-Version 1.6.3beta02 [April 26, 2013]
-  Test for 'arm*' not just 'arm' in the host_cpu configure variable.
-  Rebuilt the configure scripts.
+Version 1.7.0beta10 [April 24, 2013]
+  Attempt to fix the PNG_ARM_NEON configuration mess.
 
-Version 1.6.3beta03 [April 30, 2013]
-  Expanded manual paragraph about writing private chunks, particularly
-    the need to call png_set_keep_unknown_chunks() when writing them.
+Version 1.7.0beta11 [April 26, 2013]
+  Test for 'arm*', not just 'arm' in the host_cpu configure variable.
+
+Version 1.7.0beta12 [April 30, 2013]
+  Added png_app_warning for out-of-range unknown chunk index in
+    png_set_unknown_chunk_location().
+  Expanded manual paragraph about writing private chunks.
   Avoid dereferencing NULL pointer possibly returned from
      png_create_write_struct() (Andrew Church).
 
-Version 1.6.3beta05 [May 9, 2013]
+Version 1.7.0beta13 [May 12, 2013]
+  Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the
+    right zlib header files.
+  Separated CPPFLAGS and CFLAGS in contrib/pngminim/*/makefile
+  Updated contrib/pngminus/pnm2png.c (Paul Stewart):
+    Check for EOF
+    Ignore "#" delimited comments in input file to pnm2png.c.
+    Fixed whitespace handling
+    Added a call to png_set_packing()
+    Initialize dimension values so if sscanf fails at least we have known
+      invalid values.
   Calculate our own zlib windowBits when decoding rather than trusting the
     CMF bytes in the PNG datastream.
   Added an option to force maximum window size for inflating, which was
@@ -4539,15 +4589,6 @@
     only works with libpng versions that can be made to reliably fail when
     the deflate data contains an out-of-window reference.  This means only
     1.6 and later.
-  Fixed gnu issues: g++ needs a static_cast, gcc 4.4.7 has a broken warning
-    message which it is easier to work round than ignore.
-  Updated contrib/pngminus/pnm2png.c (Paul Stewart):
-    Check for EOF
-    Ignore "#" delimited comments in input file to pnm2png.c.
-    Fixed whitespace handling
-    Added a call to png_set_packing()
-    Initialize dimension values so if sscanf fails at least we have known
-      invalid values.
   Attempt to detect configuration issues with png-fix-too-far-back, which
     requires both the correct libpng and the correct zlib to function
     correctly.
@@ -4555,21 +4596,11 @@
   Added information in the documentation about problems with and fixes for
     the bad CRC and bad iTXt chunk situations.
 
-Version 1.6.3beta06 [May 12, 2013]
-  Allow contrib/pngminus/pnm2png.c to compile without WRITE_INVERT and
-    WRITE_PACK supported (writes error message that it can't read P1 or
-    P4 PBM files).
-  Improved png-fix-too-far-back usage message, added --suffix option.
-  Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the
-    right zlib header files.
-  Separated CPPFLAGS and CFLAGS in contrib/pngminim/*/makefile
-
-Version 1.6.3beta07 [June 8, 2013]
+Version 1.7.0beta14 [June 8, 2013]
   Removed a redundant test in png_set_IHDR().
   Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt)
   Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt
-  Enclose the prototypes for the simplified write API in
-    #ifdef PNG_STDIO_SUPPORTED/#endif
+  Enclose the prototypes for the simplified write API in #ifdef STDIO/#endif
   Make ARM NEON support work at compile time (not just configure time).
     This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when
     using a compiler that compiles for multiple architectures at one time.
@@ -4589,79 +4620,50 @@
     the confusion that would result by declaring the init function even when
     it is not used, so that it will always get prefixed.
 
-Version 1.6.3beta08 [June 18, 2013]
+Version 1.7.0beta15 [June 18, 2013]
   Revised libpng.3 so that "doclifter" can process it.
 
-Version 1.6.3beta09 [June 27, 2013]
+Version 1.7.0beta16 [July 5, 2013]
   Revised example.c to illustrate use of PNG_DEFAULT_sRGB and PNG_GAMMA_MAC_18
     as parameters for png_set_gamma().  These have been available since
     libpng-1.5.4.
   Renamed contrib/tools/png-fix-too-far-back.c to pngfix.c and revised it
     to check all compressed chunks known to libpng.
-
-Version 1.6.3beta10 [July 5, 2013]
   Updated documentation to show default behavior of benign errors correctly.
-  Only compile ARM code when PNG_READ_SUPPORTED is defined.
-  Fixed undefined behavior in contrib/tools/pngfix.c and added new strip
-    option. pngfix relied on undefined behavior and even a simple change from
-    gcc to g++ caused it to fail.  The new strip option 'unsafe' has been
-    implemented and is the default if --max is given.  Option names have
-    been clarified, with --strip=transform now stripping the bKGD chunk,
-    which was stripped previously with --strip=unused.
-  Added all documented chunk types to pngpriv.h
-  Unified pngfix.c source with libpng17.
+  Added perfect hash code generation for lists of PNG chunks. This is
+    a work in progress; checked in for use in pngfix.c
+  Ported ARM no-read patch from libpng16.
+  Ported pngfix.c patches from libpng16.
 
-Version 1.6.3rc01 [July 11, 2013]
-  No changes.
-
-Version 1.6.3 [July 18, 2013]
+Version 1.7.0beta17 [August 21, 2013]
   Revised manual about changes in iTXt chunk handling made in libpng-1.6.0.
   Added "/* SAFE */" comments in pngrutil.c and pngrtran.c where warnings
     may be erroneously issued by code-checking applications.
-
-Version 1.6.4beta01 [August 21, 2013]
   Added information about png_set_options() to the manual.
   Delay calling png_init_filter_functions() until a row with nonzero filter
     is found.
 
-Version 1.6.4beta02 [August 30, 2013]
+Version 1.7.0beta18 [September 16, 2013]
   Fixed inconsistent conditional compilation of png_chunk_unknown_handling()
     prototype, definition, and usage.  Made it depend on
     PNG_HANDLE_AS_UNKNOWN_SUPPORTED everywhere.
 
-Version 1.6.4rc01 [September 5, 2013]
-  No changes.
-
-Version 1.6.4 [September 12, 2013]
-  No changes.
-
-Version 1.6.5 [September 14, 2013]
-  Removed two stray lines of code from arm/arm_init.c.
-
-Version 1.6.6 [September 16, 2013]
-  Removed two stray lines of code from arm/arm_init.c, again.
-
-Version 1.6.7beta01 [September 30, 2013]
-  Revised unknown chunk code to correct several bugs in the NO_SAVE_/NO_WRITE
-    combination
-  Allow HANDLE_AS_UNKNOWN to work when other options are configured off. Also
-    fixed the pngminim makefiles to work when $(MAKEFLAGS) contains stuff
-    which terminates the make options (as by default in recent versions of
-    Gentoo).
+Version 1.7.0beta19 [September 30, 2013]
+  Reverted the change to unknown handling #defines; the change breaks 'NOREAD'
+    builds.
+  Fixed default behavior of ARM_NEON_API. If the ARM NEON API option is
+    compiled without the CHECK option it defaulted to on, not off.
+  Catch up with recent libpng16 changes; unknown handling and spelling
+    corrections
   Avoid up-cast warnings in pngvalid.c. On ARM the alignment requirements of
     png_modifier are greater than that of png_store and as a consequence
     compilation of pngvalid.c results in a warning about increased alignment
-    requirements because of the bare cast to (png_modifier*). The code is safe,
-    because the pointer is known to point to a stack allocated png_modifier,
-    but this change avoids the warning.
-  Fixed default behavior of ARM_NEON_API. If the ARM NEON API option was
-    compiled without the CHECK option it defaulted to on, not off.
-  Check user callback behavior in pngunknown.c. Previous versions compiled
-    if SAVE_UNKNOWN was not available but did nothing since the callback
-    was never implemented.
-  Merged pngunknown.c with 1.7 version and back ported 1.7 improvements/fixes
+    requirements because of the bare cast to (png_modifier*).  The code is
+    safe, because the pointer is known to point to a stack allocated
+    png_modifier, but this change avoids the warning.
+  Fixed some grammatical changes and updated the png chunks list.
 
-Version 1.6.7beta02 [October 12, 2013]
+Version 1.7.0beta20 [October 13, 2013]
   Made changes for compatibility with automake 1.14:
     1) Added the 'compile' program to the list of programs that must be cleaned
        in autogen.sh
@@ -4687,15 +4689,13 @@
   Make autogen.sh work with automake 1.13 as well as 1.14. Do this by always
     removing the 1.14 'compile' script but never checking for it.
 
-Version 1.6.7beta03 [October 19, 2013]
+Version 1.7.0beta21 [November 2, 2013]
   Added ARMv8 support (James Yu <james.yu at linaro.org>).  Added file
     arm/filter_neon_intrinsics.c; enable with -mfpu=neon.
   Revised pngvalid to generate size images with as many filters as it can
     manage, limited by the number of rows.
   Cleaned up ARM NEON compilation handling. The tests are now in pngpriv.h
     and detect the broken GCC compilers.
-
-Version 1.6.7beta04 [October 26, 2013]
   Allow clang derived from older GCC versions to use ARM intrinsics. This
     causes all clang builds that use -mfpu=neon to use the intrinsics code,
     not the assembler code.  This has only been tested on iOS 7. It may be
@@ -4705,17 +4705,14 @@
     PNG_ARM_NEON_IMPLEMENTATION to the correct value (2 or 1).  This macro
     is undefined by default and the build type is selected in pngpriv.h.
 
-Version 1.6.7rc01 [November 2, 2013]
-  No changes.
-
-Version 1.6.7rc02 [November 7, 2013]
+Version 1.7.0beta22 [November 7, 2013]
   Fixed #include in filter_neon_intrinsics.c and ctype macros. The ctype char
     checking macros take an unsigned char argument, not a signed char.
 
-Version 1.6.7 [November 14, 2013]
-  No changes.
-
-Version 1.6.8beta01 [November 24, 2013]
+Version 1.7.0beta23 [November 24, 2013]
+  Changed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED in pngpread.c to
+    #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED to be consistent with
+    what is in pngpriv.h.
   Moved prototype for png_handle_unknown() in pngpriv.h outside of
     the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block.
   Added "-Wall" to CFLAGS in contrib/pngminim/*/makefile
@@ -4731,28 +4728,13 @@
     This reverts to the previous 'static' implementation and works round
     the 'unused static function' warning by using PNG_UNUSED().
 
-Version 1.6.8beta02 [November 30, 2013]
+Version 1.7.0beta24 [December 15, 2013]
   Removed or marked PNG_UNUSED some harmless "dead assignments" reported
     by clang scan-build.
   Changed tabs to 3 spaces in png_debug macros and changed '"%s"m'
     to '"%s" m' to improve portability among compilers.
   Changed png_free_default() to free() in pngtest.c
-
-Version 1.6.8rc01 [December 12, 2013]
   Tidied up pngfix inits and fixed pngtest no-write builds.
-
-Version 1.6.8rc02 [December 14, 2013]
-  Handle zero-length PLTE chunk or NULL palette with png_error()
-    instead of png_chunk_report(), which by default issues a warning
-    rather than an error, leading to later reading from a NULL pointer
-    (png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954
-    and VU#650142.  Libpng-1.6.1 through 1.6.7 are vulnerable.
-    Libpng-1.6.0 and earlier do not have this bug.
-
-Version 1.6.8 [December 19, 2013]
-  No changes.
-
-Version 1.6.9beta01 [December 26, 2013]
   Bookkeeping: Moved functions around (no changes). Moved transform
     function definitions before the place where they are called so that
     they can be made static. Move the intrapixel functions and the
@@ -4765,50 +4747,60 @@
     segment of the DLL by 1208 bytes, about 0.6%. It also simplifies
     maintenance by removing the declarations from pngpriv.h and allowing
     easier changes to the internal interfaces.
-  Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69
-    in the tar distributions.
+  Handle zero-length PLTE chunk or NULL palette with png_error()
+    instead of png_chunk_report(), which by default issues a warning
+    rather than an error, leading to later reading from a NULL pointer
+    (png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954
+    and VU#650142.  Libpng-1.6.1 through 1.6.7 and libpng-1.7.0beta03
+    through 1.7.0beta23 are vulnerable.  Libpng-1.6.0 and earlier do not
+    have the bug.
 
-Version 1.6.9beta02 [January 1, 2014]
-  Added checks for libpng 1.5 to pngvalid.c.  This supports the use of
-    this version of pngvalid in libpng 1.5
-  Merged with pngvalid.c from libpng-1.7 changes to create a single
-    pngvalid.c
+Version 1.7.0beta25 [December 26, 2013]
+  Merged files with version 1.6.8 that have not changed since then.
+  Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69
+
+Version 1.7.0beta26 [January 1, 2014]
+  Added libpng 1.5 checks to pngvalid.c
+  Merged with 1.5 and 1.6 changes to create a single pngvalid.c
+  Added dSIG to chunk list in png.h
   Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner).
-  Merged pngrio.c, pngtrans.c, pngwio.c, and pngerror.c with libpng-1.7.0
-  Merged libpng-1.7.0 changes to make no-interlace configurations work
-    with test programs.
-  Revised pngvalid.c to support libpng 1.5, which does not support the
-    PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when appropriate in
-    pngvalid.c
+  Merged pngrio.c, pngtrans.c, and pngwio.c with libpng-1.6.9
+  Fixed test programs for interlace options. Made pngvalid.c and
+    pngtest.c work correctly when READ_INTERLACING and/or WRITE_INTERLACING
+    are switched off.
+  Changed pngvalid.c to support libpng 1.5, which does not support
+    the PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when
+    appropriate in pngvalid.c
   Allow unversioned links created on install to be disabled in configure.
     In configure builds 'make install' changes/adds links like png.h
     and libpng.a to point to the newly installed, versioned, files (e.g.
     libpng17/png.h and libpng17.a). Three new configure options and some
     rearrangement of Makefile.am allow creation of these links to be disabled.
 
-Version 1.6.9beta03 [January 10, 2014]
+Version 1.7.0beta27 [January 10, 2014]
   Removed potentially misleading warning from png_check_IHDR().
 
-Version 1.6.9beta04 [January 20, 2014]
+Version 1.7.0beta28 [January 20, 2014]
   Updated scripts/makefile.* to use CPPFLAGS (Cosmin).
   Added clang attribute support (Cosmin).
 
-Version 1.6.9rc01 [January 28, 2014]
-  No changes.
+Version 1.7.0beta29 [January 30, 2014]
+  Quiet an uninitialized memory warning from VS2013 in png_get_png().
 
-Version 1.6.9rc02 [January 30, 2014]
-  Quiet an uninitialized memory warning from VC2013 in png_get_png().
-
-Version 1.6.9 [February 6, 2014]
-
-Version 1.6.10beta01 [February 9, 2014]
-  Backported changes from libpng-1.7.0beta30 and beta31:
+Version 1.7.0beta30 [February 2, 2014]
   Fixed a large number of instances where PNGCBAPI was omitted from
     function definitions.
-  Added pngimage test program for png_read_png() and png_write_png()
-    with two new test scripts.
+  Added pngimage test program for png_read_png and png_write_png. This
+    is a work-in-progress; no tests are run automatically at present and
+    the program by virtue of exhaustively testing all the transforms is
+    very slow.
+
+Version 1.7.0beta31 [February 6, 2014]
+  Make png_read_png() and png_write_png() prototypes in png.h depend
+    upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
   Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
     png_set_packing() in png_read_png().
+  Completed full working pngimage test program and added two test scripts.
   Fixed combination of ~alpha with shift. On read invert alpha, processing
     occurred after shift processing, which causes the final values to be
     outside the range that should be produced by the shift. Reversing the
@@ -4819,8 +4811,10 @@
     the read code to return an invalid sBIT chunk, which might lead to
     application errors or crashes.  Such chunks are now skipped (with
     chunk_benign_error).
-  Make png_read_png() and png_write_png() prototypes in png.h depend
-    upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
+  Restored a line, "c = b;", that was inadvertently deleted from the
+    PAETH filtering code from libpng-1.7.0beta24/pngrutil.c. Deleted
+    the other instance of "c = b;" which is the one that triggered a
+    scan-build warning.
   Support builds with unsupported PNG_TRANSFORM_* values.  All of the
     PNG_TRANSFORM_* values are always defined in png.h and, because they
     are used for both read and write in some cases, it is not reliable
@@ -4830,7 +4824,7 @@
     and it adds corresponding code to pngimage.c to handle such options
     by not attempting to test them.
 
-Version 1.6.10beta02 [February 23, 2014]
+Version 1.7.0beta32 [February 26, 2014]
   Moved redefines of png_error(), png_warning(), png_chunk_error(),
     and png_chunk_warning() from pngpriv.h to png.h to make them visible
     to libpng-calling applications.
@@ -4847,8 +4841,6 @@
     it more robust against future programming errors.
   Check for __has_extension before using it in pngconf.h, to
     support older Clang versions (Jeremy Sequoia).
-  Treat CRC error handling with png_set_crc_action(), instead of with
-    png_set_benign_errors(), which has been the case since libpng-1.6.0beta18.
   Use a user warning handler in contrib/gregbook/readpng2.c instead of default,
     so warnings will be put on stderr even if libpng has CONSOLE_IO disabled.
   Added png_ptr->process_mode = PNG_READ_IDAT_MODE in png_push_read_chunk
@@ -4857,157 +4849,52 @@
     This fixes CERT VU#684412 and CVE-2014-0333.
   Don't recognize known sRGB profiles as sRGB if they have been hacked,
     but don't reject them and don't issue a copyright violation warning.
-
-Version 1.6.10beta03 [February 25, 2014]
-  Moved some documentation from png.h to libpng.3 and libpng-manual.txt
   Minor editing of contrib/arm-neon/README and contrib/examples/*.c
+  Moved some documentation from png.h to libpng.3 and libpng-manual.txt
 
-Version 1.6.10rc01 [February 27, 2014]
+Version 1.7.0beta33 [February 27, 2014]
   Fixed typos in the manual and in scripts/pnglibconf.dfa (CFLAGS -> CPPFLAGS
     and PNG_USR_CONFIG -> PNG_USER_CONFIG).
 
-Version 1.6.10rc02 [February 28, 2014]
-  Removed unreachable return statement after png_chunk_error()
-    in pngrutil.c
-
-Version 1.6.10rc03 [March 4, 2014]
-  Un-deprecated png_data_freer().
-
-Version 1.6.10 [March 6, 2014]
-  No changes.
-
-Version 1.6.11beta01 [March 17, 2014]
+Version 1.7.0beta34 [March 17, 2014]
+  Treat CRC error handling with png_set_crc_action(), instead of with
+    png_set_benign_errors(), which has been the case since libpng-1.6.0beta18.
   Use "if (value != 0)" instead of "if (value)" consistently.
   Changed ZlibSrcDir from 1.2.5 to 1.2.8 in projects/vstudio.
   Moved configuration information from the manual to the INSTALL file.
 
-Version 1.6.11beta02 [April 6, 2014]
+Version 1.7.0beta35 [August 6, 2014]
   Removed #if/#else/#endif from inside two pow() calls in pngvalid.c because
     they were handled improperly by Portland Group's PGI-14.1 - PGI-14.3
     when using its "__builtin_pow()" function.
-  Silence 'unused parameter' build warnings (Cosmin Truta).
-  $(CP) is now used alongside $(RM_F).  Also, use 'copy' instead of 'cp'
-    where applicable, and applied other minor makefile changes (Cosmin).
-  Don't warn about invalid dimensions exceeding user limits (Cosmin).
+  Silence 'unused parameter' build warnings (Cosmin).
+  $(CP) is now used alongside $(RM_F).  Also, use 'copy' instead
+    of 'cp' where applicable, and applied other minor makefile changes.
+  Don't warn about invalid dimensions exceeding user limits.
   Allow an easy replacement of the default pre-built configuration
     header with a custom header, via the make PNGLIBCONF_H_PREBUILT
-    macro (Cosmin).
-
-Version 1.6.11beta03 [April 6, 2014]
+    macro.
   Fixed a typo in pngrutil.c, introduced in libpng-1.5.6, that interferes
     with "blocky" expansion of sub-8-bit interlaced PNG files (Eric Huss).
-  Optionally use  __builtin_bswap16() in png_do_swap().
-
-Version 1.6.11beta04 [April 19, 2014]
-  Made progressive reading of interlaced images consistent with the
-    behavior of the sequential reader and consistent with the manual, by
-    moving some code out of the PNG_READ_INTERLACING_SUPPORTED blocks. The
-    row_callback now receives the proper pass number and unexpanded rows, when
-    png_combine_row() isn't built or used, and png_set_interlace_handling()
-    is not called.
-  Allow PNG_sRGB_PROFILE_CHECKING = (-1) to mean no sRGB profile checking.
-
-Version 1.6.11beta05 [April 26, 2014]
-  Do not reject ICC V2 profiles that lack padding (Kai-Uwe Behrmann).
-  Relocated closing bracket of the sRGB profile test loop to avoid getting
-    "Not recognizing known sRGB profile that has been edited" warning for
-    ICC V2 profiles that lack the MD5 signature in the profile header.
-
-Version 1.6.11beta06 [May 19, 2014]
-  Added PNG_SKIP_sRGB_CHECK_PROFILE choice for png_set_option().
-
-Version 1.6.11rc01 [May 27, 2014]
-  No changes.
-
-Version 1.6.11rc02 [June 3, 2014]
-  Test ZLIB_VERNUM instead of PNG_ZLIB_VERNUM in contrib/tools/pngfix.c
-
-Version 1.6.11 [June 5, 2014]
-  No changes.
-
-Version 1.6.12rc01 [June 6, 2014]
-  Relocated new code from 1.6.11beta06 in png.c to a point after the
-    declarations (Max Stepin).
-
-Version 1.6.12rc02 [June 7, 2014]
-  Changed file permissions of contrib/tools/intgamma.sh,
-    test-driver, and compile from 0644 to 0755 (Cosmin).
-
-Version 1.6.12rc03 [June 8, 2014]
-  Ensure "__has_attribute()" macro exists before trying to use it with
-    old clang compilers (MacPorts Ticket #43939).
-
-Version 1.6.12 [June 12, 2014]
-  No changes.
-
-Version 1.6.13beta01 [July 4, 2014]
-  Quieted -Wsign-compare and -Wclobber compiler warnings in
-    contrib/pngminus/*.c
-  Added "(void) png_ptr;" where needed in contrib/gregbook to quiet
-    compiler complaints about unused pointers.
-  Split a long output string in contrib/gregbook/rpng2-x.c.
-  Added "PNG_SET_OPTION" requirement for sRGB chunk support to pnglibconf.dfa,
-    Needed for write-only support (John Bowler).
-  Changed "if defined(__ARM_NEON__)" to
-    "if (defined(__ARM_NEON__) || defined(__ARM_NEON))" (James Wu).
-  Fixed clang no-warning builds: png_digit was defined but never used.
-    
-Version 1.6.13beta02 [July 21, 2014]
-  Fixed an incorrect separator ("/" should be "\") in scripts/makefile.vcwin32
-    (bug report from Wolfgang S. Kechel).  Bug was introduced in libpng-1.6.11.
-    Also fixed makefile.bc32, makefile.bor, makefile.msc, makefile.intel, and
-    makefile.tc3 similarly.
-
-Version 1.6.13beta03 [August 3, 2014]
   Removed scripts/makefile.elf. It has not worked since libpng-1.5.0beta14
     due to elimination of the PNG_FUNCTION_EXPORT and PNG_DATA_EXPORT
     definitions from pngconf.h.
   Ensure that CMakeLists.txt makes the target "lib" directory before making
     symbolic link into it (SourceForge bug report #226 by Rolf Timmermans).
-
-Version 1.6.13beta04 [August 8, 2014]
   Added opinion that the ECCN (Export Control Classification Number) for
     libpng is EAR99 to the README file.
-  Eliminated use of "$<" in makefile explicit rules, when copying
-    $PNGLIBCONF_H_PREBUILT.  This does not work on some versions of make;
-    bug introduced in libpng version 1.6.11.
 
-Version 1.6.13rc01 [August 14, 2014]
-  Made "ccopts" agree with "CFLAGS" in scripts/makefile.hp* and makefile.*sunu
-
-Version 1.6.13 [August 21, 2014]
-  No changes.
-
-Version 1.6.14beta01 [September 14, 2014]
-  Guard usage of png_ptr->options with #ifdef PNG_SET_OPTION_SUPPORTED.
-  Do not build contrib/tools/pngfix.c when PNG_SETJMP_NOT_SUPPORTED,
-    to allow "make" to complete without setjmp support (bug report by
-    Claudio Fontana)
-  Add "#include <setjmp.h>" to contrib/tools/pngfix.c (John Bowler)
-
-Version 1.6.14beta02 [September 18, 2014]
-  Use nanosleep() instead of usleep() in contrib/gregbook/rpng2-x.c
-    because usleep() is deprecated.
-  Define usleep() in contrib/gregbook/rpng2-x.c if not already defined
-    in unistd.h and nanosleep() is not available; fixes error introduced
-    in libpng-1.6.13.
-  Disable floating point exception handling in pngvalid.c when
-    PNG_FLOATING_ARITHMETIC is not supported (bug report by "zootus
-    at users.sourceforge.net").
-
-Version 1.6.14beta03 [September 19, 2014]
-  Define FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in pngvalid.c if not
-    already defined.  Revert floating point exception handling in pngvalid.c
-    to version 1.6.14beta01 behavior.
-
-Version 1.6.14beta04 [September 27, 2014]
+Version 1.7.0beta36 [September 27, 2014]
+  Updated scripts/makefiles from libpng-1.6.13beta04.
+  Minor updates to the manual from libpng-1.6.14beta04.
   Fixed incorrect handling of the iTXt compression flag in pngrutil.c
     (bug report by Shunsaku Hirata).  Bug was introduced in libpng-1.6.0.
 
-Version 1.6.14beta05 [October 1, 2014]
-  Added "option READ_iCCP enables READ_COMPRESSED_TEXT" to pnglibconf.dfa
+Version 1.7.0beta37 [September 28, 2014]
+  Merged scripts/*, pngvalid.c and pngfix.c with libpng-1.6.14beta04.
 
-Version 1.6.14beta06 [October 5, 2014]
+Version 1.7.0beta38 [October 17, 2014]
+  Added "option READ_iCCP enables READ_COMPRESSED_TEXT" to pnglibconf.dfa
   Removed unused "text_len" parameter from private function png_write_zTXt().
   Conditionally compile some code in png_deflate_claim(), when
     PNG_WARNINGS_SUPPORTED and PNG_ERROR_TEXT_SUPPORTED are disabled.
@@ -5016,39 +4903,15 @@
     to pnglibconf.dfa.
   Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa,
     to make it possible to configure a libpng that supports iCCP but not TEXT.
-
-Version 1.6.14beta07 [October 7, 2014]
   Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa
   Only mark text chunks as written after successfully writing them.
 
-Version 1.6.14rc01 [October 15, 2014]
-  Fixed some typos in comments.
+Version 1.7.0beta39 [November 1, 2014]
+  Ported cosmetic changes from libpng-1.6.15beta02.
 
-Version 1.6.14rc02 [October 17, 2014]
-  Changed png_convert_to_rfc_1123() to png_convert_to_rfc_1123_buffer()
-    in the manual, to reflect the change made in libpng-1.6.0.
-  Updated README file to explain that direct access to the png_struct
-    and info_struct members has not been permitted since libpng-1.5.0.
-
-Version 1.6.14 [October 23, 2014]
-  No changes.
-
-Version 1.6.15beta01 [October 29, 2014]
-  Changed "if (!x)" to "if (x == 0)" and "if (x)" to "if (x != 0)"
-  Simplified png_free_data().
-  Added missing "ptr = NULL" after some instances of png_free().
-
-Version 1.6.15beta02 [November 1, 2014]
-  Changed remaining "if (!x)" to "if (x == 0)" and "if (x)" to "if (x != 0)"
-
-Version 1.6.15beta03 [November 3, 2014]
-  Added PNG_USE_ARM_NEON configuration flag (Marcin Juszkiewicz).
-
-Version 1.6.15beta04 [November 4, 2014]
-  Removed new PNG_USE_ARM_NEON configuration flag and made a one-line
-    revision to configure.ac to support ARM on aarch64 instead (John Bowler).
-
-Version 1.6.15beta05 [November 5, 2014]
+Version 1.7.0beta40 [November 6, 2014]
+  Made a one-line revision to configure.ac to support ARM on aarch64
+    (bug report by Marcin Juszkiewicz, fix by John Bowler).
   Use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING in
     example.c, pngtest.c, and applications in the contrib directory.
   Avoid out-of-bounds memory access in png_user_version_check().
@@ -5069,110 +4932,109 @@
     numeric constant.  This adds appropriate, safe, casts to make the
     warnings go away.
 
-Version 1.6.15beta06 [November 6, 2014]
-  Reverted use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING
-    in the manual, example.c, pngtest.c, and applications in the contrib
-    directory.  It was incorrect advice.
-
-Version 1.6.15beta07 [November 7, 2014]
-  Removed #ifdef PNG_16BIT_SUPPORTED/#endif around png_product2(); it is
-    needed by png_reciprocal2().
+Version 1.7.0beta41 [November 7, 2014]
   Added #ifdef PNG_16BIT_SUPPORTED/#endif around png_log16bit() and
     png_do_swap().
   Changed all "#endif /* PNG_FEATURE_SUPPORTED */" to "#endif /* FEATURE */"
 
-Version 1.6.15beta08 [November 8, 2014]
-  More housecleaning in *.h
-
-Version 1.6.15rc01 [November 13, 2014]
-
-Version 1.6.15rc02 [November 14, 2014]
+Version 1.7.0beta42 [November 20, 2014]
   The macros passed in the command line to Borland make were ignored if
     similarly-named macros were already defined in makefiles. This behavior
     is different from POSIX make and other make programs.  Surround the
     macro definitions with ifndef guards (Cosmin).
-
-Version 1.6.15rc03 [November 16, 2014]
   Added "-D_CRT_SECURE_NO_WARNINGS" to CFLAGS in scripts/makefile.vcwin32.
   Removed the obsolete $ARCH variable from scripts/makefile.darwin.
+  Merged clang no-warning fix from libpng-1.6.13: png_digit was defined
+    but never used in pngerror.c.
 
-Version 1.6.15 [November 20, 2014]
-  No changes.
-
-Version 1.6.16beta01 [December 14, 2014]
+Version 1.7.0beta43 [December 18, 2014]
   Added ".align 2" to arm/filter_neon.S to support old GAS assemblers that
     don't do alignment correctly.
-  Revised Makefile.am and scripts/symbols.dfn to work with MinGW/MSYS
-    (Bob Friesenhahn).
-
-Version 1.6.16beta02 [December 15, 2014]
-  Revised Makefile.am and scripts/*.dfn again to work with MinGW/MSYS;
-    renamed scripts/*.dfn to scripts/*.c (John Bowler).
-
-Version 1.6.16beta03 [December 21, 2014]
+  Revised Makefile.am and scripts/*.dfn to work with MinGW/MSYS;
+    renamed scripts/*.dfn to scripts/*.c (Bob Friesenhahn and John Bowler).
   Quiet a "comparison always true" warning in pngstest.c (John Bowler).
 
-Version 1.6.16rc01 [December 21, 2014]
+Version 1.7.0beta44 [December 23, 2014]
   Restored a test on width that was removed from png.c at libpng-1.6.9
     (Bug report by Alex Eubanks, CVE-2015-0973).
-
-Version 1.6.16rc02 [December 21, 2014]
-  Undid the update to pngrutil.c in 1.6.16rc01.
-
-Version 1.6.16rc03 [December 21, 2014]
   Fixed an overflow in png_combine_row() with very wide interlaced images
-    (Bug report and fix by John Bowler, CVE-2014-9495).
-
-Version 1.6.16 [December 22, 2014]
-  No changes.
-
-Version 1.6.17beta01 [January 29, 2015]
-  Removed duplicate PNG_SAFE_LIMITS_SUPPORTED handling from pngconf.h
+    (Bug report and fix by John Bowler, CVE-2014-9475).
   Corrected the width limit calculation in png_check_IHDR().
-  Removed user limits from pngfix. Also pass NULL pointers to
-    png_read_row to skip the unnecessary row de-interlace stuff.
-  Added testing of png_set_packing() to pngvalid.c
-  Regenerated configure scripts in the *.tar distributions with libtool-2.4.4
-  Implement previously untested cases of libpng transforms in pngvalid.c
-  Fixed byte order in 2-byte filler, in png_do_read_filler().
-  Made the check for out-of-range values in png_set_tRNS() detect
-    values that are exactly 2^bit_depth, and work on 16-bit platforms.
-  Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47.
-  Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
-    pngset.c to avoid warnings about dead code.
+  Removed extraneous handling of PNG_SAFE_LIMITS_SUPPORTED from pngconf.h
 
-Version 1.6.17beta02 [February 7, 2015]
-  Work around one more Coverity-scan dead-code warning.
-  Do not build png_product2() when it is unused.
-
-Version 1.6.17beta03 [February 17, 2015]
-  Display user limits in the output from pngtest.
+Version 1.7.0beta45 [December 28, 2014]
   Eliminated the PNG_SAFE_LIMITS macro and restored the 1-million-column
     and 1-million-row default limits in pnglibconf.dfa, that can be reset
     by the user at build time or run time.  This provides a more robust
     defense against DOS and as-yet undiscovered overflows.
+  Removed user limits from pngfix. Also pass NULL pointers to
+    png_read_row to skip the unnecessary row de-interlace stuff.
+  Added testing of png_set_packing() to pngvalid.c
 
-Version 1.6.17beta04 [February 21, 2015]
-  Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default.
+Version 1.7.0beta46 [January 2, 2015]
+  Regenerated configure scripts in the tar distributions with libtool-2.4.4
+  Implement previously untested cases of libpng transforms in pngvalid.c
+  Fixed byte order in 2-byte filler, in png_do_read_filler().
   Allow user to call png_get_IHDR() with NULL arguments (Reuben Hawkins).
+
+Version 1.7.0beta47 [January 29, 2015]
+  Made the check for out-of-range values in png_set_tRNS() detect
+    values that are exactly 2^bit_depth, and work on 16-bit platforms.
+  Added PNG_SKIP_sRGB_CHECK_PROFILE choice for png_set_option().
+  Report all IHDR errors before exiting png_check_IHDR().
+  Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47.
+  Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
+    pngset.c to avoid warnings about dead code.
+
+Version 1.7.0beta48 [February 7, 2015]
+  Work around one more Coverity-scan dead-code warning.
+  Do not build png_product2() when it is unused.
+
+Version 1.7.0beta49 [February 11, 2015]
+  Combined sub_row, up_row, avg_row, and paeth_row buffers into a
+    single try_row buffer.
+  Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default.
+  Consolidated redundant code in pngwutil.c
+  Deal with integer overflow of sum in pngwutil.c
+
+Version 1.7.0beta50 [February 15, 2015]
+  Combined sub_row, up_row, avg_row, and paeth_row buffers into a
+    single try_row buffer and in cases where two or more of those are
+    being tested, a second tst_row buffer.  This improves CPU speed
+    over that achieved by libpng-1.7.0beta49.
+
+Version 1.7.0beta51 [February 17, 2015]
+  Combined similar parts of png_write_find_filter() into a png_increase_lmins()
+    function.
+  Display user limits in the output from pngtest.
+  Replaced test for harmless integer overflow (wraparound) in pngwutil.c
+    with a method that prevents overflow and does not increase cpu usage
+    significantly.
+
+Version 1.7.0beta52 [February 21, 2015]
+  Added information about setjmp/simplified API interaction in the
+    manual page and INSTALL file. Added information about using
+    row_pointers with a single height*width*bpp allocated block
+    to the manual page.
   Rebuilt configure scripts with automake-1.15 and libtool-2.4.6
 
-Version 1.6.17beta05 [February 25, 2015]
+Version 1.7.0beta53 [February 23, 2015]
   Restored compiling of png_reciprocal2 with PNG_NO_16BIT.
 
-Version 1.6.17beta06 [February 27, 2015]
+Version 1.7.0beta54 [March 4, 2015]
   Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block
     of png.h.
+  Conditionally compile a small amount of code in pngwutil.c
   Avoid runtime checks when converting integer to png_byte with
     Visual Studio (Sergey Kosarevsky)
+  Merged pngwrite.c with libpng-1.6.17beta06/pngwrite.c
 
-Version 1.6.17rc01 [March 4, 2015]
-  No changes.
-
-Version 1.6.17rc02 [March 9, 2015]
+Version 1.7.0beta55 [March 9, 2015]
   Removed some comments that the configure script did not handle
     properly from scripts/pnglibconf.dfa and pnglibconf.h.prebuilt.
-  Free the unknown_chunks structure even when it contains no data.
+  Spelling fixes ("then", "occured") reported by Lauri Nurmi.
+  Added more error reporting in png_default_read_data().
+  Merged png_free_data() with libpng-1.6.17rc02.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
@@ -5181,3 +5043,4 @@
 or to glennrp at users.sourceforge.net
 
 Glenn R-P
+#endif
diff --git a/LICENSE b/LICENSE
index 69f993e..630eda5 100644
--- a/LICENSE
+++ b/LICENSE
@@ -10,7 +10,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.7.0beta55, March 4, 2015, are
+libpng versions 1.2.6, August 15, 2004, through 1.7.0beta55, March 9, 2015, are
 Copyright (c) 2004, 2006-2015 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.2.5
 with the following individual added to the list of Contributing Authors
@@ -108,4 +108,4 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-March 4, 2015
+March 9, 2015
diff --git a/README b/README
index 92d8da7..e26286c 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.7.0beta55 - March 4, 2015 (shared library 17.0)
+README for libpng version 1.7.0beta55 - March 9, 2015 (shared library 17.0)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
diff --git a/contrib/tools/pngfix.c b/contrib/tools/pngfix.c
index fce56de..f788f0b 100644
--- a/contrib/tools/pngfix.c
+++ b/contrib/tools/pngfix.c
@@ -2138,7 +2138,7 @@
           *
           * z-rc is the zlib failure code; message is the error message with
           * spaces replaced by '-'.  The compressed byte count indicates where
-          * in the zlib stream the error occured.
+          * in the zlib stream the error occurred.
           */
          type_name(zlib->chunk->chunk_type, stdout);
          printf(" SKP %s %d %s ", zlib_flevel(zlib), zlib->file_bits,
@@ -3757,7 +3757,7 @@
 "  non-zero code is returned).",
 "    0x10: The file could not be read, even with corrections.",
 "    0x20: The output file could not be written.",
-"    0x40: An unexpected, potentially internal, error occured.",
+"    0x40: An unexpected, potentially internal, error occurred.",
 "  If the command line arguments are incorrect the program exits with exit",
 "  255.  Some older operating systems only support 7-bit exit codes, on those",
 "  systems it is suggested that this program is first tested by supplying",
diff --git a/libpng-manual.txt b/libpng-manual.txt
index ffdeb14..cec1c89 100644
--- a/libpng-manual.txt
+++ b/libpng-manual.txt
@@ -1,6 +1,6 @@
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.6.17rc02 - March 9, 2015
+ libpng version 1.7.0beta55 - March 9, 2015
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -11,15 +11,15 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.6.17rc02 - March 9, 2015
+ libpng versions 0.97, January 1998, through 1.7.0beta55 - March 9, 2015
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
- libpng 1.0 beta 6 - version 0.96 - May 28, 1997
+ libpng 1.0 beta 6  version 0.96 May 28, 1997
  Updated and distributed by Andreas Dilger
  Copyright (c) 1996, 1997 Andreas Dilger
 
- libpng 1.0 beta 2 - version 0.88 - January 26, 1996
+ libpng 1.0 beta 2 - version 0.88  January 26, 1996
  For conditions of distribution and use, see copyright
  notice in png.h. Copyright (c) 1995, 1996 Guy Eric
  Schalnat, Group 42, Inc.
@@ -42,10 +42,11 @@
     X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
    XI. Changes to Libpng from version 1.4.x to 1.5.x
   XII. Changes to Libpng from version 1.5.x to 1.6.x
- XIII. Detecting libpng
-  XIV. Source code repository
-   XV. Coding style
-  XVI. Y2K Compliance in libpng
+ XIII. Changes to Libpng from version 1.6.x to 1.7.x
+  XIV. Detecting libpng
+   XV. Source code repository
+  XVI. Coding style
+ XVII. Y2K Compliance in libpng
 
 I. Introduction
 
@@ -344,23 +345,22 @@
 to replace them with custom functions.  See the discussion under
 Customizing libpng.
 
+
     FILE *fp = fopen(file_name, "rb");
     if (!fp)
     {
        return (ERROR);
     }
 
-    if (fread(header, 1, number, fp) != number)
-    {
-       return (ERROR);
-    }
-
+    fread(header, 1, number, fp);
     is_png = !png_sig_cmp(header, 0, number);
+
     if (!is_png)
     {
        return (NOT_PNG);
     }
 
+
 Next, png_struct and png_info need to be allocated and initialized.  In
 order to ensure that the size of these structures is correct even with a
 dynamically linked libpng, there are functions to initialize and
@@ -428,12 +428,16 @@
 
 If you would rather avoid the complexity of setjmp/longjmp issues,
 you can compile libpng with PNG_NO_SETJMP, in which case
-errors will result in a call to PNG_ABORT() which defaults to abort().
+errors will result in a call to PNG_ABORT which defaults to abort().
 
-You can #define PNG_ABORT() to a function that does something
+You can #define PNG_ABORT to a function or other C code that does something
 more useful than abort(), as long as your function does not
 return.
 
+If you do this, you cannot #define PNG_SIMPLIFIED_READ_SUPPORTED or
+PNG_SIMPLIFIED_WRITE_SUPPORTED, because the simplified API requires
+setjmp() support.
+
 Now you need to set up the input code.  The default for libpng is to
 use the C function fread().  If you use this, you will need to pass a
 valid FILE * in the function png_init_io().  Be sure that the file is
@@ -525,15 +529,15 @@
 
     png_get_user_chunk_ptr(png_ptr);
 
-If you call the png_set_read_user_chunk_fn() function, then all unknown
-chunks which the callback does not handle will be saved when read.  You can
-cause them to be discarded by returning '1' ("handled") instead of '0'.  This
-behavior will change in libpng 1.7 and the default handling set by the
-png_set_keep_unknown_chunks() function, described below, will be used when the
-callback returns 0.  If you want the existing behavior you should set the global
-default to PNG_HANDLE_CHUNK_IF_SAFE now; this is compatible with all current
-versions of libpng and with 1.7.  Libpng 1.6 issues a warning if you keep the
-default, or PNG_HANDLE_CHUNK_NEVER, and the callback returns 0.
+If you call the png_set_read_user_chunk_fn() function, then all unknown chunks
+will be passed to your callback when read.  You can cause known chunks to be
+passed in as well by using png_set_keep_unknown_chunks (see below) - this will
+prevent the normal libpng handling of those known chunks.
+
+If your callback returns 0 the default unknown handling will be used (see
+below).  This is new behavior in libpng 1.7, prior to 1.7 it was not possible to
+discard a chunk; PNG_HANDLE_CHUNK_IF_SAFE was forced.  Libpng 1.6.0 issues a
+warning when this was done.
 
 At this point, you can set up a callback function that will be
 called after each row has been read, which you can use to control
@@ -632,10 +636,8 @@
     ...
 
     #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
-      /* ignore all unknown chunks
-       * (use global setting "2" for libpng16 and earlier):
-       */
-      png_set_keep_unknown_chunks(read_ptr, 2, NULL, 0);
+      /* ignore all unknown chunks: */
+      png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
 
       /* except for vpAg: */
       png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
@@ -649,12 +651,15 @@
 
 The PNG specification allows the width and height of an image to be as
 large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
+Since very few applications really need to process such large images,
+we have imposed an arbitrary 1,000,000 limit on rows and columns.
 Larger images will be rejected immediately with a png_error() call. If
-you wish to change these limits, you can use
+you wish to change this limit, you can use
 
    png_set_user_limits(png_ptr, width_max, height_max);
 
-to set your own limits (libpng may reject some very wide images
+to set your own limits, or use width_max = height_max = 0x7fffffffL
+to allow all valid dimensions (libpng may reject some very large images
 anyway because of potential buffer overflow conditions).
 
 You should put this statement after you create the PNG structure and
@@ -1180,7 +1185,10 @@
    png_set_rows(png_ptr, info_ptr, &row_pointers);
 
 Alternatively you could allocate your image in one big block and define
-row_pointers[i] to point into the proper places in your block.
+row_pointers[i] to point into the proper places in your block.  If
+you do this, be sure to call png_read_update_info() described below,
+to update the "rowbytes" value to account for any transformations that
+change the number of bytes per row before you use it to allocate your block.
 
 If you use png_set_rows(), the application is responsible for freeing
 row_pointers (and row_pointers[i], if they were separately allocated).
@@ -1269,12 +1277,13 @@
     interlace_type, compression_type, or filter_method can
     be NULL if you are not interested in their values.
 
-    Note that png_get_IHDR() returns 32-bit data into
+    Note that png_get_IHDR() returns png_uint_32 data into
     the application's width and height variables.
     This is an unsafe situation if these are not png_uint_32
-    variables.  In such situations, the
-    png_get_image_width() and png_get_image_height()
-    functions described below are safer.
+    variables, or if they are 32-bit variables on a 64-bit
+    platform.  In such situations, the png_get_image_width()
+    and png_get_image_height() functions described below are
+    safer.
 
     width            = png_get_image_width(png_ptr,
                          info_ptr);
@@ -2737,11 +2746,10 @@
 
 If you would rather avoid the complexity of setjmp/longjmp issues,
 you can compile libpng with PNG_NO_SETJMP, in which case
-errors will result in a call to PNG_ABORT() which defaults to abort().
+errors will result in a call to PNG_ABORT which defaults to abort().
 
-You can #define PNG_ABORT() to a function that does something
-more useful than abort(), as long as your function does not
-return.
+You can #define PNG_ABORT to a function or other C code that does something
+more useful than abort(), as long as your function does not return.
 
 Checking for invalid palette index on write was added at libpng
 1.5.10.  If a pixel contains an invalid (out-of-range) index libpng issues
@@ -3259,7 +3267,7 @@
 although this isn't a requirement.  Unlike the tIME chunk, the
 "Creation Time" tEXt chunk is not expected to be automatically changed
 by the software.  To facilitate the use of RFC 1123 dates, a function
-png_convert_to_rfc1123_buffer(buffer, png_timep) is provided to
+png_convert_to_rfc1123_buffer(png_ptr, buffer, png_timep) is provided to
 convert from PNG time to an RFC 1123 format string.  The caller must provide
 a writeable buffer of at least 29 bytes.
 
@@ -4159,7 +4167,7 @@
 Errors handled through png_error() are fatal, meaning that png_error()
 should never return to its caller.  Currently, this is handled via
 setjmp() and longjmp() (unless you have compiled libpng with
-PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
+PNG_NO_SETJMP, in which case it is handled via PNG_ABORT),
 but you could change this to do things like exit() if you should wish,
 as long as your function does not return.
 
@@ -5061,6 +5069,7 @@
 and is interpreted by libpng to convey a one-tracer-curve gray profile or a
 three-tracer-curve RGB profile as appropriate.
 
+
 Prior to libpng-1.6.0 a warning would be issued if the iTXt chunk contained
 an empty language field or an empty translated keyword.  Both of these
 are allowed by the PNG specification, so these warnings are no longer issued.
@@ -5109,7 +5118,55 @@
 chunk.  This error was fixed in libpng-1.6.3, and a tool (called
 contrib/tools/png-fix-itxt) has been added to the libpng distribution.
 
-XIII.  Detecting libpng
+Starting with libpng-1.6.17, the PNG_SAFE_LIMITS macro was eliminated
+and safe limits are used by default (users who need larger limits
+can still override them at compile time or run time, as described above).
+
+The new limits are
+                                default   spec limit
+   png_user_width_max         1,000,000  2,147,483,647
+   png_user_height_max        1,000,000  2,147,483,647
+   png_user_chunk_cache_max         128  unlimited
+   png_user_chunk_malloc_max  8,000,000  unlimited
+
+XIII.  Changes to Libpng from version 1.6.x to 1.7.x
+
+Some functions that were deprecated in libpng-1.6.0 were removed:
+    png_reset_zstream(),
+    png_info_init_3(),
+    png_data_freer() and its associated flags,
+    png_malloc_default(),
+    and png_free_default().
+
+The PNG_ABORT() macro was changed to PNG_ABORT, and the default is now
+"abort()" for all platforms (previously it was "ExitProcess(0)" on
+Windows platforms).  Starting with libpng-1.7.0 you have to define
+PNG_ABORT instead of PNG_ABORT(), and you must include a terminating
+semicolon in your definition, e.g.,
+
+    #if PNGCRUSH_LIBPNG_VER >= 10700
+    #  ifdef _WINDOWS_
+    #    define PNG_ABORT ExitProcess(0);
+    #  else
+    #    define PNG_ABORT abort();
+    #  endif
+    #else
+    #  ifdef _WINDOWS_
+    #    define PNG_ABORT() ExitProcess(0)
+    #  else
+    #    define PNG_ABORT() abort()
+    #  endif
+    #endif
+
+The png_get_IHDR() function now allows users to supply NULL for any
+argument in which they aren't interested.  Previously, the width, height,
+bit_depth, and color_type arguments were not allowed to be NULL.
+
+The 8-bit compose and rgb_to_grayscale operations were made more accurate.
+While these did not introduce API incompatibility, there may be differences
+in unit test results.
+
+XIV.  Detecting libpng
 
 The png_get_io_ptr() function has been present since libpng-0.88, has never
 changed, and is unaffected by conditional compilation macros.  It is the
@@ -5142,7 +5199,7 @@
 SourceForge bug tracker, to the png-mng-implement at lists.sf.net
 mailing list, or directly to glennrp.
 
-XV. Coding style
+XVI. Coding style
 
 Our coding style is similar to the "Allman" style
 (See http://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly
@@ -5277,7 +5334,7 @@
 
 Other rules can be inferred by inspecting the libpng source.
 
-XVI. Y2K Compliance in libpng
+XVII. Y2K Compliance in libpng
 
 March 9, 2015
 
@@ -5285,7 +5342,7 @@
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.6.17rc02 are Y2K compliant.  It is my belief that earlier
+upward through 1.7.0beta55 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has two year fields.  One is a 2-byte unsigned integer
@@ -5301,9 +5358,8 @@
 
 There are seven time-related functions:
 
-    png_convert_to_rfc_1123_buffer() in png.c
-      (formerly png_convert_to_rfc_1152() in error, and
-      also formerly png_convert_to_rfc_1123())
+    png_convert_to_rfc_1123() in png.c
+      (formerly png_convert_to_rfc_1152() in error)
     png_convert_from_struct_tm() in pngwrite.c, called
       in pngwrite.c
     png_convert_from_time_t() in pngwrite.c
diff --git a/libpng.3 b/libpng.3
index 8530739..349e9ff 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
 .TH LIBPNG 3 "March 9, 2015"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.6.17rc02
+libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta55
 .SH SYNOPSIS
 \fB
 #include <png.h>\fP
@@ -23,7 +23,7 @@
 
 \fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
 
-\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
+\fBpng_charp png_convert_to_rfc1123_buffer (png_structp \fP\fIpng_ptr\fP\fB, char \fP\fIout[29]\fP\fB, png_timep \fIptime\fP\fB);\fP
 
 \fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
 
@@ -35,8 +35,6 @@
 
 \fBpng_structp png_create_write_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
 
-\fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP
-
 \fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
 
 \fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP
@@ -51,8 +49,6 @@
 
 \fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
 
-\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
-
 \fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
 
 \fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
@@ -229,16 +225,12 @@
 
 \fBint png_image_write_to_stdio (png_imagep \fP\fIimage\fP\fB, FILE \fP\fI*file\fP\fB, int \fP\fIconvert_to_8_bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fP\fIrow_stride\fP\fB, void \fI*colormap)\fP\fB);\fP
 
-\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
-
 \fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
 
 \fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
 
 \fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
 
-\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
-
 \fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
 
 \fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP
@@ -265,8 +257,6 @@
 
 \fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
 
-\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
-
 \fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
 
 \fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
@@ -504,7 +494,7 @@
 .SH LIBPNG.TXT
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.6.17rc02 - March 9, 2015
+ libpng version 1.7.0beta55 - March 9, 2015
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -515,15 +505,15 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.6.17rc02 - March 9, 2015
+ libpng versions 0.97, January 1998, through 1.7.0beta55 - March 9, 2015
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
- libpng 1.0 beta 6 - version 0.96 - May 28, 1997
+ libpng 1.0 beta 6  version 0.96 May 28, 1997
  Updated and distributed by Andreas Dilger
  Copyright (c) 1996, 1997 Andreas Dilger
 
- libpng 1.0 beta 2 - version 0.88 - January 26, 1996
+ libpng 1.0 beta 2 - version 0.88  January 26, 1996
  For conditions of distribution and use, see copyright
  notice in png.h. Copyright (c) 1995, 1996 Guy Eric
  Schalnat, Group 42, Inc.
@@ -546,10 +536,11 @@
     X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
    XI. Changes to Libpng from version 1.4.x to 1.5.x
   XII. Changes to Libpng from version 1.5.x to 1.6.x
- XIII. Detecting libpng
-  XIV. Source code repository
-   XV. Coding style
-  XVI. Y2K Compliance in libpng
+ XIII. Changes to Libpng from version 1.6.x to 1.7.x
+  XIV. Detecting libpng
+   XV. Source code repository
+  XVI. Coding style
+ XVII. Y2K Compliance in libpng
 
 .SH I. Introduction
 
@@ -848,23 +839,22 @@
 to replace them with custom functions.  See the discussion under
 Customizing libpng.
 
+
     FILE *fp = fopen(file_name, "rb");
     if (!fp)
     {
        return (ERROR);
     }
 
-    if (fread(header, 1, number, fp) != number)
-    {
-       return (ERROR);
-    }
-
+    fread(header, 1, number, fp);
     is_png = !png_sig_cmp(header, 0, number);
+
     if (!is_png)
     {
        return (NOT_PNG);
     }
 
+
 Next, png_struct and png_info need to be allocated and initialized.  In
 order to ensure that the size of these structures is correct even with a
 dynamically linked libpng, there are functions to initialize and
@@ -932,12 +922,16 @@
 
 If you would rather avoid the complexity of setjmp/longjmp issues,
 you can compile libpng with PNG_NO_SETJMP, in which case
-errors will result in a call to PNG_ABORT() which defaults to abort().
+errors will result in a call to PNG_ABORT which defaults to abort().
 
-You can #define PNG_ABORT() to a function that does something
+You can #define PNG_ABORT to a function or other C code that does something
 more useful than abort(), as long as your function does not
 return.
 
+If you do this, you cannot #define PNG_SIMPLIFIED_READ_SUPPORTED or
+PNG_SIMPLIFIED_WRITE_SUPPORTED, because the simplified API requires
+setjmp() support.
+
 Now you need to set up the input code.  The default for libpng is to
 use the C function fread().  If you use this, you will need to pass a
 valid FILE * in the function png_init_io().  Be sure that the file is
@@ -1029,15 +1023,15 @@
 
     png_get_user_chunk_ptr(png_ptr);
 
-If you call the png_set_read_user_chunk_fn() function, then all unknown
-chunks which the callback does not handle will be saved when read.  You can
-cause them to be discarded by returning '1' ("handled") instead of '0'.  This
-behavior will change in libpng 1.7 and the default handling set by the
-png_set_keep_unknown_chunks() function, described below, will be used when the
-callback returns 0.  If you want the existing behavior you should set the global
-default to PNG_HANDLE_CHUNK_IF_SAFE now; this is compatible with all current
-versions of libpng and with 1.7.  Libpng 1.6 issues a warning if you keep the
-default, or PNG_HANDLE_CHUNK_NEVER, and the callback returns 0.
+If you call the png_set_read_user_chunk_fn() function, then all unknown chunks
+will be passed to your callback when read.  You can cause known chunks to be
+passed in as well by using png_set_keep_unknown_chunks (see below) - this will
+prevent the normal libpng handling of those known chunks.
+
+If your callback returns 0 the default unknown handling will be used (see
+below).  This is new behavior in libpng 1.7, prior to 1.7 it was not possible to
+discard a chunk; PNG_HANDLE_CHUNK_IF_SAFE was forced.  Libpng 1.6.0 issues a
+warning when this was done.
 
 At this point, you can set up a callback function that will be
 called after each row has been read, which you can use to control
@@ -1136,10 +1130,8 @@
     ...
 
     #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
-      /* ignore all unknown chunks
-       * (use global setting "2" for libpng16 and earlier):
-       */
-      png_set_keep_unknown_chunks(read_ptr, 2, NULL, 0);
+      /* ignore all unknown chunks: */
+      png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
 
       /* except for vpAg: */
       png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
@@ -1153,12 +1145,15 @@
 
 The PNG specification allows the width and height of an image to be as
 large as 2^(31\-1 (0x7fffffff), or about 2.147 billion rows and columns.
+Since very few applications really need to process such large images,
+we have imposed an arbitrary 1,000,000 limit on rows and columns.
 Larger images will be rejected immediately with a png_error() call. If
-you wish to change these limits, you can use
+you wish to change this limit, you can use
 
    png_set_user_limits(png_ptr, width_max, height_max);
 
-to set your own limits (libpng may reject some very wide images
+to set your own limits, or use width_max = height_max = 0x7fffffffL
+to allow all valid dimensions (libpng may reject some very large images
 anyway because of potential buffer overflow conditions).
 
 You should put this statement after you create the PNG structure and
@@ -1684,7 +1679,10 @@
    png_set_rows(png_ptr, info_ptr, &row_pointers);
 
 Alternatively you could allocate your image in one big block and define
-row_pointers[i] to point into the proper places in your block.
+row_pointers[i] to point into the proper places in your block.  If
+you do this, be sure to call png_read_update_info() described below,
+to update the "rowbytes" value to account for any transformations that
+change the number of bytes per row before you use it to allocate your block.
 
 If you use png_set_rows(), the application is responsible for freeing
 row_pointers (and row_pointers[i], if they were separately allocated).
@@ -1773,12 +1771,13 @@
     interlace_type, compression_type, or filter_method can
     be NULL if you are not interested in their values.
 
-    Note that png_get_IHDR() returns 32-bit data into
+    Note that png_get_IHDR() returns png_uint_32 data into
     the application's width and height variables.
     This is an unsafe situation if these are not png_uint_32
-    variables.  In such situations, the
-    png_get_image_width() and png_get_image_height()
-    functions described below are safer.
+    variables, or if they are 32-bit variables on a 64-bit
+    platform.  In such situations, the png_get_image_width()
+    and png_get_image_height() functions described below are
+    safer.
 
     width            = png_get_image_width(png_ptr,
                          info_ptr);
@@ -3241,11 +3240,10 @@
 
 If you would rather avoid the complexity of setjmp/longjmp issues,
 you can compile libpng with PNG_NO_SETJMP, in which case
-errors will result in a call to PNG_ABORT() which defaults to abort().
+errors will result in a call to PNG_ABORT which defaults to abort().
 
-You can #define PNG_ABORT() to a function that does something
-more useful than abort(), as long as your function does not
-return.
+You can #define PNG_ABORT to a function or other C code that does something
+more useful than abort(), as long as your function does not return.
 
 Checking for invalid palette index on write was added at libpng
 1.5.10.  If a pixel contains an invalid (out-of-range) index libpng issues
@@ -3763,7 +3761,7 @@
 although this isn't a requirement.  Unlike the tIME chunk, the
 "Creation Time" tEXt chunk is not expected to be automatically changed
 by the software.  To facilitate the use of RFC 1123 dates, a function
-png_convert_to_rfc1123_buffer(buffer, png_timep) is provided to
+png_convert_to_rfc1123_buffer(png_ptr, buffer, png_timep) is provided to
 convert from PNG time to an RFC 1123 format string.  The caller must provide
 a writeable buffer of at least 29 bytes.
 
@@ -4663,7 +4661,7 @@
 Errors handled through png_error() are fatal, meaning that png_error()
 should never return to its caller.  Currently, this is handled via
 setjmp() and longjmp() (unless you have compiled libpng with
-PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
+PNG_NO_SETJMP, in which case it is handled via PNG_ABORT),
 but you could change this to do things like exit() if you should wish,
 as long as your function does not return.
 
@@ -5565,6 +5563,7 @@
 and is interpreted by libpng to convey a one-tracer-curve gray profile or a
 three-tracer-curve RGB profile as appropriate.
 
+
 Prior to libpng-1.6.0 a warning would be issued if the iTXt chunk contained
 an empty language field or an empty translated keyword.  Both of these
 are allowed by the PNG specification, so these warnings are no longer issued.
@@ -5613,7 +5612,55 @@
 chunk.  This error was fixed in libpng-1.6.3, and a tool (called
 contrib/tools/png-fix-itxt) has been added to the libpng distribution.
 
-.SH XIII.  Detecting libpng
+Starting with libpng-1.6.17, the PNG_SAFE_LIMITS macro was eliminated
+and safe limits are used by default (users who need larger limits
+can still override them at compile time or run time, as described above).
+
+The new limits are
+                                default   spec limit
+   png_user_width_max         1,000,000  2,147,483,647
+   png_user_height_max        1,000,000  2,147,483,647
+   png_user_chunk_cache_max         128  unlimited
+   png_user_chunk_malloc_max  8,000,000  unlimited
+
+.SH XIII.  Changes to Libpng from version 1.6.x to 1.7.x
+
+Some functions that were deprecated in libpng-1.6.0 were removed:
+    png_reset_zstream(),
+    png_info_init_3(),
+    png_data_freer() and its associated flags,
+    png_malloc_default(),
+    and png_free_default().
+
+The PNG_ABORT() macro was changed to PNG_ABORT, and the default is now
+"abort()" for all platforms (previously it was "ExitProcess(0)" on
+Windows platforms).  Starting with libpng-1.7.0 you have to define
+PNG_ABORT instead of PNG_ABORT(), and you must include a terminating
+semicolon in your definition, e.g.,
+
+    #if PNGCRUSH_LIBPNG_VER >= 10700
+    #  ifdef _WINDOWS_
+    #    define PNG_ABORT ExitProcess(0);
+    #  else
+    #    define PNG_ABORT abort();
+    #  endif
+    #else
+    #  ifdef _WINDOWS_
+    #    define PNG_ABORT() ExitProcess(0)
+    #  else
+    #    define PNG_ABORT() abort()
+    #  endif
+    #endif
+
+The png_get_IHDR() function now allows users to supply NULL for any
+argument in which they aren't interested.  Previously, the width, height,
+bit_depth, and color_type arguments were not allowed to be NULL.
+
+The 8-bit compose and rgb_to_grayscale operations were made more accurate.
+While these did not introduce API incompatibility, there may be differences
+in unit test results.
+
+.SH XIV.  Detecting libpng
 
 The png_get_io_ptr() function has been present since libpng-0.88, has never
 changed, and is unaffected by conditional compilation macros.  It is the
@@ -5646,7 +5693,7 @@
 SourceForge bug tracker, to the png-mng-implement at lists.sf.net
 mailing list, or directly to glennrp.
 
-.SH XV. Coding style
+.SH XVI. Coding style
 
 Our coding style is similar to the "Allman" style
 (See http://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly
@@ -5781,7 +5828,7 @@
 
 Other rules can be inferred by inspecting the libpng source.
 
-.SH XVI. Y2K Compliance in libpng
+.SH XVII. Y2K Compliance in libpng
 
 March 9, 2015
 
@@ -5789,7 +5836,7 @@
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.6.17rc02 are Y2K compliant.  It is my belief that earlier
+upward through 1.7.0beta55 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has two year fields.  One is a 2-byte unsigned integer
@@ -5805,9 +5852,8 @@
 
 There are seven time-related functions:
 
-    png_convert_to_rfc_1123_buffer() in png.c
-      (formerly png_convert_to_rfc_1152() in error, and
-      also formerly png_convert_to_rfc_1123())
+    png_convert_to_rfc_1123() in png.c
+      (formerly png_convert_to_rfc_1152() in error)
     png_convert_from_struct_tm() in pngwrite.c, called
       in pngwrite.c
     png_convert_from_time_t() in pngwrite.c
@@ -6013,7 +6059,7 @@
  1.6.5               16    10605  16.so.16.5[.0]
  1.6.6               16    10606  16.so.16.6[.0]
  1.6.7beta01-04      16    10607  16.so.16.7[.0]
- 1.6.7rc01-02        16    10607  16.so.16.7[.0]
+ 1.6.7rc01-03        16    10607  16.so.16.7[.0]
  1.6.7               16    10607  16.so.16.7[.0]
  1.6.8beta01-02      16    10608  16.so.16.8[.0]
  1.6.8rc01-02        16    10608  16.so.16.8[.0]
@@ -6027,7 +6073,7 @@
  1.6.11beta01-06     16    10611  16.so.16.11[.0]
  1.6.11rc01-02       16    10611  16.so.16.11[.0]
  1.6.11              16    10611  16.so.16.11[.0]
- 1.6.12rc01          16    10612  16.so.16.12[.0]
+ 1.6.12rc01-03       16    10612  16.so.16.12[.0]
  1.6.12              16    10612  16.so.16.12[.0]
  1.6.13beta01-04     16    10613  16.so.16.13[.0]
  1.6.13rc01-02       16    10613  16.so.16.13[.0]
@@ -6042,7 +6088,9 @@
  1.6.16rc01-02       16    10616  16.so.16.16[.0]
  1.6.16              16    10616  16.so.16.16[.0]
  1.6.17beta01-06     16    10617  16.so.16.17[.0]
- 1.6.17rc01-02       16    10617  16.so.16.17[.0]
+ 1.6.17rc01          16    10617  16.so.16.17[.0]
+ 1.7.0alpha01-10     17    10700  17.so.17.0[.0]
+ 1.7.0beta01-55      17    10700  17.so.17.0[.0]
 
 Henceforth the source version will match the shared-library minor
 and patch numbers; the shared-library major version number will be
@@ -6099,7 +6147,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.6.17rc02 - March 9, 2015:
+Libpng version 1.7.0beta55 - March 9, 2015:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
 
@@ -6122,8 +6170,8 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.6.17rc02, March 9, 2015, are
-Copyright (c) 2004,2006-2014 Glenn Randers-Pehrson, and are
+libpng versions 1.2.6, August 15, 2004, through 1.7.0beta55, March 9, 2015, are
+Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.2.5
 with the following individual added to the list of Contributing Authors
 
diff --git a/libpngpf.3 b/libpngpf.3
index 539c332..194b6a0 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "March 4, 2015"
+.TH LIBPNGPF 3 "March 9, 2015"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta55
 (private functions)
diff --git a/png.5 b/png.5
index f021413..b5dc685 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "March 4, 2015"
+.TH PNG 5 "March 9, 2015"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 396e905..d4597e4 100644
--- a/png.c
+++ b/png.c
@@ -1,7 +1,7 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * Last changed in libpng 1.6.17 [(PENDING RELEASE)]
+ * Last changed in libpng 1.7.0 [(PENDING RELEASE)]
  * Copyright (c) 1998-2015 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -14,7 +14,7 @@
 #include "pngpriv.h"
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_6_17rc02 Your_png_h_is_not_version_1_6_17rc02;
+typedef png_libpng_version_1_7_0beta55 Your_png_h_is_not_version_1_7_0beta55;
 
 /* Tells libpng that we have already handled the first "num_bytes" bytes
  * of the PNG file signature.  If the PNG data is embedded into another
@@ -34,7 +34,7 @@
    if (num_bytes > 8)
       png_error(png_ptr, "Too many bytes for PNG signature");
 
-   png_ptr->sig_bytes = (png_byte)((num_bytes < 0 ? 0 : num_bytes) & 0xff);
+   png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
 }
 
 /* Checks whether the supplied bytes match the PNG signature.  We allow
@@ -237,22 +237,21 @@
     */
    memset(&create_struct, 0, (sizeof create_struct));
 
-   /* Added at libpng-1.2.6 */
-#  ifdef PNG_USER_LIMITS_SUPPORTED
+   /* These limits are only used on read at present, and if READ is not turned
+    * on neither will USER_LIMITS be.  The width/height and chunk malloc limits
+    * are constants, so if they cannot be set they don't get defined in
+    * png_struct, the user_chunk_cache limits is a down-counter, when it reaches
+    * 1 no more chunks will be handled.  0 means unlimited, consequently the
+    * limit is 1 more than the number of chunks that will be handled.
+    */
+#  ifdef PNG_SET_USER_LIMITS_SUPPORTED
       create_struct.user_width_max = PNG_USER_WIDTH_MAX;
       create_struct.user_height_max = PNG_USER_HEIGHT_MAX;
-
-#     ifdef PNG_USER_CHUNK_CACHE_MAX
-         /* Added at libpng-1.2.43 and 1.4.0 */
-         create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
-#     endif
-
-#     ifdef PNG_USER_CHUNK_MALLOC_MAX
-         /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists
-          * in png_struct regardless.
-          */
-         create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
-#     endif
+      create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
+#  endif
+#  ifdef PNG_USER_LIMITS_SUPPORTED
+      /* Must exist even if the initial value is constant */
+      create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
 #  endif
 
    /* The following two API calls simply set fields in png_struct, so it is safe
@@ -386,60 +385,6 @@
    }
 }
 
-/* Initialize the info structure.  This is now an internal function (0.89)
- * and applications using it are urged to use png_create_info_struct()
- * instead.  Use deprecated in 1.6.0, internal use removed (used internally it
- * is just a memset).
- *
- * NOTE: it is almost inconceivable that this API is used because it bypasses
- * the user-memory mechanism and the user error handling/warning mechanisms in
- * those cases where it does anything other than a memset.
- */
-PNG_FUNCTION(void,PNGAPI
-png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size),
-   PNG_DEPRECATED)
-{
-   png_inforp info_ptr = *ptr_ptr;
-
-   png_debug(1, "in png_info_init_3");
-
-   if (info_ptr == NULL)
-      return;
-
-   if ((sizeof (png_info)) > png_info_struct_size)
-   {
-      *ptr_ptr = NULL;
-      /* The following line is why this API should not be used: */
-      free(info_ptr);
-      info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL,
-         (sizeof *info_ptr)));
-      *ptr_ptr = info_ptr;
-   }
-
-   /* Set everything to 0 */
-   memset(info_ptr, 0, (sizeof *info_ptr));
-}
-
-/* The following API is not called internally */
-void PNGAPI
-png_data_freer(png_const_structrp png_ptr, png_inforp info_ptr,
-   int freer, png_uint_32 mask)
-{
-   png_debug(1, "in png_data_freer");
-
-   if (png_ptr == NULL || info_ptr == NULL)
-      return;
-
-   if (freer == PNG_DESTROY_WILL_FREE_DATA)
-      info_ptr->free_me |= mask;
-
-   else if (freer == PNG_USER_WILL_FREE_DATA)
-      info_ptr->free_me &= ~mask;
-
-   else
-      png_error(png_ptr, "Unknown freer parameter in png_data_freer");
-}
-
 void PNGAPI
 png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
    int num)
@@ -730,29 +675,6 @@
 
    return 1;
 }
-
-#    if PNG_LIBPNG_VER < 10700
-/* To do: remove the following from libpng-1.7 */
-/* Original API that uses a private buffer in png_struct.
- * Deprecated because it causes png_struct to carry a spurious temporary
- * buffer (png_struct::time_buffer), better to have the caller pass this in.
- */
-png_const_charp PNGAPI
-png_convert_to_rfc1123(png_structrp png_ptr, png_const_timep ptime)
-{
-   if (png_ptr != NULL)
-   {
-      /* The only failure above if png_ptr != NULL is from an invalid ptime */
-      if (png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime) == 0)
-         png_warning(png_ptr, "Ignoring invalid time value");
-
-      else
-         return png_ptr->time_buffer;
-   }
-
-   return NULL;
-}
-#    endif /* LIBPNG_VER < 10700 */
 #  endif /* TIME_RFC1123 */
 
 #endif /* READ || WRITE */
@@ -766,13 +688,13 @@
 #else
 #  ifdef __STDC__
    return PNG_STRING_NEWLINE \
-     "libpng version 1.6.17rc02 - March 9, 2015" PNG_STRING_NEWLINE \
+     "libpng version 1.7.0beta55 - March 9, 2015" PNG_STRING_NEWLINE \
      "Copyright (c) 1998-2015 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
      "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
      "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
      PNG_STRING_NEWLINE;
 #  else
-      return "libpng version 1.6.17rc02 - March 9, 2015\
+      return "libpng version 1.7.0beta55 - March 9, 2015\
       Copyright (c) 1998-2015 Glenn Randers-Pehrson\
       Copyright (c) 1996-1997 Andreas Dilger\
       Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -869,9 +791,9 @@
 
    for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
    {
-      palette[i].red = (png_byte)(v & 0xff);
-      palette[i].green = (png_byte)(v & 0xff);
-      palette[i].blue = (png_byte)(v & 0xff);
+      palette[i].red = (png_byte)v;
+      palette[i].green = (png_byte)v;
+      palette[i].blue = (png_byte)v;
    }
 }
 #endif
@@ -923,19 +845,6 @@
 #endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */
 #endif /* SET_UNKNOWN_CHUNKS */
 
-#ifdef PNG_READ_SUPPORTED
-/* This function, added to libpng-1.0.6g, is untested. */
-int PNGAPI
-png_reset_zstream(png_structrp png_ptr)
-{
-   if (png_ptr == NULL)
-      return Z_STREAM_ERROR;
-
-   /* WARNING: this resets the window bits to the maximum! */
-   return (inflateReset(&png_ptr->zstream));
-}
-#endif /* READ */
-
 /* This function was added to libpng-1.0.7 */
 png_uint_32 PNGAPI
 png_access_version_number(void)
@@ -1176,7 +1085,7 @@
    png_colorspace_sync_info(png_ptr, info_ptr);
 }
 #endif
-#endif /* GAMMA */
+#endif
 
 #ifdef PNG_COLORSPACE_SUPPORTED
 /* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for
@@ -1930,6 +1839,10 @@
       return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
          "too short");
 
+   if (profile_length & 3)
+      return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
+         "invalid length");
+
    return 1;
 }
 
@@ -1950,11 +1863,6 @@
       return png_icc_profile_error(png_ptr, colorspace, name, temp,
          "length does not match profile");
 
-   temp = (png_uint_32) (*(profile+8));
-   if (temp > 3 && (profile_length & 3))
-      return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
-         "invalid length");
-
    temp = png_get_uint_32(profile+128); /* tag count: 12 bytes/tag */
    if (temp > 357913930 || /* (2^32-4-132)/12: maximum possible tag count */
       profile_length < 132+12*temp) /* truncated tag table */
@@ -2236,7 +2144,6 @@
     * by sRGB (but maybe defined by a later ICC specification) the read of
     * the profile will fail at that point.
     */
-
    png_uint_32 length = 0;
    png_uint_32 intent = 0x10000; /* invalid */
 #if PNG_sRGB_PROFILE_CHECKS > 1
@@ -2393,7 +2300,7 @@
 png_colorspace_set_rgb_coefficients(png_structrp png_ptr)
 {
    /* Set the rgb_to_gray coefficients from the colorspace. */
-   if (png_ptr->rgb_to_gray_coefficients_set == 0 &&
+   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_RGB_TO_GRAY_SET) == 0 &&
       (png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
    {
       /* png_set_background has not been called, get the coefficients from the Y
@@ -3201,26 +3108,34 @@
 #   endif /* FIXED_POINT */
 #endif /* SCAL */
 
-#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
-   !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \
+#if !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && (\
+   defined(PNG_FLOATING_POINT_SUPPORTED) && \
    (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \
    defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \
    defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \
-   (defined(PNG_sCAL_SUPPORTED) && \
-   defined(PNG_FLOATING_ARITHMETIC_SUPPORTED))
+   (defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) &&\
+   defined(PNG_sCAL_SUPPORTED)))
 png_fixed_point
 png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
 {
-   double r = floor(100000 * fp + .5);
+   if (fp < 0)
+   {
+      if (fp > -21474.836485)
+         return (png_fixed_point)(100000*fp - .5);
+   }
 
-   if (r > 2147483647. || r < -2147483648.)
-      png_fixed_error(png_ptr, text);
+   else
+   {
+      if (fp < 21474.836475)
+         return (png_fixed_point)(100000*fp + .5);
+   }
+
+   /* Overflow */
+   png_fixed_error(png_ptr, text);
 
 #  ifndef PNG_ERROR_TEXT_SUPPORTED
    PNG_UNUSED(text)
 #  endif
-
-   return (png_fixed_point)r;
 }
 #endif
 
@@ -3398,29 +3313,20 @@
 #endif
 
 #ifdef PNG_READ_GAMMA_SUPPORTED
-#ifdef PNG_16BIT_SUPPORTED
+#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
 /* A local convenience routine. */
 static png_fixed_point
 png_product2(png_fixed_point a, png_fixed_point b)
 {
    /* The required result is 1/a * 1/b; the following preserves accuracy. */
-#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
-   double r = a * 1E-5;
-   r *= b;
-   r = floor(r+.5);
-
-   if (r <= 2147483647. && r >= -2147483648.)
-      return (png_fixed_point)r;
-#else
    png_fixed_point res;
 
    if (png_muldiv(&res, a, b, 100000) != 0)
       return res;
-#endif
 
    return 0; /* overflow */
 }
-#endif /* 16BIT */
+#endif /* FLOATING_ARITHMETIC */
 
 /* The inverse of the above. */
 png_fixed_point
@@ -3438,10 +3344,10 @@
          return (png_fixed_point)r;
    }
 #else
-   /* This may overflow because the range of png_fixed_point isn't symmetric,
-    * but this API is only used for the product of file and screen gamma so it
-    * doesn't matter that the smallest number it can produce is 1/21474, not
-    * 1/100000
+   /* This may overflow because the range of png_fixed_point isn't
+    * symmetric, but this API is only used for the product of file and
+    * screen gamma so it doesn't matter that the smallest number it can
+    * produce is 1/21474, not 1/100000
     */
    png_fixed_point res = png_product2(a, b);
 
@@ -3727,10 +3633,9 @@
     * step.
     */
    x -= x >> 8;
-   return (png_byte)(((x + 0x7fffffU) >> 24) & 0xff);
+   return (png_byte)((x + 0x7fffffU) >> 24);
 }
 
-#ifdef PNG_16BIT_SUPPORTED
 static png_uint_16
 png_exp16bit(png_fixed_point lg2)
 {
@@ -3741,7 +3646,6 @@
    x -= x >> 16;
    return (png_uint_16)((x + 32767U) >> 16);
 }
-#endif /* 16BIT */
 #endif /* FLOATING_ARITHMETIC */
 
 png_byte
@@ -3788,10 +3692,9 @@
 #     endif
    }
 
-   return (png_byte)(value & 0xff);
+   return (png_byte)value;
 }
 
-#ifdef PNG_16BIT_SUPPORTED
 png_uint_16
 png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
 {
@@ -3803,7 +3706,7 @@
           * overflow on an ANSI-C90 compliant system so the cast needs to ensure
           * that this is not possible.
           */
-         double r = floor(65535*pow((png_int_32)value/65535.,
+         double r = floor(65535.*pow((png_int_32)value/65535.,
                      gamma_val*.00001)+.5);
          return (png_uint_16)r;
 #     else
@@ -3820,7 +3723,6 @@
 
    return (png_uint_16)value;
 }
-#endif /* 16BIT */
 
 /* This does the right thing based on the bit_depth field of the
  * png_struct, interpreting values as 8-bit or 16-bit.  While the result
@@ -3834,183 +3736,336 @@
    if (png_ptr->bit_depth == 8)
       return png_gamma_8bit_correct(value, gamma_val);
 
-#ifdef PNG_16BIT_SUPPORTED
    else
       return png_gamma_16bit_correct(value, gamma_val);
-#else
-      /* should not reach this */
-      return 0;
-#endif /* 16BIT */
 }
 
-#ifdef PNG_16BIT_SUPPORTED
-/* Internal function to build a single 16-bit table - the table consists of
- * 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount
- * to shift the input values right (or 16-number_of_signifiant_bits).
- *
- * The caller is responsible for ensuring that the table gets cleaned up on
- * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument
- * should be somewhere that will be cleaned.
- */
-static void
-png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
-   PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
+#define PNG_GAMMA_TABLE_8       0 /* 8-bit entries in png_byte */
+#define PNG_GAMMA_TABLE_8_IN_16 1 /* 8-bit entries * 257 in png_uint_16 */
+#define PNG_GAMMA_TABLE_16      2 /* 16-bit entries in png_uint_16 */
+
+typedef struct
 {
-   /* Various values derived from 'shift': */
-   PNG_CONST unsigned int num = 1U << (8U - shift);
-#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
-   /* CSE the division and work round wacky GCC warnings (see the comments
-    * in png_gamma_8bit_correct for where these come from.)
+   png_fixed_point gamma;
+   png_uint_32     mult;
+   unsigned int    add;
+   unsigned int    shift;  /* input value is (i * mult + add) >> shift */
+   int             output; /* One of the above values */
+   int             adjust; /* Divide or multiple output by 257 */
+   png_voidp       table;  /* Lookup table */
+}  gamma_table_data;
+
+static unsigned int
+write_gamma_table_entry(const gamma_table_data *data, png_uint_32 i)
+   /* Calculate and write a single entry into table[i], the value of the entry
+    * written is returned.
     */
-   PNG_CONST double fmax = 1./(((png_int_32)1 << (16U - shift))-1);
-#endif
-   PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
-   PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);
-   unsigned int i;
-
-   png_uint_16pp table = *ptable =
-       (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p)));
-
-   for (i = 0; i < num; i++)
-   {
-      png_uint_16p sub_table = table[i] =
-          (png_uint_16p)png_malloc(png_ptr, 256 * (sizeof (png_uint_16)));
-
-      /* The 'threshold' test is repeated here because it can arise for one of
-       * the 16-bit tables even if the others don't hit it.
-       */
-      if (png_gamma_significant(gamma_val) != 0)
-      {
-         /* The old code would overflow at the end and this would cause the
-          * 'pow' function to return a result >1, resulting in an
-          * arithmetic error.  This code follows the spec exactly; ig is
-          * the recovered input sample, it always has 8-16 bits.
-          *
-          * We want input * 65535/max, rounded, the arithmetic fits in 32
-          * bits (unsigned) so long as max <= 32767.
-          */
-         unsigned int j;
-         for (j = 0; j < 256; j++)
-         {
-            png_uint_32 ig = (j << (8-shift)) + i;
-#           ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
-               /* Inline the 'max' scaling operation: */
-               /* See png_gamma_8bit_correct for why the cast to (int) is
-                * required here.
-                */
-               double d = floor(65535.*pow(ig*fmax, gamma_val*.00001)+.5);
-               sub_table[j] = (png_uint_16)d;
-#           else
-               if (shift != 0)
-                  ig = (ig * 65535U + max_by_2)/max;
-
-               sub_table[j] = png_gamma_16bit_correct(ig, gamma_val);
-#           endif
-         }
-      }
-      else
-      {
-         /* We must still build a table, but do it the fast way. */
-         unsigned int j;
-
-         for (j = 0; j < 256; j++)
-         {
-            png_uint_32 ig = (j << (8-shift)) + i;
-
-            if (shift != 0)
-               ig = (ig * 65535U + max_by_2)/max;
-
-            sub_table[j] = (png_uint_16)ig;
-         }
-      }
-   }
-}
-
-/* NOTE: this function expects the *inverse* of the overall gamma transformation
- * required.
- */
-static void
-png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
-   PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
 {
-   PNG_CONST unsigned int num = 1U << (8U - shift);
-   PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
-   unsigned int i;
-   png_uint_32 last;
-
-   png_uint_16pp table = *ptable =
-       (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p)));
-
-   /* 'num' is the number of tables and also the number of low bits of low
-    * bits of the input 16-bit value used to select a table.  Each table is
-    * itself indexed by the high 8 bits of the value.
+   png_uint_32 in = (i * data->mult + data->add) >> data->shift;
+   unsigned int out;
+   
+   /* If the output is TABLE_8 with no adjust, or the output is not with an
+    * adjust, use 8-bit correction.
     */
-   for (i = 0; i < num; i++)
-      table[i] = (png_uint_16p)png_malloc(png_ptr,
-          256 * (sizeof (png_uint_16)));
-
-   /* 'gamma_val' is set to the reciprocal of the value calculated above, so
-    * pow(out,g) is an *input* value.  'last' is the last input value set.
-    *
-    * In the loop 'i' is used to find output values.  Since the output is
-    * 8-bit there are only 256 possible values.  The tables are set up to
-    * select the closest possible output value for each input by finding
-    * the input value at the boundary between each pair of output values
-    * and filling the table up to that boundary with the lower output
-    * value.
-    *
-    * The boundary values are 0.5,1.5..253.5,254.5.  Since these are 9-bit
-    * values the code below uses a 16-bit value in i; the values start at
-    * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last
-    * entries are filled with 255).  Start i at 128 and fill all 'last'
-    * table entries <= 'max'
-    */
-   last = 0;
-   for (i = 0; i < 255; ++i) /* 8-bit output value */
+   if ((data->output == PNG_GAMMA_TABLE_8) != (data->adjust != 0))
    {
-      /* Find the corresponding maximum input value */
-      png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */
+      out = png_gamma_8bit_correct((unsigned int)in, data->gamma);
 
-      /* Find the boundary value in 16 bits: */
-      png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val);
-
-      /* Adjust (round) to (16-shift) bits: */
-      bound = (bound * max + 32768U)/65535U + 1U;
-
-      while (last < bound)
-      {
-         table[last & (0xffU >> shift)][last >> (8U - shift)] = out;
-         last++;
-      }
+      if (data->adjust != 0)
+         out *= 257U;
    }
 
-   /* And fill in the final entries. */
-   while (last < (num << 8))
+   else /* 16-bit correction */
    {
-      table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U;
-      last++;
+      out = png_gamma_16bit_correct((unsigned int)in, data->gamma);
+
+      if (data->adjust != 0)
+         out = PNG_DIV257(out);
    }
-}
-#endif /* 16BIT */
 
-/* Build a single 8-bit table: same as the 16-bit case but much simpler (and
- * typically much faster).  Note that libpng currently does no sBIT processing
- * (apparently contrary to the spec) so a 256-entry table is always generated.
- */
-static void
-png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,
-   PNG_CONST png_fixed_point gamma_val)
-{
-   unsigned int i;
-   png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);
-
-   if (png_gamma_significant(gamma_val) != 0)
-      for (i=0; i<256; i++)
-         table[i] = png_gamma_8bit_correct(i, gamma_val);
+   if (data->output == PNG_GAMMA_TABLE_8)
+      ((png_bytep)data->table)[i] = (png_byte)out;
 
    else
-      for (i=0; i<256; ++i)
-         table[i] = (png_byte)(i & 0xff);
+      ((png_uint_16p)data->table)[i] = (png_uint_16)out;
+
+   return out;
+}
+
+static void
+write_gamma_table(const gamma_table_data *data, png_uint_32 lo,
+   unsigned int loval, png_uint_32 hi, unsigned int hival)
+   /* Fill in gamma table entries between lo and hi, exclusive.  The entries at
+    * table[lo] and table[hi] have already been written, the intervening entries
+    * are written.
+    */
+{
+   if (hi > lo+1) /* Else nothing to fill in */
+   {
+      if (hival == loval)
+      {
+         /* All intervening entries must be the same. */
+         if (data->output == PNG_GAMMA_TABLE_8)
+         {
+            png_bytep table8 = ((png_bytep)data->table);
+
+            while (++lo < hi)
+               table8[lo] = (png_byte)loval;
+         }
+
+         else
+         {
+            png_uint_16p table16 = ((png_uint_16p)data->table);
+
+            while (++lo < hi)
+               table16[lo] = (png_uint_16)loval;
+         }
+      }
+
+      else
+      {
+         png_uint_32 mid = (lo+hi) >> 1;
+         unsigned int midval = write_gamma_table_entry(data, mid);
+
+         /* The algorithm used is to divide the entries to be written in half
+          * and fill in the middle.  For all practical tables with significant
+          * gamma this will result in a performance gain because the expensive
+          * gamma correction arithmetic is avoided for some entries.
+          */
+         write_gamma_table(data, lo, loval, mid, midval);
+         write_gamma_table(data, mid, midval, hi, hival);
+      }
+   }
+}
+
+static void *
+png_build_gamma_table(png_structrp png_ptr, png_fixed_point gamma_val,
+   int output/*as above*/, int input_depth, int use_shift)
+   /* Build a gamma lookup table to encode input_depth bit input values.
+    * The table will have 2^input_depth entries plus an extra one if use_shift
+    * is specified.  With shift the table is accessed:
+    *
+    *    table[(original-value + rounding) >> shift]
+    *
+    * And an extra entry exists to accomodate overflow of original-value on
+    * rounding.  If use_shift is not specified the table is accessed with an
+    * input_depth bit value and the original values must have been correctly
+    * scaled to this range (not using a shift!)
+    *
+    * Each table entry contains input-value^gamma_val rounded to the output
+    * precision.  This is 8 bit precision unless output is specified as
+    * PNG_GAMMA_TABLE_16, in which case it is 16-bit precision.  For
+    * PNG_GAMMA_TABLE_8_IN_16 the 8-bit value is scaled to 16-bits by
+    * multiplying by 257.
+    */
+{
+   png_uint_32 size;
+   unsigned int hival;
+   gamma_table_data data;
+
+   /* If use_shift is true or if the input or output is not 8-bit the gamma
+    * correction will use the 16-bit correction code.  This requires a value in
+    * the range 0..65535.  For use_shift the value is simply:
+    *
+    *    input << shift
+    *
+    * For the scaling case the value is:
+    *
+    *    round(input * 65535 / ((1<<input_depth)-1)
+    *
+    * Both these expressions can be rewritten as:
+    *
+    *    (input * mult + add) >> shift;
+    *
+    * With 'mult' and 'add' chosen to minimize the error for all input values
+    * in the range 0..((1<<input_depth)-1).  The following table does this for
+    * the scaling case.  In fact all the answers are except except for the
+    * 13-bit case, where the maximum error (from the exact value) is 0.500183.
+    *
+    * This table can be produced using the code in contrib/tools/scale.c
+    */
+   static const struct
+   {
+      png_uint_32 mult;
+      png_uint_16 add;
+      png_byte    shift;
+   }  multadd65535[16] =
+   {
+      {      65535,     0,  0 }, /* 65535/1 */
+      {      21845,     0,  0 }, /* 65535/3 */
+      {      37449,     0,  2 }, /* 65535/7 */
+      {       4369,     0,  0 }, /* 65535/15 */
+      {      33825,     0,  4 }, /* 65535/31 */
+      {     266301,   121,  8 }, /* 65535/63 */
+      {    1056817,   970, 11 }, /* 65535/127 */
+      {        257,     0,  0 }, /* 65535/255 */
+      {     262653,  1020, 11 }, /* 65535/511 */
+      {    1049585,  8165, 14 }, /* 65535/1023 */
+      {    2098145, 31774, 16 }, /* 65535/2047 */
+      {      65551,  2055, 12 }, /* 65535/4095 */
+      {      65543,  4100, 13 }, /* 65535/8191 ERROR: .5+0.000183128*/
+      {      65539,  8193, 14 }, /* 65535/16383 */
+      {      32769,     0, 14 }, /* 65535/32767 */
+      {          1,     0,  0 }  /* 65535/65535 */
+#  if 0 /* inverse */
+      {      1,         0, 15 }, /* 1/65535 */
+      {      3,     32769, 16 }, /* 3/65535 */
+      {  28673, 134188470, 28 }, /* 7/65535 */
+      {     15,     32775, 16 }, /* 15/65535 */
+      {  31745,  33522654, 26 }, /* 31/65535 */
+      {  64513,  33552693, 26 }, /* 63/65535 */
+      {  65025,  16776620, 25 }, /* 127/65535 */
+      {    255,     32895, 16 }, /* 255/65535 */
+      {  65409,   4194134, 23 }, /* 511/65535 */
+      {  65473,   2097037, 22 }, /* 1023/65535 */
+      {  65505,   1048544, 21 }, /* 2047/65535 */
+      {  65521,    524167, 20 }, /* 4095/65535 */
+      {  65529,    262136, 19 }, /* 8191/65535 */
+      {  65533,    131065, 18 }, /* 16383/65535 */
+      {      1,         0,  1 }, /* 32767/65535 */
+      {      1,         0,  0 }  /* 65535/65535 */
+#  endif
+   };
+
+   /* When both the input and output are 8-bit (i.e. the output is not
+    * PNG_GAMMA_TABLE_16 and the input_depth is <9) the 8-bit gamma correction
+    * code can be used, it is slightly faster.  This requires values scaled to
+    * 255, not 65535:
+    */
+   static const struct
+   {
+      png_uint_16 mult;
+      png_byte    add;
+      png_byte    shift;
+   }  multadd255[8] =
+   {
+      { 255,    0,  0 }, /* 255/1 */
+      {  85,    0,  0 }, /* 255/3 */
+      {  73,    0,  1 }, /* 255/7 */
+      {  17,    0,  0 }, /* 255/15 */
+      { 527,   23,  6 }, /* 255/31 */
+      { 259,   33,  6 }, /* 255/63 */
+      { 129,    0,  6 }, /* 255/127 */
+      {   1,    0,  0 }  /* 255/255 */
+#  if 0 /* inverse */
+      {   1,    0,  7 }, /* 1/255 */
+      {   3,  129,  8 }, /* 3/255 */
+      { 225, 4060, 13 }, /* 7/255 */
+      {  15,  135,  8 }, /* 15/255 */
+      { 249, 1014, 11 }, /* 31/255 */
+      { 253,  505, 10 }, /* 63/255 */
+      {   1,    0,  1 }, /* 127/255 */
+      {   1,    0,  0 }  /* 255/255 */
+#  endif
+   };
+
+   /* Basic table size, increased by one below in the use_shift case where the
+    * input is rounded.
+    */
+   size = 1U << input_depth;
+   data.gamma = gamma_val;
+   data.output = output;
+
+   if (output < PNG_GAMMA_TABLE_16 && input_depth <= 8)
+   {
+      /* The 8-bit correction can only be used if both input and output have no
+       * more than 8 bits of precision.
+       */
+      data.adjust = output > PNG_GAMMA_TABLE_8;
+
+      if (use_shift != 0)
+      {
+         /* The multiplier does the shift: */
+         data.mult = 1U << (8-input_depth);
+         data.add = 0;
+         data.shift = 0;
+         if (input_depth < 8) ++size;
+      }
+
+      else
+      {
+         data.mult = multadd255[input_depth-1].mult;
+         data.add = multadd255[input_depth-1].add;
+         data.shift = multadd255[input_depth-1].shift;
+      }
+   }
+
+   else
+   {
+      /* 16-bit correction is used for cases where input or output require more
+       * than 8 bits.
+       */
+      data.adjust = output == PNG_GAMMA_TABLE_8;
+
+      if (use_shift != 0)
+      {
+         data.mult = 1U << (16-input_depth);
+         data.add = 0;
+         data.shift = 0;
+         if (input_depth < 16) ++size;
+      }
+
+      else
+      {
+         data.mult = multadd65535[input_depth-1].mult;
+         data.add = multadd65535[input_depth-1].add;
+         data.shift = multadd65535[input_depth-1].shift;
+      }
+   }
+
+   if (output == PNG_GAMMA_TABLE_8)
+   {
+      data.table = png_malloc(png_ptr, size * sizeof (png_byte));
+      ((png_bytep)data.table)[0] = 0;
+      hival = ((png_bytep)data.table)[size-1] = 255;
+   }
+
+   else
+   {
+      /* Output is 16 bits, although it may only have 8 bits of precision */
+      data.table = png_malloc(png_ptr, size * sizeof (png_uint_16));
+      ((png_uint_16p)data.table)[0] = 0;
+      hival = ((png_uint_16p)data.table)[size-1] = 65535;
+   }
+
+   if (png_gamma_significant(gamma_val) != 0)
+      write_gamma_table(&data, 0, 0, size-1, hival);
+
+   else /* gamma_val not significant */
+   {
+      if (output == PNG_GAMMA_TABLE_8)
+      {
+         png_uint_32 i;
+         png_bytep table8 = ((png_bytep)data.table);
+
+         if (data.adjust)
+            for (i=1; i<size-1; ++i)
+               table8[i] = (png_byte)PNG_DIV257((i * data.mult + data.add) >>
+                  data.shift);
+
+         else
+            for (i=1; i<size-1; ++i)
+               table8[i] = (png_byte)((i * data.mult + data.add) >> data.shift);
+      }
+
+      else
+      {
+         png_uint_32 i;
+         png_uint_16p table16 = ((png_uint_16p)data.table);
+
+         if (data.adjust)
+            for (i=1; i<size-1; ++i)
+               table16[i] = (png_uint_16)(((i * data.mult + data.add) >>
+                  data.shift) * 257U);
+
+         else
+            for (i=1; i<size-1; ++i)
+               table16[i] = (png_uint_16)((i * data.mult + data.add) >>
+                  data.shift);
+      }
+   }
+
+   return data.table;
 }
 
 /* Used from png_read_destroy and below to release the memory used by the gamma
@@ -4022,19 +4077,8 @@
    png_free(png_ptr, png_ptr->gamma_table);
    png_ptr->gamma_table = NULL;
 
-#ifdef PNG_16BIT_SUPPORTED
-   if (png_ptr->gamma_16_table != NULL)
-   {
-      int i;
-      int istop = (1 << (8 - png_ptr->gamma_shift));
-      for (i = 0; i < istop; i++)
-      {
-         png_free(png_ptr, png_ptr->gamma_16_table[i]);
-      }
    png_free(png_ptr, png_ptr->gamma_16_table);
    png_ptr->gamma_16_table = NULL;
-   }
-#endif /* 16BIT */
 
 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
    defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
@@ -4044,30 +4088,10 @@
    png_free(png_ptr, png_ptr->gamma_to_1);
    png_ptr->gamma_to_1 = NULL;
 
-#ifdef PNG_16BIT_SUPPORTED
-   if (png_ptr->gamma_16_from_1 != NULL)
-   {
-      int i;
-      int istop = (1 << (8 - png_ptr->gamma_shift));
-      for (i = 0; i < istop; i++)
-      {
-         png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
-      }
    png_free(png_ptr, png_ptr->gamma_16_from_1);
    png_ptr->gamma_16_from_1 = NULL;
-   }
-   if (png_ptr->gamma_16_to_1 != NULL)
-   {
-      int i;
-      int istop = (1 << (8 - png_ptr->gamma_shift));
-      for (i = 0; i < istop; i++)
-      {
-         png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
-      }
    png_free(png_ptr, png_ptr->gamma_16_to_1);
    png_ptr->gamma_16_to_1 = NULL;
-   }
-#endif /* 16BIT */
 #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
 }
 
@@ -4077,7 +4101,7 @@
  * we don't need to allocate > 64K chunks for a full 16-bit table.
  */
 void /* PRIVATE */
-png_build_gamma_table(png_structrp png_ptr, int bit_depth)
+png_build_gamma_tables(png_structrp png_ptr, int bit_depth)
 {
   png_debug(1, "in png_build_gamma_table");
 
@@ -4095,28 +4119,44 @@
 
   if (bit_depth <= 8)
   {
-     png_build_8bit_table(png_ptr, &png_ptr->gamma_table,
-         png_ptr->screen_gamma > 0 ?  png_reciprocal2(png_ptr->colorspace.gamma,
-         png_ptr->screen_gamma) : PNG_FP_1);
+     png_ptr->gamma_table = png_voidcast(png_bytep, png_build_gamma_table(
+         png_ptr, png_ptr->screen_gamma > 0 ?
+         png_reciprocal2(png_ptr->colorspace.gamma, png_ptr->screen_gamma) :
+         PNG_FP_1, PNG_GAMMA_TABLE_8, 8/*input depth*/, 0/*scale*/));
 
 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
    defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
    defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
      if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
      {
-        png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1,
-            png_reciprocal(png_ptr->colorspace.gamma));
+        /* This sets the accuracy of 8-bit composition and the 8-bit RGB to gray
+         * conversion - PNG_MAX_GAMMA_8 (the number of bits in the sixteen bit
+         * value that are considered significant.)
+         */
+        png_ptr->gamma_to_1 = png_voidcast(png_uint_16p, png_build_gamma_table(
+            png_ptr, png_reciprocal(png_ptr->colorspace.gamma),
+            PNG_GAMMA_TABLE_16, 8/*input depth*/, 0/*scale*/));
 
-        png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,
-            png_ptr->screen_gamma > 0 ?  png_reciprocal(png_ptr->screen_gamma) :
-            png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);
+        png_ptr->gamma_from_1 = png_voidcast(png_bytep, png_build_gamma_table(
+            png_ptr, png_ptr->screen_gamma > 0 ?
+            png_reciprocal(png_ptr->screen_gamma) :
+            png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */,
+            PNG_GAMMA_TABLE_8, PNG_MAX_GAMMA_8/*input depth*/, 1/*shift*/));
+
+        png_ptr->gamma_shift = 16-PNG_MAX_GAMMA_8;
      }
 #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
   }
-#ifdef PNG_16BIT_SUPPORTED
   else
   {
      png_byte shift, sig_bit;
+     int table_type;
+
+#    ifdef PNG_16BIT_SUPPORTED
+         table_type = PNG_GAMMA_TABLE_16;
+#    else
+         table_type = PNG_GAMMA_TABLE_8_IN_16;
+#    endif
 
      if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
      {
@@ -4131,27 +4171,8 @@
      else
         sig_bit = png_ptr->sig_bit.gray;
 
-     /* 16-bit gamma code uses this equation:
-      *
-      *   ov = table[(iv & 0xff) >> gamma_shift][iv >> 8]
-      *
-      * Where 'iv' is the input color value and 'ov' is the output value -
-      * pow(iv, gamma).
-      *
-      * Thus the gamma table consists of up to 256 256-entry tables.  The table
-      * is selected by the (8-gamma_shift) most significant of the low 8 bits of
-      * the color value then indexed by the upper 8 bits:
-      *
-      *   table[low bits][high 8 bits]
-      *
-      * So the table 'n' corresponds to all those 'iv' of:
-      *
-      *   <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1>
-      *
-      */
      if (sig_bit > 0 && sig_bit < 16U)
-        /* shift == insignificant bits */
-        shift = (png_byte)((16U - sig_bit) & 0xff);
+        shift = (png_byte)(16U - sig_bit); /* shift == insignificant bits */
 
      else
         shift = 0; /* keep all 16 bits */
@@ -4160,55 +4181,47 @@
      {
         /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
          * the significant bits in the *input* when the output will
-         * eventually be 8 bits.  By default it is 11.
+         * eventually be 8 bits.
          */
         if (shift < (16U - PNG_MAX_GAMMA_8))
            shift = (16U - PNG_MAX_GAMMA_8);
-     }
 
-     if (shift > 8U)
-        shift = 8U; /* Guarantees at least one table! */
+        table_type = PNG_GAMMA_TABLE_8_IN_16;
+     }
 
      png_ptr->gamma_shift = shift;
 
-     /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now
-      * PNG_COMPOSE).  This effectively smashed the background calculation for
-      * 16-bit output because the 8-bit table assumes the result will be reduced
-      * to 8 bits.
-      */
-     if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)
-         png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
-         png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma,
-         png_ptr->screen_gamma) : PNG_FP_1);
-
-     else
-         png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
-         png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma,
-         png_ptr->screen_gamma) : PNG_FP_1);
+     png_ptr->gamma_16_table = png_voidcast(png_uint_16p, png_build_gamma_table(
+         png_ptr, png_ptr->screen_gamma > 0 ? png_reciprocal2(
+         png_ptr->colorspace.gamma, png_ptr->screen_gamma) : PNG_FP_1,
+         table_type, (16-shift)/*input depth*/, 1/*shift*/));
 
 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
    defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
    defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
      if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)
      {
-        png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,
-            png_reciprocal(png_ptr->colorspace.gamma));
+        png_ptr->gamma_16_to_1 = png_voidcast(png_uint_16p,
+            png_build_gamma_table(png_ptr,
+            png_reciprocal(png_ptr->colorspace.gamma), PNG_GAMMA_TABLE_16,
+            (16-shift)/*input depth*/, 1/*shift*/));
 
         /* Notice that the '16 from 1' table should be full precision, however
          * the lookup on this table still uses gamma_shift, so it can't be.
          * TODO: fix this.
          */
-        png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,
-            png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
-            png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);
+        png_ptr->gamma_16_from_1 = png_voidcast(png_uint_16p,
+            png_build_gamma_table(png_ptr, png_ptr->screen_gamma > 0 ?
+            png_reciprocal(png_ptr->screen_gamma) :
+            png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */,
+            PNG_GAMMA_TABLE_16, (16-shift)/*input depth*/, 1/*shift*/));
      }
 #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
   }
-#endif /* 16BIT */
 }
 #endif /* READ_GAMMA */
 
-/* HARDWARE OR SOFTWARE OPTION SUPPORT */
+/* HARDWARE OPTION SUPPORT */
 #ifdef PNG_SET_OPTION_SUPPORTED
 int PNGAPI
 png_set_option(png_structrp png_ptr, int option, int onoff)
@@ -4220,7 +4233,7 @@
       int setting = (2 + (onoff != 0)) << option;
       int current = png_ptr->options;
 
-      png_ptr->options = (png_byte)(((current & ~mask) | setting) & 0xff);
+      png_ptr->options = (png_byte)((current & ~mask) | setting);
 
       return (current & mask) >> option;
    }
@@ -4287,6 +4300,7 @@
    57105,57646,58190,58737,59287,59840,60396,60955,
    61517,62082,62650,63221,63795,64372,64952,65535
 };
+
 #endif /* SIMPLIFIED_READ */
 
 /* The base/delta tables are required for both read and write (but currently
diff --git a/png.h b/png.h
index 82854e9..9baa42a 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.7.0beta55, March 7, 2015
+ * libpng version 1.7.0beta55, March 9, 2015
  *
  * Copyright (c) 1998-2015 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -12,7 +12,7 @@
  * Authors and maintainers:
  *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  *   libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
- *   libpng versions 0.97, January 1998, through 1.7.0beta55, March 7, 2015: Glenn
+ *   libpng versions 0.97, January 1998, through 1.7.0beta55, March 9, 2015: Glenn
  *   See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -248,7 +248,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.7.0beta55, March 7, 2015, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.7.0beta55, March 9, 2015, are
  * Copyright (c) 2004, 2006-2015 Glenn Randers-Pehrson, and are
  * distributed according to the same disclaimer and license as libpng-1.2.5
  * with the following individual added to the list of Contributing Authors:
@@ -360,7 +360,7 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    March 7, 2015
+ *    March 9, 2015
  *
  *    Since the PNG Development group is an ad-hoc body, we can't make
  *    an official declaration.
@@ -430,7 +430,7 @@
 /* Version information for png.h - this should match the version in png.c */
 #define PNG_LIBPNG_VER_STRING "1.7.0beta55"
 #define PNG_HEADER_VERSION_STRING \
-     " libpng version 1.7.0beta55 - March 7, 2015\n"
+     " libpng version 1.7.0beta55 - March 9, 2015\n"
 
 #define PNG_LIBPNG_VER_SONUM   17
 #define PNG_LIBPNG_VER_DLLNUM  17
diff --git a/pngconf.h b/pngconf.h
index be4f56e..8a53843 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.7.0beta55, March 7, 2015
+ * libpng version 1.7.0beta55, March 9, 2015
  *
  * Copyright (c) 1998-2015 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngrio.c b/pngrio.c
index f30c768..f33d8de 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -49,18 +49,42 @@
 void PNGCBAPI
 png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
 {
-   png_size_t check;
+   png_FILE_p io_ptr;
 
-   if (png_ptr == NULL)
-      return;
+   io_ptr = png_get_io_ptr(png_ptr);
 
-   /* fread() returns 0 on error, so it is OK to store this in a png_size_t
+   if (length == 0)
+      png_error(png_ptr, "Read Error: invalid length requested");
+
+   clearerr(io_ptr);
+
+   if (fileno(io_ptr) == -1)
+      png_error(png_ptr, "Read Error: invalid io_ptr");
+
+   /*
+    * fread() returns 0 on error, so it is OK to store this in a png_size_t
     * instead of an int, which is what fread() actually returns.
     */
-   check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
+   if ((png_size_t)fread((void *)data, sizeof (png_byte), length,
+        io_ptr) != length)
+   {
+      clearerr(io_ptr);
+      png_error(png_ptr, "Read Error: invalid length returned");
+   }
 
-   if (check != length)
-      png_error(png_ptr, "Read Error");
+   if (ferror(io_ptr))
+   {
+      clearerr(io_ptr);
+      png_error(png_ptr, "Read Error: error returned by fread()");
+   }
+
+   if (feof(io_ptr))
+   {
+      clearerr(io_ptr);
+      png_error(png_ptr, "Read Error: unexpected end of file");
+   }
+
+   clearerr(io_ptr);
 }
 #endif
 
diff --git a/projects/vstudio/readme.txt b/projects/vstudio/readme.txt
index 6477d8b..6d97284 100644
--- a/projects/vstudio/readme.txt
+++ b/projects/vstudio/readme.txt
@@ -1,7 +1,7 @@
 
 VisualStudio instructions
 
-libpng version 1.7.0beta55 - March 4, 2015
+libpng version 1.7.0beta55 - March 9, 2015
 
 Copyright (c) 1998-2010 Glenn Randers-Pehrson
 
diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props
index 9b014f7..3015f8c 100644
--- a/projects/vstudio/zlib.props
+++ b/projects/vstudio/zlib.props
@@ -2,7 +2,7 @@
 <!--
  * zlib.props - location of zlib source
  *
- * libpng version 1.7.0beta55 - March 4, 2015
+ * libpng version 1.7.0beta55 - March 9, 2015
  *
  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  *
diff --git a/scripts/README.txt b/scripts/README.txt
index 5a7174f..cb01b1e 100644
--- a/scripts/README.txt
+++ b/scripts/README.txt
@@ -1,5 +1,5 @@
 
-Makefiles for  libpng version 1.7.0beta55 - March 7, 2015
+Makefiles for  libpng version 1.7.0beta55 - March 9, 2015
 
 pnglibconf.h.prebuilt       =>  Stores configuration settings
  makefile.linux    =>  Linux/ELF makefile
diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa
index ede5879..01e02b5 100644
--- a/scripts/pnglibconf.dfa
+++ b/scripts/pnglibconf.dfa
@@ -8,7 +8,7 @@
 com
 version
 com
-com Copyright (c) 1998-2014 Glenn Randers-Pehrson
+com Copyright (c) 1998-2015 Glenn Randers-Pehrson
 com
 com This code is released under the libpng license.
 com For conditions of distribution and use, see the disclaimer
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index 384cdc8..d602d97 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -2,7 +2,7 @@
 
 /* pnglibconf.h - library build configuration */
 
-/* Libpng version 1.7.0beta55 - March 7, 2015 */
+/* Libpng version 1.7.0beta55 - March 9, 2015 */
 
 /* Copyright (c) 1998-2014 Glenn Randers-Pehrson */