diff -ru4NwbB libpng-1.5.1/Makefile.am libpng-1.5.2/Makefile.am
--- libpng-1.5.1/Makefile.am	2011-02-02 22:58:25.869490312 -0600
+++ libpng-1.5.2/Makefile.am	2011-03-31 11:23:47.610923954 -0500
@@ -123,9 +123,9 @@
 # with the symbol file format.
 SYMBOL_CFLAGS = -DPNGLIB_LIBNAME='PNG@PNGLIB_MAJOR@@PNGLIB_MINOR@_0'\
 		-DPNGLIB_VERSION='@PNGLIB_VERSION@'\
 		-DSYMBOL_PREFIX='$(SYMBOL_PREFIX)'\
-		-DPNG_NO_USE_READ_MACROS
+		-DPNG_NO_USE_READ_MACROS -DPNG_BUILDING_SYMBOL_TABLE
 
 .dfn.out:
 	rm -f $@ dfn.c dfn?.out
 	test -d scripts || mkdir scripts
@@ -161,9 +161,9 @@
 	rm -f $@ dfn?.out
 	test -z "$(CPPFLAGS)" 
 	echo "com @PNGLIB_VERSION@ STANDARD API DEFINITION" |\
 	$(AWK) -f ${srcdir}/scripts/options.awk out=dfn1.out\
-	    logunsupported=1 - ${srcdir}/scripts/pnglibconf.dfa 1>&2
+	    logunsupported=2 - ${srcdir}/scripts/pnglibconf.dfa 1>&2
 	$(AWK) -f ${srcdir}/scripts/options.awk out=dfn2.out dfn1.out 1>&2
 	rm dfn1.out
 	mv dfn2.out $@
 
diff -ru4NwbB libpng-1.5.1/contrib/pngminim/decoder/makefile libpng-1.5.2/contrib/pngminim/decoder/makefile
--- libpng-1.5.1/contrib/pngminim/decoder/makefile	2011-02-02 22:58:18.911815534 -0600
+++ libpng-1.5.2/contrib/pngminim/decoder/makefile	2011-03-31 11:23:41.516255281 -0500
@@ -3,13 +3,15 @@
 
 #CC=cc
 CC=gcc
 LD=$(CC)
-STRIP=strip
 
 # If awk fails try
 # make AWK=nawk
 
+# If cpp fails try
+# make CPP=/lib/cpp
+
 RM=rm -f
 COPY=cp
 
 CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DNO_GZIP -I. -O1
@@ -86,9 +88,8 @@
 all: pngm2pnm$(E)
 
 pngm2pnm$(E): $(OBJS)
 	$(LD) -o pngm2pnm$(E) $(OBJS)
-	$(STRIP) pngm2pnm$(E)
 
 # The DFA_XTRA setting turns all libpng options off then
 # turns on those required for this minimal build.
 # The CPP_FLAGS setting causes pngusr.h to be included in
diff -ru4NwbB libpng-1.5.1/contrib/pngminim/encoder/makefile libpng-1.5.2/contrib/pngminim/encoder/makefile
--- libpng-1.5.1/contrib/pngminim/encoder/makefile	2011-02-02 22:58:18.945692990 -0600
+++ libpng-1.5.2/contrib/pngminim/encoder/makefile	2011-03-31 11:23:41.551695708 -0500
@@ -3,13 +3,15 @@
 
 #CC=cc
 CC=gcc
 LD=$(CC)
-STRIP=strip
 
 # If awk fails try
 # make AWK=nawk
 
+# If cpp fails try
+# make CPP=/lib/cpp
+
 RM=rm -f
 COPY=cp
 
 CFLAGS=-DPNG_USER_CONFIG -DNO_GZIP -I. -O1
@@ -85,9 +87,8 @@
 all: pnm2pngm$(E)
 
 pnm2pngm$(E): $(OBJS)
 	$(LD) -o pnm2pngm$(E) $(OBJS)
-	$(STRIP) pnm2pngm$(E)
 
 # The DFA_XTRA setting turns all libpng options off then
 # turns on those required for this minimal build.
 # The CPP_FLAGS setting causes pngusr.h to be included in
diff -ru4NwbB libpng-1.5.1/contrib/pngminim/preader/makefile libpng-1.5.2/contrib/pngminim/preader/makefile
--- libpng-1.5.1/contrib/pngminim/preader/makefile	2011-02-02 22:58:18.979854051 -0600
+++ libpng-1.5.2/contrib/pngminim/preader/makefile	2011-03-31 11:23:41.587641284 -0500
@@ -3,13 +3,15 @@
 
 #CC=cc
 CC=gcc
 LD=$(CC)
-STRIP=strip
 
 # If awk fails try
 # make AWK=nawk
 
+# If cpp fails try
+# make CPP=/lib/cpp
+
 RM=rm -f
 COPY=cp
 
 #XINC = -I/usr/include			# old-style, stock X distributions
@@ -101,9 +103,8 @@
 all: $(PROGDOCS) rpng2-x$(E)
 
 rpng2-x$(E): $(OBJS)
 	$(LD) -o rpng2-x$(E) $(OBJS) $(LIBS)
-	$(STRIP) rpng2-x$(E)
 
 # The DFA_XTRA setting turns all libpng options off then
 # turns on those required for this minimal build.
 # The CPP_FLAGS setting causes pngusr.h to be included in
diff -ru4NwbB libpng-1.5.1/example.c libpng-1.5.2/example.c
--- libpng-1.5.1/example.c	2011-02-02 22:58:17.717026939 -0600
+++ libpng-1.5.2/example.c	2011-03-31 11:23:40.691343668 -0500
@@ -1,9 +1,9 @@
 
 #if 0 /* in case someone actually tries to compile this */
 
 /* example.c - an example of using libpng
- * Last changed in libpng 1.5.0 [January 6, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * This file has been placed in the public domain by the authors.
  * Maintained 1998-2011 Glenn Randers-Pehrson
  * Maintained 1996, 1997 Andreas Dilger)
  * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
diff -ru4NwbB libpng-1.5.1/png.c libpng-1.5.2/png.c
--- libpng-1.5.1/png.c	2011-02-02 22:58:17.727227609 -0600
+++ libpng-1.5.2/png.c	2011-03-31 11:23:40.702025995 -0500
@@ -1,8 +1,8 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.1 [February 3, 2011]
  * Copyright (c) 1998-2011 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.)
  *
diff -ru4NwbB libpng-1.5.1/png.h libpng-1.5.2/png.h
--- libpng-1.5.1/png.h	2011-02-02 22:58:17.679708709 -0600
+++ libpng-1.5.2/png.h	2011-03-31 11:23:40.652780723 -0500
@@ -146,8 +146,11 @@
  *    1.5.0                   15    10500  15.so.15.0[.0]
  *    1.5.1beta01-11          15    10501  15.so.15.1[.0]
  *    1.5.1rc01-02            15    10501  15.so.15.1[.0]
  *    1.5.1                   15    10501  15.so.15.1[.0]
+ *    1.5.2beta01-03          15    10502  15.so.15.2[.0]
+ *    1.5.2rc01-03            15    10502  15.so.15.2[.0]
+ *    1.5.2                   15    10502  15.so.15.2[.0]
  *
  *   Henceforth the source version will match the shared-library major
  *   and minor numbers; the shared-library major version number will be
  *   used for changes in backward compatibility, as it is intended.  The
@@ -404,9 +407,13 @@
 #   include "pnglibconf.h"
 #endif
 
 #ifndef PNG_VERSION_INFO_ONLY
-/* Standard header files (not needed for the version info) */
+#  ifndef PNG_BUILDING_SYMBOL_TABLE
+  /*
+   *   Standard header files (not needed for the version info or while
+   *   building symbol table -- see scripts/pnglibconf.dfa)
+   */
 #  ifdef PNG_SETJMP_SUPPORTED
 #    include <setjmp.h>
 #  endif
 
@@ -416,8 +423,9 @@
 #ifdef PNG_CONVERT_tIME_SUPPORTED
    /* "time.h" functions are not supported on all operating systems */
 #  include <time.h>
 #endif
+#  endif
 
 /* Machine specific configuration. */
 #  include "pngconf.h"
 #endif
@@ -795,37 +803,46 @@
 typedef struct png_struct_def png_struct;
 typedef PNG_CONST png_struct FAR * png_const_structp;
 typedef png_struct FAR * png_structp;
 
-typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp), );
-typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t), );
-typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp), );
+typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));
+typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t));
+typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));
 typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32, 
-    int), );
+    int));
 typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32, 
-    int), );
+    int));
 
 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-typedef PNG_CALLBACK(void, *png_progressive_info_ptr, 
-    (png_structp, png_infop), );
-typedef PNG_CALLBACK(void, *png_progressive_end_ptr,
-    (png_structp, png_infop), );
-typedef PNG_CALLBACK(void, *png_progressive_row_ptr,
-    (png_structp, png_bytep, png_uint_32, int), );
+typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));
+typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));
+
+/* The following callback receives png_uint_32 row_number, int pass for the
+ * png_bytep data of the row.  When transforming an interlaced image the
+ * row number is the row number within the sub-image of the interlace pass, so
+ * the value will increase to the height of the sub-image (not the full image)
+ * then reset to 0 for the next pass.
+ *
+ * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
+ * find the output pixel (x,y) given an interlaced sub-image pixel
+ * (row,col,pass).  (See below for these macros.)
+ */
+typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep,
+    png_uint_32, int));
 #endif
 
 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
     defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
-typedef PNG_CALLBACK(void, *png_user_transform_ptr,
-    (png_structp, png_row_infop, png_bytep), );
+typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop,
+    png_bytep));
 #endif
 
 #ifdef PNG_USER_CHUNKS_SUPPORTED
 typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp, 
-    png_unknown_chunkp), );
+    png_unknown_chunkp));
 #endif
 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
-typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp), );
+typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp));
 #endif
 
 #ifdef PNG_SETJMP_SUPPORTED
 /* This must match the function definition in <setjmp.h>, and the
@@ -880,10 +897,10 @@
  * ignores the first argument) should be completely compatible with the
  * following.
  */
 typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp, 
-    png_alloc_size_t), );
-typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp), );
+    png_alloc_size_t));
+typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));
 
 typedef png_struct FAR * FAR * png_structpp;
 
 /* Section 3: exported functions
@@ -1060,8 +1077,15 @@
 PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structp png_ptr));
 PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structp png_ptr));
 #endif
 
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
+/* Expand to 16 bit channels, forces conversion of palette to RGB and expansion
+ * of a tRNS chunk if present.
+ */
+PNG_EXPORT(221, void, png_set_expand_16, (png_structp png_ptr));
+#endif
+
 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
 /* Use blue, green, red order for pixels. */
 PNG_EXPORT(30, void, png_set_bgr, (png_structp png_ptr));
 #endif
@@ -1474,11 +1498,15 @@
 #ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
 /* Return information about the row currently being processed.  Note that these
  * APIs do not fail but will return unexpected results if called outside a user
  * transform callback.  Also note that when transforming an interlaced image the
- * row number is still the row in the final, de-interlaced, image but the row
- * only contains the data of the current pass - consult png_row_info for the
- * actual width of the row!
+ * row number is the row number within the sub-image of the interlace pass, so
+ * the value will increase to the height of the sub-image (not the full image)
+ * then reset to 0 for the next pass.
+ *
+ * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
+ * find the output pixel (x,y) given an interlaced sub-image pixel
+ * (row,col,pass).  (See below for these macros.)
  */
 PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp));
 PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp));
 #endif
@@ -2141,10 +2169,11 @@
    -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
 #define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
    -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
 
-/* For the progressive reader it is necessary to find the row in the output
- * image given a row in an interlaced image, so two more macros:
+/* For the reader row callbacks (both progressive and sequential) it is
+ * necessary to find the row in the output image given a row in an interlaced
+ * image, so two more macros:
  */
 #define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
    (((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
 #define PNG_COL_FROM_PASS_COL(xIn, pass) \
@@ -2267,9 +2296,9 @@
  * one to use is one more than this.)  Maintainer, remember to add an entry to
  * scripts/symbols.def as well.
  */
 #ifdef PNG_EXPORT_LAST_ORDINAL
-  PNG_EXPORT_LAST_ORDINAL(220);
+  PNG_EXPORT_LAST_ORDINAL(221);
 #endif
 
 #ifdef __cplusplus
 }
diff -ru4NwbB libpng-1.5.1/pngconf.h libpng-1.5.2/pngconf.h
--- libpng-1.5.1/pngconf.h	2011-02-02 22:58:17.686514505 -0600
+++ libpng-1.5.2/pngconf.h	2011-03-31 11:23:40.659587365 -0500
@@ -1,8 +1,8 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.5.2 - March 31, 2011
+ * libpng version 1.5.2 - March 31, 2011
  *
  * Copyright (c) 1998-2011 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.)
@@ -21,8 +21,9 @@
 
 #ifndef PNGCONF_H
 #define PNGCONF_H
 
+#ifndef PNG_BUILDING_SYMBOL_TABLE
 /* PNG_NO_LIMITS_H may be used to turn off the use of the standard C
  * definition file for  machine specific limits, this may impact the
  * correctness of the definitons below (see uses of INT_MAX).
  */
@@ -45,8 +46,9 @@
  */
 #ifdef PNG_STDIO_SUPPORTED
 #  include <stdio.h>
 #endif
+#endif
 
 /* This controls optimization of the reading of 16 and 32 bit values
  * from PNG files.  It can be set on a per-app-file basis - it
  * just changes whether a macro is used to the function is called.
@@ -281,25 +283,17 @@
 #    define PNG_IMPEXP
 #  endif
 #endif
 
-/* THe following complexity is concerned with getting the 'attributes' of the
- * declared function in the correct place.  This potentially requires a separate
- * PNG_EXPORT function for every compiler.
+/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat
+ * 'attributes' as a storage class - the attributes go at the start of the
+ * function definition, and attributes are always appended regardless of the
+ * compiler.  This considerably simplifies these macros but may cause problems
+ * if any compilers both need function attributes and fail to handle them as
+ * a storage class (this is unlikely.)
  */
 #ifndef PNG_FUNCTION
-#  ifdef __GNUC__
-#     define PNG_FUNCTION(type, name, args, attributes)\
-         attributes type name args
-#  else /* !GNUC */
-#     ifdef _MSC_VER
-#        define PNG_FUNCTION(type, name, args, attributes)\
-         attributes type name args
-#     else /* !MSC */
-#        define PNG_FUNCTION(type, name, args, attributes)\
-            type name args
-#     endif
-#  endif
+#  define PNG_FUNCTION(type, name, args, attributes) attributes type name args
 #endif
 
 #ifndef PNG_EXPORT_TYPE
 #  define PNG_EXPORT_TYPE(type) PNG_IMPEXP type
@@ -309,24 +303,29 @@
     * table entries, so we discard it here.  See the .dfn files in the
     * scripts directory.
     */
 #ifndef PNG_EXPORTA
+
 #  define PNG_EXPORTA(ordinal, type, name, args, attributes)\
-      extern PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args),\
-         attributes)
+      PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \
+        extern attributes)
 #endif
 
+/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
+ * so make something non-empty to satisfy the requirement:
+ */
+#define PNG_EMPTY /*empty list*/
+
 #define PNG_EXPORT(ordinal, type, name, args)\
-   PNG_EXPORTA(ordinal, type, name, args, )
+   PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
 
 /* Use PNG_REMOVED to comment out a removed interface. */
 #ifndef PNG_REMOVED
 #  define PNG_REMOVED(ordinal, type, name, args, attributes)
 #endif
 
 #ifndef PNG_CALLBACK
-#  define PNG_CALLBACK(type, name, args, attributes)\
-   type (PNGCBAPI name) PNGARG(args) attributes
+#  define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args)
 #endif
 
 /* Support for compiler specific function attributes.  These are used
  * so that where compiler support is available incorrect use of API
@@ -346,18 +345,32 @@
    * so that where compiler support is available incorrect use of API
    * functions in png.h will generate compiler warnings.  Added at libpng
    * version 1.2.41.
    */
-#  ifdef __GNUC__
+#  if defined(__GNUC__)
 #    ifndef PNG_USE_RESULT
 #      define PNG_USE_RESULT __attribute__((__warn_unused_result__))
 #    endif
 #    ifndef PNG_NORETURN
 #      define PNG_NORETURN   __attribute__((__noreturn__))
 #    endif
 #    ifndef PNG_PTR_NORETURN
+       /* It's not enough to have the compiler be the correct compiler at
+        * this point - it's necessary for the library (which defines
+        * the type of the library longjmp) to also be the GNU library.
+        * This is because many systems use the GNU compiler with a
+        * non-GNU libc implementation.  Min/GW headers are also compatible
+        * with GCC as well as uclibc, so it seems best to exclude known
+        * problem libcs here rather than just including known libcs.
+        *
+        * NOTE: this relies on the only use of PNG_PTR_NORETURN being with
+        * the system longjmp.  If the same type is used elsewhere then this
+        * will need to be changed.
+        */
+#      if !defined(__CYGWIN__)
 #      define PNG_PTR_NORETURN   __attribute__((__noreturn__))
 #    endif
+#    endif
 #    ifndef PNG_ALLOCATED
 #      define PNG_ALLOCATED  __attribute__((__malloc__))
 #    endif
 
@@ -379,12 +392,13 @@
 #        else
 #          define PNG_PRIVATE \
             __attribute__((__deprecated__))
 #        endif
-#      endif /* PNG_PRIVATE */
+#      endif
 #    endif /* PNGLIB_BUILD */
 #  endif /* __GNUC__ */
-#  ifdef _MSC_VER /* may need to check value */
+
+#  if defined(_MSC_VER)  && (_MSC_VER >= 1300)
 #    ifndef PNG_USE_RESULT
 #      define PNG_USE_RESULT /*not supported*/
 #    endif
 #    ifndef PNG_NORETURN
@@ -409,11 +423,11 @@
 #        define PNG_DEPSTRUCT  __declspec(deprecated)
 #      endif
 #      ifndef PNG_PRIVATE
 #        define PNG_PRIVATE __declspec(deprecated)
-#      endif /* PNG_PRIVATE */
+#      endif
 #    endif /* PNGLIB_BUILD */
-#  endif /* __GNUC__ */
+#  endif /* _MSC_VER */
 #endif /* PNG_PEDANTIC_WARNINGS */
 
 #ifndef PNG_DEPRECATED
 #  define PNG_DEPRECATED  /* Use of this function is deprecated */
@@ -423,8 +437,11 @@
 #endif
 #ifndef PNG_NORETURN
 #  define PNG_NORETURN    /* This function does not return */
 #endif
+#ifndef PNG_PTR_NORETURN
+#  define PNG_PTR_NORETURN /* This function does not return */
+#endif
 #ifndef PNG_ALLOCATED
 #  define PNG_ALLOCATED   /* The result of the function is new memory */
 #endif
 #ifndef PNG_DEPSTRUCT
diff -ru4NwbB libpng-1.5.1/pngerror.c libpng-1.5.2/pngerror.c
--- libpng-1.5.1/pngerror.c	2011-02-02 22:58:17.732911879 -0600
+++ libpng-1.5.2/pngerror.c	2011-03-31 11:23:40.707921261 -0500
@@ -1,8 +1,8 @@
 
 /* pngerror.c - stub functions for i/o and memory allocation
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.1 [February 3, 2011]
  * Copyright (c) 1998-2011 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.)
  *
diff -ru4NwbB libpng-1.5.1/pngget.c libpng-1.5.2/pngget.c
--- libpng-1.5.1/pngget.c	2011-02-02 22:58:17.740070723 -0600
+++ libpng-1.5.2/pngget.c	2011-03-31 11:23:40.715373597 -0500
@@ -1,8 +1,8 @@
 
 /* pngget.c - retrieval of values from info struct
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.1 [February 3, 2011]
  * Copyright (c) 1998-2011 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.)
  *
diff -ru4NwbB libpng-1.5.1/pngmem.c libpng-1.5.2/pngmem.c
--- libpng-1.5.1/pngmem.c	2011-02-02 22:58:17.746290285 -0600
+++ libpng-1.5.2/pngmem.c	2011-03-31 11:23:40.721711366 -0500
@@ -1,8 +1,8 @@
 
 /* pngmem.c - stub functions for memory allocation
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.1 [February 3, 2011]
  * Copyright (c) 1998-2011 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.)
  *
diff -ru4NwbB libpng-1.5.1/pngpread.c libpng-1.5.2/pngpread.c
--- libpng-1.5.1/pngpread.c	2011-02-02 22:58:17.755135954 -0600
+++ libpng-1.5.2/pngpread.c	2011-03-31 11:23:40.730867797 -0500
@@ -1,8 +1,8 @@
 
 /* pngpread.c - read a png file in push mode
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * Copyright (c) 1998-2011 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.)
  *
@@ -1025,9 +1025,9 @@
        (int)(png_ptr->row_buf[0]));
 
    png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
 
-   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
+   if (png_ptr->transformations)
       png_do_read_transformations(png_ptr);
 
 #ifdef PNG_READ_INTERLACING_SUPPORTED
    /* Blow up interlaced rows to full size */
diff -ru4NwbB libpng-1.5.1/pngpriv.h libpng-1.5.2/pngpriv.h
--- libpng-1.5.1/pngpriv.h	2011-02-02 22:58:17.694499401 -0600
+++ libpng-1.5.2/pngpriv.h	2011-03-31 11:23:40.667851883 -0500
@@ -5,9 +5,9 @@
  * Copyright (c) 1998-2011 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.)
  *
- * Last changed in libpng 1.5.0 [January 6, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  *
  * This code is released under the libpng license.
  * For conditions of distribution and use, see the disclaimer
  * and license in png.h
@@ -82,15 +82,17 @@
 #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
 #  define PNG_MAX_MALLOC_64K
 #endif
 
+#ifndef PNG_UNUSED
 /* Unused formal parameter warnings are silenced using the following macro
  * which is expected to have no bad effects on performance (optimizing
  * compilers will probably remove it entirely).  Note that if you replace
  * it with something other than whitespace, you must include the terminating
  * semicolon.
  */
 #define PNG_UNUSED(param) (void)param;
+#endif
 
 /* Just a little check that someone hasn't tried to define something
  * contradictory.
  */
@@ -285,9 +287,9 @@
 #define PNG_INVERT_MONO         0x0020
 #define PNG_QUANTIZE            0x0040
 #define PNG_BACKGROUND          0x0080
 #define PNG_BACKGROUND_EXPAND   0x0100
-                          /*    0x0200 unused */
+#define PNG_EXPAND_16           0x0200     /* Added to libpng 1.5.2 */
 #define PNG_16_TO_8             0x0400
 #define PNG_RGBA                0x0800
 #define PNG_EXPAND              0x1000
 #define PNG_GAMMA               0x2000
@@ -339,10 +341,10 @@
 #define PNG_FLAG_LIBRARY_MISMATCH         0x20000L
 #define PNG_FLAG_STRIP_ERROR_NUMBERS      0x40000L
 #define PNG_FLAG_STRIP_ERROR_TEXT         0x80000L
 #define PNG_FLAG_MALLOC_NULL_MEM_OK       0x100000L
-#define PNG_FLAG_ADD_ALPHA                0x200000L  /* Added to libpng-1.2.8 */
-#define PNG_FLAG_STRIP_ALPHA              0x400000L  /* Added to libpng-1.2.8 */
+                                  /*      0x200000L  unused */
+                                  /*      0x400000L  unused */
 #define PNG_FLAG_BENIGN_ERRORS_WARN       0x800000L  /* Added to libpng-1.4.0 */
                                   /*     0x1000000L  unused */
                                   /*     0x2000000L  unused */
                                   /*     0x4000000L  unused */
@@ -771,10 +773,10 @@
 #endif
 
 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
     defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
-PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
-    png_bytep row, png_uint_32 flags));
+PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info,
+    png_bytep row, int at_start));
 #endif
 
 #ifdef PNG_16BIT_SUPPORTED
 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
@@ -874,8 +876,13 @@
 PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
     png_bytep row, png_const_color_16p trans_color));
 #endif
 
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
+PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info,
+    png_bytep row));
+#endif
+
 /* The following decodes the appropriate chunks, and does error correction,
  * then calls the appropriate callback for the chunk if it is valid.
  */
 
@@ -1183,15 +1190,15 @@
  * for overflow, true (1) if no overflow, in which case *res
  * holds the result.
  */
 PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a,
-    png_int_32 times, png_int_32 div));
+    png_int_32 multiplied_by, png_int_32 divided_by));
 #endif
 
 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
 /* Same deal, but issue a warning on overflow and return 0. */
 PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr,
-    png_fixed_point a, png_int_32 times, png_int_32 div));
+    png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by));
 #endif
 
 #ifdef PNG_READ_GAMMA_SUPPORTED
 /* Calculate a reciprocal - used for gamma values.  This returns
@@ -1216,14 +1223,14 @@
  * While the input is an 'unsigned' value it must actually be the
  * correct bit value - 0..255 or 0..65535 as required.
  */
 PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr,
-    unsigned int value, png_fixed_point gamma));
-PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma));
+    unsigned int value, png_fixed_point gamma_value));
+PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value));
 PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value,
-    png_fixed_point gamma));
+    png_fixed_point gamma_value));
 PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value,
-    png_fixed_point gamma));
+    png_fixed_point gamma_value));
 PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
     int bit_depth));
 #endif
 
diff -ru4NwbB libpng-1.5.1/pngread.c libpng-1.5.2/pngread.c
--- libpng-1.5.1/pngread.c	2011-02-02 22:58:17.763092690 -0600
+++ libpng-1.5.2/pngread.c	2011-03-31 11:23:40.738999129 -0500
@@ -1,8 +1,8 @@
 
 /* pngread.c - read a PNG file
  *
- * Last changed in libpng 1.5.1 [$RDATE%]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * Copyright (c) 1998-2011 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.)
  *
@@ -487,11 +487,13 @@
 void PNGAPI
 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
 {
    PNG_IDAT;
+#ifdef PNG_READ_INTERLACING_SUPPORTED
    PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
        0xff};
    PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
+#endif
    int ret;
 
    if (png_ptr == NULL)
       return;
@@ -701,9 +703,9 @@
    }
 #endif
 
 
-   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
+   if (png_ptr->transformations)
       png_do_read_transformations(png_ptr);
 
 #ifdef PNG_READ_INTERLACING_SUPPORTED
    /* Blow up interlaced rows to full size */
@@ -1310,9 +1312,9 @@
                            voidp params)
 {
    int row;
 
-   if (png_ptr == NULL)
+   if (png_ptr == NULL || info_ptr == NULL)
       return;
 
    /* png_read_info() gives us all of the information from the
     * PNG file before the first IDAT (image data chunk).
@@ -1425,8 +1427,13 @@
 #endif
 
    /* We don't handle adding filler bytes */
 
+   /* We use png_read_image and rely on that for interlace handling, but we also
+    * call png_read_update_info therefore must turn on interlace handling now:
+    */
+   (void)png_set_interlace_handling(png_ptr);
+
    /* Optional call to gamma correct and add the background to the palette
     * and update info structure.  REQUIRED if you are expecting libpng to
     * update the palette for you (i.e., you selected such a transform above).
     */
diff -ru4NwbB libpng-1.5.1/pngrtran.c libpng-1.5.2/pngrtran.c
--- libpng-1.5.1/pngrtran.c	2011-02-02 22:58:17.782646907 -0600
+++ libpng-1.5.2/pngrtran.c	2011-03-31 11:23:40.759414573 -0500
@@ -1,8 +1,8 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * Copyright (c) 1998-2011 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.)
  *
@@ -136,8 +136,9 @@
    if (png_ptr == NULL)
       return;
 
    png_ptr->transformations |= PNG_16_TO_8;
+   png_ptr->transformations &= ~PNG_EXPAND_16;
 }
 #endif
 
 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
@@ -148,9 +149,9 @@
 
    if (png_ptr == NULL)
       return;
 
-   png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
+   png_ptr->transformations |= PNG_STRIP_ALPHA;
 }
 #endif
 
 #ifdef PNG_READ_QUANTIZE_SUPPORTED
@@ -685,8 +686,27 @@
    png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
 }
 #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
 
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
+/* Expand to 16 bit channels, expand the tRNS chunk too (because otherwise
+ * it may not work correctly.)
+ */
+void PNGAPI
+png_set_expand_16(png_structp png_ptr)
+{
+   png_debug(1, "in png_set_expand_16");
+
+   if (png_ptr == NULL)
+      return;
+
+   png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);
+   png_ptr->transformations &= ~PNG_16_TO_8;
+
+   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
+}
+#endif
+
 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
 void PNGAPI
 png_set_gray_to_rgb(png_structp png_ptr)
 {
@@ -1072,9 +1092,9 @@
              * to a simple alpha channel strip.
              */
             png_ptr->transformations &= ~PNG_BACKGROUND;
             png_ptr->transformations &= ~PNG_GAMMA;
-            png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
+            png_ptr->transformations |= PNG_STRIP_ALPHA;
          }
 
          /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
          else
@@ -1206,9 +1226,9 @@
       }
 
       /* Handled alpha, still need to strip the channel. */
       png_ptr->transformations &= ~PNG_BACKGROUND;
-      png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
+      png_ptr->transformations |= PNG_STRIP_ALPHA;
    }
 #endif /* PNG_READ_BACKGROUND_SUPPORTED */
 
 #ifdef PNG_READ_SHIFT_SUPPORTED
@@ -1284,8 +1304,16 @@
       }
    }
 #endif
 
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
+   if (png_ptr->transformations & PNG_EXPAND_16 && info_ptr->bit_depth == 8 &&
+      info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
+   {
+      info_ptr->bit_depth = 16;
+   }
+#endif
+
 #ifdef PNG_READ_BACKGROUND_SUPPORTED
    if (png_ptr->transformations & PNG_BACKGROUND)
    {
       info_ptr->color_type = (png_byte)(info_ptr->color_type &
@@ -1352,9 +1380,9 @@
    else
       info_ptr->channels = 1;
 
 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
-   if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
+   if (png_ptr->transformations & PNG_STRIP_ALPHA)
       info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
 #endif
 
    if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
@@ -1444,20 +1473,26 @@
          if (png_ptr->num_trans &&
              (png_ptr->transformations & PNG_EXPAND_tRNS))
             png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
                 &(png_ptr->trans_color));
-         else
 
+         else
             png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
                 NULL);
       }
    }
 #endif
 
+   /* Delay the 'expand 16' step until later for efficiency, so that the
+    * intermediate steps work with 8 bit data.
+    */
+
 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
-   if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
-      png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
-          PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
+   if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
+      (png_ptr->row_info.color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
+      png_ptr->row_info.color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
+      png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1,
+         0/*!at_start, because SWAP_ALPHA happens later*/);
 #endif
 
 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
    if (png_ptr->transformations & PNG_RGB_TO_GRAY)
@@ -1564,8 +1599,18 @@
          png_error(png_ptr, "png_do_quantize returned rowbytes=0");
    }
 #endif /* PNG_READ_QUANTIZE_SUPPORTED */
 
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
+   /* Do the expansion now, after all the arithmetic has been done.  Notice
+    * that previous transformations can handle the PNG_EXPAND_16 flag if this
+    * is efficient (particularly true in the case of gamma correction, where
+    * better accuracy results faster!)
+    */
+   if (png_ptr->transformations & PNG_EXPAND_16)
+      png_do_expand_16(&png_ptr->row_info, png_ptr->row_buf + 1);
+#endif
+
 #ifdef PNG_READ_INVERT_SUPPORTED
    if (png_ptr->transformations & PNG_INVERT_MONO)
       png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
 #endif
@@ -1591,8 +1636,11 @@
       png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
 #endif
 
 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
+   /*NOTE: this must be in the wrong place - what happens if BGR is set too?
+    * Need pngvalid to test this combo.
+    */
    /* If gray -> RGB, do so now only if we did not do so above */
    if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
        (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
       png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -4063,8 +4111,39 @@
    }
 }
 #endif
 
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
+/* If the bit depth is 8 and the colour type is not a palette type expand the
+ * whole row to 16 bits.  Has no effect otherwise.
+ */
+void /* PRIVATE */
+png_do_expand_16(png_row_infop row_info, png_bytep row)
+{
+   if (row_info->bit_depth == 8 &&
+      row_info->color_type != PNG_COLOR_TYPE_PALETTE)
+   {
+      /* The row have a sequence of bytes containing [0..255] and we need
+       * to turn it into another row containing [0..65535], to do this we
+       * calculate:
+       *
+       *  (input / 255) * 65535
+       *
+       *  Which happens to be exactly input * 257 and this can be achieved
+       *  simply by byte replication in place (copying backwards).
+       */
+      png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
+      png_byte *dp = sp + row_info->rowbytes;  /* destination, end + 1 */
+      while (dp > sp)
+         dp[-2] = dp[-1] = *--sp, dp -= 2;
+
+      row_info->rowbytes *= 2;
+      row_info->bit_depth = 16;
+      row_info->pixel_depth = (png_byte)(row_info->channels * 16);
+   }
+}
+#endif
+
 #ifdef PNG_READ_QUANTIZE_SUPPORTED
 void /* PRIVATE */
 png_do_quantize(png_row_infop row_info, png_bytep row,
     png_const_bytep palette_lookup, png_const_bytep quantize_lookup)
diff -ru4NwbB libpng-1.5.1/pngrutil.c libpng-1.5.2/pngrutil.c
--- libpng-1.5.1/pngrutil.c	2011-02-02 22:58:17.796148619 -0600
+++ libpng-1.5.2/pngrutil.c	2011-03-31 11:23:40.773411012 -0500
@@ -1,8 +1,8 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * Copyright (c) 1998-2011 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.)
  *
@@ -1274,11 +1274,9 @@
 /* Note: this does not properly handle chunks that are > 64K under DOS */
 {
    png_bytep entry_start;
    png_sPLT_t new_palette;
-#ifdef PNG_POINTER_INDEXING_SUPPORTED
    png_sPLT_entryp pp;
-#endif
    png_uint_32 data_length;
    int entry_size, i;
    png_uint_32 skip = 0;
    png_size_t slength;
@@ -1441,9 +1439,9 @@
          pp[i].blue  = png_get_uint_16(entry_start); entry_start += 2;
          pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
       }
 
-      pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
+      pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2;
    }
 #endif
 
    /* Discard all chunk data except the name and stash that */
@@ -3462,8 +3460,26 @@
       }
    }
 #endif
 
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
+   if (png_ptr->transformations & PNG_EXPAND_16)
+   {
+#     ifdef PNG_READ_EXPAND_SUPPORTED
+         /* In fact it is an error if it isn't supported, but checking is
+          * the safe way.
+          */
+         if (png_ptr->transformations & PNG_EXPAND)
+         {
+            if (png_ptr->bit_depth < 16)
+               max_pixel_depth *= 2;
+         }
+         else
+#     endif
+         png_ptr->transformations &= ~PNG_EXPAND_16;
+   }
+#endif
+
 #ifdef PNG_READ_FILLER_SUPPORTED
    if (png_ptr->transformations & (PNG_FILLER))
    {
       if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
diff -ru4NwbB libpng-1.5.1/pngset.c libpng-1.5.2/pngset.c
--- libpng-1.5.1/pngset.c	2011-02-02 22:58:17.804187237 -0600
+++ libpng-1.5.2/pngset.c	2011-03-31 11:23:40.781719738 -0500
@@ -1,8 +1,8 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.1 [February 3, 2011]
  * Copyright (c) 1998-2011 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.)
  *
diff -ru4NwbB libpng-1.5.1/pngtrans.c libpng-1.5.2/pngtrans.c
--- libpng-1.5.1/pngtrans.c	2011-02-02 22:58:17.819661451 -0600
+++ libpng-1.5.2/pngtrans.c	2011-03-31 11:23:40.797375493 -0500
@@ -1,8 +1,8 @@
 
 /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * Copyright (c) 1998-2011 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.)
  *
@@ -423,172 +423,117 @@
 #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
 
 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
     defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
-/* Remove filler or alpha byte(s) */
+/* Remove a channel - this used to be 'png_do_strip_filler' but it used a
+ * somewhat weird combination of flags to determine what to do.  All the calls
+ * to png_do_strip_filler are changed in 1.5.2 to call this instead with the
+ * correct arguments.
+ *
+ * The routine isn't general - the channel must be the channel at the start or
+ * end (not in the middle) of each pixel.
+ */
 void /* PRIVATE */
-png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
+png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
 {
-   png_debug(1, "in png_do_strip_filler");
-
-   {
-      png_bytep sp = row;
-      png_bytep dp = row;
-      png_uint_32 row_width = row_info->width;
-      png_uint_32 i;
-
-      if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
-          (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
-          (flags & PNG_FLAG_STRIP_ALPHA))) &&
-          row_info->channels == 4)
+   png_bytep sp = row; /* source pointer */
+   png_bytep dp = row; /* destination pointer */
+   png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */
+
+   /* At the start sp will point to the first byte to copy and dp to where
+    * it is copied to.  ep always points just beyond the end of the row, so
+    * the loop simply copies (channels-1) channels until sp reaches ep.
+    */
+   /* GA, GX, XG cases */
+   if (row_info->channels == 2)
       {
          if (row_info->bit_depth == 8)
          {
-            /* This converts from RGBX or RGBA to RGB */
-            if (flags & PNG_FLAG_FILLER_AFTER)
-            {
-               dp += 3; sp += 4;
-               for (i = 1; i < row_width; i++)
-               {
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  sp++;
-               }
-            }
+         if (at_start) /* Skip initial filler */
+            ++sp;
+         else          /* Skip initial channels and, for sp, the filler */
+            sp += 2, ++dp;
+
+         /* For a 1 pixel wide image there is nothing to do */
+         while (sp < ep)
+            *dp++ = *sp, sp += 2;
 
-            /* This converts from XRGB or ARGB to RGB */
-            else
-            {
-               for (i = 0; i < row_width; i++)
-               {
-                  sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-               }
-            }
-            row_info->pixel_depth = 24;
-            row_info->rowbytes = row_width * 3;
+         row_info->pixel_depth = 8;
          }
 
-         else /* if (row_info->bit_depth == 16) */
-         {
-            if (flags & PNG_FLAG_FILLER_AFTER)
-            {
-               /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
-               sp += 8; dp += 6;
-               for (i = 1; i < row_width; i++)
+      else if (row_info->bit_depth == 16)
                {
-                  /* This could be (although png_memcpy is probably slower):
-                  png_memcpy(dp, sp, 6);
-                  sp += 8;
-                  dp += 6;
-                  */
-
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
+         if (at_start)
                   sp += 2;
-               }
+         else
+            sp += 4, dp += 2;
+
+         while (sp < ep)
+            *dp++ = *sp++, *dp++ = *sp, sp += 3;
+
+         row_info->pixel_depth = 16;
             }
 
             else
-            {
-               /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
-               for (i = 0; i < row_width; i++)
-               {
-                  /* This could be (although png_memcpy is probably slower):
-                  png_memcpy(dp, sp, 6);
-                  sp += 8;
-                  dp += 6;
-                  */
+         return; /* bad bit depth */
 
-                  sp += 2;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-               }
-            }
+      row_info->channels = 1;
 
-            row_info->pixel_depth = 48;
-            row_info->rowbytes = row_width * 6;
-         }
-         row_info->channels = 3;
+      /* Finally fix the color type if it records an alpha channel */
+      if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+         row_info->color_type = PNG_COLOR_TYPE_GRAY;
       }
 
-      else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
-         (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
-         (flags & PNG_FLAG_STRIP_ALPHA))) &&
-          row_info->channels == 2)
+   /* RGBA, RGBX, XRGB cases */
+   else if (row_info->channels == 4)
       {
          if (row_info->bit_depth == 8)
          {
-            if (flags & PNG_FLAG_FILLER_AFTER)
-            {
-               /* This converts from GX or GA to G */
-               for (i = 0; i < row_width; i++)
-               {
-                  *dp++ = *sp++;
-                  sp++;
-               }
-            }
+         if (at_start) /* Skip initial filler */
+            ++sp;
+         else          /* Skip initial channels and, for sp, the filler */
+            sp += 4, dp += 3;
+
+         /* Note that the loop adds 3 to dp and 4 to sp each time. */
+         while (sp < ep)
+            *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
 
-            else
-            {
-               /* This converts from XG or AG to G */
-               for (i = 0; i < row_width; i++)
-               {
-                  sp++;
-                  *dp++ = *sp++;
-               }
-            }
-
-            row_info->pixel_depth = 8;
-            row_info->rowbytes = row_width;
+         row_info->pixel_depth = 24;
          }
 
-         else /* if (row_info->bit_depth == 16) */
-         {
-            if (flags & PNG_FLAG_FILLER_AFTER)
-            {
-               /* This converts from GGXX or GGAA to GG */
-               sp += 4; dp += 2;
-               for (i = 1; i < row_width; i++)
+      else if (row_info->bit_depth == 16)
                {
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
+         if (at_start)
                   sp += 2;
-               }
-            }
-
             else
+            sp += 8, dp += 6;
+
+         while (sp < ep)
             {
-               /* This converts from XXGG or AAGG to GG */
-               for (i = 0; i < row_width; i++)
-               {
-                  sp += 2;
-                  *dp++ = *sp++;
-                  *dp++ = *sp++;
-               }
+            /* Copy 6 bytes, skip 2 */
+            *dp++ = *sp++, *dp++ = *sp++;
+            *dp++ = *sp++, *dp++ = *sp++;
+            *dp++ = *sp++, *dp++ = *sp, sp += 3;
             }
 
-            row_info->pixel_depth = 16;
-            row_info->rowbytes = row_width * 2;
-         }
-         row_info->channels = 1;
+         row_info->pixel_depth = 48;
       }
 
-      if (flags & PNG_FLAG_STRIP_ALPHA)
-        row_info->color_type = (png_byte)(row_info->color_type &
-            ~PNG_COLOR_MASK_ALPHA);
+      else
+         return; /* bad bit depth */
+
+      row_info->channels = 3;
+
+      /* Finally fix the color type if it records an alpha channel */
+      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+         row_info->color_type = PNG_COLOR_TYPE_RGB;
    }
+
+   else
+      return; /* The filler channel has gone already */
+
+   /* Fix the rowbytes value. */
+   row_info->rowbytes = dp-row;
 }
 #endif
 
 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
@@ -702,13 +647,18 @@
    return ((png_voidp)png_ptr->user_transform_ptr);
 }
 #endif
 
+#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
 png_uint_32 PNGAPI
 png_get_current_row_number(png_const_structp png_ptr)
 {
+   /* See the comments in png.h - this is the sub-image row when reading and
+    * interlaced image.
+    */
    if (png_ptr != NULL)
       return png_ptr->row_number;
+
    return PNG_UINT_32_MAX; /* help the app not to fail silently */
 }
 
 png_byte PNGAPI
@@ -717,7 +667,8 @@
    if (png_ptr != NULL)
       return png_ptr->pass;
    return 8; /* invalid */
 }
+#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */
 #endif /* PNG_READ_USER_TRANSFORM_SUPPORTED ||
           PNG_WRITE_USER_TRANSFORM_SUPPORTED */
 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff -ru4NwbB libpng-1.5.1/pngvalid.c libpng-1.5.2/pngvalid.c
--- libpng-1.5.1/pngvalid.c	2011-02-02 22:58:17.839843080 -0600
+++ libpng-1.5.2/pngvalid.c	2011-03-31 11:23:40.818304211 -0500
@@ -1,8 +1,8 @@
 
 /* pngvalid.c - validate libpng by constructing then reading png files.
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * Copyright (c) 2011 Glenn Randers-Pehrson
  * Written by John Cunningham Bowler
  *
  * This code is released under the libpng license.
@@ -978,9 +978,9 @@
          pool->list = next->next;
          next->next = NULL;
 
          fprintf(stderr, "\t%lu bytes @ %p\n",
-             (unsigned long)next->size, next+1);
+             (unsigned long)next->size, (PNG_CONST void*)(next+1));
          /* The NULL means this will always return, even if the memory is
           * corrupted.
           */
          store_memory_free(NULL, pool, next);
@@ -3071,9 +3071,18 @@
       /* In the case where the reader doesn't do the interlace it gives
        * us the y in the sub-image:
        */
       if (dp->do_interlace && dp->interlace_type == PNG_INTERLACE_ADAM7)
+      {
+         /* Use this opportunity to validate the png 'current' APIs: */
+         if (y != png_get_current_row_number(pp))
+            png_error(pp, "png_get_current_row_number is broken");
+
+         if (pass != png_get_current_pass_number(pp))
+            png_error(pp, "png_get_current_pass_number is broken");
+
          y = PNG_ROW_FROM_PASS_ROW(y, pass);
+      }
 
       /* Validate this just in case. */
       if (y >= dp->h)
          png_error(pp, "invalid y to progressive row callback");
@@ -4458,8 +4467,50 @@
       bit_depth);
 }
 
 IT(expand_gray_1_2_4_to_8, expand);
+/* png_set_expand_16 */
+static void
+image_transform_png_set_expand_16_set(PNG_CONST image_transform *this,
+    transform_display *that, png_structp pp, png_infop pi)
+{
+   png_set_expand_16(pp);
+   this->next->set(this->next, that, pp, pi);
+}
+
+static void
+image_transform_png_set_expand_16_mod(PNG_CONST image_transform *this,
+    image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
+{
+   /* Expect expand_16 to expand everything to 16 bits as a result of also
+    * causing 'expand' to happen.
+    */
+   if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
+      image_pixel_convert_PLTE(that, &display->this);
+
+   if (that->have_tRNS)
+      image_pixel_add_alpha(that, &display->this);
+
+   if (that->bit_depth < 16)
+      that->sample_depth = that->bit_depth = 16;
+
+   this->next->mod(this->next, that, pp, display);
+}
+
+static int
+image_transform_png_set_expand_16_add(image_transform *this,
+    PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
+{
+   UNUSED(colour_type)
+
+   this->next = *that;
+   *that = this;
+
+   /* expand_16 does something unless the bit depth is already 16. */
+   return bit_depth < 16;
+}
+
+IT(expand_16, expand_gray_1_2_4_to_8);
 
 /* png_set_strip_16 */
 static void
 image_transform_png_set_strip_16_set(PNG_CONST image_transform *this,
@@ -4509,9 +4560,9 @@
 
    return bit_depth > 8;
 }
 
-IT(strip_16, expand_gray_1_2_4_to_8);
+IT(strip_16, expand_16);
 
 /* png_set_strip_alpha */
 static void
 image_transform_png_set_strip_alpha_set(PNG_CONST image_transform *this,
diff -ru4NwbB libpng-1.5.1/pngwrite.c libpng-1.5.2/pngwrite.c
--- libpng-1.5.1/pngwrite.c	2011-02-02 22:58:17.853713669 -0600
+++ libpng-1.5.2/pngwrite.c	2011-03-31 11:23:40.832722141 -0500
@@ -1,8 +1,8 @@
 
 /* pngwrite.c - general routines to write a PNG file
  *
- * Last changed in libpng 1.5.1 [March 31, 2011]
+ * Last changed in libpng 1.5.1 [February 3, 2011]
  * Copyright (c) 1998-2011 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.)
  *
@@ -1176,9 +1176,9 @@
  * filtered data going to zlib more consistent, hopefully resulting in
  * better compression.
  */
 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED      /* GRR 970116 */
-/* Conveneince reset API. */
+/* Convenience reset API. */
 static void
 png_reset_filter_heuristics(png_structp png_ptr)
 {
    /* Clear out any old values in the 'weights' - this must be done because if
diff -ru4NwbB libpng-1.5.1/pngwtran.c libpng-1.5.2/pngwtran.c
--- libpng-1.5.1/pngwtran.c	2011-02-02 22:58:17.859790706 -0600
+++ libpng-1.5.2/pngwtran.c	2011-03-31 11:23:40.839135854 -0500
@@ -1,8 +1,8 @@
 
 /* pngwtran.c - transforms the data in a row for PNG writers
  *
- * Last changed in libpng 1.5.0 [January 6, 2011]
+ * Last changed in libpng 1.5.2 [March 31, 2011]
  * Copyright (c) 1998-2011 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.)
  *
@@ -43,10 +43,10 @@
 #endif
 
 #ifdef PNG_WRITE_FILLER_SUPPORTED
    if (png_ptr->transformations & PNG_FILLER)
-      png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
-          png_ptr->flags);
+      png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1,
+         !(png_ptr->flags & PNG_FILLER_AFTER));
 #endif
 
 #ifdef PNG_WRITE_PACKSWAP_SUPPORTED
    if (png_ptr->transformations & PNG_PACKSWAP)
diff -ru4NwbB libpng-1.5.1/scripts/makefile.vcwin32 libpng-1.5.2/scripts/makefile.vcwin32
--- libpng-1.5.1/scripts/makefile.vcwin32	2011-02-02 22:58:20.908376594 -0600
+++ libpng-1.5.2/scripts/makefile.vcwin32	2011-03-31 11:23:42.875345646 -0500
@@ -1,7 +1,7 @@
 # makefile for libpng
 # Copyright (C) 1998 Tim Wegner
-# Copyright (C) 2006,2009 Glenn Randers-Pehrson
+# Copyright (C) 2006,2009,2011 Glenn Randers-Pehrson
 #
 # This code is released under the libpng license.
 # For conditions of distribution and use, see the disclaimer
 # and license in png.h
@@ -14,9 +14,9 @@
 # Compiler, linker, librarian, and other tools
 CC = cl
 LD = link
 AR = lib
-CFLAGS  = -nologo -MD -O2 -W3 -I..\zlib
+CFLAGS  = -nologo -D_CRT_SECURE_NO_DEPRECATE -MD -O2 -W3 -I..\zlib
 LDFLAGS = -nologo
 ARFLAGS = -nologo
 RM = del
 
@@ -35,10 +35,10 @@
 # Targets
 all: libpng.lib
 
 # see scripts/pnglibconf.mak for more options
-pnglibconf.h: scripts/pnglibconf.h.prebuilt
-	cp scripts/pnglibconf.h.prebuilt $@
+pnglibconf.h: scripts\pnglibconf.h.prebuilt
+       copy scripts\pnglibconf.h.prebuilt $@
 
 png$(O): %HEADERS%
 	$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
 
diff -ru4NwbB libpng-1.5.1/scripts/pnglibconf.dfa libpng-1.5.2/scripts/pnglibconf.dfa
--- libpng-1.5.1/scripts/pnglibconf.dfa	2011-01-22 18:03:50.437008000 -0600
+++ libpng-1.5.2/scripts/pnglibconf.dfa	2011-02-12 09:16:01.541296000 -0600
@@ -303,8 +303,9 @@
 option READ_TRANSFORMS requires READ
 = NO_READ_TRANSFORMS READ_TRANSFORMS_NOT_SUPPORTED
 
 option READ_EXPAND requires READ_TRANSFORMS
+option READ_EXPAND_16 requires READ_TRANSFORMS READ_16BIT enables READ_EXPAND
 option READ_SHIFT requires READ_TRANSFORMS
 option READ_PACK requires READ_TRANSFORMS
 option READ_BGR requires READ_TRANSFORMS
 option READ_SWAP requires READ_TRANSFORMS READ_16BIT
diff -ru4NwbB libpng-1.5.1/scripts/pnglibconf.h.prebuilt libpng-1.5.2/scripts/pnglibconf.h.prebuilt
--- libpng-1.5.1/scripts/pnglibconf.h.prebuilt	2011-01-22 18:03:50.445714000 -0600
+++ libpng-1.5.2/scripts/pnglibconf.h.prebuilt	2011-02-12 09:20:50.414618000 -0600
@@ -2,175 +2,180 @@
 /* libpng STANDARD API DEFINITION */
 
 /* pnglibconf.h - library build configuration */
 
-/* libpng version 1.5.0 - last changed on January 6, 2011 */
+/* libpng version 1.5.0 - last changed on February 11, 2011 */
 
 /* Copyright (c) 1998-2011 Glenn Randers-Pehrson */
 
 /* This code is released under the libpng license. */
 /* For conditions of distribution and use, see the disclaimer */
 /* and license in png.h */
 
 /* pnglibconf.h */
-/* Machine generated file: DO NOT EDIT */
 /* Derived from: scripts/pnglibconf.dfa */
+/* If you edit this file by hand you must obey the rules expressed in */
+/* pnglibconf.dfa with respect to the dependencies between the following */
+/* symbols.  It is much better to generate a new file using */
+/* scripts/libpngconf.mak */
+  
 #ifndef PNGLCONF_H
 #define PNGLCONF_H
 /* settings */
-#define PNG_MAX_GAMMA_8 11
-#define PNG_CALLOC_SUPPORTED
-#define PNG_QUANTIZE_RED_BITS 5
-#define PNG_USER_WIDTH_MAX 1000000L
-#define PNG_QUANTIZE_GREEN_BITS 5
 #define PNG_API_RULE 0
+#define PNG_CALLOC_SUPPORTED
+#define PNG_COST_SHIFT 3
+#define PNG_DEFAULT_READ_MACROS 1
+#define PNG_GAMMA_THRESHOLD_FIXED 5000
+#define PNG_MAX_GAMMA_8 11
 #define PNG_QUANTIZE_BLUE_BITS 5
+#define PNG_QUANTIZE_GREEN_BITS 5
+#define PNG_QUANTIZE_RED_BITS 5
+#define PNG_sCAL_PRECISION 5
 #define PNG_USER_CHUNK_CACHE_MAX 0
+#define PNG_USER_CHUNK_MALLOC_MAX 0
 #define PNG_USER_HEIGHT_MAX 1000000L
-#define PNG_sCAL_PRECISION 5
-#define PNG_COST_SHIFT 3
+#define PNG_USER_WIDTH_MAX 1000000L
 #define PNG_WEIGHT_SHIFT 8
-#define PNG_USER_CHUNK_MALLOC_MAX 0
-#define PNG_DEFAULT_READ_MACROS 1
 #define PNG_ZBUF_SIZE 8192
-#define PNG_GAMMA_THRESHOLD_FIXED 5000
 /* end of settings */
 /* options */
-#define PNG_INFO_IMAGE_SUPPORTED
-#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
-#define PNG_POINTER_INDEXING_SUPPORTED
-#define PNG_WARNINGS_SUPPORTED
-#define PNG_FLOATING_ARITHMETIC_SUPPORTED
-#define PNG_WRITE_SUPPORTED
-#define PNG_WRITE_INTERLACING_SUPPORTED
-#define PNG_WRITE_16BIT_SUPPORTED
-#define PNG_EASY_ACCESS_SUPPORTED
+#define PNG_16BIT_SUPPORTED
 #define PNG_ALIGN_MEMORY_SUPPORTED
-#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
-#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
-#define PNG_USER_LIMITS_SUPPORTED
-#define PNG_FIXED_POINT_SUPPORTED
-/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
-#define PNG_ERROR_TEXT_SUPPORTED
-#define PNG_READ_SUPPORTED
-/*#undef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED*/
 #define PNG_BENIGN_ERRORS_SUPPORTED
-#define PNG_SETJMP_SUPPORTED
-#define PNG_WRITE_FLUSH_SUPPORTED
-#define PNG_MNG_FEATURES_SUPPORTED
+#define PNG_bKGD_SUPPORTED
+#define PNG_CHECK_cHRM_SUPPORTED
+#define PNG_cHRM_SUPPORTED
+#define PNG_CONSOLE_IO_SUPPORTED
+#define PNG_CONVERT_tIME_SUPPORTED
+#define PNG_EASY_ACCESS_SUPPORTED
+#define PNG_ERROR_TEXT_SUPPORTED
+#define PNG_FIXED_POINT_SUPPORTED
+#define PNG_FLOATING_ARITHMETIC_SUPPORTED
 #define PNG_FLOATING_POINT_SUPPORTED
+#define PNG_gAMA_SUPPORTED
+#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
+#define PNG_hIST_SUPPORTED
+#define PNG_iCCP_SUPPORTED
 #define PNG_INCH_CONVERSIONS_SUPPORTED
-#define PNG_STDIO_SUPPORTED
-#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
-#define PNG_USER_MEM_SUPPORTED
+#define PNG_INFO_IMAGE_SUPPORTED
 #define PNG_IO_STATE_SUPPORTED
-#define PNG_SET_USER_LIMITS_SUPPORTED
+#define PNG_iTXt_SUPPORTED
+#define PNG_MNG_FEATURES_SUPPORTED
+#define PNG_oFFs_SUPPORTED
+#define PNG_pCAL_SUPPORTED
+#define PNG_pHYs_SUPPORTED
+#define PNG_POINTER_INDEXING_SUPPORTED
+#define PNG_PROGRESSIVE_READ_SUPPORTED
+#define PNG_READ_16BIT_SUPPORTED
+#define PNG_READ_16_TO_8_SUPPORTED
 #define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
-#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
-#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
-#define PNG_WRITE_FILTER_SUPPORTED
-#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
-#define PNG_WRITE_iCCP_SUPPORTED
-#define PNG_READ_TRANSFORMS_SUPPORTED
-#define PNG_READ_GAMMA_SUPPORTED
+#define PNG_READ_BACKGROUND_SUPPORTED
+#define PNG_READ_BGR_SUPPORTED
 #define PNG_READ_bKGD_SUPPORTED
-#define PNG_UNKNOWN_CHUNKS_SUPPORTED
-#define PNG_READ_sCAL_SUPPORTED
-#define PNG_WRITE_hIST_SUPPORTED
-#define PNG_READ_OPT_PLTE_SUPPORTED
-#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
-#define PNG_WRITE_gAMA_SUPPORTED
+#define PNG_READ_cHRM_SUPPORTED
+#define PNG_READ_COMPOSITE_NODIV_SUPPORTED
+#define PNG_READ_EXPAND_16_SUPPORTED
+#define PNG_READ_EXPAND_SUPPORTED
+#define PNG_READ_FILLER_SUPPORTED
+#define PNG_READ_gAMA_SUPPORTED
+#define PNG_READ_GAMMA_SUPPORTED
 #define PNG_READ_GRAY_TO_RGB_SUPPORTED
-#define PNG_WRITE_pCAL_SUPPORTED
+#define PNG_READ_hIST_SUPPORTED
+#define PNG_READ_iCCP_SUPPORTED
+#define PNG_READ_INTERLACING_SUPPORTED
+#define PNG_READ_INT_FUNCTIONS_SUPPORTED
 #define PNG_READ_INVERT_ALPHA_SUPPORTED
-#define PNG_WRITE_TRANSFORMS_SUPPORTED
-#define PNG_READ_sBIT_SUPPORTED
+#define PNG_READ_INVERT_SUPPORTED
+#define PNG_READ_iTXt_SUPPORTED
+#define PNG_READ_oFFs_SUPPORTED
+#define PNG_READ_OPT_PLTE_SUPPORTED
 #define PNG_READ_PACK_SUPPORTED
-#define PNG_WRITE_SWAP_SUPPORTED
-#define PNG_READ_cHRM_SUPPORTED
-#define PNG_WRITE_tIME_SUPPORTED
-#define PNG_READ_INTERLACING_SUPPORTED
-#define PNG_READ_tRNS_SUPPORTED
-#define PNG_WRITE_pHYs_SUPPORTED
-#define PNG_WRITE_INVERT_SUPPORTED
+#define PNG_READ_PACKSWAP_SUPPORTED
+#define PNG_READ_pCAL_SUPPORTED
+#define PNG_READ_pHYs_SUPPORTED
+#define PNG_READ_QUANTIZE_SUPPORTED
 #define PNG_READ_RGB_TO_GRAY_SUPPORTED
-#define PNG_WRITE_sRGB_SUPPORTED
-#define PNG_READ_oFFs_SUPPORTED
-#define PNG_WRITE_FILLER_SUPPORTED
-#define PNG_WRITE_TEXT_SUPPORTED
-#define PNG_WRITE_SHIFT_SUPPORTED
-#define PNG_PROGRESSIVE_READ_SUPPORTED
+#define PNG_READ_sBIT_SUPPORTED
+#define PNG_READ_sCAL_SUPPORTED
 #define PNG_READ_SHIFT_SUPPORTED
-#define PNG_CONVERT_tIME_SUPPORTED
-#define PNG_READ_USER_TRANSFORM_SUPPORTED
-#define PNG_READ_INT_FUNCTIONS_SUPPORTED
-#define PNG_READ_USER_CHUNKS_SUPPORTED
-#define PNG_READ_hIST_SUPPORTED
-#define PNG_READ_16BIT_SUPPORTED
-#define PNG_READ_SWAP_ALPHA_SUPPORTED
-#define PNG_READ_COMPOSITE_NODIV_SUPPORTED
-#define PNG_SEQUENTIAL_READ_SUPPORTED
-#define PNG_READ_BACKGROUND_SUPPORTED
-#define PNG_READ_QUANTIZE_SUPPORTED
-#define PNG_READ_iCCP_SUPPORTED
-#define PNG_READ_STRIP_ALPHA_SUPPORTED
-#define PNG_READ_PACKSWAP_SUPPORTED
+#define PNG_READ_sPLT_SUPPORTED
 #define PNG_READ_sRGB_SUPPORTED
-#define PNG_WRITE_tEXt_SUPPORTED
-#define PNG_READ_gAMA_SUPPORTED
-#define PNG_READ_pCAL_SUPPORTED
-#define PNG_READ_EXPAND_SUPPORTED
-#define PNG_WRITE_sPLT_SUPPORTED
+#define PNG_READ_STRIP_ALPHA_SUPPORTED
+#define PNG_READ_SUPPORTED
+#define PNG_READ_SWAP_ALPHA_SUPPORTED
 #define PNG_READ_SWAP_SUPPORTED
+#define PNG_READ_tEXt_SUPPORTED
+#define PNG_READ_TEXT_SUPPORTED
 #define PNG_READ_tIME_SUPPORTED
-#define PNG_READ_pHYs_SUPPORTED
-#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
+#define PNG_READ_TRANSFORMS_SUPPORTED
+#define PNG_READ_tRNS_SUPPORTED
+#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
+#define PNG_READ_USER_CHUNKS_SUPPORTED
+#define PNG_READ_USER_TRANSFORM_SUPPORTED
+#define PNG_READ_zTXt_SUPPORTED
+#define PNG_SAVE_INT_32_SUPPORTED
+#define PNG_sBIT_SUPPORTED
+#define PNG_sCAL_SUPPORTED
+#define PNG_SEQUENTIAL_READ_SUPPORTED
+#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
+#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
+#define PNG_SETJMP_SUPPORTED
+#define PNG_SET_USER_LIMITS_SUPPORTED
+#define PNG_sPLT_SUPPORTED
+#define PNG_sRGB_SUPPORTED
+#define PNG_STDIO_SUPPORTED
+#define PNG_tEXt_SUPPORTED
+#define PNG_TEXT_SUPPORTED
 #define PNG_TIME_RFC1123_SUPPORTED
-#define PNG_READ_TEXT_SUPPORTED
-#define PNG_WRITE_BGR_SUPPORTED
+#define PNG_tIME_SUPPORTED
+#define PNG_tRNS_SUPPORTED
+#define PNG_UNKNOWN_CHUNKS_SUPPORTED
 #define PNG_USER_CHUNKS_SUPPORTED
-#define PNG_CONSOLE_IO_SUPPORTED
-#define PNG_WRITE_PACK_SUPPORTED
-#define PNG_READ_FILLER_SUPPORTED
+#define PNG_USER_LIMITS_SUPPORTED
+#define PNG_USER_MEM_SUPPORTED
+#define PNG_USER_TRANSFORM_INFO_SUPPORTED
+#define PNG_USER_TRANSFORM_PTR_SUPPORTED
+#define PNG_WARNINGS_SUPPORTED
+#define PNG_WRITE_16BIT_SUPPORTED
+#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
+#define PNG_WRITE_BGR_SUPPORTED
 #define PNG_WRITE_bKGD_SUPPORTED
-#define PNG_WRITE_tRNS_SUPPORTED
-#define PNG_READ_sPLT_SUPPORTED
-#define PNG_WRITE_sCAL_SUPPORTED
+#define PNG_WRITE_cHRM_SUPPORTED
+#define PNG_WRITE_FILLER_SUPPORTED
+#define PNG_WRITE_FILTER_SUPPORTED
+#define PNG_WRITE_FLUSH_SUPPORTED
+#define PNG_WRITE_gAMA_SUPPORTED
+#define PNG_WRITE_hIST_SUPPORTED
+#define PNG_WRITE_iCCP_SUPPORTED
+#define PNG_WRITE_INTERLACING_SUPPORTED
+#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
+#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
+#define PNG_WRITE_INVERT_SUPPORTED
+#define PNG_WRITE_iTXt_SUPPORTED
 #define PNG_WRITE_oFFs_SUPPORTED
-#define PNG_READ_tEXt_SUPPORTED
+#define PNG_WRITE_PACK_SUPPORTED
+#define PNG_WRITE_PACKSWAP_SUPPORTED
+#define PNG_WRITE_pCAL_SUPPORTED
+#define PNG_WRITE_pHYs_SUPPORTED
 #define PNG_WRITE_sBIT_SUPPORTED
-#define PNG_READ_INVERT_SUPPORTED
-#define PNG_READ_16_TO_8_SUPPORTED
-#define PNG_WRITE_cHRM_SUPPORTED
-#define PNG_16BIT_SUPPORTED
+#define PNG_WRITE_sCAL_SUPPORTED
+#define PNG_WRITE_SHIFT_SUPPORTED
+#define PNG_WRITE_sPLT_SUPPORTED
+#define PNG_WRITE_sRGB_SUPPORTED
+#define PNG_WRITE_SUPPORTED
+#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
+#define PNG_WRITE_SWAP_SUPPORTED
+#define PNG_WRITE_tEXt_SUPPORTED
+#define PNG_WRITE_TEXT_SUPPORTED
+#define PNG_WRITE_tIME_SUPPORTED
+#define PNG_WRITE_TRANSFORMS_SUPPORTED
+#define PNG_WRITE_tRNS_SUPPORTED
+#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
 #define PNG_WRITE_USER_TRANSFORM_SUPPORTED
-#define PNG_READ_BGR_SUPPORTED
-#define PNG_WRITE_PACKSWAP_SUPPORTED
-#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
-#define PNG_sCAL_SUPPORTED
+#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
 #define PNG_WRITE_zTXt_SUPPORTED
-#define PNG_sBIT_SUPPORTED
-#define PNG_cHRM_SUPPORTED
-#define PNG_bKGD_SUPPORTED
-#define PNG_tRNS_SUPPORTED
-#define PNG_WRITE_iTXt_SUPPORTED
-#define PNG_oFFs_SUPPORTED
-#define PNG_USER_TRANSFORM_PTR_SUPPORTED
-#define PNG_USER_TRANSFORM_INFO_SUPPORTED
-#define PNG_hIST_SUPPORTED
-#define PNG_iCCP_SUPPORTED
-#define PNG_sRGB_SUPPORTED
-#define PNG_READ_zTXt_SUPPORTED
-#define PNG_gAMA_SUPPORTED
-#define PNG_pCAL_SUPPORTED
-#define PNG_CHECK_cHRM_SUPPORTED
-#define PNG_tIME_SUPPORTED
-#define PNG_pHYs_SUPPORTED
-#define PNG_READ_iTXt_SUPPORTED
-#define PNG_TEXT_SUPPORTED
-#define PNG_SAVE_INT_32_SUPPORTED
-#define PNG_sPLT_SUPPORTED
-#define PNG_tEXt_SUPPORTED
 #define PNG_zTXt_SUPPORTED
-#define PNG_iTXt_SUPPORTED
+/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
+/*#undef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED*/
 /* end of options */
 #endif /* PNGLCONF_H */
diff -ru4NwbB libpng-1.5.1/scripts/pnglibconf.mak libpng-1.5.2/scripts/pnglibconf.mak
--- libpng-1.5.1/scripts/pnglibconf.mak	2010-08-24 15:58:27.146948000 -0500
+++ libpng-1.5.2/scripts/pnglibconf.mak	2011-03-19 14:02:07.910649000 -0500
@@ -11,10 +11,11 @@
 AWK = mawk
 AWK = nawk
 AWK = one-true-awk
 AWK = awk  # Crashes on SunOS 5.10 - use 'nawk'
+CPP = $(CC) -E # Does not work on SUN OS 5.10 - use /lib/cpp
 SED = sed
-CPP = $(CC) -E
+
 COPY = cp
 DELETE = rm -f
 ECHO = echo
 DFA_XTRA = # Appended to scripts/options.awk
@@ -32,8 +33,9 @@
 pnglibconf.h: pnglibconf.dfn
 	$(DELETE) $@ dfn.c dfn1.out dfn2.out dfn3.out
 	$(ECHO) '#include "pnglibconf.dfn"' >dfn.c
 	$(CPP) $(DFNFLAGS) dfn.c >dfn1.out
+	$(ECHO) "If 'cpp -e' crashes try /lib/cpp (e.g. CPP='/lib/cpp')" >&2
 	$(SED) -n -e 's|^.*PNG_DEFN_MAGIC-\(.*\)-PNG_DEFN_END.*$$|\1|p'\
 	    dfn1.out >dfn2.out
 	$(SED) -e 's| *@@@ *||g' -e 's| *$$||' dfn2.out >dfn3.out
 	$(COPY) dfn3.out $@
diff -ru4NwbB libpng-1.5.1/scripts/symbols.def libpng-1.5.2/scripts/symbols.def
--- libpng-1.5.1/scripts/symbols.def	2011-02-02 22:58:20.937934664 -0600
+++ libpng-1.5.2/scripts/symbols.def	2011-03-31 11:23:42.905754321 -0500
@@ -225,4 +225,5 @@
  png_get_current_row_number @217
  png_get_current_pass_number @218
  png_process_data_pause @219
  png_process_data_skip @220
+ png_set_expand_16 @221