[libpng10] Imported from libpng-1.0.50.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index 4339355..86f4756 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.0.48 - August 13, 2009
+Libpng 1.0.50 - September 10, 2009
 
 This is a public release of libpng, intended for use in production codes.
 
@@ -8,50 +8,43 @@
 Source files with LF line endings (for Unix/Linux) and with a
 "configure" script
 
-   libpng-1.0.48.tar.xz (LZMA-compressed, recommended)
-   libpng-1.0.48.tar.gz
-   libpng-1.0.48.tar.bz2
+   libpng-1.0.50.tar.xz (LZMA-compressed, recommended)
+   libpng-1.0.50.tar.gz
+   libpng-1.0.50.tar.bz2
 
 Source files with LF line endings (for Unix/Linux) without the
 "configure" script
 
-   libpng-1.0.48-no-config.tar.xz (LZMA-compressed, recommended)
-   libpng-1.0.48-no-config.tar.gz
-   libpng-1.0.48-no-config.tar.bz2
+   libpng-1.0.50-no-config.tar.xz (LZMA-compressed, recommended)
+   libpng-1.0.50-no-config.tar.gz
+   libpng-1.0.50-no-config.tar.bz2
 
 Source files with CRLF line endings (for Windows), without the
 "configure" script
 
-   lpng1048.zip
-   lpng1048.7z
-   lpng1048.tar.bz2
+   lpng1050.zip
+   lpng1050.7z
+   lpng1050.tar.bz2
 
 Project files
 
-   libpng-1.0.48-project-netware.zip
-   libpng-1.0.48-project-wince.zip
+   libpng-1.0.50-project-netware.zip
+   libpng-1.0.50-project-wince.zip
 
 Other information:
 
-   libpng-1.0.48-README.txt
-   libpng-1.0.48-KNOWNBUGS.txt
-   libpng-1.0.48-LICENSE.txt
-   libpng-1.0.48-Y2K-compliance.txt
+   libpng-1.0.50-README.txt
+   libpng-1.0.50-KNOWNBUGS.txt
+   libpng-1.0.50-LICENSE.txt
+   libpng-1.0.50-Y2K-compliance.txt
 
-Changes since the last public release (1.0.47):
+Changes since the last public release (1.0.49):
 
-version 1.0.48 [August 13, 2009]
+version 1.0.50 [September 10, 2009]
 
-  Added a prototype for png_64bit_product() in png.h
-  Expanded the information about prototypes in the libpng style section of
-    the documentation.
-  Rebuilt configure scripts with autoconf-2.64.
-  Avoid a possible NULL dereference in debug build, in png_set_text_2().
-    (bug introduced in libpng-0.95, discovered by Evan Rouault)
-  Replaced *.tar.lzma with *.tar.xz in distribution.  Get the xz codec
-    from <http://tukaani.org/xz>.
-  Reject attempt to write iCCP chunk with negative embedded profile length
-    (JD Chen)
+version 1.0.50 [September 10, 2009]
+  Removed some editing cruft from pngset.c and pngwutil.c.
+
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 
diff --git a/CHANGES b/CHANGES
index 9a8bbed..64fc14f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2448,6 +2448,19 @@
 version 1.2.39 and 1.0.48 [August 13, 2009]
   No changes.
 
+version 1.2.40beta01 [August 20, 2009]
+  Removed an extra png_debug() recently added to png_write_find_filter().
+  Fixed incorrect #ifdef in pngset.c regarding unknown chunk support.
+
+version 1.2.40rc01 [September 2, 2009]
+  Various bugfixes and improvements to CMakeLists.txt (Philip Lowman)
+
+version 1.2.40 and 1.0.49 [September 10, 2009]
+  No changes.
+
+version 1.0.50 [September 10, 2009]
+  Removed some editing cruft from pngset.c and pngwutil.c.
+
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
diff --git a/INSTALL b/INSTALL
index b4ac8b2..3a3d0a7 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
 
-Installing libpng version 1.0.48 - August 13, 2009
+Installing libpng version 1.0.50 - September 10, 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.0.48" or "lpng109" and "zlib-1.2.1"
+might be called "libpng-1.0.50" 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:
@@ -101,9 +101,9 @@
  CMakeLists.txt    =>  "cmake" script
  makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)
  makefile.elf      =>  Linux/ELF makefile symbol versioning,
-                       gcc, creates libpng10.so.0.1.0.48)
+                       gcc, creates libpng10.so.0.1.0.50)
  makefile.linux    =>  Linux/ELF makefile
-                       (gcc, creates libpng10.so.0.1.0.48)
+                       (gcc, creates libpng10.so.0.1.0.50)
  makefile.gcc      =>  Generic makefile (gcc, creates static libpng.a)
  makefile.knr      =>  Archaic UNIX Makefile that converts files with
                        ansi2knr (Requires ansi2knr.c from
@@ -125,14 +125,14 @@
  makefile.openbsd  =>  OpenBSD makefile
  makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)
  makefile.sggcc    =>  Silicon Graphics (gcc,
-                       creates libpng10.so.0.1.0.48)
+                       creates libpng10.so.0.1.0.50)
  makefile.sunos    =>  Sun makefile
  makefile.solaris  =>  Solaris 2.X makefile (gcc,
-                       creates libpng10.so.0.1.0.48)
+                       creates libpng10.so.0.1.0.50)
  makefile.solaris-x86 =>  Solaris/intelMMX 2.X makefile (gcc,
-                       creates libpng10.so.0.1.0.48)
+                       creates libpng10.so.0.1.0.50)
  makefile.so9      =>  Solaris 9 makefile (gcc,
-                       creates libpng10.so.0.1.0.48)
+                       creates libpng10.so.0.1.0.50)
  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 bb8245f..6a6c154 100644
--- a/KNOWNBUG
+++ b/KNOWNBUG
@@ -1,5 +1,5 @@
 
-Known bugs in libpng version 1.0.48
+Known bugs in libpng version 1.0.50
 
 1. February 23, 2006: The custom makefiles don't build libpng with -lz.
 
diff --git a/LICENSE b/LICENSE
index 0e6cc18..027bcf5 100644
--- a/LICENSE
+++ b/LICENSE
@@ -10,7 +10,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.0.48, August 13, 2009, are
+libpng versions 1.2.6, August 15, 2004, through 1.0.50, September 10, 2009, are
 Copyright (c) 2004, 2006-2009 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.2.5
 with the following individual added to the list of Contributing Authors
@@ -108,4 +108,4 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-August 13, 2009
+September 10, 2009
diff --git a/Makefile.am b/Makefile.am
index dfb8cb7..de5e2bd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -86,7 +86,7 @@
 	${srcdir}/contrib/pngsuite/* \
 	${srcdir}/contrib/visupng/* \
 	$(TESTS) \
-	example.c libpng-1.0.48.txt pngvcrd.c 
+	example.c libpng-1.0.50.txt pngvcrd.c 
 
 CLEANFILES= pngout.png libpng10.pc libpng10-config libpng.vers \
 libpng.sym
diff --git a/Makefile.in b/Makefile.in
index 781070d..5fbfe44 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -352,7 +352,7 @@
 	${srcdir}/contrib/pngsuite/* \
 	${srcdir}/contrib/visupng/* \
 	$(TESTS) \
-	example.c libpng-1.0.48.txt pngvcrd.c 
+	example.c libpng-1.0.50.txt pngvcrd.c 
 
 CLEANFILES = pngout.png libpng10.pc libpng10-config libpng.vers \
 libpng.sym
diff --git a/README b/README
index 5f71a1a..b4dfece 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.0.48 - August 13, 2009 (shared library 10.0)
+README for libpng version 1.0.50 - September 10, 2009 (shared library 10.0)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
@@ -194,11 +194,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 libpng10.so.0.1.0.48)
+                            gcc, creates libpng10.so.0.1.0.50)
        makefile.linux   =>  Linux/ELF makefile
-                            (gcc, creates libpng10.so.0.1.0.48)
+                            (gcc, creates libpng10.so.0.1.0.50)
        makefile.gcmmx   =>  Linux/ELF makefile
-                            (gcc, creates libpng10.so.0.1.0.48,
+                            (gcc, creates libpng10.so.0.1.0.50,
                             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
@@ -220,12 +220,12 @@
        makefile.openbsd =>  OpenBSD makefile
        makefile.sgi     =>  Silicon Graphics IRIX (cc, creates static lib)
        makefile.sggcc   =>  Silicon Graphics
-                            (gcc, creates libpng10.so.0.1.0.48)
+                            (gcc, creates libpng10.so.0.1.0.50)
        makefile.sunos   =>  Sun makefile
        makefile.solaris =>  Solaris 2.X makefile
-                            (gcc, creates libpng10.so.0.1.0.48)
+                            (gcc, creates libpng10.so.0.1.0.50)
        makefile.so9     =>  Solaris 9 makefile
-                            (gcc, creates libpng10.so.0.1.0.48)
+                            (gcc, creates libpng10.so.0.1.0.50)
        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/Y2KINFO b/Y2KINFO
index c2d4d98..0c5ec35 100644
--- a/Y2KINFO
+++ b/Y2KINFO
@@ -1,13 +1,13 @@
    Y2K compliance in libpng:
    =========================
 
-      August 13, 2009
+      September 10, 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.0.48 are Y2K compliant.  It is my belief that earlier
+      upward through 1.0.50 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 1781a4b..9c4525b 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.64 for libpng 1.0.48.
+# Generated by GNU Autoconf 2.64 for libpng 1.0.50.
 #
 # Report bugs to <png-mng-implement@lists.sourceforge.net>.
 #
@@ -698,8 +698,8 @@
 # Identity of this package.
 PACKAGE_NAME='libpng'
 PACKAGE_TARNAME='libpng'
-PACKAGE_VERSION='1.0.48'
-PACKAGE_STRING='libpng 1.0.48'
+PACKAGE_VERSION='1.0.50'
+PACKAGE_STRING='libpng 1.0.50'
 PACKAGE_BUGREPORT='png-mng-implement@lists.sourceforge.net'
 PACKAGE_URL=''
 
@@ -1432,7 +1432,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures libpng 1.0.48 to adapt to many kinds of systems.
+\`configure' configures libpng 1.0.50 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1502,7 +1502,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of libpng 1.0.48:";;
+     short | recursive ) echo "Configuration of libpng 1.0.50:";;
    esac
   cat <<\_ACEOF
 
@@ -1609,7 +1609,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-libpng configure 1.0.48
+libpng configure 1.0.50
 generated by GNU Autoconf 2.64
 
 Copyright (C) 2009 Free Software Foundation, Inc.
@@ -2034,7 +2034,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by libpng $as_me 1.0.48, which was
+It was created by libpng $as_me 1.0.50, which was
 generated by GNU Autoconf 2.64.  Invocation command line was
 
   $ $0 $@
@@ -2842,7 +2842,7 @@
 
 # Define the identity of the package.
  PACKAGE='libpng'
- VERSION='1.0.48'
+ VERSION='1.0.50'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2906,10 +2906,10 @@
 
 
 
-PNGLIB_VERSION=1.0.48
+PNGLIB_VERSION=1.0.50
 PNGLIB_MAJOR=1
 PNGLIB_MINOR=0
-PNGLIB_RELEASE=48
+PNGLIB_RELEASE=50
 
 
 
@@ -12047,7 +12047,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by libpng $as_me 1.0.48, which was
+This file was extended by libpng $as_me 1.0.50, which was
 generated by GNU Autoconf 2.64.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -12111,7 +12111,7 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_version="\\
-libpng config.status 1.0.48
+libpng config.status 1.0.50
 configured by $0, generated by GNU Autoconf 2.64,
   with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/configure.ac b/configure.ac
index 639cf74..dc64e18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,15 +18,15 @@
 
 dnl Version number stuff here:
 
-AC_INIT([libpng], [1.0.48], [png-mng-implement@lists.sourceforge.net])
+AC_INIT([libpng], [1.0.50], [png-mng-implement@lists.sourceforge.net])
 AM_INIT_AUTOMAKE
 dnl stop configure from automagically running automake
 AM_MAINTAINER_MODE
 
-PNGLIB_VERSION=1.0.48
+PNGLIB_VERSION=1.0.50
 PNGLIB_MAJOR=1
 PNGLIB_MINOR=0
-PNGLIB_RELEASE=48
+PNGLIB_RELEASE=50
 
 dnl End of version number stuff
 
diff --git a/libpng-1.0.48.txt b/libpng-1.0.50.txt
similarity index 99%
rename from libpng-1.0.48.txt
rename to libpng-1.0.50.txt
index b4d74a7..1b5a95c 100644
--- a/libpng-1.0.48.txt
+++ b/libpng-1.0.50.txt
@@ -1,6 +1,6 @@
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.0.48 - August 13, 2009
+ libpng version 1.0.50 - September 10, 2009
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2009 Glenn Randers-Pehrson
@@ -11,7 +11,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.0.48 - August 13, 2009
+ libpng versions 0.97, January 1998, through 1.0.50 - September 10, 2009
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2009 Glenn Randers-Pehrson
 
@@ -2963,13 +2963,13 @@
 
 XIII. Y2K Compliance in libpng
 
-August 13, 2009
+September 10, 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.0.48 are Y2K compliant.  It is my belief that earlier
+upward through 1.0.50 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 2ac11de..07e99ae 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "August 13, 2009"
+.TH LIBPNG 3 "September 10, 2009"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.0.48
+libpng \- Portable Network Graphics (PNG) Reference Library 1.0.50
 .SH SYNOPSIS
 \fI\fB
 
@@ -821,7 +821,7 @@
 .SH LIBPNG.TXT
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.0.48 - August 13, 2009
+ libpng version 1.0.50 - September 10, 2009
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2009 Glenn Randers-Pehrson
@@ -832,7 +832,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.0.48 - August 13, 2009
+ libpng versions 0.97, January 1998, through 1.0.50 - September 10, 2009
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2009 Glenn Randers-Pehrson
 
@@ -3784,13 +3784,13 @@
 
 .SH XIII. Y2K Compliance in libpng
 
-August 13, 2009
+September 10, 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.0.48 are Y2K compliant.  It is my belief that earlier
+upward through 1.0.50 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
@@ -4069,6 +4069,9 @@
  1.2.39rc01          13    10239  12.so.0.39[.0]
  1.0.48              10    10048  10.so.0.48[.0]
  1.2.39              13    10239  12.so.0.39[.0]
+ 1.2.40rc01          13    10240  12.so.0.40[.0]
+ 1.0.49              10    10049  10.so.0.49[.0]
+ 1.2.40              13    10240  12.so.0.40[.0]
 
 Henceforth the source version will match the shared-library minor
 and patch numbers; the shared-library major version number will be
@@ -4124,7 +4127,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.0.48 - August 13, 2009:
+Libpng version 1.0.50 - September 10, 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).
 
@@ -4147,7 +4150,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.0.48, August 13, 2009, are
+libpng versions 1.2.6, August 15, 2004, through 1.0.50, September 10, 2009, are
 Copyright (c) 2004,2006-2008 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
@@ -4246,7 +4249,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-August 13, 2009
+September 10, 2009
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index 9d9af2f..9db0b60 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 "August 13, 2009"
+.TH LIBPNGPF 3 "September 10, 2009"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.0.48
+libpng \- Portable Network Graphics (PNG) Reference Library 1.0.50
 (private functions)
 .SH SYNOPSIS
 \fB#include <png.h>\fP
diff --git a/png.5 b/png.5
index 1e7d7df..30923ba 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "August 13, 2009"
+.TH PNG 5 "September 10, 2009"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index b59344c..29e701f 100644
--- a/png.c
+++ b/png.c
@@ -16,7 +16,7 @@
 #include "png.h"
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_0_48 Your_png_h_is_not_version_1_0_48;
+typedef version_1_0_50 Your_png_h_is_not_version_1_0_50;
 
 /* Version information for C files.  This had better match the version
  * string defined in png.h.  */
@@ -705,7 +705,7 @@
 png_get_copyright(png_structp png_ptr)
 {
    png_ptr = png_ptr;  /* Silence compiler warning about unused png_ptr */
-   return ((png_charp) "\n libpng version 1.0.48 - August 13, 2009\n\
+   return ((png_charp) "\n libpng version 1.0.50 - September 10, 2009\n\
    Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\
    Copyright (c) 1996-1997 Andreas Dilger\n\
    Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
diff --git a/png.h b/png.h
index 152f047..07e7800 100644
--- a/png.h
+++ b/png.h
@@ -1,6 +1,6 @@
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.0.48 - August 13, 2009
+ * libpng version 1.0.50 - September 10, 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.)
@@ -10,7 +10,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.0.48 - August 13, 2009: Glenn
+ *  libpng versions 0.97, January 1998, through 1.0.50 - September 10, 2009: Glenn
  *  See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -241,6 +241,10 @@
  *    1.2.39rc01              13    10239  12.so.0.39[.0]
  *    1.0.48                  10    10048  10.so.0.48[.0]
  *    1.2.39                  13    10239  12.so.0.39[.0]
+ *    1.2.40beta01            13    10240  12.so.0.40[.0]
+ *    1.2.40rc01              13    10240  12.so.0.40[.0]
+ *    1.0.49                  10    10049  10.so.0.49[.0]
+ *    1.2.40                  13    10240  12.so.0.40[.0]
  *
  *    Henceforth the source version will match the shared-library major
  *    and minor numbers; the shared-library major version number will be
@@ -272,7 +276,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.0.48, August 13, 2009, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.0.50, September 10, 2009, are
  * Copyright (c) 2004, 2006-2009 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:
@@ -384,13 +388,13 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    August 13, 2009
+ *    September 10, 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.0.48 are Y2K compliant.  It is my belief that earlier
+ *    upward through 1.0.50 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
@@ -446,9 +450,9 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.0.48"
+#define PNG_LIBPNG_VER_STRING "1.0.50"
 #define PNG_HEADER_VERSION_STRING \
-   " libpng version 1.0.48 - August 13, 2009\n"
+   " libpng version 1.0.50 - September 10, 2009\n"
 
 #define PNG_LIBPNG_VER_SONUM   0
 #define PNG_LIBPNG_VER_DLLNUM  10
@@ -456,7 +460,7 @@
 /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
 #define PNG_LIBPNG_VER_MAJOR   1
 #define PNG_LIBPNG_VER_MINOR   0
-#define PNG_LIBPNG_VER_RELEASE 48
+#define PNG_LIBPNG_VER_RELEASE 50
 /* This should match the numeric part of the final component of
  * PNG_LIBPNG_VER_STRING, omitting any leading zero:
  */
@@ -486,14 +490,14 @@
  * version 1.0.0 was mis-numbered 100 instead of 10000).  From
  * version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=release
  */
-#define PNG_LIBPNG_VER 10048 /* 1.0.48 */
+#define PNG_LIBPNG_VER 10050 /* 1.0.50 */
 
 #ifndef PNG_VERSION_INFO_ONLY
-/* include the compression library's header */
+/* Include the compression library's header */
 #include "zlib.h"
 #endif
 
-/* include all user configurable info, including optional assembler routines */
+/* Include all user configurable info, including optional assembler routines */
 #include "pngconf.h"
 
 /*
@@ -575,7 +579,7 @@
  */
 #ifdef PNG_USE_GLOBAL_ARRAYS
 PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
-  /* need room for 99.99.99beta99z */
+  /* Need room for 99.99.99beta99z */
 #else
 #define png_libpng_ver png_get_header_ver(NULL)
 #endif
@@ -785,7 +789,7 @@
  */
 typedef struct png_info_struct
 {
-   /* the following are necessary for every PNG file */
+   /* The following are necessary for every PNG file */
    png_uint_32 width;       /* width of image in pixels (from IHDR) */
    png_uint_32 height;      /* height of image in pixels (from IHDR) */
    png_uint_32 valid;       /* valid chunk data (see PNG_INFO_ below) */
@@ -1190,10 +1194,10 @@
 #define PNG_TRANSFORM_SWAP_ALPHA     0x0100    /* read and write */
 #define PNG_TRANSFORM_SWAP_ENDIAN    0x0200    /* read and write */
 #define PNG_TRANSFORM_INVERT_ALPHA   0x0400    /* read and write */
-#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* WRITE only, deprecated */
+#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* write only, deprecated */
 /* Added to libpng-1.2.34 */
-#define PNG_TRANSFORM_STRIP_FILLER_BEFORE 0x0800  /* WRITE only */
-#define PNG_TRANSFORM_STRIP_FILLER_AFTER  0x1000  /* WRITE only */
+#define PNG_TRANSFORM_STRIP_FILLER_BEFORE 0x0800  /* write only */
+#define PNG_TRANSFORM_STRIP_FILLER_AFTER  0x1000  /* write only */
 
 /* Flags for MNG supported features */
 #define PNG_FLAG_MNG_EMPTY_PLTE     0x01
@@ -1434,7 +1438,7 @@
 #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
     defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
     defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
-/* changed from png_byte to png_uint_32 at version 1.2.0 */
+/* Changed from png_byte to png_uint_32 at version 1.2.0 */
 #ifdef PNG_1_0_X
    png_byte mng_features_permitted;
 #else
@@ -1513,7 +1517,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_0_48;
+typedef png_structp version_1_0_50;
 
 typedef png_struct FAR * FAR * png_structpp;
 
@@ -2090,7 +2094,7 @@
 extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
    png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
 
-/* function that combines rows.  Not very much different than the
+/* Function that combines rows.  Not very much different than the
  * png_combine_row() call.  Is this even used?????
  */
 extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
@@ -2996,7 +3000,7 @@
 
 /* Variables declared in png.c - only it needs to define PNG_NO_EXTERN */
 #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
-/* place to hold the signature string for a PNG file. */
+/* Place to hold the signature string for a PNG file. */
 #ifdef PNG_USE_GLOBAL_ARRAYS
    PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
 #else
diff --git a/pngconf.h b/pngconf.h
index b849dee..5b6bc8f 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.0.48 - August 13, 2009
+ * libpng version 1.0.50 - September 10, 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.)
diff --git a/pngset.c b/pngset.c
index 3c110eb..9e1b885 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.2.39 [August 13, 2009]
+ * Last changed in libpng 1.2.40 [September 10, 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.)
@@ -25,6 +25,7 @@
 png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
 {
    png_debug1(1, "in %s storage function", "bKGD");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -41,6 +42,7 @@
    double green_x, double green_y, double blue_x, double blue_y)
 {
    png_debug1(1, "in %s storage function", "cHRM");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -74,6 +76,7 @@
    png_fixed_point blue_x, png_fixed_point blue_y)
 {
    png_debug1(1, "in %s storage function", "cHRM fixed");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -112,7 +115,9 @@
 png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
 {
    double png_gamma;
+
    png_debug1(1, "in %s storage function", "gAMA");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -140,6 +145,7 @@
    png_fixed_point png_gamma;
 
    png_debug1(1, "in %s storage function", "gAMA");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -177,8 +183,10 @@
    int i;
 
    png_debug1(1, "in %s storage function", "hIST");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
+
    if (info_ptr->num_palette == 0 || info_ptr->num_palette
        > PNG_MAX_PALETTE_LENGTH)
    {
@@ -221,6 +229,7 @@
    int filter_type)
 {
    png_debug1(1, "in %s storage function", "IHDR");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -328,6 +337,7 @@
    png_int_32 offset_x, png_int_32 offset_y, int unit_type)
 {
    png_debug1(1, "in %s storage function", "oFFs");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -348,6 +358,7 @@
    int i;
 
    png_debug1(1, "in %s storage function", "pCAL");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -417,6 +428,7 @@
              int unit, double width, double height)
 {
    png_debug1(1, "in %s storage function", "sCAL");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -435,6 +447,7 @@
    png_uint_32 length;
 
    png_debug1(1, "in %s storage function", "sCAL");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -480,6 +493,7 @@
    png_uint_32 res_x, png_uint_32 res_y, int unit_type)
 {
    png_debug1(1, "in %s storage function", "pHYs");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -496,6 +510,7 @@
 {
 
    png_debug1(1, "in %s storage function", "PLTE");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -546,6 +561,7 @@
    png_color_8p sig_bit)
 {
    png_debug1(1, "in %s storage function", "sBIT");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -559,6 +575,7 @@
 png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
 {
    png_debug1(1, "in %s storage function", "sRGB");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -586,6 +603,7 @@
       int_green_y, int_blue_x, int_blue_y;
 #endif
    png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -655,6 +673,7 @@
    png_uint_32 length;
 
    png_debug1(1, "in %s storage function", "iCCP");
+
    if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
       return;
 
@@ -869,6 +888,7 @@
 png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
 {
    png_debug1(1, "in %s storage function", "tIME");
+
    if (png_ptr == NULL || info_ptr == NULL ||
        (png_ptr->mode & PNG_WROTE_tIME))
       return;
@@ -884,6 +904,7 @@
    png_bytep trans, int num_trans, png_color_16p trans_values)
 {
    png_debug1(1, "in %s storage function", "tRNS");
+
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
@@ -1008,7 +1029,7 @@
 }
 #endif /* PNG_sPLT_SUPPORTED */
 
-#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
 void PNGAPI
 png_set_unknown_chunks(png_structp png_ptr,
    png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
@@ -1088,7 +1109,9 @@
 {
    /* This function is deprecated in favor of png_permit_mng_features()
       and will be removed from libpng-1.3.0 */
+
    png_debug(1, "in png_permit_empty_plte, DEPRECATED.");
+
    if (png_ptr == NULL)
       return;
    png_ptr->mng_features_permitted = (png_byte)
@@ -1103,6 +1126,7 @@
 png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
 {
    png_debug(1, "in png_permit_mng_features");
+
    if (png_ptr == NULL)
       return (png_uint_32)0;
    png_ptr->mng_features_permitted =
@@ -1164,8 +1188,10 @@
    png_user_chunk_ptr read_user_chunk_fn)
 {
    png_debug(1, "in png_set_read_user_chunk_fn");
+
    if (png_ptr == NULL)
       return;
+
    png_ptr->read_user_chunk_fn = read_user_chunk_fn;
    png_ptr->user_chunk_ptr = user_chunk_ptr;
 }
diff --git a/pngtest.c b/pngtest.c
index b8015de..c87b956 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1689,4 +1689,4 @@
 }
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_0_48 your_png_h_is_not_version_1_0_48;
+typedef version_1_0_50 your_png_h_is_not_version_1_0_50;
diff --git a/pngwutil.c b/pngwutil.c
index aed280e..f52495c 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,7 +1,7 @@
 
 /* pngwutil.c - utilities to write a PNG file
  *
- * Last changed in libpng 1.2.39 [August 13, 2009]
+ * Last changed in libpng 1.2.40 [September 10, 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.)
@@ -102,6 +102,7 @@
 
    png_debug2(0, "Writing %s chunk, length = %lu", chunk_name,
       (unsigned long)length);
+
    if (png_ptr == NULL)
       return;
 
@@ -398,6 +399,7 @@
    png_byte buf[13]; /* Buffer to store the IHDR info */
 
    png_debug(1, "in png_write_IHDR");
+
    /* Check that we have valid input data from the application info */
    switch (color_type)
    {
@@ -575,6 +577,7 @@
    png_byte buf[3];
 
    png_debug(1, "in png_write_PLTE");
+
    if ((
 #if defined(PNG_MNG_FEATURES_SUPPORTED)
         !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
@@ -634,6 +637,7 @@
 #ifdef PNG_USE_LOCAL_ARRAYS
    PNG_IDAT;
 #endif
+
    png_debug(1, "in png_write_IDAT");
 
    /* Optimize the CMF field in the zlib stream. */
@@ -688,7 +692,9 @@
 #ifdef PNG_USE_LOCAL_ARRAYS
    PNG_IEND;
 #endif
+
    png_debug(1, "in png_write_IEND");
+
    png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
      (png_size_t)0);
    png_ptr->mode |= PNG_HAVE_IEND;
@@ -707,6 +713,7 @@
    png_byte buf[4];
 
    png_debug(1, "in png_write_gAMA");
+
    /* file_gamma is saved in 1/100,000ths */
    igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
    png_save_uint_32(buf, igamma);
@@ -723,6 +730,7 @@
    png_byte buf[4];
 
    png_debug(1, "in png_write_gAMA");
+
    /* file_gamma is saved in 1/100,000ths */
    png_save_uint_32(buf, (png_uint_32)file_gamma);
    png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
@@ -741,6 +749,7 @@
    png_byte buf[1];
 
    png_debug(1, "in png_write_sRGB");
+
    if (srgb_intent >= PNG_sRGB_INTENT_LAST)
          png_warning(png_ptr,
             "Invalid sRGB rendering intent specified");
@@ -849,6 +858,7 @@
 #endif
 
    png_debug(1, "in png_write_sPLT");
+
    if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0)
       return;
 
@@ -922,6 +932,7 @@
    png_size_t size;
 
    png_debug(1, "in png_write_sBIT");
+
    /* Make sure we don't depend upon the order of PNG_COLOR_8 */
    if (color_type & PNG_COLOR_MASK_COLOR)
    {
@@ -1029,6 +1040,7 @@
    png_byte buf[32];
 
    png_debug(1, "in png_write_cHRM");
+
    /* Each value is saved in 1/100,000ths */
 #if !defined(PNG_NO_CHECK_cHRM)
    if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
@@ -1065,6 +1077,7 @@
    png_byte buf[6];
 
    png_debug(1, "in png_write_tRNS");
+
    if (color_type == PNG_COLOR_TYPE_PALETTE)
    {
       if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
@@ -1120,6 +1133,7 @@
    png_byte buf[6];
 
    png_debug(1, "in png_write_bKGD");
+
    if (color_type == PNG_COLOR_TYPE_PALETTE)
    {
       if (
@@ -1174,6 +1188,7 @@
    png_byte buf[3];
 
    png_debug(1, "in png_write_hIST");
+
    if (num_hist > (int)png_ptr->num_palette)
    {
       png_debug2(3, "num_hist = %d, num_palette = %d", num_hist,
@@ -1214,6 +1229,7 @@
    int kwarn=0;
 
    png_debug(1, "in png_check_keyword");
+
    *new_key = NULL;
 
    if (key == NULL || (key_len = png_strlen(key)) == 0)
@@ -1337,6 +1353,7 @@
    png_charp new_key;
 
    png_debug(1, "in png_write_tEXt");
+
    if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
       return;
 
@@ -1525,6 +1542,7 @@
    png_byte buf[9];
 
    png_debug(1, "in png_write_oFFs");
+
    if (unit_type >= PNG_OFFSET_LAST)
       png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
 
@@ -1551,6 +1569,7 @@
    int i;
 
    png_debug1(1, "in png_write_pCAL (%d parameters)", nparams);
+
    if (type >= PNG_EQUATION_LAST)
       png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
 
@@ -1684,6 +1703,7 @@
    png_byte buf[9];
 
    png_debug(1, "in png_write_pHYs");
+
    if (unit_type >= PNG_RESOLUTION_LAST)
       png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
 
@@ -1708,6 +1728,7 @@
    png_byte buf[7];
 
    png_debug(1, "in png_write_tIME");
+
    if (mod_time->month  > 12 || mod_time->month  < 1 ||
        mod_time->day    > 31 || mod_time->day    < 1 ||
        mod_time->hour   > 23 || mod_time->second > 60)
@@ -1752,6 +1773,7 @@
    png_size_t buf_size;
 
    png_debug(1, "in png_write_start_row");
+
    buf_size = (png_size_t)(PNG_ROWBYTES(
       png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
 
@@ -1852,6 +1874,7 @@
    int ret;
 
    png_debug(1, "in png_write_finish_row");
+
    /* Next row */
    png_ptr->row_number++;
 
@@ -1961,6 +1984,7 @@
 #endif
 
    png_debug(1, "in png_do_write_interlace");
+
    /* We don't have to do anything on the last pass (6) */
 #if defined(PNG_USELESS_TESTS_SUPPORTED)
    if (row != NULL && row_info != NULL && pass < 6)
@@ -2133,8 +2157,6 @@
 
    png_debug(1, "in png_write_find_filter");
 
-
-   png_debug(1, "in png_write_find_filter");
    /* Find out how many bytes offset each pixel is */
    bpp = (row_info->pixel_depth + 7) >> 3;
 
@@ -2744,6 +2766,7 @@
 png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
 {
    png_debug(1, "in png_write_filtered_row");
+
    png_debug1(2, "filter = %d", filtered_row[0]);
    /* Set up the zlib input buffer */
 
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index d24a315..acd6b27 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -1,5 +1,5 @@
-
-project(PNG)
+project(PNG C)
+cmake_minimum_required(VERSION 2.4.3)
 
 # Copyright (C) 2007 Glenn Randers-Pehrson
 
@@ -9,12 +9,16 @@
 
 set(PNGLIB_MAJOR 1)
 set(PNGLIB_MINOR 0)
-set(PNGLIB_RELEASE 48)
+set(PNGLIB_RELEASE 50)
 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
 
+set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+
 # needed packages
 find_package(ZLIB REQUIRED)
+include_directories(${ZLIB_INCLUDE_DIR})
+
 if(NOT WIN32)
  find_library(M_LIBRARY
      NAMES m
@@ -23,24 +27,33 @@
  if(NOT M_LIBRARY)
    message(STATUS
      "math library 'libm' not found - floating point support disabled")
- endif(NOT M_LIBRARY)
-else(NOT WIN32)
+ endif()
+else()
  # not needed on windows
  set(M_LIBRARY "")
-endif(NOT WIN32)
-
+endif()
 
 # COMMAND LINE OPTIONS
-option(PNG_SHARED "Build shared lib" YES)
-option(PNG_STATIC "Build static lib" YES)
+if(DEFINED PNG_SHARED)
+  option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
+else()
+  option(PNG_SHARED "Build shared lib" ON)
+endif()
+if(DEFINED PNG_STATIC)
+  option(PNG_STATIC "Build static lib" ${PNG_STATIC})
+else()
+  option(PNG_STATIC "Build static lib" ON)
+endif()
+
 if(MINGW)
   option(PNG_TESTS  "Build pngtest" NO)
 else(MINGW)
   option(PNG_TESTS  "Build pngtest" YES)
 endif(MINGW)
+
 option(PNG_NO_CONSOLE_IO "FIXME" YES)
 option(PNG_NO_STDIO      "FIXME" YES)
-option(PNG_DEBUG         "Build with debug output" YES)
+option(PNG_DEBUG         "Build with debug output" NO)
 option(PNGARG            "FIXME" YES)
 #TODO:
 # PNG_CONSOLE_IO_SUPPORTED
@@ -57,20 +70,16 @@
       set(png_asm_tmp "OFF")
    endif("uname_output" MATCHES "^.*i[1-9]86.*$")
  endif(uname_executable)
-else(NOT WIN32)
+else()
  # this env var is normally only set on win64
  SET(TEXT "ProgramFiles(x86)")
  if("$ENV{${TEXT}}" STREQUAL "")
   set(png_asm_tmp "ON")
  endif("$ENV{${TEXT}}" STREQUAL "")
-endif(NOT WIN32)
+endif()
 
 # SET LIBNAME
-# msvc does not append 'lib' - do it here to have consistent name
-if(MSVC)
- set(PNG_LIB_NAME lib)
-endif(MSVC)
-set(PNG_LIB_NAME ${PNG_LIB_NAME}png${PNGLIB_MAJOR}${PNGLIB_MINOR})
+set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
 
 # to distinguish between debug and release lib
 set(CMAKE_DEBUG_POSTFIX "d")
@@ -104,54 +113,67 @@
   add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
 endif(MSVC)
 
-add_definitions(-DZLIB_DLL)
+if(PNG_SHARED OR  NOT MSVC)
+	#if building msvc static this has NOT do be defined
+	add_definitions(-DZLIB_DLL)
+endif()
 
 add_definitions(-DLIBPNG_NO_MMX)
 add_definitions(-DPNG_NO_MMX_CODE)
 
 if(PNG_CONSOLE_IO_SUPPORTED)
  add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
-endif(PNG_CONSOLE_IO_SUPPORTED)
+endif()
 
 if(PNG_NO_CONSOLE_IO)
  add_definitions(-DPNG_NO_CONSOLE_IO)
-endif(PNG_NO_CONSOLE_IO)
+endif()
 
 if(PNG_NO_STDIO)
  add_definitions(-DPNG_NO_STDIO)
-endif(PNG_NO_STDIO)
+endif()
 
 if(PNG_DEBUG)
  add_definitions(-DPNG_DEBUG)
-endif(PNG_DEBUG)
+endif()
 
 if(NOT M_LIBRARY AND NOT WIN32)
  add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
-endif(NOT M_LIBRARY AND NOT WIN32)
+endif()
 
 # NOW BUILD OUR TARGET
 include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
 
 if(PNG_SHARED)
  add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
+ if(MSVC)
+   # msvc does not append 'lib' - do it here to have consistent name
+   set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
+ endif()
  target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
-endif(PNG_SHARED)
+endif()
+
 if(PNG_STATIC)
 # does not work without changing name
  set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
  add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
-endif(PNG_STATIC)
+ if(MSVC)
+   # msvc does not append 'lib' - do it here to have consistent name
+   set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
+ endif()
+endif()
+
 
 if(PNG_SHARED AND WIN32)
  set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
-endif(PNG_SHARED AND WIN32)
+endif()
 
-if(PNG_TESTS)
+if(PNG_TESTS AND PNG_SHARED)
 # does not work with msvc due to png_lib_ver issue
  add_executable(pngtest ${pngtest_sources})
  target_link_libraries(pngtest ${PNG_LIB_NAME})
 #  add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
-endif(PNG_TESTS)
+endif()
 
 
 # CREATE PKGCONFIG FILES
@@ -171,30 +193,49 @@
   ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)
 
 # SET UP LINKS
-set_target_properties(${PNG_LIB_NAME} PROPERTIES
-#    VERSION 0.${PNGLIB_RELEASE}.1.0.48
+if(PNG_SHARED)
+  set_target_properties(${PNG_LIB_NAME} PROPERTIES
+#    VERSION 0.${PNGLIB_RELEASE}.1.0.50
      VERSION 0.${PNGLIB_RELEASE}.0
      SOVERSION 0
      CLEAN_DIRECT_OUTPUT 1)
-if(NOT WIN32)
-  # that's uncool on win32 - it overwrites our static import lib...
-  set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
-     OUTPUT_NAME ${PNG_LIB_NAME}
-     CLEAN_DIRECT_OUTPUT 1)
-endif(NOT WIN32)
-# INSTALL
-install_targets(/lib ${PNG_LIB_NAME})
+endif()
 if(PNG_STATIC)
-  install_targets(/lib ${PNG_LIB_NAME_STATIC})
-endif(PNG_STATIC)
+  if(NOT WIN32)
+    # that's uncool on win32 - it overwrites our static import lib...
+    set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
+       OUTPUT_NAME ${PNG_LIB_NAME}
+       CLEAN_DIRECT_OUTPUT 1)
+  endif()
+endif()
+
+# INSTALL
+if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
+    if(PNG_SHARED)
+        install(TARGETS ${PNG_LIB_NAME}
+            RUNTIME DESTINATION bin
+            LIBRARY DESTINATION lib
+            ARCHIVE DESTINATION lib)
+    endif()
+    if(PNG_STATIC)
+        install(TARGETS ${PNG_LIB_NAME_STATIC}
+            LIBRARY DESTINATION lib
+            ARCHIVE DESTINATION lib)
+    endif()
+endif()
+
+if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
 install(FILES png.h pngconf.h         DESTINATION include)
 install(FILES png.h pngconf.h         DESTINATION include/${PNGLIB_NAME})
-install(FILES libpng.3 libpngpf.3             DESTINATION man/man3)
-install(FILES png.5                           DESTINATION man/man5)
-install(FILES ${PNG_BINARY_DIR}/libpng.pc     DESTINATION lib/pkgconfig)
-install(FILES ${PNG_BINARY_DIR}/libpng-config      DESTINATION bin)
-install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc  DESTINATION lib/pkgconfig)
-install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
+endif()
+if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
+    install(FILES libpng.3 libpngpf.3             DESTINATION man/man3)
+    install(FILES png.5                           DESTINATION man/man5)
+    install(FILES ${PNG_BINARY_DIR}/libpng.pc     DESTINATION lib/pkgconfig)
+    install(FILES ${PNG_BINARY_DIR}/libpng-config      DESTINATION bin)
+    install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc  DESTINATION lib/pkgconfig)
+    install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
+endif()
 
 # what's with libpng.txt and all the extra files?
 
diff --git a/scripts/libpng-config-head.in b/scripts/libpng-config-head.in
index 092a391..0ab0b16 100755
--- a/scripts/libpng-config-head.in
+++ b/scripts/libpng-config-head.in
@@ -11,7 +11,7 @@
 
 # Modeled after libxml-config.
 
-version=1.0.48
+version=1.0.50
 prefix=""
 libdir=""
 libs=""
diff --git a/scripts/libpng.pc.in b/scripts/libpng.pc.in
index f1a2cb3..14fa67c 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.0.48
+Version: 1.0.50
 Libs: -L${libdir} -lpng10
 Cflags: -I${includedir}
diff --git a/scripts/makefile.32sunu b/scripts/makefile.32sunu
index 61b01be..5ec3911 100644
--- a/scripts/makefile.32sunu
+++ b/scripts/makefile.32sunu
@@ -11,7 +11,7 @@
 # Library name:
 LIBNAME=libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.64sunu b/scripts/makefile.64sunu
index bffef9d..fa8bc03 100644
--- a/scripts/makefile.64sunu
+++ b/scripts/makefile.64sunu
@@ -11,7 +11,7 @@
 # Library name:
 LIBNAME=libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.aix b/scripts/makefile.aix
index d76b615..608a105 100644
--- a/scripts/makefile.aix
+++ b/scripts/makefile.aix
@@ -23,7 +23,7 @@
 
 LIBNAME=libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 prefix=/usr/local
diff --git a/scripts/makefile.beos b/scripts/makefile.beos
index 846887d..dc198ee 100644
--- a/scripts/makefile.beos
+++ b/scripts/makefile.beos
@@ -11,7 +11,7 @@
 # Library name:
 LIBNAME=libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.cygwin b/scripts/makefile.cygwin
index 5fe0049..85f08b2 100644
--- a/scripts/makefile.cygwin
+++ b/scripts/makefile.cygwin
@@ -77,7 +77,7 @@
 LIBNAME = libpng10
 PNGMAJ = 0
 CYGDLL = 10
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 SHAREDLIB=cygpng$(CYGDLL).dll
diff --git a/scripts/makefile.darwin b/scripts/makefile.darwin
index 4a7c798..488f0dd 100644
--- a/scripts/makefile.darwin
+++ b/scripts/makefile.darwin
@@ -22,7 +22,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 10
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.dec b/scripts/makefile.dec
index c7bd350..3cfd44e 100644
--- a/scripts/makefile.dec
+++ b/scripts/makefile.dec
@@ -8,7 +8,7 @@
 
 # Library name:
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 LIBNAME = libpng10
 
diff --git a/scripts/makefile.elf b/scripts/makefile.elf
index 0d9275d..3c52b12 100644
--- a/scripts/makefile.elf
+++ b/scripts/makefile.elf
@@ -16,7 +16,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.gcmmx b/scripts/makefile.gcmmx
index bb44276..53dfadc 100644
--- a/scripts/makefile.gcmmx
+++ b/scripts/makefile.gcmmx
@@ -17,7 +17,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.hp64 b/scripts/makefile.hp64
index f4b73f7..ea75b67 100644
--- a/scripts/makefile.hp64
+++ b/scripts/makefile.hp64
@@ -21,7 +21,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.hpgcc b/scripts/makefile.hpgcc
index 3d61816..58a5f35 100644
--- a/scripts/makefile.hpgcc
+++ b/scripts/makefile.hpgcc
@@ -11,7 +11,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.hpux b/scripts/makefile.hpux
index 2bfdbdb..4e6b9a8 100644
--- a/scripts/makefile.hpux
+++ b/scripts/makefile.hpux
@@ -21,7 +21,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.linux b/scripts/makefile.linux
index 377a9ef..7e8fad0 100644
--- a/scripts/makefile.linux
+++ b/scripts/makefile.linux
@@ -10,7 +10,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.mingw b/scripts/makefile.mingw
index 1c06360..b0268da 100644
--- a/scripts/makefile.mingw
+++ b/scripts/makefile.mingw
@@ -77,7 +77,7 @@
 LIBNAME = libpng10
 PNGMAJ = 0
 MINGDLL = 10
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 SHAREDLIB=libpng$(MINGDLL).dll
diff --git a/scripts/makefile.ne12bsd b/scripts/makefile.ne12bsd
index 2ce20f2..2338964 100644
--- a/scripts/makefile.ne12bsd
+++ b/scripts/makefile.ne12bsd
@@ -17,7 +17,7 @@
 
 LIB=	png10
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	1.0.48
+SHLIB_MINOR=	1.0.50
 SRCS=	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 c7ee1d5..1d6ea4d 100644
--- a/scripts/makefile.netbsd
+++ b/scripts/makefile.netbsd
@@ -17,7 +17,7 @@
 
 LIB=	png
 SHLIB_MAJOR=	3
-SHLIB_MINOR=	1.0.48
+SHLIB_MINOR=	1.0.50
 SRCS=	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 f507595..9ed6db1 100644
--- a/scripts/makefile.nommx
+++ b/scripts/makefile.nommx
@@ -10,7 +10,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.openbsd b/scripts/makefile.openbsd
index 3f07d4f..3d209cd 100644
--- a/scripts/makefile.openbsd
+++ b/scripts/makefile.openbsd
@@ -11,7 +11,7 @@
 MANDIR= ${PREFIX}/man/cat
 
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	1.0.48
+SHLIB_MINOR=	1.0.50
 
 LIB=	png
 SRCS=	png.c pngerror.c pngget.c pngmem.c pngpread.c \
diff --git a/scripts/makefile.sco b/scripts/makefile.sco
index cbc853b..6d13ad5 100644
--- a/scripts/makefile.sco
+++ b/scripts/makefile.sco
@@ -12,7 +12,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.sggcc b/scripts/makefile.sggcc
index c3b8eec..0a446a9 100644
--- a/scripts/makefile.sggcc
+++ b/scripts/makefile.sggcc
@@ -9,7 +9,7 @@
 # Library name:
 LIBNAME=libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.sgi b/scripts/makefile.sgi
index 039a4fb..1f56c68 100644
--- a/scripts/makefile.sgi
+++ b/scripts/makefile.sgi
@@ -9,7 +9,7 @@
 # Library name:
 LIBNAME=libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.so9 b/scripts/makefile.so9
index 25bacfc..893d440 100644
--- a/scripts/makefile.so9
+++ b/scripts/makefile.so9
@@ -11,7 +11,7 @@
 
 # Library name:
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 LIBNAME = libpng10
 
diff --git a/scripts/makefile.solaris b/scripts/makefile.solaris
index eac0d14..88dfe1c 100644
--- a/scripts/makefile.solaris
+++ b/scripts/makefile.solaris
@@ -11,7 +11,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/makefile.solaris-x86 b/scripts/makefile.solaris-x86
index d6eba1c..942ab63 100644
--- a/scripts/makefile.solaris-x86
+++ b/scripts/makefile.solaris-x86
@@ -11,7 +11,7 @@
 # Library name:
 LIBNAME = libpng10
 PNGMAJ = 0
-PNGMIN = 1.0.48
+PNGMIN = 1.0.50
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # Shared library names:
diff --git a/scripts/pngos2.def b/scripts/pngos2.def
index 9c29054..92f5209 100644
--- a/scripts/pngos2.def
+++ b/scripts/pngos2.def
@@ -2,7 +2,7 @@
 ; PNG.LIB module definition file for OS/2
 ;----------------------------------------
 
-; Version 1.0.48
+; Version 1.0.50
 
 LIBRARY		PNG
 DESCRIPTION	"PNG image compression library for OS/2"
diff --git a/scripts/pngw32.def b/scripts/pngw32.def
index e656163..168cdaa 100644
--- a/scripts/pngw32.def
+++ b/scripts/pngw32.def
@@ -5,7 +5,7 @@
 LIBRARY
 
 EXPORTS
-;Version 1.0.48
+;Version 1.0.50
   png_build_grayscale_palette  @1
   png_check_sig        @2
   png_chunk_error      @3