[libpng17] Avoid runtime checks when converting integer to png_byte with

Visual Studio (Sergey Kosarevsky)
diff --git a/ANNOUNCE b/ANNOUNCE
index 357548d..ee55fc6 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.7.0beta54 - February 25, 2015
+Libpng 1.7.0beta54 - February 28, 2015
 
 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.
@@ -731,7 +731,12 @@
 Version 1.7.0beta53 [February 23, 2015]
   Restored compiling of png_reciprocal2 with PNG_NO_16BIT.
 
-Version 1.7.0beta54 [February 25, 2015]
+Version 1.7.0beta54 [February 28, 2015]
+  Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block
+    of png.h.
+  Conditionally compile a small amount of code in pngwutil.c
+  Avoid runtime checks when converting integer to png_byte with
+    Visual Studio (Sergey Kosarevsky)
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/CHANGES b/CHANGES
index 995c2ef..cd9e5bf 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5021,7 +5021,12 @@
 Version 1.7.0beta53 [February 23, 2015]
   Restored compiling of png_reciprocal2 with PNG_NO_16BIT.
 
-Version 1.7.0beta54 [February 25, 2015]
+Version 1.7.0beta54 [February 28, 2015]
+  Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block
+    of png.h.
+  Conditionally compile a small amount of code in pngwutil.c
+  Avoid runtime checks when converting integer to png_byte with
+    Visual Studio (Sergey Kosarevsky)
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/png.h b/png.h
index 4e7a31a..84c3f42 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.7.0beta54 - February 25, 2015
+ * libpng version 1.7.0beta54 - February 28, 2015
  * Copyright (c) 1998-2015 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.7.0beta54 - February 25, 2015: Glenn
+ *   libpng versions 0.97, January 1998, through 1.7.0beta54 - February 28, 2015: Glenn
  *   See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -200,7 +200,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.7.0beta54, February 25, 2015, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.7.0beta54, February 28, 2015, are
  * Copyright (c) 2004, 2006-2015 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:
@@ -312,7 +312,7 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    February 25, 2015
+ *    February 28, 2015
  *
  *    Since the PNG Development group is an ad-hoc body, we can't make
  *    an official declaration.
@@ -382,7 +382,7 @@
 /* Version information for png.h - this should match the version in png.c */
 #define PNG_LIBPNG_VER_STRING "1.7.0beta54"
 #define PNG_HEADER_VERSION_STRING \
-     " libpng version 1.7.0beta54 - February 25, 2015\n"
+     " libpng version 1.7.0beta54 - February 28, 2015\n"
 
 #define PNG_LIBPNG_VER_SONUM   17
 #define PNG_LIBPNG_VER_DLLNUM  17
@@ -590,8 +590,10 @@
  * systems where (char) is more than 8 bits.
  */
 #define PNG_STRING_FROM_CHUNK(s,c)\
-   (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\
-   ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c)))
+   (void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \
+   ((char*)(s))[1]=(char)(((c)>>16) & 0xff),\
+   ((char*)(s))[2]=(char)(((c)>>8) & 0xff), \
+   ((char*)(s))[3]=(char)((c & 0xff)))
 
 /* Do the same but terminate with a null character. */
 #define PNG_CSTRING_FROM_CHUNK(s,c)\
@@ -1658,11 +1660,13 @@
  * header file (zlib.h) for an explination of the compression functions.
  */
 
+#ifdef PNG_WRITE_SUPPORTED
 /* Set the filtering method(s) used by libpng.  Currently, the only valid
  * value for "method" is 0.
  */
 PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method,
     int filters));
+#endif /* WRITE */
 
 /* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
  * These defines match the values in the PNG specification.
@@ -1694,6 +1698,7 @@
 #define PNG_ALL_FILTERS    (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
    PNG_FILTER_AVG | PNG_FILTER_PAETH)
 
+#ifdef PNG_WRITE_SUPPORTED
 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */
 /* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
  * defines, either the default (minimum-sum-of-absolute-differences), or
@@ -1740,7 +1745,6 @@
 #define PNG_FILTER_HEURISTIC_WEIGHTED   2  /* Experimental feature */
 #define PNG_FILTER_HEURISTIC_LAST       3  /* Not a valid value */
 
-#ifdef PNG_WRITE_SUPPORTED
 /* Set the library compression level.  Currently, valid values range from
  * 0 - 9, corresponding directly to the zlib compression levels 0 - 9
  * (0 - no compression, 9 - "maximal" compression).  Note that tests have
diff --git a/pngrutil.c b/pngrutil.c
index cb00eab..03d9331 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -3820,7 +3820,7 @@
    while (row < rp_end)
    {
       int a = *row + *prev_row++;
-      *row++ = (png_byte)a;
+      *row++ = (png_byte)(a&0xFF);
    }
 
    /* Remainder */
@@ -3851,7 +3851,7 @@
       if (pc < pa) a = c;
 
       a += *row;
-      *row++ = (png_byte)a;
+      *row++ = (png_byte)(a&0xFF);
    }
 }