[master] Changed argument of png_get_io_ptr() back to png_struct

because we promised not to change its signature, so it can be used
safely in configure scripts to detect libpng.
diff --git a/ANNOUNCE b/ANNOUNCE
index b79704e..d9887ae 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.4.6beta04 - January 21, 2011
+Libpng 1.4.6beta04 - January 22, 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.
@@ -38,7 +38,7 @@
 version 1.4.6beta03 [January 14, 2011]
   Fixed some typecasts in png_debug statements (Cosmin).
 
-version 1.4.6beta04 [January 21, 2011]
+version 1.4.6beta04 [January 22, 2011]
   Updated documentation of png_set|get_tRNS() (Thomas Klausner).
   Added const_png_structp and const_png_infop types, and used them in
     prototypes for most png_get_*() functions.
diff --git a/CHANGES b/CHANGES
index 29c5c69..41fba70 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2747,11 +2747,13 @@
 version 1.4.6beta03 [January 14, 2011]
   Fixed some typecasts in png_debug statements (Cosmin).
 
-version 1.4.6beta04 [January 21, 2011]
+version 1.4.6beta04 [January 22, 2011]
   Updated documentation of png_set|get_tRNS() (Thomas Klausner).
   Added const_png_structp and const_png_infop types, and used them in
     prototypes for most png_get_*() functions.
   In the manual, describe the png_get_IHDR() arguments in the correct order.
+  Ported change in png_do_rgb_to_gray() from libpng-1.5.1, to make
+    it more robust against internal libpng coding errors.
 
 Send comments/corrections/commendations to glennrp at users.sourceforge.net
 or to png-mng-implement at lists.sf.net (subscription required; visit
diff --git a/png.c b/png.c
index 8e052f1..acbead5 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.6 [January 21, 2011]
+ * Last changed in libpng 1.4.6 [January 22, 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.)
@@ -470,7 +470,7 @@
  * pointer before png_write_destroy() or png_read_destroy() are called.
  */
 png_voidp PNGAPI
-png_get_io_ptr(const_png_structp png_ptr)
+png_get_io_ptr(png_structp png_ptr)
 {
    if (png_ptr == NULL)
       return (NULL);
@@ -547,13 +547,13 @@
 #else
 #ifdef __STDC__
    return ((png_charp) PNG_STRING_NEWLINE \
-     "libpng version 1.4.6beta04 - January 21, 2011" PNG_STRING_NEWLINE \
+     "libpng version 1.4.6beta04 - January 22, 2011" PNG_STRING_NEWLINE \
      "Copyright (c) 1998-2010 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.6beta04 - January 21, 2011\
+      return ((png_charp) "libpng version 1.4.6beta04 - January 22, 2011\
       Copyright (c) 1998-2010 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 f2aa890..f0b3591 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.4.6beta04 - January 21, 2011
+ * libpng version 1.4.6beta04 - January 22, 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.4.6beta04 - January 21, 2011: Glenn
+ *  libpng versions 0.97, January 1998, through 1.4.6beta04 - January 22, 2011: Glenn
  *  See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -186,7 +186,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.4.6beta04, January 21, 2011, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.4.6beta04, January 22, 2011, are
  * Copyright (c) 2004, 2006-2010 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:
@@ -298,7 +298,7 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    January 21, 2011
+ *    January 22, 2011
  *
  *    Since the PNG Development group is an ad-hoc body, we can't make
  *    an official declaration.
@@ -362,7 +362,7 @@
 /* Version information for png.h - this should match the version in png.c */
 #define PNG_LIBPNG_VER_STRING "1.4.6beta04"
 #define PNG_HEADER_VERSION_STRING \
-   " libpng version 1.4.6beta04 - January 21, 2011\n"
+   " libpng version 1.4.6beta04 - January 22, 2011\n"
 
 #define PNG_LIBPNG_VER_SONUM   14
 #define PNG_LIBPNG_VER_DLLNUM  14
@@ -1993,7 +1993,7 @@
    png_voidp io_ptr, png_rw_ptr read_data_fn));
 
 /* Return the user pointer associated with the I/O functions */
-PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((const_png_structp png_ptr));
+PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
 
 PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
    png_read_status_ptr read_row_fn));
diff --git a/pngrtran.c b/pngrtran.c
index 36c3348..a475f9a 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -2290,7 +2290,7 @@
 
    png_debug(1, "in png_do_rgb_to_gray");
 
-   if (
+   if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) &&
       (row_info->color_type & PNG_COLOR_MASK_COLOR))
    {
       png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;