[libpng17] Imported from libpng-1.7.0alpha01.tar
diff --git a/LICENSE b/LICENSE
index 673a6b8..0712681 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.0alpha01, December 10, 2012, are
+libpng versions 1.2.6, August 15, 2004, through 1.7.0alpha01, December 15, 2012, are
 Copyright (c) 2004, 2006-2012 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
-December 10, 2012
+December 15, 2012
diff --git a/README b/README
index f0bb68b..1c4874a 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.7.0alpha01 - December 10, 2012 (shared library 17.0)
+README for libpng version 1.7.0alpha01 - December 15, 2012 (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/arm/arm_init.c b/arm/arm_init.c
index 6b0a925..6d19cf1 100644
--- a/arm/arm_init.c
+++ b/arm/arm_init.c
@@ -1,8 +1,9 @@
 
-/* filter_neon.S - NEON optimised filter functions
+/* arm_init.c - NEON optimised filter functions
  *
- * Copyright (c) 2011 Glenn Randers-Pehrson
+ * Copyright (c) 2012 Glenn Randers-Pehrson
  * Written by Mans Rullgard, 2011.
+ * Last changed in libpng 1.6.0 [(PENDING RELEASE)]
  *
  * This code is released under the libpng license.
  * For conditions of distribution and use, see the disclaimer
@@ -50,6 +51,17 @@
       return;
 #endif
 
+   /* IMPORTANT: any new external functions used here must be declared using
+    * PNG_INTERNAL_FUNCTION in ../pngpriv.h.  This is required so that the
+    * 'prefix' option to configure works:
+    *
+    *    ./configure --with-libpng-prefix=foobar_
+    *
+    * Verify you have got this right by running the above command, doing a build
+    * and examining pngprefix.h; it must contain a #define for every external
+    * function you add.  (Notice that this happens automatically for the
+    * initialization function.)
+    */
    pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
 
    if (bpp == 3)
diff --git a/arm/filter_neon.S b/arm/filter_neon.S
index 9ce04d3..4aa500c 100644
--- a/arm/filter_neon.S
+++ b/arm/filter_neon.S
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2011 Glenn Randers-Pehrson
  * Written by Mans Rullgard, 2011.
+ * Last changed in libpng 1.5.7 [December 15, 2011]
  *
  * This code is released under the libpng license.
  * For conditions of distribution and use, see the disclaimer
diff --git a/contrib/tools/scale.c b/contrib/tools/scale.c
index 3b14c31..6fe0867 100644
--- a/contrib/tools/scale.c
+++ b/contrib/tools/scale.c
@@ -236,3 +236,241 @@
    /* Just an exit code - the printout above lists the problem */
    return err;
 }
+/* Given a target range and a source range work out an expression to scale from
+ * the source to the target of the form:
+ *
+ *    (number * mult + add)>>16
+ *
+ * The command arguments are:
+ *
+ *    scale target source
+ *
+ * and the program works out a pair of numbers, mult and add, that evaluate:
+ *
+ *          number * target
+ *   round( --------------- )
+ *              source
+ *
+ * exactly for number in the range 0..source
+ */
+#define _ISOC99_SOURCE 1
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+static double minerr;
+static unsigned long minmult, minadd, minshift;
+static long mindelta;
+
+static int
+test(unsigned long target, unsigned long source, unsigned long mult,
+   long add, unsigned long shift, long delta)
+{
+   unsigned long i;
+   double maxerr = 0;
+   double rs = (double)target/source;
+
+   for (i=0; i<=source; ++i)
+   {
+      unsigned long t = i*mult+add;
+      double err = fabs((t >> shift) - i*rs);
+
+      if (err > minerr)
+         return 0;
+
+      if (err > maxerr)
+         maxerr = err;
+   }
+
+   if (maxerr < minerr)
+   {
+      minerr = maxerr;
+      minmult = mult;
+      minadd = add;
+      minshift = shift;
+      mindelta = delta;
+   }
+
+   return maxerr < .5;
+}
+
+static int
+dotest(unsigned long target, unsigned long source, unsigned long mult,
+   long add, unsigned long shift, long delta, int print)
+{
+   if (test(target, source, mult, add, shift, delta))
+   {
+      if (print & 4)
+         printf("      {%11lu,%6ld /* >>%lu */ }, /* %lu/%lu */\n",
+            mult, add, shift, target, source);
+
+      else if (print & 2)
+         printf("      {%11lu,%6ld,%3lu }, /* %lu/%lu */\n",
+            mult, add, shift, target, source);
+
+      else if (print)
+         printf("number * %lu/%lu = (number * %lu + %ld) >> %lu [delta %ld]\n",
+            target, source, mult, add, shift, delta);
+
+      return 1;
+   }
+
+   return 0;
+}
+
+static int
+find(unsigned long target, unsigned long source, int print, int fixshift)
+{
+   unsigned long shift = 0;
+   unsigned long shiftlim = 0;
+
+   /* In the final math the sum is at most (source*mult+add) >> shift, so:
+    *
+    *    source*mult+add < 1<<32
+    *    mult < (1<<32)/source
+    *
+    * but:
+    *
+    *    mult = (target<<shift)/source
+    *
+    * so:
+    *
+    *    (target<<shift) < (1<<32)
+    */
+   if (fixshift < 0)
+      while ((target<<shiftlim) < 0x80000000U) ++shiftlim;
+
+   else
+      shift = shiftlim = (unsigned long)fixshift;
+
+   minerr = 1E8;
+
+   for (; shift<=shiftlim; ++shift)
+   {
+      unsigned long mult = ((target<<shift) + (source>>1)) / source;
+      long delta;
+      long limit = 1; /* seems to be sufficient */
+      long add, start, end;
+
+      end = 1<<shift;
+      start = -end;
+
+      for (add=start; add<=end; ++add)
+         if (dotest(target,source,mult,add,shift,0,print))
+            return 1;
+
+      for (delta=1; delta<=limit; ++delta)
+      {
+#        if 0
+            fprintf(stderr, "%lu/%lu: shift %lu, delta %lu\n", target, source,
+               shift, delta);
+#        endif
+
+         for (add=start; add<=end; ++add)
+         {
+            if (dotest(target, source, mult-delta, add, shift, -delta, print))
+               return 1;
+
+            if (dotest(target, source, mult+delta, add, shift, delta, print))
+               return 1;
+         }
+      }
+   }
+
+   if (print & 4)
+      printf("      {%11lu,%6ld /* >>%lu */ }, /* %lu/%lu ERROR: .5+%g*/\n",
+         minmult, minadd, minshift, target, source, minerr-.5);
+
+   else if (print & 2)
+      printf("      {%11lu,%6ld,%3lu }, /* %lu/%lu ERROR: .5+%g*/\n",
+         minmult, minadd, minshift, target, source, minerr-.5);
+
+   else if (print)
+      printf(
+         "number * %lu/%lu ~= (number * %lu + %ld) >> %lu +/-.5+%g [delta %ld]\n",
+         target, source, minmult, minadd, minshift, minerr-.5, mindelta);
+
+   return 0;
+}
+
+static void
+usage(const char *prog)
+{
+   fprintf(stderr,
+      "usage: %s {--denominator|--maxshift|--code} target {source}\n"
+      " For each 'source' prints 'mult' and 'add' such that:\n\n"
+      "   (number * mult + add) >> 16 = round(number*target/source)\n\n"
+      " for all integer values of number in the range 0..source.\n\n"
+      " --denominator: swap target and source (specify a single source first\n"
+      "                and follow with multiple targets.)\n"
+      "    --maxshift: find the lowest shift value that works for all the\n"
+      "                repeated 'source' values\n"
+      "        --code: output C code for array/structure initialization\n",
+      prog);
+   exit(1);
+}
+
+int
+main(int argc, const char **argv)
+{
+   int i, err = 0, maxshift = 0, firstsrc = 1, code = 0, denominator = 0;
+   unsigned long target, shift = 0;
+
+   while (argc > 1)
+   {
+      if (strcmp(argv[firstsrc], "--maxshift") == 0)
+      {
+         maxshift = 1;
+         ++firstsrc;
+      }
+
+      else if (strcmp(argv[firstsrc], "--code") == 0)
+      {
+         code = 1;
+         ++firstsrc;
+      }
+
+      else if (strcmp(argv[firstsrc], "--denominator") == 0)
+      {
+         denominator = 1;
+         ++firstsrc;
+      }
+
+      else
+         break;
+   }
+
+
+   if (argc < 2+firstsrc)
+      usage(argv[0]);
+
+   target = strtoul(argv[firstsrc++], 0, 0);
+   if (target == 0) usage(argv[0]);
+
+   for (i=firstsrc; i<argc; ++i)
+   {
+      unsigned long source = strtoul(argv[i], 0, 0);
+
+      if (source == 0) usage(argv[0]);
+
+      if (!find(denominator ? source : target, denominator ? target : source,
+         maxshift ? 0 : 1+code, -1))
+         err = 1;
+
+      if (minshift > shift) shift = minshift;
+   }
+
+   if (maxshift) for (i=firstsrc; i<argc; ++i)
+   {
+      unsigned long source = strtoul(argv[i], 0, 0);
+
+      if (!find(denominator ? source : target, denominator ? target : source,
+         code ? 4 : 1, shift))
+         err = 1;
+   }
+
+   /* Just an exit code - the printout above lists the problem */
+   return err;
+}
diff --git a/libpng-manual.txt b/libpng-manual.txt
index 33ae86b..6d3c93f 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.0alpha01 - December 10, 2012
+ libpng version 1.7.0alpha01 - December 15, 2012
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2011 Glenn Randers-Pehrson
@@ -11,7 +11,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.7.0alpha01 - December 10, 2012
+ libpng versions 0.97, January 1998, through 1.7.0alpha01 - December 15, 2012
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2011 Glenn Randers-Pehrson
 
@@ -5126,7 +5126,7 @@
 
 XVI. Y2K Compliance in libpng
 
-December 10, 2012
+December 15, 2012
 
 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 a48a3fe..cc23172 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,4 +1,4 @@
-.TH LIBPNG 3 "December 10, 2012"
+.TH LIBPNG 3 "December 15, 2012"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0alpha01
 .SH SYNOPSIS
@@ -997,7 +997,7 @@
 .SH LIBPNG.TXT
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.7.0alpha01 - December 10, 2012
+ libpng version 1.7.0alpha01 - December 15, 2012
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2011 Glenn Randers-Pehrson
@@ -1008,7 +1008,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.7.0alpha01 - December 10, 2012
+ libpng versions 0.97, January 1998, through 1.7.0alpha01 - December 15, 2012
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2011 Glenn Randers-Pehrson
 
@@ -6124,7 +6124,7 @@
 
 .SH XVI. Y2K Compliance in libpng
 
-December 10, 2012
+December 15, 2012
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
@@ -6393,7 +6393,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.7.0alpha01 - December 10, 2012:
+Libpng version 1.7.0alpha01 - December 15, 2012:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
 
@@ -6416,7 +6416,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.7.0alpha01, December 10, 2012, are
+libpng versions 1.2.6, August 15, 2004, through 1.7.0alpha01, December 15, 2012, 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
@@ -6515,7 +6515,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-December 10, 2012
+December 15, 2012
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index 07d5b33..01bff51 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "December 10, 2012"
+.TH LIBPNGPF 3 "December 15, 2012"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0alpha01
 (private functions)
diff --git a/png.5 b/png.5
index 016082a..9415916 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "December 10, 2012"
+.TH PNG 5 "December 15, 2012"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/pngrutil.c b/pngrutil.c
index f46793e..86bf4cd 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -3868,6 +3868,14 @@
 
 static void
 png_init_filter_functions(png_structrp pp)
+   /* This function is called once for every PNG image to set the
+    * implementations required to reverse the filtering of PNG rows.  Reversing
+    * the filter is the first transformation performed on the row data.  It is
+    * performed in place, therefore an implementation can be selected based on
+    * the image pixel format.  If the implementation depends on image width then
+    * take care to ensure that it works corretly if the image is interlaced -
+    * interlacing causes the actual row width to vary.
+    */
 {
    unsigned int bpp = (pp->pixel_depth + 7) >> 3;
 
@@ -3898,6 +3906,10 @@
 png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
    png_const_bytep prev_row, int filter)
 {
+   /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
+    * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
+    * implementations.  See png_init_filter_functions above.
+    */
    if (pp->read_filter[0] == NULL)
       png_init_filter_functions(pp);
    if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)
diff --git a/projects/vstudio/readme.txt b/projects/vstudio/readme.txt
index 779b946..688aefd 100644
--- a/projects/vstudio/readme.txt
+++ b/projects/vstudio/readme.txt
@@ -1,7 +1,7 @@
 
 VisualStudio instructions
 
-libpng version 1.7.0alpha01 - December 10, 2012
+libpng version 1.7.0alpha01 - December 15, 2012
 
 Copyright (c) 1998-2010 Glenn Randers-Pehrson
 
diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props
index d205e75..752f381 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.0alpha01 - December 10, 2012
+ * libpng version 1.7.0alpha01 - December 15, 2012
  *
  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  *
diff --git a/scripts/README.txt b/scripts/README.txt
index 7d2b023..8fc1251 100644
--- a/scripts/README.txt
+++ b/scripts/README.txt
@@ -1,5 +1,5 @@
 
-Makefiles for  libpng version 1.7.0alpha01 - December 10, 2012
+Makefiles for  libpng version 1.7.0alpha01 - December 15, 2012
 
 pnglibconf.h.prebuilt       =>  Stores configuration settings
  makefile.linux    =>  Linux/ELF makefile
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index 3b9436b..5378c58 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -3,7 +3,7 @@
 
 /* pnglibconf.h - library build configuration */
 
-/* Libpng 1.7.0alpha01 - December 10, 2012 */
+/* Libpng 1.7.0alpha01 - December 15, 2012 */
 
 /* Copyright (c) 1998-2012 Glenn Randers-Pehrson */
 
diff --git a/scripts/symbols.def b/scripts/symbols.def
index 4a6537f..538a9b8 100644
--- a/scripts/symbols.def
+++ b/scripts/symbols.def
@@ -28,7 +28,6 @@
  png_write_info_before_PLTE @20
  png_write_info @21
  png_read_info @22
- png_convert_to_rfc1123 @23
  png_convert_from_struct_tm @24
  png_convert_from_time_t @25
  png_set_expand @26