Imported from libpng-1.4.0beta51.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index b4e44d9..0fdaeb6 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.4.0beta50 - March 9, 2009
+Libpng 1.4.0beta51 - March 21, 2009
 
 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.
@@ -9,27 +9,27 @@
 Source files with LF line endings (for Unix/Linux) and with a
 "configure" script
 
-   1.4.0beta50.tar.gz
-   1.4.0beta50.tar.bz2
+   1.4.0beta51.tar.gz
+   1.4.0beta51.tar.bz2
 
 Source files with LF line endings (for Unix/Linux) without the
 "configure" script
 
-   1.4.0beta50-no-config.tar.gz
-   1.4.0beta50-no-config.tar.bz2
+   1.4.0beta51-no-config.tar.gz
+   1.4.0beta51-no-config.tar.bz2
 
 Source files with CRLF line endings (for Windows), without the
 "configure" script
 
-   lp140b50.zip
-   lp140b50.tar.bz2
+   lp140b51.zip
+   lp140b51.tar.bz2
 
 Other information:
 
-   1.4.0beta50-README.txt
-   1.4.0beta50-KNOWNBUGS.txt
-   1.4.0beta50-LICENSE.txt
-   1.4.0beta50-Y2K-compliance.txt
+   1.4.0beta51-README.txt
+   1.4.0beta51-KNOWNBUGS.txt
+   1.4.0beta51-LICENSE.txt
+   1.4.0beta51-Y2K-compliance.txt
 
 Changes since the last public release (1.2.10):
 
@@ -343,7 +343,7 @@
   Added check for zero-area RGB cHRM triange in png_check_cHRM() and
     png_check_cHRM_fixed().
 
-version 1.4.0beta39 [March 9, 2009]
+version 1.4.0beta39 [March 21, 2009]
   Revised png_warning() to write its message on standard output by default
     when warning_fn is NULL.
 
@@ -392,9 +392,19 @@
     (bug introduced in libpng-1.2.34/1.4.0beta29).
   Revised comments in png_set_read_fn() and png_set_write_fn().
 
-version 1.4.0beta50 [March 9, 2009]
+version 1.4.0beta50 [March 21, 2009]
   Use png_calloc() instead of png_malloc() to allocate big_row_buf when
     reading an interlaced file, to avoid a possible UMR.
+  Undid recent revision of PNG_NO_STDIO version of png_write_flush().  Users
+    having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined
+    or supply their own flush_fn() replacement.
+  Revised libpng*.txt and png.h documentation about use of png_write_flush()
+    and png_set_write_fn().
+  Removed fflush() from pngtest.c.
+  Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h
+
+version 1.4.0beta51 [March 21, 2009]
+  Removed new png_fileno() macro from pngconf.h .
 
 version 1.4.0betaN [future]
   Build shared libraries with -lz and sometimes -lm.
diff --git a/CHANGES b/CHANGES
index 9156366..d4fda86 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2068,9 +2068,19 @@
     (bug introduced in libpng-1.2.34/1.4.0beta29).
   Revised comments in png_set_read_fn() and png_set_write_fn().
 
-version 1.4.0beta50 [March 9, 2009]
+version 1.4.0beta50 [March 21, 2009]
   Use png_calloc() instead of png_malloc() to allocate big_row_buf when
     reading an interlaced file, to avoid a possible UMR.
+  Undid revision of PNG_NO_STDIO version of png_write_flush().  Users
+    having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined
+    or supply their own flush_fn() replacement.
+  Revised libpng*.txt and png.h documentation about use of png_write_flush()
+    and png_set_write_fn().
+  Removed fflush() from pngtest.c.
+  Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h
+
+version 1.4.0beta51 [March 21, 2009]
+  Removed new png_fileno() macro from pngconf.h .
 
 version 1.4.0betaN [future]
   Build shared libraries with -lz and sometimes -lm.
diff --git a/INSTALL b/INSTALL
index cdb5b43..054d0e2 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
 
-Installing libpng version 1.4.0beta50 - March 9, 2009
+Installing libpng version 1.4.0beta51 - March 21, 2009
 
 On Unix/Linux and similar systems, you can simply type
 
@@ -44,7 +44,7 @@
 correspond to the version of zlib that's installed.
 
 You can rename the directories that you downloaded (they
-might be called "libpng-1.4.0beta50" or "lpng109" and "zlib-1.2.1"
+might be called "libpng-1.4.0beta51" or "lpng109" and "zlib-1.2.1"
 or "zlib121") so that you have directories called "zlib" and "libpng".
 
 Your directory structure should look like this:
@@ -95,14 +95,14 @@
  CMakeLists.txt    =>  "cmake" script
  makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)
  makefile.elf      =>  Linux/ELF makefile symbol versioning,
-                       gcc, creates libpng14.so.14.1.4.0beta50)
+                       gcc, creates libpng14.so.14.1.4.0beta51)
  makefile.linux    =>  Linux/ELF makefile
-                       (gcc, creates libpng14.so.14.1.4.0beta50)
+                       (gcc, creates libpng14.so.14.1.4.0beta51)
  makefile.gcmmx    =>  Linux/ELF makefile
-                       (gcc, creates libpng14.so.14.1.4.0beta50,
+                       (gcc, creates libpng14.so.14.1.4.0beta51,
                        uses assembler code tuned for Intel MMX platform)
  makefile.nommx    =>  Linux/ELF makefile
-                       (gcc, creates libpng14.so.14.1.4.0beta50
+                       (gcc, creates libpng14.so.14.1.4.0beta51
                        does not use Intel MMX assembler code)
  makefile.gcc      =>  Generic makefile (gcc, creates static libpng.a)
  makefile.knr      =>  Archaic UNIX Makefile that converts files with
@@ -125,12 +125,12 @@
  makefile.openbsd  =>  OpenBSD makefile
  makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)
  makefile.sggcc    =>  Silicon Graphics (gcc,
-                       creates libpng14.so.14.1.4.0beta50)
+                       creates libpng14.so.14.1.4.0beta51)
  makefile.sunos    =>  Sun makefile
  makefile.solaris  =>  Solaris 2.X makefile (gcc,
-                       creates libpng14.so.14.1.4.0beta50)
+                       creates libpng14.so.14.1.4.0beta51)
  makefile.so9      =>  Solaris 9 makefile (gcc,
-                       creates libpng14.so.14.1.4.0beta50)
+                       creates libpng14.so.14.1.4.0beta51)
  makefile.32sunu   =>  Sun Ultra 32-bit makefile
  makefile.64sunu   =>  Sun Ultra 64-bit makefile
  makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc
diff --git a/KNOWNBUG b/KNOWNBUG
index 8abe209..ba00d2b 100644
--- a/KNOWNBUG
+++ b/KNOWNBUG
@@ -1,5 +1,5 @@
 
-Known bugs in libpng version 1.4.0beta50
+Known bugs in libpng version 1.4.0beta51
 
 1. April 22, 2001: pnggccrd.c has been reported to crash on NetBSD when
    reading interlaced PNG files, when assembler code is enabled but running
diff --git a/LICENSE b/LICENSE
index ab366ec..0f2e500 100644
--- a/LICENSE
+++ b/LICENSE
@@ -8,7 +8,7 @@
 If you modify libpng you may insert additional notices immediately following
 this sentence.
 
-libpng versions 1.2.6, August 15, 2004, through 1.4.0beta50, March 9, 2009, are
+libpng versions 1.2.6, August 15, 2004, through 1.4.0beta51, March 21, 2009, 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
@@ -106,4 +106,4 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-March 9, 2009
+March 21, 2009
diff --git a/Makefile.am b/Makefile.am
index 08b4435..9329f65 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -86,7 +86,7 @@
 	${srcdir}/contrib/pngsuite/* \
 	${srcdir}/contrib/visupng/* \
 	$(TESTS) \
-	example.c libpng-1.4.0beta50.txt pngvcrd.c 
+	example.c libpng-1.4.0beta51.txt pngvcrd.c 
 
 CLEANFILES= pngout.png libpng14.pc libpng14-config libpng.vers \
 libpng.sym
diff --git a/Makefile.in b/Makefile.in
index 48979a5..8cf7ac2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -331,7 +331,7 @@
 	${srcdir}/contrib/pngsuite/* \
 	${srcdir}/contrib/visupng/* \
 	$(TESTS) \
-	example.c libpng-1.4.0beta50.txt pngvcrd.c 
+	example.c libpng-1.4.0beta51.txt pngvcrd.c 
 
 CLEANFILES = pngout.png libpng14.pc libpng14-config libpng.vers \
 libpng.sym
diff --git a/README b/README
index e70af01..d3ad9bb 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.4.0beta50 - March 9, 2009 (shared library 14.0)
+README for libpng version 1.4.0beta51 - March 21, 2009 (shared library 14.0)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
@@ -184,11 +184,11 @@
        descrip.mms      =>  VMS makefile for MMS or MMK
        makefile.std     =>  Generic UNIX makefile (cc, creates static libpng.a)
        makefile.elf     =>  Linux/ELF makefile symbol versioning,
-                            gcc, creates libpng14.so.14.1.4.0beta50)
+                            gcc, creates libpng14.so.14.1.4.0beta51)
        makefile.linux   =>  Linux/ELF makefile
-                            (gcc, creates libpng14.so.14.1.4.0beta50)
+                            (gcc, creates libpng14.so.14.1.4.0beta51)
        makefile.gcmmx   =>  Linux/ELF makefile
-                            (gcc, creates libpng14.so.14.1.4.0beta50,
+                            (gcc, creates libpng14.so.14.1.4.0beta51,
                             uses assembler code tuned for Intel MMX platform)
        makefile.gcc     =>  Generic makefile (gcc, creates static libpng.a)
        makefile.knr     =>  Archaic UNIX Makefile that converts files with
@@ -210,12 +210,12 @@
        makefile.openbsd =>  OpenBSD makefile
        makefile.sgi     =>  Silicon Graphics IRIX (cc, creates static lib)
        makefile.sggcc   =>  Silicon Graphics
-                            (gcc, creates libpng14.so.14.1.4.0beta50)
+                            (gcc, creates libpng14.so.14.1.4.0beta51)
        makefile.sunos   =>  Sun makefile
        makefile.solaris =>  Solaris 2.X makefile
-                            (gcc, creates libpng14.so.14.1.4.0beta50)
+                            (gcc, creates libpng14.so.14.1.4.0beta51)
        makefile.so9     =>  Solaris 9 makefile
-                            (gcc, creates libpng14.so.14.1.4.0beta50)
+                            (gcc, creates libpng14.so.14.1.4.0beta51)
        makefile.32sunu  =>  Sun Ultra 32-bit makefile
        makefile.64sunu  =>  Sun Ultra 64-bit makefile
        makefile.sco     =>  For SCO OSr5  ELF and Unixware 7 with Native cc
diff --git a/configure b/configure
index 6b804ac..af527d9 100755
--- a/configure
+++ b/configure
Binary files differ
diff --git a/configure.ac b/configure.ac
index f468186..46c8a54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,12 +18,12 @@
 
 dnl Version number stuff here:
 
-AC_INIT([libpng], [1.4.0beta50], [png-mng-implement@lists.sourceforge.net])
+AC_INIT([libpng], [1.4.0beta51], [png-mng-implement@lists.sourceforge.net])
 AM_INIT_AUTOMAKE
 dnl stop configure from automagically running automake
 AM_MAINTAINER_MODE
 
-PNGLIB_VERSION=1.4.0beta50
+PNGLIB_VERSION=1.4.0beta51
 PNGLIB_MAJOR=1
 PNGLIB_MINOR=4
 PNGLIB_RELEASE=0
diff --git a/contrib/pngminim/encoder/pngusr.h b/contrib/pngminim/encoder/pngusr.h
index 904673a..18989d1 100644
--- a/contrib/pngminim/encoder/pngusr.h
+++ b/contrib/pngminim/encoder/pngusr.h
@@ -51,6 +51,7 @@
 #define PNG_NO_WRITE_FILTER
 #define PNG_NO_WRITE_WEIGHTED_FILTER
 #define PNG_NO_WRITE_INTERLACING_SUPPORTED
+#define PNG_NO_WRITE_FLUSH
 
 #define PNG_NO_INFO_IMAGE
 #define PNG_NO_USER_MEM
diff --git a/example.c b/example.c
index b93e0f8..ffc8da2 100644
--- a/example.c
+++ b/example.c
@@ -2,7 +2,7 @@
 #if 0 /* in case someone actually tries to compile this */
 
 /* example.c - an example of using libpng
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * This file has been placed in the public domain by the authors.
  * Maintained 1998-2009 Glenn Randers-Pehrson
  * Maintained 1996, 1997 Andreas Dilger)
@@ -342,11 +342,13 @@
    /* The easiest way to read the image: */
    png_bytep row_pointers[height];
 
+   /* Clear the pointer array */
    for (row = 0; row < height; row++)
-   {
+      row_pointers[row] = NULL;
+
+   for (row = 0; row < height; row++)
       row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr,
          info_ptr));
-   }
 
    /* Now it's time to read the image.  One of these methods is REQUIRED */
 #ifdef entire /* Read the entire image in one go */
@@ -597,7 +599,7 @@
     */
    if (setjmp(png_jmpbuf(png_ptr)))
    {
-      /* If we get here, we had a problem reading the file */
+      /* If we get here, we had a problem writing the file */
       fclose(fp);
       png_destroy_write_struct(&png_ptr, &info_ptr);
       return (ERROR);
@@ -692,7 +694,7 @@
     *   write_my_chunk();
     *   png_write_info(png_ptr, info_ptr);
     *
-    * However, given the level of known- and unknown-chunk support in 1.1.0
+    * However, given the level of known- and unknown-chunk support in 1.2.0
     * and up, this should no longer be necessary.
     */
 
@@ -771,9 +773,7 @@
 
       /* If you are only writing one row at a time, this works */
       for (y = 0; y < height; y++)
-      {
          png_write_rows(png_ptr, &row_pointers[y], 1);
-      }
    }
 #endif no_entire /* use only one output method */
 
diff --git a/libpng-1.4.0beta50.txt b/libpng-1.4.0beta51.txt
similarity index 94%
rename from libpng-1.4.0beta50.txt
rename to libpng-1.4.0beta51.txt
index ec730aa..b974dc7 100644
--- a/libpng-1.4.0beta50.txt
+++ b/libpng-1.4.0beta51.txt
@@ -1,13 +1,17 @@
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.4.0beta50 - March 9, 2009
+ libpng version 1.4.0beta51 - March 21, 2009
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
- Copyright (c) 1998-2005 Glenn Randers-Pehrson
+ Copyright (c) 1998-2009 Glenn Randers-Pehrson
  For conditions of distribution and use, see copyright
  notice in png.h.
 
- based on:
+ Based on:
+
+ libpng versions 0.97, January 1998, through 1.4.0beta51 - March 21, 2009
+ Updated and distributed by Glenn Randers-Pehrson
+ Copyright (c) 1998-2008 Glenn Randers-Pehrson
 
  libpng 1.0 beta 6  version 0.96 May 28, 1997
  Updated and distributed by Andreas Dilger
@@ -33,6 +37,10 @@
 will need.  We assume that libpng is already installed; see the
 INSTALL file for instructions on how to install libpng.
 
+For examples of libpng usage, see the files "example.c", "pngtest.c",
+and the files in the "contrib" directory, all of which are included in the
+libpng distribution.
+
 Libpng was written as a companion to the PNG specification, as a way
 of reducing the amount of time and effort it takes to support the PNG
 file format in application programs.
@@ -43,12 +51,14 @@
 The W3C and ISO documents have identical technical content.
 
 The PNG-1.2 specification is available at
-<http://www.libpng.org/pub/png/documents/>
+<http://www.libpng.org/pub/png/documents/>.  It is technically equivalent
+to the PNG specification (second edition) but has some additional material.
 
 The PNG-1.0 specification is available
 as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
-W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
-additional chunks are described in the special-purpose public chunks
+W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
+
+Some additional chunks are described in the special-purpose public chunks
 documents at <http://www.libpng.org/pub/png/documents/>.
 
 Other information
@@ -256,15 +266,19 @@
          png_unknown_chunkp chunk);
     {
        /* The unknown chunk structure contains your
-          chunk data: */
+          chunk data, along with similar data for any other
+          unknown chunks: */
+
            png_byte name[5];
            png_byte *data;
            png_size_t size;
+
        /* Note that libpng has already taken care of
           the CRC handling */
 
-       /* put your code here.  Return one of the
-          following: */
+       /* put your code here.  Search for your chunk in the
+          unknown chunk structure, process it, and return one
+          of the following: */
 
        return (-n); /* chunk had an error */
        return (0); /* did not recognize */
@@ -284,6 +298,11 @@
 
     png_get_user_chunk_ptr(png_ptr);
 
+If you call the png_set_read_user_chunk_fn() function, then all unknown
+chunks will be saved when read, in case your callback function will need
+one or more of them.  This behavior can be changed with the
+png_set_keep_unknown_chunks() function, described below.
+
 At this point, you can set up a callback function that will be
 called after each row has been read, which you can use to control
 a progress meter or the like.  It's demonstrated in pngtest.c.
@@ -300,18 +319,42 @@
 To inform libpng about your function, use
 
     png_set_read_status_fn(png_ptr, read_row_callback);
+
+Width and height limits
+
+The PNG specification allows the width and height of an image to be as
+large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
+Since very few applications really need to process such large images,
+we have imposed an arbitrary 1-million limit on rows and columns.
+Larger images will be rejected immediately with a png_error() call. If
+you wish to override this limit, you can use
+
+   png_set_user_limits(png_ptr, width_max, height_max);
+
+to set your own limits, or use width_max = height_max = 0x7fffffffL
+to allow all valid dimensions (libpng may reject some very large images
+anyway because of potential buffer overflow conditions).
+
+You should put this statement after you create the PNG structure and
+before calling png_read_info(), png_read_png(), or png_process_data().
+If you need to retrieve the limits that are being applied, use
+
+   width_max = png_get_user_width_max(png_ptr);
+   height_max = png_get_user_height_max(png_ptr);
+
 Unknown-chunk handling
 
 Now you get to set the way the library processes unknown chunks in the
 input PNG stream. Both known and unknown chunks will be read.  Normal
 behavior is that known chunks will be parsed into information in
-various info_ptr members; unknown chunks will be discarded. To change
-this, you can call:
+various info_ptr members while unknown chunks will be discarded. This
+behavior can be wasteful if your application will never use some known
+chunk types. To change this, you can call:
 
     png_set_keep_unknown_chunks(png_ptr, keep,
         chunk_list, num_chunks);
-    keep       - 0: do not handle as unknown
-                 1: do not keep
+    keep       - 0: default unknown chunk handling
+                 1: ignore; do not keep
                  2: keep only if safe-to-copy
                  3: keep even if unsafe-to-copy
                You can use these definitions:
@@ -334,6 +377,36 @@
 take precedence.  The IHDR and IEND chunks should not be named in
 chunk_list; if they are, libpng will process them normally anyway.
 
+Here is an example of the usage of png_set_keep_unknown_chunks(),
+where the private "vpAg" chunk will later be processed by a user chunk
+callback function:
+
+    png_byte vpAg[5]={118, 112,  65, 103, (png_byte) '\0'};
+
+    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+      png_byte unused_chunks[]=
+      {
+        104,  73,  83,  84, (png_byte) '\0',   /* hIST */
+        105,  84,  88, 116, (png_byte) '\0',   /* iTXt */
+        112,  67,  65,  76, (png_byte) '\0',   /* pCAL */
+        115,  67,  65,  76, (png_byte) '\0',   /* sCAL */
+        115,  80,  76,  84, (png_byte) '\0',   /* sPLT */
+        116,  73,  77,  69, (png_byte) '\0',   /* tIME */
+      };
+    #endif
+
+    ...
+
+    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+      /* ignore all unknown chunks: */
+      png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
+      /* except for vpAg: */
+      png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
+      /* also ignore unused known chunks: */
+      png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
+         (int)sizeof(unused_chunks)/5);
+    #endif
+
 User limits
 
 The PNG specification allows the width and height of an image to be as
@@ -395,7 +468,7 @@
     PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples
 
 (This excludes setting a background color, doing gamma transformation,
-and setting filler.)  If this is the case, simply do this:
+dithering, and setting filler.)  If this is the case, simply do this:
 
     png_read_png(png_ptr, info_ptr, png_transforms, NULL)
 
@@ -422,14 +495,16 @@
 If you know your image size and pixel size ahead of time, you can allocate
 row_pointers prior to calling png_read_png() with
 
-   if (height > PNG_UINT_32_MAX/sizeof(png_bytep))
+   if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
       png_error (png_ptr,
          "Image is too tall to process in memory");
    if (width > PNG_UINT_32_MAX/pixel_size)
       png_error (png_ptr,
          "Image is too wide to process in memory");
    row_pointers = png_malloc(png_ptr,
-      height*sizeof(png_bytep));
+      height*png_sizeof(png_bytep));
+   for (int i=0; i<height, i++)
+      row_pointers[i]=NULL;  /* security precaution */
    for (int i=0; i<height, i++)
       row_pointers[i]=png_malloc(png_ptr,
          width*pixel_size);
@@ -806,8 +881,43 @@
 
 As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
 added.  It expands the sample depth without changing tRNS to alpha.
-%12%At the same time, png_set_gray_1_2_4_to_8() was deprecated, and it
-%12%will be removed from a future version.
+
+As of libpng version 1.4.0beta51, not all possible expansions are supported.
+
+In the following table, the 01 means grayscale with depth<8, 31 means
+indexed with depth<8, other numerals represent the color type, "T" means
+the tRNS chunk is present, A means an alpha channel is present, and O
+means tRNS or alpha is present but all pixels in the image are opaque.
+
+  FROM  01  31   0  0T  0O   2  2T  2O   3  3T  3O  4A  4O  6A  6O 
+   TO
+   01    -                   
+   31        -
+    0    1       -           
+   0T                -
+   0O                    -
+    2           GX           -
+   2T                            -
+   2O                                -
+    3        1                           -
+   3T                                        -
+   3O                                            -
+   4A                T                               -
+   4O                                                    -
+   6A               GX         TX           TX               -
+   6O                   GX                      TX               -
+
+Within the matrix,
+     "-" means the transformation is not supported.
+     "X" means the transformation is obtained by png_set_expand().
+     "1" means the transformation is obtained by
+         png_set_expand_gray_1_2_4_to_8
+     "G" means the transformation is obtained by
+         png_set_gray_to_rgb().
+     "P" means the transformation is obtained by
+         png_set_expand_palette_to_rgb().
+     "T" means the transformation is obtained by
+         png_set_tRNS_to_alpha().
 
 PNG can have files with 16 bits per channel.  If you only can handle
 8 bits per channel, this will strip the pixels down to 8 bit.
@@ -1041,7 +1151,6 @@
    else
       png_set_gamma(png_ptr, screen_gamma, 0.45455);
 
-
 PNG files describe monochrome as black being zero and white being one.
 The following code will reverse this (make black be one and white be
 zero):
@@ -1724,6 +1833,11 @@
                      can also be
                      PNG_INTRAPIXEL_DIFFERENCING)
 
+If you call png_set_IHDR(), the call must appear before any of the
+other png_set_*() functions, which might require access to some of
+the IHDR settings.  The remaining png_set_*() functions can be called
+in any order.
+
     png_set_PLTE(png_ptr, info_ptr, palette,
        num_palette);
     palette        - the palette for the file
@@ -1995,7 +2109,6 @@
     PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity
                                 to transparency
     PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples
-
     PNG_TRANSFORM_STRIP_FILLER        Strip out filler
                                       bytes (deprecated).
     PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
@@ -2340,17 +2453,13 @@
 
 V. Modifying/Customizing libpng:
 
-There are three issues here.  The first is changing how libpng does
+There are two issues here.  The first is changing how libpng does
 standard things like memory allocation, input/output, and error handling.
 The second deals with more complicated things like adding new chunks,
 adding new transformations, and generally changing how libpng works.
 Both of those are compile-time issues; that is, they are generally
 determined at the time the code is written, and there is rarely a need
-to provide the user with a means of changing them.  The third is a
-run-time issue:  choosing between and/or tuning one or more alternate
-versions of computationally intensive routines; specifically, optimized
-assembly-language (and therefore compiler- and platform-dependent)
-versions.
+to provide the user with a means of changing them.
 
 Memory allocation, input/output, and error handling
 
@@ -2382,6 +2491,9 @@
 function will normally call png_error() if it receives a NULL from the
 system memory allocator or from your replacement malloc_fn().
 
+Your free_fn() will never be called with a NULL ptr, since libpng's
+png_free() checks for NULL before calling free_fn().
+
 Input/Output in libpng is done through png_read() and png_write(),
 which currently just call fread() and fwrite().  The FILE * is stored in
 png_struct and is initialized via png_init_io().  If you wish to change
@@ -2413,8 +2525,11 @@
 handling end-of-data errors.
 
 Supplying NULL for the read, write, or flush functions sets them back
-to using the default C stream functions.  It is an error to read from
-a write stream, and vice versa.
+to using the default C stream functions, which expect the io_ptr to
+point to a standard *FILE structure.  It is probably a mistake
+to use NULL for one of write_data_fn and output_flush_fn but not both
+of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
+It is an error to read from a write stream, and vice versa.
 
 Error handling in libpng is done through png_error() and png_warning().
 Errors handled through png_error() are fatal, meaning that png_error()
@@ -2520,9 +2635,11 @@
 Configuring for compiler xxx:
 
 All includes for libpng are in pngconf.h.  If you need to add, change
-or delete an include, this is the place to do it.  The includes that
-are not needed outside libpng are placed inside pngpriv.h, which is
-only used by the routines inside libpng itself.
+or delete an include, this is the place to do it.
+The includes that are not needed outside libpng are placed in pngpriv.h,
+which is only used by the routines inside libpng itself.
+The files in libpng proper only include pngpriv.h and png.h, which
+in turn includes pngconf.h.
 
 Configuring zlib:
 
@@ -2738,7 +2855,7 @@
 them.  You may wish to consider using libmng (available at
 http://www.libmng.com) instead.
 
-VIII.  Changes to Libpng from version 0.88
+VII.  Changes to Libpng from version 0.88
 
 It should be noted that versions of libpng later than 0.96 are not
 distributed by the original libpng author, Guy Schalnat, nor by
@@ -2787,15 +2904,15 @@
 
    png_uint_32 application_vn = PNG_LIBPNG_VER;
 
-IX. Y2K Compliance in libpng
+VIII. Y2K Compliance in libpng
 
-March 9, 2009
+March 21, 2009
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.4.0beta50 are Y2K compliant.  It is my belief that earlier
+upward through 1.4.0beta51 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has three year fields.  One is a 2-byte unsigned integer that
diff --git a/libpng.3 b/libpng.3
index 65e7f19..3131eea 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "March 9, 2009"
+.TH LIBPNG 3 "March 21, 2009"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta50
+libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta51
 .SH SYNOPSIS
 \fI\fB
 
@@ -809,14 +809,18 @@
 .SH LIBPNG.TXT
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.4.0beta50 - March 9, 2009
+ libpng version 1.4.0beta51 - March 21, 2009
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
- Copyright (c) 1998-2005 Glenn Randers-Pehrson
+ Copyright (c) 1998-2009 Glenn Randers-Pehrson
  For conditions of distribution and use, see copyright
  notice in png.h.
 
- based on:
+ Based on:
+
+ libpng versions 0.97, January 1998, through 1.4.0beta51 - March 21, 2009
+ Updated and distributed by Glenn Randers-Pehrson
+ Copyright (c) 1998-2008 Glenn Randers-Pehrson
 
  libpng 1.0 beta 6  version 0.96 May 28, 1997
  Updated and distributed by Andreas Dilger
@@ -842,6 +846,10 @@
 will need.  We assume that libpng is already installed; see the
 INSTALL file for instructions on how to install libpng.
 
+For examples of libpng usage, see the files "example.c", "pngtest.c",
+and the files in the "contrib" directory, all of which are included in the
+libpng distribution.
+
 Libpng was written as a companion to the PNG specification, as a way
 of reducing the amount of time and effort it takes to support the PNG
 file format in application programs.
@@ -852,12 +860,14 @@
 The W3C and ISO documents have identical technical content.
 
 The PNG-1.2 specification is available at
-<http://www.libpng.org/pub/png/documents/>
+<http://www.libpng.org/pub/png/documents/>.  It is technically equivalent
+to the PNG specification (second edition) but has some additional material.
 
 The PNG-1.0 specification is available
 as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
-W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
-additional chunks are described in the special-purpose public chunks
+W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
+
+Some additional chunks are described in the special-purpose public chunks
 documents at <http://www.libpng.org/pub/png/documents/>.
 
 Other information
@@ -1065,15 +1075,19 @@
          png_unknown_chunkp chunk);
     {
        /* The unknown chunk structure contains your
-          chunk data: */
+          chunk data, along with similar data for any other
+          unknown chunks: */
+
            png_byte name[5];
            png_byte *data;
            png_size_t size;
+
        /* Note that libpng has already taken care of
           the CRC handling */
 
-       /* put your code here.  Return one of the
-          following: */
+       /* put your code here.  Search for your chunk in the
+          unknown chunk structure, process it, and return one
+          of the following: */
 
        return (-n); /* chunk had an error */
        return (0); /* did not recognize */
@@ -1093,6 +1107,11 @@
 
     png_get_user_chunk_ptr(png_ptr);
 
+If you call the png_set_read_user_chunk_fn() function, then all unknown
+chunks will be saved when read, in case your callback function will need
+one or more of them.  This behavior can be changed with the
+png_set_keep_unknown_chunks() function, described below.
+
 At this point, you can set up a callback function that will be
 called after each row has been read, which you can use to control
 a progress meter or the like.  It's demonstrated in pngtest.c.
@@ -1109,18 +1128,42 @@
 To inform libpng about your function, use
 
     png_set_read_status_fn(png_ptr, read_row_callback);
+
+.SS Width and height limits
+
+The PNG specification allows the width and height of an image to be as
+large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
+Since very few applications really need to process such large images,
+we have imposed an arbitrary 1-million limit on rows and columns.
+Larger images will be rejected immediately with a png_error() call. If
+you wish to override this limit, you can use
+
+   png_set_user_limits(png_ptr, width_max, height_max);
+
+to set your own limits, or use width_max = height_max = 0x7fffffffL
+to allow all valid dimensions (libpng may reject some very large images
+anyway because of potential buffer overflow conditions).
+
+You should put this statement after you create the PNG structure and
+before calling png_read_info(), png_read_png(), or png_process_data().
+If you need to retrieve the limits that are being applied, use
+
+   width_max = png_get_user_width_max(png_ptr);
+   height_max = png_get_user_height_max(png_ptr);
+
 .SS Unknown-chunk handling
 
 Now you get to set the way the library processes unknown chunks in the
 input PNG stream. Both known and unknown chunks will be read.  Normal
 behavior is that known chunks will be parsed into information in
-various info_ptr members; unknown chunks will be discarded. To change
-this, you can call:
+various info_ptr members while unknown chunks will be discarded. This
+behavior can be wasteful if your application will never use some known
+chunk types. To change this, you can call:
 
     png_set_keep_unknown_chunks(png_ptr, keep,
         chunk_list, num_chunks);
-    keep       - 0: do not handle as unknown
-                 1: do not keep
+    keep       - 0: default unknown chunk handling
+                 1: ignore; do not keep
                  2: keep only if safe-to-copy
                  3: keep even if unsafe-to-copy
                You can use these definitions:
@@ -1143,6 +1186,36 @@
 take precedence.  The IHDR and IEND chunks should not be named in
 chunk_list; if they are, libpng will process them normally anyway.
 
+Here is an example of the usage of png_set_keep_unknown_chunks(),
+where the private "vpAg" chunk will later be processed by a user chunk
+callback function:
+
+    png_byte vpAg[5]={118, 112,  65, 103, (png_byte) '\0'};
+
+    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+      png_byte unused_chunks[]=
+      {
+        104,  73,  83,  84, (png_byte) '\0',   /* hIST */
+        105,  84,  88, 116, (png_byte) '\0',   /* iTXt */
+        112,  67,  65,  76, (png_byte) '\0',   /* pCAL */
+        115,  67,  65,  76, (png_byte) '\0',   /* sCAL */
+        115,  80,  76,  84, (png_byte) '\0',   /* sPLT */
+        116,  73,  77,  69, (png_byte) '\0',   /* tIME */
+      };
+    #endif
+
+    ...
+
+    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+      /* ignore all unknown chunks: */
+      png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
+      /* except for vpAg: */
+      png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
+      /* also ignore unused known chunks: */
+      png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
+         (int)sizeof(unused_chunks)/5);
+    #endif
+
 .SS User limits
 
 The PNG specification allows the width and height of an image to be as
@@ -1204,7 +1277,7 @@
     PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples
 
 (This excludes setting a background color, doing gamma transformation,
-and setting filler.)  If this is the case, simply do this:
+dithering, and setting filler.)  If this is the case, simply do this:
 
     png_read_png(png_ptr, info_ptr, png_transforms, NULL)
 
@@ -1231,14 +1304,16 @@
 If you know your image size and pixel size ahead of time, you can allocate
 row_pointers prior to calling png_read_png() with
 
-   if (height > PNG_UINT_32_MAX/sizeof(png_bytep))
+   if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
       png_error (png_ptr,
          "Image is too tall to process in memory");
    if (width > PNG_UINT_32_MAX/pixel_size)
       png_error (png_ptr,
          "Image is too wide to process in memory");
    row_pointers = png_malloc(png_ptr,
-      height*sizeof(png_bytep));
+      height*png_sizeof(png_bytep));
+   for (int i=0; i<height, i++)
+      row_pointers[i]=NULL;  /* security precaution */
    for (int i=0; i<height, i++)
       row_pointers[i]=png_malloc(png_ptr,
          width*pixel_size);
@@ -1615,8 +1690,43 @@
 
 As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
 added.  It expands the sample depth without changing tRNS to alpha.
-%12%At the same time, png_set_gray_1_2_4_to_8() was deprecated, and it
-%12%will be removed from a future version.
+
+As of libpng version 1.4.0beta51, not all possible expansions are supported.
+
+In the following table, the 01 means grayscale with depth<8, 31 means
+indexed with depth<8, other numerals represent the color type, "T" means
+the tRNS chunk is present, A means an alpha channel is present, and O
+means tRNS or alpha is present but all pixels in the image are opaque.
+
+  FROM  01  31   0  0T  0O   2  2T  2O   3  3T  3O  4A  4O  6A  6O 
+   TO
+   01    -                   
+   31        -
+    0    1       -           
+   0T                -
+   0O                    -
+    2           GX           -
+   2T                            -
+   2O                                -
+    3        1                           -
+   3T                                        -
+   3O                                            -
+   4A                T                               -
+   4O                                                    -
+   6A               GX         TX           TX               -
+   6O                   GX                      TX               -
+
+Within the matrix,
+     "-" means the transformation is not supported.
+     "X" means the transformation is obtained by png_set_expand().
+     "1" means the transformation is obtained by
+         png_set_expand_gray_1_2_4_to_8
+     "G" means the transformation is obtained by
+         png_set_gray_to_rgb().
+     "P" means the transformation is obtained by
+         png_set_expand_palette_to_rgb().
+     "T" means the transformation is obtained by
+         png_set_tRNS_to_alpha().
 
 PNG can have files with 16 bits per channel.  If you only can handle
 8 bits per channel, this will strip the pixels down to 8 bit.
@@ -1850,7 +1960,6 @@
    else
       png_set_gamma(png_ptr, screen_gamma, 0.45455);
 
-
 PNG files describe monochrome as black being zero and white being one.
 The following code will reverse this (make black be one and white be
 zero):
@@ -2533,6 +2642,11 @@
                      can also be
                      PNG_INTRAPIXEL_DIFFERENCING)
 
+If you call png_set_IHDR(), the call must appear before any of the
+other png_set_*() functions, which might require access to some of
+the IHDR settings.  The remaining png_set_*() functions can be called
+in any order.
+
     png_set_PLTE(png_ptr, info_ptr, palette,
        num_palette);
     palette        - the palette for the file
@@ -2804,7 +2918,6 @@
     PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity
                                 to transparency
     PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples
-
     PNG_TRANSFORM_STRIP_FILLER        Strip out filler
                                       bytes (deprecated).
     PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
@@ -3149,17 +3262,13 @@
 
 .SH V. Modifying/Customizing libpng:
 
-There are three issues here.  The first is changing how libpng does
+There are two issues here.  The first is changing how libpng does
 standard things like memory allocation, input/output, and error handling.
 The second deals with more complicated things like adding new chunks,
 adding new transformations, and generally changing how libpng works.
 Both of those are compile-time issues; that is, they are generally
 determined at the time the code is written, and there is rarely a need
-to provide the user with a means of changing them.  The third is a
-run-time issue:  choosing between and/or tuning one or more alternate
-versions of computationally intensive routines; specifically, optimized
-assembly-language (and therefore compiler- and platform-dependent)
-versions.
+to provide the user with a means of changing them.
 
 Memory allocation, input/output, and error handling
 
@@ -3191,6 +3300,9 @@
 function will normally call png_error() if it receives a NULL from the
 system memory allocator or from your replacement malloc_fn().
 
+Your free_fn() will never be called with a NULL ptr, since libpng's
+png_free() checks for NULL before calling free_fn().
+
 Input/Output in libpng is done through png_read() and png_write(),
 which currently just call fread() and fwrite().  The FILE * is stored in
 png_struct and is initialized via png_init_io().  If you wish to change
@@ -3222,8 +3334,11 @@
 handling end-of-data errors.
 
 Supplying NULL for the read, write, or flush functions sets them back
-to using the default C stream functions.  It is an error to read from
-a write stream, and vice versa.
+to using the default C stream functions, which expect the io_ptr to
+point to a standard *FILE structure.  It is probably a mistake
+to use NULL for one of write_data_fn and output_flush_fn but not both
+of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
+It is an error to read from a write stream, and vice versa.
 
 Error handling in libpng is done through png_error() and png_warning().
 Errors handled through png_error() are fatal, meaning that png_error()
@@ -3329,9 +3444,11 @@
 .SS Configuring for compiler xxx:
 
 All includes for libpng are in pngconf.h.  If you need to add, change
-or delete an include, this is the place to do it.  The includes that
-are not needed outside libpng are placed inside pngpriv.h, which is
-only used by the routines inside libpng itself.
+or delete an include, this is the place to do it.
+The includes that are not needed outside libpng are placed in pngpriv.h,
+which is only used by the routines inside libpng itself.
+The files in libpng proper only include pngpriv.h and png.h, which
+in turn includes pngconf.h.
 
 .SS Configuring zlib:
 
@@ -3547,7 +3664,7 @@
 them.  You may wish to consider using libmng (available at
 http://www.libmng.com) instead.
 
-.SH VIII.  Changes to Libpng from version 0.88
+.SH VII.  Changes to Libpng from version 0.88
 
 It should be noted that versions of libpng later than 0.96 are not
 distributed by the original libpng author, Guy Schalnat, nor by
@@ -3596,15 +3713,15 @@
 
    png_uint_32 application_vn = PNG_LIBPNG_VER;
 
-.SH IX. Y2K Compliance in libpng
+.SH VIII. Y2K Compliance in libpng
 
-March 9, 2009
+March 21, 2009
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.4.0beta50 are Y2K compliant.  It is my belief that earlier
+upward through 1.4.0beta51 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has three year fields.  One is a 2-byte unsigned integer that
@@ -3772,7 +3889,7 @@
  1.4.0beta9-14       14    10400  14.so.0.0[.0]
  1.2.13              13    10213  12.so.0.13[.0]
  1.4.0beta15-36      14    10400  14.so.0.0[.0]
- 1.4.0beta37-50      14    10400  14.so.14.0[.0]
+ 1.4.0beta37-51      14    10400  14.so.14.0[.0]
 
 Henceforth the source version will match the shared-library minor
 and patch numbers; the shared-library major version number will be
@@ -3828,7 +3945,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.4.0beta50 - March 9, 2009:
+Libpng version 1.4.0beta51 - March 21, 2009:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
 
@@ -3849,7 +3966,7 @@
 If you modify libpng you may insert additional notices immediately following
 this sentence.
 
-libpng versions 1.2.6, August 15, 2004, through 1.4.0beta50, March 9, 2009, are
+libpng versions 1.2.6, August 15, 2004, through 1.4.0beta51, March 21, 2009, 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
@@ -3948,7 +4065,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-March 9, 2009
+March 21, 2009
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index ff5eb7f..158567d 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 "March 9, 2009"
+.TH LIBPNGPF 3 "March 21, 2009"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta50
+libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta51
 (private functions)
 .SH SYNOPSIS
 \fB#include <png.h>\fP
diff --git a/png.5 b/png.5
index 6383c61..4ad8aa6 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "March 9, 2009"
+.TH PNG 5 "March 21, 2009"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index d9c8f6f..03ae770 100644
--- a/png.c
+++ b/png.c
@@ -1,7 +1,7 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -13,7 +13,7 @@
 #include "pngpriv.h"
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_4_0beta50 Your_png_h_is_not_version_1_4_0beta50;
+typedef version_1_4_0beta51 Your_png_h_is_not_version_1_4_0beta51;
 
 /* Version information for C files.  This had better match the version
  * string defined in png.h.  */
@@ -641,13 +641,13 @@
 #else
 #ifdef __STDC__
    return ((png_charp) PNG_STRING_NEWLINE \
-     "libpng version x 1.4.0beta50 - March 9, 2009" PNG_STRING_NEWLINE \
+     "libpng version x 1.4.0beta51 - March 21, 2009" PNG_STRING_NEWLINE \
      "Copyright (c) 1998-2009 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 ((png_charp) "libpng version 1.4.0beta50 - March 9, 2009\
+      return ((png_charp) "libpng version 1.4.0beta51 - March 21, 2009\
       Copyright (c) 1998-2009 Glenn Randers-Pehrson\
       Copyright (c) 1996-1997 Andreas Dilger\
       Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.");
diff --git a/png.h b/png.h
index a0b7d51..275525e 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.4.0beta50 - March 9, 2009
+ * libpng version 1.4.0beta51 - March 21, 2009
  * Copyright (c) 1998-2009 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.)
@@ -9,7 +9,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.4.0beta50 - March 9, 2009: Glenn
+ *  libpng versions 0.97, January 1998, through 1.4.0beta51 - March 21, 2009: Glenn
  *  See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -127,7 +127,7 @@
  *    1.4.0beta9-14           14    10400  14.so.0.0[.0]
  *    1.2.13                  13    10213  12.so.0.10[.0]
  *    1.4.0beta15-36          14    10400  14.so.0.0[.0]
- *    1.4.0beta37-50          14    10400  14.so.14.0[.0]
+ *    1.4.0beta37-51          14    10400  14.so.14.0[.0]
  *
  *    Henceforth the source version will match the shared-library major
  *    and minor numbers; the shared-library major version number will be
@@ -157,7 +157,7 @@
  * If you modify libpng you may insert additional notices immediately following
  * this sentence.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.4.0beta50, March 9, 2009, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.4.0beta51, March 21, 2009, 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:
@@ -275,7 +275,7 @@
  *    an official declaration.
  *
  *    This is your unofficial assurance that libpng from version 0.71 and
- *    upward through 1.4.0beta50 are Y2K compliant.  It is my belief that earlier
+ *    upward through 1.4.0beta51 are Y2K compliant.  It is my belief that earlier
  *    versions were also Y2K compliant.
  *
  *    Libpng only has three year fields.  One is a 2-byte unsigned integer
@@ -331,9 +331,9 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.4.0beta50"
+#define PNG_LIBPNG_VER_STRING "1.4.0beta51"
 #define PNG_HEADER_VERSION_STRING \
-   " libpng version 1.4.0beta50 - March 9, 2009\n"
+   " libpng version 1.4.0beta51 - March 21, 2009\n"
 
 #define PNG_LIBPNG_VER_SONUM   14
 #define PNG_LIBPNG_VER_DLLNUM  14
@@ -345,7 +345,7 @@
 /* This should match the numeric part of the final component of
  * PNG_LIBPNG_VER_STRING, omitting any leading zero: */
 
-#define PNG_LIBPNG_VER_BUILD  50
+#define PNG_LIBPNG_VER_BUILD  51
 
 /* Release Status */
 #define PNG_LIBPNG_BUILD_ALPHA    1
@@ -1356,7 +1356,7 @@
 /* This triggers a compiler error in png.c, if png.c and png.h
  * do not agree upon the version number.
  */
-typedef png_structp version_1_4_0beta50;
+typedef png_structp version_1_4_0beta51;
 
 typedef png_struct FAR * FAR * png_structpp;
 
@@ -1524,7 +1524,8 @@
 #endif
 
 #if defined(PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED)
-extern PNG_EXPORT(void,png_set_premultiply_alpha) PNGARG((png_structp png_ptr));
+extern PNG_EXPORT(void,png_set_premultiply_alpha)
+  PNGARG((png_structp png_ptr));
 #endif
 
 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
@@ -1835,6 +1836,11 @@
  * If buffered output is not used, then output_flush_fn can be set to NULL.
  * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
  * output_flush_fn will be ignored (and thus can be NULL).
+ * It is probably a mistake to use NULL for output_flush_fn if
+ * write_data_fn is not also NULL unless you have built libpng with
+ * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's
+ * default flush function, which uses the standard *FILE structure, will
+ * be used.
  */
 extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
    png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
diff --git a/pngconf.h b/pngconf.h
index 9432ebf..483d1b7 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.4.0beta50 - March 9, 2009
+ * libpng version 1.4.0beta51 - March 21, 2009
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1339,7 +1339,6 @@
 #  define NOCHECK 0
 #  define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
 #  define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
-#  define png_fileno  _fileno     /* Added to v 1.4.0 */
 #  define png_strcpy  _fstrcpy
 #  define png_strncpy _fstrncpy   /* Added to v 1.2.6 */
 #  define png_strlen  _fstrlen
@@ -1351,7 +1350,6 @@
 #  if defined(_WINDOWS_)  /* favor Windows over C runtime fns */
 #    define CVT_PTR(ptr)         (ptr)
 #    define CVT_PTR_NOCHECK(ptr) (ptr)
-#    define png_fileno  fileno
 #    define png_strcpy  lstrcpyA
 #    define png_strncpy lstrcpynA
 #    define png_strlen  lstrlenA
@@ -1362,7 +1360,6 @@
 #  else
 #    define CVT_PTR(ptr)         (ptr)
 #    define CVT_PTR_NOCHECK(ptr) (ptr)
-#    define png_fileno  fileno      /* Added to v 1.4.0 */
 #    define png_strcpy  strcpy
 #    define png_strncpy strncpy     /* Added to v 1.2.6 */
 #    define png_strlen  strlen
diff --git a/pngerror.c b/pngerror.c
index 4b55c2c..f98e1f2 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -1,7 +1,7 @@
 
 /* pngerror.c - stub functions for i/o and memory allocation
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -44,40 +44,19 @@
      {
        if (*error_message == PNG_LITERAL_SHARP)
        {
-       /* Strip "#nnnn " from beginning of error message. */
-         /*
-          *                 012345678901234567890
-          *  error_message: #nnnn   text\0
-          *  error_number:  nnnn\0
-          *  msg:        :  nnnn \0
-          *  offset points to the first blank after nnnn
-          *  In this example, offset is 5.
-          */
+           /* Strip "#nnnn " from beginning of error message. */
            int offset;
            for (offset = 1; offset<15; offset++)
               if (error_message[offset] == ' ')
                   break;
-          /* it is 5 because the loop iterations saw
-           * offset==1, error_message[1]=="n"; offset++.
-           * offset==2, error_message[2]=="n"; offset++.
-           * offset==3, error_message[3]=="n"; offset++.
-           * offset==4, error_message[4]=="n"; offset++.
-           * offset==5, error_message[5]==" "; break.
-           */
            if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
            {
               int i;
-           /* Copy the "nnnn" or however many there are, plus the
-            * blank to the beginning of "msg" string.
-            */
               for (i = 0; i < offset - 1; i++)
                  msg[i] = error_message[i + 1];
-           /* In the example, "i" ends up being 5.
-            */
               msg[i - 1] = '\0';
               error_message = msg;
            }
-           /* msg, and error_message, now contain "nnnn \0". */
            else
               error_message += offset;
        }
@@ -259,16 +238,8 @@
 #ifndef PNG_NO_CONSOLE_IO
 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
    if (*error_message == PNG_LITERAL_SHARP)
-       {
-       /* Strip "#nnnn " from beginning of error message. */
-     /*
-      *                 012345678901234567890
-      *  error_message: #nnnn   text\0
-      *  error_number:  nnnn\0
-      *  offset points to the first blank after nnnn
-      *  In this example, offset is 5, and we want to
-      *  insert a terminating NULL at error_number[4].
-      */
+   {
+     /* Strip "#nnnn " from beginning of error message. */
      int offset;
      char error_number[16];
      for (offset = 0; offset<15; offset++)
@@ -277,21 +248,9 @@
          if (error_message[offset] == ' ')
              break;
      }
-        /* This is unnecessarily slightly different from above, but
-         * offset is still 5 because the loop iterations saw
-         * offset==0, error_message[0]=="#"; error_number[0]="n";offset++.
-         * offset==1, error_message[1]=="n"; error_number[1]="n";offset++
-         * offset==2, error_message[2]=="n"; error_number[2]="n";offset++
-         * offset==3, error_message[3]=="n"; error_number[3]="n";offset++
-         * offset==4, error_message[4]=="n"; error_number[4]=" ";offset++.
-         * offset==5, error_message[5]==" "; break.
-         */
      if ((offset > 1) && (offset < 15))
      {
-       /* Replace the " " with a string-terminating NULL */
        error_number[offset - 1] = '\0';
-       /* GRR: this should be [offset + 1] */
-       /* should we update "offset" to point to the beginning of the text? */
        fprintf(stderr, "libpng error no. %s: %s",
           error_number, error_message + offset + 1);
        fprintf(stderr, PNG_STRING_NEWLINE);
diff --git a/pngget.c b/pngget.c
index 03b01f8..306b292 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,7 +1,7 @@
 
 /* pngget.c - retrieval of values from info struct
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngmem.c b/pngmem.c
index f11c3e2..edc0152 100644
--- a/pngmem.c
+++ b/pngmem.c
@@ -1,7 +1,7 @@
 
 /* pngmem.c - stub functions for memory allocation
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngpread.c b/pngpread.c
index e7817a2..d1806a7 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1,7 +1,7 @@
 
 /* pngpread.c - read a png file in push mode
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngpriv.h b/pngpriv.h
index ec6a5d0..1163e31 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -1,7 +1,7 @@
 
 /* pngpriv.h - private declarations for use inside libpng
  *
- * libpng version 1.4.0beta50 - March 9, 2009
+ * libpng version 1.4.0beta51 - March 21, 2009
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -123,7 +123,8 @@
                        /*     0x800000L     Unused */
 #define PNG_ADD_ALPHA         0x1000000L  /* Added to libpng-1.2.7 */
 #define PNG_EXPAND_tRNS       0x2000000L  /* Added to libpng-1.2.9 */
-#define PNG_PREMULTIPLY_ALPHA 0x4000000L  /* Added to libpng-1.4.0 by volker */
+#define PNG_PREMULTIPLY_ALPHA 0x4000000L  /* Added to libpng-1.4.0 */
+                                          /* by volker */
                        /*   0x8000000L  unused */
                        /*  0x10000000L  unused */
                        /*  0x20000000L  unused */
@@ -583,17 +584,17 @@
    png_bytep row));
 #endif
 
-#if defined(PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED)
-PNG_EXTERN void png_do_read_premultiply_alpha PNGARG((png_row_infop row_info,
-   png_bytep row));
-#endif
-
 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
     defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
 PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
    png_bytep row, png_uint_32 flags));
 #endif
 
+#if defined(PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED)
+PNG_EXTERN void png_do_read_premultiply_alpha
+   PNGARG((png_row_infop row_info, png_bytep row));
+#endif
+
 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
 PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
 #endif
diff --git a/pngread.c b/pngread.c
index 8e43932..42b2e64 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,7 +1,7 @@
 
 /* pngread.c - read a PNG file
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1383,17 +1383,15 @@
 #else
       info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
          info_ptr->height * png_sizeof(png_bytep));
-      png_memset(info_ptr->row_pointers, 0,
-         info_ptr->height * png_sizeof(png_bytep));
+      png_memset(info_ptr->row_pointers, 0, info_ptr->height
+         * png_sizeof(png_bytep));
 #endif
 #ifdef PNG_FREE_ME_SUPPORTED
       info_ptr->free_me |= PNG_FREE_ROWS;
 #endif
       for (row = 0; row < (int)info_ptr->height; row++)
-      {
          info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
             png_get_rowbytes(png_ptr, info_ptr));
-      }
    }
 
    png_read_image(png_ptr, info_ptr->row_pointers);
diff --git a/pngrio.c b/pngrio.c
index 14135bd..5b4b54a 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -1,7 +1,7 @@
 
 /* pngrio.c - functions for data input
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngrtran.c b/pngrtran.c
index b13d477..9335c91 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,7 +1,7 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1465,7 +1465,8 @@
 
 #if defined(PNG_READ_PREMULTIPLY_ALPHA_SUPPORTED)
    if (png_ptr->transformations & PNG_PREMULTIPLY_ALPHA)
-      png_do_read_premultiply_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
+      png_do_read_premultiply_alpha(&(png_ptr->row_info),
+         png_ptr->row_buf + 1);
 #endif
 
 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
diff --git a/pngrutil.c b/pngrutil.c
index d332b92..e1a4190 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,7 +1,7 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -3252,11 +3252,11 @@
    {
      png_free(png_ptr, png_ptr->big_row_buf);
      if (png_ptr->interlaced)
-       png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, row_bytes+64);
+       png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, row_bytes + 64);
      else
-       png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
-     png_ptr->row_buf = png_ptr->big_row_buf+32;
-     png_ptr->old_big_row_buf_size = row_bytes+64;
+      png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64);
+     png_ptr->row_buf = png_ptr->big_row_buf + 32;
+     png_ptr->old_big_row_buf_size = row_bytes + 64;
    }
 
 #ifdef PNG_MAX_MALLOC_64K
diff --git a/pngset.c b/pngset.c
index 7b52f98..f6a9c38 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,7 +1,7 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngtest.c b/pngtest.c
index 10f503e..3038a7c 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,7 +1,7 @@
 
 /* pngtest.c - a simple test program to test libpng
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -318,10 +318,8 @@
 static void
 pngtest_flush(png_structp png_ptr)
 {
-   png_FILE_p io_ptr;
-   io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
-   if (io_ptr != NULL)
-      fflush(io_ptr);
+   /* Do nothing; fflush() is said to be just a waste of energy. */
+   png_ptr = png_ptr;  /* stifle compiler warning */
 }
 #endif
 
@@ -1613,4 +1611,4 @@
 }
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_4_0beta50 your_png_h_is_not_version_1_4_0beta50;
+typedef version_1_4_0beta51 your_png_h_is_not_version_1_4_0beta51;
diff --git a/pngtrans.c b/pngtrans.c
index 04a1644..c6d0a84 100644
--- a/pngtrans.c
+++ b/pngtrans.c
@@ -1,7 +1,7 @@
 
 /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwio.c b/pngwio.c
index 535a15d..29cb010 100644
--- a/pngwio.c
+++ b/pngwio.c
@@ -1,7 +1,7 @@
 
 /* pngwio.c - functions for data output
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -119,8 +119,7 @@
    png_FILE_p io_ptr;
    if (png_ptr == NULL) return;
    io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
-   if (io_ptr != NULL && png_fileno(io_ptr) != -1)
-      fflush(io_ptr);
+   fflush(io_ptr);
 }
 #endif
 #endif
@@ -149,7 +148,10 @@
                    PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
                    time, output_flush_fn will be ignored, although it must be
                    supplied for compatibility.  May be NULL, in which case
-                   libpng's default function will be used. */
+                   libpng's default function will be used, if
+                   PNG_WRITE_FLUSH_SUPPORTED is defined.  This is not
+                   a good idea if io_ptr does not point to a standard
+                   *FILE structure. */
 void PNGAPI
 png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
    png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
diff --git a/pngwrite.c b/pngwrite.c
index 9078ee1..f5ce493 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,7 +1,7 @@
 
 /* pngwrite.c - general routines to write a PNG file
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwtran.c b/pngwtran.c
index 59c8ae0..6b44196 100644
--- a/pngwtran.c
+++ b/pngwtran.c
@@ -1,7 +1,7 @@
 
 /* pngwtran.c - transforms the data in a row for PNG writers
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwutil.c b/pngwutil.c
index e3aabc0..ad9f29b 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,7 +1,7 @@
 
 /* pngwutil.c - utilities to write a PNG file
  *
- * Last changed in libpng 1.4.0 [March 9, 2009]
+ * Last changed in libpng 1.4.0 [March 21, 2009]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index 499ef56..46d70b5 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -178,7 +178,7 @@
 
 # SET UP LINKS
 set_target_properties(${PNG_LIB_NAME} PROPERTIES
-#    VERSION 0.${PNGLIB_RELEASE}.1.4.0beta50
+#    VERSION 0.${PNGLIB_RELEASE}.1.4.0beta51
      VERSION 0.${PNGLIB_RELEASE}.0
      SOVERSION 0
      CLEAN_DIRECT_OUTPUT 1)
diff --git a/scripts/libpng-config-head.in b/scripts/libpng-config-head.in
index 83e9179..6da2168 100755
--- a/scripts/libpng-config-head.in
+++ b/scripts/libpng-config-head.in
@@ -8,7 +8,7 @@
 
 # Modeled after libxml-config.
 
-version=1.4.0beta50
+version=1.4.0beta51
 prefix=""
 libdir=""
 libs=""
diff --git a/scripts/libpng.pc.in b/scripts/libpng.pc.in
index cb9b3b3..4f4d1c4 100644
--- a/scripts/libpng.pc.in
+++ b/scripts/libpng.pc.in
@@ -5,6 +5,6 @@
 
 Name: libpng
 Description: Loads and saves PNG files
-Version: 1.4.0beta50
+Version: 1.4.0beta51
 Libs: -L${libdir} -lpng14
 Cflags: -I${includedir}
diff --git a/scripts/makefile.32sunu b/scripts/makefile.32sunu
index b5db70c..498b4fb 100644
--- a/scripts/makefile.32sunu
+++ b/scripts/makefile.32sunu
@@ -8,7 +8,7 @@
 # Library name:
 LIBNAME=libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.64sunu b/scripts/makefile.64sunu
index f548e90..919b528 100644
--- a/scripts/makefile.64sunu
+++ b/scripts/makefile.64sunu
@@ -8,7 +8,7 @@
 # Library name:
 LIBNAME=libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.aix b/scripts/makefile.aix
index a26961d..085b335 100644
--- a/scripts/makefile.aix
+++ b/scripts/makefile.aix
@@ -20,7 +20,7 @@
 
 LIBNAME=libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 prefix=/usr/local
diff --git a/scripts/makefile.beos b/scripts/makefile.beos
index 6023a3d..5d227ff 100644
--- a/scripts/makefile.beos
+++ b/scripts/makefile.beos
@@ -8,7 +8,7 @@
 # Library name:
 LIBNAME=libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.cygwin b/scripts/makefile.cygwin
index 53c756e..19aab83 100644
--- a/scripts/makefile.cygwin
+++ b/scripts/makefile.cygwin
@@ -65,7 +65,7 @@
 LIBNAME = libpng14
 PNGMAJ = 14
 CYGDLL = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 SHAREDLIB=cygpng$(CYGDLL).dll
diff --git a/scripts/makefile.darwin b/scripts/makefile.darwin
index 7f23b2e..3fc9ef6 100644
--- a/scripts/makefile.darwin
+++ b/scripts/makefile.darwin
@@ -19,7 +19,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 12
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.dec b/scripts/makefile.dec
index 73cdea6..2329486 100644
--- a/scripts/makefile.dec
+++ b/scripts/makefile.dec
@@ -5,7 +5,7 @@
 
 # Library name:
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 LIBNAME = libpng14
 
diff --git a/scripts/makefile.elf b/scripts/makefile.elf
index 09e4768..b43b1e9 100644
--- a/scripts/makefile.elf
+++ b/scripts/makefile.elf
@@ -12,7 +12,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.gcmmx b/scripts/makefile.gcmmx
index 8e8821b..4917ffd 100644
--- a/scripts/makefile.gcmmx
+++ b/scripts/makefile.gcmmx
@@ -16,7 +16,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.hp64 b/scripts/makefile.hp64
index e13fe57..4add23d 100644
--- a/scripts/makefile.hp64
+++ b/scripts/makefile.hp64
@@ -18,7 +18,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.hpgcc b/scripts/makefile.hpgcc
index c7f9655..67ae91a 100644
--- a/scripts/makefile.hpgcc
+++ b/scripts/makefile.hpgcc
@@ -8,7 +8,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.hpux b/scripts/makefile.hpux
index 805bbe1..8a49a6f 100644
--- a/scripts/makefile.hpux
+++ b/scripts/makefile.hpux
@@ -18,7 +18,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.linux b/scripts/makefile.linux
index 3e56cd0..b5ff13e 100644
--- a/scripts/makefile.linux
+++ b/scripts/makefile.linux
@@ -6,7 +6,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.mingw b/scripts/makefile.mingw
index 95b5e42..29d9ca2 100644
--- a/scripts/makefile.mingw
+++ b/scripts/makefile.mingw
@@ -81,7 +81,7 @@
 LIBNAME = libpng14
 PNGMAJ = 14 
 MINGDLL = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 SHAREDLIB=libpng$(MINGDLL).dll
diff --git a/scripts/makefile.ne12bsd b/scripts/makefile.ne12bsd
index 977d8ad..e8fa81d 100644
--- a/scripts/makefile.ne12bsd
+++ b/scripts/makefile.ne12bsd
@@ -14,7 +14,7 @@
 
 LIB=	png14
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	1.4.0beta50
+SHLIB_MINOR=	1.4.0beta51
 SRCS=	pnggccrd.c png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
 		pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
 		pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.netbsd b/scripts/makefile.netbsd
index e7a70a3..1e0b07f 100644
--- a/scripts/makefile.netbsd
+++ b/scripts/makefile.netbsd
@@ -13,7 +13,7 @@
 
 LIB=	png
 SHLIB_MAJOR=	3
-SHLIB_MINOR=	1.4.0beta50
+SHLIB_MINOR=	1.4.0beta51
 SRCS=	pnggccrd.c png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
 		pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
 		pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.nommx b/scripts/makefile.nommx
index 8c4f5cb..b654fdd 100644
--- a/scripts/makefile.nommx
+++ b/scripts/makefile.nommx
@@ -16,7 +16,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.openbsd b/scripts/makefile.openbsd
index b74e2b1..7d6446f 100644
--- a/scripts/makefile.openbsd
+++ b/scripts/makefile.openbsd
@@ -8,7 +8,7 @@
 MANDIR= ${PREFIX}/man/cat
 
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	1.4.0beta50
+SHLIB_MINOR=	1.4.0beta51
 
 LIB=	png
 SRCS=	png.c pngerror.c pnggccrd.c pngget.c pngmem.c pngpread.c \
diff --git a/scripts/makefile.sco b/scripts/makefile.sco
index 45c449a..04e478d 100644
--- a/scripts/makefile.sco
+++ b/scripts/makefile.sco
@@ -9,7 +9,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.sggcc b/scripts/makefile.sggcc
index fcbec7d..4c17c7d 100644
--- a/scripts/makefile.sggcc
+++ b/scripts/makefile.sggcc
@@ -6,7 +6,7 @@
 # Library name:
 LIBNAME=libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.sgi b/scripts/makefile.sgi
index 210e09d..4734325 100644
--- a/scripts/makefile.sgi
+++ b/scripts/makefile.sgi
@@ -6,7 +6,7 @@
 # Library name:
 LIBNAME=libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.so9 b/scripts/makefile.so9
index cd451c8..62b9584 100644
--- a/scripts/makefile.so9
+++ b/scripts/makefile.so9
@@ -8,7 +8,7 @@
 
 # Library name:
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 LIBNAME = libpng14
 
diff --git a/scripts/makefile.solaris b/scripts/makefile.solaris
index 9d0f190..9734eb7 100644
--- a/scripts/makefile.solaris
+++ b/scripts/makefile.solaris
@@ -8,7 +8,7 @@
 # Library name:
 LIBNAME = libpng14
 PNGMAJ = 14
-PNGMIN = 1.4.0beta50
+PNGMIN = 1.4.0beta51
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/pngos2.def b/scripts/pngos2.def
index beafa26..bdc2e40 100644
--- a/scripts/pngos2.def
+++ b/scripts/pngos2.def
@@ -2,7 +2,7 @@
 ; PNG.LIB module definition file for OS/2
 ;----------------------------------------
 
-; Version 1.4.0beta50
+; Version 1.4.0beta51
 
 LIBRARY		PNG
 DESCRIPTION	"PNG image compression library for OS/2"
diff --git a/scripts/pngwin.def b/scripts/pngwin.def
index 7fa083c..953a68a 100644
--- a/scripts/pngwin.def
+++ b/scripts/pngwin.def
@@ -5,7 +5,7 @@
 LIBRARY
 
 EXPORTS
-;Version 1.4.0beta50
+;Version 1.4.0beta51
   png_build_grayscale_palette
   png_chunk_error
   png_chunk_warning