[libpng16] Imported from libpng-1.6.19beta01.tar
diff --git a/LICENSE b/LICENSE
index 3c9af2f..36fb838 100644
--- a/LICENSE
+++ b/LICENSE
@@ -10,7 +10,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.0.7, July 1, 2000, through 1.6.19beta01, July 24, 2015, are
+libpng versions 1.0.7, July 1, 2000, through 1.6.19beta01, July 29, 2015, are
 Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.0.6
 with the following individuals added to the list of Contributing Authors:
@@ -104,4 +104,4 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-July 24, 2015
+July 29, 2015
diff --git a/README b/README
index d1e59f0..28ecdd9 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.6.19beta01 - July 24, 2015 (shared library 16.0)
+README for libpng version 1.6.19beta01 - July 29, 2015 (shared library 16.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/pngminus/pnm2png.c b/contrib/pngminus/pnm2png.c
index 7bf720f..8fa64cd 100644
--- a/contrib/pngminus/pnm2png.c
+++ b/contrib/pngminus/pnm2png.c
@@ -3,6 +3,7 @@
  *  copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
  *
  *  version 1.0 - 1999.10.15 - First version.
+ *  version 1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)
  *
  *  Permission to use, copy, modify, and distribute this software and
  *  its documentation for any purpose and without fee is hereby granted,
@@ -200,17 +201,17 @@
   char          width_token[16];
   char          height_token[16];
   char          maxval_token[16];
-  volatile int           color_type;
+  volatile int    color_type=1;
   unsigned long   ul_width=0, ul_alpha_width=0;
   unsigned long   ul_height=0, ul_alpha_height=0;
   unsigned long   ul_maxval=0;
-  volatile png_uint_32   width, height;
-  volatile png_uint_32   alpha_width, alpha_height;
+  volatile png_uint_32   width=0, height=0;
+  volatile png_uint_32   alpha_width=0, alpha_height=0;
   png_uint_32   maxval;
   volatile int           bit_depth = 0;
-  int           channels;
+  int           channels=0;
   int           alpha_depth = 0;
-  int           alpha_present;
+  int           alpha_present=0;
   int           row, col;
   BOOL          raw, alpha_raw = FALSE;
 #if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
@@ -356,8 +357,10 @@
     channels = 3;
   else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
     channels = 4;
+#if 0
   else
-    channels = 0; /* should not happen */
+    channels = 0; /* cannot happen */
+#endif
 
   alpha_present = (channels - 1) % 2;
 
@@ -429,12 +432,16 @@
       NULL);
   if (!png_ptr)
   {
+    free (png_pixels);
+    png_pixels = NULL;
     return FALSE;
   }
   info_ptr = png_create_info_struct (png_ptr);
   if (!info_ptr)
   {
     png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
+    free (png_pixels);
+    png_pixels = NULL;
     return FALSE;
   }
 
@@ -449,7 +456,9 @@
   /* setjmp() must be called in every function that calls a PNG-reading libpng function */
   if (setjmp (png_jmpbuf(png_ptr)))
   {
-    png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
+    png_destroy_write_struct (&png_ptr, &info_ptr);
+    free (png_pixels);
+    png_pixels = NULL;
     return FALSE;
   }
 
@@ -470,7 +479,9 @@
     if ((row_pointers = (png_byte **)
         malloc (height * sizeof (png_bytep))) == NULL)
     {
-      png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
+      png_destroy_write_struct (&png_ptr, &info_ptr);
+      free (png_pixels);
+      png_pixels = NULL;
       return FALSE;
     }
   }
@@ -486,7 +497,7 @@
   png_write_end (png_ptr, info_ptr);
 
   /* clean up after the write, and free any memory allocated */
-  png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
+  png_destroy_write_struct (&png_ptr, &info_ptr);
 
   if (row_pointers != (unsigned char**) NULL)
     free (row_pointers);
diff --git a/libpng-manual.txt b/libpng-manual.txt
index f8a9cbc..84e8019 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.19beta01 - July 25, 2015
+ libpng version 1.6.19beta01 - July 29, 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.6.19beta01 - July 25, 2015
+ libpng versions 0.97, January 1998, through 1.6.19beta01 - July 29, 2015
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
@@ -5304,7 +5304,7 @@
 
 XVI. Y2K Compliance in libpng
 
-July 25, 2015
+July 29, 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 719a73d..90b9b7d 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,4 +1,4 @@
-.TH LIBPNG 3 "July 25, 2015"
+.TH LIBPNG 3 "July 29, 2015"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.6.19beta01
 .SH SYNOPSIS
@@ -508,7 +508,7 @@
 .SH LIBPNG.TXT
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.6.19beta01 - July 25, 2015
+ libpng version 1.6.19beta01 - July 29, 2015
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -519,7 +519,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.6.19beta01 - July 25, 2015
+ libpng versions 0.97, January 1998, through 1.6.19beta01 - July 29, 2015
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
@@ -5812,7 +5812,7 @@
 
 .SH XVI. Y2K Compliance in libpng
 
-July 25, 2015
+July 29, 2015
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
@@ -6042,7 +6042,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]
@@ -6133,7 +6133,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.6.19beta01 - July 25, 2015:
+Libpng version 1.6.19beta01 - July 29, 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).
 
@@ -6156,7 +6156,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.0.7, July 1, 2000, through 1.6.19beta01, July 25, 2015, are
+libpng versions 1.0.7, July 1, 2000, through 1.6.19beta01, July 29, 2015, are
 Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.0.6
 with the following individuals added to the list of Contributing Authors:
@@ -6250,7 +6250,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-July 25, 2015
+July 29, 2015
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index 9397bec..e3f8ce0 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "July 24, 2015"
+.TH LIBPNGPF 3 "July 29, 2015"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.6.19beta01
 (private functions)
diff --git a/png.5 b/png.5
index 2107544..40a7a5a 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "July 24, 2015"
+.TH PNG 5 "July 29, 2015"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.h b/png.h
index 29961c5..678a59a 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.6.19beta01, July 26, 2015
+ * libpng version 1.6.19beta01, July 29, 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.89, June 1996, through 0.96, May 1997: Andreas Dilger
- *   libpng versions 0.97, January 1998, through 1.6.19beta01, July 26, 2015: Glenn
+ *   libpng versions 0.97, January 1998, through 1.6.19beta01, July 29, 2015: Glenn
  *   See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -251,7 +251,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.0.7, July 1, 2000, through 1.6.19beta01, July 26, 2015, are
+ * libpng versions 1.0.7, July 1, 2000, through 1.6.19beta01, July 29, 2015, are
  * Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, and are
  * distributed according to the same disclaimer and license as libpng-1.0.6
  * with the following individuals added to the list of Contributing Authors:
@@ -360,7 +360,7 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    July 26, 2015
+ *    July 29, 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.6.19beta01"
 #define PNG_HEADER_VERSION_STRING \
-     " libpng version 1.6.19beta01 - July 26, 2015\n"
+     " libpng version 1.6.19beta01 - July 29, 2015\n"
 
 #define PNG_LIBPNG_VER_SONUM   16
 #define PNG_LIBPNG_VER_DLLNUM  16
diff --git a/pngpriv.h b/pngpriv.h
index 1997503..761d4ad 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -575,10 +575,6 @@
 #define PNG_STRUCT_PNG   0x0001
 #define PNG_STRUCT_INFO  0x0002
 
-/* Scaling factor for filter heuristic weighting calculations */
-#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
-#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
-
 /* Flags for the png_ptr->flags rather than declaring a byte for each one */
 #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY     0x0001
 #define PNG_FLAG_ZSTREAM_INITIALIZED      0x0002 /* Added to libpng-1.6.0 */
diff --git a/projects/vstudio/readme.txt b/projects/vstudio/readme.txt
index bf6b91e..67da6c8 100644
--- a/projects/vstudio/readme.txt
+++ b/projects/vstudio/readme.txt
@@ -1,7 +1,7 @@
 
 VisualStudio instructions
 
-libpng version 1.6.19beta01 - July 24, 2015
+libpng version 1.6.19beta01 - July 29, 2015
 
 Copyright (c) 1998-2010 Glenn Randers-Pehrson
 
diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props
index f3d2b4d..15e5c1f 100644
--- a/projects/vstudio/zlib.props
+++ b/projects/vstudio/zlib.props
@@ -2,7 +2,7 @@
 <!--
  * zlib.props - location of zlib source
  *
- * libpng version 1.6.19beta01 - July 24, 2015
+ * libpng version 1.6.19beta01 - July 29, 2015
  *
  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  *
diff --git a/scripts/README.txt b/scripts/README.txt
index 4ccc43e..6c3adc5 100644
--- a/scripts/README.txt
+++ b/scripts/README.txt
@@ -1,5 +1,5 @@
 
-Makefiles for  libpng version 1.6.19beta01 - July 24, 2015
+Makefiles for  libpng version 1.6.19beta01 - July 29, 2015
 
 pnglibconf.h.prebuilt       =>  Stores configuration settings
  makefile.linux    =>  Linux/ELF makefile
diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa
index 07293ae..b2b7b43 100644
--- a/scripts/pnglibconf.dfa
+++ b/scripts/pnglibconf.dfa
@@ -515,9 +515,7 @@
 
 option WRITE_INTERLACING requires WRITE
 
-# The following depends, internally, on WEIGHT_SHIFT and COST_SHIFT
-# where are set below.
-
+# Deprecated, will be removed.
 option WRITE_WEIGHTED_FILTER requires WRITE
 
 option WRITE_FLUSH requires WRITE
@@ -668,11 +666,6 @@
 
 setting GAMMA_THRESHOLD_FIXED default 5000
 
-# Scaling factor for filter heuristic weighting calculations
-
-setting WEIGHT_SHIFT default 8
-setting COST_SHIFT default 3
-
 # Precision to use when converting a floating point value to a PNG
 # extension format string in an sCAL chunk (only relevant if the
 # floating point API is enabled)
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index 6ae959e..0907e23 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -2,7 +2,7 @@
 
 /* pnglibconf.h - library build configuration */
 
-/* Libpng version 1.6.19beta01 - July 24, 2015 */
+/* Libpng version 1.6.19beta01 - July 29, 2015 */
 
 /* Copyright (c) 1998-2014 Glenn Randers-Pehrson */
 
@@ -185,7 +185,6 @@
 /* end of options */
 /* settings */
 #define PNG_API_RULE 0
-#define PNG_COST_SHIFT 3
 #define PNG_DEFAULT_READ_MACROS 1
 #define PNG_GAMMA_THRESHOLD_FIXED 5000
 #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE
@@ -204,7 +203,6 @@
 #define PNG_USER_CHUNK_MALLOC_MAX 8000000
 #define PNG_USER_HEIGHT_MAX 1000000
 #define PNG_USER_WIDTH_MAX 1000000
-#define PNG_WEIGHT_SHIFT 8
 #define PNG_ZBUF_SIZE 8192
 #define PNG_ZLIB_VERNUM 0 /* unknown */
 #define PNG_Z_DEFAULT_COMPRESSION (-1)