[libpng17] Imported from libpng-1.7.0beta61.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index ffc8177..b48e105 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.7.0beta61 - May 20, 2015
+Libpng 1.7.0beta61 - May 31, 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.
@@ -799,9 +799,14 @@
   Replaced "unexpected" with an integer (0xabadca11) in pngset.c
     where a long was expected, to avoid a compiler warning when PNG_DEBUG > 1.
 
-Version 1.7.0beta61 [May 20, 2015]
+Version 1.7.0beta61 [May 31, 2015]
   Avoid Coverity issue 80858 (REVERSE NULL) in pngtest.c
-  Avoid a harmless potential integer overflow in png_XYZ_from_xy().
+  Avoid a harmless potential integer overflow in png_XYZ_from_xy() (Bug
+    report from Christopher Ferris).
+  Changed png_voidcast(), etc., to voidcast(), etc., in contrib/tools/pngfix.c
+    to avoid confusion with the libpng private macros.
+  Fixed old cut&paste bug in the weighted filter selection code in
+    pngwutil.c, introduced in libpng-0.95, March 1997.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/CHANGES b/CHANGES
index 3924669..0c1a6ad 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5094,9 +5094,14 @@
   Replaced "unexpected" with an integer (0xabadca11) in pngset.c
     where a long was expected, to avoid a compiler warning when PNG_DEBUG > 1.
 
-Version 1.7.0beta61 [May 20, 2015]
+Version 1.7.0beta61 [May 31, 2015]
   Avoid Coverity issue 80858 (REVERSE NULL) in pngtest.c PNG_DEBUG builds.
-  Avoid a harmless potential integer overflow in png_XYZ_from_xy().
+  Avoid a harmless potential integer overflow in png_XYZ_from_xy() (Bug
+    report from Christopher Ferris).
+  Changed png_voidcast(), etc., to voidcast(), etc., in contrib/tools/pngfix.c
+    to avoid confusion with the libpng private macros.
+  Fixed old cut&paste bug in the weighted filter selection code in
+    pngwutil.c, introduced in libpng-0.95, March 1997.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/LICENSE b/LICENSE
index 06e8e24..949a0b7 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.0beta61, May 6, 2015, are
+libpng versions 1.2.6, August 15, 2004, through 1.7.0beta61, May 31, 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
-May 6, 2015
+May 31, 2015
diff --git a/README b/README
index 482be57..2ea186f 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.7.0beta61 - May 6, 2015 (shared library 17.0)
+README for libpng version 1.7.0beta61 - May 31, 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.
@@ -134,7 +134,7 @@
 to others, if necessary.
 
 Please do not send suggestions on how to change PNG.  We have
-been discussing PNG for nineteen years now, and it is official and
+been discussing PNG for twenty years now, and it is official and
 finished.  If you have suggestions for libpng, however, I'll
 gladly listen.  Even if your suggestion is not used immediately,
 it may be used later.
diff --git a/contrib/tools/pngfix.c b/contrib/tools/pngfix.c
index f788f0b..0094262 100644
--- a/contrib/tools/pngfix.c
+++ b/contrib/tools/pngfix.c
@@ -71,8 +71,8 @@
  * with older builds.
  */
 #if ZLIB_VERNUM < 0x1260
-#  define PNGZ_MSG_CAST(s) png_constcast(char*,s)
-#  define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)
+#  define PNGZ_MSG_CAST(s) constcast(char*,s)
+#  define PNGZ_INPUT_CAST(b) constcast(png_bytep,b)
 #else
 #  define PNGZ_MSG_CAST(s) (s)
 #  define PNGZ_INPUT_CAST(b) (b)
@@ -86,17 +86,17 @@
 
 /* Copied from pngpriv.h */
 #ifdef __cplusplus
-#  define png_voidcast(type, value) static_cast<type>(value)
-#  define png_constcast(type, value) const_cast<type>(value)
-#  define png_aligncast(type, value) \
+#  define voidcast(type, value) static_cast<type>(value)
+#  define constcast(type, value) const_cast<type>(value)
+#  define aligncast(type, value) \
    static_cast<type>(static_cast<void*>(value))
-#  define png_aligncastconst(type, value) \
+#  define aligncastconst(type, value) \
    static_cast<type>(static_cast<const void*>(value))
 #else
-#  define png_voidcast(type, value) (value)
-#  define png_constcast(type, value) ((type)(value))
-#  define png_aligncast(type, value) ((void*)(value))
-#  define png_aligncastconst(type, value) ((const void*)(value))
+#  define voidcast(type, value) (value)
+#  define constcast(type, value) ((type)(value))
+#  define aligncast(type, value) ((void*)(value))
+#  define aligncastconst(type, value) ((const void*)(value))
 #endif /* __cplusplus */
 
 #if PNG_LIBPNG_VER < 10700
@@ -446,7 +446,7 @@
 make_random_bytes(png_uint_32* seed, void* pv, size_t size)
 {
    png_uint_32 u0 = seed[0], u1 = seed[1];
-   png_bytep bytes = png_voidcast(png_bytep, pv);
+   png_bytep bytes = voidcast(png_bytep, pv);
 
    /* There are thirty-three bits; the next bit in the sequence is bit-33 XOR
     * bit-20.  The top 1 bit is in u1, the bottom 32 are in u0.
@@ -668,7 +668,7 @@
       if (length < tail->length) /* arithmetic overflow */
          length = tail->length;
             
-      next = png_voidcast(IDAT_list*, malloc(IDAT_list_size(NULL, length)));
+      next = voidcast(IDAT_list*, malloc(IDAT_list_size(NULL, length)));
       CLEAR(*next);
 
       /* The caller must handle this: */
@@ -3535,7 +3535,7 @@
    /* This just returns the (file*).  The chunk and idat control structures
     * don't always exist.
     */
-   struct control *control = png_voidcast(struct control*,
+   struct control *control = voidcast(struct control*,
       png_get_error_ptr(png_ptr));
    return &control->file;
 }
@@ -3543,7 +3543,7 @@
 static void
 allocate(struct file *file, int allocate_idat)
 {
-   struct control *control = png_voidcast(struct control*, file->alloc_ptr);
+   struct control *control = voidcast(struct control*, file->alloc_ptr);
 
    if (allocate_idat)
    {
diff --git a/libpng-manual.txt b/libpng-manual.txt
index 8269a8c..a8eacbb 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.7.0beta61 - May 7, 2015
+ libpng version 1.7.0beta61 - May 31, 2015
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -11,7 +11,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.7.0beta61 - May 7, 2015
+ libpng versions 0.97, January 1998, through 1.7.0beta61 - May 31, 2015
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
@@ -5346,7 +5346,7 @@
 
 XVII. Y2K Compliance in libpng
 
-May 7, 2015
+May 31, 2015
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
diff --git a/libpng.3 b/libpng.3
index 770473c..4559ee9 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,4 +1,4 @@
-.TH LIBPNG 3 "May 7, 2015"
+.TH LIBPNG 3 "May 31, 2015"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta61
 .SH SYNOPSIS
@@ -494,7 +494,7 @@
 .SH LIBPNG.TXT
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.7.0beta61 - May 7, 2015
+ libpng version 1.7.0beta61 - May 31, 2015
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -505,7 +505,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.7.0beta61 - May 7, 2015
+ libpng versions 0.97, January 1998, through 1.7.0beta61 - May 31, 2015
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
@@ -5840,7 +5840,7 @@
 
 .SH XVII. Y2K Compliance in libpng
 
-May 7, 2015
+May 31, 2015
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
@@ -6157,7 +6157,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.7.0beta61 - May 7, 2015:
+Libpng version 1.7.0beta61 - May 31, 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).
 
@@ -6180,7 +6180,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.7.0beta61, May 7, 2015, are
+libpng versions 1.2.6, August 15, 2004, through 1.7.0beta61, May 31, 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
@@ -6279,7 +6279,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-May 7, 2015
+May 31, 2015
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index e642f3d..a243457 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "May 6, 2015"
+.TH LIBPNGPF 3 "May 31, 2015"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta61
 (private functions)
diff --git a/png.5 b/png.5
index 766fe3e..1276a88 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "May 6, 2015"
+.TH PNG 5 "May 31, 2015"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 2fd92e1..4530bd0 100644
--- a/png.c
+++ b/png.c
@@ -689,13 +689,13 @@
 #else
 #  ifdef __STDC__
    return PNG_STRING_NEWLINE \
-     "libpng version 1.7.0beta61 - May 20, 2015" PNG_STRING_NEWLINE \
+     "libpng version 1.7.0beta61 - May 31, 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.7.0beta61 - May 20, 2015\
+      return "libpng version 1.7.0beta61 - May 31, 2015\
       Copyright (c) 1998-2015 Glenn Randers-Pehrson\
       Copyright (c) 1996-1997 Andreas Dilger\
       Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
diff --git a/png.h b/png.h
index d5f7441..1d71d05 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.7.0beta61, May 6, 2015
+ * libpng version 1.7.0beta61, May 31, 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.0beta61, May 6, 2015: Glenn
+ *   libpng versions 0.97, January 1998, through 1.7.0beta61, May 31, 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.0beta61, May 6, 2015, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.7.0beta61, May 31, 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:
  * =========================
  *
- *    May 6, 2015
+ *    May 31, 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.0beta61"
 #define PNG_HEADER_VERSION_STRING \
-     " libpng version 1.7.0beta61 - May 6, 2015\n"
+     " libpng version 1.7.0beta61 - May 31, 2015\n"
 
 #define PNG_LIBPNG_VER_SONUM   17
 #define PNG_LIBPNG_VER_DLLNUM  17
diff --git a/pngconf.h b/pngconf.h
index e02a5d2..ff258bd 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.7.0beta61, May 6, 2015
+ * libpng version 1.7.0beta61, May 31, 2015
  *
  * Copyright (c) 1998-2015 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngstruct.h b/pngstruct.h
index 52b4869..dfe3f2b 100644
--- a/pngstruct.h
+++ b/pngstruct.h
@@ -330,15 +330,23 @@
     *
     * Members that hold pointers to the decompressed image rows.
     */
-   png_bytep row_buf;  /* buffer for the current (unfiltered) row */
+   png_bytep row_buf;         /* buffer to save current (unfiltered) row.
+                               * While reading, this is a pointer into
+                               * big_row_buf; while writing it is separately
+                               * allocated.
+                               */
 #if defined(PNG_WRITE_FILTER_SUPPORTED) || defined(PNG_READ_SUPPORTED)
-   png_bytep prev_row; /* buffer to save the previous (unfiltered) row */
+   png_bytep prev_row;        /* buffer to save previous (unfiltered) row.
+                               * While reading this is a pointer into
+                               * big_prev_row; while writing it is separately
+                               * allocated if needed.
+                               */
 #endif
 
 #ifdef PNG_READ_SUPPORTED
    /* The row_buf and prev_row pointers are misaligned so that the start of the
     * row - after the filter byte - is aligned, the 'big_' pointers record the
-    * original allocated pointer.
+    * original allocated pointer.  These are only used while reading.
     */
    png_bytep big_row_buf;
    png_bytep big_prev_row;
diff --git a/pngwutil.c b/pngwutil.c
index 4167d48..e698f49 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -2841,7 +2841,7 @@
 
          for (j = 0; j < num_p_filters; j++)
          {
-            if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
+            if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
             {
                sumlo = (sumlo * png_ptr->filter_weights[j]) >>
                    PNG_WEIGHT_SHIFT;
diff --git a/projects/vstudio/readme.txt b/projects/vstudio/readme.txt
index e0006e5..33d42b3 100644
--- a/projects/vstudio/readme.txt
+++ b/projects/vstudio/readme.txt
@@ -1,7 +1,7 @@
 
 VisualStudio instructions
 
-libpng version 1.7.0beta61 - May 6, 2015
+libpng version 1.7.0beta61 - May 31, 2015
 
 Copyright (c) 1998-2010 Glenn Randers-Pehrson
 
diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props
index 58a325b..1ce25f4 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.0beta61 - May 6, 2015
+ * libpng version 1.7.0beta61 - May 31, 2015
  *
  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  *
diff --git a/scripts/README.txt b/scripts/README.txt
index 1b79ddf..c77cf3f 100644
--- a/scripts/README.txt
+++ b/scripts/README.txt
@@ -1,5 +1,5 @@
 
-Makefiles for  libpng version 1.7.0beta61 - May 6, 2015
+Makefiles for  libpng version 1.7.0beta61 - May 31, 2015
 
 pnglibconf.h.prebuilt       =>  Stores configuration settings
  makefile.linux    =>  Linux/ELF makefile
diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa
index 01e02b5..6f526bd 100644
--- a/scripts/pnglibconf.dfa
+++ b/scripts/pnglibconf.dfa
@@ -241,8 +241,8 @@
 # ARM_NEON_API:   (PNG_ARM_NEON == 1) allow the optimization to be switched on
 #                 with png_set_option
 # ARM_NEON_CHECK: (PNG_ARM_NEON == 1) compile a run-time check to see if Neon
-#                 extensions are supported, this is poorly supported and
-#                 deprectated - use the png_set_option API.
+#                 extensions are supported. This is poorly supported and
+#                 deprecated - use the png_set_option API.
 setting ARM_NEON_OPT
 option ARM_NEON_API disabled requires ALIGNED_MEMORY enables SET_OPTION,
    sets ARM_NEON_OPT 1
@@ -672,7 +672,7 @@
 # are only interested in 8 bits anyway.  Increasing this value
 # results in more memory being used, and more pow() functions
 # being called to fill in the gamma tables.  Don't set this value
-# less then 8, and even that may not work (I haven't tested it).
+# less than 8, and even that may not work (I haven't tested it).
 
 setting MAX_GAMMA_8 default 11
 
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index e8d048c..6737ec5 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -2,7 +2,7 @@
 
 /* pnglibconf.h - library build configuration */
 
-/* Libpng version 1.7.0beta61 - May 6, 2015 */
+/* Libpng version 1.7.0beta61 - May 31, 2015 */
 
 /* Copyright (c) 1998-2014 Glenn Randers-Pehrson */