[libpng15] Remove simplified interface
diff --git a/ANNOUNCE b/ANNOUNCE
index 95a7b1a..0499f2f 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.5.7beta05 - November 22, 2011
+Libpng 1.5.7beta05 - November 23, 2011
 
 This is not intended to be a public release.  It will be replaced
 within a few weeks by a public version or by another test version.
@@ -99,13 +99,17 @@
     Also removed a duplicate setting of this flag.
   Added files that were omitted from the libpng-1.5.7beta03 zip distribution.
 
-Version 1.5.7beta05 [November 22, 2011]
+Version 1.5.7beta05 [November 23, 2011]
   Removed "zTXt" from warning in generic chunk decompression function.
   Validate time settings passed to pngset() and png_convert_to_rfc1123()
     (Frank Busse).
-  Allow row_stride==0 to indicate default stride in simplified API.
   Added MINGW support to CMakeLists.txt
   Reject invalid compression flag or method when reading the iTXt chunk.
+  Backed out 'simplified' API changes. The API seems too complex and there
+    is a lack of consensus or enthusiasm for the proposals.  The API also
+    reveals significant bugs inside libpng (double gamma correction and the
+    known bug of being unable to retrieve a corrected palette.) It seems
+    better to wait until the bugs, at least, are corrected.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net:
 (subscription required; visit
diff --git a/CHANGES b/CHANGES
index 8242dbe..e7cd6c0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3744,13 +3744,17 @@
     Also removed a duplicate setting of this flag.
   Added files that were omitted from the libpng-1.5.7beta03 zip distribution.
 
-Version 1.5.7beta05 [November 22, 2011]
+Version 1.5.7beta05 [November 23, 2011]
   Removed "zTXt" from warning in generic chunk decompression function.
   Validate time settings passed to pngset() and png_convert_to_rfc1123()
     (Frank Busse).
-  Allow row_stride==0 to indicate default stride in simplified API.
   Added MINGW support to CMakeLists.txt
   Reject invalid compression flag or method when reading the iTXt chunk.
+  Backed out 'simplified' API changes. The API seems too complex and there
+    is a lack of consensus or enthusiasm for the proposals.  The API also
+    reveals significant bugs inside libpng (double gamma correction and the
+    known bug of being unable to retrieve a corrected palette.) It seems
+    better to wait until the bugs, at least, are corrected.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/LICENSE b/LICENSE
index ba3b0fb..3b180b4 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.5.7beta05, November 18, 2011, are
+libpng versions 1.2.6, August 15, 2004, through 1.5.7beta05, November 23, 2011, are
 Copyright (c) 2004, 2006-2011 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
-November 18, 2011
+November 23, 2011
diff --git a/Makefile.am b/Makefile.am
index 2b66ff0..41b3f34 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,13 +18,12 @@
 pngtest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
 TESTS = test-pngtest.sh
 
-# Do the following only if the contrib directory is present.
-check_PROGRAMS+= pngvalid pngstest
+# Only do the following if the contrib directory is present.
+check_PROGRAMS+= pngvalid
 pngvalid_SOURCES = pngvalid.c
-pngstest_SOURCES = contrib/libtests/pngstest.c
 pngvalid_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
 pngstest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
-TESTS += test-pngvalid-simple.sh test-pngvalid-full.sh test-pngstest.sh
+TESTS += test-pngvalid-simple.sh test-pngvalid-full.sh
 
 # man pages
 dist_man_MANS= libpng.3 libpngpf.3 png.5
@@ -132,7 +131,7 @@
 # The following is necessary to ensure that the local pnglibconf.h is used, not
 # an installed one (this can happen immediately after on a clean system if
 # 'make test' is the first thing the user does.)
-contrib/libtests/pngstest.o pngvalid.o pngtest.o: pnglibconf.h
+pngvalid.o pngtest.o: pnglibconf.h
 
 # We must use -DPNG_NO_USE_READ_MACROS here even when the library may actually
 # be built with PNG_USE_READ_MACROS; this prevents the read macros from
diff --git a/Makefile.in b/Makefile.in
index e3f7010..d0ccefe 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -40,7 +40,7 @@
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-check_PROGRAMS = pngtest$(EXEEXT) pngvalid$(EXEEXT) pngstest$(EXEEXT)
+check_PROGRAMS = pngtest$(EXEEXT) pngvalid$(EXEEXT)
 @PNG_ARM_NEON_TRUE@am__append_1 = arm/filter_neon.S
 
 #   Versioned symbols and restricted exports
@@ -124,9 +124,6 @@
 	$(AM_CFLAGS) $(CFLAGS) \
 	$(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS) $(LDFLAGS) -o \
 	$@
-am_pngstest_OBJECTS = pngstest.$(OBJEXT)
-pngstest_OBJECTS = $(am_pngstest_OBJECTS)
-pngstest_DEPENDENCIES = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
 am_pngtest_OBJECTS = pngtest.$(OBJEXT)
 pngtest_OBJECTS = $(am_pngtest_OBJECTS)
 pngtest_DEPENDENCIES = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
@@ -154,10 +151,10 @@
 	$(LDFLAGS) -o $@
 SOURCES = $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES) \
 	$(nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES) \
-	$(pngstest_SOURCES) $(pngtest_SOURCES) $(pngvalid_SOURCES)
+	$(pngtest_SOURCES) $(pngvalid_SOURCES)
 DIST_SOURCES =  \
 	$(am__libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES_DIST) \
-	$(pngstest_SOURCES) $(pngtest_SOURCES) $(pngvalid_SOURCES)
+	$(pngtest_SOURCES) $(pngvalid_SOURCES)
 man3dir = $(mandir)/man3
 man5dir = $(mandir)/man5
 NROFF = nroff
@@ -184,6 +181,7 @@
 pkgincludedir = $(includedir)/$(PNGLIB_BASENAME)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
+AM_CCASFLAGS = @AM_CCASFLAGS@
 AR = @AR@
 AS = @AS@
 AUTOCONF = @AUTOCONF@
@@ -329,16 +327,14 @@
 # to get red "FAIL" and green "PASS" notations during tests.
 # AUTOMAKE_OPTIONS = foreign color-tests
 AUTOMAKE_OPTIONS = foreign
+
+# test programs - run on make check, make distcheck
+TESTS_ENVIRONMENT = srcdir=$(srcdir)
 pngtest_SOURCES = pngtest.c
 pngtest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
+TESTS = test-pngtest.sh test-pngvalid-simple.sh test-pngvalid-full.sh
 pngvalid_SOURCES = pngvalid.c
 pngvalid_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
-pngstest_SOURCES = contrib/libtests/pngstest.c
-pngstest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
-TESTS = test-pngtest.sh test-pngvalid-simple.sh test-pngvalid-full.sh \
-	test-pngstest.sh
-
-TESTS_ENVIRONMENT = srcdir=$(srcdir)
 
 # man pages
 dist_man_MANS = libpng.3 libpngpf.3 png.5
@@ -494,9 +490,6 @@
 	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
 	echo " rm -f" $$list; \
 	rm -f $$list
-pngstest$(EXEEXT): $(pngstest_OBJECTS) $(pngstest_DEPENDENCIES) 
-	@rm -f pngstest$(EXEEXT)
-	$(LINK) $(pngstest_OBJECTS) $(pngstest_LDADD) $(LIBS)
 pngtest$(EXEEXT): $(pngtest_OBJECTS) $(pngtest_DEPENDENCIES) 
 	@rm -f pngtest$(EXEEXT)
 	$(LINK) $(pngtest_OBJECTS) $(pngtest_LDADD) $(LIBS)
@@ -560,7 +553,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la-pngwrite.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la-pngwtran.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la-pngwutil.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pngstest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pngtest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pngvalid.Po@am__quote@
 
@@ -718,20 +710,6 @@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la-pngwutil.lo `test -f 'pngwutil.c' || echo '$(srcdir)/'`pngwutil.c
 
-pngstest.o: contrib/libtests/pngstest.c
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT pngstest.o -MD -MP -MF $(DEPDIR)/pngstest.Tpo -c -o pngstest.o `test -f 'contrib/libtests/pngstest.c' || echo '$(srcdir)/'`contrib/libtests/pngstest.c
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/pngstest.Tpo $(DEPDIR)/pngstest.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='contrib/libtests/pngstest.c' object='pngstest.o' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o pngstest.o `test -f 'contrib/libtests/pngstest.c' || echo '$(srcdir)/'`contrib/libtests/pngstest.c
-
-pngstest.obj: contrib/libtests/pngstest.c
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT pngstest.obj -MD -MP -MF $(DEPDIR)/pngstest.Tpo -c -o pngstest.obj `if test -f 'contrib/libtests/pngstest.c'; then $(CYGPATH_W) 'contrib/libtests/pngstest.c'; else $(CYGPATH_W) '$(srcdir)/contrib/libtests/pngstest.c'; fi`
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/pngstest.Tpo $(DEPDIR)/pngstest.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='contrib/libtests/pngstest.c' object='pngstest.obj' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o pngstest.obj `if test -f 'contrib/libtests/pngstest.c'; then $(CYGPATH_W) 'contrib/libtests/pngstest.c'; else $(CYGPATH_W) '$(srcdir)/contrib/libtests/pngstest.c'; fi`
-
 mostlyclean-libtool:
 	-rm -f *.lo
 
@@ -1357,7 +1335,7 @@
 # The following is necessary to ensure that the local pnglibconf.h is used, not
 # an installed one (this can happen immediately after on a clean system if
 # 'make test' is the first thing the user does.)
-contrib/libtests/pngstest.o pngvalid.o pngtest.o: pnglibconf.h
+pngvalid.o pngtest.o: pnglibconf.h
 
 .dfn.out:
 	rm -f $@ dfn.c dfn?.out
diff --git a/README b/README
index dd8c49d..6407ad4 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.5.7beta05 - November 18, 2011 (shared library 15.0)
+README for libpng version 1.5.7beta05 - November 23, 2011 (shared library 15.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/libtests/pngstest.c b/contrib/libtests/pngstest.c
deleted file mode 100644
index 5c8a34b..0000000
--- a/contrib/libtests/pngstest.c
+++ /dev/null
@@ -1,1685 +0,0 @@
-/*-
- * pngstest.c
- *
- * Copyright (c) 2011 John Cunningham Bowler
- *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
- *
- * This code is released under the libpng license.
- * For conditions of distribution and use, see the disclaimer
- * and license in png.h
- *
- * Test for the PNG 'simplified' APIs.
- */
-#define _ISOC90_SOURCE 1
-#define MALLOC_CHECK_ 2/*glibc facility: turn on debugging*/
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <ctype.h>
-#include <math.h>
-
-#include "../../png.h"
-
-#include "../sRGBtables/sRGB.h"
-
-/* The following is to support direct compilation of this file as C++ */
-#ifdef __cplusplus
-#  define voidcast(type, value) static_cast<type>(value)
-#else
-#  define voidcast(type, value) (value)
-#endif /* __cplusplus */
-
-/* Math support - neither Cygwin nor Visual Studio have C99 support and we need
- * a predictable rounding function, so make one here:
- */
-static double
-closestinteger(double x)
-{
-   return floor(x + .5);
-}
-
-/* Cast support: remove GCC whines. */
-static png_byte
-u8d(double d)
-{
-   d = closestinteger(d);
-   return (png_byte)d;
-}
-
-static png_uint_16
-u16d(double d)
-{
-   d = closestinteger(d);
-   return (png_uint_16)d;
-}
-
-/* sRGB support: use exact calculations rounded to the nearest int, see the
- * fesetround() call in main().
- */
-static png_byte
-sRGB(double linear /*range 0.0 .. 1.0*/)
-{
-   return u8d(255 * sRGB_from_linear(linear));
-}
-
-static png_byte
-isRGB(int fixed_linear)
-{
-   return sRGB(fixed_linear / 65535.);
-}
-
-static png_uint_16
-ilineara(int fixed_srgb, int alpha)
-{
-   return u16d((257 * alpha) * linear_from_sRGB(fixed_srgb / 255.));
-}
-
-static double
-YfromRGBint(int ir, int ig, int ib)
-{
-   double r = ir;
-   double g = ig;
-   double b = ib;
-   return YfromRGB(r, g, b);
-}
-
-#define READ_FILE 1      /* else memory */
-#define USE_STDIO 2      /* else use file name */
-#define USE_BACKGROUND 4 /* else composite in place */
-#define VERBOSE 8
-#define KEEP_TMPFILES 16 /* else delete temporary files */
-#define KEEP_GOING 32
-
-static void
-print_opts(png_uint_32 opts)
-{
-   if (opts & READ_FILE)
-      printf(" --file");
-   if (opts & USE_STDIO)
-      printf(" --stdio");
-   if (opts & USE_BACKGROUND)
-      printf(" --background");
-   if (opts & VERBOSE)
-      printf(" --verbose");
-   if (opts & KEEP_TMPFILES)
-      printf(" --preserve");
-   if (opts & KEEP_GOING)
-      printf(" --keep-going");
-}
-
-#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */
-
-/* A name table for all the formats - defines the format of the '+' arguments to
- * pngstest.
- */
-static PNG_CONST char * PNG_CONST format_names[32] =
-{
-   "sRGB-gray",
-   "sRGB-gray+alpha",
-   "sRGB-rgb",
-   "sRGB-rgb+alpha",
-   "linear-gray",
-   "linear-gray+alpha",
-   "linear-rgb",
-   "linear-rgb+alpha",
-   "sRGB-gray",
-   "sRGB-gray+alpha",
-   "sRGB-bgr",
-   "sRGB-bgr+alpha",
-   "linear-gray",
-   "linear-gray+alpha",
-   "linear-bgr",
-   "linear-bgr+alpha",
-   "sRGB-gray",
-   "alpha+sRGB-gray",
-   "sRGB-rgb",
-   "alpha+sRGB-rgb",
-   "linear-gray",
-   "alpha+linear-gray",
-   "linear-rgb",
-   "alpha+linear-rgb",
-   "sRGB-gray",
-   "alpha+sRGB-gray",
-   "sRGB-bgr",
-   "alpha+sRGB-bgr",
-   "linear-gray",
-   "alpha+linear-gray",
-   "linear-bgr",
-   "alpha+linear-bgr",
-};
-
-/* Decode an argument to a format number. */
-static png_uint_32
-formatof(const char *arg)
-{
-   char *ep;
-   unsigned long format = strtoul(arg, &ep, 0);
-
-   if (ep > arg && *ep == 0 && format < 32)
-      return (png_uint_32)format;
-
-   else for (format=0; format < 32; ++format)
-   {
-      if (strcmp(format_names[format], arg) == 0)
-         return (png_uint_32)format;
-   }
-
-   fprintf(stderr, "pngstest: format name '%s' invalid\n", arg);
-   return 32;
-}
-
-/* THE Image STRUCTURE */
-/* The super-class of a png_image, contains the decoded image plus the input
- * data necessary to re-read the file with a different format.
- */
-typedef struct
-{
-   png_image   image;
-   png_uint_32 opts;
-   const char *file_name;
-   int         stride_extra;
-   FILE       *input_file;
-   png_voidp   input_memory;
-   png_size_t  input_memory_size;
-   png_bytep   buffer;
-   ptrdiff_t   stride;
-   png_size_t  bufsize;
-   png_size_t  allocsize;
-   png_color   background;
-   char        tmpfile_name[32];
-}
-Image;
-
-/* Initializer: also sets the permitted error limit for 16-bit operations. */
-static void
-newimage(Image *image)
-{
-   memset(image, 0, sizeof *image);
-}
-
-/* Reset the image to be read again - only needs to rewind the FILE* at present.
- */
-static void
-resetimage(Image *image)
-{
-   if (image->input_file != NULL)
-      rewind(image->input_file);
-}
-
-/* Free the image buffer; the buffer is re-used on a re-read, this is just for
- * cleanup.
- */
-static void
-freebuffer(Image *image)
-{
-   if (image->buffer) free(image->buffer);
-   image->buffer = NULL;
-   image->bufsize = 0;
-   image->allocsize = 0;
-}
-
-/* Delete function; cleans out all the allocated data and the temporary file in
- * the image.
- */
-static void
-freeimage(Image *image)
-{
-   freebuffer(image);
-   png_image_free(&image->image);
-
-   if (image->input_file != NULL)
-   {
-      fclose(image->input_file);
-      image->input_file = NULL;
-   }
-
-   if (image->input_memory != NULL)
-   {
-      free(image->input_memory);
-      image->input_memory = NULL;
-      image->input_memory_size = 0;
-   }
-
-   if (image->tmpfile_name[0] != 0 && (image->opts & KEEP_TMPFILES) == 0)
-   {
-      remove(image->tmpfile_name);
-      image->tmpfile_name[0] = 0;
-   }
-}
-
-/* This is actually a re-initializer; allows an image structure to be re-used by
- * freeing everything that relates to an old image.
- */
-static void initimage(Image *image, png_uint_32 opts, const char *file_name,
-   int stride_extra)
-{
-   freeimage(image);
-   memset(&image->image, 0, sizeof image->image);
-   image->opts = opts;
-   image->file_name = file_name;
-   image->stride_extra = stride_extra;
-}
-
-/* Make sure the image buffer is big enough; allows re-use of the buffer if the
- * image is re-read.
- */
-#define BUFFER_INIT8 73
-static void
-allocbuffer(Image *image)
-{
-   png_size_t size = PNG_IMAGE_BUFFER_SIZE(image->image, image->stride);
-
-   if (size+32 > image->bufsize)
-   {
-      freebuffer(image);
-      image->buffer = voidcast(png_bytep, malloc(size+32));
-      if (image->buffer == NULL)
-      {
-         fprintf(stderr,
-            "simpletest: out of memory allocating %lu(+32) byte buffer\n",
-            (unsigned long)size);
-         exit(1);
-      }
-      image->bufsize = size+32;
-   }
-
-   memset(image->buffer, 95, image->bufsize);
-   memset(image->buffer+16, BUFFER_INIT8, size);
-   image->allocsize = size;
-}
-
-/* Make sure 16 bytes match the given byte. */
-static int
-check16(png_const_bytep bp, int b)
-{
-   int i = 16;
-
-   do
-      if (*bp != b) return 1;
-   while (--i);
-
-   return 0;
-}
-
-/* Check for overwrite in the image buffer. */
-static void
-checkbuffer(Image *image, const char *arg)
-{
-   if (check16(image->buffer, 95))
-   {
-      fprintf(stderr, "%s: overwrite at start of image buffer\n", arg);
-      exit(1);
-   }
-
-   if (check16(image->buffer+16+image->allocsize, 95))
-   {
-      fprintf(stderr, "%s: overwrite at end of image buffer\n", arg);
-      exit(1);
-   }
-}
-
-/* ERROR HANDLING */
-/* Log a terminal error, also frees the libpng part of the image if necessary.
- */
-static int
-logerror(Image *image, const char *a1, const char *a2, const char *a3)
-{
-   if (image->image.warning_or_error)
-      fprintf(stderr, "%s%s%s: %s\n", a1, a2, a3, image->image.message);
-
-   else
-      fprintf(stderr, "%s%s%s\n", a1, a2, a3);
-
-   if (image->image.opaque != NULL)
-   {
-      fprintf(stderr, "%s: image opaque pointer non-NULL on error\n",
-         image->file_name);
-      png_image_free(&image->image);
-   }
-
-   return 0;
-}
-
-/* Log an error and close a file (just a utility to do both things in one
- * function call.)
- */
-static int
-logclose(Image *image, FILE *f, const char *name, const char *operation)
-{
-   int e = errno;
-
-   fclose(f);
-   return logerror(image, name, operation, strerror(e));
-}
-
-/* Make sure the png_image has been freed - validates that libpng is doing what
- * the spec says and freeing the image.
- */
-static int
-checkopaque(Image *image)
-{
-   if (image->image.opaque != NULL)
-   {
-      png_image_free(&image->image);
-      return logerror(image, image->file_name, ": opaque not NULL", "");
-   }
-
-   else
-      return 1;
-}
-
-/* IMAGE COMPARISON/CHECKING */
-/* Compare the pixels of two images, which should be the same but aren't.  The
- * images must have been checked for a size match.
- */
-typedef struct
-{
-   png_uint_32 format;
-   png_uint_16 r16, g16, b16, y16, a16;
-   png_byte    r8, g8, b8, y8, a8;
-} Pixel;
-
-/* This is not particularly fast, but it works.  The input has pixels stored
- * either as pre-multiplied linear 16-bit or as sRGB encoded non-pre-multiplied
- * 8-bit values.  The routine reads either and does exact conversion to the
- * other format.
- *
- * Grayscale values are mapped r==g==b=y.  Non-alpha images have alpha
- * 65535/255.  Color images have a correctly calculated Y value using the sRGB Y
- * calculation.
- *
- * The API returns false if an error is detected; this can only be if the alpha
- * value is less than the component in the linear case.
- */
-static int 
-get_pixel(Image *image, Pixel *pixel, png_const_bytep pp)
-{
-   png_uint_32 format = image->image.format;
-   int result = 1;
-
-   pixel->format = format;
-
-   /* Initialize the alpha values for opaque: */
-   pixel->a8 = 255;
-   pixel->a16 = 65535;
-
-   switch (PNG_IMAGE_COMPONENT_SIZE(format))
-   {
-      default:
-         fprintf(stderr, "pngstest: impossible component size: %lu\n",
-            (unsigned long)PNG_IMAGE_COMPONENT_SIZE(format));
-         exit(1);
-
-      case sizeof (png_uint_16):
-         {
-            png_const_uint_16p up = (png_const_uint_16p)pp;
-
-            if ((format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
-               (format & PNG_FORMAT_FLAG_ALPHA) != 0)
-               pixel->a16 = *up++;
-
-            if ((format & PNG_FORMAT_FLAG_COLOR) != 0)
-            {
-               if ((format & PNG_FORMAT_FLAG_BGR) != 0)
-               {
-                  pixel->b16 = *up++;
-                  pixel->g16 = *up++;
-                  pixel->r16 = *up++;
-               }
-
-               else
-               {
-                  pixel->r16 = *up++;
-                  pixel->g16 = *up++;
-                  pixel->b16 = *up++;
-               }
-
-               /* Because the 'Y' calculation is linear the pre-multiplication
-                * of the r16,g16,b16 values can be ignored.
-                */
-               pixel->y16 = u16d(YfromRGBint(pixel->r16, pixel->g16,
-                  pixel->b16));
-            }
-
-            else
-               pixel->r16 = pixel->g16 = pixel->b16 = pixel->y16 = *up++;
-
-            if ((format & PNG_FORMAT_FLAG_AFIRST) == 0 &&
-               (format & PNG_FORMAT_FLAG_ALPHA) != 0)
-               pixel->a16 = *up++;
-
-            /* 'a1' is 1/65535 * 1/alpha, for alpha in the range 0..1 */
-            if (pixel->a16 == 0)
-            {
-               pixel->r8 = pixel->g8 = pixel->b8 = pixel->y8 = 255;
-               pixel->a8 = 0;
-            }
-
-            else
-            {
-               double a1 = 1. / pixel->a16;
-
-               if (pixel->a16 < pixel->r16)
-                  result = 0, pixel->r8 = 255;
-               else
-                  pixel->r8 = sRGB(pixel->r16 * a1);
-
-               if (pixel->a16 < pixel->g16)
-                  result = 0, pixel->g8 = 255;
-               else
-                  pixel->g8 = sRGB(pixel->g16 * a1);
-
-               if (pixel->a16 < pixel->b16)
-                  result = 0, pixel->b8 = 255;
-               else
-                  pixel->b8 = sRGB(pixel->b16 * a1);
-
-               if (pixel->a16 < pixel->y16)
-                  result = 0, pixel->y8 = 255;
-               else
-                  pixel->y8 = sRGB(pixel->y16 * a1);
-
-               /* The 8-bit alpha value is just a16/257. */
-               pixel->a8 = u8d(pixel->a16 / 257.);
-            }
-         }
-         break;
-
-      case sizeof (png_byte):
-         {
-            double y;
-
-            if ((format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
-               (format & PNG_FORMAT_FLAG_ALPHA) != 0)
-               pixel->a8 = *pp++;
-
-            if ((format & PNG_FORMAT_FLAG_COLOR) != 0)
-            {
-               if ((format & PNG_FORMAT_FLAG_BGR) != 0)
-               {
-                  pixel->b8 = *pp++;
-                  pixel->g8 = *pp++;
-                  pixel->r8 = *pp++;
-               }
-
-               else
-               {
-                  pixel->r8 = *pp++;
-                  pixel->g8 = *pp++;
-                  pixel->b8 = *pp++;
-               }
-
-               /* The y8 value requires convert to linear, convert to &, convert
-                * to sRGB:
-                */
-               y = YfromRGB(linear_from_sRGB(pixel->r8/255.),
-                  linear_from_sRGB(pixel->g8/255.),
-                  linear_from_sRGB(pixel->b8/255.));
-
-               pixel->y8 = sRGB(y);
-            }
-
-            else
-            {
-               pixel->r8 = pixel->g8 = pixel->b8 = pixel->y8 = *pp++;
-               y = linear_from_sRGB(pixel->y8/255.);
-            }
-
-            if ((format & PNG_FORMAT_FLAG_AFIRST) == 0 &&
-               (format & PNG_FORMAT_FLAG_ALPHA) != 0)
-               pixel->a8 = *pp++;
-
-            pixel->r16 = ilineara(pixel->r8, pixel->a8);
-            pixel->g16 = ilineara(pixel->g8, pixel->a8);
-            pixel->b16 = ilineara(pixel->b8, pixel->a8);
-            pixel->y16 = u16d((257 * pixel->a8) * y);
-            pixel->a16 = (png_uint_16)(pixel->a8 * 257);
-         }
-         break;
-   }
-
-   return result;
-}
-
-/* Two pixels are equal if the value of the left equals the value of the right
- * as defined by the format of the right, or if it is close enough given the
- * permitted error limits.  If the formats match the values should (exactly!)
- *
- * If the right pixel has no alpha channel but the left does, it was removed
- * somehow.  For an 8-bit *output* removal uses the background color if given
- * else the default (the value filled in to the row buffer by allocbuffer()
- * above.)
- *
- * The result of this function is NULL if the pixels match else a reason why
- * they don't match.
- *
- * Error values below are inflated because some of the conversions are done
- * inside libpng using a simple power law transform of .45455 and others are
- * done in the simplified API code using the correct sRGB tables.  This needs
- * to be made consistent.
- */
-static int error_to_linear = 811; /* by experiment */
-static int error_to_linear_grayscale = 424; /* by experiment */
-static int error_to_sRGB = 6; /* by experiment */
-static int error_to_sRGB_grayscale = 11; /* by experiment */
-static int error_in_compose = 0;
-static int error_via_linear = 14; /* by experiment */
-static int error_in_premultiply = 1;
-
-static const char *
-cmppixel(Pixel *a, Pixel *b, const png_color *background, int via_linear)
-{
-   int error_limit = 0;
-
-   if (b->format & PNG_FORMAT_FLAG_LINEAR)
-   {
-      /* If the input was non-opaque then use the pre-multiplication error
-       * limit.
-       */
-      if ((a->format & PNG_FORMAT_FLAG_ALPHA) && a->a16 < 65535)
-         error_limit = error_in_premultiply;
-
-      if (b->format & PNG_FORMAT_FLAG_ALPHA)
-      {
-         /* Expect an exact match. */
-         if (b->a16 != a->a16)
-            return "linear alpha mismatch";
-      }
-
-      else if (a->format & PNG_FORMAT_FLAG_ALPHA)
-      {
-         /* An alpha channel has been removed, the destination is linear so the
-          * removal algorithm is just the premultiplication - compose on black -
-          * and the 16-bit colors are correct already.
-          */
-      }
-
-      if (b->format & PNG_FORMAT_FLAG_COLOR)
-      {
-         const char *err = "linear color mismatch";
-
-         /* Check for an exact match. */
-         if (a->r16 == b->r16 && a->g16 == b->g16 && a->b16 == b->b16)
-            return NULL;
-
-         /* Not an exact match; allow drift only if the input is 8-bit */
-         if (!(a->format & PNG_FORMAT_FLAG_LINEAR))
-         {
-            if (error_limit < error_to_linear)
-            {
-               error_limit = error_to_linear;
-               err = "sRGB to linear conversion error";
-            }
-         }
-
-         if (abs(a->r16-b->r16) <= error_limit &&
-            abs(a->g16-b->g16) <= error_limit &&
-            abs(a->b16-b->b16) <= error_limit)
-            return NULL;
-
-         return err;
-      }
-
-      else /* b is grayscale */
-      {
-         const char *err = "linear gray mismatch";
-
-         /* Check for an exact match. */
-         if (a->y16 == b->y16)
-            return NULL;
-
-         /* Not an exact match; allow drift only if the input is 8-bit or if it
-          * has been converted from color.
-          */
-         if (!(a->format & PNG_FORMAT_FLAG_LINEAR))
-         {
-            /* Converted to linear, check for that drift. */
-            if (error_limit < error_to_linear)
-            {
-               error_limit = error_to_linear;
-               err = "8-bit gray to linear conversion error";
-            }
-
-            if (abs(a->y16-b->y16) <= error_to_linear)
-               return NULL;
-
-         }
-
-         if (a->format & PNG_FORMAT_FLAG_COLOR)
-         {
-            /* Converted to grayscale, allow drift */
-            if (error_limit < error_to_linear_grayscale)
-            {
-               error_limit = error_to_linear_grayscale;
-               err = "color to linear gray conversion error";
-            }
-         }
-
-         if (abs(a->y16-b->y16) <= error_limit)
-            return NULL;
-
-         return err;
-      }
-   }
-
-   else /* RHS is 8-bit */
-   {
-      const char *err;
-
-      /* For 8-bit to 8-bit use 'error_via_linear'; this handles the cases where
-       * the original image is compared with the output of another conversion:
-       * see where the parameter is set to non-zero below.
-       */
-      if (!(a->format & PNG_FORMAT_FLAG_LINEAR) && via_linear)
-         error_limit = error_via_linear;
-
-      if (b->format & PNG_FORMAT_FLAG_COLOR)
-         err = "8-bit color mismatch";
-      
-      else
-         err = "8-bit gray mismatch";
-
-      /* If the original data had an alpha channel and was not pre-multiplied
-       * pre-multiplication may lose precision in non-opaque pixel values.  If
-       * the output is linear the premultiplied 16-bit values will be used, but
-       * if 'via_linear' is set an intermediate 16-bit pre-multiplied form has
-       * been used and this must be taken into account here.
-       */
-      if (via_linear && (a->format & PNG_FORMAT_FLAG_ALPHA) &&
-         !(a->format & PNG_FORMAT_FLAG_LINEAR) &&
-         a->a16 < 65535)
-      {
-         if (a->a16 > 0)
-         {
-            /* First calculate the rounded 16-bit component values, (r,g,b) or y
-             * as appropriate, then back-calculate the 8-bit values for
-             * comparison below.
-             */
-            if (a->format & PNG_FORMAT_FLAG_COLOR)
-            {
-               double r = closestinteger((65535. * a->r16) / a->a16)/65535;
-               double g = closestinteger((65535. * a->g16) / a->a16)/65535;
-               double blue = closestinteger((65535. * a->b16) / a->a16)/65535;
-
-               a->r16 = u16d(r * a->a16);
-               a->g16 = u16d(g * a->a16);
-               a->b16 = u16d(blue * a->a16);
-               a->y16 = u16d(YfromRGBint(a->r16, a->g16, a->b16));
-
-               a->r8 = u8d(r * 255);
-               a->g8 = u8d(g * 255);
-               a->b8 = u8d(blue * 255);
-               a->y8 = u8d(255 * YfromRGB(r, g, blue));
-            }
-
-            else
-            {
-               double y = closestinteger((65535. * a->y16) / a->a16)/65535.;
-
-               a->b16 = a->g16 = a->r16 = a->y16 = u16d(y * a->a16);
-               a->b8 = a->g8 = a->r8 = a->y8 = u8d(255 * y);
-            }
-         }
-
-         else
-         {
-            a->r16 = a->g16 = a->b16 = a->y16 = 0;
-            a->r8 = a->g8 = a->b8 = a->y8 = 255;
-         }
-      }
-
-
-      if (b->format & PNG_FORMAT_FLAG_ALPHA)
-      {
-         /* Expect an exact match on the 8 bit value. */
-         if (b->a8 != a->a8)
-            return "8-bit alpha mismatch";
-
-         /* If the *input* was linear+alpha as well libpng will have converted
-          * the non-premultiplied format directly to the sRGB non-premultiplied
-          * format and the precision loss on an intermediate pre-multiplied
-          * format will have been avoided.  In this case we will get spurious
-          * values in the non-opaque pixels.
-          */
-         if (!via_linear && (a->format & PNG_FORMAT_FLAG_LINEAR) != 0 &&
-            (a->format & PNG_FORMAT_FLAG_ALPHA) != 0 &&
-            a->a16 < 65535)
-         {
-            /* We don't know the original values (libpng has already removed
-             * them) but we can make sure they are in range here by doing a
-             * comparison on the pre-multiplied values instead.
-             */
-            if (a->a16 > 0)
-            {
-               if (b->format & PNG_FORMAT_FLAG_COLOR)
-               {
-                  double r, g, blue;
-
-                  r = (255. * b->r16)/b->a16;
-                  b->r8 = u8d(r);
-
-                  g = (255. * b->g16)/b->a16;
-                  b->g8 = u8d(g);
-
-                  blue = (255. * b->b16)/b->a16;
-                  b->b8 = u8d(blue);
-
-                  b->y8 = u8d(YfromRGB(r, g, blue));
-               }
-
-               else
-               {
-                  b->r8 = b->g8 = b->b8 = b->y8 =
-                     u8d((255. * b->y16)/b->a16);
-               }
-            }
-
-            else
-               b->r8 = b->g8 = b->b8 = b->y8 = 255;
-         }
-      }
-
-      else if (a->format & PNG_FORMAT_FLAG_ALPHA)
-      {
-         png_uint_32 alpha;
-
-         /* An alpha channel has been removed; the background will have been
-          * composed in.  Adjust the 'a' pixel to represent this by doing the
-          * correct compose.  Set the error limit, above, to an appropriate
-          * value for the compose operation.
-          */
-         if (error_limit < error_in_compose)
-            error_limit = error_in_compose;
-
-         alpha = 65535 - a->a16; /* for the background */
-
-         if (b->format & PNG_FORMAT_FLAG_COLOR) /* background is rgb */
-         {
-            err = "8-bit color compose error";
-
-            if (via_linear)
-            {
-               /* The 16-bit values are already correct (being pre-multiplied),
-                * just recalculate the 8-bit values.
-                */
-               a->r8 = isRGB(a->r16);
-               a->g8 = isRGB(a->g16);
-               a->b8 = isRGB(a->b16);
-               a->y8 = isRGB(a->y16);
-
-               /* There should be no libpng error in this (ideally) */
-               error_limit = 0;
-            }
-
-            else if (background == NULL)
-            {
-               double add = alpha * linear_from_sRGB(BUFFER_INIT8/255.);
-               double r, g, blue, y;
-
-               r = a->r16 + add;
-               a->r16 = u16d(r);
-               a->r8 = sRGB(r/65535);
-
-               g = a->g16 + add;
-               a->g16 = u16d(g);
-               a->g8 = sRGB(g/65535);
-
-               blue = a->b16 + add;
-               a->b16 = u16d(blue);
-               a->b8 = sRGB(blue/65535);
-
-               y = YfromRGB(r, g, blue);
-               a->y16 = u16d(y);
-               a->y8 = sRGB(y/65535);
-            }
-
-            else
-            {
-               double r, g, blue, y;
-
-               r = a->r16 + alpha * linear_from_sRGB(background->red/255.);
-               a->r16 = u16d(r);
-               a->r8 = sRGB(r/65535);
-
-               g = a->g16 + alpha * linear_from_sRGB(background->green/255.);
-               a->g16 = u16d(g);
-               a->g8 = sRGB(g/65535);
-
-               blue = a->b16 + alpha * linear_from_sRGB(background->blue/255.);
-               a->b16 = u16d(blue);
-               a->b8 = sRGB(blue/65535);
-
-               y = YfromRGB(r, g, blue);
-               a->y16 = u16d(y * 65535);
-               a->y8 = sRGB(y);
-            }
-         }
-
-         else /* background is gray */
-         {
-            err = "8-bit gray compose error";
-
-            if (via_linear)
-            {
-               a->r8 = a->g8 = a->b8 = a->y8 = isRGB(a->y16);
-               error_limit = 0;
-            }
-
-            else
-            {
-               /* When the output is gray the background comes from just the
-                * green channel.
-                */
-               double y = a->y16 + alpha * linear_from_sRGB(
-                  (background == NULL ? BUFFER_INIT8 : background->green)/255.);
-
-               a->r16 = a->g16 = a->b16 = a->y16 = u16d(y);
-               a->r8 = a->g8 = a->b8 = a->y8 = sRGB(y/65535);
-            }
-         }
-      }
-
-      if (b->format & PNG_FORMAT_FLAG_COLOR)
-      {
-
-         /* Check for an exact match. */
-         if (a->r8 == b->r8 && a->g8 == b->g8 && a->b8 == b->b8)
-            return NULL;
-
-         /* Check for linear to 8-bit conversion. */
-         if (a->format & PNG_FORMAT_FLAG_LINEAR)
-         {
-            if (error_limit < error_to_sRGB)
-            {
-               err = "linear to sRGB conversion error";
-               error_limit = error_to_sRGB;
-            }
-         }
-
-         if (abs(a->r8-b->r8) <= error_limit &&
-            abs(a->g8-b->g8) <= error_limit &&
-            abs(a->b8-b->b8) <= error_limit)
-            return NULL;
-
-         return err;
-      }
-
-      else /* b is grayscale */
-      {
-         /* Check for an exact match. */
-         if (a->y8 == b->y8)
-            return NULL;
-
-         /* Not an exact match; allow drift only if the input is linear or if it
-          * has been converted from color.
-          */
-         if (a->format & PNG_FORMAT_FLAG_LINEAR)
-         {
-            /* Converted to linear, check for that drift. */
-            if (error_limit < error_to_sRGB)
-            {
-               error_limit = error_to_sRGB;
-               err = "linear to 8-bit gray conversion error";
-            }
-         }
-
-         if (a->format & PNG_FORMAT_FLAG_COLOR)
-         {
-            /* Converted to grayscale, allow drift */
-            if (error_limit < error_to_sRGB_grayscale)
-            {
-               error_limit = error_to_sRGB_grayscale;
-               err = "color to 8-bit gray conversion error";
-            }
-         }
-
-         if (abs(a->y8-b->y8) <= error_limit)
-            return NULL;
-
-         return err;
-      }
-   }
-}
-
-/* Basic image formats; control the data but not the layout thereof. */
-#define BASE_FORMATS\
-   (PNG_FORMAT_FLAG_ALPHA|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_LINEAR)
-
-static void
-print_pixel(char string[64], Pixel *pixel)
-{
-   switch (pixel->format & BASE_FORMATS)
-   {
-      case 0: /* 8-bit, one channel */
-         sprintf(string, "%s(%d)", format_names[pixel->format], pixel->y8);
-         break;
-
-      case PNG_FORMAT_FLAG_ALPHA:
-         sprintf(string, "%s(%d,%d)", format_names[pixel->format], pixel->y8,
-            pixel->a8);
-         break;
-
-      case PNG_FORMAT_FLAG_COLOR:
-         sprintf(string, "%s(%d,%d,%d)", format_names[pixel->format],
-            pixel->r8, pixel->g8, pixel->b8);
-         break;
-
-      case PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA:
-         sprintf(string, "%s(%d,%d,%d,%d)", format_names[pixel->format],
-            pixel->r8, pixel->g8, pixel->b8, pixel->a8);
-         break;
-
-      case PNG_FORMAT_FLAG_LINEAR:
-         sprintf(string, "%s(%d)", format_names[pixel->format], pixel->y16);
-         break;
-
-      case PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA:
-         sprintf(string, "%s(%d,%d)", format_names[pixel->format], pixel->y16,
-            pixel->a16);
-         break;
-
-      case PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR:
-         sprintf(string, "%s(%d,%d,%d)", format_names[pixel->format],
-            pixel->r16, pixel->g16, pixel->b16);
-         break;
-
-      case PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA:
-         sprintf(string, "%s(%d,%d,%d,%d)", format_names[pixel->format],
-            pixel->r16, pixel->g16, pixel->b16, pixel->a16);
-         break;
-
-      default:
-         sprintf(string, "invalid-format");
-         break;
-   }
-}
-
-static int
-logpixel(Image *image, png_uint_32 x, png_uint_32 y, Pixel *a, Pixel *b,
-   const char *reason)
-{
-   char pixel_a[64], pixel_b[64];
-   char error_buffer[256];
-
-   print_pixel(pixel_a, a);
-   print_pixel(pixel_b, b);
-   sprintf(error_buffer, "(%lu,%lu) %s: %s -> %s", (unsigned long)x,
-      (unsigned long)y, reason, pixel_a, pixel_b);
-   return logerror(image, image->file_name, error_buffer, "");
-}
-
-/* Compare two images, the original 'a', which was written out then read back in
- * to * give image 'b'.  The formats may have been changed.
- */
-static int
-compare_two_images(Image *a, Image *b, int via_linear)
-{
-   png_uint_32 width = a->image.width;
-   png_uint_32 height = a->image.height;
-   png_uint_32 formata = a->image.format;
-   png_uint_32 formatb = b->image.format;
-   ptrdiff_t stridea = a->stride;
-   ptrdiff_t strideb = b->stride;
-   png_const_bytep rowa = a->buffer+16;
-   png_const_bytep rowb = b->buffer+16;
-   png_byte channels;
-   int linear = 0;
-   int result = 1;
-   unsigned int check_alpha = 0; /* must be zero or one */
-   png_byte swap_mask[4];
-   png_uint_32 x, y;
-   png_const_bytep ppa, ppb;
-   const png_color *background =
-      ((a->opts & USE_BACKGROUND) ? &a->background : NULL);
-
-   /* This should never happen: */
-   if (width != b->image.width || height != b->image.height)
-      return logerror(a, a->file_name, ": width x height changed: ",
-         b->file_name);
-
-   /* Find the first row and inter-row space. */
-   if (formata & PNG_FORMAT_FLAG_LINEAR)
-   {
-      stridea *= sizeof (png_uint_16);
-      ++linear;
-   }
-
-   if (formatb & PNG_FORMAT_FLAG_LINEAR)
-   {
-      strideb *= sizeof (png_uint_16);
-      ++linear;
-   }
-
-   if (stridea < 0) rowa += (height-1) * (-stridea);
-   if (strideb < 0) rowb += (height-1) * (-strideb);
-
-   /* The following are used only if the formats match, except that 'channels'
-    * is a flag for matching formats.
-    */
-   channels = 0;
-   swap_mask[3] = swap_mask[2] = swap_mask[1] = swap_mask[0] = 0;
-
-   /* Set up the masks if no base format change, or if the format change was
-    * just to add an alpha channel.
-    */
-   if (((formata | PNG_FORMAT_FLAG_ALPHA) & BASE_FORMATS) ==
-         (formatb & BASE_FORMATS))
-   {
-      png_byte astart = 0; /* index of first component */
-      png_byte bstart = 0;
-
-      /* Set to the actual number of channels in 'a' */
-      channels = (formata & PNG_FORMAT_FLAG_COLOR) ? 3 : 1;
-
-      if (formata & PNG_FORMAT_FLAG_ALPHA)
-      {
-         /* Both formats have an alpha channel */
-         if (formata & PNG_FORMAT_FLAG_AFIRST)
-         {
-            astart = 1;
-
-            if (formatb & PNG_FORMAT_FLAG_AFIRST)
-            {
-               bstart = 1;
-               swap_mask[0] = 0;
-            }
-
-            else
-               swap_mask[0] = channels; /* 'b' alpha is at end */
-         }
-
-         else if (formatb & PNG_FORMAT_FLAG_AFIRST)
-         {
-            /* 'a' alpha is at end, 'b' is at start (0) */
-            bstart = 1;
-            swap_mask[channels] = 0;
-         }
-
-         else
-            swap_mask[channels] = channels;
-
-         ++channels;
-      }
-
-      else if (formatb & PNG_FORMAT_FLAG_ALPHA)
-      {
-         /* Only 'b' has an alpha channel */
-         check_alpha = 1;
-         if (formatb & PNG_FORMAT_FLAG_AFIRST)
-         {
-            bstart = 1;
-            /* Put the location of the alpha channel in swap_mask[3], since it
-             * cannot be used if 'a' does not have an alpha channel.
-             */
-            swap_mask[3] = 0;
-         }
-
-         else
-            swap_mask[3] = channels;
-      }
-
-      if (formata & PNG_FORMAT_FLAG_COLOR)
-      {
-         unsigned int swap = 0;
-
-         /* Colors match, but are they swapped? */
-         if ((formata ^ formatb) & PNG_FORMAT_FLAG_BGR) /* Swapped. */
-            swap = 2;
-
-         swap_mask[astart+0] = (png_byte)(bstart+(0^swap));
-         swap_mask[astart+1] = (png_byte)(bstart+1);
-         swap_mask[astart+2] = (png_byte)(bstart+(2^swap));
-      }
-
-      else /* grayscale: 1 channel */
-         swap_mask[astart] = bstart;
-   }
-
-   ppa = rowa;
-   ppb = rowb;
-   for (x=y=0; y<height;)
-   {
-      /* Do the fast test if possible. */
-      if (channels != 0) switch (linear)
-      {
-         case 2: /* both sides linear */
-            {
-               png_const_uint_16p lppa = (png_const_uint_16p)ppa;
-               png_const_uint_16p lppb = (png_const_uint_16p)ppb;
-
-               while (x < width) switch (channels)
-               {
-                  case 4:
-                     if (lppa[3] != lppb[swap_mask[3]])
-                        goto linear_mismatch;
-                  case 3:
-                     if (lppa[2] != lppb[swap_mask[2]])
-                        goto linear_mismatch;
-                  case 2:
-                     if (lppa[1] != lppb[swap_mask[1]])
-                        goto linear_mismatch;
-                  case 1:
-                     if (lppa[0] != lppb[swap_mask[0]])
-                        goto linear_mismatch;
-
-                     /* The pixels apparently match, but if an alpha channel has
-                      * been added (in b) it must be 65535 too.
-                      */
-                     if (check_alpha && 65535 != lppb[swap_mask[3]])
-                        goto linear_mismatch;
-
-                     /* This pixel matches, advance to the next. */
-                     lppa += channels;
-                     lppb += channels + check_alpha;
-                     ++x;
-                  default:
-                     break;
-               }
-
-            linear_mismatch:
-               ppa = (png_const_bytep)lppa;
-               ppb = (png_const_bytep)lppb;
-            }
-            break;
-
-         case 0: /* both sides sRGB */
-            while (x < width) switch (channels)
-            {
-               case 4:
-                  if (ppa[3] != ppb[swap_mask[3]])
-                     goto sRGB_mismatch;
-               case 3:
-                  if (ppa[2] != ppb[swap_mask[2]])
-                     goto sRGB_mismatch;
-               case 2:
-                  if (ppa[1] != ppb[swap_mask[1]])
-                     goto sRGB_mismatch;
-               case 1:
-                  if (ppa[0] != ppb[swap_mask[0]])
-                     goto sRGB_mismatch;
-
-                  /* The pixels apparently match, but if an alpha channel has
-                   * been added (in b) it must be 1.0 too.
-                   */
-                  if (check_alpha && 255 != ppb[swap_mask[3]])
-                     goto sRGB_mismatch;
-
-                  /* This pixel matches, advance to the next. */
-                  ppa += channels;
-                  ppb += channels + check_alpha;
-                  ++x;
-               default:
-                  break;
-            }
-
-         sRGB_mismatch:
-            break;
-
-         default: /* formats do not match */
-            break;
-      }
-
-      /* If at the end of the row advance to the next row, if not at the end
-       * compare the pixels the slow way.
-       */
-      if (x < width)
-      {
-         Pixel pixel_a, pixel_b;
-         const char *mismatch;
-
-         get_pixel(a, &pixel_a, ppa);
-         get_pixel(b, &pixel_b, ppb);
-         mismatch = cmppixel(&pixel_a, &pixel_b, background, via_linear);
-
-         if (mismatch != NULL)
-         {
-            (void)logpixel(a, x, y, &pixel_a, &pixel_b, mismatch);
-
-            if ((a->opts & KEEP_GOING) == 0)
-               return 0;
-
-            result = 0;
-         }
-
-         ++x;
-      }
-
-      if (x >= width)
-      {
-         x = 0;
-         ++y;
-         rowa += stridea;
-         rowb += strideb;
-         ppa = rowa;
-         ppb = rowb;
-      }
-   }
-
-   return result;
-}
-
-/* Read the file; how the read gets done depends on which of input_file and
- * input_memory have been set.
- */
-static int
-read_file(Image *image, png_uint_32 format)
-{
-   if (image->input_memory != NULL)
-   {
-      if (!png_image_begin_read_from_memory(&image->image, image->input_memory,
-         image->input_memory_size))
-         return logerror(image, "memory init: ", image->file_name, "");
-   }
-
-   else if (image->input_file != NULL)
-   {
-      if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
-         return logerror(image, "stdio init: ", image->file_name, "");
-   }
-
-   else
-   {
-      if (!png_image_begin_read_from_file(&image->image, image->file_name))
-         return logerror(image, "file init: ", image->file_name, "");
-   }
-
-   /* Have an initialized image with all the data we need plus, maybe, an
-    * allocated file (myfile) or buffer (mybuffer) that need to be freed.
-    */
-   {
-      int result;
-
-      /* Various random settings for detecting overwrites */
-      image->background.red = 89;
-      image->background.green = 78;
-      image->background.blue = 178;
-
-      /* Print both original and output formats. */
-      if (image->opts & VERBOSE)
-         printf("%s %lu x %lu %s -> %s\n", image->file_name,
-            (unsigned long)image->image.width,
-            (unsigned long)image->image.height,
-            format_names[image->image.format & 0x1f],
-            (format & FORMAT_NO_CHANGE) != 0 || image->image.format == format
-            ? "no change" : format_names[format & 0x1f]);
-
-      if ((format & FORMAT_NO_CHANGE) == 0)
-         image->image.format = format;
-
-      image->stride = PNG_IMAGE_ROW_STRIDE(image->image) + image->stride_extra;
-      allocbuffer(image);
-
-      result = png_image_finish_read(&image->image,
-         (image->opts & USE_BACKGROUND) ? &image->background : NULL,
-         image->buffer+16, (png_int_32)image->stride);
-
-      checkbuffer(image, image->file_name);
-
-      if (result)
-         return checkopaque(image);
-
-      else
-         return logerror(image, image->file_name, ": image read failed", "");
-   }
-}
-
-/* Reads from a filename, which must be in image->file_name, but uses
- * image->opts to choose the method.
- */
-static int
-read_one_file(Image *image, png_uint_32 format)
-{
-   if (!(image->opts & READ_FILE) || (image->opts & USE_STDIO))
-   {
-      /* memory or stdio. */
-      FILE *f = fopen(image->file_name, "rb");
-
-      if (f != NULL)
-      {
-         if (image->opts & READ_FILE)
-            image->input_file = f;
-
-         else /* memory */
-         {
-            if (fseek(f, 0, SEEK_END) == 0)
-            {
-               long int cb = ftell(f);
-
-               if (cb >= 0 && (unsigned long int)cb < (size_t)~(size_t)0)
-               {
-                  png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
-
-                  if (b != NULL)
-                  {
-                     rewind(f);
-
-                     if (fread(b, (size_t)cb, 1, f) == 1)
-                     {
-                        fclose(f);
-                        image->input_memory_size = cb;
-                        image->input_memory = b;
-                     }
-
-                     else
-                     {
-                        free(b);
-                        return logclose(image, f, image->file_name,
-                           ": read failed");
-                     }
-                  }
-
-                  else
-                     return logclose(image, f, image->file_name,
-                        ": out of memory");
-               }
-
-               else
-                  return logclose(image, f, image->file_name, ": tell failed");
-            }
-
-            else
-               return logclose(image, f, image->file_name, ": seek failed: ");
-         }
-      }
-
-      else
-         return logerror(image, image->file_name, ": open failed: ",
-            strerror(errno));
-   }
-
-   return read_file(image, format);
-}
-
-static int
-write_one_file(Image *output, Image *image, int convert_to_8bit)
-{
-   if (image->opts & USE_STDIO)
-   {
-      FILE *f = tmpfile();
-
-      if (f != NULL)
-      {
-         if (png_image_write_to_stdio(&image->image, f, convert_to_8bit,
-            image->buffer+16, (png_int_32)image->stride))
-         {
-            if (fflush(f) == 0)
-            {
-               rewind(f);
-               initimage(output, image->opts, "tmpfile", image->stride_extra);
-               output->input_file = f;
-               if (!checkopaque(image))
-                  return 0;
-            }
-
-            else
-               return logclose(image, f, "tmpfile", ": flush");
-         }
-
-         else
-         {
-            fclose(f);
-            return logerror(image, "tmpfile", ": write failed", "");
-         }
-      }
-
-      else
-         return logerror(image, "tmpfile", ": open: ", strerror(errno));
-   }
-
-   else
-   {
-      static int counter = 0;
-      char name[32];
-
-      sprintf(name, "TMP%d.png", ++counter);
-
-      if (png_image_write_to_file(&image->image, name, convert_to_8bit,
-         image->buffer+16, (png_int_32)image->stride))
-      {
-         initimage(output, image->opts, output->tmpfile_name,
-            image->stride_extra);
-         /* Afterwards, or freeimage will delete it! */
-         strcpy(output->tmpfile_name, name);
-
-         if (!checkopaque(image))
-            return 0;
-      }
-
-      else
-         return logerror(image, name, ": write failed", "");
-   }
-
-   /* 'output' has an initialized temporary image, read this back in and compare
-    * this against the original: there should be no change since the original
-    * format was written unmodified unless 'convert_to_8bit' was specified.
-    */
-   if (read_file(output, FORMAT_NO_CHANGE))
-   {
-      if ((output->image.format & BASE_FORMATS) !=
-         ((image->image.format & BASE_FORMATS) &
-            ~(convert_to_8bit ? PNG_FORMAT_FLAG_LINEAR : 0)))
-         return logerror(image, image->file_name, ": format changed on read:",
-            output->file_name);
-
-      return compare_two_images(image, output, 0);
-   }
-
-   else
-      return logerror(output, output->tmpfile_name,
-         ": read of new file failed", "");
-}
-
-static int
-testimage(Image *image, png_uint_32 opts, png_uint_32 formats)
-{
-   int result;
-   Image copy;
-
-   /* Copy the original data, stealing it from 'image' */
-   checkopaque(image);
-   copy = *image;
-
-   copy.opts = opts;
-   copy.buffer = NULL;
-   copy.bufsize = 0;
-   copy.allocsize = 0;
-
-   image->input_file = NULL;
-   image->input_memory = NULL;
-   image->input_memory_size = 0;
-   image->tmpfile_name[0] = 0;
-
-   {
-      png_uint_32 format;
-      Image output;
-
-      newimage(&output);
-      
-      result = 1;
-      for (format=0; format<32; ++format) if (formats & (1<<format))
-      {
-         resetimage(&copy);
-         result = read_file(&copy, format);
-         if (!result)
-            break;
-
-         /* Make sure the file just read matches the original file. */
-         result = compare_two_images(image, &copy, 0);
-         if (!result)
-            break;
-
-         /* Write the *copy* just made to a new file to make sure the write side
-          * works ok.  Check the conversion to sRGB if the copy is linear.
-          */
-         result = write_one_file(&output, &copy, 0/*convert to 8bit*/);
-         if (!result)
-            break;
-
-         /* Validate against the original too: */
-         result = compare_two_images(image, &output, 0);
-         if (!result)
-            break;
-
-         if ((output.image.format & PNG_FORMAT_FLAG_LINEAR) != 0)
-         {
-            /* 'output' is linear, convert to the corresponding sRGB format. */
-            result = write_one_file(&output, &copy, 1/*convert to 8bit*/);
-            if (!result)
-               break;
-
-            /* This may involve a conversion via linear; in the ideal world this
-             * would round-trip correctly, but libpng 1.5.7 is not the ideal
-             * world so allow a drift (error_via_linear).
-             *
-             * 'image' has an alpha channel but 'output' does not then there
-             * will a strip-alpha-channel operation (because 'output' is
-             * linear), handle this by composing on black when doing the
-             * comparison.
-             */
-            result = compare_two_images(image, &output, 1/*via_linear*/);
-            if (!result)
-               break;
-         }
-      }
-
-      freeimage(&output);
-   }
-
-   freeimage(&copy);
-
-   return result;
-}
-
-int
-main(int argc, const char **argv)
-{
-   png_uint_32 opts = 0;
-   png_uint_32 formats = (png_uint_32)~0; /* a mask of formats to test */
-   const char *touch = NULL;
-   int log_pass = 0;
-   int stride_extra = 0;
-   int retval = 0;
-   int c;
-
-   for (c=1; c<argc; ++c)
-   {
-      const char *arg = argv[c];
-
-      if (strcmp(arg, "--log") == 0)
-         log_pass = 1;
-      else if (strcmp(arg, "--file") == 0)
-         opts |= READ_FILE;
-      else if (strcmp(arg, "--memory") == 0)
-         opts &= ~READ_FILE;
-      else if (strcmp(arg, "--stdio") == 0)
-         opts |= USE_STDIO;
-      else if (strcmp(arg, "--name") == 0)
-         opts &= ~USE_STDIO;
-      else if (strcmp(arg, "--background") == 0)
-         opts |= USE_BACKGROUND;
-      else if (strcmp(arg, "--composite") == 0)
-         opts &= ~USE_BACKGROUND;
-      else if (strcmp(arg, "--verbose") == 0)
-         opts |= VERBOSE;
-      else if (strcmp(arg, "--quiet") == 0)
-         opts &= ~VERBOSE;
-      else if (strcmp(arg, "--preserve") == 0)
-         opts |= KEEP_TMPFILES;
-      else if (strcmp(arg, "--nopreserve") == 0)
-         opts &= ~KEEP_TMPFILES;
-      else if (strcmp(arg, "--keep-going") == 0)
-         opts |= KEEP_GOING;
-      else if (strcmp(arg, "--stop") == 0)
-         opts &= ~KEEP_GOING;
-      else if (strcmp(arg, "--touch") == 0)
-      {
-         if (c+1 < argc)
-            touch = argv[++c];
-
-         else
-         {
-            fprintf(stderr, "%s: %s requires a file name argument\n",
-               argv[0], arg);
-            exit(1);
-         }
-      }
-      else if (arg[0] == '+')
-      {
-         png_uint_32 format = formatof(arg+1);
-
-         if (format > 31)
-            exit(1);
-
-         if (formats == (png_uint_32)~0)
-            formats = 0;
-
-         formats |= 1<<format;
-      }
-      else if (arg[0] == '-')
-      {
-         fprintf(stderr, "%s: unknown option: %s\n", argv[0], arg);
-         exit(1);
-      }
-      else
-      {
-         int result;
-         Image image;
-
-         newimage(&image);
-         initimage(&image, opts, arg, stride_extra);
-         result = read_one_file(&image, FORMAT_NO_CHANGE);
-         if (result)
-            result = testimage(&image, opts, formats);
-         freeimage(&image);
-
-         if (log_pass)
-         {
-            if (result)
-               printf("PASS:");
-
-            else
-            {
-               printf("FAIL:");
-               retval = 1;
-            }
-
-            print_opts(opts);
-            printf(" %s\n", arg);
-         }
-
-         else if (!result)
-            exit(1);
-      }
-   }
-
-   if (retval == 0 && touch != NULL)
-   {
-      FILE *fsuccess = fopen(touch, "wt");
-
-      if (fsuccess != NULL)
-      {
-         int error = 0;
-         fprintf(fsuccess, "PNG simple API tests succeeded\n");
-         fflush(fsuccess);
-         error = ferror(fsuccess);
-
-         if (fclose(fsuccess) || error)
-         {
-            fprintf(stderr, "%s: write failed\n", touch);
-            exit(1);
-         }
-      }
-
-      else
-      {
-         fprintf(stderr, "%s: open failed\n", touch);
-         exit(1);
-      }
-   }
-
-   return retval;
-}
diff --git a/contrib/libtests/timepng.c b/contrib/libtests/timepng.c
deleted file mode 100644
index 36354bf..0000000
--- a/contrib/libtests/timepng.c
+++ /dev/null
@@ -1,289 +0,0 @@
-/* timepng.c
- *
- * Copyright (c) 2011 John Cunningham Bowler
- *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
- *
- * This code is released under the libpng license.
- * For conditions of distribution and use, see the disclaimer
- * and license in png.h
- *
- * Load an arbitrary number of PNG files (from the command line, or, if there
- * are no arguments on the command line, from stdin) then run a time test by
- * reading each file by row.  The test does nothing with the read result and
- * does no transforms.  The only output is a time as a floating point number of
- * seconds with 9 decimal digits.
- */
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <time.h>
-
-#include "png.h"
-
-static int read_png(FILE *fp)
-{
-   png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
-   png_infop info_ptr = NULL;
-   png_bytep row = NULL, display = NULL;
-
-   if (png_ptr == NULL)
-      return 0;
-
-   if (setjmp(png_jmpbuf(png_ptr)))
-   {
-      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-      if (row != NULL) free(row);
-      if (display != NULL) free(display);
-      return 0;
-   }
-
-   png_init_io(png_ptr, fp);
-
-   info_ptr = png_create_info_struct(png_ptr);
-   if (info_ptr == NULL)
-      png_error(png_ptr, "OOM allocating info structure");
-
-   png_read_info(png_ptr, info_ptr);
-
-   {
-      png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
-
-      row = malloc(rowbytes);
-      display = malloc(rowbytes);
-
-      if (row == NULL || display == NULL)
-         png_error(png_ptr, "OOM allocating row buffers");
-
-      {
-         png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
-         int passes = png_set_interlace_handling(png_ptr);
-         int pass;
-
-         png_start_read_image(png_ptr);
-
-         for (pass = 0; pass < passes; ++pass)
-         {
-            png_uint_32 y = height;
-
-            /* NOTE: this trashes the row each time; interlace handling won't
-             * work, but this avoids memory thrashing for speed testing.
-             */
-            while (y-- > 0)
-               png_read_row(png_ptr, row, display);
-         }
-      }
-   }
-
-   /* Make sure to read to the end of the file: */
-   png_read_end(png_ptr, info_ptr);
-   png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-   free(row);
-   free(display);
-   return 1;
-}
-
-static int mytime(struct timespec *t)
-{
-   /* Do the timing using clock_gettime and the per-process timer. */
-   if (!clock_gettime(CLOCK_PROCESS_CPUTIME_ID, t))
-      return 1;
-
-   perror("CLOCK_PROCESS_CPUTIME_ID");
-   fprintf(stderr, "timepng: could not get the time\n");
-   return 0;
-}
-
-static int perform_one_test(FILE *fp, int nfiles)
-{
-   int i;
-   struct timespec before, after;
-
-   /* Clear out all errors: */
-   rewind(fp);
-
-   if (mytime(&before))
-   {
-      for (i=0; i<nfiles; ++i)
-      {
-         if (read_png(fp))
-         {
-            if (ferror(fp))
-            {
-               perror("temporary file");
-               fprintf(stderr, "file %d: error reading PNG data\n", i);
-               return 0;
-            }
-         }
-
-         else
-         {
-            perror("temporary file");
-            fprintf(stderr, "file %d: error from libpng\n", i);
-            return 0;
-         }
-      }
-   }
-
-   else
-      return 0;
-
-   if (mytime(&after))
-   {
-      /* Work out the time difference and print it - this is the only output,
-       * so flush it immediately.
-       */
-      unsigned long s = after.tv_sec - before.tv_sec;
-      long ns = after.tv_nsec - before.tv_nsec;
-
-      if (ns < 0)
-      {
-         --s;
-         ns += 1000000000;
-
-         if (ns < 0)
-         {
-            fprintf(stderr, "timepng: bad clock from kernel\n");
-            return 0;
-         }
-      }
-
-      printf("%lu.%.9ld\n", s, ns);
-      fflush(stdout);
-      if (ferror(stdout))
-      {
-         fprintf(stderr, "timepng: error writing output\n");
-         return 0;
-      }
-
-      /* Successful return */
-      return 1;
-   }
-
-   else
-      return 0;
-}
-
-static int add_one_file(FILE *fp, char *name)
-{
-   FILE *ip = fopen(name, "rb");
-
-   if (ip != NULL)
-   {
-      int ch;
-      for (;;)
-      {
-         ch = getc(ip);
-         if (ch == EOF) break;
-         putc(ch, fp);
-      }
-
-      if (ferror(ip))
-      {
-         perror(name);
-         fprintf(stderr, "%s: read error\n", name);
-         return 0;
-      }
-
-      (void)fclose(ip);
-
-      if (ferror(fp))
-      {
-         perror("temporary file");
-         fprintf(stderr, "temporary file write error\n");
-         return 0;
-      }
-   }
-
-   else
-   {
-      perror(name);
-      fprintf(stderr, "%s: open failed\n", name);
-      return 0;
-   }
-
-   return 1;
-}
-
-int main(int argc, char **argv)
-{
-   int ok = 0;
-   FILE *fp = tmpfile();
-
-   if (fp != NULL)
-   {
-      int err = 0;
-      int nfiles = 0;
-
-      if (argc > 1)
-      {
-         int i;
-
-         for (i=1; i<argc; ++i)
-         {
-            if (add_one_file(fp, argv[i]))
-               ++nfiles;
-
-            else
-            {
-               err = 1;
-               break;
-            }
-         }
-      }
-
-      else
-      {
-         char filename[FILENAME_MAX+1];
-
-         while (fgets(filename, FILENAME_MAX+1, stdin))
-         {
-            int len = strlen(filename);
-
-            if (filename[len-1] == '\n')
-            {
-               filename[len-1] = 0;
-               if (add_one_file(fp, filename))
-                  ++nfiles;
-
-               else
-               {
-                  err = 1;
-                  break;
-               }
-            }
-
-            else
-            {
-               fprintf(stderr, "timepng: truncated file name ...%s\n",
-                  filename+len-32);
-               err = 1;
-               break;
-            }
-         }
-
-         if (ferror(stdin))
-         {
-            fprintf(stderr, "timepng: stdin: read error\n");
-            err = 1;
-         }
-      }
-
-      if (!err)
-      {
-         if (nfiles > 0)
-            ok = perform_one_test(fp, nfiles);
-
-         else
-            fprintf(stderr, "usage: timepng {files} or ls files | timepng\n");
-      }
-
-      (void)fclose(fp);
-   }
-
-   else
-      fprintf(stderr, "timepng: could not open temporary file\n");
-
-   /* Exit code 0 on success. */
-   return ok == 0;
-}
diff --git a/contrib/sRGBtables/cvtcolor.c b/contrib/sRGBtables/cvtcolor.c
deleted file mode 100644
index a7a2e3d..0000000
--- a/contrib/sRGBtables/cvtcolor.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*-
- * convert.c
- *
- * Convert 8-bit sRGB or 16-bit linear values to another format.
- *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
- * Copyright (c) 2011 Written by John Cunningham Bowler
- *
- * This code is released under the libpng license.
- * For conditions of distribution and use, see the disclaimer
- * and license in png.h
- */
-#define _ISOC99_SOURCE 1
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <stdio.h>
-
-#include <fenv.h>
-
-#include "sRGB.h"
-
-static void
-usage(const char *prog)
-{
-   fprintf(stderr,
-      "%s: usage: %s [-linear|-sRGB] [-gray|-color] component{1,4}\n",
-      prog, prog);
-   exit(1);
-}
-
-unsigned long
-component(const char *prog, const char *arg, int issRGB)
-{
-   char *ep;
-   unsigned long c = strtoul(arg, &ep, 0);
-
-   if (ep <= arg || *ep || c > 65535 || (issRGB && c > 255))
-   {
-      fprintf(stderr, "%s: %s: invalid component value (%lu)\n", prog, arg, c);
-      usage(prog);
-   }
-
-   return c;
-}
-
-int
-main(int argc, const char **argv)
-{
-   const char *prog = *argv++;
-   int to_linear = 0, to_gray = 0, to_color = 0;
-   int channels = 0;
-   double c[4];
-
-   /* FE_TONEAREST is the IEEE754 round to nearest, preferring even, mode; i.e.
-    * everything rounds to the nearest value except that '.5' rounds to the
-    * nearest even value.
-    */
-   fesetround(FE_TONEAREST);
-
-   c[3] = c[2] = c[1] = c[0] = 0;
-
-   while (--argc > 0 && **argv == '-')
-   {
-      const char *arg = 1+*argv++;
-
-      if (strcmp(arg, "sRGB") == 0)
-         to_linear = 0;
-
-      else if (strcmp(arg, "linear") == 0)
-         to_linear = 1;
-
-      else if (strcmp(arg, "gray") == 0)
-         to_gray = 1, to_color = 0;
-
-      else if (strcmp(arg, "color") == 0)
-         to_gray = 0, to_color = 1;
-
-      else
-         usage(prog);
-   }
-
-   switch (argc)
-   {
-      default:
-         usage(prog);
-         break;
-
-      case 4:
-         c[3] = component(prog, argv[3], to_linear);
-         ++channels;
-      case 3:
-         c[2] = component(prog, argv[2], to_linear);
-         ++channels;
-      case 2:
-         c[1] = component(prog, argv[1], to_linear);
-         ++channels;
-      case 1:
-         c[0] = component(prog, argv[0], to_linear);
-         ++channels;
-         break;
-      }
-
-   if (to_linear)
-   {
-      int i;
-      int components = channels;
-
-      if ((components & 1) == 0)
-         --components;
-
-      for (i=0; i<components; ++i) c[i] = linear_from_sRGB(c[i] / 255);
-      if (components < channels)
-         c[components] = c[components] / 255;
-   }
-
-   else
-   {
-      int i;
-      for (i=0; i<4; ++i) c[i] /= 65535;
-
-      if ((channels & 1) == 0)
-      {
-         double alpha = c[channels-1];
-
-         if (alpha > 0)
-            for (i=0; i<channels-1; ++i) c[i] /= alpha;
-         else
-            for (i=0; i<channels-1; ++i) c[i] = 1;
-      }
-   }
-
-   if (to_gray)
-   {
-      if (channels < 3)
-      {
-         fprintf(stderr, "%s: too few channels (%d) for -gray\n",
-            prog, channels);
-         usage(prog);
-      }
-
-      c[0] = YfromRGB(c[0], c[1], c[2]);
-      channels -= 2;
-   }
-
-   if (to_color)
-   {
-      if (channels > 2)
-      {
-         fprintf(stderr, "%s: too many channels (%d) for -color\n",
-            prog, channels);
-         usage(prog);
-      }
-
-      c[3] = c[1]; /* alpha, if present */
-      c[2] = c[1] = c[0];
-   }
-
-   if (to_linear)
-   {
-      int i;
-      if ((channels & 1) == 0)
-      {
-         double alpha = c[channels-1];
-         for (i=0; i<channels-1; ++i) c[i] *= alpha;
-      }
-
-      for (i=0; i<channels; ++i) c[i] = nearbyint(c[i] * 65535);
-   }
-
-   else /* to sRGB */
-   {
-      int i = (channels+1)&~1;
-      while (--i >= 0)
-         c[i] = sRGB_from_linear(c[i]);
-
-      for (i=0; i<channels; ++i) c[i] = nearbyint(c[i] * 255);
-   }
-
-   {
-      int i;
-      for (i=0; i<channels; ++i) printf(" %g", c[i]);
-   }
-   printf("\n");
-
-   return 0;
-}
diff --git a/contrib/sRGBtables/makesRGB.c b/contrib/sRGBtables/makesRGB.c
deleted file mode 100644
index 9f75b68..0000000
--- a/contrib/sRGBtables/makesRGB.c
+++ /dev/null
@@ -1,430 +0,0 @@
-/* makesRGB.c -- build sRGB-to-linear and linear-to-sRGB conversion tables
- *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
- * Copyright (c) 2011 John Cunningham Bowler
- *
- * This code is released under the libpng license.
- * For conditions of distribution and use, see the disclaimer
- * and license in png.h
- *
- * Make a table to convert 8-bit sRGB encoding values into the closest 16-bit
- * linear value.
- *
- * Make two tables to take a linear value scaled to 255*65535 and return an
- * approximation to the 8-bit sRGB encoded value.  Calculate the error in these
- * tables and display it.
- */
-#define _C99_SOURCE 1
-#include <stdio.h>
-#include <math.h>
-#include <stdlib.h>
-
-/* pngpriv.h includes the definition of 'PNG_sRGB_FROM_LINEAR' which is required
- * to verify the actual code.
- */
-#include "../../pngpriv.h"
-
-#include "sRGB.h"
-
-/* The tables are declared 'const' in pngpriv.h, so this redefines the tables to
- * be used.
- */
-#define png_sRGB_table sRGB_table
-#define png_sRGB_base sRGB_base
-#define png_sRGB_delta sRGB_delta
-
-static png_uint_16 png_sRGB_table[256];
-static png_uint_16 png_sRGB_base[512];
-static png_byte png_sRGB_delta[512];
-
-static const unsigned int max_input = 255*65535;
-
-double
-fsRGB(double l)
-{
-   return sRGB_from_linear(l/max_input);
-}
-
-double
-sRGB(unsigned int i)
-{
-   return fsRGB(i);
-}
-
-double
-finvsRGB(unsigned int i)
-{
-   return 65535 * linear_from_sRGB(i/255.);
-}
-
-png_uint_16
-invsRGB(unsigned int i)
-{
-   unsigned int x = nearbyint(finvsRGB(i));
-
-   if (x > 65535)
-   {
-      fprintf(stderr, "invsRGB(%u) overflows to %u\n", i, x);
-      exit(1);
-   }
-
-   return (png_uint_16)x;
-}
-
-int
-main(int argc, char **argv)
-{
-   unsigned int i, i16, ibase;
-   double min_error = 0;
-   double max_error = 0;
-   double min_error16 = 0;
-   double max_error16 = 0;
-   double adjust;
-   double adjust_lo = 0.4, adjust_hi = 0.6, adjust_mid = 0.5;
-   unsigned int ec_lo = 0, ec_hi = 0, ec_mid = 0;
-   unsigned int error_count = 0;
-   unsigned int error_count16 = 0;
-   int test_only = 0;
-
-   if (argc > 1)
-      test_only = strcmp("--test", argv[1]) == 0;
-
-   /* Initialize the encoding table first. */
-   for (i=0; i<256; ++i)
-   {
-      png_sRGB_table[i] = invsRGB(i);
-   }
-
-   /* Now work out the decoding tables (this is where the error comes in because
-    * there are 512 set points and 512 straight lines between them.)
-    */
-   for (;;)
-   {
-      if (ec_lo == 0)
-         adjust = adjust_lo;
-
-      else if (ec_hi == 0)
-         adjust = adjust_hi;
-
-      else if (ec_mid == 0)
-         adjust = adjust_mid;
-
-      else if (ec_mid < ec_hi)
-         adjust = (adjust_mid + adjust_hi)/2;
-
-      else if (ec_mid < ec_lo)
-         adjust = (adjust_mid + adjust_lo)/2;
-
-      else
-      {
-         fprintf(stderr, "not reached: %u .. %u .. %u\n", ec_lo, ec_mid, ec_hi);
-         exit(1);
-      }
-
-      /* Calculate the table using the current 'adjust' */
-      for (i=0; i<=511; ++i)
-      {
-         double lo = 255 * sRGB(i << 15);
-         double hi = 255 * sRGB((i+1) << 15);
-         unsigned int calc;
-
-         calc = nearbyint((lo+adjust) * 256);
-         if (calc > 65535)
-         {
-            fprintf(stderr, "table[%d][0]: overflow %08x (%d)\n", i, calc,
-               calc);
-            exit(1);
-         }
-         png_sRGB_base[i] = calc;
-
-         calc = nearbyint((hi-lo) * 32);
-         if (calc > 255)
-         {
-            fprintf(stderr, "table[%d][1]: overflow %08x (%d)\n", i, calc,
-               calc);
-            exit(1);
-         }
-         png_sRGB_delta[i] = calc;
-      }
-
-      /* Check the 16-bit linear values alone: */
-      error_count16 = 0;
-      for (i16=0; i16 <= 65535; ++i16)
-      {
-         unsigned int i = 255*i16;
-         unsigned int iexact = nearbyint(255*sRGB(i));
-         unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);
-
-         if (icalc != iexact)
-            ++error_count16;
-      }
-
-      /* Now try changing the adjustment. */
-      if (ec_lo == 0)
-         ec_lo = error_count16;
-
-      else if (ec_hi == 0)
-         ec_hi = error_count16;
-
-      else if (ec_mid == 0)
-      {
-         ec_mid = error_count16;
-         printf("/* initial error counts: %u .. %u .. %u */\n", ec_lo, ec_mid,
-            ec_hi);
-      }
-
-      else if (error_count16 < ec_mid)
-      {
-         printf("/* adjust (mid ): %f: %u -> %u */\n", adjust, ec_mid,
-            error_count16);
-         ec_mid = error_count16;
-         adjust_mid = adjust;
-      }
-
-      else if (adjust < adjust_mid && error_count16 < ec_lo)
-      {
-         printf("/* adjust (low ): %f: %u -> %u */\n", adjust, ec_lo,
-            error_count16);
-         ec_lo = error_count16;
-         adjust_lo = adjust;
-      }
-
-      else if (adjust > adjust_mid && error_count16 < ec_hi)
-      {
-         printf("/* adjust (high): %f: %u -> %u */\n", adjust, ec_hi,
-            error_count16);
-         ec_hi = error_count16;
-         adjust_hi = adjust;
-      }
-
-      else
-      {
-         adjust = adjust_mid;
-         printf("/* adjust: %f: %u */\n", adjust, ec_mid);
-         break;
-      }
-   }
-
-   /* For each entry in the table try to adjust it to minimize the error count
-    * in that entry.  Each entry corresponds to 128 input values.
-    */
-   for (ibase=0; ibase<65536; ibase+=128)
-   {
-      png_uint_16 base = png_sRGB_base[ibase >> 7], trybase = base, ob=base;
-      png_byte delta = png_sRGB_delta[ibase >> 7], trydelta = delta, od=delta;
-      unsigned int ecbase = 0, eco;
-
-      for (;;)
-      {
-         png_sRGB_base[ibase >> 7] = trybase;
-         png_sRGB_delta[ibase >> 7] = trydelta;
-
-         /* Check the 16-bit linear values alone: */
-         error_count16 = 0;
-         for (i16=ibase; i16 < ibase+128; ++i16)
-         {
-            unsigned int i = 255*i16;
-            unsigned int iexact = nearbyint(255*sRGB(i));
-            unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);
-
-            if (icalc != iexact)
-               ++error_count16;
-         }
-
-         if (error_count16 == 0)
-            break;
-
-         if (ecbase == 0)
-         {
-            eco = ecbase = error_count16;
-            ++trybase; /* First test */
-         }
-
-         else if (error_count16 < ecbase)
-         {
-            if (trybase > base)
-            {
-               base = trybase;
-               ++trybase;
-            }
-            else if (trybase < base)
-            {
-               base = trybase;
-               --trybase;
-            }
-            else if (trydelta > delta)
-            {
-               delta = trydelta;
-               ++trydelta;
-            }
-            else if (trydelta < delta)
-            {
-               delta = trydelta;
-               --trydelta;
-            }
-            else
-            {
-               fprintf(stderr, "makesRGB: impossible\n");
-               exit(1);
-            }
-            ecbase = error_count16;
-         }
-
-         else
-         {
-            if (trybase > base)
-               trybase = base-1;
-            else if (trybase < base)
-            {
-               trybase = base;
-               ++trydelta;
-            }
-            else if (trydelta > delta)
-               trydelta = delta-1;
-            else if (trydelta < delta)
-               break; /* end of tests */
-         }
-      }
-
-      png_sRGB_base[ibase >> 7] = base;
-      png_sRGB_delta[ibase >> 7] = delta;
-      if (base != ob || delta != od)
-      {
-         printf("/* table[%u]={%u,%u} -> {%u,%u} %u -> %u errors */\n",
-            ibase>>7, ob, od, base, delta, eco, ecbase);
-      }
-      else if (0)
-         printf("/* table[%u]={%u,%u} %u errors */\n", ibase>>7, ob, od,
-            ecbase);
-   }
-
-   /* Only do the full (slow) test at the end: */
-   min_error = -.4999;
-   max_error = .4999;
-   error_count = 0;
-
-   for (i=0; i <= max_input; ++i)
-   {
-      unsigned int iexact = nearbyint(255*sRGB(i));
-      unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);
-
-      if (icalc != iexact)
-      {
-         double err = 255*sRGB(i) - icalc;
-
-         if (err > (max_error+.001) || err < (min_error-.001))
-         {
-            printf(
-               "/* 0x%08x: exact: %3d, got: %3d [tables: %08x, %08x] (%f) */\n",
-               i, iexact, icalc, png_sRGB_base[i>>15],
-               png_sRGB_delta[i>>15], err);
-         }
-
-         ++error_count;
-         if (err > max_error)
-            max_error = err;
-         else if (err < min_error)
-            min_error = err;
-      }
-   }
-
-   /* Re-check the 16-bit cases too, including the warning if there is an error
-    * bigger than 1.
-    */
-   error_count16 = 0;
-   max_error16 = 0;
-   min_error16 = 0;
-   for (i16=0; i16 <= 65535; ++i16)
-   {
-      unsigned int i = 255*i16;
-      unsigned int iexact = nearbyint(255*sRGB(i));
-      unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);
-
-      if (icalc != iexact)
-      {
-         double err = 255*sRGB(i) - icalc;
-
-         ++error_count16;
-         if (err > max_error16)
-            max_error16 = err;
-         else if (err < min_error16)
-            min_error16 = err;
-
-         if (abs(icalc - iexact) > 1)
-            printf(
-               "/* 0x%04x: exact: %3d, got: %3d [tables: %08x, %08x] (%f) */\n",
-               i16, iexact, icalc, png_sRGB_base[i>>15],
-               png_sRGB_delta[i>>15], err);
-      }
-   }
-
-   /* Check the round trip for each 8-bit sRGB value. */
-   for (i16=0; i16 <= 255; ++i16)
-   {
-      unsigned int i = 255 * png_sRGB_table[i16];
-      unsigned int iexact = nearbyint(255*sRGB(i));
-      unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);
-
-      if (i16 != iexact)
-      {
-         fprintf(stderr, "8-bit rounding error: %d -> %d\n", i16, iexact);
-         exit(1);
-      }
-
-      if (icalc != i16)
-      {
-         double finv = finvsRGB(i16);
-
-         printf("/* 8-bit roundtrip error: %d -> %f -> %d(%f) */\n",
-            i16, finv, icalc, fsRGB(255*finv));
-      }
-   }
-
-
-   printf("/* error: %g - %g, %u (%g%%) of readings inexact */\n",
-      min_error, max_error, error_count, (100.*error_count)/max_input);
-   printf("/* 16-bit error: %g - %g, %u (%g%%) of readings inexact */\n",
-      min_error16, max_error16, error_count16, (100.*error_count16)/65535);
-
-   if (!test_only)
-   {
-      printf("PNG_CONST png_uint_16 png_sRGB_table[256] =\n{\n   ");
-      for (i=0; i<255; )
-      {
-         do
-         {
-            printf("%d,", png_sRGB_table[i++]);
-         }
-         while ((i & 0x7) != 0 && i<255);
-         if (i<255) printf("\n   ");
-      }
-      printf("%d\n};\n\n", png_sRGB_table[i]);
-
-
-      printf("PNG_CONST png_uint_16 png_sRGB_base[512] =\n{\n   ");
-      for (i=0; i<511; )
-      {
-         do
-         {
-            printf("%d,", png_sRGB_base[i++]);
-         }
-         while ((i & 0x7) != 0 && i<511);
-         if (i<511) printf("\n   ");
-      }
-      printf("%d\n};\n\n", png_sRGB_base[i]);
-
-      printf("PNG_CONST png_byte png_sRGB_delta[512] =\n{\n   ");
-      for (i=0; i<511; )
-      {
-         do
-         {
-            printf("%d,", png_sRGB_delta[i++]);
-         }
-         while ((i & 0xf) != 0 && i<511);
-         if (i<511) printf("\n   ");
-      }
-      printf("%d\n};\n\n", png_sRGB_delta[i]);
-   }
-
-   return 0;
-}
diff --git a/contrib/sRGBtables/sRGB.h b/contrib/sRGBtables/sRGB.h
deleted file mode 100644
index ce28953..0000000
--- a/contrib/sRGBtables/sRGB.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * sRGB.h
- *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
- * Copyright (c) 2011 John Cunningham Bowler
- *
- * This code is released under the libpng license.
- * For conditions of distribution and use, see the disclaimer
- * and license in png.h
- *
- * Utility file; not actually a header, this contains definitions of sRGB
- * calculation functions for inclusion in those test programs that need them.
- *
- * All routines take and return a floating point value in the range
- * 0 to 1.0, doing a calculation according to the sRGB specification
- * (in fact the source of the numbers is the wikipedia article at
- * http://en.wikipedia.org/wiki/SRGB).
- */
-static double
-sRGB_from_linear(double l)
-{
-   if (l <= 0.0031308)
-      l *= 12.92;
-
-   else
-      l = 1.055 * pow(l, 1/2.4) - 0.055;
-
-   return l;
-}
-
-static double
-linear_from_sRGB(double s)
-{
-   if (s <= 0.04045)
-      return s / 12.92;
-
-   else
-      return pow((s+0.055)/1.055, 2.4);
-}
-
-static double
-YfromRGB(double r, double g, double b)
-{
-   /* Use the sRGB (rounded) coefficients for Rlinear, Glinear, Blinear to get
-    * the CIE Y value (also linear).
-    */
-   return 0.2126 * r + 0.7152 * g + 0.0722 * b;
-}
diff --git a/libpng-manual.txt b/libpng-manual.txt
index 4c6e115..3994b6f 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.5.7beta05 - November 21, 2011
+ libpng version 1.5.7beta05 - November 23, 2011
  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.5.7beta05 - November 21, 2011
+ libpng versions 0.97, January 1998, through 1.5.7beta05 - November 23, 2011
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2011 Glenn Randers-Pehrson
 
@@ -4573,7 +4573,7 @@
 
 XIV. Y2K Compliance in libpng
 
-November 21, 2011
+November 23, 2011
 
 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 3375e83..c0eb1e9 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,4 +1,4 @@
-.TH LIBPNG 3 "November 21, 2011"
+.TH LIBPNG 3 "November 23, 2011"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.5.7beta05
 .SH SYNOPSIS
@@ -8,36 +8,6 @@
 
 \fI\fB
 
-\fBint \fP\fIpng_image_begin_read_from_file\fP\fB, (png_imagep \fIimage,
-
-\fBconst char \fI*file_name)\fP\fB);\fP
-
-\fBint \fP\fIpng_image_begin_read_from_stdio\fP\fB, (png_imagep \fIimage,
-
-\fBFILE* \fIfile)\fP\fB);\fP
-
-\fBint, \fP\fIpng_image_begin_read_from_memory\fP\fB, (png_imagep \fIimage,
-
-\fBpng_const_voidp \fP\fImemory\fP\fB, png_size_t \fIsize)\fP\fB);\fP
-
-\fBint \fP\fIpng_image_finish_read\fP\fB, (png_imagep \fIimage,
-
-\fBpng_colorp \fP\fIbackground\fP\fB, void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride)\fP\fB);\fP
-
-\fBvoid \fP\fIpng_image_free\fP\fB, (png_imagep \fIimage)\fP\fB);\fP
-
-\fBint \fP\fIpng_image_write_to_file\fP\fB, (png_imagep \fIimage,
-
-\fBconst char \fP\fI*file\fP\fB, int \fP\fIconvert_to_8bit\fP\fB, const void \fI*buffer,
-
-\fBpng_int_32 \fIrow_stride)\fP\fB);\fP
-
-\fBint \fP\fIpng_image_write_to_stdio\fP\fB, (png_imagep \fP\fIimage\fP\fB, FILE \fI*file,
-
-\fBint \fP\fIconvert_to_8_bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride)\fP\fB);\fP
-
-\fI\fB
-
 \fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
 
 \fI\fB
@@ -462,36 +432,6 @@
 
 \fI\fB
 
-\fBint png_image_begin_read_from_file (png_imagep \fP\fIimage\fP\fB, const char \fI*file_name\fP\fB);\fP
-
-\fI\fB
-
-\fBint png_image_begin_read_from_stdio (png_imagep \fP\fIimage\fP\fB, FILE* \fIfile\fP\fB);\fP
-
-\fI\fB
-
-\fBint, png_image_begin_read_from_memory (png_imagep \fP\fIimage\fP\fB, png_const_voidp \fP\fImemory\fP\fB, png_size_t \fIsize\fP\fB);\fP
-
-\fI\fB
-
-\fBint png_image_finish_read (png_imagep \fP\fIimage\fP\fB, png_colorp \fP\fIbackground\fP\fB, void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_image_free (png_imagep \fIimage\fP\fB);\fP
-
-\fI\fB
-
-\fBint png_image_write_to_file (png_imagep \fP\fIimage\fP\fB, const char \fP\fI*file\fP\fB, int \fP\fIconvert_to_8bit\fP\fB, const void \fI*buffer,
-
-\fBpng_int_32 \fIrow_stride\fP\fB);\fP
-
-\fI\fB
-
-\fBint png_image_write_to_stdio (png_imagep \fP\fIimage\fP\fB, FILE \fP\fI*file\fP\fB, int \fP\fIconvert_to_8_bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride)\fP\fB);\fP
-
-\fI\fB
-
 \fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
 
 \fI\fB
@@ -1037,7 +977,7 @@
 .SH LIBPNG.TXT
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.5.7beta05 - November 21, 2011
+ libpng version 1.5.7beta05 - November 23, 2011
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2011 Glenn Randers-Pehrson
@@ -1048,7 +988,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.5.7beta05 - November 21, 2011
+ libpng versions 0.97, January 1998, through 1.5.7beta05 - November 23, 2011
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2011 Glenn Randers-Pehrson
 
@@ -5611,7 +5551,7 @@
 
 .SH XIV. Y2K Compliance in libpng
 
-November 21, 2011
+November 23, 2011
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
@@ -5876,7 +5816,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.5.7beta05 - November 21, 2011:
+Libpng version 1.5.7beta05 - November 23, 2011:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
 
@@ -5899,7 +5839,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.5.7beta05, November 21, 2011, are
+libpng versions 1.2.6, August 15, 2004, through 1.5.7beta05, November 23, 2011, 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
@@ -5998,7 +5938,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-November 21, 2011
+November 23, 2011
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index 092eeb8..2c41079 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "November 18, 2011"
+.TH LIBPNGPF 3 "November 23, 2011"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library 1.5.7beta05
 (private functions)
diff --git a/png.5 b/png.5
index ca03f81..3375375 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "November 18, 2011"
+.TH PNG 5 "November 23, 2011"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 469351d..d919161 100644
--- a/png.c
+++ b/png.c
@@ -655,13 +655,13 @@
 #else
 #  ifdef __STDC__
    return PNG_STRING_NEWLINE \
-     "libpng version 1.5.7beta05 - November 19, 2011" PNG_STRING_NEWLINE \
+     "libpng version 1.5.7beta05 - November 23, 2011" PNG_STRING_NEWLINE \
      "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
      "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
      "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
      PNG_STRING_NEWLINE;
 #  else
-      return "libpng version 1.5.7beta05 - November 19, 2011\
+      return "libpng version 1.5.7beta05 - November 23, 2011\
       Copyright (c) 1998-2011 Glenn Randers-Pehrson\
       Copyright (c) 1996-1997 Andreas Dilger\
       Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -2864,262 +2864,4 @@
   }
 }
 #endif /* READ_GAMMA */
-
-/* sRGB support */
-#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
-   defined PNG_SIMPLIFIED_WRITE_SUPPORTED
-/* sRGB conversion tables; these are machine generated with the code in
- * contrib/sRGBtables/makesRGB.c.  The sRGB to linear table is exact (to the
- * nearest 16 bit linear fraction).  The inverse (linear to sRGB) table has
- * accuracies as follows:
- *
- * For all possible (255*65535+1) input values:
- *
- *    error: -0.515566 - 0.625971, 79441 (0.475369%) of readings inexact
- *
- * For the input values corresponding to the 65536 16-bit values:
- *
- *    error: -0.513727 - 0.607759, 308 (0.469978%) of readings inexact
- *
- * In all cases the inexact readings are off by one.
- */
-
-#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
-/* The convert-to-sRGB table is only currently required for read. */
-PNG_CONST_DATA png_uint_16 png_sRGB_table[256] =
-{
-   0,20,40,60,80,99,119,139,
-   159,179,199,219,241,264,288,313,
-   340,367,396,427,458,491,526,562,
-   599,637,677,718,761,805,851,898,
-   947,997,1048,1101,1156,1212,1270,1330,
-   1391,1453,1517,1583,1651,1720,1790,1863,
-   1937,2013,2090,2170,2250,2333,2418,2504,
-   2592,2681,2773,2866,2961,3058,3157,3258,
-   3360,3464,3570,3678,3788,3900,4014,4129,
-   4247,4366,4488,4611,4736,4864,4993,5124,
-   5257,5392,5530,5669,5810,5953,6099,6246,
-   6395,6547,6700,6856,7014,7174,7335,7500,
-   7666,7834,8004,8177,8352,8528,8708,8889,
-   9072,9258,9445,9635,9828,10022,10219,10417,
-   10619,10822,11028,11235,11446,11658,11873,12090,
-   12309,12530,12754,12980,13209,13440,13673,13909,
-   14146,14387,14629,14874,15122,15371,15623,15878,
-   16135,16394,16656,16920,17187,17456,17727,18001,
-   18277,18556,18837,19121,19407,19696,19987,20281,
-   20577,20876,21177,21481,21787,22096,22407,22721,
-   23038,23357,23678,24002,24329,24658,24990,25325,
-   25662,26001,26344,26688,27036,27386,27739,28094,
-   28452,28813,29176,29542,29911,30282,30656,31033,
-   31412,31794,32179,32567,32957,33350,33745,34143,
-   34544,34948,35355,35764,36176,36591,37008,37429,
-   37852,38278,38706,39138,39572,40009,40449,40891,
-   41337,41785,42236,42690,43147,43606,44069,44534,
-   45002,45473,45947,46423,46903,47385,47871,48359,
-   48850,49344,49841,50341,50844,51349,51858,52369,
-   52884,53401,53921,54445,54971,55500,56032,56567,
-   57105,57646,58190,58737,59287,59840,60396,60955,
-   61517,62082,62650,63221,63795,64372,64952,65535
-};
-
-#endif /* simplified read only */
-
-/* The base/delta tables are required for both read and write (but currently
- * only the simplified versions.)
- */
-PNG_CONST_DATA png_uint_16 png_sRGB_base[512] =
-{
-   128,1782,3383,4644,5675,6564,7357,8074,
-   8732,9346,9921,10463,10977,11466,11935,12384,
-   12816,13233,13634,14024,14402,14769,15125,15473,
-   15812,16142,16466,16781,17090,17393,17690,17981,
-   18266,18546,18822,19093,19359,19621,19879,20133,
-   20383,20630,20873,21113,21349,21583,21813,22041,
-   22265,22487,22707,22923,23138,23350,23559,23767,
-   23972,24175,24376,24575,24772,24967,25160,25352,
-   25542,25730,25916,26101,26284,26465,26645,26823,
-   27000,27176,27350,27523,27695,27865,28034,28201,
-   28368,28533,28697,28860,29021,29182,29341,29500,
-   29657,29813,29969,30123,30276,30429,30580,30730,
-   30880,31028,31176,31323,31469,31614,31758,31902,
-   32045,32186,32327,32468,32607,32746,32884,33021,
-   33158,33294,33429,33564,33697,33831,33963,34095,
-   34226,34357,34486,34616,34744,34873,35000,35127,
-   35253,35379,35504,35629,35753,35876,35999,36122,
-   36244,36365,36486,36606,36726,36845,36964,37083,
-   37201,37318,37435,37551,37668,37783,37898,38013,
-   38127,38241,38354,38467,38580,38692,38803,38915,
-   39026,39136,39246,39356,39465,39574,39682,39790,
-   39898,40005,40112,40219,40325,40431,40537,40642,
-   40747,40851,40955,41059,41163,41266,41369,41471,
-   41573,41675,41777,41878,41979,42079,42179,42279,
-   42379,42478,42577,42676,42775,42873,42971,43068,
-   43165,43262,43359,43456,43552,43648,43743,43839,
-   43934,44028,44123,44217,44311,44405,44499,44592,
-   44685,44778,44870,44962,45054,45146,45238,45329,
-   45420,45511,45601,45692,45782,45872,45961,46051,
-   46140,46229,46318,46406,46494,46583,46670,46758,
-   46846,46933,47020,47107,47193,47280,47366,47452,
-   47538,47623,47709,47794,47879,47964,48048,48133,
-   48217,48301,48385,48468,48552,48635,48718,48801,
-   48884,48966,49048,49131,49213,49294,49376,49458,
-   49539,49620,49701,49782,49862,49943,50023,50103,
-   50183,50263,50342,50422,50501,50580,50659,50738,
-   50816,50895,50973,51051,51129,51207,51285,51362,
-   51439,51517,51594,51671,51747,51824,51900,51977,
-   52053,52129,52205,52280,52356,52432,52507,52582,
-   52657,52732,52807,52881,52956,53030,53104,53178,
-   53252,53326,53400,53473,53546,53620,53693,53766,
-   53839,53911,53984,54056,54129,54201,54273,54345,
-   54417,54489,54560,54632,54703,54774,54845,54916,
-   54987,55058,55129,55199,55269,55340,55410,55480,
-   55550,55620,55689,55759,55828,55898,55967,56036,
-   56105,56174,56243,56311,56380,56448,56517,56585,
-   56653,56721,56789,56857,56924,56992,57059,57127,
-   57194,57261,57328,57395,57462,57529,57595,57662,
-   57728,57795,57861,57927,57993,58059,58125,58191,
-   58256,58322,58387,58453,58518,58583,58648,58713,
-   58778,58843,58908,58972,59037,59101,59165,59230,
-   59294,59358,59422,59486,59549,59613,59677,59740,
-   59804,59867,59930,59993,60056,60119,60182,60245,
-   60308,60370,60433,60495,60558,60620,60682,60744,
-   60806,60868,60930,60992,61054,61115,61177,61238,
-   61300,61361,61422,61483,61544,61605,61666,61727,
-   61788,61848,61909,61969,62030,62090,62150,62211,
-   62271,62331,62391,62450,62510,62570,62630,62689,
-   62749,62808,62867,62927,62986,63045,63104,63163,
-   63222,63281,63340,63398,63457,63515,63574,63632,
-   63691,63749,63807,63865,63923,63981,64039,64097,
-   64155,64212,64270,64328,64385,64443,64500,64557,
-   64614,64672,64729,64786,64843,64900,64956,65013,
-   65070,65126,65183,65239,65296,65352,65409,65465
-};
-
-PNG_CONST_DATA png_byte png_sRGB_delta[512] =
-{
-   207,201,158,129,113,100,90,82,77,72,68,64,61,59,56,54,
-   52,50,49,47,46,45,43,42,41,40,39,39,38,37,36,36,
-   35,34,34,33,33,32,32,31,31,30,30,30,29,29,28,28,
-   28,27,27,27,27,26,26,26,25,25,25,25,24,24,24,24,
-   23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,
-   21,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19,
-   19,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,
-   17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
-   16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,
-   15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,
-   14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,
-   13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,
-   12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
-   12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,
-   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
-   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
-   11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
-   10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
-   10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
-   10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
-   9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
-   9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
-   9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
-   9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
-   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
-   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
-   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
-   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
-   8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,
-   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-#endif /* SIMPLIFIED READ/WRITE sRGB support */
-
-/* SIMPLIFIED READ/WRITE SUPPORT */
-#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
-   defined PNG_SIMPLIFIED_WRITE_SUPPORTED
-static int
-png_image_free_function(png_voidp argument)
-{
-   png_imagep image = png_voidcast(png_imagep, argument);
-   png_controlp cp = image->opaque;
-   png_control c;
-
-   /* Double check that we have a png_ptr - it should be impossible to get here
-    * without one.
-    */
-   if (cp->png_ptr == NULL)
-      return 0;
-
-   /* First free any data held in the control structure. */
-#  ifdef PNG_STDIO_SUPPORTED
-      if (cp->owned_file)
-      {
-         FILE *fp = png_voidcast(FILE*, cp->png_ptr->io_ptr);
-         cp->owned_file = 0;
-
-         /* Ignore errors here. */
-         if (fp != NULL)
-         {
-            cp->png_ptr->io_ptr = NULL;
-            (void)fclose(fp);
-         }
-      }
-#  endif
-
-   /* Copy the control structure so that the original, allocated, version can be
-    * safely freed.  Notice that a png_error here stops the remainder of the
-    * cleanup, but this is probably fine because that would indicate bad memory
-    * problems anyway.
-    */
-   c = *cp;
-   image->opaque = &c;
-   png_free(c.png_ptr, cp);
-
-   /* Then the structures, calling the correct API. */
-   if (c.for_write)
-   {
-#     ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
-         png_destroy_write_struct(&c.png_ptr, &c.info_ptr);
-#     else
-         png_error(c.png_ptr, "simplified write not supported");
-#     endif
-   }
-   else
-   {
-#     ifdef PNG_SIMPLIFIED_READ_SUPPORTED
-         png_destroy_read_struct(&c.png_ptr, &c.info_ptr, NULL);
-#     else
-         png_error(c.png_ptr, "simplified read not supported");
-#     endif
-   }
-
-   /* Success. */
-   return 1;
-}
-
-void PNGAPI
-png_image_free(png_imagep image)
-{
-   /* Safely call the real function, but only if doing so is safe at this point
-    * (if not inside an error handling context).  Otherwise assume
-    * png_safe_execute will call this API after the return.
-    */
-   if (image != NULL && image->opaque != NULL &&
-      image->opaque->error_buf == NULL)
-   {
-      /* Ignore errors here: */
-      (void)png_safe_execute(image, png_image_free_function, image);
-      image->opaque = NULL;
-   }
-}
-
-int /* PRIVATE */
-png_image_error(png_imagep image, png_const_charp error_message)
-{
-   /* Utility to log an error. */
-   png_safecat(image->message, sizeof image->message, 0, error_message);
-   image->warning_or_error = 1;
-   png_image_free(image);
-   return 0;
-}
-
-#endif /* SIMPLIFIED READ/WRITE */
 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
diff --git a/png.h b/png.h
index bcb5610..4386b73 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.5.7beta05 - November 22, 2011
+ * libpng version 1.5.7beta05 - November 23, 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.)
@@ -11,7 +11,7 @@
  * Authors and maintainers:
  *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  *   libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
- *   libpng versions 0.97, January 1998, through 1.5.7beta05 - November 22, 2011: Glenn
+ *   libpng versions 0.97, January 1998, through 1.5.7beta05 - November 23, 2011: Glenn
  *   See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -195,7 +195,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.5.7beta05, November 22, 2011, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.5.7beta05, November 23, 2011, are
  * Copyright (c) 2004, 2006-2011 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:
@@ -307,7 +307,7 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    November 22, 2011
+ *    November 23, 2011
  *
  *    Since the PNG Development group is an ad-hoc body, we can't make
  *    an official declaration.
@@ -373,7 +373,7 @@
 /* Version information for png.h - this should match the version in png.c */
 #define PNG_LIBPNG_VER_STRING "1.5.7beta05"
 #define PNG_HEADER_VERSION_STRING \
-     " libpng version 1.5.7beta05 - November 22, 2011\n"
+     " libpng version 1.5.7beta05 - November 23, 2011\n"
 
 #define PNG_LIBPNG_VER_SONUM   15
 #define PNG_LIBPNG_VER_DLLNUM  15
@@ -491,7 +491,6 @@
  * 2. Type definitions (base types are defined in pngconf.h), structure
  *    definitions.
  * 3. Exported library functions.
- * 4. Simplified API.
  *
  * The library source code has additional files (principally pngpriv.h) that
  * allow configuration of the library.
@@ -2629,296 +2628,6 @@
       : (png_int_32)png_get_uint_32(buf)))
 #endif
 
-/*******************************************************************************
- *  SIMPLIFIED API
- *******************************************************************************
- *
- * Please read the documentation in libpng-manual.txt if you don't understand
- * what follows.
- *
- * The simplified API hides the details of both libpng and the PNG file format
- * itself.  It allows PNG files to be read into a very limited number of
- * in-memory bitmap formats or to be written from the same formats.  If these
- * formats do not accomodate your needs then you can, and should, use the more
- * sophisticated APIs above - these support a wide variety of in-memory formats
- * and a wide variety of sophisticated transformations to those formats as well
- * as a wide variety of APIs to manipulate ancilliary information.
- *
- * To read a PNG file using the simplified API:
- *
- * 1) Declare a 'png_image' structure (see below) on the stack and memset() it
- * to all zero.
- * 2) Call the appropriate png_image_begin_read... function.
- * 3) Set the png_image 'format' member to the required format and allocate a
- * buffer for the image.
- * 4) Call png_image_finish_read to read the image into your buffer.
- *
- * There are no restrictions on the format of the PNG input itself; all valid
- * color types, bit depths, and interlace methods are acceptable, and the
- * input image is transformed as necessary to the requested in-memory format
- * during the png_image_finish_read() step.
- *
- * To write a PNG file using the simplified API:
- *
- * 1) Declare a 'png_image' structure on the stack and memset() it to all zero.
- * 2) Initialize the members of the structure that describe the image, setting
- * the 'format' member to the format of the image in memory.
- * 3) Call the appropriate png_image_write... function with a pointer to the
- * image to write the PNG data.
- *
- * png_image is a structure that describes the in-memory format of an image
- * when it is being read or define the in-memory format of an image that you
- * need to write:
- *
- */
-
-typedef struct png_control *png_controlp;
-typedef struct
-{
-   png_uint_32  width;  /* Image width in pixels (columns) */
-   png_uint_32  height; /* Image height in pixels (rows) */
-   png_uint_32  format; /* Image format as defined below */
-   png_uint_32  flags;  /* A bit mask containing informational flags */
-   png_controlp opaque; /* Initialize to NULL, free with png_image_free */
-
-   /* In the event of an error or warning the following field will be set to a
-    * non-zero value and the 'message' field will contain a '\0' terminated
-    * string with the libpng error or warning message.  If both warnings and
-    * an error were encountered, only the error is recorded.  If there
-    * are multiple warnings, only the first one is recorded.
-    *
-    * As of libpng-1.5.7 the values are
-    *    0 - no warning or error
-    *    1 - error
-    *    2 - warning
-    */
-   png_uint_32  warning_or_error;
-   char         message[64];
-} png_image, *png_imagep;
-
-/* The pixels (samples) of the image have one to four channels whose components
- * have original values in the range 0 to 1.0:
- *
- * 1: A single gray or luminance channel (G).
- * 2: A gray/luminance channel and an alpha channel (GA).
- * 3: Three red, green, blue color channels (RGB).
- * 4: Three color channels and an alpha channel (RGBA).
- *
- * The channels are encoded in one of two ways:
- *
- * a) As a small integer, value 0..255, contained in a (png_byte).  For the
- * alpha channel the original value is simply value/255.  For the color or
- * luminance channels the value is encoded according to the sRGB specification
- * and matches the 8-bit format expected by typical display devices.
- *
- *    The color/gray channels are not scaled (pre-multiplied) by the alpha
- * channel and are suitable for passing to color management software.
- *
- * b) As a value in the range 0..65535, contained in a (png_uint_16).  All
- * channels can be converted to the original value by dividing by 65535; all
- * channels are linear.  Color channels use the RGB encoding (RGB end-points) of
- * the sRGB specification.  This encoding is identified by the
- * PNG_FORMAT_FLAG_LINEAR flag below.
- *
- *    When an alpha channel is present it is expected to denote pixel coverage
- * of the color or luminance channels and is returned as an associated alpha
- * channel: the color/gray channels are scaled (pre-multiplied) by the alpha
- * value.
- */
-
-/* PNG_FORMAT_*
- *
- * #defines to be used in png_image::format.  Each #define identifies a
- * particular layout of channel data and, if present, alpha values.  There are
- * separate defines for each of the two channel encodings.
- *
- * A format is built up using single bit flag values.  Not all combinations are
- * valid: use the bit flag values below for testing a format returned by the
- * read APIs, but set formats from the derived values.
- *
- * NOTE: libpng can be built with particular features disabled, if you see
- * compiler errors because the definition of one of the following flags has been
- * compiled out it is because libpng does not have the required support.  It is
- * possible, however, for the libpng configuration to enable the format on just
- * read or just write; in that case you may see an error at run time.  You can
- * guard against this by checking for the definition of:
- *
- *    PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED
- */
-#define PNG_FORMAT_FLAG_ALPHA    0x01 /* format with an alpha channel */
-#define PNG_FORMAT_FLAG_COLOR    0x02 /* color format: otherwise grayscale */
-#define PNG_FORMAT_FLAG_LINEAR   0x04 /* png_uint_16 channels else png_byte */
-
-#ifdef PNG_FORMAT_BGR_SUPPORTED
-#  define PNG_FORMAT_FLAG_BGR    0x08 /* BGR colors, else order is RGB */
-#endif
-
-#ifdef PNG_FORMAT_AFIRST_SUPPORTED
-#  define PNG_FORMAT_FLAG_AFIRST 0x10 /* alpha channel comes first */
-#endif
-
-/* Supported formats are as follows.  Future versions of libpng may support more
- * formats; for compatibility with older versions simply check if the format
- * macro is defined using #ifdef.  These defines describe the in-memory layout
- * of the components of the pixels of the image.
- *
- * First the single byte formats:
- */
-#define PNG_FORMAT_GRAY 0
-#define PNG_FORMAT_GA   PNG_FORMAT_FLAG_ALPHA
-#define PNG_FORMAT_AG   (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)
-#define PNG_FORMAT_RGB  PNG_FORMAT_FLAG_COLOR
-#define PNG_FORMAT_BGR  (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)
-#define PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)
-#define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)
-#define PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)
-#define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)
-
-/* Then the linear (png_uint_16) formats.  When naming these "Y" is used to
- * indicate a luminance (gray) channel.  The component order within the pixel
- * is always the same - there is no provision for swapping the order of the
- * components in the linear format.
- */
-#define PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR
-#define PNG_FORMAT_LINEAR_Y_ALPHA (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)
-#define PNG_FORMAT_LINEAR_RGB (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)
-#define PNG_FORMAT_LINEAR_RGB_ALPHA \
-   (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA)
-
-/* PNG_IMAGE macros
- *
- * These are convenience macros to derive information from a png_image structure
- */
-#define PNG_IMAGE_CHANNELS(fmt)\
-   (1+((fmt)&(PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA)))
-   /* Return the total number of channels in a given format: 1..4 */
-
-#define PNG_IMAGE_COMPONENT_SIZE(fmt)\
-   (((fmt) & PNG_FORMAT_FLAG_LINEAR) ? sizeof (png_uint_16) : sizeof (png_byte))
-   /* Return the size in bytes of a single component of a pixel in the image. */
-
-#define PNG_IMAGE_PIXEL_SIZE(fmt)\
-   (PNG_IMAGE_CHANNELS(fmt) * PNG_IMAGE_COMPONENT_SIZE(fmt))
-   /* Return the size in bytes of a single pixel in the image. */
-   
-#define PNG_IMAGE_ROW_STRIDE(image)\
-   (PNG_IMAGE_CHANNELS((image).format) * (image).width)
-   /* Return the total number of components in a single row of the image; this
-    * is the minimum 'row stride', the minimum count of components between each
-    * row.
-    */
-
-#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\
-   (PNG_IMAGE_COMPONENT_SIZE((image).format) * (image).height * (row_stride))
-   /* Return the size, in bytes, of an image buffer given a png_image and a row
-    * stride - the number of components to leave space for in each row.
-    */
-
-#define PNG_IMAGE_SIZE(image)\
-   PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image))
-   /* Return the size, in bytes, of the image in memory given just a png_image;
-    * the row stride is the minimum stride required for the image.
-    */
-
-/* PNG_IMAGE_FLAG_*
- *
- * Flags containing additional information about the image are held in the
- * 'flags' field of png_image.
- */
-#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 1
-   /* This indicates the the RGB values of the in-memory bitmap do not
-    * correspond to the red, green and blue end-points defined by sRGB.
-    */
-
-#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
-/* READ APIs
- * ---------
- *
- * The png_image passed to the read APIs must have been initialized by setting
- * the png_controlp field 'opaque' to NULL (or, better, memset the whole thing.)
- */
-#ifdef PNG_STDIO_SUPPORTED
-PNG_EXPORT(234, int, png_image_begin_read_from_file, (png_imagep image,
-   const char *file_name));
-   /* The named file is opened for read and the image header is filled in
-    * from the PNG header in the file.
-    */
-
-PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image,
-   FILE* file));
-   /* The PNG header is read from the stdio FILE object. */
-#endif /* PNG_STDIO_SUPPORTED */
-
-PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image,
-   png_const_voidp memory, png_size_t size));
-   /* The PNG header is read from the given memory buffer. */
-
-PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image,
-   png_colorp background, void *buffer, png_int_32 row_stride));
-   /* Finish reading the image into the supplied buffer and clean up the
-    * png_image structure.
-    *
-    * row_stride is the step, in png_byte or png_uint_16 units as appropriate,
-    * between adjacent rows.  A positive stride indicates that the top-most row
-    * is first in the buffer - the normal top-down arrangement.  A negative
-    * stride indicates that the bottom-most row is first in the buffer.
-    *
-    * background need only be supplied if an alpha channel must be removed from
-    * a png_byte format and the removal is to be done by compositing on a solid
-    * color; otherwise it may be NULL and any composition will be done directly
-    * onto the buffer.  The value is an sRGB color to use for the background,
-    * for grayscale output the green channel is used.
-    *
-    * For linear output removing the alpha channel is always done by compositing
-    * on black.
-    */
-
-PNG_EXPORT(238, void, png_image_free, (png_imagep image));
-   /* Free any data allocated by libpng in image->opaque, setting the pointer to
-    * NULL.  May be called at any time after the structure is initialized.
-    */
-#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */
-
-#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
-/* WRITE APIS
- * ----------
- * For write you must initialize a png_image structure to describe the image to
- * be written:
- *
- * opaque: must be initialized to NULL
- * width: image width in pixels
- * height: image height in rows
- * format: the format of the data you wish to write
- * flags: set to 0 unless one of the defined flags applies; set
- *    PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB
- *    values do not correspond to the colors in sRGB.
- */
-PNG_EXPORT(239, int, png_image_write_to_file, (png_imagep image,
-   const char *file, int convert_to_8bit, const void *buffer,
-   png_int_32 row_stride));
-   /* Write the image to the named file. */
-
-PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file,
-   int convert_to_8_bit, const void *buffer, png_int_32 row_stride));
-   /* Write the image to the given (FILE*). */
-
-/* With all write APIs if image is in one of the linear formats with
- * (png_uint_16) data then setting convert_to_8_bit will cause the output to be
- * a (png_byte) PNG gamma encoded according to the sRGB specification, otherwise
- * a 16-bit linear encoded PNG file is written.
- *
- * With all APIs row_stride is handled as in the read APIs - it is the spacing
- * from one row to the next in component sized units (float) and if negative
- * indicates a bottom-up row layout in the buffer.
- *
- * Note that the write API does not support interlacing, sub-8-bit pixels,
- * and indexed (paletted) images.
- */
-#endif /* PNG_SIMPLIFIED_WRITE_SUPPORTED */
-/*******************************************************************************
- *  END OF SIMPLIFIED API
- ******************************************************************************/
-
 /* Maintainer: Put new public prototypes here ^, in libpng.3, and project
  * defs
  */
@@ -2928,7 +2637,7 @@
  * scripts/symbols.def as well.
  */
 #ifdef PNG_EXPORT_LAST_ORDINAL
-  PNG_EXPORT_LAST_ORDINAL(240);
+  PNG_EXPORT_LAST_ORDINAL(233);
 #endif
 
 #ifdef __cplusplus
diff --git a/pngconf.h b/pngconf.h
index d274772..3b6706c 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.5.7beta05 - November 18, 2011
+ * libpng version 1.5.7beta05 - November 23, 2011
  *
  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngerror.c b/pngerror.c
index d09bcba..c287655 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -673,87 +673,4 @@
    }
 }
 #endif
-
-#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
-   defined PNG_SIMPLIFIED_WRITE_SUPPORTED
-   /* Currently the above both depend on SETJMP_SUPPORTED, however it would be
-    * possible to implement without setjmp support just so long as there is some
-    * way to handle the error return here:
-    */
-PNG_FUNCTION(void /* PRIVATE */,
-png_safe_error,(png_structp png_ptr, png_const_charp error_message),
-   PNG_NORETURN)
-{
-   png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
-
-   /* An error is always logged here, overwriting anything (typically a warning)
-    * that is already there:
-    */
-   if (image != NULL)
-   {
-      png_safecat(image->message, sizeof image->message, 0, error_message);
-      image->warning_or_error = 1;
-
-      /* Retrieve the jmp_buf from within the png_control, making this work for
-       * C++ compilation too is pretty tricky: C++ wants a pointer to the first
-       * element of a jmp_buf, but C doesn't tell us the type of that.
-       */
-      if (image->opaque != NULL && image->opaque->error_buf != NULL)
-         longjmp(png_control_jmp_buf(image->opaque), 1);
-
-      /* Missing longjmp buffer, the following is to help debugging: */
-      {
-         size_t pos = png_safecat(image->message, sizeof image->message, 0,
-            "bad longjmp: ");
-         png_safecat(image->message, sizeof image->message, pos, error_message);
-      }
-   }
-
-   /* Here on an internal programming error. */
-   abort();
-}
-
-#ifdef PNG_WARNINGS_SUPPORTED
-void /* PRIVATE */
-png_safe_warning(png_structp png_ptr, png_const_charp warning_message)
-{
-   png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
-
-   /* A warning is only logged if there is no prior warning or error. */
-   if (image->warning_or_error == 0)
-   {
-      png_safecat(image->message, sizeof image->message, 0, warning_message);
-      image->warning_or_error = 2;
-   }
-}
-#endif
-
-int /* PRIVATE */
-png_safe_execute(png_imagep imageIn, int (*function)(png_voidp), png_voidp arg)
-{
-   volatile png_imagep image = imageIn;
-   volatile int result;
-   volatile png_voidp saved_error_buf;
-   jmp_buf safe_jmpbuf;
-
-   /* Safely execute function(arg) with png_error returning to this function. */
-   saved_error_buf = image->opaque->error_buf;
-   result = setjmp(safe_jmpbuf) == 0;
-
-   if (result)
-   {
-
-      image->opaque->error_buf = safe_jmpbuf;
-      result = function(arg);
-   }
-
-   image->opaque->error_buf = saved_error_buf;
-
-   /* And do the cleanup prior to any failure return. */
-   if (!result)
-      png_image_free(image);
-
-   return result;
-}
-#endif /* SIMPLIFIED READ/WRITE */
 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/pngpriv.h b/pngpriv.h
index 09f6892..2fdf09b 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -258,26 +258,6 @@
 #  define PNG_EXTERN extern
 #endif
 
-#ifndef PNG_CONST_DATA
-/* Some compilers fail if given an "extern const" data declaration followed by a
- * "const" definition, therefore declaring const data in pngpriv.h is
- * impossible, the following allows a work-round for the problematic compilers
- * by defining -DPNG_NO_CONST_DATA on the command line (notice that this does
- * not affect static const definitions, where there is no declaration.)
- */
-#  ifndef PNG_NO_CONST_DATA
-      /* List of compilers where "extern const" is known to be OK: */
-#     if defined __GNUC__ || defined _MSC_VER || defined __WATCOMC__
-#        define PNG_CONST_DATA const
-#     endif
-#  endif
-
-   /* Default to disabling const data declarations: */
-#  ifndef PNG_CONST_DATA
-#     define PNG_CONST_DATA /*const*/
-#  endif
-#endif
-
 /* Some fixed point APIs are still required even if not exported because
  * they get used by the corresponding floating point APIs.  This magic
  * deals with this:
@@ -548,26 +528,6 @@
    abs((int)((c1).green) - (int)((c2).green)) + \
    abs((int)((c1).blue) - (int)((c2).blue)))
 
-/* Added to libpng-1.5.7: sRGB conversion tables */
-#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
-   defined PNG_SIMPLIFIED_WRITE_SUPPORTED
-#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
-extern /*PRIVATE*/ PNG_CONST_DATA png_uint_16 png_sRGB_table[256];
-   /* Convert from an sRGB encoded value 0..255 to a 16-bit linear value,
-    * 0..65535.  This table gives the closes 16-bit answers (no errors).
-    */
-#endif
-
-extern /*PRIVATE*/ PNG_CONST_DATA png_uint_16 png_sRGB_base[512];
-extern /*PRIVATE*/ PNG_CONST_DATA png_byte png_sRGB_delta[512];
-
-#define PNG_sRGB_FROM_LINEAR(linear) ((png_sRGB_base[(linear)>>15] +\
-   ((((linear)&0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8)
-   /* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB
-    * encoded value with maximum error 0.646365.  Note that the input is not a
-    * 16-bit value; it has been multiplied by 255! */
-#endif /* PNG_SIMPLIFIED_READ/WRITE */
-
 /* Added to libpng-1.2.6 JB */
 #define PNG_ROWBYTES(pixel_bits, width) \
     ((pixel_bits) >= 8 ? \
@@ -1658,59 +1618,8 @@
     int bit_depth));
 #endif
 
-/* SIMPLIFIED READ/WRITE SUPPORT */
-#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
-   defined PNG_SIMPLIFIED_WRITE_SUPPORTED
-/* The internal structure that png_image::opaque points to. */
-typedef struct png_control
-{
-   png_structp  png_ptr;
-   png_infop    info_ptr;
-   png_voidp    error_buf;     /* Always a jmp_buf at present. */
-
-   png_const_bytep memory;     /* Memory buffer. */
-   png_size_t      size;       /* Size of the memory buffer. */
-
-   unsigned int for_write :1;  /* Otherwise it is a read structure */
-   unsigned int owned_file :1; /* We own the file in io_ptr */
-} png_control;
-
-/* Return the pointer to the jmp_buf from a png_control: necessary because C
- * does not reveal the type of the elements of jmp_buf.
- */
-#ifdef __cplusplus
-#  define png_control_jmp_buf(pc) (((jmp_buf*)((pc)->error_buf))[0])
-#else
-#  define png_control_jmp_buf(pc) ((pc)->error_buf)
-#endif
-
-/* Utility to safely execute a piece of libpng code catching and logging any
- * errors that might occur.  Returns true on success, false on failure (either
- * of the function or as a result of a png_error.)
- */
-PNG_FUNCTION(void, png_safe_error, (png_structp png_ptr,
-   png_const_charp error_message), PNG_NORETURN);
-
-#ifdef PNG_WARNINGS_SUPPORTED
-   PNG_EXTERN void png_safe_warning(png_structp png_ptr,
-      png_const_charp warning_message);
-#else
-#  define png_safe_warning 0/*dummy argument*/
-#endif
-
-PNG_EXTERN int png_safe_execute PNGARG((png_imagep image,
-   int (*function)(png_voidp), png_voidp arg));
-
-/* Utility to log an error, this also cleans up the png_image, the function
- * always returns 0 (false).
- */
-PNG_EXTERN int png_image_error(png_imagep image, png_const_charp error_message);
-
-#endif /* SIMPLIFIED READ/WRITE */
-
 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
 
-
 #include "pngdebug.h"
 
 #ifdef __cplusplus
diff --git a/pngread.c b/pngread.c
index 7583831..6427f9a 100644
--- a/pngread.c
+++ b/pngread.c
@@ -15,9 +15,6 @@
  */
 
 #include "pngpriv.h"
-#if defined PNG_SIMPLIFIED_READ_SUPPORTED && defined PNG_STDIO_SUPPORTED
-#  include <errno.h>
-#endif
 
 #ifdef PNG_READ_SUPPORTED
 
@@ -1308,1153 +1305,4 @@
 }
 #endif /* PNG_INFO_IMAGE_SUPPORTED */
 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
-
-#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
-/* SIMPLIFIED READ
- *
- * This code currently relies on the sequential reader, though it could easily
- * be made to work with the progressive one.
- */
-/* Do all the *safe* initialization - 'safe' means that png_error won't be
- * called, so setting up the jmp_buf is not required.  This means that anything
- * called from here must *not* call png_malloc - it has to call png_malloc_warn
- * instead so that control is returned safely back to this routine.
- */
-static int
-png_image_read_init(png_imagep image)
-{
-   png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, image,
-          png_safe_error, png_safe_warning);
-
-   if (png_ptr != NULL)
-   {
-      png_infop info_ptr = png_create_info_struct(png_ptr);
-
-      if (info_ptr != NULL)
-      {
-         png_controlp control = png_voidcast(png_controlp,
-            png_malloc_warn(png_ptr, sizeof *control));
-
-         if (control != NULL)
-         {
-            memset(control, 0, sizeof *control);
-
-            control->png_ptr = png_ptr;
-            control->info_ptr = info_ptr;
-            control->for_write = 0;
-
-            image->opaque = control;
-            return 1;
-         }
-
-         /* Error clean up */
-         png_destroy_info_struct(png_ptr, &info_ptr);
-      }
-
-      png_destroy_read_struct(&png_ptr, NULL, NULL);
-   }
-
-   return png_image_error(image, "png_image_read: out of memory");
-}
-
-/* Utility to find the base format of a PNG file from a png_struct. */
-static png_uint_32
-png_image_format(png_structp png_ptr, png_infop info_ptr)
-{
-   png_uint_32 format = 0;
-
-   if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
-      format |= PNG_FORMAT_FLAG_COLOR;
-
-   if (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)
-      format |= PNG_FORMAT_FLAG_ALPHA;
-
-   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
-      format |= PNG_FORMAT_FLAG_ALPHA;
-
-   if (png_ptr->bit_depth == 16)
-      format |= PNG_FORMAT_FLAG_LINEAR;
-
-   return format;
-}
-
-/* Do the main body of a 'png_image_begin_read' function; read the PNG file
- * header and fill in all the information.  This is executed in a safe context,
- * unlike the init routine above.
- */
-static int
-png_image_read_header(png_voidp argument)
-{
-   png_imagep image = png_voidcast(png_imagep, argument);
-   png_structp png_ptr = image->opaque->png_ptr;
-   png_infop info_ptr = image->opaque->info_ptr;
-
-   png_read_info(png_ptr, info_ptr);
-
-   /* Do this the fast way; just read directly out of png_struct. */
-   image->width = png_ptr->width;
-   image->height = png_ptr->height;
-
-   {
-      png_uint_32 format = png_image_format(png_ptr, info_ptr);
-
-      image->format = format;
-      image->flags = 0;
-
-      /* Now try to work out whether the color data does not match sRGB. */
-      if ((format & PNG_FORMAT_FLAG_COLOR) != 0 &&
-         (info_ptr->valid & PNG_INFO_sRGB) == 0)
-      {
-         /* gamma is irrelevant because libpng does gamma correction, what
-          * matters is if the cHRM chunk doesn't match or, in the absence of
-          * cRHM, if the iCCP profile appears to have different end points.
-          */
-         if (info_ptr->valid & PNG_INFO_cHRM)
-         {
-            /* TODO: this is a copy'n'paste from pngrutil.c, make a common
-             * checking function.  This checks for a 1% error.
-             */
-            /* The cHRM chunk is used in preference to iCCP */
-            if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270,  1000) ||
-                PNG_OUT_OF_RANGE(info_ptr->y_white, 32900,  1000) ||
-                PNG_OUT_OF_RANGE(info_ptr->x_red,   64000,  1000) ||
-                PNG_OUT_OF_RANGE(info_ptr->y_red,   33000,  1000) ||
-                PNG_OUT_OF_RANGE(info_ptr->x_green, 30000,  1000) ||
-                PNG_OUT_OF_RANGE(info_ptr->y_green, 60000,  1000) ||
-                PNG_OUT_OF_RANGE(info_ptr->x_blue,  15000,  1000) ||
-                PNG_OUT_OF_RANGE(info_ptr->y_blue,   6000,  1000))
-               image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB;
-         }
-
-         else if (info_ptr->valid & PNG_INFO_iCCP)
-         {
-#        if 0
-            /* TODO: IMPLEMENT THIS! Remember to remove iCCP from
-                 the chunks_to_ignore list */
-            /* Here if we just have an iCCP chunk. */
-            if (!png_iCCP_is_sRGB(png_ptr, info_ptr))
-#        endif
-               image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB;
-         }
-      }
-   }
-
-   return 1;
-}
-
-#ifdef PNG_STDIO_SUPPORTED
-int PNGAPI
-png_image_begin_read_from_stdio(png_imagep image, FILE* file)
-{
-   if (image != NULL)
-   {
-      if (file != NULL)
-      {
-         if (png_image_read_init(image))
-         {
-            /* This is slightly evil, but png_init_io doesn't do anything other
-             * than this and we haven't changed the standard IO functions so
-             * this saves a 'safe' function.
-             */
-            image->opaque->png_ptr->io_ptr = file;
-            return png_safe_execute(image, png_image_read_header, image);
-         }
-      }
-
-      else
-         return png_image_error(image,
-            "png_image_begin_read_from_stdio: invalid argument");
-   }
-
-   return 0;
-}
-
-int PNGAPI
-png_image_begin_read_from_file(png_imagep image, const char *file_name)
-{
-   if (image != NULL)
-   {
-      if (file_name != NULL)
-      {
-         FILE *fp = fopen(file_name, "rb");
-
-         if (fp != NULL)
-         {
-            if (png_image_read_init(image))
-            {
-               image->opaque->png_ptr->io_ptr = fp;
-               image->opaque->owned_file = 1;
-               return png_safe_execute(image, png_image_read_header, image);
-            }
-
-            /* Clean up: just the opened file. */
-            (void)fclose(fp);
-         }
-
-         else
-            return png_image_error(image, strerror(errno));
-      }
-
-      else
-         return png_image_error(image,
-            "png_image_begin_read_from_file: invalid argument");
-   }
-
-   return 0;
-}
-#endif /* PNG_STDIO_SUPPORTED */
-
-static void PNGCBAPI
-png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need)
-{
-   if (png_ptr != NULL)
-   {
-      png_imagep image = png_voidcast(png_imagep, png_ptr->io_ptr);
-      if (image != NULL)
-      {
-         png_controlp cp = image->opaque;
-         if (cp != NULL)
-         {
-            png_const_bytep memory = cp->memory;
-            png_size_t size = cp->size;
-
-            if (memory != NULL && size >= need)
-            {
-               memcpy(out, memory, need);
-               cp->memory = memory + need;
-               cp->size = size - need;
-               return;
-            }
-
-            png_error(png_ptr, "read beyond end of data");
-         }
-      }
-
-      png_error(png_ptr, "invalid memory read");
-   }
-}
-
-int PNGAPI png_image_begin_read_from_memory(png_imagep image,
-   png_const_voidp memory, png_size_t size)
-{
-   if (image != NULL)
-   {
-      if (memory != NULL && size > 0)
-      {
-         if (png_image_read_init(image))
-         {
-            /* Now set the IO functions to read from the memory buffer and
-             * store it into io_ptr.  Again do this in-place to avoid calling a
-             * libpng function that requires error handling.
-             */
-            image->opaque->memory = png_voidcast(png_const_bytep, memory);
-            image->opaque->size = size;
-            image->opaque->png_ptr->io_ptr = image;
-            image->opaque->png_ptr->read_data_fn = png_image_memory_read;
-
-            return png_safe_execute(image, png_image_read_header, image);
-         }
-      }
-
-      else
-         return png_image_error(image,
-            "png_image_begin_read_from_memory: invalid argument");
-   }
-
-   return 0;
-}
-
-/* Arguments to png_image_finish_read: */
-typedef struct
-{
-   /* Arguments: */
-   png_imagep image;
-   png_voidp  buffer;
-   png_int_32 row_stride;
-   png_colorp background;
-   /* Local variables: */
-   png_bytep  local_row;
-   png_bytep  first_row;
-   ptrdiff_t  row_bytes; /* unsigned arithmetic step between rows */
-} png_image_read_control;
-
-/* Just the row reading part of png_image_read. */
-static int
-png_image_read_composite(png_voidp argument)
-{
-   png_image_read_control *display = png_voidcast(png_image_read_control*,
-      argument);
-   png_imagep image = display->image;
-   png_structp png_ptr = image->opaque->png_ptr;
-   png_byte interlace_type = png_ptr->interlaced;
-   int passes;
-
-   switch (interlace_type)
-   {
-      case PNG_INTERLACE_NONE:
-         passes = 1;
-         break;
-
-      case PNG_INTERLACE_ADAM7:
-         passes = PNG_INTERLACE_ADAM7_PASSES;
-         break;
-
-      default:
-         png_error(png_ptr, "unknown interlace type");
-   }
-
-   {
-      png_uint_32 height = image->height;
-      png_uint_32 width = image->width;
-      unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) ? 3 : 1;
-      int pass;
-
-      for (pass = 0; pass < passes; ++pass)
-      {
-         png_bytep        row = display->first_row;
-         unsigned int     startx, stepx, stepy;
-         png_uint_32      y;
-
-         if (interlace_type == PNG_INTERLACE_ADAM7)
-         {
-            /* The row may be empty for a short image: */
-            if (PNG_PASS_COLS(width, pass) == 0)
-               continue;
-
-            startx = PNG_PASS_START_COL(pass);
-            stepx = PNG_PASS_COL_OFFSET(pass);
-            y = PNG_PASS_START_ROW(pass);
-            stepy = PNG_PASS_ROW_OFFSET(pass);
-         }
-
-         else
-         {
-            y = 0;
-            startx = 0;
-            stepx = stepy = 1;
-         }
-
-         /* The following are invariants across all the rows: */
-         startx *= channels;
-         stepx *= channels;
-         
-         for (; y<height; y += stepy)
-            {
-               png_bytep inrow = display->local_row;
-               png_bytep outrow = row + startx;
-               png_const_bytep end_row = row + width * channels;
-
-               /* Read the row, which is packed: */
-               png_read_row(png_ptr, inrow, NULL);
-
-               /* Now do the composition on each pixel in this row. */
-               for (; outrow < end_row; outrow += stepx)
-               {
-                  png_byte alpha = inrow[channels];
-
-                  if (alpha > 0) /* else no change to the output */
-                  {
-                     unsigned int c;
-
-                     for (c=0; c<channels; ++c)
-                     {
-                        png_uint_32 component = inrow[c];
-
-                        if (alpha < 255) /* else just use component */
-                        {
-                           /* This is PNG_OPTIMIZED_ALPHA, the component value
-                            * is a linear 8-bit value.  Combine this with the
-                            * current outrow[c] value which is sRGB encoded.
-                            * Arithmetic here is 16-bits to preserve the output
-                            * values correctly.
-                            */
-                           component *= 257*255; /* =65535 */
-                           component += (255-alpha)*png_sRGB_table[outrow[c]];
-
-                           /* So 'component' is scaled by 255*65535 and is
-                            * therefore appropriate for the sRGB to linear
-                            * convertion table.
-                            */
-                           component = PNG_sRGB_FROM_LINEAR(component);
-                        }
-
-                        outrow[c] = (png_byte)component;
-                     }
-                  }
-
-                  inrow += channels+1; /* components and alpha channel */
-               }
-
-               row += display->row_bytes;
-            }
-      }
-   }
-
-   return 1;
-}
-
-/* The do_local_background case; called when all the following transforms are to
- * be done:
- *
- * PNG_RGB_TO_GRAY
- * PNG_COMPOSITE
- * PNG_GAMMA
- *
- * This is a work-round for the fact that both the PNG_RGB_TO_GRAY and
- * PNG_COMPOSITE code performs gamma correction, so we get double gamma
- * correction.  The fix-up is to prevent the PNG_COMPOSITE operation happening
- * inside libpng, so this routine sees an 8 or 16-bit gray+alpha row and handles
- * the removal or pre-multiplication of the alpha channel.
- */
-static int
-png_image_read_background(png_voidp argument)
-{
-   png_image_read_control *display = png_voidcast(png_image_read_control*,
-      argument);
-   png_imagep image = display->image;
-   png_structp png_ptr = image->opaque->png_ptr;
-   png_infop info_ptr = image->opaque->info_ptr;
-   png_byte interlace_type = png_ptr->interlaced;
-   png_uint_32 height = image->height;
-   png_uint_32 width = image->width;
-   int pass, passes;
-
-   /* Double check the convoluted logic below.  We expect to get here with
-    * libpng doing rgb to gray and gamma correction but background processing
-    * left to the png_image_read_background function.  The rows libpng produce
-    * might be 8 or 16-bit but should always have two channels; gray plus alpha.
-    */
-   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
-      png_error(png_ptr, "lost rgb to gray");
-
-   if ((png_ptr->transformations & PNG_COMPOSE) != 0)
-      png_error(png_ptr, "unexpected compose");
-
-   /* The palette code zaps PNG_GAMMA in place... */
-   if ((png_ptr->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
-      (png_ptr->transformations & PNG_GAMMA) == 0)
-      png_error(png_ptr, "lost gamma correction");
-
-   if (png_get_channels(png_ptr, info_ptr) != 2)
-      png_error(png_ptr, "lost/gained channels");
-
-   switch (interlace_type)
-   {
-      case PNG_INTERLACE_NONE:
-         passes = 1;
-         break;
-
-      case PNG_INTERLACE_ADAM7:
-         passes = PNG_INTERLACE_ADAM7_PASSES;
-         break;
-
-      default:
-         png_error(png_ptr, "unknown interlace type");
-   }
-
-   switch (png_get_bit_depth(png_ptr, info_ptr))
-   {
-      default:
-         png_error(png_ptr, "unexpected bit depth");
-         break;
-
-      case 8:
-         /* 8-bit sRGB gray values with an alpha channel; the alpha channel is
-          * to be removed by composing on a backgroundi: either the row if
-          * display->background is NULL or display->background.green if not.
-          * Unlike the code above ALPHA_OPTIMIZED has *not* been done.
-          */
-         for (pass = 0; pass < passes; ++pass)
-         {
-            png_bytep        row = display->first_row;
-            unsigned int     startx, stepx, stepy;
-            png_uint_32      y;
-
-            if (interlace_type == PNG_INTERLACE_ADAM7)
-            {
-               /* The row may be empty for a short image: */
-               if (PNG_PASS_COLS(width, pass) == 0)
-                  continue;
-
-               startx = PNG_PASS_START_COL(pass);
-               stepx = PNG_PASS_COL_OFFSET(pass);
-               y = PNG_PASS_START_ROW(pass);
-               stepy = PNG_PASS_ROW_OFFSET(pass);
-            }
-
-            else
-            {
-               y = 0;
-               startx = 0;
-               stepx = stepy = 1;
-            }
-            
-            if (display->background == NULL)
-            {
-               for (; y<height; y += stepy)
-                  {
-                     png_bytep inrow = display->local_row;
-                     png_bytep outrow = row + startx;
-                     png_const_bytep end_row = row + width;
-
-                     /* Read the row, which is packed: */
-                     png_read_row(png_ptr, inrow, NULL);
-
-                     /* Now do the composition on each pixel in this row. */
-                     for (; outrow < end_row; outrow += stepx)
-                     {
-                        png_byte alpha = inrow[1];
-
-                        if (alpha > 0) /* else no change to the output */
-                        {
-                           png_uint_32 component = inrow[0];
-
-                           if (alpha < 255) /* else just use component */
-                           {
-                              /* Since PNG_OPTIMIZED_ALPHA was not set it is
-                               * necessary to invert the sRGB transfer
-                               * function and multiply the alpha out.
-                               */
-                              component = png_sRGB_table[component] * alpha;
-                              component += png_sRGB_table[outrow[0]] *
-                                 (255-alpha);
-                              component = PNG_sRGB_FROM_LINEAR(component);
-                           }
-
-                           outrow[0] = (png_byte)component;
-                        }
-
-                        inrow += 2; /* gray and alpha channel */
-                     }
-
-                     row += display->row_bytes;
-                  }
-            }
-
-            else /* constant background value */
-            {
-               png_byte background8 = display->background->green;
-               png_uint_16 background = png_sRGB_table[background8];
-
-               for (; y<height; y += stepy)
-                  {
-                     png_bytep inrow = display->local_row;
-                     png_bytep outrow = row + startx;
-                     png_const_bytep end_row = row + width;
-
-                     /* Read the row, which is packed: */
-                     png_read_row(png_ptr, inrow, NULL);
-
-                     /* Now do the composition on each pixel in this row. */
-                     for (; outrow < end_row; outrow += stepx)
-                     {
-                        png_byte alpha = inrow[1];
-
-                        if (alpha > 0) /* else use background */
-                        {
-                           png_uint_32 component = inrow[0];
-
-                           if (alpha < 255) /* else just use component */
-                           {
-                              component = png_sRGB_table[component] * alpha;
-                              component += background * (255-alpha);
-                              component = PNG_sRGB_FROM_LINEAR(component);
-                           }
-
-                           outrow[0] = (png_byte)component;
-                        }
-
-                        else
-                           outrow[0] = background8;
-
-                        inrow += 2; /* gray and alpha channel */
-                     }
-
-                     row += display->row_bytes;
-                  }
-            }
-         }
-         break;
-
-      case 16:
-         /* 16-bit linear with pre-multiplied alpha; the pre-multiplication must
-          * still be done and, maybe, the alpha channel removed.  This code also
-          * handles the alpha-first option.
-          */
-         {
-            unsigned int outchannels = png_get_channels(png_ptr, info_ptr);
-            int preserve_alpha = (image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
-            int swap_alpha = 0;
-
-            if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
-               swap_alpha = 1;
-
-            for (pass = 0; pass < passes; ++pass)
-            {
-               png_uint_16p     row = (png_uint_16p)display->first_row;
-               unsigned int     startx, stepx, stepy; /* all in pixels */
-               png_uint_32      y;
-
-               if (interlace_type == PNG_INTERLACE_ADAM7)
-               {
-                  /* The row may be empty for a short image: */
-                  if (PNG_PASS_COLS(width, pass) == 0)
-                     continue;
-
-                  startx = PNG_PASS_START_COL(pass);
-                  stepx = PNG_PASS_COL_OFFSET(pass);
-                  y = PNG_PASS_START_ROW(pass);
-                  stepy = PNG_PASS_ROW_OFFSET(pass);
-               }
-
-               else
-               {
-                  y = 0;
-                  startx = 0;
-                  stepx = stepy = 1;
-               }
-
-               startx *= outchannels;
-               stepx *= outchannels;
-               
-               for (; y<height; y += stepy)
-                  {
-                     png_uint_16p inrow;
-                     png_uint_16p outrow = row + startx;
-                     png_uint_16p end_row = row + width * outchannels;
-
-                     /* Read the row, which is packed: */
-                     png_read_row(png_ptr, display->local_row, NULL);
-                     inrow = (png_uint_16p)display->local_row;
-
-                     /* Now do the pre-multiplication on each pixel in this row.
-                      */
-                     for (; outrow < end_row; outrow += stepx)
-                     {
-                        png_uint_32 component = inrow[0];
-                        png_uint_16 alpha = inrow[1];
-
-                        if (alpha > 0) /* else 0 */
-                        {
-                           if (alpha < 65535) /* else just use component */
-                           {
-                              component *= alpha;
-                              component += 32767;
-                              component /= 65535;
-                           }
-                        }
-
-                        else
-                           component = 0;
-
-                        outrow[swap_alpha] = (png_uint_16)component;
-                        if (outchannels > 1)
-                           outrow[1 ^ swap_alpha] = alpha;
-
-                        inrow += 2; /* components and alpha channel */
-                     }
-
-                     row += display->row_bytes;
-                  }
-            }
-         }
-         break;
-   }
-
-   return 1;
-}
-
-/* The guts of png_image_finish_read as a png_safe_execute callback. */
-static int
-png_image_read_end(png_voidp argument)
-{
-   png_image_read_control *display = png_voidcast(png_image_read_control*,
-      argument);
-   png_imagep image = display->image;
-   png_structp png_ptr = image->opaque->png_ptr;
-   png_infop info_ptr = image->opaque->info_ptr;
-
-   png_uint_32 format = image->format;
-   int linear = (format & PNG_FORMAT_FLAG_LINEAR) != 0;
-   int do_local_compose = 0;
-   int do_local_background = 0; /* to avoid double gamma correction bug */
-   int passes = 0;
-
-   /* Add transforms to ensure the correct output format is produced then check
-    * that the required implementation support is there.  Always expand; always
-    * need 8 bits minimum, no palette and expanded tRNS.
-    */
-   png_set_expand(png_ptr);
-   
-   /* Now check the format to see if it was modified. */
-   {
-      png_uint_32 base_format = png_image_format(png_ptr, info_ptr);
-      png_uint_32 change = format ^ base_format;
-      png_fixed_point output_gamma;
-      int mode; /* alpha mode */
-
-      /* Do this first so that we have a record if rgb to gray is happening. */
-      if (change & PNG_FORMAT_FLAG_COLOR)
-      {
-         /* gray<->color transformation required. */
-         if (format & PNG_FORMAT_FLAG_COLOR)
-            png_set_gray_to_rgb(png_ptr);
-
-         else
-         {
-            /* libpng can't do both rgb to gray and
-             * background/pre-multiplication if there is also significant gamma
-             * correction, because both operations require linear colors and
-             * the code only supports one transform doing the gamma correction.
-             * Handle this by doing the pre-multiplication or background
-             * operation in this code, if necessary.
-             *
-             * TODO: fix this by rewriting pngrtran.c (!)
-             *
-             * For the moment (given that fixing this in pngrtran.c is an
-             * enormous change) 'do_local_background' is used to indicate that
-             * the problem exists.
-             */
-            if (base_format & PNG_FORMAT_FLAG_ALPHA)
-               do_local_background = 1/*maybe*/;
-
-            png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE,
-               PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
-         }
-
-         change &= ~PNG_FORMAT_FLAG_COLOR;
-      }
-
-      /* Set the gamma appropriately, linear for 16-bit input, sRGB otherwise.
-       */
-      {
-         png_fixed_point input_gamma_default;
-
-         if (base_format & PNG_FORMAT_FLAG_LINEAR)
-            input_gamma_default = PNG_GAMMA_LINEAR;
-         else
-            input_gamma_default = PNG_DEFAULT_sRGB;
-
-         /* Call png_set_alpha_mode to set the default for the input gamma; the
-          * output gamma is set by a second call below.
-          */
-         png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, input_gamma_default);
-      }
-
-      if (linear)
-      {
-         /* If there *is* an alpha channel in the input it must be multiplied
-          * out; use PNG_ALPHA_STANDARD, otherwise just use PNG_ALPHA_PNG.
-          */
-         if (base_format & PNG_FORMAT_FLAG_ALPHA)
-            mode = PNG_ALPHA_STANDARD; /* associated alpha */
-
-         else
-            mode = PNG_ALPHA_PNG;
-
-         output_gamma = PNG_GAMMA_LINEAR;
-      }
-
-      else
-      {
-         mode = PNG_ALPHA_PNG;
-         output_gamma = PNG_DEFAULT_sRGB;
-      }
-
-      /* If 'do_local_background' is set check for the presence of gamma
-       * correction; this is part of the work-round for the libpng bug
-       * described above.
-       *
-       * TODO: fix libpng and remove this.
-       */
-      if (do_local_background)
-      {
-         png_fixed_point gtest;
-
-         /* This is 'png_gamma_threshold' from pngrtran.c; the test used for
-          * gamma correction, the screen gamma hasn't been set on png_struct
-          * yet; it's set below.  png_struct::gamma, however, is set to the
-          * final value.
-          */
-         if (png_muldiv(&gtest, output_gamma, png_ptr->gamma, PNG_FP_1) &&
-            !png_gamma_significant(gtest))
-            do_local_background = 0;
-
-         else if (mode == PNG_ALPHA_STANDARD)
-         {
-            do_local_background = 2/*required*/;
-            mode = PNG_ALPHA_PNG; /* prevent libpng doing it */
-         }
-
-         /* else leave as 1 for the checks below */
-      }
-
-      /* If the bit-depth changes then handle that here. */
-      if (change & PNG_FORMAT_FLAG_LINEAR)
-      {
-         if (linear /*16-bit output*/)
-            png_set_expand_16(png_ptr);
-
-         else /* 8-bit output */
-            png_set_scale_16(png_ptr);
-
-         change &= ~PNG_FORMAT_FLAG_LINEAR;
-      }
-
-      /* Now the background/alpha channel changes. */
-      if (change & PNG_FORMAT_FLAG_ALPHA)
-      {
-         /* Removing an alpha channel requires composition for the 8-bit
-          * formats; for the 16-bit it is already done, above, by the
-          * pre-multiplication and the channel just needs to be stripped.
-          */
-         if (base_format & PNG_FORMAT_FLAG_ALPHA)
-         {
-            /* If RGB->gray is happening the alpha channel must be left and the
-             * operation completed locally.
-             *
-             * TODO: fix libpng and remove this.
-             */
-            if (do_local_background)
-               do_local_background = 2/*required*/;
-
-            /* 16-bit output: just remove the channel */
-            else if (linear) /* compose on black (well, pre-multiply) */
-               png_set_strip_alpha(png_ptr);
-
-            /* 8-bit output: do an appropriate compose */
-            else if (display->background != NULL)
-            {
-               png_color_16 c;
-
-               c.index = 0; /*unused*/
-               c.red = display->background->red;
-               c.green = display->background->green;
-               c.blue = display->background->blue;
-               c.gray = display->background->green;
-
-               /* This is always an 8-bit sRGB value, using the 'green' channel
-                * for gray is much better than calculating the luminance here;
-                * we can get off-by-one errors in that calculation relative to
-                * the app expectations and that will show up in transparent
-                * pixels.
-                */
-               png_set_background_fixed(png_ptr, &c,
-                  PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
-                  0/*gamma: not used*/);
-            }
-
-            else /* compose on row: implemented below. */
-            {
-               do_local_compose = 1;
-               /* This leaves the alpha channel in the output, so it has to be
-                * removed by the code below.  Set the encoding to the 'OPTIMIZE'
-                * one so the code only has to hack on the pixels that require
-                * composition.
-                */
-               mode = PNG_ALPHA_OPTIMIZED;
-            }
-         }
-
-         else /* output needs an alpha channel */
-         {
-            /* This is tricky because it happens before the swap operation has
-             * been accomplished; however, the swap does *not* swap the added
-             * alpha channel (weird API), so it must be added in the correct
-             * place.
-             */
-            png_uint_32 filler; /* opaque filler */
-            int where;
-
-            if (linear)
-               filler = 65535;
-
-            else
-               filler = 255;
-
-#           ifdef PNG_FORMAT_AFIRST_SUPPORTED
-               if (format & PNG_FORMAT_FLAG_AFIRST)
-               {
-                  where = PNG_FILLER_BEFORE;
-                  change &= ~PNG_FORMAT_FLAG_AFIRST;
-               }
-
-               else
-#           endif
-               where = PNG_FILLER_AFTER;
-
-            png_set_add_alpha(png_ptr, filler, where);
-         }
-
-         /* This stops the (irrelevant) call to swap_alpha below. */
-         change &= ~PNG_FORMAT_FLAG_ALPHA;
-      }
-
-      /* Now set the alpha mode correctly; this is always done, even if there is
-       * no alpha channel in either the input or the output because it correctly
-       * sets the output gamma.
-       */
-      png_set_alpha_mode_fixed(png_ptr, mode, output_gamma);
-
-#     ifdef PNG_FORMAT_BGR_SUPPORTED
-         if (change & PNG_FORMAT_FLAG_BGR)
-         {
-            /* Check only the output format; PNG is never BGR; don't do this if
-             * the output is gray, but fix up the 'format' value in that case.
-             */
-            if (format & PNG_FORMAT_FLAG_COLOR)
-               png_set_bgr(png_ptr);
-
-            else
-               format &= ~PNG_FORMAT_FLAG_BGR;
-
-            change &= ~PNG_FORMAT_FLAG_BGR;
-         }
-#     endif
-
-#     ifdef PNG_FORMAT_AFIRST_SUPPORTED
-         if (change & PNG_FORMAT_FLAG_AFIRST)
-         {
-            /* Only relevant if there is an alpha channel - it's particularly
-             * important to handle this correctly because do_local_compose may
-             * be set above and then libpng will keep the alpha channel for this
-             * code to remove.
-             */
-            if (format & PNG_FORMAT_FLAG_ALPHA)
-            {
-               /* Disable this if doing a local background,
-                * TODO: remove this when local background is no longer required.
-                */
-               if (do_local_background != 2)
-                  png_set_swap_alpha(png_ptr);
-            }
-
-            else
-               format &= ~PNG_FORMAT_FLAG_AFIRST;
-
-            change &= ~PNG_FORMAT_FLAG_AFIRST;
-         }
-#     endif
-
-      /* If the *output* is 16-bit then we need to check for a byte-swap on this
-       * architecture.
-       */
-      if (linear)
-      {
-         PNG_CONST png_uint_16 le = 0x0001;
-
-         if (*(png_const_bytep)&le)
-            png_set_swap(png_ptr);
-      }
-
-      /* If change is not now 0 some transformation is missing - error out. */
-      if (change)
-         png_error(png_ptr, "png_read_image: unsupported transformation");
-   }
-
-#  ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
-      /* Prepare the reader to ignore all recognized chunks whose data will not
-       * be used, i.e., all chunks recognized by libpng except for those
-       * involved in basic image reading:
-       *
-       *    IHDR, PLTE, IDAT, IEND
-       *
-       * Or image data handling:
-       *
-       *    tRNS, bKGD, gAMA, cHRM, sRGB, iCCP and sBIT.
-       *
-       * This provides a small performance improvement and eliminates any
-       * potential vulnerability to security problems in the unused chunks.
-       *
-       * TODO: make it so that this is an explicit list to process, not a list
-       * to ignore?
-       */
-      {
-          static PNG_CONST png_byte chunks_to_ignore[] = {
-              104,  73,  83,  84, '\0',  /* hIST */
-              105,  84,  88, 116, '\0',  /* iTXt */
-              111,  70,  70, 115, '\0',  /* oFFs */
-              112,  67,  65,  76, '\0',  /* pCAL */
-              112,  72,  89, 115, '\0',  /* pHYs */
-              115,  67,  65,  76, '\0',  /* sCAL */
-              115,  80,  76,  84, '\0',  /* sPLT */
-              116,  69,  88, 116, '\0',  /* tEXt */
-              116,  73,  77,  69, '\0',  /* tIME */
-              122,  84,  88, 116, '\0'   /* zTXt */
-          };
-
-          /* Ignore unknown chunks */
-          png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
-            NULL, 0);
-
-          /* Ignore known but unused chunks */
-          png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
-            chunks_to_ignore, (sizeof chunks_to_ignore)/5);
-       }
-#  endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */
-
-   /* Update the 'info' structure and make sure the result is as required; first
-    * make sure to turn on the interlace handling if it will be required
-    * (because it can't be turned on *after* the call to png_read_update_info!)
-    *
-    * TODO: remove the do_local_background fixup below.
-    */
-   if (!do_local_compose && do_local_background != 2)
-      passes = png_set_interlace_handling(png_ptr);
-
-   png_read_update_info(png_ptr, info_ptr);
-
-   {
-      png_uint_32 info_format = 0;
-
-      if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
-         info_format |= PNG_FORMAT_FLAG_COLOR;
-
-      if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
-      {
-         /* do_local_compose removes this channel below. */
-         if (!do_local_compose)
-         {
-            /* do_local_background does the same if required. */
-            if (do_local_background != 2 ||
-               (format & PNG_FORMAT_FLAG_ALPHA) != 0)
-               info_format |= PNG_FORMAT_FLAG_ALPHA;
-         }
-      }
-
-      else if (do_local_compose) /* internal error */
-         png_error(png_ptr, "png_image_read: alpha channel lost");
-
-      if (info_ptr->bit_depth == 16)
-         info_format |= PNG_FORMAT_FLAG_LINEAR;
-
-#     ifdef PNG_FORMAT_BGR_SUPPORTED
-         if (png_ptr->transformations & PNG_BGR)
-            info_format |= PNG_FORMAT_FLAG_BGR;
-#     endif
-
-#     ifdef PNG_FORMAT_AFIRST_SUPPORTED
-         if (png_ptr->transformations & PNG_SWAP_ALPHA ||
-            ((png_ptr->transformations & PNG_ADD_ALPHA) != 0 &&
-            (png_ptr->flags & PNG_FLAG_FILLER_AFTER) == 0))
-            info_format |= PNG_FORMAT_FLAG_AFIRST;
-#     endif
-
-      /* This is actually an internal error. */
-      if (info_format != format)
-         png_error(png_ptr, "png_read_image: invalid transformations");
-   }
-
-   /* Now read the rows.  If do_local_compose is set then it is necessary to use
-    * a local row buffer.  The output will be GA, RGBA or BGRA and must be
-    * converted to G, RGB or BGR as appropriate.  The 'local_row' member of the
-    * display acts as a flag.
-    */
-   {
-      png_bytep first_row = png_voidcast(png_bytep, display->buffer);
-      ptrdiff_t row_bytes = display->row_stride;
-
-      if (linear)
-         row_bytes *= sizeof (png_uint_16);
-
-      /* The following expression is designed to work correctly whether it gives
-       * a signed or an unsigned result.
-       */
-      if (row_bytes < 0)
-         first_row += (image->height-1) * (-row_bytes);
-
-      display->first_row = first_row;
-      display->row_bytes = row_bytes;
-   }
-
-   if (do_local_compose)
-   {
-      int result;
-      png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
-         png_get_rowbytes(png_ptr, info_ptr)));
-
-      display->local_row = row;
-      result = png_safe_execute(image, png_image_read_composite, display);
-      display->local_row = NULL;
-      png_free(png_ptr, row);
-
-      return result;
-   }
-
-   else if (do_local_background == 2)
-   {
-      int result;
-      png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
-         png_get_rowbytes(png_ptr, info_ptr)));
-
-      display->local_row = row;
-      result = png_safe_execute(image, png_image_read_background, display);
-      display->local_row = NULL;
-      png_free(png_ptr, row);
-
-      return result;
-   }
-
-   else
-   {
-      png_alloc_size_t row_bytes = display->row_bytes;
-
-      while (--passes >= 0)
-      {
-         png_uint_32      y = image->height;
-         png_bytep        row = display->first_row;
-         
-         while (y-- > 0)
-         {
-            png_read_row(png_ptr, row, NULL);
-            row += row_bytes;
-         }
-      }
-
-      return 1;
-   }
-}
-
-int PNGAPI
-png_image_finish_read(png_imagep image, png_colorp background, void *buffer,
-   png_int_32 row_stride)
-{
-   if (image != NULL)
-   {
-      png_uint_32 check;
-
-      if (row_stride == 0)
-         row_stride = PNG_IMAGE_ROW_STRIDE(*image);
-
-      if (row_stride < 0)
-         check = -row_stride;
-
-      else
-         check = row_stride;
-
-      if (buffer != NULL && check >= PNG_IMAGE_ROW_STRIDE(*image))
-      {
-         int result;
-         png_image_read_control display;
-
-         memset(&display, 0, sizeof display);
-         display.image = image;
-         display.buffer = buffer;
-         display.row_stride = row_stride;
-         display.background = background;
-         display.local_row = NULL;
-         result = png_safe_execute(image, png_image_read_end, &display);
-         png_image_free(image);
-         return result;
-      }
-
-      else
-         return png_image_error(image,
-            "png_image_finish_read: invalid argument");
-   }
-
-   return 0;
-}
-
-#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */
 #endif /* PNG_READ_SUPPORTED */
diff --git a/pngtest.c b/pngtest.c
index 835a274..33d06fe 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1163,6 +1163,10 @@
       if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
       {
          pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
+
+         if (verbose)
+            printf("\nText compression=%d\n", text_ptr->compression);
+
          png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
       }
    }
diff --git a/pngwrite.c b/pngwrite.c
index 0802174..92a9b95 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -12,9 +12,6 @@
  */
 
 #include "pngpriv.h"
-#if defined PNG_SIMPLIFIED_WRITE_SUPPORTED && defined PNG_STDIO_SUPPORTED
-#  include <errno.h>
-#endif
 
 #ifdef PNG_WRITE_SUPPORTED
 
@@ -1655,563 +1652,4 @@
    PNG_UNUSED(params)
 }
 #endif
-
-
-#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
-#ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */
-/* Initialize the write structure - general purpose utility. */
-static int
-png_image_write_init(png_imagep image)
-{
-   png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image,
-          png_safe_error, png_safe_warning);
-
-   if (png_ptr != NULL)
-   {
-      png_infop info_ptr = png_create_info_struct(png_ptr);
-
-      if (info_ptr != NULL)
-      {
-         png_controlp control = png_voidcast(png_controlp,
-            png_malloc_warn(png_ptr, sizeof *control));
-
-         if (control != NULL)
-         {
-            memset(control, 0, sizeof *control);
-
-            control->png_ptr = png_ptr;
-            control->info_ptr = info_ptr;
-            control->for_write = 1;
-
-            image->opaque = control;
-            return 1;
-         }
-
-         /* Error clean up */
-         png_destroy_info_struct(png_ptr, &info_ptr);
-      }
-
-      png_destroy_write_struct(&png_ptr, NULL);
-   }
-
-   return png_image_error(image, "png_image_read: out of memory");
-}
-
-/* Arguments to png_image_write_main: */
-typedef struct
-{
-   /* Arguments: */
-   png_imagep      image;
-   png_const_voidp buffer;
-   png_int_32      row_stride;
-   int             convert_to_8bit;
-   /* Local variables: */
-   png_const_voidp first_row;
-   ptrdiff_t       row_bytes;
-   png_voidp       local_row;
-} png_image_write_control;
-
-/* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to
- * do any necessary byte swapping.  The component order is defined by the
- * png_image format value.
- */
-static int
-png_write_image_16bit(png_voidp argument)
-{
-   png_image_write_control *display = png_voidcast(png_image_write_control*,
-      argument);
-   png_imagep image = display->image;
-   png_structp png_ptr = image->opaque->png_ptr;
-
-   png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,
-      display->first_row);
-   png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
-   png_uint_16p row_end;
-   int channels = (image->format & PNG_FORMAT_FLAG_COLOR) ? 3 : 1;
-   int aindex = 0;
-   png_uint_32 y = image->height;
-
-   if (image->format & PNG_FORMAT_FLAG_ALPHA)
-   {
-      if (image->format & PNG_FORMAT_FLAG_AFIRST)
-      {
-         aindex = -1;
-         ++input_row; /* To point to the first component */
-         ++output_row;
-      }
-
-      else
-         aindex = channels;
-   }
-
-   else
-      png_error(png_ptr, "png_write_image: internal call error");
-
-   /* Work out the output row end and count over this, note that the increment
-    * above to 'row' means that row_end can actually be beyond the end of the
-    * row; this is correct.
-    */
-   row_end = output_row + image->width * (channels+1);
-
-   while (y-- > 0)
-   {
-      png_const_uint_16p in_ptr = input_row;
-      png_uint_16p out_ptr = output_row;
-
-      while (out_ptr < row_end)
-      {
-         png_uint_16 alpha = in_ptr[aindex];
-         png_uint_32 reciprocal = 0;
-         int c;
-
-         out_ptr[aindex] = alpha;
-
-         /* Calculate a reciprocal.  The correct calculation is simply
-          * component/alpha*65535 << 15. (I.e. 15 bits of precision); this
-          * allows correct rounding by adding .5 before the shift.  'reciprocal'
-          * is only initialized when required.
-          */
-         if (alpha > 0 && alpha < 65535)
-            reciprocal = ((0xffff<<15)+(alpha>>1))/alpha;
-
-         c = channels;
-         do /* always at least one channel */
-         {
-            png_uint_16 component = *in_ptr++;
-
-            /* The following gives 65535 for an alpha of 0, which is fine,
-             * otherwise if 0/0 is represented as some other value there is more
-             * likely to be a discontinuity which will probably damage
-             * compression when moving from a fully transparent area to a
-             * nearly transparent one.  (The assumption here is that opaque
-             * areas tend not to be 0 intensity.)
-             */
-            if (component >= alpha)
-               component = 65535;
-
-            /* component<alpha, so component/alpha is less than one and
-             * component*reciprocal is less than 2^31.
-             */
-            else if (component > 0 && alpha < 65535)
-            {
-               png_uint_32 calc = component * reciprocal;
-               calc += 16384; /* round to nearest */
-               component = (png_uint_16)(calc >> 15);
-            }
-
-            *out_ptr++ = component;
-         }
-         while (--c > 0);
-
-         /* Skip to next component (skip the intervening alpha channel) */
-         ++in_ptr;
-         ++out_ptr;
-      }
-
-      png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row));
-      input_row += display->row_bytes/(sizeof (png_uint_16));
-   }
-
-   return 1;
-}
-
-/* Given 16-bit input (1 to 4 channels) write 8-bit output.  If an alpha channel
- * is present it must be removed from the components, the components are then
- * written in sRGB encoding.  No components are added or removed.
- */
-static int
-png_write_image_8bit(png_voidp argument)
-{
-   png_image_write_control *display = png_voidcast(png_image_write_control*,
-      argument);
-   png_imagep image = display->image;
-   png_structp png_ptr = image->opaque->png_ptr;
-
-   png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,
-      display->first_row);
-   png_bytep output_row = png_voidcast(png_bytep, display->local_row);
-   png_uint_32 y = image->height;
-   int channels = (image->format & PNG_FORMAT_FLAG_COLOR) ? 3 : 1;
-
-   if (image->format & PNG_FORMAT_FLAG_ALPHA)
-   {
-      png_bytep row_end;
-      int aindex;
-
-      if (image->format & PNG_FORMAT_FLAG_AFIRST)
-      {
-         aindex = -1;
-         ++input_row; /* To point to the first component */
-         ++output_row;
-      }
-
-      else
-         aindex = channels;
-
-      /* Use row_end in place of a loop counter: */
-      row_end = output_row + image->width * (channels+1);
-
-      while (y-- > 0)
-      {
-         png_const_uint_16p in_ptr = input_row;
-         png_bytep out_ptr = output_row;
-
-         if (aindex != 0) while (out_ptr < row_end) /* Alpha channel case */
-         {
-            png_uint_16 alpha = in_ptr[aindex];
-            png_uint_32 reciprocal = 0;
-            int c;
-
-            /* Scale and write the alpha channel.  See pngrtran.c
-             * png_do_scale_16_to_8 for a discussion of this calculation.  The
-             * code here has machine native values, so use:
-             *
-             *    (V * 255 + 32895) >> 16
-             */
-            out_ptr[aindex] = (png_byte)((alpha * 255 + 32895) >> 16);
-
-            /* Calculate a reciprocal.  As above the calculation can be done to
-             * 15 bits of accuracy, however the output needs to be scaled in the
-             * range 0..255*65535, so include that scaling here.
-             */
-            if (alpha > 0 && alpha < 65535)
-               reciprocal = (((0xffff*0xff)<<7)+(alpha>>1))/alpha;
-
-            c = channels;
-            do /* always at least one channel */
-            {
-               /* Need 32 bit accuracy in the sRGB tables */
-               png_uint_32 component = *in_ptr++;
-
-               /* The following gives 1.0 for an alpha of 0, which is fine,
-                * otherwise if 0/0 is represented as some other value there is
-                * more likely to be a discontinuity which will probably damage
-                * compression when moving from a fully transparent area to a
-                * nearly transparent one.  (The assumption here is that opaque
-                * areas tend not to be 0 intensity.)
-                */
-               if (component >= alpha)
-                  *out_ptr++ = 255;
-
-               /* component<alpha, so component/alpha is less than one and
-                * component*reciprocal is less than 2^31.
-                */
-               else if (component > 0)
-               {
-                  if (alpha < 65535)
-                  {
-                     component *= reciprocal;
-                     component += 64; /* round to nearest */
-                     component >>= 7;
-                  }
-
-                  else
-                     component *= 255;
-
-                  /* Convert the component to sRGB. */
-                  *out_ptr++ = (png_byte)PNG_sRGB_FROM_LINEAR(component);
-               }
-
-               else
-                  *out_ptr++ = 0;
-            }
-            while (--c > 0);
-
-            /* Skip to next component (skip the intervening alpha channel) */
-            ++in_ptr;
-            ++out_ptr;
-         } /* while out_ptr < row_end */
-
-         png_write_row(png_ptr, png_voidcast(png_const_bytep,
-            display->local_row));
-         input_row += display->row_bytes/(sizeof (png_uint_16));
-      } /* while y */
-   }
-
-   else
-   {
-      /* No alpha channel, so the row_end really is the end of the row and it
-       * is sufficient to loop over the components one by one.
-       */
-      png_bytep row_end = output_row + image->width * channels;
-
-      while (y-- > 0)
-      {
-         png_const_uint_16p in_ptr = input_row;
-         png_bytep out_ptr = output_row;
-
-         while (out_ptr < row_end)
-         {
-            png_uint_32 component = *in_ptr++;
-
-            component *= 255;
-            *out_ptr++ = (png_byte)PNG_sRGB_FROM_LINEAR(component);
-         }
-
-         png_write_row(png_ptr, output_row);
-         input_row += display->row_bytes/(sizeof (png_uint_16));
-      }
-   }
-
-   return 1;
-}
-
-static int
-png_image_write_main(png_voidp argument)
-{
-   png_image_write_control *display = png_voidcast(png_image_write_control*,
-      argument);
-   png_imagep image = display->image;
-   png_structp png_ptr = image->opaque->png_ptr;
-   png_infop info_ptr = image->opaque->info_ptr;
-   png_uint_32 format = image->format;
-
-   int linear = (format & PNG_FORMAT_FLAG_LINEAR) != 0; /* input */
-   int alpha = (format & PNG_FORMAT_FLAG_ALPHA) != 0;
-   int write_16bit = linear && !display->convert_to_8bit;
-
-   /* Default the 'row_stride' parameter if required. */
-   if (display->row_stride == 0)
-      display->row_stride = PNG_IMAGE_ROW_STRIDE(*image);
-
-   /* Set the required transforms then write the rows in the correct order. */
-   png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
-      write_16bit ? 16 : 8,
-      ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
-      ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
-      PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
-
-   /* Counter-intuitively the data transformations must be called *after*
-    * png_write_info, not before as in the read code, but the 'set' functions
-    * must still be called before.  Just set the color space information, never
-    * write an interlaced image.
-    */
-   if (write_16bit)
-   {
-      /* The gamma here is 1.0 (linear) and the cHRM chunk matches sRGB. */
-      png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_LINEAR);
-
-      if (!(image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB))
-         png_set_cHRM_fixed(png_ptr, info_ptr,
-            /* color      x       y */
-            /* white */ 31270, 32900,
-            /* red   */ 64000, 33000,
-            /* green */ 30000, 60000,
-            /* blue  */ 15000,  6000
-         );
-   }
-
-   else if (!(image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB))
-      png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_PERCEPTUAL);
-
-   /* Else writing an 8-bit file and the *colors* aren't sRGB, but the 8-bit
-    * space must still be gamma encoded.
-    */
-   else
-      png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE);
-
-   /* Write the file header. */
-   png_write_info(png_ptr, info_ptr);
-
-   /* Now set up the data transformations (*after* the header is written),
-    * remove the handled transformations from the 'format' flags for checking.
-    *
-    * First check for a little endian system if writing 16 bit files.
-    */
-   if (write_16bit)
-   {
-      PNG_CONST png_uint_16 le = 0x0001;
-
-      if (*(png_const_bytep)&le)
-         png_set_swap(png_ptr);
-   }
-
-#  ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
-      if (format & PNG_FORMAT_FLAG_BGR)
-      {
-         if (format & PNG_FORMAT_FLAG_COLOR)
-            png_set_bgr(png_ptr);
-         format &= ~PNG_FORMAT_FLAG_BGR;
-      }
-#  endif
-
-#  ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
-      if (format & PNG_FORMAT_FLAG_AFIRST)
-      {
-         if (format & PNG_FORMAT_FLAG_ALPHA)
-            png_set_swap_alpha(png_ptr);
-         format &= ~PNG_FORMAT_FLAG_AFIRST;
-      }
-#  endif
-
-   /* That should have handled all (both) the transforms. */
-   if ((format & ~(png_uint_32)(PNG_FORMAT_FLAG_COLOR | PNG_FORMAT_FLAG_LINEAR |
-         PNG_FORMAT_FLAG_ALPHA)) != 0)
-      png_error(png_ptr, "png_write_image: unsupported transformation");
-
-   {
-      png_const_bytep row = png_voidcast(png_const_bytep, display->buffer);
-      ptrdiff_t row_bytes = display->row_stride;
-
-      if (linear)
-         row_bytes *= sizeof (png_uint_16);
-
-      if (row_bytes < 0)
-         row += (image->height-1) * (-row_bytes);
-
-      display->first_row = row;
-      display->row_bytes = row_bytes;
-   }
-
-   /* Check for the cases that currently require a pre-transform on the row
-    * before it is written.  This only applies when the input is 16-bit and
-    * either there is an alpha channel or it is converted to 8-bit.
-    */
-   if ((linear && alpha) || display->convert_to_8bit)
-   {
-      png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
-         png_get_rowbytes(png_ptr, info_ptr)));
-      int result;
-
-      display->local_row = row;
-      if (write_16bit)
-         result = png_safe_execute(image, png_write_image_16bit, display);
-      else
-         result = png_safe_execute(image, png_write_image_8bit, display);
-      display->local_row = NULL;
-
-      png_free(png_ptr, row);
-
-      /* Skip the 'write_end' on error: */
-      if (!result)
-         return 0;
-   }
-
-   /* Otherwise this is the case where the input is in a format currently
-    * supported by the rest of the libpng write code; call it directly.
-    */
-   else
-   {
-      png_const_bytep row = png_voidcast(png_const_bytep, display->first_row);
-      ptrdiff_t row_bytes = display->row_bytes;
-      png_uint_32 y = image->height;
-
-      while (y-- > 0)
-      {
-         png_write_row(png_ptr, row);
-         row += row_bytes;
-      }
-   }
-
-   png_write_end(png_ptr, info_ptr);
-   return 1;
-}
-
-int PNGAPI
-png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
-   const void *buffer, png_int_32 row_stride)
-{
-   /* Write the image to the given (FILE*). */
-   if (image != NULL)
-   {
-      if (file != NULL)
-      {
-         if (png_image_write_init(image))
-         {
-            png_image_write_control display;
-            int result;
-
-            /* This is slightly evil, but png_init_io doesn't do anything other
-             * than this and we haven't changed the standard IO functions so
-             * this saves a 'safe' function.
-             */
-            image->opaque->png_ptr->io_ptr = file;
-
-            memset(&display, 0, sizeof display);
-            display.image = image;
-            display.buffer = buffer;
-            display.row_stride = row_stride;
-            display.convert_to_8bit = convert_to_8bit;
-
-            result = png_safe_execute(image, png_image_write_main, &display);
-            png_image_free(image);
-            return result;
-         }
-
-         else
-            return 0;
-      }
-
-      else
-         return png_image_error(image,
-            "png_image_write_to_stdio: invalid argument");
-   }
-
-   else
-      return 0;
-}
-
-int PNGAPI
-png_image_write_to_file(png_imagep image, const char *file_name,
-   int convert_to_8bit, const void *buffer, png_int_32 row_stride)
-{
-   /* Write the image to the named file. */
-   if (image != NULL)
-   {
-      if (file_name != NULL)
-      {
-         FILE *fp = fopen(file_name, "wb");
-
-         if (fp != NULL)
-         {
-            if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer,
-               row_stride))
-            {
-               int error; /* from fflush/fclose */
-
-               /* Make sure the file is flushed correctly. */
-               if (fflush(fp) == 0 && ferror(fp) == 0)
-               {
-                  if (fclose(fp) == 0)
-                     return 1;
-
-                  error = errno; /* from fclose */
-               }
-
-               else
-               {
-                  error = errno; /* from fflush or ferror */
-                  (void)fclose(fp);
-               }
-
-               (void)remove(file_name);
-               /* The image has already been cleaned up; this is just used to
-                * set the error (because the original write succeeded).
-                */
-               return png_image_error(image, strerror(error));
-            }
-
-            else
-            {
-               /* Clean up: just the opened file. */
-               (void)fclose(fp);
-               (void)remove(file_name);
-               return 0;
-            }
-         }
-
-         else
-            return png_image_error(image, strerror(errno));
-      }
-
-      else
-         return png_image_error(image,
-            "png_image_write_to_file: invalid argument");
-   }
-
-   else
-      return 0;
-}
-#endif /* PNG_STDIO_SUPPORTED */
-#endif /* SIMPLIFIED_WRITE */
 #endif /* PNG_WRITE_SUPPORTED */
diff --git a/projects/owatcom/libpng.wpj b/projects/owatcom/libpng.wpj
index fe7583f..aaea64a 100644
--- a/projects/owatcom/libpng.wpj
+++ b/projects/owatcom/libpng.wpj
@@ -7,7 +7,7 @@
 256
 0
 8960
-9294
+9284
 2
 MProject
 3
@@ -25,7 +25,7 @@
 MCommand
 19
 @type pngconfig.inf
-4
+3
 5
 WFileName
 10
@@ -39,74 +39,54 @@
 12
 pngvalid.tgt
 8
-WFileName
-12
-pngstest.tgt
-9
 WVList
-4
-10
+3
+9
 VComponent
-11
+10
 WRect
 0
 0
-5638
-4174
+5632
+4164
 0
 0
-12
+11
 WFileName
 10
 libpng.tgt
 0
 0
-13
+12
 VComponent
-14
+13
 WRect
 1280
-1550
-5638
-4174
+1540
+5632
+4164
 0
 0
-15
+14
 WFileName
 11
 pngtest.tgt
 0
 1
-16
+15
 VComponent
-17
+16
 WRect
-524
-497
-5638
-4174
+518
+487
+5632
+4164
 0
 0
-18
+17
 WFileName
 12
 pngvalid.tgt
 0
 1
-19
-VComponent
-20
-WRect
-2054
-2701
-5674
-4232
-0
-0
-21
-WFileName
-12
-pngstest.tgt
-0
-1
-19
+9
diff --git a/projects/owatcom/pngstest.tgt b/projects/owatcom/pngstest.tgt
index e589f02..e69de29 100644
--- a/projects/owatcom/pngstest.tgt
+++ b/projects/owatcom/pngstest.tgt
@@ -1,219 +0,0 @@
-40
-targetIdent
-0
-MProject
-1
-MComponent
-0
-2
-WString
-4
-NEXE
-3
-WString
-5
-nc2en
-1
-0
-0
-4
-MCommand
-0
-5
-MCommand
-1035
-pngstest --log ../../contrib/pngsuite/basn0g01.png ../../contrib/pngsuite/basn0g02.png ../../contrib/pngsuite/basn0g04.png ../../contrib/pngsuite/basn0g08.png ../../contrib/pngsuite/basn0g16.png ../../contrib/pngsuite/basn2c08.png ../../contrib/pngsuite/basn2c16.png ../../contrib/pngsuite/basn3p01.png ../../contrib/pngsuite/basn3p02.png ../../contrib/pngsuite/basn3p04.png ../../contrib/pngsuite/basn3p08.png ../../contrib/pngsuite/basn4a08.png ../../contrib/pngsuite/basn4a16.png ../../contrib/pngsuite/basn6a08.png ../../contrib/pngsuite/basn6a16.png ../../contrib/pngsuite/ftbbn1g04.png ../../contrib/pngsuite/ftbbn2c16.png ../../contrib/pngsuite/ftbbn3p08.png ../../contrib/pngsuite/ftbgn2c16.png ../../contrib/pngsuite/ftbgn3p08.png ../../contrib/pngsuite/ftbrn2c08.png ../../contrib/pngsuite/ftbwn1g16.png ../../contrib/pngsuite/ftbwn3p08.png ../../contrib/pngsuite/ftbyn3p08.png ../../contrib/pngsuite/ftp0n1g08.png ../../contrib/pngsuite/ftp0n2c08.png ../../contrib/pngsuite/ftp0n3p08.png ../../contrib/pngsuite/ftp1n3p08.png
-6
-MItem
-12
-pngstest.exe
-7
-WString
-4
-NEXE
-8
-WVList
-6
-9
-MVState
-10
-WString
-7
-WINLINK
-11
-WString
-11
-?????Stack:
-1
-12
-WString
-4
-768k
-0
-13
-MVState
-14
-WString
-7
-WINLINK
-15
-WString
-28
-?????Library directories(;):
-1
-16
-WString
-8
-$(%zlib)
-0
-17
-MVState
-18
-WString
-7
-WINLINK
-19
-WString
-18
-?????Libraries(,):
-1
-20
-WString
-19
-libpng.lib zlib.lib
-0
-21
-MVState
-22
-WString
-7
-WINLINK
-23
-WString
-11
-?????Stack:
-0
-24
-WString
-4
-768k
-0
-25
-MVState
-26
-WString
-7
-WINLINK
-27
-WString
-28
-?????Library directories(;):
-0
-28
-WString
-8
-$(%zlib)
-0
-29
-MVState
-30
-WString
-7
-WINLINK
-31
-WString
-18
-?????Libraries(,):
-0
-32
-WString
-19
-libpng.lib zlib.lib
-0
-33
-WVList
-1
-34
-ActionStates
-35
-WString
-4
-&Run
-36
-WVList
-0
--1
-1
-1
-0
-37
-WPickList
-2
-38
-MItem
-3
-*.c
-39
-WString
-4
-COBJ
-40
-WVList
-2
-41
-MVState
-42
-WString
-3
-WCC
-43
-WString
-25
-n????Include directories:
-1
-44
-WString
-39
-"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt"
-0
-45
-MVState
-46
-WString
-3
-WCC
-47
-WString
-25
-n????Include directories:
-0
-48
-WString
-39
-"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt"
-0
-49
-WVList
-0
--1
-1
-1
-0
-50
-MItem
-33
-..\..\contrib\libtests\pngstest.c
-51
-WString
-4
-COBJ
-52
-WVList
-0
-53
-WVList
-0
-38
-1
-1
-0
diff --git a/projects/vstudio/pngstest/pngstest.vcxproj b/projects/vstudio/pngstest/pngstest.vcxproj
index 58d7236..e69de29 100644
--- a/projects/vstudio/pngstest/pngstest.vcxproj
+++ b/projects/vstudio/pngstest/pngstest.vcxproj
@@ -1,218 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug Library|Win32">
-      <Configuration>Debug Library</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release Library|Win32">
-      <Configuration>Release Library</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}</ProjectGuid>
-    <Keyword>Win32Proj</Keyword>
-    <RootNamespace>pngstest</RootNamespace>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <Import Project="$(SolutionDir)\zlib.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-    <CustomBuildAfterTargets />
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-    <CustomBuildAfterTargets />
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-    <CustomBuildAfterTargets />
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-    <CustomBuildAfterTargets />
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <MinimalRebuild>false</MinimalRebuild>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <Optimization>Disabled</Optimization>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
-      <CompileAsManaged>false</CompileAsManaged>
-      <TreatWarningAsError>true</TreatWarningAsError>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <StringPooling>true</StringPooling>
-      <FunctionLevelLinking>false</FunctionLevelLinking>
-      <BrowseInformation>true</BrowseInformation>
-      <FloatingPointExceptions>false</FloatingPointExceptions>
-    </ClCompile>
-    <Link>
-      <SubSystem>Console</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
-      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
-    </Link>
-    <CustomBuildStep>
-      <Message>Executing libpng simplified API test program</Message>
-      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
-      <Outputs>$(IntDir)pngstest.out</Outputs>
-      <Inputs>$(OutDir)pngstest.exe</Inputs>
-    </CustomBuildStep>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
-    <ClCompile>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <WarningLevel>Level4</WarningLevel>
-      <MinimalRebuild>false</MinimalRebuild>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <Optimization>Disabled</Optimization>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
-      <CompileAsManaged>false</CompileAsManaged>
-      <TreatWarningAsError>true</TreatWarningAsError>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <StringPooling>true</StringPooling>
-      <FunctionLevelLinking>false</FunctionLevelLinking>
-      <BrowseInformation>true</BrowseInformation>
-      <FloatingPointExceptions>false</FloatingPointExceptions>
-    </ClCompile>
-    <Link>
-      <SubSystem>Console</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
-      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
-    </Link>
-    <CustomBuildStep>
-      <Message>Executing libpng simplified API test program</Message>
-      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
-      <Outputs>$(IntDir)pngstest.out</Outputs>
-      <Inputs>$(OutDir)pngstest.exe</Inputs>
-    </CustomBuildStep>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level4</WarningLevel>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <Optimization>Full</Optimization>
-      <FunctionLevelLinking>false</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
-      <CompileAsManaged>false</CompileAsManaged>
-      <TreatWarningAsError>true</TreatWarningAsError>
-      <StringPooling>true</StringPooling>
-      <MinimalRebuild>false</MinimalRebuild>
-      <BrowseInformation>true</BrowseInformation>
-      <WholeProgramOptimization>true</WholeProgramOptimization>
-      <FloatingPointExceptions>false</FloatingPointExceptions>
-    </ClCompile>
-    <Link>
-      <SubSystem>Console</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
-      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
-      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
-    </Link>
-    <CustomBuildStep>
-      <Message>Executing libpng simplified API test program</Message>
-      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
-      <Outputs>$(IntDir)pngstest.out</Outputs>
-      <Inputs>$(OutDir)pngstest.exe</Inputs>
-    </CustomBuildStep>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
-    <ClCompile>
-      <WarningLevel>Level4</WarningLevel>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <Optimization>Full</Optimization>
-      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
-      <FunctionLevelLinking>false</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
-      <CompileAsManaged>false</CompileAsManaged>
-      <TreatWarningAsError>true</TreatWarningAsError>
-      <StringPooling>true</StringPooling>
-      <MinimalRebuild>false</MinimalRebuild>
-      <BrowseInformation>true</BrowseInformation>
-      <WholeProgramOptimization>true</WholeProgramOptimization>
-      <FloatingPointExceptions>false</FloatingPointExceptions>
-    </ClCompile>
-    <Link>
-      <SubSystem>Console</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
-      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
-      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
-    </Link>
-    <CustomBuildStep>
-      <Message>Executing libpng simplified API test program</Message>
-      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
-      <Outputs>$(IntDir)pngstest.out</Outputs>
-      <Inputs>$(OutDir)pngstest.exe</Inputs>
-    </CustomBuildStep>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\..\contrib\libtests\pngstest.c" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
-</Project>
diff --git a/projects/vstudio/pngstest/pngstest.vcxproj.orig b/projects/vstudio/pngstest/pngstest.vcxproj.orig
new file mode 100644
index 0000000..58d7236
--- /dev/null
+++ b/projects/vstudio/pngstest/pngstest.vcxproj.orig
@@ -0,0 +1,218 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug Library|Win32">
+      <Configuration>Debug Library</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release Library|Win32">
+      <Configuration>Release Library</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>pngstest</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <Import Project="$(SolutionDir)\zlib.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <CustomBuildAfterTargets />
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <CustomBuildAfterTargets />
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <CustomBuildAfterTargets />
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <CustomBuildAfterTargets />
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>
+      <WarningLevel>Level4</WarningLevel>
+      <MinimalRebuild>false</MinimalRebuild>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
+      <CompileAsManaged>false</CompileAsManaged>
+      <TreatWarningAsError>true</TreatWarningAsError>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <StringPooling>true</StringPooling>
+      <FunctionLevelLinking>false</FunctionLevelLinking>
+      <BrowseInformation>true</BrowseInformation>
+      <FloatingPointExceptions>false</FloatingPointExceptions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
+    </Link>
+    <CustomBuildStep>
+      <Message>Executing libpng simplified API test program</Message>
+      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
+      <Outputs>$(IntDir)pngstest.out</Outputs>
+      <Inputs>$(OutDir)pngstest.exe</Inputs>
+    </CustomBuildStep>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>
+      <WarningLevel>Level4</WarningLevel>
+      <MinimalRebuild>false</MinimalRebuild>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
+      <CompileAsManaged>false</CompileAsManaged>
+      <TreatWarningAsError>true</TreatWarningAsError>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <StringPooling>true</StringPooling>
+      <FunctionLevelLinking>false</FunctionLevelLinking>
+      <BrowseInformation>true</BrowseInformation>
+      <FloatingPointExceptions>false</FloatingPointExceptions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
+    </Link>
+    <CustomBuildStep>
+      <Message>Executing libpng simplified API test program</Message>
+      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
+      <Outputs>$(IntDir)pngstest.out</Outputs>
+      <Inputs>$(OutDir)pngstest.exe</Inputs>
+    </CustomBuildStep>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level4</WarningLevel>
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Full</Optimization>
+      <FunctionLevelLinking>false</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
+      <CompileAsManaged>false</CompileAsManaged>
+      <TreatWarningAsError>true</TreatWarningAsError>
+      <StringPooling>true</StringPooling>
+      <MinimalRebuild>false</MinimalRebuild>
+      <BrowseInformation>true</BrowseInformation>
+      <WholeProgramOptimization>true</WholeProgramOptimization>
+      <FloatingPointExceptions>false</FloatingPointExceptions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
+      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
+    </Link>
+    <CustomBuildStep>
+      <Message>Executing libpng simplified API test program</Message>
+      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
+      <Outputs>$(IntDir)pngstest.out</Outputs>
+      <Inputs>$(OutDir)pngstest.exe</Inputs>
+    </CustomBuildStep>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
+    <ClCompile>
+      <WarningLevel>Level4</WarningLevel>
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Full</Optimization>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <FunctionLevelLinking>false</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
+      <CompileAsManaged>false</CompileAsManaged>
+      <TreatWarningAsError>true</TreatWarningAsError>
+      <StringPooling>true</StringPooling>
+      <MinimalRebuild>false</MinimalRebuild>
+      <BrowseInformation>true</BrowseInformation>
+      <WholeProgramOptimization>true</WholeProgramOptimization>
+      <FloatingPointExceptions>false</FloatingPointExceptions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
+      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
+    </Link>
+    <CustomBuildStep>
+      <Message>Executing libpng simplified API test program</Message>
+      <Command>"$(OutDir)pngstest.exe" --log --touch "$(IntDir)pngstest.out" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn1g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn1g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n1g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>
+      <Outputs>$(IntDir)pngstest.out</Outputs>
+      <Inputs>$(OutDir)pngstest.exe</Inputs>
+    </CustomBuildStep>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\..\contrib\libtests\pngstest.c" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
diff --git a/projects/vstudio/readme.txt b/projects/vstudio/readme.txt
index 9db30d0..a08ac3d 100644
--- a/projects/vstudio/readme.txt
+++ b/projects/vstudio/readme.txt
@@ -1,7 +1,7 @@
 
 VisualStudio instructions
 
-libpng version 1.5.7beta05 - November 18, 2011
+libpng version 1.5.7beta05 - November 23, 2011
 
 Copyright (c) 1998-2010 Glenn Randers-Pehrson
 
diff --git a/projects/vstudio/vstudio.sln b/projects/vstudio/vstudio.sln
index 215ed0e..4ab6641 100644
--- a/projects/vstudio/vstudio.sln
+++ b/projects/vstudio/vstudio.sln
@@ -24,13 +24,6 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pnglibconf", "pnglibconf\pnglibconf.vcxproj", "{EB33566E-DA7F-4D28-9077-88C0B7C77E35}"
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngstest", "pngstest\pngstest.vcxproj", "{277AC57F-313B-4D06-B119-A3CDB672D2FF}"
-	ProjectSection(ProjectDependencies) = postProject
-		{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
-		{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}
-		{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}
-	EndProjectSection
-EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug Library|Win32 = Debug Library|Win32
diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props
index aae2786..7645bb7 100644
--- a/projects/vstudio/zlib.props
+++ b/projects/vstudio/zlib.props
@@ -2,7 +2,7 @@
 <!--
  * zlib.props - location of zlib source
  *
- * libpng version 1.5.7beta05 - November 18, 2011
+ * libpng version 1.5.7beta05 - November 23, 2011
  *
  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  *
diff --git a/scripts/README.txt b/scripts/README.txt
index 2cabf82..c1a2d19 100644
--- a/scripts/README.txt
+++ b/scripts/README.txt
@@ -1,5 +1,5 @@
 
-Makefiles for  libpng version 1.5.7beta05 - November 18, 2011
+Makefiles for  libpng version 1.5.7beta05 - November 23, 2011
 
 pnglibconf.h.prebuilt       =>  Stores configuration settings
  makefile.linux    =>  Linux/ELF makefile
diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa
index 548c661..8f8ec86 100644
--- a/scripts/pnglibconf.dfa
+++ b/scripts/pnglibconf.dfa
@@ -576,31 +576,3 @@
 # leave the row_pointers member out of the info structure.
 
 option INFO_IMAGE
-
-# Simplified API options
-# Read:
-option SIMPLIFIED_READ requires SEQUENTIAL_READ READ_TRANSFORMS SETJMP
-option SIMPLIFIED_READ enables READ_EXPAND READ_16BIT READ_EXPAND_16
-option SIMPLIFIED_READ enables READ_SCALE_16_TO_8 READ_RGB_TO_GRAY
-option SIMPLIFIED_READ enables READ_ALPHA_MODE READ_BACKGROUND READ_STRIP_ALPHA
-option SIMPLIFIED_READ enables READ_FILLER READ_SWAP
-
-option SIMPLIFIED_READ_AFIRST requires SIMPLIFIED_READ disabled
-option READ_SWAP_ALPHA enables SIMPLIFIED_READ_AFIRST
-
-option SIMPLIFIED_READ_BGR requires SIMPLIFIED_READ disabled
-option READ_BGR enables SIMPLIFIED_READ_BGR
-
-# Write:
-option SIMPLIFIED_WRITE requires WRITE STDIO SETJMP
-option SIMPLIFIED_WRITE enables WRITE_SWAP WRITE_gAMA WRITE_sRGB WRITE_cHRM
-
-option SIMPLIFIED_WRITE_AFIRST requires SIMPLIFIED_WRITE disabled
-option WRITE_SWAP_ALPHA enables SIMPLIFIED_WRITE_AFIRST
-
-option SIMPLIFIED_WRITE_BGR requires SIMPLIFIED_WRITE disabled
-option WRITE_BGR enables SIMPLIFIED_WRITE_BGR
-
-# Formats:
-option FORMAT_AFIRST if SIMPLIFIED_READ_AFIRST SIMPLIFIED_WRITE_AFIRST
-option FORMAT_BGR if SIMPLIFIED_READ_BGR SIMPLIFIED_WRITE_BGR
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index c101cf2..198f386 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -3,7 +3,7 @@
 
 /* pnglibconf.h - library build configuration */
 
-/* Libpng 1.5.7beta05 - November 18, 2011 */
+/* Libpng 1.5.7beta05 - November 23, 2011 */
 
 /* Copyright (c) 1998-2011 Glenn Randers-Pehrson */
 
@@ -128,12 +128,6 @@
 #define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
 #define PNG_SETJMP_SUPPORTED
 #define PNG_SET_USER_LIMITS_SUPPORTED
-#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
-#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED
-#define PNG_SIMPLIFIED_READ_SUPPORTED
-#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
-#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
-#define PNG_SIMPLIFIED_WRITE_SUPPORTED
 #define PNG_sPLT_SUPPORTED
 #define PNG_sRGB_SUPPORTED
 #define PNG_STDIO_SUPPORTED
diff --git a/scripts/symbols.def b/scripts/symbols.def
index 11d3e03..25ca78a 100644
--- a/scripts/symbols.def
+++ b/scripts/symbols.def
@@ -239,10 +239,3 @@
  png_get_cHRM_XYZ_fixed @231
  png_set_cHRM_XYZ @232
  png_set_cHRM_XYZ_fixed @233
- png_image_begin_read_from_file @234
- png_image_begin_read_from_stdio @235
- png_image_begin_read_from_memory @236
- png_image_finish_read @237
- png_image_free @238
- png_image_write_to_file @239
- png_image_write_to_stdio @240
diff --git a/test-pngstest.sh b/test-pngstest.sh
deleted file mode 100755
index e1d6674..0000000
--- a/test-pngstest.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-#
-# Run the simplified API tests
-err=0
-
-echo >> pngtest-log.txt
-echo "============ pngstest.sh ==============" >> pngtest-log.txt
-
-echo "Running test-pngstest.sh on contrib/pngsuite/*.png"
-for opts in "" "--background"
-do
-   if ./pngstest --log "$@" $opts ${srcdir}/contrib/pngsuite/*.png \
-      >>pngtest-log.txt 2>&1
-   then
-      echo "  PASS: pngstest $opts"
-   else
-      echo "  FAIL: pngstest $opts"
-      err=1
-   fi
-done
-   
-exit $err