Bug 403239 - "Update libpng to version 1.2.23 and reduce libpng footprint" [p=glennrp@gmail.com (Glenn Randers-Pehrson) r=stuart sr=tor a1.9=schrep]
authorreed@reedloden.com
Tue, 13 Nov 2007 03:03:32 -0800
changeset 7948 f7de0dc44970712bc126e02ba6c9c244758b4575
parent 7947 e291fb1065ab151bc061ba1e02c0acd4c47bb326
child 7949 fb3d803ef884bc0ba6c108f05eab9f2a572db716
push idunknown
push userunknown
push dateunknown
reviewersstuart, tor
bugs403239
milestone1.9b2pre
Bug 403239 - "Update libpng to version 1.2.23 and reduce libpng footprint" [p=glennrp@gmail.com (Glenn Randers-Pehrson) r=stuart sr=tor a1.9=schrep]
configure.in
modules/libimg/png/CHANGES
modules/libimg/png/LICENSE
modules/libimg/png/MOZCHANGES
modules/libimg/png/Makefile.in
modules/libimg/png/README
modules/libimg/png/libpng.txt
modules/libimg/png/mozpngconf.h
modules/libimg/png/png.c
modules/libimg/png/png.h
modules/libimg/png/pngconf.h
modules/libimg/png/pngerror.c
modules/libimg/png/pnggccrd.c
modules/libimg/png/pngpread.c
modules/libimg/png/pngrtran.c
modules/libimg/png/pngrutil.c
modules/libimg/png/pngset.c
modules/libimg/png/pngvcrd.c
modules/libpr0n/decoders/png/Makefile.in
modules/libpr0n/decoders/png/nsPNGDecoder.cpp
modules/libpr0n/encoders/png/Makefile.in
--- a/configure.in
+++ b/configure.in
@@ -5548,29 +5548,16 @@ MOZ_ARG_ENABLE_STRING(image-decoders,
         option=`echo $option | sed 's/^-//'`
         MOZ_IMG_DECODERS=`echo "$MOZ_IMG_DECODERS" | sed "s/ ${option}//"`
     else
         MOZ_IMG_DECODERS="$MOZ_IMG_DECODERS $option"
     fi
 done],
     MOZ_IMG_DECODERS="$MOZ_IMG_DECODERS_DEFAULT")
 
-if test `echo "$MOZ_IMG_DECODERS" | grep -c png` -ne 0; then
-    MOZ_PNG_CFLAGS="$MOZ_PNG_CFLAGS -DMOZ_PNG_READ"
-    AC_MSG_CHECKING([if pnggccrd.c can be compiled without PNG_NO_MMX_CODE])
-    AC_TRY_COMPILE([#define MOZ_PNG_READ 1
-                    #include "$_topsrcdir/modules/libimg/png/pnggccrd.c"],,
-                    _results=yes,
-                    _results=no)
-    AC_MSG_RESULT([$_results])
-    if test "$_results" = "no"; then
-        MOZ_PNG_CFLAGS="$MOZ_PNG_CFLAGS -DPNG_NO_MMX_CODE"
-    fi
-fi
-
 dnl Dupes are removed in the encoder section because it will also add decoders
 
 dnl ========================================================
 dnl Image encoders
 dnl ========================================================
 MOZ_ARG_ENABLE_STRING(image-encoders,
 [  --enable-image-encoders[={mod1,mod2,default,all,none}]
                           Enable specific image encoders],
@@ -5587,20 +5574,16 @@ MOZ_ARG_ENABLE_STRING(image-encoders,
         addencoder=`echo "$MOZ_IMG_ENCODERS" | sed "s/ ${option}//"`
     else
         addencoder="$option"
     fi
     MOZ_IMG_ENCODERS="$MOZ_IMG_ENCODERS $addencoder"
 done],
     MOZ_IMG_ENCODERS="$MOZ_IMG_ENCODERS_DEFAULT")
 
-if test `echo "$MOZ_IMG_ENCODERS" | grep -c png` -ne 0; then
-    MOZ_PNG_CFLAGS="$MOZ_PNG_CFLAGS -DMOZ_PNG_WRITE"
-fi
-
 dnl Remove dupes
 MOZ_IMG_DECODERS=`${PERL} ${srcdir}/build/unix/uniq.pl ${MOZ_IMG_DECODERS}`
 MOZ_IMG_ENCODERS=`${PERL} ${srcdir}/build/unix/uniq.pl ${MOZ_IMG_ENCODERS}`
 
 dnl ========================================================
 dnl experimental ldap features
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(ldap-experimental,
--- a/modules/libimg/png/CHANGES
+++ b/modules/libimg/png/CHANGES
@@ -1475,17 +1475,17 @@ version 1.2.9beta4 [March 3, 2006]
 version 1.2.9beta5 [March 4, 2006]
   Removed trailing blanks from source files.
   Put version and date of latest change in each source file, and changed
     copyright year accordingly.
   More cleanup of configure.ac, Makefile.ac, and associated scripts.
   Restored scripts/makefile.elf which was inadvertently deleted.
 
 version 1.2.9beta6 [March 6, 2006]
-  Fixed typo (22) in configuration files.
+  Fixed typo (23) in configuration files.
 
 version 1.2.9beta7 [March 7, 2006]
   Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am
   Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s()
     in png.h.
   Updated makefile.elf as suggested by debian.
   Made cosmetic changes to some makefiles, adding LN_SF and other macros.
   Made some makefiles accept "exec_prefix".
@@ -1981,15 +1981,39 @@ version 1.2.22beta4 [October 7, 2007]
   Changed some 0 to '\0'.
 
 version 1.0.30rc1 and 1.2.22rc1 [October 8, 2007]
   No changes.
 
 version 1.0.30 and 1.2.22 [October 13, 2007]
   No changes.
 
+version 1.2.23beta01 [October 15, 2007]
+  Reduced number of invocations of png_strlen() in pngset.c.
+  Changed [azAZ09_] to [_abcde...89] in Makefile.am for better localization.
+
+version 1.2.23beta02 [October 16, 2007]
+  Eliminated png_strncpy() and png_strcpy() (Pierre Poissinger)
+  Changed $AN to $(AN) in Makefile.am.
+
+version 1.2.23beta03 [October 16, 2007]
+  Fixed off-by-one error in pngset.c
+  Restore statement to set last character of buffer to \0 in pngerror.c
+
+version 1.2.23beta04 [October 23, 2007]
+  Reject attempt to set all-zero cHRM values.
+
+version 1.2.23beta05 [October 26, 2007]
+  Add missing quotes in projects/visualc6, lost in version 1.2.20rc3
+
+version 1.2.23rc01 [November 2, 2007]
+  No changes.
+
+version 1.2.23 [November 6, 2007]
+  No changes.
+
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
 to subscribe)
 or to glennrp at users.sourceforge.net
 
 Glenn R-P
--- a/modules/libimg/png/LICENSE
+++ b/modules/libimg/png/LICENSE
@@ -3,17 +3,17 @@ This copy of the libpng notices is provi
 any discrepancy between this copy and the notices in the file png.h that is
 included in the libpng distribution, the latter shall prevail.
 
 COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
 
 If you modify libpng you may insert additional notices immediately following
 this sentence.
 
-libpng versions 1.2.6, August 15, 2004, through 1.2.22, October 13, 2007, are
+libpng versions 1.2.6, August 15, 2004, through 1.2.23, November 6, 2007, are
 Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.2.5
 with the following individual added to the list of Contributing Authors
 
    Cosmin Truta
 
 libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
 Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
@@ -101,9 +101,9 @@ boxes and the like:
 Also, the PNG logo (in PNG format, of course) is supplied in the
 files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
 
 Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is a
 certification mark of the Open Source Initiative.
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-October 13, 2007
+November 6, 2007
--- a/modules/libimg/png/MOZCHANGES
+++ b/modules/libimg/png/MOZCHANGES
@@ -1,18 +1,22 @@
 
 Changes made to pristine png source by mozilla.org developers.
 
-2007/10/13  -- Sync with libpng-1.2.22 (removes MMX support) (bug #386585)
+2007/11/10  -- Synced with libpng-1.2.23; Removed pnggccrd.c and pngvcrd.c;
+               Reduced footprint by removing error and warning text
+               (bug #403239)
 
-2007/07/27  -- Enable cHRM and iCCP chunks for color management (bug #16769)
+2007/10/13  -- Synced with libpng-1.2.22 (removes MMX support) (bug #386585)
 
-2007/05/05  -- Zero png_ptr->num_trans on CRC error (bug #374810)
+2007/07/27  -- Enabled cHRM and iCCP chunks for color management (bug #16769)
+
+2007/05/05  -- Zeroed png_ptr->num_trans on CRC error (bug #374810)
 
 2007/04/19  -- Synced with libpng-1.2.16 tree (bug #373249)
 
 2007/03/20  -- Added support for APNG (bug #257197)
 
 2006/06/27  -- Synced with libpng-1.2.12 tree (bug #334110)
 
 2004/10/07  -- Synced with libpng-1.2.7 tree (bug #261922)
 
-2004/10/07  -- add mozpngconf.h (bug #208607)
+2004/10/07  -- Added mozpngconf.h (bug #208607)
--- a/modules/libimg/png/Makefile.in
+++ b/modules/libimg/png/Makefile.in
@@ -50,33 +50,47 @@ endif
 LIBXUL_LIBRARY = 1
 
 REQUIRES	= $(ZLIB_REQUIRES) \
 		  $(NULL)
 
 CSRCS		= \
 		png.c \
 		pngerror.c \
-		pnggccrd.c \
 		pngget.c \
 		pngmem.c \
+		pngset.c \
+		pngtrans.c \
+		$(NULL)
+
+# These files enable support for reading PNGs
+ifneq (,$(filter png,$(MOZ_IMG_DECODERS)))
+CSRCS		+= \
 		pngpread.c \
 		pngread.c \
 		pngrio.c \
 		pngrutil.c \
-		pngset.c \
-		pngtrans.c \
+		$(NULL)
+
+DEFINES		+= -DMOZ_PNG_READ
+endif
+
+# These files enable support for writing PNGs
+ifneq (,$(filter png,$(MOZ_IMG_ENCODERS)))
+CSRCS		+= \
 		pngwio.c \
 		pngwrite.c \
 		pngwtran.c \
 		pngrtran.c \
 		pngwutil.c \
-		pngvcrd.c \
 		$(NULL)
 
+DEFINES		+= -DMOZ_PNG_WRITE
+endif
+
 EXPORTS		= png.h pngconf.h mozpngconf.h
 
 LOCAL_INCLUDES	= -I$(srcdir)
 
 FORCE_STATIC_LIB = 1
 # This library is used by other shared libs in a static build
 FORCE_USE_PIC = 1
 
--- a/modules/libimg/png/README
+++ b/modules/libimg/png/README
@@ -1,9 +1,9 @@
-README for libpng version 1.2.22 - October 13, 2007 (shared library 12.0)
+README for libpng version 1.2.23 - November 6, 2007 (shared library 12.0)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
 
 Libpng comes in several distribution formats.  Get libpng-*.tar.gz
 or libpng-*.tar.bz2 if you want UNIX-style line endings in the text
 files, or lpng*.zip if you want DOS-style line endings.
 
@@ -108,29 +108,29 @@ Send comments/corrections/commendations 
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
 to subscribe) or to glennrp at users.sourceforge.net
 
 You can't reach Guy, the original libpng author, at the addresses
 given in previous versions of this document.  He and Andreas will read mail
 addressed to the png-implement list, however.
 
 Please do not send general questions about PNG.  Send them to
-the (png-list at ccrc.wustl.edu, subscription required, write to
-majordomo at ccrc.wustl.edu with "subscribe png-list" in your message).
+the (png-mng-misc at lists.sourceforge.net, subscription required, visit
+https://lists.sourceforge.net/lists/listinfo/png-mng-implement to subscribe)
 On the other hand,
 please do not send libpng questions to that address, send them to me
 or to the png-implement list.  I'll
 get them in the end anyway.  If you have a question about something
 in the PNG specification that is related to using libpng, send it
 to me.  Send me any questions that start with "I was using libpng,
 and ...".  If in doubt, send questions to me.  I'll bounce them
 to others, if necessary.
 
 Please do not send suggestions on how to change PNG.  We have
-been discussing PNG for nine years now, and it is official and
+been discussing PNG for twelve years now, and it is official and
 finished.  If you have suggestions for libpng, however, I'll
 gladly listen.  Even if your suggestion is not used immediately,
 it may be used later.
 
 Files in this distribution:
 
       ANNOUNCE      =>  Announcement of this version, with recent changes
       CHANGES       =>  Description of changes between libpng versions
@@ -185,21 +185,21 @@ Files in this distribution:
                             Netware.
        wince.txt        =>  Contains instructions for downloading a Microsoft
                             Visual C++ (Windows CD Toolkit) workspace for
                             building libpng and zlib on WindowsCE
       scripts       =>  Directory containing scripts for building libpng:
        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 libpng12.so.0.1.2.22)
+                            gcc, creates libpng12.so.0.1.2.23)
        makefile.linux   =>  Linux/ELF makefile
-                            (gcc, creates libpng12.so.0.1.2.22)
+                            (gcc, creates libpng12.so.0.1.2.23)
        makefile.gcmmx   =>  Linux/ELF makefile
-                            (gcc, creates libpng12.so.0.1.2.22,
+                            (gcc, creates libpng12.so.0.1.2.23,
                             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
                             ansi2knr (Requires ansi2knr.c from
                             ftp://ftp.cs.wisc.edu/ghost)
        makefile.aix     =>  AIX makefile
        makefile.cygwin  =>  Cygwin/gcc makefile
        makefile.darwin  =>  Darwin makefile
@@ -211,22 +211,22 @@ Files in this distribution:
        makefile.ibmc    =>  IBM C/C++ version 3.x for Win32 and OS/2 (static)
        makefile.intel   =>  Intel C/C++ version 4.0 and later
        libpng.icc       =>  Project file, IBM VisualAge/C++ 4.0 or later
        makefile.netbsd  =>  NetBSD/cc makefile, PNGGCCRD, makes libpng.so.
        makefile.ne12bsd  =>  NetBSD/cc makefile, PNGGCCRD, makes libpng12.so
        makefile.openbsd =>  OpenBSD makefile
        makefile.sgi     =>  Silicon Graphics IRIX (cc, creates static lib)
        makefile.sggcc   =>  Silicon Graphics
-                            (gcc, creates libpng12.so.0.1.2.22)
+                            (gcc, creates libpng12.so.0.1.2.23)
        makefile.sunos   =>  Sun makefile
        makefile.solaris =>  Solaris 2.X makefile
-                            (gcc, creates libpng12.so.0.1.2.22)
+                            (gcc, creates libpng12.so.0.1.2.23)
        makefile.so9     =>  Solaris 9 makefile
-                            (gcc, creates libpng12.so.0.1.2.22)
+                            (gcc, creates libpng12.so.0.1.2.23)
        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
        makefile.mips    =>  MIPS makefile
        makefile.acorn   =>  Acorn makefile
        makefile.amiga   =>  Amiga makefile
        smakefile.ppc    =>  AMIGA smakefile for SAS C V6.58/7.00 PPC
                             compiler (Requires SCOPTIONS, copied from
--- a/modules/libimg/png/libpng.txt
+++ b/modules/libimg/png/libpng.txt
@@ -1,11 +1,11 @@
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.2.22 - October 13, 2007
+ libpng version 1.2.23 - November 6, 2007
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2007 Glenn Randers-Pehrson
  For conditions of distribution and use, see copyright
  notice in png.h.
 
  based on:
 
@@ -2791,23 +2791,23 @@ version with leading zero, and release n
 
 You can also check which version of png.h you used when compiling your
 application:
 
    png_uint_32 application_vn = PNG_LIBPNG_VER;
 
 IX. Y2K Compliance in libpng
 
-October 13, 2007
+November 6, 2007
 
 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.22 are Y2K compliant.  It is my belief that earlier
+upward through 1.2.23 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
 will hold years up to 65535.  The other two hold the date in text
 format, and will hold years up to 9999.
 
 The integer is
     "png_uint_16 year" in png_time_struct.
--- a/modules/libimg/png/mozpngconf.h
+++ b/modules/libimg/png/mozpngconf.h
@@ -37,16 +37,17 @@
 #ifndef MOZPNGCONF_H
 #define MOZPNGCONF_H
 
 #define PNG_NO_GLOBAL_ARRAYS
 
 #ifndef MOZ_PNG_READ
 #define PNG_NO_READ_SUPPORTED
 #endif
+#define PNG_NO_ASSEMBLER_CODE
 #define PNG_NO_WARN_UNINITIALIZED_ROW
 #define PNG_NO_READ_BACKGROUND
 #define PNG_NO_READ_DITHER
 #define PNG_NO_READ_INVERT
 #define PNG_NO_READ_SHIFT
 #define PNG_NO_READ_PACK
 #define PNG_NO_READ_PACKSWAP
 #define PNG_NO_READ_FILLER
@@ -468,9 +469,23 @@
 #define png_set_add_alpha               MOZ_PNG_set_add_alpha
 
 /* libpng-1.2.9 additions */
 #define png_set_expand_gray_1_2_4_to_8  MOZ_PNG_set_x_g_124_to_8
 #define png_save_int_32                 MOZ_PNG_save_int_32
 #define png_save_uint_16                MOZ_PNG_save_uint_16
 #define png_save_uint_32                MOZ_PNG_save_uint_32
 
+/* libpng-1.2.22 addition */
+#define png_err                         MOZ_PNG_err
+
+#ifndef PR_LOGGING
+  #define MOZ_PNG_warning(s1,s2) ""
+  #define MOZ_PNG_chunk_warn(s1,s2) ""
+  #if PNG_LIBPNG_VER > 10221
+    #define PNG_NO_WARNINGS
+    #define PNG_NO_ERROR_TEXT
+    #define MOZ_PNG_error(s1,s2) MOZ_PNG_err(s1)
+    #define MOZ_PNG_chunk_err(s1,s2) MOZ_PNG_err(s1)
+  #endif
 #endif
+
+#endif /* MOZPNGCONF_H */
--- a/modules/libimg/png/png.c
+++ b/modules/libimg/png/png.c
@@ -8,17 +8,17 @@
  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  */
 
 #define PNG_INTERNAL
 #define PNG_NO_EXTERN
 #include "png.h"
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_22 Your_png_h_is_not_version_1_2_22;
+typedef version_1_2_23 Your_png_h_is_not_version_1_2_23;
 
 /* 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 */
 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
 
@@ -691,17 +691,17 @@ png_convert_to_rfc1123(png_structp png_p
 #endif /* PNG_TIME_RFC1123_SUPPORTED */
 
 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
 
 png_charp PNGAPI
 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.2.22 - October 13, 2007\n\
+   return ((png_charp) "\n libpng version 1.2.23 - November 6, 2007\n\
    Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
    Copyright (c) 1996-1997 Andreas Dilger\n\
    Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
 }
 
 /* The following return the library version as a short string in the
  * format 1.0.0 through 99.99.99zz.  To get the version of *.h files
  * used with your application, print out PNG_LIBPNG_VER_STRING, which
--- a/modules/libimg/png/png.h
+++ b/modules/libimg/png/png.h
@@ -1,20 +1,20 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.2.22 - October 13, 2007
+ * libpng version 1.2.23 - November 6, 2007
  * Copyright (c) 1998-2007 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.)
  *
  * 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.22 - October 13, 2007: Glenn
+ *  libpng versions 0.97, January 1998, through 1.2.23 - November 6, 2007: Glenn
  *  See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
  *
  *    Due to various miscommunications, unforeseen code incompatibilities
  *    and occasional factors outside the authors' control, version numbering
  *    on the library has not always been consistent and straightforward.
  *    The following table summarizes matters since version 0.89c, which was
@@ -164,16 +164,19 @@
  *    1.2.21rc1-3             13    10221  12.so.0.21[.0]
  *    1.0.29                  10    10029  10.so.0.29[.0]
  *    1.2.21                  13    10221  12.so.0.21[.0]
  *    1.2.22beta1-4           13    10222  12.so.0.22[.0]
  *    1.0.30rc1               10    10030  10.so.0.30[.0]
  *    1.2.22rc1               13    10222  12.so.0.22[.0]
  *    1.0.30                  10    10030  10.so.0.30[.0]
  *    1.2.22                  13    10222  12.so.0.22[.0]
+ *    1.2.23beta01-05         13    10223  12.so.0.23[.0]
+ *    1.2.23rc01              13    10223  12.so.0.23[.0]
+ *    1.2.23                  13    10223  12.so.0.23[.0]
  *
  *    Henceforth the source version will match the shared-library major
  *    and minor numbers; the shared-library major version number will be
  *    used for changes in backward compatibility, as it is intended.  The
  *    PNG_LIBPNG_VER macro, which is not used within libpng but is available
  *    for applications, is an unsigned integer of the form xyyzz corresponding
  *    to the source version x.y.z (leading zeros in y and z).  Beta versions
  *    were given the previous public release number plus a letter, until
@@ -193,17 +196,17 @@
  */
 
 /*
  * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
  *
  * If you modify libpng you may insert additional notices immediately following
  * this sentence.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.2.22, October 13, 2007, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.2.23, November 6, 2007, are
  * Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
  * distributed according to the same disclaimer and license as libpng-1.2.5
  * with the following individual added to the list of Contributing Authors:
  *
  *    Cosmin Truta
  *
  * libpng versions 1.0.7, July 1, 2000, through 1.2.5, October 3, 2002, are
  * Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
@@ -305,23 +308,23 @@
  *
  * Thanks to Frank J. T. Wojcik for helping with the documentation.
  */
 
 /*
  * Y2K compliance in libpng:
  * =========================
  *
- *    October 13, 2007
+ *    November 6, 2007
  *
  *    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.22 are Y2K compliant.  It is my belief that earlier
+ *    upward through 1.2.23 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 will hold years up to 65535.  The other two hold the date in text
  *    format, and will hold years up to 9999.
  *
  *    The integer is
  *        "png_uint_16 year" in png_time_struct.
@@ -367,27 +370,27 @@
 
 /* This is not the place to learn how to use libpng.  The file libpng.txt
  * describes how to use libpng, and the file example.c summarizes it
  * with some code on which to build.  This file is useful for looking
  * at the actual function definitions and structure components.
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.2.22"
+#define PNG_LIBPNG_VER_STRING "1.2.23"
 #define PNG_HEADER_VERSION_STRING \
-   " libpng version 1.2.22 - October 13, 2007\n"
+   " libpng version 1.2.23 - November 6, 2007\n"
 
 #define PNG_LIBPNG_VER_SONUM   0
 #define PNG_LIBPNG_VER_DLLNUM  13
 
 /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
 #define PNG_LIBPNG_VER_MAJOR   1
 #define PNG_LIBPNG_VER_MINOR   2
-#define PNG_LIBPNG_VER_RELEASE 22
+#define PNG_LIBPNG_VER_RELEASE 23
 /* This should match the numeric part of the final component of
  * PNG_LIBPNG_VER_STRING, omitting any leading zero: */
 
 #define PNG_LIBPNG_VER_BUILD  0
 
 /* Release Status */
 #define PNG_LIBPNG_BUILD_ALPHA    1
 #define PNG_LIBPNG_BUILD_BETA     2
@@ -405,17 +408,17 @@
 
 #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
 
 /* Careful here.  At one time, Guy wanted to use 082, but that would be octal.
  * We must not include leading zeros.
  * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
  * 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 10222 /* 1.2.22 */
+#define PNG_LIBPNG_VER 10223 /* 1.2.23 */
 
 #ifndef PNG_VERSION_INFO_ONLY
 /* include the compression library's header */
 #include "zlib.h"
 #endif
 
 /* include all user configurable info, including optional assembler routines */
 #include "pngconf.h"
@@ -646,19 +649,20 @@ typedef png_time FAR * png_timep;
 typedef png_time FAR * FAR * png_timepp;
 
 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 /* png_unknown_chunk is a structure to hold queued chunks for which there is
  * no specific support.  The idea is that we can use this to queue
  * up private chunks for output even though the library doesn't actually
  * know about their semantics.
  */
+#define PNG_CHUNK_NAME_LENGTH 5
 typedef struct png_unknown_chunk_t
 {
-    png_byte name[5];
+    png_byte name[PNG_CHUNK_NAME_LENGTH];
     png_byte *data;
     png_size_t size;
 
     /* libpng-using applications should NOT directly modify this byte. */
     png_byte location; /* mode of operation at read time */
 }
 png_unknown_chunk;
 typedef png_unknown_chunk FAR * png_unknown_chunkp;
@@ -1468,17 +1472,17 @@ struct png_struct_def
    png_unknown_chunk unknown_chunk;
 #endif
 };
 
 
 /* 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_2_22;
+typedef png_structp version_1_2_23;
 
 typedef png_struct FAR * FAR * png_structpp;
 
 /* Here are the function definitions most commonly used.  This is not
  * the place to find out how to use libpng.  See libpng.txt for the
  * full explanation, see example.c for the summary.  This just provides
  * a simple one line description of the use of each function.
  */
--- a/modules/libimg/png/pngconf.h
+++ b/modules/libimg/png/pngconf.h
@@ -1,12 +1,12 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.2.22 - October 13, 2007
+ * libpng version 1.2.23 - November 6, 2007
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2007 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.)
  */
 
 /* Any machine specific code is near the front of this file, so if you
  * are configuring libpng for a machine, you may want to read the section
@@ -1437,18 +1437,16 @@ typedef z_stream FAR *  png_zstreamp;
 
 #if defined(USE_FAR_KEYWORD)  /* memory model independent fns */
 /* use this to make far-to-near assignments */
 #  define CHECK   1
 #  define NOCHECK 0
 #  define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
 #  define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
 #  define png_snprintf _fsnprintf   /* Added to v 1.2.19 */
-#  define png_strcpy  _fstrcpy
-#  define png_strncpy _fstrncpy   /* Added to v 1.2.6 */
 #  define png_strlen  _fstrlen
 #  define png_memcmp  _fmemcmp    /* SJT: added */
 #  define png_memcpy  _fmemcpy
 #  define png_memset  _fmemset
 #else /* use the usual functions */
 #  define CVT_PTR(ptr)         (ptr)
 #  define CVT_PTR_NOCHECK(ptr) (ptr)
 #  ifndef PNG_NO_SNPRINTF
@@ -1467,18 +1465,16 @@ typedef z_stream FAR *  png_zstreamp;
       * or malevolent buffer overflows.  If you don't have snprintf()
       * as a general rule you should provide one (you can get one from
       * Portable OpenSSH). */
 #    define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
 #    define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
 #    define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
         sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
 #  endif
-#  define png_strcpy  strcpy
-#  define png_strncpy strncpy     /* Added to v 1.2.6 */
 #  define png_strlen  strlen
 #  define png_memcmp  memcmp      /* SJT: added */
 #  define png_memcpy  memcpy
 #  define png_memset  memset
 #endif
 /* End of memory model independent support */
 
 /* Just a little check that someone hasn't tried to define something
--- a/modules/libimg/png/pngerror.c
+++ b/modules/libimg/png/pngerror.c
@@ -1,12 +1,12 @@
 
 /* pngerror.c - stub functions for i/o and memory allocation
  *
- * Last changed in libpng 1.2.22 [October 13, 2007]
+ * Last changed in libpng 1.2.22 [November 6, 2007]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2007 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.)
  *
  * This file provides a location for all error handling.  Users who
  * need special error handling are expected to write replacement functions
  * and use png_set_error_fn() to use those functions.  See the instructions
@@ -131,16 +131,18 @@ png_warning(png_structp png_ptr, png_con
  * if the character is invalid.
  */
 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
 static PNG_CONST char png_digit[16] = {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    'A', 'B', 'C', 'D', 'E', 'F'
 };
 
+#define PNG_MAX_ERROR_TEXT 64
+
 #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
 static void /* PRIVATE */
 png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
    error_message)
 {
    int iout = 0, iin = 0;
 
    while (iin < 4)
@@ -160,42 +162,42 @@ png_format_buffer(png_structp png_ptr, p
    }
 
    if (error_message == NULL)
       buffer[iout] = '\0';
    else
    {
       buffer[iout++] = ':';
       buffer[iout++] = ' ';
-      png_strncpy(buffer+iout, error_message, 63);
-      buffer[iout+63] = '\0';
+      png_memcpy(buffer+iout, error_message, PNG_MAX_ERROR_TEXT);
+      buffer[iout+PNG_MAX_ERROR_TEXT-1] = '\0';
    }
 }
 
 #ifdef PNG_READ_SUPPORTED
 void PNGAPI
 png_chunk_error(png_structp png_ptr, png_const_charp error_message)
 {
-   char msg[18+64];
+   char msg[18+PNG_MAX_ERROR_TEXT];
    if (png_ptr == NULL)
      png_error(png_ptr, error_message);
    else
    {
      png_format_buffer(png_ptr, msg, error_message);
      png_error(png_ptr, msg);
    }
 }
 #endif /* PNG_READ_SUPPORTED */
 #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
 
 #ifndef PNG_NO_WARNINGS
 void PNGAPI
 png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
 {
-   char msg[18+64];
+   char msg[18+PNG_MAX_ERROR_TEXT];
    if (png_ptr == NULL)
      png_warning(png_ptr, warning_message);
    else
    {
      png_format_buffer(png_ptr, msg, warning_message);
      png_warning(png_ptr, msg);
    }
 }
deleted file mode 100644
--- a/modules/libimg/png/pnggccrd.c
+++ /dev/null
@@ -1,1 +0,0 @@
-/* pnggccrd.c was removed from libpng-1.2.20. */
--- a/modules/libimg/png/pngpread.c
+++ b/modules/libimg/png/pngpread.c
@@ -1,12 +1,12 @@
 
 /* pngpread.c - read a png file in push mode
  *
- * Last changed in libpng 1.2.22 [October 13, 2007]
+ * Last changed in libpng 1.2.22 [November 6, 2007]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2007 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.)
  */
 
 #define PNG_INTERNAL
 #include "png.h"
@@ -1667,19 +1667,21 @@ png_push_handle_unknown(png_structp png_
 #ifdef PNG_MAX_MALLOC_64K
       if (length > (png_uint_32)65535L)
       {
           png_warning(png_ptr, "unknown chunk too large to fit in memory");
           skip = length - (png_uint_32)65535L;
           length = (png_uint_32)65535L;
       }
 #endif
-      png_strncpy((png_charp)png_ptr->unknown_chunk.name,
-	 (png_charp)png_ptr->chunk_name, 4);
-      png_ptr->unknown_chunk.name[4] = '\0';
+      png_memcpy((png_charp)png_ptr->unknown_chunk.name,
+                 (png_charp)png_ptr->chunk_name, 
+                 png_sizeof(png_ptr->unknown_chunk.name));
+      png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1]='\0';
+
       png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
       png_ptr->unknown_chunk.size = (png_size_t)length;
       png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
       if(png_ptr->read_user_chunk_fn != NULL)
       {
          /* callback to user unknown chunk handler */
          int ret;
--- a/modules/libimg/png/pngrtran.c
+++ b/modules/libimg/png/pngrtran.c
@@ -1,12 +1,12 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * Last changed in libpng 1.2.22 [October 13, 2007]
+ * Last changed in libpng 1.2.22 [November 6, 2007]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2007 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.)
  *
  * This file contains functions optionally called by an application
  * in order to tell libpng how to handle data when reading a PNG.
  * Transformations that are used in both reading and writing are
--- a/modules/libimg/png/pngrutil.c
+++ b/modules/libimg/png/pngrutil.c
@@ -1,12 +1,12 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * Last changed in libpng 1.2.22 [October 13, 2007]
+ * Last changed in libpng 1.2.22 [November 6, 2007]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2007 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.)
  *
  * This file contains routines that are only called from within
  * libpng itself during the course of reading an image.
  */
@@ -2385,19 +2385,20 @@ png_handle_unknown(png_structp png_ptr, 
 #ifdef PNG_MAX_MALLOC_64K
        if (length > (png_uint_32)65535L)
        {
            png_warning(png_ptr, "unknown chunk too large to fit in memory");
            skip = length - (png_uint_32)65535L;
            length = (png_uint_32)65535L;
        }
 #endif
-       png_strncpy((png_charp)png_ptr->unknown_chunk.name,
-	 (png_charp)png_ptr->chunk_name, 4);
-       png_ptr->unknown_chunk.name[4] = '\0';
+       png_memcpy((png_charp)png_ptr->unknown_chunk.name,
+                  (png_charp)png_ptr->chunk_name, 
+                  png_sizeof(png_ptr->unknown_chunk.name));
+       png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] = '\0';
        png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
        png_ptr->unknown_chunk.size = (png_size_t)length;
        png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
        if(png_ptr->read_user_chunk_fn != NULL)
        {
           /* callback to user unknown chunk handler */
           int ret;
--- a/modules/libimg/png/pngset.c
+++ b/modules/libimg/png/pngset.c
@@ -1,12 +1,12 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * Last changed in libpng 1.2.22 [October 13, 2007]
+ * Last changed in libpng 1.2.22 [November 6, 2007]
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2007 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.)
  *
  * The functions here are used during reads to store data from the file
  * into the info struct, and during writes to store application data
  * into the info struct for writing into the file.  This abstracts the
@@ -36,17 +36,23 @@ png_set_bKGD(png_structp png_ptr, png_in
 void PNGAPI
 png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
    double white_x, double white_y, double red_x, double red_y,
    double green_x, double green_y, double blue_x, double blue_y)
 {
    png_debug1(1, "in %s storage function\n", "cHRM");
    if (png_ptr == NULL || info_ptr == NULL)
       return;
-
+   if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
+       blue_x || blue_y))
+   {
+      png_warning(png_ptr,
+        "Ignoring attempt to set all-zero chromaticity values");
+      return;
+   }
    if (white_x < 0.0 || white_y < 0.0 ||
          red_x < 0.0 ||   red_y < 0.0 ||
        green_x < 0.0 || green_y < 0.0 ||
         blue_x < 0.0 ||  blue_y < 0.0)
    {
       png_warning(png_ptr,
         "Ignoring attempt to set negative chromaticity value");
       return;
@@ -88,16 +94,23 @@ png_set_cHRM_fixed(png_structp png_ptr, 
    png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
    png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
    png_fixed_point blue_x, png_fixed_point blue_y)
 {
    png_debug1(1, "in %s storage function\n", "cHRM");
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
+   if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
+       blue_x || blue_y))
+   {
+      png_warning(png_ptr,
+        "Ignoring attempt to set all-zero chromaticity values");
+      return;
+   }
    if (white_x < 0 || white_y < 0 ||
          red_x < 0 ||   red_y < 0 ||
        green_x < 0 || green_y < 0 ||
         blue_x < 0 ||  blue_y < 0)
    {
       png_warning(png_ptr,
         "Ignoring attempt to set negative chromaticity value");
       return;
@@ -679,29 +692,30 @@ png_set_sRGB_gAMA_and_cHRM(png_structp p
 #if defined(PNG_iCCP_SUPPORTED)
 void PNGAPI
 png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
              png_charp name, int compression_type,
              png_charp profile, png_uint_32 proflen)
 {
    png_charp new_iccp_name;
    png_charp new_iccp_profile;
+   png_uint_32 length;
 
    png_debug1(1, "in %s storage function\n", "iCCP");
    if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
       return;
 
-   new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
+   length = png_strlen(name)+1;
+   new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
    if (new_iccp_name == NULL)
    {
       png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
       return;
    }
-   png_strncpy(new_iccp_name, name, png_strlen(name));
-   new_iccp_name[png_strlen(name)] = '\0';
+   png_memcpy(new_iccp_name, name, length);
    new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
    if (new_iccp_profile == NULL)
    {
       png_free (png_ptr, new_iccp_name);
       png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
       return;
    }
    png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
@@ -972,27 +986,27 @@ png_set_sPLT(png_structp png_ptr,
            info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
     png_free(png_ptr, info_ptr->splt_palettes);
     info_ptr->splt_palettes=NULL;
 
     for (i = 0; i < nentries; i++)
     {
         png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
         png_sPLT_tp from = entries + i;
+        png_uint_32 length;
 
-        to->name = (png_charp)png_malloc_warn(png_ptr,
-          png_strlen(from->name) + 1);
+        length = png_strlen(from->name) + 1;
+        to->name = (png_charp)png_malloc_warn(png_ptr, length);
         if (to->name == NULL)
         {
            png_warning(png_ptr,
              "Out of memory while processing sPLT chunk");
         }
         /* TODO: use png_malloc_warn */
-        png_strncpy(to->name, from->name, png_strlen(from->name));
-        to->name[png_strlen(from->name)] = '\0';
+        png_memcpy(to->name, from->name, length);
         to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
             from->nentries * png_sizeof(png_sPLT_entry));
         /* TODO: use png_malloc_warn */
         png_memcpy(to->entries, from->entries,
             from->nentries * png_sizeof(png_sPLT_entry));
         if (to->entries == NULL)
         {
            png_warning(png_ptr,
@@ -1050,17 +1064,17 @@ png_set_acTL(png_structp png_ptr, png_in
     info_ptr->num_frames = num_frames;
     info_ptr->num_plays = num_plays;
     
     info_ptr->valid |= PNG_INFO_acTL;
     
     return (1);
 }
 
-/* delay_num and delay_den can hold any values including zero */
+/* delay_num and delay_den can hold any 16-bit values including zero */
 png_uint_32 PNGAPI
 png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, 
     png_uint_32 width, png_uint_32 height,
     png_uint_32 x_offset, png_uint_32 y_offset,
     png_uint_16 delay_num, png_uint_16 delay_den,
     png_byte dispose_op, png_byte blend_op)
 {
     png_debug1(1, "in %s storage function\n", "fcTL");
@@ -1174,18 +1188,21 @@ png_set_unknown_chunks(png_structp png_p
     png_free(png_ptr, info_ptr->unknown_chunks);
     info_ptr->unknown_chunks=NULL;
 
     for (i = 0; i < num_unknowns; i++)
     {
         png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
         png_unknown_chunkp from = unknowns + i;
 
-        png_strncpy((png_charp)to->name, (png_charp)from->name, 4);
-        to->name[4] = '\0';
+        png_memcpy((png_charp)to->name, 
+                   (png_charp)from->name, 
+                   png_sizeof(from->name));
+        to->name[png_sizeof(to->name)-1] = '\0';
+
         to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
         if (to->data == NULL)
         {
            png_warning(png_ptr,
               "Out of memory while processing unknown chunk.");
         }
         else
         {
deleted file mode 100644
--- a/modules/libimg/png/pngvcrd.c
+++ /dev/null
@@ -1,1 +0,0 @@
-/* pnggvrd.c was removed from libpng-1.2.20. */
--- a/modules/libpr0n/decoders/png/Makefile.in
+++ b/modules/libpr0n/decoders/png/Makefile.in
@@ -57,10 +57,18 @@ REQUIRES = xpcom \
            imglib2 \
            $(PNG_REQUIRES) \
            $(ZLIB_REQUIRES) \
            $(LCMS_REQUIRES) \
            $(NULL)
 
 CPPSRCS		= nsPNGDecoder.cpp
 
+ifneq (,$(filter png,$(MOZ_IMG_ENCODERS)))
+DEFINES		+= -DMOZ_PNG_WRITE
+endif
+
+ifneq (,$(filter png,$(MOZ_IMG_DECODERS)))
+DEFINES		+= -DMOZ_PNG_READ
+endif
+
 include $(topsrcdir)/config/rules.mk
 
--- a/modules/libpr0n/decoders/png/nsPNGDecoder.cpp
+++ b/modules/libpr0n/decoders/png/nsPNGDecoder.cpp
@@ -129,31 +129,32 @@ void nsPNGDecoder::CreateFrame(png_uint_
           mImage.get ()));
 
   mFrameHasNoAlpha = PR_TRUE;
 }
 
 // set timeout and frame disposal method for the current frame
 void nsPNGDecoder::SetAnimFrameInfo()
 {
-  png_uint_16 delay_num, delay_den; /* in seconds */
+  png_uint_16 delay_num, delay_den;
+  /* delay, in seconds is delay_num/delay_den */
   png_byte dispose_op;
   png_byte blend_op;
   PRInt32 timeout; /* in milliseconds */
   
   delay_num = png_get_next_frame_delay_num(mPNG, mInfo);
   delay_den = png_get_next_frame_delay_den(mPNG, mInfo);
   dispose_op = png_get_next_frame_dispose_op(mPNG, mInfo);
   blend_op = png_get_next_frame_blend_op(mPNG, mInfo);
 
   if (delay_num == 0) {
     timeout = 0; // gfxImageFrame::SetTimeout() will set to a minimum
   } else {
     if (delay_den == 0)
-      delay_den = 100; // so sais the APNG spec
+      delay_den = 100; // so says the APNG spec
     
     // Need to cast delay_num to float to have a proper division and
     // the result to int to avoid compiler warning
     timeout = static_cast<PRInt32>
                          (static_cast<PRFloat64>(delay_num) * 1000 / delay_den);
   }
   mFrame->SetTimeout(timeout);
   
@@ -347,16 +348,17 @@ NS_IMETHODIMP nsPNGDecoder::WriteFrom(ns
 // Adapted from http://www.littlecms.com/pngchrm.c example code
 static cmsHPROFILE
 PNGGetColorProfile(png_structp png_ptr, png_infop info_ptr,
                    int color_type, PRUint32 *inType, PRUint32 *intent)
 {
   cmsHPROFILE profile = nsnull;
   *intent = INTENT_PERCEPTUAL;   // XXX: should this be the default?
 
+#ifndef PNG_NO_READ_iCCP
   // First try to see if iCCP chunk is present
   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_iCCP)) {
     png_uint_32 profileLen;
     char *profileData, *profileName;
     int compression;
 
     png_get_iCCP(png_ptr, info_ptr, &profileName, &compression,
                  &profileData, &profileLen);
@@ -381,49 +383,54 @@ PNGGetColorProfile(png_structp png_ptr, 
 
     if (mismatch) {
       cmsCloseProfile(profile);
       profile = nsnull;
     } else {
       *intent = cmsTakeRenderingIntent(profile);
     }
   }
+#endif
 
+#ifndef PNG_NO_READ_sRGB
   // Check sRGB chunk
   if (!profile && png_get_valid(png_ptr, info_ptr, PNG_INFO_sRGB)) {
     profile = cmsCreate_sRGBProfile();
 
     if (profile) {
       int fileIntent;
       png_get_sRGB(png_ptr, info_ptr, &fileIntent);
       PRUint32 map[] = { INTENT_PERCEPTUAL, INTENT_RELATIVE_COLORIMETRIC,
                          INTENT_SATURATION, INTENT_ABSOLUTE_COLORIMETRIC };
       *intent = map[fileIntent];
     }
   }
+#endif
 
   // Check gAMA/cHRM chunks
   if (!profile && png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
     cmsCIExyY whitePoint = {0.3127, 0.3290, 1.0};         // D65
     cmsCIExyYTRIPLE primaries = {
       {0.6400, 0.3300, 1.0},
       {0.3000, 0.6000, 1.0},
       {0.1500, 0.0600, 1.0}
     };
 
+#ifndef PNG_NO_READ_cHRM
     if (png_get_valid(png_ptr, info_ptr, PNG_INFO_cHRM)) {
       png_get_cHRM(png_ptr, info_ptr,
                    &whitePoint.x, &whitePoint.y,
                    &primaries.Red.x,   &primaries.Red.y,
                    &primaries.Green.x, &primaries.Green.y,
                    &primaries.Blue.x,  &primaries.Blue.y);
 
       whitePoint.Y =
         primaries.Red.Y = primaries.Green.Y = primaries.Blue.Y = 1.0;
     }
+#endif
 
     double gammaOfFile;
     LPGAMMATABLE gammaTable[3];
 
     png_get_gAMA(png_ptr, info_ptr, &gammaOfFile);
 
     gammaTable[0] = gammaTable[1] = gammaTable[2] =
       cmsBuildGamma(256, 1/gammaOfFile);
--- a/modules/libpr0n/encoders/png/Makefile.in
+++ b/modules/libpr0n/encoders/png/Makefile.in
@@ -51,13 +51,21 @@ EXTRA_DSO_LIBS	= gkgfx
 REQUIRES	= xpcom \
 		  gfx \
 		  string \
 		  imglib2 \
 		  $(PNG_REQUIRES) \
 		  $(ZLIB_REQUIRES) \
 		  $(NULL)
 
+ifneq (,$(filter png,$(MOZ_IMG_ENCODERS)))
+DEFINES		+= -DMOZ_PNG_WRITE
+endif
+
+ifneq (,$(filter png,$(MOZ_IMG_DECODERS)))
+DEFINES		+= -DMOZ_PNG_READ
+endif
+
 CPPSRCS		= nsPNGEncoder.cpp
 
 include $(topsrcdir)/config/rules.mk