Imported from libpng-1.2.0beta5.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index d1ba026..7a2cecd 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.2.0beta4 - June 23, 2001
+Libpng 1.2.0beta5 - August 8, 2001
 
 This is a public release of libpng, intended for use in production codes.
 
@@ -18,6 +18,13 @@
      of png_write_oFFS width and height from png_uint_32 to png_int_32.
   Updated example.c
   Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c
+  Revised makefile.gcmmx
+  Revised pnggccrd.c to conditionally compile some thread-unsafe code only
+     when PNG_THREAD_UNSAFE_OK is defined.
+  Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with
+     value exceeding 2^bit_depth-1
+  Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c
+  Removed restriction that do_invert_mono only operate on 1-bit opaque files
 
 Send comments/corrections/commendations to
 png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
diff --git a/CHANGES b/CHANGES
index caabf7f..caf9310 100644
--- a/CHANGES
+++ b/CHANGES
@@ -967,6 +967,16 @@
      of png_write_oFFS width and height from png_uint_32 to png_int_32.
   Updated example.c
   Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c
+version 1.2.0beta5 [August 8, 2001]
+  Revised contrib/gregbook
+  Revised makefile.gcmmx
+  Revised pnggccrd.c to conditionally compile some thread-unsafe code only
+     when PNG_THREAD_UNSAFE_OK is defined.
+  Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with
+     value exceeding 2^bit_depth-1
+  Revised makefile.sgi and makefile.sggcc
+  Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c
+  Removed restriction that do_invert_mono only operate on 1-bit opaque files
 
 Send comments/corrections/commendations to
 png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
diff --git a/INSTALL b/INSTALL
index 436ed1c..d33151b 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
 
-Installing libpng version 1.2.0beta4 - June 23, 2001
+Installing libpng version 1.2.0beta5 - August 8, 2001
 
 Before installing libpng, you must first install zlib.  zlib
 can usually be found wherever you got libpng.  zlib can be
@@ -10,7 +10,7 @@
 version of zlib that's installed.
 
 You can rename the directories that you downloaded (they
-might be called "libpng-1.2.0beta4" or "lpng109" and "zlib-1.1.3"
+might be called "libpng-1.2.0beta5" or "lpng109" and "zlib-1.1.3"
 or "zlib113") so that you have directories called "zlib" and "libpng".
 
 Your directory structure should look like this:
@@ -64,8 +64,8 @@
 include
 
  makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)
- makefile.linux    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.2.0beta4)
- makefile.gcmmx    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.2.0beta4,
+ makefile.linux    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.2.0beta5)
+ makefile.gcmmx    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.2.0beta5,
                        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
@@ -82,9 +82,9 @@
  makefile.macosx   =>  MACOS X Makefile
  makefile.netbsd   =>  NetBSD/cc makefile, uses PNGGCCRD
  makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)
- makefile.sggcc    =>  Silicon Graphics (gcc, creates libpng.so.2.1.2.0beta4)
+ makefile.sggcc    =>  Silicon Graphics (gcc, creates libpng.so.2.1.2.0beta5)
  makefile.sunos    =>  Sun makefile
- makefile.solaris  =>  Solaris 2.X makefile (gcc, creates libpng.so.2.1.2.0beta4)
+ makefile.solaris  =>  Solaris 2.X makefile (gcc, creates libpng.so.2.1.2.0beta5)
  makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc
  makefile.mips     =>  MIPS makefile
  makefile.acorn    =>  Acorn makefile
diff --git a/LICENSE b/LICENSE
index 2c9e223..26d2c90 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.0.7, July 1, 2000, through 1.2.0beta4, June 23, 2001, are
+libpng versions 1.0.7, July 1, 2000, through 1.2.0beta5, August 8, 2001, are
 Copyright (c) 2000 Glenn Randers-Pehrson
 and are distributed according to the same disclaimer and license as libpng-1.0.6
 with the following individuals added to the list of Contributing Authors
@@ -99,4 +99,4 @@
 
 Glenn Randers-Pehrson
 randeg@alum.rpi.edu
-June 23, 2001
+August 8, 2001
diff --git a/README b/README
index c497e3a..4aadc09 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng 1.2.0beta4 - June 23, 2001 (shared library 2.1)
+README for libpng 1.2.0beta5 - August 8, 2001 (shared library 2.1)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
@@ -187,9 +187,9 @@
        descrip.mms      =>  VMS makefile for MMS or MMK
        makefile.std     =>  Generic UNIX makefile (cc, creates static libpng.a)
        makefile.linux   =>  Linux/ELF makefile
-                            (gcc, creates libpng.so.2.1.2.0beta4)
+                            (gcc, creates libpng.so.2.1.2.0beta5)
        makefile.gcmmx   =>  Linux/ELF makefile (gcc, creates
-                            libpng.so.2.1.2.0beta4, uses assembler code
+                            libpng.so.2.1.2.0beta5, 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
@@ -206,10 +206,10 @@
        makefile.macosx  =>  MACOS X Makefile
        makefile.netbsd  =>  NetBSD/cc makefile, uses PNGGCCRD
        makefile.sgi     =>  Silicon Graphics IRIX (cc, creates static lib)
-       makefile.sggcc   =>  Silicon Graphics (gcc, creates libpng.so.2.1.2.0beta4)
+       makefile.sggcc   =>  Silicon Graphics (gcc, creates libpng.so.2.1.2.0beta5)
        makefile.sunos   =>  Sun makefile
        makefile.solaris =>  Solaris 2.X makefile
-                            (gcc, creates libpng.so.2.1.2.0beta4)
+                            (gcc, creates libpng.so.2.1.2.0beta5)
        makefile.sco     =>  For SCO OSr5  ELF and Unixware 7 with Native cc
        makefile.mips    =>  MIPS makefile
        makefile.acorn   =>  Acorn makefile
diff --git a/Y2KINFO b/Y2KINFO
index 657780a..573bd51 100644
--- a/Y2KINFO
+++ b/Y2KINFO
@@ -1,13 +1,13 @@
    Y2K compliance in libpng:
    =========================
 
-      June 23, 2001
+      August 8, 2001
 
       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.2.0beta4 are Y2K compliant.  It is my belief that earlier
+      upward through 1.2.0beta5 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
diff --git a/configure b/configure
index 257d841..9ef33f1 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 echo "
-  There is no \"configure\" script for Libpng-1.2.0beta4.  Instead, please
+  There is no \"configure\" script for Libpng-1.2.0beta5.  Instead, please
   copy the appropriate makefile for your system from the \"scripts\"
   directory.  Read the INSTALL file for more details.
 "
diff --git a/contrib/gregbook/LICENSE b/contrib/gregbook/LICENSE
index 5714772..175ebfd 100644
--- a/contrib/gregbook/LICENSE
+++ b/contrib/gregbook/LICENSE
@@ -1,6 +1,6 @@
   ---------------------------------------------------------------------------
 
-      Copyright (c) 1998-2000 Greg Roelofs.  All rights reserved.
+      Copyright (c) 1998-2001 Greg Roelofs.  All rights reserved.
 
       This software is provided "as is," without warranty of any kind,
       express or implied.  In no event shall the author or contributors
diff --git a/contrib/gregbook/README b/contrib/gregbook/README
index 4bb80b4..c67045c 100644
--- a/contrib/gregbook/README
+++ b/contrib/gregbook/README
@@ -44,10 +44,10 @@
 
    toucan.png         transparent PNG for testing (by Stefan Schneider)
 
-Note that the programs are designed to be functional, but their primary
-purpose is to illustrate how to use libpng to add PNG support to other
-programs.  As such, their user interfaces are crude and definitely not
-intended for everyday use.
+Note that, although the programs are designed to be functional, their
+primary purpose is to illustrate how to use libpng to add PNG support to
+other programs.  As such, their user interfaces are crude and definitely
+are not intended for everyday use.
 
 Please see http://www.libpng.org/pub/png/pngbook.html for further infor-
 mation and links to the latest version of the source code, and Chapters
@@ -55,7 +55,7 @@
 
 Greg Roelofs
 newt@pobox.com
-30 May 2001
+30 June 2001
 
 
 BUILD INSTRUCTIONS
@@ -131,7 +131,7 @@
      current folder.  Like the Unix versions, the two windowed programs
      (rpng and rpng2) now display a usage screen in a console window when
      invoked without command-line arguments; this is new behavior as of
-     the May 2001 release.  Note that the programs use the Unix-style "-"
+     the June 2001 release.  Note that the programs use the Unix-style "-"
      character to specify options, instead of the more common DOS/Windows
      "/" character.  (For example:  "rpng2-win -bgpat 4 foo.png", not
      "rpng2-win /bgpat 4 foo.png")
diff --git a/contrib/gregbook/README.w32 b/contrib/gregbook/README.w32
deleted file mode 100644
index 58e43cd..0000000
--- a/contrib/gregbook/README.w32
+++ /dev/null
@@ -1,53 +0,0 @@
-See the main README file for basic instructions on compiling and running
-the programs.  See http://www.libpng.org/pub/png/pngbook.html for further
-information and links to the source code, and Chapters 13-15 of the book
-for detailed discussion of the three programs.
-
-Since the two viewers, rpng and rpng2, are both designed to write infor-
-mation to the console (i.e., a DOS-window command line) while displaying
-the image in a graphical window--and since I haven't yet figured out how
-to do that under Windows--here are the usage screens for the two programs:
-
-
-rpng-win 1.02 of 19 March 2000:  Simple PNG Viewer for Windows
-   Compiled with libpng 1.0.5; using libpng 1.0.5.
-   Compiled with zlib 1.1.3; using zlib 1.1.3.
-
-Usage:  rpng-win [-gamma exp] [-bgcolor bg] file.png
-    exp 	transfer-function exponent (``gamma'') of the display
-		  system in floating-point format (e.g., ``2.2''); equal
-		  to the product of the lookup-table exponent (varies)
-		  and the CRT exponent (usually 2.2); must be positive
-    bg  	desired background color in 7-character hex RGB format
-		  (e.g., ``#ff7f00'' for orange:  same as HTML colors);
-		  used with transparent images
-
-Press Q, Esc or mouse button 1 after image is displayed to quit.
-
-
-rpng2-win 1.04 of 19 March 2000:  Progressive PNG Viewer for Windows
-   Compiled with libpng 1.0.5; using libpng 1.0.5.
-   Compiled with zlib 1.1.3; using zlib 1.1.3.
-
-Usage:  rpng2-win [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing] file.png
-
-    exp 	transfer-function exponent (``gamma'') of the display
-		  system in floating-point format (e.g., ``2.2''); equal
-		  to the product of the lookup-table exponent (varies)
-		  and the CRT exponent (usually 2.2); must be positive
-    bg  	desired background color in 7-character hex RGB format
-		  (e.g., ``#ff7f00'' for orange:  same as HTML colors);
-		  used with transparent images; overrides -bgpat
-    pat 	desired background pattern number (1-16); used with
-		  transparent images; overrides -bgcolor
-    -timing	enables delay for every block read, to simulate modem
-		  download of image (~36 Kbps)
-
-Press Q, Esc or mouse button 1 after image is displayed to quit.
-
-
-The usage screen for the third (non-windowed) program, wpng, can be seen
-simply by invoking it without any parameters (``wpng'').
-
-Greg Roelofs
-19 March 2000
diff --git a/contrib/gregbook/rpng2-win.c b/contrib/gregbook/rpng2-win.c
index 6cbd0fa..0c1a9d1 100644
--- a/contrib/gregbook/rpng2-win.c
+++ b/contrib/gregbook/rpng2-win.c
@@ -26,6 +26,7 @@
               fixed command-line parsing bug
     - 1.10:  enabled "message window"/console (thanks to David Geldreich)
     - 1.20:  added runtime MMX-enabling/disabling and new -mmx* options
+    - 1.21:  made minor tweak to usage screen to fit within 25-line console
 
   ---------------------------------------------------------------------------
 
@@ -56,7 +57,7 @@
 
 #define PROGNAME  "rpng2-win"
 #define LONGNAME  "Progressive PNG Viewer for Windows"
-#define VERSION   "1.20 of 28 May 2001"
+#define VERSION   "1.21 of 29 June 2001"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -451,12 +452,13 @@
           "\t\t  combining rows, and expanding interlacing, respectively\n"
 #endif
           "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
-          "Press Q or Esc to quit this usage screen.\n"
-          "\n", PROGNAME,
+          "Press Q or Esc to quit this usage screen. ",
+          PROGNAME,
 #if (defined(__i386__) || defined(_M_IX86))
           strlen(PROGNAME), " ",
 #endif
           strlen(PROGNAME), " ", default_display_exponent, num_bgpat);
+        fflush(stderr);
         do
             ch = _getch();
         while (ch != 'q' && ch != 'Q' && ch != 0x1B);
@@ -466,6 +468,7 @@
         fprintf(stderr,
           "\n   [console window:  closing this window will terminate %s]\n\n",
           PROGNAME);
+        fflush(stderr);
     }
 
 
diff --git a/libpng.3 b/libpng.3
index 5b66ca8..579b46b 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "June 23, 2001"
+.TH LIBPNG 3 "August 8, 2001"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.2.0beta4
+libpng \- Portable Network Graphics (PNG) Reference Library 1.2.0beta5
 .SH SYNOPSIS
 \fI\fB
 
@@ -787,7 +787,7 @@
 .SH LIBPNG.TXT
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.2.0beta4 - June 23, 2001
+ libpng version 1.2.0beta5 - August 8, 2001
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alum.rpi.edu>
  Copyright (c) 1998-2001 Glenn Randers-Pehrson
@@ -865,7 +865,9 @@
 instances of the structures.  Each thread should have its own
 png_struct and png_info instances, and thus its own image.
 Libpng does not protect itself against two threads using the
-same instance of a structure.
+same instance of a structure.  Note: thread safety may be defeated
+by use of some of the MMX assembler code in pnggccrd.c, which is only
+compiled when the user defines PNG_THREAD_UNSAFE_OK.
 
 
 .SH II. Structures
@@ -1577,7 +1579,7 @@
 convert the PNG pixel data back to the original bit depth of the image.
 This call reduces the pixels back down to the original bit depth:
 
-    png_color_16p sig_bit;
+    png_color_8p sig_bit;
 
     if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
         png_set_shift(png_ptr, sig_bit);
@@ -1789,7 +1791,13 @@
 The following code will reverse this (make black be one and white be
 zero):
 
-   if (bit_depth == 1 && color_type == PNG_COLOR_GRAY)
+   if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
+      png_set_invert_mono(png_ptr);
+
+This function can also be used to invert grayscale and gray-alpha images:
+
+   if (color_type == PNG_COLOR_TYPE_GRAY ||
+        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
       png_set_invert_mono(png_ptr);
 
 PNG files store 16 bit pixels in network byte order (big-endian,
@@ -3605,13 +3613,13 @@
 
 .SH IX. Y2K Compliance in libpng
 
-June 23, 2001
+August 8, 2001
 
 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.2.0beta4 are Y2K compliant.  It is my belief that earlier
+upward through 1.2.0beta5 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
@@ -3786,7 +3794,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.2.0beta4 - June 23, 2001:
+Libpng version 1.2.0beta5 - August 8, 2001:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (randeg@alum.rpi.edu).
 
@@ -3803,7 +3811,7 @@
 If you modify libpng you may insert additional notices immediately following
 this sentence.
 
-libpng versions 1.0.7, July 1, 2000, through  1.2.0beta4, June 23, 2001, are
+libpng versions 1.0.7, July 1, 2000, through  1.2.0beta5, August 8, 2001, are
 Copyright (c) 2000-2001 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.0.6
 with the following individuals added to the list of Contributing Authors
@@ -3895,7 +3903,7 @@
 
 Glenn Randers-Pehrson
 randeg@alum.rpi.edu
-June 23, 2001
+August 8, 2001
 
 .\" end of man page
 
diff --git a/libpng.txt b/libpng.txt
index 0b80568..0e27c17 100644
--- a/libpng.txt
+++ b/libpng.txt
@@ -1,6 +1,6 @@
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.2.0beta4 - June 23, 2001
+ libpng version 1.2.0beta5 - August 8, 2001
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alum.rpi.edu>
  Copyright (c) 1998-2001 Glenn Randers-Pehrson
@@ -78,7 +78,9 @@
 instances of the structures.  Each thread should have its own
 png_struct and png_info instances, and thus its own image.
 Libpng does not protect itself against two threads using the
-same instance of a structure.
+same instance of a structure.  Note: thread safety may be defeated
+by use of some of the MMX assembler code in pnggccrd.c, which is only
+compiled when the user defines PNG_THREAD_UNSAFE_OK.
 
 
 II. Structures
@@ -790,7 +792,7 @@
 convert the PNG pixel data back to the original bit depth of the image.
 This call reduces the pixels back down to the original bit depth:
 
-    png_color_16p sig_bit;
+    png_color_8p sig_bit;
 
     if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
         png_set_shift(png_ptr, sig_bit);
@@ -1002,7 +1004,13 @@
 The following code will reverse this (make black be one and white be
 zero):
 
-   if (bit_depth == 1 && color_type == PNG_COLOR_GRAY)
+   if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
+      png_set_invert_mono(png_ptr);
+
+This function can also be used to invert grayscale and gray-alpha images:
+
+   if (color_type == PNG_COLOR_TYPE_GRAY ||
+        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
       png_set_invert_mono(png_ptr);
 
 PNG files store 16 bit pixels in network byte order (big-endian,
@@ -2818,13 +2826,13 @@
 
 IX. Y2K Compliance in libpng
 
-June 23, 2001
+August 8, 2001
 
 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.2.0beta4 are Y2K compliant.  It is my belief that earlier
+upward through 1.2.0beta5 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/libpngpf.3 b/libpngpf.3
index f3bf997..34f00ec 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 "June 23, 2001"
+.TH LIBPNGPF 3 "August 8, 2001"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.2.0beta4
+libpng \- Portable Network Graphics (PNG) Reference Library 1.2.0beta5
 (private functions)
 .SH SYNOPSIS
 \fB#include <png.h>\fP
diff --git a/png.5 b/png.5
index feabe83..cd7faf0 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "June 23, 2001"
+.TH PNG 5 "August 8, 2001"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 3e2c01d..e62d9a4 100644
--- a/png.c
+++ b/png.c
@@ -1,7 +1,7 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * libpng version 1.2.0beta4 - June 23, 2001
+ * libpng version 1.2.0beta5 - August 8, 2001
  * Copyright (c) 1998-2001 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.)
@@ -13,14 +13,14 @@
 #include "png.h"
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_0beta4 Your_png_h_is_not_version_1_2_0beta4;
+typedef version_1_2_0beta5 Your_png_h_is_not_version_1_2_0beta5;
 
 /* Version information for C files.  This had better match the version
  * string defined in png.h.  */
 
 #ifdef PNG_USE_GLOBAL_ARRAYS
 /* png_libpng_ver was changed to a function in version 1.0.5c */
-const char png_libpng_ver[18] = "1.2.0beta4";
+const char png_libpng_ver[18] = "1.2.0beta5";
 
 /* png_sig was changed to a function in version 1.0.5c */
 /* Place to hold the signature string for a PNG file. */
@@ -646,7 +646,7 @@
 png_get_copyright(png_structp png_ptr)
 {
    if (png_ptr != NULL || png_ptr == NULL)  /* silence compiler warning */
-   return ((png_charp) "\n libpng version 1.2.0beta4 - June 23, 2001\n\
+   return ((png_charp) "\n libpng version 1.2.0beta5 - August 8, 2001\n\
    Copyright (c) 1998-2001 Glenn Randers-Pehrson\n\
    Copyright (c) 1996, 1997 Andreas Dilger\n\
    Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n");
@@ -664,8 +664,8 @@
 {
    /* Version of *.c files used when building libpng */
    if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
-      return((png_charp) "1.2.0beta4");
-   return((png_charp) "1.2.0beta4");
+      return((png_charp) "1.2.0beta5");
+   return((png_charp) "1.2.0beta5");
 }
 
 png_charp PNGAPI
diff --git a/png.h b/png.h
index 6db4e0c..06a6533 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.2.0beta4 - June 23, 2001
+ * libpng version 1.2.0beta5 - August 8, 2001
  * Copyright (c) 1998-2001 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.2.0beta4 - June 23, 2001: Glenn
+ *  libpng versions 0.97, January 1998, through 1.2.0beta5 - August 8, 2001: Glenn
  *  See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -105,7 +105,7 @@
  * If you modify libpng you may insert additional notices immediately following
  * this sentence.
  *
- * libpng versions 1.0.7, July 1, 2000, through  1.2.0beta4, June 23, 2001, are
+ * libpng versions 1.0.7, July 1, 2000, through  1.2.0beta5, August 8, 2001, are
  * Copyright (c) 2000, 2001 Glenn Randers-Pehrson, and are
  * distributed according to the same disclaimer and license as libpng-1.0.6
  * with the following individuals added to the list of Contributing Authors
@@ -210,13 +210,13 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    June 23, 2001
+ *    August 8, 2001
  *
  *    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.2.0beta4 are Y2K compliant.  It is my belief that earlier
+ *    upward through 1.2.0beta5 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
@@ -272,7 +272,7 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.2.0beta4"
+#define PNG_LIBPNG_VER_STRING "1.2.0beta5"
 
 #define PNG_LIBPNG_VER_SONUM   3
 #define PNG_LIBPNG_VER_DLLNUM  %DLLNUM%
@@ -284,7 +284,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  4
+#define PNG_LIBPNG_VER_BUILD  5
 
 #define PNG_LIBPNG_BUILD_ALPHA    1
 #define PNG_LIBPNG_BUILD_BETA     2
@@ -1212,9 +1212,9 @@
 
 
 /* This prevents a compiler error in png_get_copyright() in png.c if png.c
-   and png.h are both at version 1.2.0beta4
+   and png.h are both at version 1.2.0beta5
  */
-typedef png_structp version_1_2_0beta4;
+typedef png_structp version_1_2_0beta5;
 
 typedef png_struct FAR * FAR * png_structpp;
 
@@ -2331,7 +2331,7 @@
 /* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */
 
 #define PNG_HEADER_VERSION_STRING \
-   " libpng version 1.2.0beta4 - June 23, 2001 (header)\n"
+   " libpng version 1.2.0beta5 - August 8, 2001 (header)\n"
 
 #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
 /* With these routines we avoid an integer divide, which will be slower on
diff --git a/pngasmrd.h b/pngasmrd.h
index d7975c5..033e36c 100644
--- a/pngasmrd.h
+++ b/pngasmrd.h
@@ -1,6 +1,6 @@
 /* pngasmrd.h - assembler version of utilities to read a PNG file
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 2001 Glenn Randers-Pehrson
  *
diff --git a/pngconf.h b/pngconf.h
index 997153a..a66b495 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,6 +1,6 @@
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -638,6 +638,12 @@
 #  endif
 #endif
 
+/* If you are sure that you don't need thread safety and you are compiling
+   with PNG_USE_PNGCCRD for an MMX application, you can define this for
+   faster execution.  See pnggccrd.c.
+#define PNG_THREAD_UNSAFE_OK
+*/
+
 #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
 #  define PNG_USER_MEM_SUPPORTED
 #endif
diff --git a/pngerror.c b/pngerror.c
index e224eef..60a6571 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -1,7 +1,7 @@
 
 /* pngerror.c - stub functions for i/o and memory allocation
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pnggccrd.c b/pnggccrd.c
index 928133a..0d448f0 100644
--- a/pnggccrd.c
+++ b/pnggccrd.c
@@ -6,7 +6,7 @@
  *     and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
  *     for Intel's performance analysis of the MMX vs. non-MMX code.
  *
- * libpng version 1.2.0beta4 - June 23, 2001
+ * libpng version 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * Copyright (c) 1998, Intel Corporation
@@ -252,7 +252,6 @@
  * so define them without: */
 #if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__)
 #  define _mmx_supported  mmx_supported
-#  define _unmask         unmask
 #  define _const4         const4
 #  define _const6         const6
 #  define _mask8_0        mask8_0
@@ -271,9 +270,6 @@
 #  define _mask48_2       mask48_2
 #  define _mask48_1       mask48_1
 #  define _mask48_0       mask48_0
-#  define _FullLength     FullLength
-#  define _MMXLength      MMXLength
-#  define _dif            dif
 #  define _LBCarryMask    LBCarryMask
 #  define _HBClearMask    HBClearMask
 #  define _ActiveMask     ActiveMask
@@ -281,10 +277,16 @@
 #  define _ActiveMaskEnd  ActiveMaskEnd
 #  define _ShiftBpp       ShiftBpp
 #  define _ShiftRem       ShiftRem
+#ifdef PNG_THREAD_UNSAFE_OK
+#  define _unmask         unmask
+#  define _FullLength     FullLength
+#  define _MMXLength      MMXLength
+#  define _dif            dif
 #  define _patemp         patemp
 #  define _pbtemp         pbtemp
 #  define _pctemp         pctemp
 #endif
+#endif
 
 
 /* These constants are used in the inlined MMX assembly code.
@@ -296,7 +298,9 @@
  *  "more than 10 operands in `asm'" errors when %ebx is used to preload unmask
  *  in the non-PIC case, so we'll just use the global unconditionally now.
  */
+#ifdef PNG_THREAD_UNSAFE_OK
 static int _unmask;
+#endif
 
 static unsigned long long _mask8_0  = 0x0102040810204080LL;
 
@@ -325,24 +329,29 @@
 
 // These are used in the row-filter routines and should/would be local
 //  variables if not for gcc addressing limitations.
+// WARNING: Their presence probably defeats the thread safety of libpng.
 
+#ifdef PNG_THREAD_UNSAFE_OK
 static png_uint_32  _FullLength;
 static png_uint_32  _MMXLength;
 static int          _dif;
 static int          _patemp;	// temp variables for Paeth routine
 static int          _pbtemp;
 static int          _pctemp;
+#endif
 
-static void /* PRIVATE */
+void /* PRIVATE */
 png_squelch_warnings(void)
 {
+#ifdef PNG_THREAD_UNSAFE_OK
    _dif = _dif;
    _patemp = _patemp;
    _pbtemp = _pbtemp;
    _pctemp = _pctemp;
+   _MMXLength = _MMXLength;
+#endif
    _const4  = _const4;
    _const6  = _const6;
-   _MMXLength = _MMXLength;
    _mask8_0  = _mask8_0;
    _mask16_1 = _mask16_1;
    _mask16_0 = _mask16_0;
@@ -587,7 +596,7 @@
             png_bytep srcptr;
             png_bytep dstptr;
 
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
                 /* && _mmx_supported */ )
             {
@@ -721,7 +730,7 @@
             png_bytep srcptr;
             png_bytep dstptr;
 
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
                 /* && _mmx_supported */ )
             {
@@ -870,7 +879,7 @@
             png_bytep srcptr;
             png_bytep dstptr;
 
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
                 /* && _mmx_supported */ )
             {
@@ -1034,7 +1043,7 @@
             png_bytep srcptr;
             png_bytep dstptr;
 
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
                 /* && _mmx_supported */ )
             {
@@ -1205,7 +1214,7 @@
             png_bytep srcptr;
             png_bytep dstptr;
 
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
                 /* && _mmx_supported */ )
             {
@@ -1431,10 +1440,7 @@
          default: /* png_ptr->row_info.pixel_depth != 1,2,4,8,16,24,32,48,64 */
          {
             /* this should never happen */
-            fprintf(stderr,
-              "libpng internal error:  png_ptr->row_info.pixel_depth = %d\n",
-              png_ptr->row_info.pixel_depth);
-            fflush(stderr);
+            png_warning(png_ptr, "Invalid row_info.pixel_depth in pnggccrd");
             break;
          }
       } /* end switch (png_ptr->row_info.pixel_depth) */
@@ -2720,6 +2726,7 @@
   _HBClearMask = {0x7f7f7f7f7f7f7f7fLL},
   _ActiveMask, _ActiveMask2, _ActiveMaskEnd, _ShiftBpp, _ShiftRem;
 
+#ifdef PNG_THREAD_UNSAFE_OK
 //===========================================================================//
 //                                                                           //
 //           P N G _ R E A D _ F I L T E R _ R O W _ M M X _ A V G           //
@@ -3204,8 +3211,8 @@
       {
 
          // GRR:  PRINT ERROR HERE:  SHOULD NEVER BE REACHED
-         fprintf(stderr,
-           "libpng:  internal logic error (png_read_filter_row_mmx_avg())\n");
+        png_warning(png_ptr,
+          "Internal logic error in pnggccrd (png_read_filter_row_mmx_avg())");
 
 #if 0
         __asm__ __volatile__ (
@@ -3301,10 +3308,11 @@
    );
 
 } /* end png_read_filter_row_mmx_avg() */
+#endif
 
 
 
-
+#ifdef PNG_THREAD_UNSAFE_OK
 //===========================================================================//
 //                                                                           //
 //         P N G _ R E A D _ F I L T E R _ R O W _ M M X _ P A E T H         //
@@ -4347,10 +4355,12 @@
    );
 
 } /* end png_read_filter_row_mmx_paeth() */
+#endif
 
 
 
 
+#ifdef PNG_THREAD_UNSAFE_OK
 //===========================================================================//
 //                                                                           //
 //           P N G _ R E A D _ F I L T E R _ R O W _ M M X _ S U B           //
@@ -4769,6 +4779,7 @@
    );
 
 } // end of png_read_filter_row_mmx_sub()
+#endif
 
 
 
@@ -4956,7 +4967,7 @@
       case 0: sprintf(filnm, "none");
          break;
       case 1: sprintf(filnm, "sub-%s",
-#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
         (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" : 
 #endif
 "x86");
@@ -4968,13 +4979,13 @@
  "x86");
          break;
       case 3: sprintf(filnm, "avg-%s",
-#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
         (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" :
 #endif
  "x86");
          break;
       case 4: sprintf(filnm, "Paeth-%s",
-#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
         (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":
 #endif
 "x86");
@@ -4995,7 +5006,7 @@
          break;
 
       case PNG_FILTER_VALUE_SUB:
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
          if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
              (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
              (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
@@ -5044,7 +5055,7 @@
          break;
 
       case PNG_FILTER_VALUE_AVG:
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
          if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
              (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
              (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
@@ -5078,7 +5089,7 @@
          break;
 
       case PNG_FILTER_VALUE_PAETH:
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
          if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
              (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
              (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
diff --git a/pngget.c b/pngget.c
index ec01a1d..2b53522 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,7 +1,7 @@
 
 /* pngget.c - retrieval of values from info struct
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngmem.c b/pngmem.c
index 7e0aecf..6e6edf5 100644
--- a/pngmem.c
+++ b/pngmem.c
@@ -1,7 +1,7 @@
 
 /* pngmem.c - stub functions for memory allocation
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngpread.c b/pngpread.c
index bc2adf9..e57a357 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1,7 +1,7 @@
 
 /* pngpread.c - read a png file in push mode
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngread.c b/pngread.c
index d9f8c9f..94a1da5 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,7 +1,7 @@
 
 /* pngread.c - read a PNG file
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -769,7 +769,7 @@
  * not called png_set_interlace_handling(), the display_row buffer will
  * be ignored, so pass NULL to it.
  *
- * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.0beta4
+ * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.0beta5
  */
 
 void PNGAPI
@@ -818,7 +818,7 @@
  * only call this function once.  If you desire to have an image for
  * each pass of a interlaced image, use png_read_rows() instead.
  *
- * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.0beta4
+ * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.0beta5
  */
 void PNGAPI
 png_read_image(png_structp png_ptr, png_bytepp image)
diff --git a/pngrio.c b/pngrio.c
index 3a210cf..633b6c3 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -1,7 +1,7 @@
 
 /* pngrio.c - functions for data input
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngrtran.c b/pngrtran.c
index 59b7fc1..29a534e 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,7 +1,7 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngrutil.c b/pngrutil.c
index 986e3c1..c39c701 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,7 +1,7 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngset.c b/pngset.c
index 062229b..2aba58e 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,7 +1,7 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngtest.c b/pngtest.c
index 471a3aa..46c6c3a 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,7 +1,7 @@
 
 /* pngtest.c - a simple test program to test libpng
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -487,7 +487,7 @@
       buffer and once to get a new free list entry. */
    {
       memory_infop pinfo = (memory_infop)png_malloc_default(png_ptr,
-         sizeof *pinfo);
+         (png_uint_32)sizeof *pinfo);
       pinfo->size = size;
       current_allocation += size;
       total_allocation += size;
@@ -1279,7 +1279,7 @@
    fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
       PNG_HEADER_VERSION_STRING);
    fprintf(STDERR," sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n",
-                    sizeof(png_struct), sizeof(png_info));
+                    (long)sizeof(png_struct), (long)sizeof(png_info));
 
    /* Do some consistency checking on the memory allocation settings, I'm
       not sure this matters, but it is nice to know, the first of these
@@ -1510,4 +1510,4 @@
 }
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_0beta4 your_png_h_is_not_version_1_2_0beta4;
+typedef version_1_2_0beta5 your_png_h_is_not_version_1_2_0beta5;
diff --git a/pngtrans.c b/pngtrans.c
index 5518dc7..359c988 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)
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -153,11 +153,14 @@
 png_do_invert(png_row_infop row_info, png_bytep row)
 {
    png_debug(1, "in png_do_invert\n");
-   if (row_info->bit_depth == 1 &&
+  /* This test removed from libpng version 1.0.13 and 1.2.0:
+   *   if (row_info->bit_depth == 1 &&
+   */
 #if defined(PNG_USELESS_TESTS_SUPPORTED)
-       row != NULL && row_info != NULL &&
+   if (row == NULL || row_info == NULL)
+     return;
 #endif
-       row_info->color_type == PNG_COLOR_TYPE_GRAY)
+   if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
    {
       png_bytep rp = row;
       png_uint_32 i;
@@ -169,6 +172,33 @@
          rp++;
       }
    }
+   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
+      row_info->bit_depth == 8)
+   {
+      png_bytep rp = row;
+      png_uint_32 i;
+      png_uint_32 istop = row_info->rowbytes;
+
+      for (i = 0; i < istop; i+=2)
+      {
+         *rp = (png_byte)(~(*rp));
+         rp+=2;
+      }
+   }
+   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
+      row_info->bit_depth == 16)
+   {
+      png_bytep rp = row;
+      png_uint_32 i;
+      png_uint_32 istop = row_info->rowbytes;
+
+      for (i = 0; i < istop; i+=4)
+      {
+         *rp = (png_byte)(~(*rp));
+         *(rp+1) = (png_byte)(~(*(rp+1)));
+         rp+=4;
+      }
+   }
 }
 #endif
 
diff --git a/pngvcrd.c b/pngvcrd.c
index 9aa2af0..2b6248a 100644
--- a/pngvcrd.c
+++ b/pngvcrd.c
@@ -2,7 +2,7 @@
  *
  * For Intel x86 CPU and Microsoft Visual C++ compiler
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * Copyright (c) 1998, Intel Corporation
diff --git a/pngwio.c b/pngwio.c
index a913f91..5854b37 100644
--- a/pngwio.c
+++ b/pngwio.c
@@ -1,7 +1,7 @@
 
 /* pngwio.c - functions for data output
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwrite.c b/pngwrite.c
index abdd837..f248f43 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,7 +1,7 @@
 
 /* pngwrite.c - general routines to write a PNG file
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwtran.c b/pngwtran.c
index a59b18b..3227d8f 100644
--- a/pngwtran.c
+++ b/pngwtran.c
@@ -1,7 +1,7 @@
 
 /* pngwtran.c - transforms the data in a row for PNG writers
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwutil.c b/pngwutil.c
index 841fcc2..68bb9a4 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,7 +1,7 @@
 
 /* pngwutil.c - utilities to write a PNG file
  *
- * libpng 1.2.0beta4 - June 23, 2001
+ * libpng 1.2.0beta5 - August 8, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -996,6 +996,12 @@
    else if (color_type == PNG_COLOR_TYPE_GRAY)
    {
       /* one 16 bit value */
+      if(tran->gray >= (1 << png_ptr->bit_depth))
+      {
+         png_warning(png_ptr,
+           "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
+         return;
+      }
       png_save_uint_16(buf, tran->gray);
       png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
    }
@@ -1005,6 +1011,12 @@
       png_save_uint_16(buf, tran->red);
       png_save_uint_16(buf + 2, tran->green);
       png_save_uint_16(buf + 4, tran->blue);
+      if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
+         {
+            png_warning(png_ptr,
+              "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
+            return;
+         }
       png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
    }
    else
@@ -1045,10 +1057,22 @@
       png_save_uint_16(buf, back->red);
       png_save_uint_16(buf + 2, back->green);
       png_save_uint_16(buf + 4, back->blue);
+      if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
+         {
+            png_warning(png_ptr,
+              "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
+            return;
+         }
       png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
    }
    else
    {
+      if(back->gray >= (1 << png_ptr->bit_depth))
+      {
+         png_warning(png_ptr,
+           "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
+         return;
+      }
       png_save_uint_16(buf, back->gray);
       png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
    }
diff --git a/projects/msvc/README.txt b/projects/msvc/README.txt
index 80250f4..b5f402e 100644
--- a/projects/msvc/README.txt
+++ b/projects/msvc/README.txt
@@ -1,5 +1,5 @@
 Microsoft Developer Studio Build File, Format Version 6.00 for
-libpng 1.2.0beta4 (June 23, 2001) and zlib
+libpng 1.2.0beta5 (August 8, 2001) and zlib
 
 Copyright (C) 2000 Simon-Pierre Cadieux
 For conditions of distribution and use, see copyright notice in png.h
diff --git a/projects/msvc/png32ms.def b/projects/msvc/png32ms.def
index a7dd3b2..fcb237a 100644
--- a/projects/msvc/png32ms.def
+++ b/projects/msvc/png32ms.def
@@ -6,7 +6,7 @@
 DESCRIPTION "PNG image compression library for Windows"
 
 EXPORTS
-;Version 1.2.0beta4
+;Version 1.2.0beta5
   png_build_grayscale_palette  @1
   png_check_sig        @2
   png_chunk_error      @3
diff --git a/projects/netware.txt b/projects/netware.txt
index 2a364b1..d366901 100644
--- a/projects/netware.txt
+++ b/projects/netware.txt
@@ -1,6 +1,6 @@
 A set of project files is available for Netware.  Get
-libpng-1.2.0beta4-project-netware.zip from a libpng distribution
+libpng-1.2.0beta5-project-netware.zip from a libpng distribution
 site such as http://libpng.sourceforge.net
 
 Put the zip file in this directory (projects) and then run
-"unzip -a libpng-1.2.0beta4-project-netware.zip"
+"unzip -a libpng-1.2.0beta5-project-netware.zip"
diff --git a/projects/wince.txt b/projects/wince.txt
index 7bb00e3..145ee1c 100644
--- a/projects/wince.txt
+++ b/projects/wince.txt
@@ -1,6 +1,6 @@
 A set of project files is available for WinCE.  Get
-libpng-1.2.0beta4-project-wince.zip from a libpng distribution
+libpng-1.2.0beta5-project-wince.zip from a libpng distribution
 site such as http://libpng.sourceforge.net
 
 Put the zip file in this directory (projects) and then run
-"unzip -a libpng-1.2.0beta4-project-wince.zip"
+"unzip -a libpng-1.2.0beta5-project-wince.zip"
diff --git a/scripts/makefile.aix b/scripts/makefile.aix
index d37c933..d15a76d 100644
--- a/scripts/makefile.aix
+++ b/scripts/makefile.aix
@@ -18,7 +18,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 prefix=/usr/local
diff --git a/scripts/makefile.beos b/scripts/makefile.beos
index 0a03503..269f8e3 100644
--- a/scripts/makefile.beos
+++ b/scripts/makefile.beos
@@ -13,7 +13,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 ALIGN=
diff --git a/scripts/makefile.cygwin b/scripts/makefile.cygwin
index f10e690..b583a97 100644
--- a/scripts/makefile.cygwin
+++ b/scripts/makefile.cygwin
@@ -39,7 +39,7 @@
 # have to change it.
 PNGMAJ = 3
 #PNGDLL = $3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGMIN_BASE = 1.2.0
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
diff --git a/scripts/makefile.dec b/scripts/makefile.dec
index 5dc8cb1..0ed4c0c 100644
--- a/scripts/makefile.dec
+++ b/scripts/makefile.dec
@@ -17,7 +17,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 CC=cc
diff --git a/scripts/makefile.gcmmx b/scripts/makefile.gcmmx
index f8b9e2e..48a552c 100644
--- a/scripts/makefile.gcmmx
+++ b/scripts/makefile.gcmmx
@@ -5,6 +5,8 @@
 
 # CAUTION: Do not use this makefile with gcc versions 2.7.2.2 and earlier.
 
+# WARNING: The assembler code in pnggccrd.c may not be thread safe.
+
 # NOTE:  When testing MMX performance on a multitasking system, make sure
 #        there are no floating-point programs (e.g., SETI@Home) running in
 #        the background!  Context switches between MMX and FPU are expensive.
@@ -30,15 +32,17 @@
 
 # for pgcc version 2.95.1, -O3 is buggy; don't use it.
 
+# Remove -DPNG_THREAD_UNSAFE_OK if you need thread safety
 ### for generic gcc:
-CFLAGS=-DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 $(ALIGN) -funroll-loops \
+CFLAGS=-DPNG_THREAD_UNSAFE_OK -DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall \
+       	-O3 $(ALIGN) -funroll-loops \
 	-fomit-frame-pointer  # $(WARNMORE) -g -DPNG_DEBUG=5
 ### for gcc 2.95.2 on 686:
-#CFLAGS=-DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 \
+#CFLAGS=-DPNG_THREAD_UNSAFE_OK -DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 \
 #	-mcpu=i686 -malign-double -ffast-math -fstrict-aliasing \
 #	$(ALIGN) -funroll-loops -funroll-all-loops -fomit-frame-pointer 
 ### for gcc 2.7.2.3 on 486 and up:
-#CFLAGS=-DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 \
+#CFLAGS=-DPNG_THREAD_UNSAFE_OK -DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 \
 #	-m486 -malign-double -ffast-math \
 #	$(ALIGN) -funroll-loops -funroll-all-loops -fomit-frame-pointer 
 
@@ -51,7 +55,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
@@ -71,20 +75,10 @@
 all: libpng.a libpng.so pngtest pngtest-static
 
 pnggccrd.o:	pnggccrd.c png.h pngconf.h
-	@echo ""
-	@echo '    You can ignore the single "control reaches end of non-void function"'
-	@echo '    warning and multiple "<variable> defined but not used" warnings:'
-	@echo ""
 	$(CC) -c $(CFLAGS) -o $@ $*.c
-	@echo ""
 
 pnggccrd.pic.o:	pnggccrd.c png.h pngconf.h
-	@echo ""
-	@echo '    You can ignore the single "control reaches end of non-void function"'
-	@echo '    warning and multiple "<variable> defined but not used" warnings:'
-	@echo ""
 	$(CC) -c $(CFLAGS) -fPIC -o $@ pnggccrd.c
-	@echo ""
 
 libpng.a: $(OBJS)
 	ar rc $@ $(OBJS)
diff --git a/scripts/makefile.hpgcc b/scripts/makefile.hpgcc
index 5ee3c8d..fad250b 100644
--- a/scripts/makefile.hpgcc
+++ b/scripts/makefile.hpgcc
@@ -34,7 +34,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.hpux b/scripts/makefile.hpux
index 4129985..80f2eb7 100644
--- a/scripts/makefile.hpux
+++ b/scripts/makefile.hpux
@@ -19,7 +19,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # where make install puts libpng.a and png.h
diff --git a/scripts/makefile.linux b/scripts/makefile.linux
index d1506fd..73f1612 100644
--- a/scripts/makefile.linux
+++ b/scripts/makefile.linux
@@ -34,7 +34,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.netbsd b/scripts/makefile.netbsd
index 5f99979..08b2fad 100644
--- a/scripts/makefile.netbsd
+++ b/scripts/makefile.netbsd
@@ -11,7 +11,7 @@
 
 LIB=png
 SHLIB_MAJOR= 3
-SHLIB_MINOR= 1.2.0beta4
+SHLIB_MINOR= 1.2.0beta5
 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.sco b/scripts/makefile.sco
index 8a42e52..d810e98 100644
--- a/scripts/makefile.sco
+++ b/scripts/makefile.sco
@@ -25,7 +25,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.sggcc b/scripts/makefile.sggcc
index 104a69b..e030915 100644
--- a/scripts/makefile.sggcc
+++ b/scripts/makefile.sggcc
@@ -22,7 +22,7 @@
 LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm
 LDSHARED=CC $(ABI) -shared
 
-VER=1.2.0beta4
+VER=1.2.0beta5
 # See "man dso" for info about shared objects
 SONUM=3
 LIBS=libpng.so.$(SONUM).$(VER)
@@ -63,6 +63,8 @@
 	chmod 644 $(prefix)/include/pngconf.h
 	cp libpng.a $(prefix)/lib
 	chmod 644 $(prefix)/lib/libpng.a
+
+install-shared: $(SHAREDLIB).$(VER)
 	cp $(SHAREDLIB).$(VER) $(libdir); chmod 755 $(SHAREDLIB).$(VER)
 	(cd $(libdir); if test -f $(SHAREDLIB).$(VER); then \
 	rm -f $(SHAREDLIB) $(SHAREDLIB).$(SONUM); \
diff --git a/scripts/makefile.sgi b/scripts/makefile.sgi
index 505cbdf..2fc40bd 100644
--- a/scripts/makefile.sgi
+++ b/scripts/makefile.sgi
@@ -27,7 +27,7 @@
 LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm
 LDSHARED=cc $(ABI) -shared
 
-VER=1.2.0beta4
+VER=1.2.0beta5
 # See "man dso" for info about shared objects
 SONUM=3
 SHAREDLIB=libpng.so
@@ -74,9 +74,9 @@
 install-shared: $(SHAREDLIB).$(SONUM).$(VER)
 	cp $(SHAREDLIB).$(SONUM).$(VER) $(libdir)
 	chmod 755 $(SHAREDLIB).$(SONUM).$(VER)
-	(cd $(libdir)
-	rm -f $(SHAREDLIB) $(SHAREDLIB).$(SONUM)
-	ln -s $(SHAREDLIB).$(SONUM).$(VER) $(SHAREDLIB).$(SONUM)
+	(cd $(libdir); if test -f $(SHAREDLIB).$(SONUM).$(VER); then \
+	rm -f $(SHAREDLIB) $(SHAREDLIB).$(SONUM); \
+	ln -s $(SHAREDLIB).$(SONUM).$(VER) $(SHAREDLIB).$(SONUM); \
 	ln -s $(SHAREDLIB).$(SONUM) $(SHAREDLIB))
 
 clean:
diff --git a/scripts/makefile.solaris b/scripts/makefile.solaris
index db604c2..9fa9270 100644
--- a/scripts/makefile.solaris
+++ b/scripts/makefile.solaris
@@ -31,7 +31,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.0beta4
+PNGMIN = 1.2.0beta5
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/pngdef.pas b/scripts/pngdef.pas
index 059acd8..7f9c59e 100644
--- a/scripts/pngdef.pas
+++ b/scripts/pngdef.pas
@@ -7,7 +7,7 @@
 interface
 
 const
-  PNG_LIBPNG_VER_STRING = '1.2.0beta4';
+  PNG_LIBPNG_VER_STRING = '1.2.0beta5';
   PNG_LIBPNG_VER        =  10200;
 
 type
diff --git a/scripts/pngos2.def b/scripts/pngos2.def
index 00788e9..8602581 100644
--- a/scripts/pngos2.def
+++ b/scripts/pngos2.def
@@ -2,7 +2,7 @@
 ; PNG.LIB module definition file for OS/2
 ;----------------------------------------
 
-; Version 1.2.0beta4
+; Version 1.2.0beta5
 
 LIBRARY		PNG
 DESCRIPTION	"PNG image compression library for OS/2"