Imported from libpng-1.0.5s.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index 45bf9b1..155caa8 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.0.5q - February 5, 2000
+Libpng 1.0.5s - February 18, 2000
 
 This is not intended to be a public release.  It will be replaced
 within a few weeks by a public version or by another test version.
@@ -139,6 +139,31 @@
   Relocated the makefile.solaris warning about PATH problems.
   Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg)
   Revised makefile.gcmmx
+  Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros
+version 1.0.5r [February 7, 2000]
+  Removed superfluous prototype for png_get_itxt from png.h
+  Fixed a bug in pngrtran.c that improperly expanded the background color.
+  Return *num_text=0 from png_get_text() when appropriate, and fix documentation
+    of png_get_text() in libpng.txt/libpng.3.
+version 1.0.5s [February 18, 2000]
+  Added "png_jmpbuf()" macro to pngconf.h, to help people migrate to the
+    new error handler that's planned for the next libpng release, and changed
+    example.c, pngtest.c, and contrib programs to use this macro.
+  Revised some of the DLL-export macros in pngconf.h (Greg Roelofs)
+  Fixed a bug in png_read_png() that caused it to fail to expand some images
+    that it should have expanded.
+  Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions
+    in pngget.c
+  Changed the allocation of palette, history, and trans arrays back to
+    the version 1.0.5 method (linking instead of copying) which restores
+    backward compatibility with version 1.0.5.  Added some remarks about
+    that in example.c
+  Updated makefile.linux and makefile.gccmmx to make directories conditionally.
+  Made cosmetic changes to pngasmrd.h
+  Added png_set_rows() and png_get_rows(), for use with png_read|write_png().
+  Modified png_read_png() to allocate info_ptr->row_pointers only if it
+    hasn't already been allocated.
+
 
 Send comments/corrections/commendations to
 png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
diff --git a/CHANGES b/CHANGES
index 5f2de77..e90ee00 100644
--- a/CHANGES
+++ b/CHANGES
@@ -611,3 +611,26 @@
   Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg)
   Revised makefile.gcmmx
   Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros
+version 1.0.5r [February 7, 2000]
+  Removed superfluous prototype for png_get_itxt from png.h
+  Fixed a bug in pngrtran.c that improperly expanded the background color.
+  Return *num_text=0 from png_get_text() when appropriate, and fix documentation
+    of png_get_text() in libpng.txt/libpng.3.
+version 1.0.5s [February 18, 2000]
+  Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the
+    new error handler that's planned for the next libpng release, and changed
+    example.c, pngtest.c, and contrib programs to use this macro.
+  Revised some of the DLL-export macros in pngconf.h (Greg Roelofs)
+  Fixed a bug in png_read_png() that caused it to fail to expand some images
+    that it should have expanded.
+  Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions
+    in pngget.c
+  Changed the allocation of palette, history, and trans arrays back to
+    the version 1.0.5 method (linking instead of copying) which restores
+    backward compatibility with version 1.0.5.  Added some remarks about
+    that in example.c.  Added "free_me" member to info_ptr and png_ptr.
+  Updated makefile.linux and makefile.gccmmx to make directories conditionally.
+  Made cosmetic changes to pngasmrd.h
+  Added png_set_rows() and png_get_rows(), for use with png_read|write_png().
+  Modified png_read_png() to allocate info_ptr->row_pointers only if it
+    hasn't already been allocated.
diff --git a/INSTALL b/INSTALL
index 114bc33..5cbfe77 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
 
-Installing libpng version 1.0.5q - February 5, 2000
+Installing libpng version 1.0.5s - February 18, 2000
 
 Before installing libpng, you must first install zlib.  zlib
 can usually be found wherever you got libpng.  zlib can be
@@ -10,7 +10,7 @@
 version of zlib that's installed.
 
 You can rename the directories that you downloaded (they
-might be called "libpng-1.0.5q" or "lpng103" and "zlib-1.1.3"
+might be called "libpng-1.0.5s" or "lpng103" and "zlib-1.1.3"
 or "zlib113") so that you have directories called "zlib" and "libpng".
 
 Your directory structure should look like this:
@@ -55,9 +55,9 @@
  makefile.hpux     =>  HPUX (10.20 and 11.00) makefile
  makefile.sgi      =>  Silicon Graphics IRIX makefile
  makefile.sunos    =>  Sun makefile
- makefile.solaris  =>  Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.5q)
- makefile.linux    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.0.5q)
- makefile.gcmmx    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.0.5q,
+ makefile.solaris  =>  Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.5s)
+ makefile.linux    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.0.5s)
+ makefile.gcmmx    =>  Linux/ELF makefile (gcc, creates libpng.so.2.1.0.5s,
                        uses assembler code tuned for Intel MMX platform)
  makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc
  makefile.mips     =>  MIPS makefile
diff --git a/KNOWNBUG b/KNOWNBUG
index 527da8c..31d9c54 100644
--- a/KNOWNBUG
+++ b/KNOWNBUG
@@ -74,3 +74,10 @@
    The new pnggccrd.c has syntax errors when compiled with gcc.
 
    STATUS: Under investigation.
+
+8. February 2000 -- BUG
+
+   When an RGBA file is expanded, only 24 or 48 bits per pixel are reserved
+   in rowbytes.
+
+   STATUS: Fixed in libpng-1.0.5s
diff --git a/LICENSE b/LICENSE
index 5f2d9dd..7102f66 100644
--- a/LICENSE
+++ b/LICENSE
@@ -5,7 +5,7 @@
 Copyright (c) 1996, 1997 Andreas Dilger
 (libpng versions 0.90, December 1996, through 0.96, May 1997)
 Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
-(libpng versions 0.97, January 1998, through 1.0.5q, February 5, 2000)
+(libpng versions 0.97, January 1998, through 1.0.5s, February 18, 2000)
 
 For the purposes of this copyright and license, "Contributing Authors"
 is defined as the following set of individuals:
@@ -68,4 +68,4 @@
 
 Glenn Randers-Pehrson
 randeg@alum.rpi.edu
-February 5, 2000
+February 18, 2000
diff --git a/README b/README
index 9e40a7e..972635d 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng 1.0.5q - February 5, 2000 (shared library 2.1)
+README for libpng 1.0.5s - February 18, 2000 (shared library 2.1)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
@@ -175,11 +175,11 @@
        makefile.sgi     =>  Silicon Graphics IRIX makefile
        makefile.sunos   =>  Sun makefile
        makefile.solaris =>  Solaris 2.X makefile
-                            (gcc, creates libpng.so.2.1.0.5q)
+                            (gcc, creates libpng.so.2.1.0.5s)
        makefile.linux   =>  Linux/ELF makefile
-                            (gcc, creates libpng.so.2.1.0.5q)
+                            (gcc, creates libpng.so.2.1.0.5s)
        makefile.gcmmx   =>  Linux/ELF makefile (gcc, creates
-                            libpng.so.2.1.0.5q, uses assembler code
+                            libpng.so.2.1.0.5s, uses assembler code
                             tuned for Intel MMX platform)
        makefile.sco     =>  For SCO OSr5  ELF and Unixware 7 with Native cc
        makefile.mips    =>  MIPS makefile
diff --git a/Y2KINFO b/Y2KINFO
index 1fb61c4..0b36bd5 100644
--- a/Y2KINFO
+++ b/Y2KINFO
@@ -1,13 +1,13 @@
    Y2K compliance in libpng:
    =========================
 
-      February 5, 2000
+      February 18, 2000
 
       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.5q are Y2K compliant.  It is my belief that earlier
+      upward through 1.0.5s 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/contrib/gregbook/readpng.c b/contrib/gregbook/readpng.c
index 6dd720f..546293f 100644
--- a/contrib/gregbook/readpng.c
+++ b/contrib/gregbook/readpng.c
@@ -89,7 +89,7 @@
     /* setjmp() must be called in every function that calls a PNG-reading
      * libpng function */
 
-    if (setjmp(png_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(png_ptr))) {
         png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
         return 2;
     }
@@ -130,7 +130,7 @@
     /* setjmp() must be called in every function that calls a PNG-reading
      * libpng function */
 
-    if (setjmp(png_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(png_ptr))) {
         png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
         return 2;
     }
@@ -184,7 +184,7 @@
     /* setjmp() must be called in every function that calls a PNG-reading
      * libpng function */
 
-    if (setjmp(png_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(png_ptr))) {
         png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
         return NULL;
     }
diff --git a/contrib/gregbook/readpng2.c b/contrib/gregbook/readpng2.c
index ee2d3d2..19d1f18 100644
--- a/contrib/gregbook/readpng2.c
+++ b/contrib/gregbook/readpng2.c
@@ -98,7 +98,7 @@
      * but compatible error handlers must either use longjmp() themselves
      * (as in this program) or exit immediately, so here we are: */
 
-    if (setjmp(mainprog_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(mainprog_ptr))) {
         png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
         return 2;
     }
@@ -136,7 +136,7 @@
     /* setjmp() must be called in every function that calls a PNG-reading
      * libpng function */
 
-    if (setjmp(mainprog_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(mainprog_ptr))) {
         png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
         mainprog_ptr->png_ptr = NULL;
         mainprog_ptr->info_ptr = NULL;
diff --git a/contrib/gregbook/writepng.c b/contrib/gregbook/writepng.c
index 44b7e9f..b94c677 100644
--- a/contrib/gregbook/writepng.c
+++ b/contrib/gregbook/writepng.c
@@ -82,7 +82,7 @@
      * but compatible error handlers must either use longjmp() themselves
      * (as in this program) or exit immediately, so here we go: */
 
-    if (setjmp(mainprog_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(mainprog_ptr))) {
         png_destroy_write_struct(&png_ptr, &info_ptr);
         return 2;
     }
@@ -239,7 +239,7 @@
     /* as always, setjmp() must be called in every function that calls a
      * PNG-writing libpng function */
 
-    if (setjmp(mainprog_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(mainprog_ptr))) {
         png_destroy_write_struct(&png_ptr, &info_ptr);
         mainprog_ptr->png_ptr = NULL;
         mainprog_ptr->info_ptr = NULL;
@@ -277,7 +277,7 @@
     /* as always, setjmp() must be called in every function that calls a
      * PNG-writing libpng function */
 
-    if (setjmp(mainprog_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(mainprog_ptr))) {
         png_destroy_write_struct(&png_ptr, &info_ptr);
         mainprog_ptr->png_ptr = NULL;
         mainprog_ptr->info_ptr = NULL;
@@ -307,7 +307,7 @@
     /* as always, setjmp() must be called in every function that calls a
      * PNG-writing libpng function */
 
-    if (setjmp(mainprog_ptr->jmpbuf)) {
+    if (setjmp(png_jmp_env(mainprog_ptr))) {
         png_destroy_write_struct(&png_ptr, &info_ptr);
         mainprog_ptr->png_ptr = NULL;
         mainprog_ptr->info_ptr = NULL;
diff --git a/contrib/pngminus/png2pnm.c b/contrib/pngminus/png2pnm.c
index a900ec2..2754d9a 100644
--- a/contrib/pngminus/png2pnm.c
+++ b/contrib/pngminus/png2pnm.c
@@ -223,7 +223,7 @@
     return FALSE;   /* out of memory */
   }
 
-  if (setjmp (png_ptr->jmpbuf))
+  if (setjmp (png_jmp_env(png_ptr)))
   {
     png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
     return FALSE;
diff --git a/contrib/pngminus/pnm2png.c b/contrib/pngminus/pnm2png.c
index 996f544..9329fcd 100644
--- a/contrib/pngminus/pnm2png.c
+++ b/contrib/pngminus/pnm2png.c
@@ -386,7 +386,7 @@
   }
 
   /* setjmp() must be called in every function that calls a PNG-reading libpng function */
-  if (setjmp (png_ptr->jmpbuf))
+  if (setjmp (png_jmp_env(png_ptr)))
   {
     png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
     return FALSE;
diff --git a/example.c b/example.c
index 691e5d1..4635bc8 100644
--- a/example.c
+++ b/example.c
@@ -111,7 +111,7 @@
     * the normal method of doing things with libpng).  REQUIRED unless you
     * set up your own error handlers in the png_create_read_struct() earlier.
     */
-   if (setjmp(png_ptr->jmpbuf))
+   if (setjmp(png_jmp_env(png_ptr)))
    {
       /* Free all of the memory associated with the png_ptr and info_ptr */
       png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
@@ -405,7 +405,7 @@
       return ERROR;
    }
 
-   if (setjmp((*png_ptr)->jmpbuf))
+   if (setjmp(png_jmp_env((*png_ptr))))
    {
       png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
       return ERROR;
@@ -433,7 +433,7 @@
 process_data(png_structp *png_ptr, png_infop *info_ptr,
    png_bytep buffer, png_uint_32 length)
 {
-   if (setjmp((*png_ptr)->jmpbuf))
+   if (setjmp(png_jmp_env((*png_ptr))))
    {
       /* Free the png_ptr and info_ptr memory on error */
       png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
@@ -515,6 +515,7 @@
    FILE *fp;
    png_structp png_ptr;
    png_infop info_ptr;
+   png_colorp palette;
 
    /* open the file */
    fp = fopen(file_name, "wb");
@@ -592,11 +593,9 @@
    palette = (png_colorp)png_malloc(png_ptr, 256 * sizeof (png_color));
    /* ... set palette colors ... */
    png_set_PLTE(png_ptr, info_ptr, palette, 256);
-   /* You can free the palette here if you like, since libpng has made its
-      own copy.  In versions of libpng earlier than version 1.0.5n, it was
-      necessary to keep the palette until after png_write_end(), because
-      libpng was using the caller's copy. */
-   free(palette);
+   /* You must not free palette here, because png_set_PLTE only makes a link to
+      the palette that you malloced.  Wait until you are about to destroy
+      the png structure. */
 
    /* optional significant bit chunk */
    /* if we are dealing with a grayscale image then */
@@ -699,10 +698,10 @@
     * use the first method if you aren't handling interlacing yourself.
     */
    png_uint_32 k, height, width;
-   png_byte image[height][width];
+   png_byte image[height][width*bytes_per_pixel];
    png_bytep row_pointers[height];
    for (k = 0; k < height; k++)
-     row_pointers[k] = image + k*width;
+     row_pointers[k] = image + k*width*bytes_per_pixel;
 
    /* One of the following output methods is REQUIRED */
 #ifdef entire /* write out the entire image data in one call */
@@ -737,11 +736,17 @@
    png_write_end(png_ptr, info_ptr);
 #endif hilevel
 
-   /* if you malloced a palette and have not already freed it, free it
-      here (do *not* free libpng's copy of the palette in info_ptr->palette,
-      as recommended in versions 1.0.5m and earlier of this example; libpng
-      now takes care of that automatically). */
-   free(palette);
+   /* If you png_malloced a palette, free it here (don't free info_ptr->palette,
+      as recommended in versions 1.0.5m and earlier of this example; if
+      libpng mallocs info_ptr->palette, libpng will free it).  If you
+      allocated it with malloc() instead of png_malloc(), use free() instead
+      of png_free(). */
+   png_free(png_ptr, palette);
+
+   /* Similarly, if you png_malloced any data that you passed in with
+      png_set_something(), such as a hist or trans array, free it here,
+      when you can be sure that libpng is through with it. */
+   png_free(png_ptr, trans);
 
    /* clean up after the write, and free any memory allocated */
    png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
diff --git a/libpng.3 b/libpng.3
index 6be60ed..8a2d29e 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "February 5, 2000"
+.TH LIBPNG 3 "February 18, 2000"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.0.5q
+libpng \- Portable Network Graphics (PNG) Reference Library 1.0.5s
 .SH SYNOPSIS
 \fI\fB
 
@@ -92,47 +92,7 @@
 
 \fI\fB
 
-\fBvoid png_free_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fI\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fI\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_spalettes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum_text\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum_text\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-
-\fI\fB
-
-\fBvoid png_free_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum_unknowns\fP\fB);\fP
+\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
 
 \fI\fB
 
@@ -262,6 +222,10 @@
 
 \fI\fB
 
+\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
 \fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
 
 \fI\fB
@@ -270,7 +234,7 @@
 
 \fI\fB
 
-\fBpng_uint_32 png_get_spalettes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fI*splt_ptr\fP\fB, int \fInum\fP\fB);\fP
+\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fI*splt_ptr\fP\fB, int \fInum\fP\fB);\fP
 
 \fI\fB
 
@@ -578,6 +542,10 @@
 
 \fI\fB
 
+\fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP
+
+\fI\fB
+
 \fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP
 
 \fI\fB
@@ -594,7 +562,7 @@
 
 \fI\fB
 
-\fBvoid png_set_spalettes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP
+\fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP
 
 \fI\fB
 
@@ -741,7 +709,7 @@
 .SH LIBPNG.TXT
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.0.5q - February 5, 2000
+ libpng version 1.0.5s - February 18, 2000
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alum.rpi.edu>
  Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -931,17 +899,18 @@
 
 When libpng encounters an error, it expects to longjmp back
 to your routine.  Therefore, you will need to call setjmp and pass
-your png_ptr->jmpbuf.  If you read the file from different
+your png_jmp_env(png_ptr).  If you read the file from different
 routines, you will need to update the jmpbuf field every time you enter
 a new routine that will call a png_ function.
 
 See your documentation of setjmp/longjmp for your compiler for more
-handling in the Customizing Libpng section below for more information on
-the libpng error handling.  If an error occurs, and libpng longjmp's
+information on setjmp/longjmp.  See the discussion on libpng error
+handling in the Customizing Libpng section below for more information
+on the libpng error handling.  If an error occurs, and libpng longjmp's
 back to your setjmp, you will want to call png_destroy_read_struct() to
 free any memory.
 
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_read_struct(&png_ptr, &info_ptr,
            &end_info);
@@ -1289,7 +1258,9 @@
                      valid 16-bit red, green and blue
                      values, regardless of color_type
 
-    num_text = png_get_text(png_ptr, info_ptr, &text_ptr);
+    num_comments   = png_get_text(png_ptr, info_ptr,
+                     &text_ptr, &num_text);
+    num_comments   - number of comments
     text_ptr       - array of png_text holding image
                      comments
     text_ptr[i]->compression - type of compression used
@@ -1307,7 +1278,8 @@
     text_ptr[i]->lang  - language of comment (NULL for unknown).
     text_ptr[i]->translated_keyword  - keyword in UTF-8 (NULL
                          for unknown).
-    num_text       - number of comments
+    num_text       - number of comments (same as num_comments;
+                     you can put NULL here to avoid the duplication)
     num_spalettes = png_get_spalettes(png_ptr, info_ptr, &palette_ptr);
     palette_ptr    - array of png_spalette structures holding contents
                      of one or more sPLT chunks read.
@@ -1850,32 +1822,26 @@
        &end_info);
 
 It is also possible to individually free the info_ptr members that
-point to allocated storage with the following functions:
+point to libpng-allocated storage with the following functions:
 
-    png_free_text(png_ptr, info_ptr, num)
-    num          - number of text item to be freed (-1 for all items)
-
-    png_free_hIST(png_ptr, info_ptr)
-
-    png_free_iCCP(png_ptr, info_ptr)
-
-    png_free_pCAL(png_ptr, info_ptr)
-
-    png_free_sCAL(png_ptr, info_ptr)
-
-    png_free_spalettes(png_ptr, info_ptr, num)
-    num          - number of suggested-paletted entry to be freed
-                   (-1 for all suggested palettes)
-
-    png_free_pixels(png_ptr, info_ptr)
-
-    png_free_unknown_chunk(png_ptr, info_ptr, num)
-    num          - number of unknown chunk to be freed
-                   (-1 for all suggested palettes)
+    png_free_data(png_ptr, info_ptr, mask, n)
+    mask         - identifies data to be freed, a mask
+                   made up by the OR one or more of
+                   PNG_FREE_PLTE, PNG_FREE_TRNS,
+                   PNG_FREE_HIST, PNG_FREE_ICCP,
+                   PNG_FREE_SPLT, PNG_FREE_ROWS,
+                   PNG_FREE_PCAL, PNG_FREE_SCAL,
+                   PNG_FREE_TEXT, PNG_FREE_UNKN,
+                   or simply PNG_FREE_ALL
+    n            - sequence number of item to be freed
+                   (-1 for all items)
 
 These functions may be safely called when the relevant storage has
 already been freed, or has not yet been allocated, and will in that
-case do nothing.
+case do nothing.  The "n" parameter is ignored if only one item
+of the selected data type, such as PLTE, is allowed.  If "n" is not
+-1, and multiple items are allowed for the data type identified in
+the mask, such as text or splt, only the n'th item is freed.
 
 For a more compact example of reading a PNG image, see the file example.c.
 
@@ -1914,7 +1880,7 @@
         return -1;
     }
 
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_read_struct(&png_ptr, &info_ptr,
            (png_infopp)NULL);
@@ -1948,7 +1914,7 @@
  int
  process_data(png_bytep buffer, png_uint_32 length)
  {
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_read_struct(&png_ptr, &info_ptr,
            (png_infopp)NULL);
@@ -2103,15 +2069,15 @@
 After you have these structures, you will need to set up the
 error handling.  When libpng encounters an error, it expects to
 longjmp() back to your routine.  Therefore, you will need to call
-setjmp() and pass the png_ptr->jmpbuf.  If you
+setjmp() and pass the png_jmp_env(png_ptr).  If you
 write the file from different routines, you will need to update
-the jmpbuf field every time you enter a new routine that will
+the png_jmp_env(png_ptr) every time you enter a new routine that will
 call a png_ function.  See your documentation of setjmp/longjmp
 for your compiler for more information on setjmp/longjmp.  See
 the discussion on libpng error handling in the Customizing Libpng
 section below for more information on the libpng error handling.
 
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_write_struct(&png_ptr, &info_ptr);
         fclose(fp);
@@ -2172,7 +2138,7 @@
        PNG_FILTER_NONE | PNG_FILTER_SUB |
        PNG_FILTER_PAETH);
 
-The png_set_compression_???() functions interface to the zlib compression
+The png_set_compression_*() functions interface to the zlib compression
 library, and should mostly be ignored unless you really know what you are
 doing.  The only generally useful call is png_set_compression_level()
 which changes how much time zlib spends on trying to compress the image
@@ -2476,7 +2442,7 @@
 write interface, or through a sequence of low-level write operations.
 You can use the high-level interface if your image data is present
 on the rowpointers member of the info structure.  All defined output
-transformations are pernmitted, enabled by the following masks.
+transformations are permitted, enabled by the following masks.
 
     PNG_TRANSFORM_IDENTITY      No transformation
     PNG_TRANSFORM_PACKING       Pack 1, 2 and 4-bit samples
@@ -2496,7 +2462,7 @@
 where png_transforms is an integer containing the logical-or of some set of
 transformation flags.  This call is equivalent to png_write_info(),
 followed by the set of transformations indicated by the transform
-mask, followed by followed by a write of the image bytes to the info
+mask, followed by followed by a write of the image bytes from the info
 member `rowpointers', followed by png_write_end().
 
 (The final parameter of this call is not yet used.  Someday it
@@ -2746,7 +2712,7 @@
     png_destroy_write_struct(&png_ptr, &info_ptr);
 
 It is also possible to individually free the info_ptr members that
-point to allocated storage with the following functions:
+point to libpng-allocated storage with the following functions:
 
     png_free_text(png_ptr, info_ptr, num)
     num          - number of text item to be freed (-1 for all items)
@@ -2759,7 +2725,7 @@
 
     png_free_sCAL(png_ptr, info_ptr)
 
-    png_free_spalettes(png_ptr, info_ptr, num)
+    png_free_sPLT(png_ptr, info_ptr, num)
     num          - number of suggested-paletted entry to be freed
                    (-1 for all suggested palettes)
 
@@ -2773,7 +2739,9 @@
 already been freed, or has not yet been allocated, and will in that
 case do nothing.
 
-If you allocated palette data, you must free it before the call to png_destroy_write_struct();
+If you allocated data such as a palette that you passed in to libpng with
+png_set_*, you must not free it until just before the call to
+png_destroy_write_struct().
 
 For a more compact example of writing a PNG image, see the file example.c.
 
@@ -2787,7 +2755,7 @@
 All of the memory allocation, input/output, and error handling in libpng
 goes through callbacks that are user settable.  The default routines are
 in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively.  To change
-these functions, call the appropriate png_set_???_fn() function.
+these functions, call the appropriate png_set_*_fn() function.
 
 Memory allocation is done through the functions png_large_malloc(),
 png_malloc(), png_realloc(), png_large_free(), and png_free().  These
@@ -2844,7 +2812,7 @@
 you wish to change the behavior of the error functions, you will need to
 set up your own message callbacks.  These functions are normally supplied
 at the time that the png_struct is created.  It is also possible to change
-these functions after png_create_???_struct() has been called by calling:
+these functions after png_create_*_struct() has been called by calling:
 
     png_set_error_fn(png_structp png_ptr,
         png_voidp error_ptr, png_error_ptr error_fn,
@@ -2926,7 +2894,7 @@
 
 You will need to write new error and warning functions that use the GUI
 interface, as described previously, and set them to be the error and
-warning functions at the time that png_create_???_struct() is called,
+warning functions at the time that png_create_*_struct() is called,
 in order to have them available during the structure initialization.
 They can be changed later via png_set_error_fn().  On some compilers,
 you may also have to change the memory allocators (png_malloc, etc.).
@@ -3147,13 +3115,13 @@
 
 .SH VII. Y2K Compliance in libpng
 
-February 5, 2000
+February 18, 2000
 
 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.5q are Y2K compliant.  It is my belief that earlier
+upward through 1.0.5s 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
@@ -3279,7 +3247,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.0.5q - February 5, 2000:
+Libpng version 1.0.5s - February 18, 2000:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (randeg@alum.rpi.edu).
 
@@ -3294,7 +3262,7 @@
 Copyright (c) 1996, 1997 Andreas Dilger
 (libpng versions 0.90, December 1996, through 0.96, May 1997)
 Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
-(libpng versions 0.97, January 1998, through 1.0.5q, February 5, 2000)
+(libpng versions 0.97, January 1998, through 1.0.5s, February 18, 2000)
 
 For the purposes of this copyright and license, "Contributing Authors"
 is defined as the following set of individuals:
diff --git a/libpng.txt b/libpng.txt
index d688eac..4be1dc0 100644
--- a/libpng.txt
+++ b/libpng.txt
@@ -1,6 +1,6 @@
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.0.5q - February 5, 2000
+ libpng version 1.0.5s - February 18, 2000
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alum.rpi.edu>
  Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -190,17 +190,18 @@
 
 When libpng encounters an error, it expects to longjmp back
 to your routine.  Therefore, you will need to call setjmp and pass
-your png_ptr->jmpbuf.  If you read the file from different
+your png_jmp_env(png_ptr).  If you read the file from different
 routines, you will need to update the jmpbuf field every time you enter
 a new routine that will call a png_ function.
 
 See your documentation of setjmp/longjmp for your compiler for more
-handling in the Customizing Libpng section below for more information on
-the libpng error handling.  If an error occurs, and libpng longjmp's
+information on setjmp/longjmp.  See the discussion on libpng error
+handling in the Customizing Libpng section below for more information
+on the libpng error handling.  If an error occurs, and libpng longjmp's
 back to your setjmp, you will want to call png_destroy_read_struct() to
 free any memory.
 
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_read_struct(&png_ptr, &info_ptr,
            &end_info);
@@ -548,7 +549,9 @@
                      valid 16-bit red, green and blue
                      values, regardless of color_type
 
-    num_text = png_get_text(png_ptr, info_ptr, &text_ptr);
+    num_comments   = png_get_text(png_ptr, info_ptr,
+                     &text_ptr, &num_text);
+    num_comments   - number of comments
     text_ptr       - array of png_text holding image
                      comments
     text_ptr[i]->compression - type of compression used
@@ -566,7 +569,8 @@
     text_ptr[i]->lang  - language of comment (NULL for unknown).
     text_ptr[i]->translated_keyword  - keyword in UTF-8 (NULL
                          for unknown).
-    num_text       - number of comments
+    num_text       - number of comments (same as num_comments;
+                     you can put NULL here to avoid the duplication)
     num_spalettes = png_get_spalettes(png_ptr, info_ptr, &palette_ptr);
     palette_ptr    - array of png_spalette structures holding contents
                      of one or more sPLT chunks read.
@@ -1109,32 +1113,26 @@
        &end_info);
 
 It is also possible to individually free the info_ptr members that
-point to allocated storage with the following functions:
+point to libpng-allocated storage with the following functions:
 
-    png_free_text(png_ptr, info_ptr, num)
-    num          - number of text item to be freed (-1 for all items)
-
-    png_free_hIST(png_ptr, info_ptr)
-
-    png_free_iCCP(png_ptr, info_ptr)
-
-    png_free_pCAL(png_ptr, info_ptr)
-
-    png_free_sCAL(png_ptr, info_ptr)
-
-    png_free_spalettes(png_ptr, info_ptr, num)
-    num          - number of suggested-paletted entry to be freed
-                   (-1 for all suggested palettes)
-
-    png_free_pixels(png_ptr, info_ptr)
-
-    png_free_unknown_chunk(png_ptr, info_ptr, num)
-    num          - number of unknown chunk to be freed
-                   (-1 for all suggested palettes)
+    png_free_data(png_ptr, info_ptr, mask, n)
+    mask         - identifies data to be freed, a mask
+                   made up by the OR one or more of
+                   PNG_FREE_PLTE, PNG_FREE_TRNS,
+                   PNG_FREE_HIST, PNG_FREE_ICCP,
+                   PNG_FREE_SPLT, PNG_FREE_ROWS,
+                   PNG_FREE_PCAL, PNG_FREE_SCAL,
+                   PNG_FREE_TEXT, PNG_FREE_UNKN,
+                   or simply PNG_FREE_ALL
+    n            - sequence number of item to be freed
+                   (-1 for all items)
 
 These functions may be safely called when the relevant storage has
 already been freed, or has not yet been allocated, and will in that
-case do nothing.
+case do nothing.  The "n" parameter is ignored if only one item
+of the selected data type, such as PLTE, is allowed.  If "n" is not
+-1, and multiple items are allowed for the data type identified in
+the mask, such as text or splt, only the n'th item is freed.
 
 For a more compact example of reading a PNG image, see the file example.c.
 
@@ -1173,7 +1171,7 @@
         return -1;
     }
 
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_read_struct(&png_ptr, &info_ptr,
            (png_infopp)NULL);
@@ -1207,7 +1205,7 @@
  int
  process_data(png_bytep buffer, png_uint_32 length)
  {
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_read_struct(&png_ptr, &info_ptr,
            (png_infopp)NULL);
@@ -1362,15 +1360,15 @@
 After you have these structures, you will need to set up the
 error handling.  When libpng encounters an error, it expects to
 longjmp() back to your routine.  Therefore, you will need to call
-setjmp() and pass the png_ptr->jmpbuf.  If you
+setjmp() and pass the png_jmp_env(png_ptr).  If you
 write the file from different routines, you will need to update
-the jmpbuf field every time you enter a new routine that will
+the png_jmp_env(png_ptr) every time you enter a new routine that will
 call a png_ function.  See your documentation of setjmp/longjmp
 for your compiler for more information on setjmp/longjmp.  See
 the discussion on libpng error handling in the Customizing Libpng
 section below for more information on the libpng error handling.
 
-    if (setjmp(png_ptr->jmpbuf))
+    if (setjmp(png_jmp_env(png_ptr)))
     {
         png_destroy_write_struct(&png_ptr, &info_ptr);
         fclose(fp);
@@ -1431,7 +1429,7 @@
        PNG_FILTER_NONE | PNG_FILTER_SUB |
        PNG_FILTER_PAETH);
 
-The png_set_compression_???() functions interface to the zlib compression
+The png_set_compression_*() functions interface to the zlib compression
 library, and should mostly be ignored unless you really know what you are
 doing.  The only generally useful call is png_set_compression_level()
 which changes how much time zlib spends on trying to compress the image
@@ -1735,7 +1733,7 @@
 write interface, or through a sequence of low-level write operations.
 You can use the high-level interface if your image data is present
 on the rowpointers member of the info structure.  All defined output
-transformations are pernmitted, enabled by the following masks.
+transformations are permitted, enabled by the following masks.
 
     PNG_TRANSFORM_IDENTITY      No transformation
     PNG_TRANSFORM_PACKING       Pack 1, 2 and 4-bit samples
@@ -1755,7 +1753,7 @@
 where png_transforms is an integer containing the logical-or of some set of
 transformation flags.  This call is equivalent to png_write_info(),
 followed by the set of transformations indicated by the transform
-mask, followed by followed by a write of the image bytes to the info
+mask, followed by followed by a write of the image bytes from the info
 member `rowpointers', followed by png_write_end().
 
 (The final parameter of this call is not yet used.  Someday it
@@ -2005,7 +2003,7 @@
     png_destroy_write_struct(&png_ptr, &info_ptr);
 
 It is also possible to individually free the info_ptr members that
-point to allocated storage with the following functions:
+point to libpng-allocated storage with the following functions:
 
     png_free_text(png_ptr, info_ptr, num)
     num          - number of text item to be freed (-1 for all items)
@@ -2018,7 +2016,7 @@
 
     png_free_sCAL(png_ptr, info_ptr)
 
-    png_free_spalettes(png_ptr, info_ptr, num)
+    png_free_sPLT(png_ptr, info_ptr, num)
     num          - number of suggested-paletted entry to be freed
                    (-1 for all suggested palettes)
 
@@ -2032,7 +2030,9 @@
 already been freed, or has not yet been allocated, and will in that
 case do nothing.
 
-If you allocated palette data, you must free it before the call to png_destroy_write_struct();
+If you allocated data such as a palette that you passed in to libpng with
+png_set_*, you must not free it until just before the call to
+png_destroy_write_struct().
 
 For a more compact example of writing a PNG image, see the file example.c.
 
@@ -2046,7 +2046,7 @@
 All of the memory allocation, input/output, and error handling in libpng
 goes through callbacks that are user settable.  The default routines are
 in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively.  To change
-these functions, call the appropriate png_set_???_fn() function.
+these functions, call the appropriate png_set_*_fn() function.
 
 Memory allocation is done through the functions png_large_malloc(),
 png_malloc(), png_realloc(), png_large_free(), and png_free().  These
@@ -2103,7 +2103,7 @@
 you wish to change the behavior of the error functions, you will need to
 set up your own message callbacks.  These functions are normally supplied
 at the time that the png_struct is created.  It is also possible to change
-these functions after png_create_???_struct() has been called by calling:
+these functions after png_create_*_struct() has been called by calling:
 
     png_set_error_fn(png_structp png_ptr,
         png_voidp error_ptr, png_error_ptr error_fn,
@@ -2185,7 +2185,7 @@
 
 You will need to write new error and warning functions that use the GUI
 interface, as described previously, and set them to be the error and
-warning functions at the time that png_create_???_struct() is called,
+warning functions at the time that png_create_*_struct() is called,
 in order to have them available during the structure initialization.
 They can be changed later via png_set_error_fn().  On some compilers,
 you may also have to change the memory allocators (png_malloc, etc.).
@@ -2406,13 +2406,13 @@
 
 VII. Y2K Compliance in libpng
 
-February 5, 2000
+February 18, 2000
 
 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.5q are Y2K compliant.  It is my belief that earlier
+upward through 1.0.5s are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has three year fields.  One is a 2-byte unsigned integer that
diff --git a/libpngpf.3 b/libpngpf.3
index f1ed3c1..c7dd883 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 February 5, 2000
+.TH LIBPNGPF 3 February 18, 2000
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.0.5q
+libpng \- Portable Network Graphics (PNG) Reference Library 1.0.5s
 (private functions)
 .SH SYNOPSIS
 \fB#include <png.h>\fP
diff --git a/png.5 b/png.5
index 0932db8..38782c5 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "February 5, 2000"
+.TH PNG 5 "February 18, 2000"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index f062252..77e7eaa 100644
--- a/png.c
+++ b/png.c
@@ -1,7 +1,7 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * libpng version 1.0.5q - February 5, 2000
+ * libpng version 1.0.5s - February 18, 2000
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
  * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -19,7 +19,7 @@
 
 #ifdef PNG_USE_GLOBAL_ARRAYS
 /* png_libpng_ver was changed to a function in version 1.0.5c */
-char png_libpng_ver[12] = "1.0.5q";
+char png_libpng_ver[12] = "1.0.5s";
 
 /* png_sig was changed to a function in version 1.0.5c */
 /* Place to hold the signature string for a PNG file. */
@@ -62,10 +62,10 @@
 /* offset to next interlace block in the y direction */
 int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
 
-/* Width of interlace block.  This is not currently used - if you need
- * it, uncomment it here and in png.h
+/* width of interlace block (used in assembler routines only) */
+#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
 int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
-*/
+#endif
 
 /* Height of interlace block.  This is not currently used - if you need
  * it, uncomment it here and in png.h
@@ -259,13 +259,16 @@
    png_memset(info_ptr, 0, sizeof (png_info));
 }
 
-#if defined(PNG_TEXT_SUPPORTED)
-/* free text item num or (if num == -1) all text items */
 void
-png_free_text(png_structp png_ptr, png_infop info_ptr, int num)
+png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num)
 {
    if (png_ptr == NULL || info_ptr == NULL)
       return;
+
+#if defined(PNG_TEXT_SUPPORTED)
+/* free text item num or (if num == -1) all text items */
+if (mask & PNG_FREE_TEXT)
+{
    if (num != -1)
    {
      if (info_ptr->text[num].key)
@@ -277,13 +280,10 @@
    else if (info_ptr->text != NULL)
    {
      int i;
-     if(info_ptr->text != NULL)
-     {
-       for (i = 0; i < info_ptr->num_text; i++)
-           png_free_text(png_ptr, info_ptr, i);
-       png_free(png_ptr, info_ptr->text);
-       info_ptr->text = NULL;
-     }
+     for (i = 0; i < info_ptr->num_text; i++)
+         png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
+     png_free(png_ptr, info_ptr->text);
+     info_ptr->text = NULL;
      info_ptr->num_text=0;
    }
 }
@@ -291,14 +291,12 @@
 
 #if defined(PNG_tRNS_SUPPORTED)
 /* free any tRNS entry */
-void
-png_free_tRNS(png_structp png_ptr, png_infop info_ptr)
+if (mask & PNG_FREE_TRNS)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (info_ptr->valid & PNG_INFO_tRNS)
    {
-       png_free(png_ptr, info_ptr->trans);
+       if (info_ptr->free_me & PNG_FREE_TRNS)
+         png_free(png_ptr, info_ptr->trans);
        info_ptr->valid &= ~PNG_INFO_tRNS;
    }
 }
@@ -306,19 +304,13 @@
 
 #if defined(PNG_sCAL_SUPPORTED)
 /* free any sCAL entry */
-void
-png_free_sCAL(png_structp png_ptr, png_infop info_ptr)
+if (mask & PNG_FREE_SCAL)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (info_ptr->valid & PNG_INFO_sCAL)
    {
 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
        png_free(png_ptr, info_ptr->scal_s_width);
        png_free(png_ptr, info_ptr->scal_s_height);
-#else
-       if(png_ptr != NULL)
-          /* silence a compiler warning */ ;
 #endif
           info_ptr->valid &= ~PNG_INFO_sCAL;
    }
@@ -327,11 +319,8 @@
 
 #if defined(PNG_pCAL_SUPPORTED)
 /* free any pCAL entry */
-void
-png_free_pCAL(png_structp png_ptr, png_infop info_ptr)
+if (mask & PNG_FREE_PCAL)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (info_ptr->valid & PNG_INFO_pCAL)
    {
        png_free(png_ptr, info_ptr->pcal_purpose);
@@ -352,15 +341,15 @@
 
 #if defined(PNG_iCCP_SUPPORTED)
 /* free any iCCP entry */
-void
-png_free_iCCP(png_structp png_ptr, png_infop info_ptr)
+if (mask & PNG_FREE_ICCP)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (info_ptr->valid & PNG_INFO_iCCP)
    {
-       png_free(png_ptr, info_ptr->iccp_name);
-       png_free(png_ptr, info_ptr->iccp_profile);
+       if (info_ptr->free_me & PNG_FREE_ICCP)
+       {
+         png_free(png_ptr, info_ptr->iccp_name);
+         png_free(png_ptr, info_ptr->iccp_profile);
+       }
        info_ptr->valid &= ~PNG_INFO_iCCP;
    }
 }
@@ -368,11 +357,8 @@
 
 #if defined(PNG_sPLT_SUPPORTED)
 /* free a given sPLT entry, or (if num == -1) all sPLT entries */
-void
-png_free_spalettes(png_structp png_ptr, png_infop info_ptr, int num)
+if (mask & PNG_FREE_SPLT)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (num != -1)
    {
        png_free(png_ptr, info_ptr->splt_palettes[num].name);
@@ -381,26 +367,22 @@
    }
    else
    {
-       int i;
+       if(info_ptr->splt_palettes_num)
+       {
+         int i;
+         for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
+            png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
 
-       if(info_ptr->splt_palettes_num == 0)
-          return;
-
-       for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
-          png_free_spalettes(png_ptr, info_ptr, i);
-
-       png_free(png_ptr, info_ptr->splt_palettes);
-       info_ptr->splt_palettes_num = 0;
+         png_free(png_ptr, info_ptr->splt_palettes);
+         info_ptr->splt_palettes_num = 0;
+       }
    }
 }
 #endif
 
 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
-void
-png_free_unknown_chunks(png_structp png_ptr, png_infop info_ptr, int num)
+if (mask & PNG_FREE_UNKN)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (num != -1)
    {
        png_free(png_ptr, info_ptr->unknown_chunks[num].data);
@@ -410,77 +392,60 @@
    {
        int i;
 
-       if(info_ptr->unknown_chunks_num == 0)
-          return;
+       if(info_ptr->unknown_chunks_num)
+       {
+         for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
+            png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
 
-       for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
-          png_free_unknown_chunks(png_ptr, info_ptr, i);
-
-       png_free(png_ptr, info_ptr->unknown_chunks);
-       info_ptr->unknown_chunks_num = 0;
-   }
-}
-void
-png_free_chunk_list(png_structp png_ptr)
-{
-   if (png_ptr == NULL)
-       return;
-   if (png_ptr->num_chunk_list)
-   {
-       png_free(png_ptr, png_ptr->chunk_list);
-       png_ptr->num_chunk_list=0;
+         png_free(png_ptr, info_ptr->unknown_chunks);
+         info_ptr->unknown_chunks_num = 0;
+       }
    }
 }
 #endif
 
 #if defined(PNG_hIST_SUPPORTED)
 /* free any hIST entry */
-void
-png_free_hIST(png_structp png_ptr, png_infop info_ptr)
+if (mask & PNG_FREE_HIST)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (info_ptr->valid & PNG_INFO_hIST)
    {
-       png_free(png_ptr, info_ptr->hist);
+       if (info_ptr->free_me & PNG_FREE_HIST)
+         png_free(png_ptr, info_ptr->hist);
        info_ptr->valid &= ~PNG_INFO_hIST;
    }
 }
 #endif
 
 /* free any PLTE entry that was internally allocated */
-void
-png_free_PLTE(png_structp png_ptr, png_infop info_ptr)
+if (mask & PNG_FREE_PLTE)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
    if (info_ptr->valid & PNG_INFO_PLTE)
    {
-       if (info_ptr->valid & PNG_ALLOCATED_INFO_PLTE)
+       if (info_ptr->free_me & PNG_FREE_PLTE)
           png_zfree(png_ptr, info_ptr->palette);
-       info_ptr->valid &= ~(PNG_INFO_PLTE|PNG_ALLOCATED_INFO_PLTE);
+       info_ptr->valid &= ~(PNG_INFO_PLTE);
        info_ptr->num_palette = 0;
    }
 }
 
 #if defined(PNG_INFO_IMAGE_SUPPORTED)
 /* free any image bits attached to the info structure */
-void
-png_free_pixels(png_structp png_ptr, png_infop info_ptr)
+if (mask & PNG_FREE_ROWS)
 {
-   if (png_ptr == NULL || info_ptr == NULL)
-       return;
-   if (info_ptr->valid & PNG_INFO_IDAT)
+   if (info_ptr->free_me & PNG_FREE_ROWS)
    {
        int row;
 
        for (row = 0; row < (int)info_ptr->height; row++)
           png_free(png_ptr, info_ptr->row_pointers[row]);
        png_free(png_ptr, info_ptr->row_pointers);
-       info_ptr->valid &= ~PNG_INFO_IDAT;
    }
 }
 #endif
+   if(num == -1)
+     info_ptr->free_me &= ~mask;
+}
 
 /* This is an internal routine to free any memory that the info struct is
  * pointing to before re-using it or freeing the struct itself.  Recall
@@ -490,35 +455,17 @@
 png_info_destroy(png_structp png_ptr, png_infop info_ptr)
 {
    png_debug(1, "in png_info_destroy\n");
-#if defined(PNG_READ_TEXT_SUPPORTED)
-   png_free_text(png_ptr, info_ptr, -1);
-#endif
-#if defined(PNG_READ_tRNS_SUPPORTED)
-   png_free_tRNS(png_ptr, info_ptr);
-#endif
-#if defined(PNG_READ_sCAL_SUPPORTED)
-   png_free_sCAL(png_ptr, info_ptr);
-#endif
-#if defined(PNG_READ_pCAL_SUPPORTED)
-   png_free_pCAL(png_ptr, info_ptr);
-#endif
-#if defined(PNG_READ_iCCP_SUPPORTED)
-   png_free_iCCP(png_ptr, info_ptr);
-#endif
-#if defined(PNG_READ_sPLT_SUPPORTED)
-   png_free_spalettes(png_ptr, info_ptr, -1);
-#endif
+
+   png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
+    
 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
-   png_free_unknown_chunks(png_ptr, info_ptr, -1);
-   png_free_chunk_list(png_ptr);
+   if (png_ptr->num_chunk_list)
+   {
+       png_free(png_ptr, png_ptr->chunk_list);
+       png_ptr->num_chunk_list=0;
+   }
 #endif
-#if defined(PNG_hIST_SUPPORTED)
-   png_free_hIST(png_ptr, info_ptr);
-#endif
-   png_free_PLTE(png_ptr, info_ptr);
-#if defined(PNG_INFO_IMAGE_SUPPORTED)
-   png_free_pixels(png_ptr, info_ptr);
-#endif
+
    png_info_init(info_ptr);
 }
 
@@ -596,7 +543,7 @@
 png_get_copyright(png_structp png_ptr)
 {
    if (png_ptr != NULL || png_ptr == NULL)  /* silence compiler warning */
-   return ("\n libpng version 1.0.5q - February 5, 2000\n\
+   return ("\n libpng version 1.0.5s - February 18, 2000\n\
    Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
    Copyright (c) 1996, 1997 Andreas Dilger\n\
    Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n");
@@ -614,8 +561,8 @@
 {
    /* Version of *.c files used when building libpng */
    if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
-      return("1.0.5q");
-   return("1.0.5q");
+      return("1.0.5s");
+   return("1.0.5s");
 }
 
 png_charp
@@ -639,9 +586,9 @@
 /* Generate a compiler error if there is an old png.h in the search path. */
 void
 png_check_version
-   (version_1_0_5q png_h_is_not_version_1_0_5q)
+   (version_1_0_5s png_h_is_not_version_1_0_5s)
 {
-   if(png_h_is_not_version_1_0_5q == NULL)
+   if(png_h_is_not_version_1_0_5s == NULL)
      return;
 }
 
diff --git a/png.h b/png.h
index a6d58ba..2c969e2 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.0.5q - February 5, 2000
+ * libpng version 1.0.5s - February 18, 2000
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
  * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
@@ -9,19 +9,19 @@
  * Authors and maintainers:
  *  libpng versions 0.71, May 1995, through 0.89c, May 1996: Guy Schalnat
  *  libpng versions 0.90, December 1996, through 0.96, May 1997: Andreas Dilger
- *  libpng versions 0.97, January 1998, through 1.0.5q - February 5, 2000: Glenn
+ *  libpng versions 0.97, January 1998, through 1.0.5s - February 18, 2000: Glenn
  *  See also "Contributing Authors", below.
  *
  * Y2K compliance in libpng:
  * =========================
  *
- *    February 5, 2000
+ *    February 18, 2000
  *
  *    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.5q are Y2K compliant.  It is my belief that earlier
+ *    upward through 1.0.5s 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
@@ -98,8 +98,9 @@
  *    1.0.4a-f                 1.0.4a-f 10005  2.1.0.4a-f
  *    1.0.5                    1.0.5    10005  2.1.0.5
  *    1.0.5a-d                 1.0.5a-d 10006  2.1.0.5a-d
- *    1.0.5e-p                 1.0.5e-p 10100  2.1.0.5e-p
- *    1.1.0                    1.1.0    10100  3.1.1.0
+ *    1.0.5e-r                 1.0.5e-r 10100  2.1.0.5e-r (not compatible)
+ *    1.0.5s                   1.0.5s   10006  2.1.0.5s   (compatible)
+ *    1.3.0                    1.3.0    10300  3.1.3.0
  *
  *    Henceforth the source version will match the shared-library minor
  *    and patch numbers; the shared-library major version number will be
@@ -123,7 +124,7 @@
  * Copyright (c) 1996, 1997 Andreas Dilger
  * (libpng versions 0.90, December 1996, through 0.96, May 1997)
  * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
- * (libpng versions 0.97, January 1998, through 1.0.5q, February 5, 2000)
+ * (libpng versions 0.97, January 1998, through 1.0.5s, February 18, 2000)
  *
  * For the purposes of this copyright and license, "Contributing Authors"
  * is defined as the following set of individuals:
@@ -212,6 +213,11 @@
 /* include all user configurable info */
 #include "pngconf.h"
 
+/* macros for optional assembler routines */
+#if defined(PNG_INTERNAL) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
+#  include "pngasmrd.h"
+#endif
+
 /* Inhibit C++ name-mangling for libpng functions but not for system calls. */
 #ifdef __cplusplus
 extern "C" {
@@ -224,14 +230,14 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.0.5q"
+#define PNG_LIBPNG_VER_STRING "1.0.5s"
 
 /* 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=bugfix */
-#define PNG_LIBPNG_VER    10100  /* 1.1.0 */
+#define PNG_LIBPNG_VER    10006  /* 1.0.6 */
 
 /* Note to maintainer: update this number in scripts/pngdef.pas as well */
 
@@ -255,9 +261,11 @@
 PNG_EXPORT_VAR (int FARDATA) png_pass_yinc[7];
 PNG_EXPORT_VAR (int FARDATA) png_pass_mask[7];
 PNG_EXPORT_VAR (int FARDATA) png_pass_dsp_mask[7];
-/* These aren't currently used.  If you need them, see png.c for more details
-PNG_EXPORT_VAR (int FARDATA) png_pass_width[7];
-PNG_EXPORT_VAR (int FARDATA) png_pass_height[7];
+#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
+extern int FARDATA png_pass_width[7];   /* now used in pngvcrd.c, pnggccrd.c */
+#endif
+/* This isn't currently used.  If you need it, see png.c for more details.
+extern int FARDATA png_pass_height[7];
 */
 #endif
 
@@ -446,7 +454,7 @@
    png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
 
    /* The following is informational only on read, and not used on writes. */
-   png_byte channels;       /* number of data channels per pixel (1, 3, 4)*/
+   png_byte channels;       /* number of data channels per pixel (1, 2, 3, 4)*/
    png_byte pixel_depth;    /* number of bits per pixel */
    png_byte spare_byte;     /* to align the data, and for future use */
    png_byte signature[8];   /* magic bytes read by libpng from start of file */
@@ -457,6 +465,8 @@
     * and initialize the appropriate fields below.
     */
 
+   png_uint_32 free_me;     /* flags items libpng is responsible for freeing */
+
 #if defined(PNG_gAMA_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
    /* The gAMA chunk describes the gamma characteristics of the system
     * on which the image was created, normally in the range [1.0, 2.5].
@@ -656,6 +666,7 @@
 #endif
 
 #if defined(PNG_INFO_IMAGE_SUPPORTED)
+   /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
    /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
    png_bytepp row_pointers;        /* the image bits */
 #endif
@@ -747,8 +758,7 @@
 #define PNG_INFO_iCCP 0x1000   /* ESR, 1.0.6 */
 #define PNG_INFO_sPLT 0x2000   /* ESR, 1.0.6 */
 #define PNG_INFO_sCAL 0x4000   /* ESR, 1.0.6 */
-#define PNG_INFO_IDAT 0x8000   /* ESR, 1.0.6 */
-#define PNG_ALLOCATED_INFO_PLTE  0x10000L  /* GR-P, 1.0.6 */
+#define PNG_INFO_IDAT 0x8000L  /* ESR, 1.0.6 */
 
 /* This is used for the transformation routines, as some of them
  * change these values for the row.  It also should enable using
@@ -803,19 +813,19 @@
 #endif
 
 /* Transform masks for the high-level interface */
-#define PNG_TRANSFORM_IDENTITY        0x0000    /* read and write */
-#define PNG_TRANSFORM_STRIP_16        0x0001  /* read only */
+#define PNG_TRANSFORM_IDENTITY       0x0000    /* read and write */
+#define PNG_TRANSFORM_STRIP_16       0x0001    /* read only */
 #define PNG_TRANSFORM_STRIP_ALPHA    0x0002    /* read only */
 #define PNG_TRANSFORM_PACKING        0x0004    /* read and write */
-#define PNG_TRANSFORM_PACKSWAP        0x0008    /* read and write */
-#define PNG_TRANSFORM_EXPAND        0x0010    /* read only */
+#define PNG_TRANSFORM_PACKSWAP       0x0008    /* read and write */
+#define PNG_TRANSFORM_EXPAND         0x0010    /* read only */
 #define PNG_TRANSFORM_INVERT_MONO    0x0020    /* read and write */
-#define PNG_TRANSFORM_SHIFT        0x0040    /* read and write */
-#define PNG_TRANSFORM_BGR        0x0080    /* read and write */
-#define PNG_TRANSFORM_SWAP_ALPHA    0x0100    /* read and write */
+#define PNG_TRANSFORM_SHIFT          0x0040    /* read and write */
+#define PNG_TRANSFORM_BGR            0x0080    /* read and write */
+#define PNG_TRANSFORM_SWAP_ALPHA     0x0100    /* read and write */
 #define PNG_TRANSFORM_SWAP_ENDIAN    0x0200    /* read and write */
-#define PNG_TRANSFORM_INVERT_ALPHA    0x0200    /* read and write */
-#define PNG_TRANSFORM_STRIP_FILLER    0x0800    /* WRITE only */
+#define PNG_TRANSFORM_INVERT_ALPHA   0x0200    /* read and write */
+#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* WRITE only */
 
 typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
 typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
@@ -861,6 +871,7 @@
 
    png_uint_32 mode;          /* tells us where we are in the PNG file */
    png_uint_32 flags;         /* flags indicating various things to libpng */
+   png_uint_32 free_me;       /* flags items libpng is responsible for freeing */
    png_uint_32 transformations; /* which transformations to perform */
 
    z_stream zstream;          /* pointer to decompression structure (below) */
@@ -1045,9 +1056,9 @@
 };
 
 /* This prevents a compiler error in png_get_copyright() in png.c if png.c
-and png.h are both at * version 1.0.5q
+and png.h are both at * version 1.0.5s
  */
-typedef png_structp version_1_0_5q;
+typedef png_structp version_1_0_5s;
 
 typedef png_struct FAR * FAR * png_structpp;
 
@@ -1577,6 +1588,23 @@
 /* frees a pointer allocated by png_malloc() */
 extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
 
+/* free data that was allocated internally */
+extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
+   png_infop info_ptr, png_uint_32 free_me, int num));
+/* flags for png_ptr->free_me and info_ptr->free_me */
+#define PNG_FREE_PLTE 0x0001
+#define PNG_FREE_TRNS 0x0002
+#define PNG_FREE_TEXT 0x0004
+#define PNG_FREE_HIST 0x0008
+#define PNG_FREE_ICCP 0x0010
+#define PNG_FREE_SPLT 0x0020
+#define PNG_FREE_ROWS 0x0040
+#define PNG_FREE_PCAL 0x0080
+#define PNG_FREE_SCAL 0x0100
+#define PNG_FREE_UNKN 0x0200
+#define PNG_FREE_LIST 0x0400
+#define PNG_FREE_ALL  0x07ff
+
 #ifdef PNG_USER_MEM_SUPPORTED
 extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
    png_uint_32 size));
@@ -1631,6 +1659,17 @@
 extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
 png_infop info_ptr));
 
+#if defined(PNG_INFO_IMAGE_SUPPORTED)
+/* Returns row_pointers, which is an array of pointers to scanlines that was
+returned from png_read_png(). */
+extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
+png_infop info_ptr));
+/* Set row_pointers, which is an array of pointers to scanlines for use
+by png_write_png(). */
+extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
+   png_infop info_ptr, png_bytepp row_pointers));
+#endif
+
 /* Returns number of color channels in image. */
 extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
 png_infop info_ptr));
@@ -1796,11 +1835,6 @@
    int type, int nparams, png_charp units, png_charpp params));
 #endif
 
-#if defined(PNG_pCAL_SUPPORTED)
-extern PNG_EXPORT(void,png_free_pCAL) PNGARG((png_structp png_ptr,
-   png_infop info_ptr));
-#endif
-
 #if defined(PNG_READ_pHYs_SUPPORTED)
 extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
    png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
@@ -1849,26 +1883,16 @@
 extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
    png_infop info_ptr, png_charp name, int compression_type,
    png_charp profile, png_uint_32 proflen));
-extern PNG_EXPORT(void,png_free_iCCP) PNGARG((png_structp png_ptr,
-   png_infop info_ptr));
 #endif
 
 #if defined(PNG_READ_sPLT_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_spalettes) PNGARG((png_structp png_ptr,
+extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
    png_infop info_ptr, png_spalette_pp entries));
 #endif
 
 #if defined(PNG_sPLT_SUPPORTED)
-extern PNG_EXPORT(void,png_set_spalettes) PNGARG((png_structp png_ptr,
+extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
    png_infop info_ptr, png_spalette_p entries, int nentries));
-extern PNG_EXPORT(void,png_free_spalettes) PNGARG((png_structp png_ptr,
-   png_infop info_ptr, int num));
-#endif
-
-#if defined(PNG_READ_iTXt_SUPPORTED)
-/* png_get_itxt also returns the number of text chunks in *num_text */
-extern PNG_EXPORT(png_uint_32,png_get_itxt) PNGARG((png_structp png_ptr,
-   png_infop info_ptr, png_textp *text_ptr, int *num_text));
 #endif
 
 #if defined(PNG_TEXT_SUPPORTED)
@@ -1886,8 +1910,6 @@
 #if defined(PNG_TEXT_SUPPORTED)
 extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
    png_infop info_ptr, png_textp text_ptr, int num_text));
-extern PNG_EXPORT(void,png_free_text) PNGARG((png_structp png_ptr,
-   png_infop info_ptr, int num_text_old));
 #endif
 
 #if defined(PNG_READ_tIME_SUPPORTED)
@@ -1913,8 +1935,6 @@
 #endif
 
 #if defined(PNG_tRNS_SUPPORTED)
-extern PNG_EXPORT(void,png_free_tRNS) PNGARG((png_structp png_ptr,
-   png_infop info_ptr));
 #endif
 
 #if defined(PNG_READ_sCAL_SUPPORTED)
@@ -1940,11 +1960,6 @@
 #endif
 #endif /* PNG_READ_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
 
-#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
-extern PNG_EXPORT(void,png_free_sCAL) PNGARG((png_structp png_ptr,
-   png_infop info_ptr));
-#endif /* PNG_READ_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
-
 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 /* provide a list of chunks and how they are to be handled, if the built-in
    handling or default unknown chunk handling is not desired.  Any chunks not
@@ -1959,11 +1974,8 @@
    png_ptr, int keep, png_bytep chunk_list, int num_chunks));
 extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
    png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
-extern PNG_EXPORT(void,png_free_unknown_chunks) PNGARG((png_structp png_ptr,
-   png_infop info_ptr, int num));
 extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
    png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
-extern PNG_EXPORT(void,png_free_chunk_list) PNGARG((png_structp png_ptr));
 #endif
 
 #if defined(PNG_INFO_IMAGE_SUPPORTED)
@@ -1975,8 +1987,6 @@
                         png_infop info_ptr,
                         int transforms,
                         voidp params));
-extern PNG_EXPORT(void, png_free_pixels) PNGARG((png_structp png_ptr,
-                        png_infop info_ptr));
 #endif
 
 /* Define PNG_DEBUG at compile time for debugging information.  Higher
@@ -2019,7 +2029,7 @@
 extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
 
 #define PNG_HEADER_VERSION_STRING \
-   " libpng version 1.0.5q - February 5, 2000 (header)\n"
+   " libpng version 1.0.5s - February 18, 2000 (header)\n"
 
 #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
 /* With these routines we avoid an integer divide, which will be slower on
@@ -2136,11 +2146,8 @@
 #define PNG_FLAG_CRC_ANCILLARY_NOWARN     0x0200
 #define PNG_FLAG_CRC_CRITICAL_USE         0x0400
 #define PNG_FLAG_CRC_CRITICAL_IGNORE      0x0800
-#define PNG_FLAG_FREE_PALETTE             0x1000
-#define PNG_FLAG_FREE_TRANS               0x2000
-#define PNG_FLAG_FREE_HIST                0x4000
-#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS      0x8000L
-#define PNG_FLAG_KEEP_UNSAFE_CHUNKS      0x10000L
+#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS      0x1000 
+#define PNG_FLAG_KEEP_UNSAFE_CHUNKS       0x2000
 
 /* For use in png_set_keep_unknown, png_handle_as_unknown */
 #define HANDLE_CHUNK_AS_DEFAULT   0
@@ -2415,14 +2422,6 @@
    int num_hist));
 #endif
 
-#if defined(PNG_hIST_SUPPORTED)
-extern PNG_EXPORT(void,png_free_hIST) PNGARG((png_structp png_ptr,
-   png_infop info_ptr));
-#endif
-
-extern PNG_EXPORT(void,png_free_PLTE) PNGARG((png_structp png_ptr,
-   png_infop info_ptr));
-
 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
     defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
 PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
diff --git a/pngasmrd.h b/pngasmrd.h
index 876f819..63b4aef 100644
--- a/pngasmrd.h
+++ b/pngasmrd.h
@@ -1,6 +1,6 @@
 /* pngasmrd.h - assembler version of utilities to read a PNG file
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1999, 2000 Glenn Randers-Pehrson
  *
@@ -9,24 +9,27 @@
 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
 
 /* Set this in the makefile for VC++ on Pentium, not in pngconf.h */
-#ifdef PNG_USE_PNGVCRD
 /* Platform must be Pentium.  Makefile must assemble and load pngvcrd.c .
  * MMX will be detected at run time and used if present.
  */
-#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
-#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
-#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+#ifdef PNG_USE_PNGVCRD
+#  define PNG_HAVE_ASSEMBLER_COMBINE_ROW
+#  define PNG_HAVE_ASSEMBLER_READ_INTERLACE
+#  define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
 #endif
 
-/* Set this in the makefile for gcc on Pentium, not in pngconf.h */
-#ifdef PNG_USE_PNGGCCRD
-/* Platform must be Pentium.  Makefile must assemble and load pnggccrd.c
- * (not available in libpng 1.0.5q).
+/* Set this in the makefile for gcc/as on Pentium, not in pngconf.h */
+/* Platform must be Pentium.  Makefile must assemble and load pnggccrd.c .
  * MMX will be detected at run time and used if present.
  */
-#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
-#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
-#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+#ifdef PNG_USE_PNGGCCRD
+#  define PNG_HAVE_ASSEMBLER_COMBINE_ROW
+#  define PNG_HAVE_ASSEMBLER_READ_INTERLACE
+#  define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
 #endif
+/*
+    GRR notes:
+      - see pnggccrd.c for info about what is currently enabled
+ */
 
 #endif
diff --git a/pngconf.h b/pngconf.h
index 16e1e77..246e3ca 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -423,7 +423,8 @@
 #define PNG_EASY_ACCESS_SUPPORTED
 #endif
 
-#ifndef PNG_NO_ASSEMBLER_CODE
+#if defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD) && \
+  !defined(PNG_NO_ASSEMBLER_CODE)
 #define PNG_ASSEMBLER_CODE_SUPPORTED
 #endif
 
@@ -711,7 +712,7 @@
 #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
 
 /* Turn this off to disable png_read_png() and
- * png_write_png() and leave the image_bits member
+ * png_write_png() and leave the row_pointers member
  * out of the info structure.
  */
 #ifndef PNG_NO_INFO_IMAGE
@@ -847,8 +848,13 @@
 
 
 #ifndef PNG_EXPORT
-   /* allow for compilation as dll under MS Windows */
-#  ifdef __WIN32DLL__
+   /* GRR 20000206:  based on zconf.h and MSVC 5.0 docs */
+#  if defined(_MSC_VER) && defined(_DLL)
+#    define PNG_EXPORT(type,symbol)        type __declspec(dllexport) symbol
+#  endif
+
+   /* allow for compilation as a DLL under MS Windows */
+#  ifdef __WIN32DLL__	/* Borland? */
 #    define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
 #  endif
 
@@ -857,7 +863,7 @@
 #    define PNG_EXPORT(type,symbol) type __attribute__((dllexport)) symbol
 #  endif
 
-   /* allow for compilation as dll with Borland C++ 5.0 */
+   /* allow for compilation as a DLL with Borland C++ 5.0 */
 #  if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
 #    define PNG_EXPORT(type,symbol) type _export symbol
 #  endif
@@ -877,6 +883,9 @@
 #endif
 
 #ifndef PNG_EXPORT_VAR
+#  if defined(_MSC_VER) && defined(_DLL)	/* GRR 20000206 */
+#    define PNG_EXPORT_VAR(type) extern type __declspec(dllexport)
+#  endif
 #  ifdef PNG_DECL_DLLEXP
 #    define PNG_EXPORT_VAR(type) extern __declspec(dllexport) type
 #  endif
@@ -903,6 +912,10 @@
 #   define PNG_ABORT() abort()
 #endif
 
+#ifdef PNG_SETJMP_SUPPORTED
+#   define png_jmp_env(png_ptr) png_ptr->jmpbuf   
+#endif
+
 #if defined(USE_FAR_KEYWORD)  /* memory model independent fns */
 /* use this to make far-to-near assignments */
 #   define CHECK   1
diff --git a/pngerror.c b/pngerror.c
index 3ef74ff..512aeb2 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -1,7 +1,7 @@
 
 /* pngerror.c - stub functions for i/o and memory allocation
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -133,6 +133,8 @@
    longjmp(png_ptr->jmpbuf, 1);
 # endif
 #else
+   if (png_ptr == NULL)
+     /* make compiler happy */ ;
    PNG_ABORT();
 #endif
 }
diff --git a/pnggccrd.c b/pnggccrd.c
index f73b1ff..504111c 100644
--- a/pnggccrd.c
+++ b/pnggccrd.c
@@ -6,7 +6,7 @@
  *     and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
  *     for Intel's performance analysis of the MMX vs. non-MMX code.
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998, Intel Corporation
  * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
diff --git a/pngget.c b/pngget.c
index c474a4f..ab6f10b 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,7 +1,7 @@
 
 /* pngget.c - retrieval of values from info struct
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -29,6 +29,17 @@
       return(0);
 }
 
+#if defined(PNG_INFO_IMAGE_SUPPORTED)
+png_bytepp
+png_get_rows(png_structp png_ptr, png_infop info_ptr)
+{
+   if (png_ptr != NULL && info_ptr != NULL)
+      return(info_ptr->row_pointers);
+   else
+      return(0);
+}
+#endif
+
 #ifdef PNG_EASY_ACCESS_SUPPORTED
 /* easy access to info, added in libpng-0.99 */
 png_uint_32
@@ -239,35 +250,35 @@
 png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
 {
    return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
-     *.03937 +.5)
+     *.0254 +.5);
 }
 
 png_uint_32
 png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
 {
    return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
-     *.03937 +.5)
+     *.0254 +.5);
 }
 
 png_uint_32
 png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
 {
    return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
-     *.03937 +.5)
+     *.0254 +.5);
 }
 
 float
 png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
 {
    return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
-     *.03937/1000000. +.5)
+     *.00003937);
 }
 
 float
 png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
 {
    return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
-     *.03937/1000000. +.5)
+     *.00003937)
 }
 
 #if defined(PNG_READ_pHYs_SUPPORTED)
@@ -296,8 +307,8 @@
          retval |= PNG_INFO_pHYs;
          if(unit_type == 1)
          {
-            if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50);
-            if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50);
+            if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
+            if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
          }
       }
    }
@@ -477,7 +488,7 @@
 
 #if defined(PNG_READ_sPLT_SUPPORTED)
 png_uint_32
-png_get_spalettes(png_structp png_ptr, png_infop info_ptr,
+png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
              png_spalette_pp spalettes)
 {
    if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
@@ -703,6 +714,8 @@
          *num_text = info_ptr->num_text;
       return ((png_uint_32)info_ptr->num_text);
    }
+   if (num_text != NULL)
+     *num_text = 0;
    return(0);
 }
 #endif
diff --git a/pngmem.c b/pngmem.c
index 840ea0c..4a47106 100644
--- a/pngmem.c
+++ b/pngmem.c
@@ -1,7 +1,7 @@
 
 /* pngmem.c - stub functions for memory allocation
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/pngpread.c b/pngpread.c
index d789308..9da0743 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1,7 +1,7 @@
 
 /* pngpread.c - read a png file in push mode
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/pngread.c b/pngread.c
index ba356dc..e468839 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,7 +1,7 @@
 
 /* pngread.c - read a PNG file
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -641,7 +641,7 @@
  * not called png_set_interlace_handling(), the display_row buffer will
  * be ignored, so pass NULL to it.
  *
- * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5q.
+ * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5s.
  */
 
 void
@@ -690,7 +690,7 @@
  * only call this function once.  If you desire to have an image for
  * each pass of a interlaced image, use png_read_rows() instead.
  *
- * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5q.
+ * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5s.
  */
 void
 png_read_image(png_structp png_ptr, png_bytepp image)
@@ -943,7 +943,7 @@
    if (info_ptr != NULL)
    {
 #if defined(PNG_TEXT_SUPPORTED)
-      png_free(png_ptr, info_ptr->text);
+      png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
 #endif
 
 #ifdef PNG_USER_MEM_SUPPORTED
@@ -957,7 +957,7 @@
    if (end_info_ptr != NULL)
    {
 #if defined(PNG_READ_TEXT_SUPPORTED)
-      png_free(png_ptr, end_info_ptr->text);
+      png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
 #endif
 #ifdef PNG_USER_MEM_SUPPORTED
       png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
@@ -1014,16 +1014,19 @@
    png_free(png_ptr, png_ptr->gamma_from_1);
    png_free(png_ptr, png_ptr->gamma_to_1);
 #endif
-   if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
+   if (png_ptr->free_me & PNG_FREE_PLTE)
       png_zfree(png_ptr, png_ptr->palette);
+   png_ptr->free_me &= ~PNG_FREE_PLTE;
 #if defined(PNG_tRNS_SUPPORTED) || \
     defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
-   if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
+   if (png_ptr->free_me & PNG_FREE_TRNS)
       png_free(png_ptr, png_ptr->trans);
+   png_ptr->free_me &= ~PNG_FREE_TRNS;
 #endif
 #if defined(PNG_READ_hIST_SUPPORTED)
-   if (png_ptr->flags & PNG_FLAG_FREE_HIST)
+   if (png_ptr->free_me & PNG_FREE_HIST)
       png_free(png_ptr, png_ptr->hist);
+   png_ptr->free_me &= ~PNG_FREE_HIST;
 #endif
 #if defined(PNG_READ_GAMMA_SUPPORTED)
    if (png_ptr->gamma_16_table != NULL)
@@ -1140,7 +1143,7 @@
        png_set_strip_alpha(png_ptr);
 #endif
 
-#if defined(PNG_READ_PACK_SUPPORTED)
+#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
    /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
     * byte into separate bytes (useful for paletted and grayscale images).
     */
@@ -1162,8 +1165,10 @@
     * channels so the data will be available as RGBA quartets.
     */
    if (transforms & PNG_TRANSFORM_EXPAND)
-       if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
-           png_set_expand(png_ptr);
+       if ((png_ptr->bit_depth < 8) ||
+           (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
+           (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
+         png_set_expand(png_ptr);
 #endif
 
    /* We don't handle background color or gamma transformation or dithering. */
@@ -1217,8 +1222,12 @@
 
    /* -------------- image transformations end here ------------------- */
 
-   info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
+   if(info_ptr->row_pointers == NULL)
+   {
+      info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
                                          info_ptr->height * sizeof(png_bytep));
+      info_ptr->free_me |= PNG_FREE_ROWS;
+   }
    for (row = 0; row < (int)info_ptr->height; row++)
        info_ptr->row_pointers[row] = png_malloc(png_ptr,
                                       png_get_rowbytes(png_ptr, info_ptr));
diff --git a/pngrio.c b/pngrio.c
index 92d9d50..2e42d17 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -1,7 +1,7 @@
 
 /* pngrio.c - functions for data input
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/pngrtran.c b/pngrtran.c
index a76a548..6037574 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,7 +1,7 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -658,7 +658,8 @@
 #endif
 
 #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
-   if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
+   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
+       (png_ptr->transformations & PNG_EXPAND))
    {
       if (!(color_type & PNG_COLOR_MASK_COLOR))  /* i.e., GRAY or GRAY_ALPHA */
       {
diff --git a/pngrutil.c b/pngrutil.c
index 4947dd2..9da17fa 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,7 +1,7 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -14,10 +14,6 @@
 #define PNG_INTERNAL
 #include "png.h"
 
-#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
-#include "pngasmrd.h"
-#endif
-
 #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
 /* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
 png_uint_32
@@ -398,7 +394,7 @@
 
    num = (int)length / 3;
    palette = (png_colorp)png_zalloc(png_ptr, (uInt)num, sizeof (png_color));
-   png_ptr->flags |= PNG_FLAG_FREE_PALETTE;
+   png_ptr->free_me |= PNG_FREE_PLTE;
    for (i = 0; i < num; i++)
    {
       png_byte buf[3];
@@ -436,7 +432,7 @@
          else
          {
             png_chunk_warning(png_ptr, "CRC error");
-            png_ptr->flags &= ~PNG_FLAG_FREE_PALETTE;
+            png_ptr->free_me &= ~PNG_FREE_PLTE;
             png_zfree(png_ptr, palette);
             return;
          }
@@ -928,6 +924,7 @@
 #endif
 
    chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
+   png_ptr->free_me |= PNG_FREE_ICCP;
    slength = (png_size_t)length;
    png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
 
@@ -1058,7 +1055,7 @@
    /* discard all chunk data except the name and stash that */
    new_palette.name = (png_charp)chunkdata;
 
-   png_set_spalettes(png_ptr, info_ptr, &new_palette, 1);
+   png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
 
    png_free(png_ptr, chunkdata);
    png_free(png_ptr, new_palette.entries);
@@ -1107,7 +1104,7 @@
       }
 
       png_ptr->trans = (png_bytep)png_malloc(png_ptr, length);
-      png_ptr->flags |= PNG_FLAG_FREE_TRANS;
+      png_ptr->free_me |= PNG_FREE_TRNS;
       png_crc_read(png_ptr, png_ptr->trans, (png_size_t)length);
       png_ptr->num_trans = (png_uint_16)length;
    }
@@ -1287,7 +1284,7 @@
    num = (int)length / 2 ;
    png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
       (png_uint_32)(num * sizeof (png_uint_16)));
-   png_ptr->flags |= PNG_FLAG_FREE_HIST;
+   png_ptr->free_me |= PNG_FREE_HIST;
    for (i = 0; i < num; i++)
    {
       png_byte buf[2];
@@ -2802,7 +2799,14 @@
       else
       {
          if (max_pixel_depth <= 8)
-            max_pixel_depth = 24;
+           {
+             if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+               max_pixel_depth = 32;
+             else
+               max_pixel_depth = 24;
+           }
+         else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+            max_pixel_depth = 64;
          else
             max_pixel_depth = 48;
       }
diff --git a/pngset.c b/pngset.c
index 011f459..660cb61 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,7 +1,7 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -135,9 +135,7 @@
    if (png_ptr == NULL || info_ptr == NULL)
       return;
 
-   info_ptr->hist = png_malloc(png_ptr, sizeof(png_uint_16) *
-      info_ptr->num_palette);
-   png_memcpy(info_ptr->hist, hist, sizeof(png_uint_16) * info_ptr->num_palette);
+   info_ptr->hist = hist;
    info_ptr->valid |= PNG_INFO_hIST;
 }
 #endif
@@ -309,7 +307,6 @@
 png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
    png_colorp palette, int num_palette)
 {
-   png_size_t length = (png_size_t)(3*num_palette);
 
    png_debug1(1, "in %s storage function\n", "PLTE");
    if (png_ptr == NULL || info_ptr == NULL)
@@ -317,13 +314,10 @@
 
    png_debug1(3, "allocating PLTE for info (%d bytes)\n", length);
 
-   info_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette,
-      sizeof (png_color));
-
-   png_memcpy(info_ptr->palette, palette, length);
+   info_ptr->palette = palette;
 
    info_ptr->num_palette = (png_uint_16)num_palette;
-   info_ptr->valid |= (PNG_INFO_PLTE|PNG_ALLOCATED_INFO_PLTE);
+   info_ptr->valid |= PNG_INFO_PLTE;
 }
 
 #if defined(PNG_sBIT_SUPPORTED)
@@ -441,6 +435,7 @@
    /* Compression is always zero but is here so the API and info structure
     * does not have to change * if we introduce multiple compression types */
    info_ptr->iccp_compression = (png_byte)compression_type;
+   info_ptr->free_me |= PNG_FREE_ICCP;
    info_ptr->valid |= PNG_INFO_iCCP;
 }
 #endif
@@ -526,8 +521,6 @@
 
       textp->key = (png_charp)png_malloc(png_ptr,
          (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4));
-      /* Caution: the calling program, not libpng, is responsible for
-         freeing this, if libpng wasn't the caller. */
       png_debug2(2, "Allocated %d bytes at %x in png_set_text\n",
          key_len + lang_len + lang_key_len + text_length + 4, textp->key);
 
@@ -573,6 +566,7 @@
 
       info_ptr->text[info_ptr->num_text]= *textp;
       info_ptr->num_text++;
+      info_ptr->free_me |= PNG_FREE_TEXT;
       png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
    }
 }
@@ -602,10 +596,7 @@
       return;
 
    if (trans != NULL)
-   {
-      info_ptr->trans = png_malloc(png_ptr, num_trans);
-      png_memcpy(info_ptr->trans, trans, num_trans);
-   }
+      info_ptr->trans = trans;
 
    if (trans_values != NULL)
    {
@@ -621,7 +612,7 @@
 
 #if defined(PNG_sPLT_SUPPORTED)
 void
-png_set_spalettes(png_structp png_ptr,
+png_set_sPLT(png_structp png_ptr,
              png_infop info_ptr, png_spalette_p entries, int nentries)
 {
     png_spalette_p        np;
@@ -653,6 +644,7 @@
     info_ptr->splt_palettes = np;
     info_ptr->splt_palettes_num += nentries;
     info_ptr->valid |= PNG_INFO_sPLT;
+    info_ptr->free_me |= PNG_FREE_SPLT;
 }
 #endif /* PNG_sPLT_SUPPORTED */
 
@@ -691,6 +683,7 @@
 
     info_ptr->unknown_chunks = np;
     info_ptr->unknown_chunks_num += num_unknowns;
+    info_ptr->free_me |= PNG_FREE_UNKN;
 }
 #endif
 
@@ -732,13 +725,14 @@
     if(png_ptr->chunk_list != (png_bytep)NULL)
     {
        png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
-       png_free_chunk_list(png_ptr);
+       png_free(png_ptr, png_ptr->chunk_list);
     }
     png_memcpy(new_list+5*old_num_chunks, chunk_list, 5*num_chunks);
     for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
        *p=(png_byte)keep;
     png_ptr->num_chunk_list=old_num_chunks+num_chunks;
     png_ptr->chunk_list=new_list;
+    png_ptr->free_me |= PNG_FREE_LIST;
 }
 #endif
 
@@ -753,3 +747,16 @@
 }
 #endif
 
+#if defined(PNG_INFO_IMAGE_SUPPORTED)
+void
+png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
+{
+   png_debug1(1, "in %s storage function\n", "rows");
+   if (png_ptr == NULL || info_ptr == NULL)
+      return;
+
+   info_ptr->row_pointers = row_pointers;
+   info_ptr->free_me |= PNG_FREE_ROWS;
+}
+#endif
+
diff --git a/pngtest.c b/pngtest.c
index a29619d..e018f4b 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,7 +1,7 @@
 
 /* pngtest.c - a simple test program to test libpng
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -524,7 +524,7 @@
    int bit_depth, color_type;
 #ifdef PNG_SETJMP_SUPPORTED
 #ifdef USE_FAR_KEYWORD
-   jmp_buf jmpbuf;
+   jmp_buf jmp_env;
 #endif
 #endif
 
@@ -579,11 +579,11 @@
 #endif
 
 #ifdef PNG_SETJMP_SUPPORTED
-   png_debug(0, "Setting jmpbuf for read struct\n");
+   png_debug(0, "Setting jmp_env for read struct\n");
 #ifdef USE_FAR_KEYWORD
-   if (setjmp(jmpbuf))
+   if (setjmp(jmp_env))
 #else
-   if (setjmp(read_ptr->jmpbuf))
+   if (setjmp(png_jmp_env(read_ptr)))
 #endif
    {
       fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
@@ -595,14 +595,14 @@
       return (1);
    }
 #ifdef USE_FAR_KEYWORD
-   png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
+   png_memcpy(png_jmp_env(read_ptr),jmp_env,sizeof(jmp_buf));
 #endif
 
-   png_debug(0, "Setting jmpbuf for write struct\n");
+   png_debug(0, "Setting jmp_env for write struct\n");
 #ifdef USE_FAR_KEYWORD
-   if (setjmp(jmpbuf))
+   if (setjmp(jmp_env))
 #else
-   if (setjmp(write_ptr->jmpbuf))
+   if (setjmp(png_jmp_env(write_ptr)))
 #endif
    {
       fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
@@ -614,7 +614,7 @@
       return (1);
    }
 #ifdef USE_FAR_KEYWORD
-   png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
+   png_memcpy(write_ptr->jmpbuf,jmp_env,sizeof(jmp_buf));
 #endif
 #endif
 
@@ -949,10 +949,10 @@
    }
 
 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
-   png_free_unknown_chunks(read_ptr, end_info_ptr, -1);
+   png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
 #endif
 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
-   png_free_unknown_chunks(write_ptr, write_info_ptr, -1);
+   png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
 #endif
 
    png_debug(0, "Reading and writing end_info data\n");
@@ -1341,7 +1341,7 @@
 /* Generate a compiler error if there is an old png.h in the search path. */
 void
 png_check_pngtest_version
-   (version_1_0_5q png_h_is_not_version_1_0_5q)
+   (version_1_0_5s png_h_is_not_version_1_0_5s)
 {
-   if(png_h_is_not_version_1_0_5q == NULL) return;
+   if(png_h_is_not_version_1_0_5s == NULL) return;
 }
diff --git a/pngtrans.c b/pngtrans.c
index 631ffc3..86c0dfd 100644
--- a/pngtrans.c
+++ b/pngtrans.c
@@ -1,7 +1,7 @@
 
 /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/pngtypes.h b/pngtypes.h
index 5db1e8d..756d8e2 100644
--- a/pngtypes.h
+++ b/pngtypes.h
@@ -1,6 +1,6 @@
 /* pngtypes.h - array of chunk-types for libpng
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/pngvcrd.c b/pngvcrd.c
index ab238a5..299827d 100644
--- a/pngvcrd.c
+++ b/pngvcrd.c
@@ -2,7 +2,7 @@
  *
  * For Intel x86 CPU and Microsoft Visual C++ compiler
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998, Intel Corporation
  * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
diff --git a/pngwio.c b/pngwio.c
index efeb913..515e0f4 100644
--- a/pngwio.c
+++ b/pngwio.c
@@ -1,7 +1,7 @@
 
 /* pngwio.c - functions for data output
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/pngwrite.c b/pngwrite.c
index e3bd282..ab68a1e 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,7 +1,7 @@
 
 /* pngwrite.c - general routines to write a PNG file
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
@@ -799,35 +799,13 @@
 
    if (info_ptr != NULL)
    {
-#if defined(PNG_WRITE_TEXT_SUPPORTED)
-      png_free_text(png_ptr, info_ptr, -1);
-#endif
-#if defined(PNG_WRITE_tRNS_SUPPORTED)
-   png_free_tRNS(png_ptr, info_ptr);
-#endif
-#if defined(PNG_WRITE_sCAL_SUPPORTED)
-      png_free_sCAL(png_ptr, info_ptr);
-#endif
-#if defined(PNG_WRITE_pCAL_SUPPORTED)
-      png_free_pCAL(png_ptr, info_ptr);
-#endif
-#if defined(PNG_WRITE_iCCP_SUPPORTED)
-      png_free_iCCP(png_ptr, info_ptr);
-#endif
-#if defined(PNG_WRITE_sPLT_SUPPORTED)
-      png_free_spalettes(png_ptr, info_ptr, -1);
-#endif
-#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
-      png_free_unknown_chunks(png_ptr, info_ptr, -1);
-      png_free_chunk_list(png_ptr);
-#endif
-#if defined(PNG_hIST_SUPPORTED)
-      png_free_hIST(png_ptr, info_ptr);
-#endif
-      png_free_PLTE(png_ptr, info_ptr);
-#if defined(PNG_INFO_IMAGE_SUPPORTED)
-   png_free_pixels(png_ptr, info_ptr);
-#endif
+      png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
+
+      if (png_ptr->num_chunk_list)
+      {
+         png_free(png_ptr, png_ptr->chunk_list);
+         png_ptr->num_chunk_list=0;
+      }
 
 #ifdef PNG_USER_MEM_SUPPORTED
       png_destroy_struct_2((png_voidp)info_ptr, free_fn);
diff --git a/pngwtran.c b/pngwtran.c
index ed7f22f..4092834 100644
--- a/pngwtran.c
+++ b/pngwtran.c
@@ -1,7 +1,7 @@
 
 /* pngwtran.c - transforms the data in a row for PNG writers
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/pngwutil.c b/pngwutil.c
index 3ddecbc..437a535 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,7 +1,7 @@
 
 /* pngwutil.c - utilities to write a PNG file
  *
- * libpng 1.0.5q - February 5, 2000
+ * libpng 1.0.5s - February 18, 2000
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
diff --git a/scripts/makefile.beos b/scripts/makefile.beos
index b863706..27dbf83 100644
--- a/scripts/makefile.beos
+++ b/scripts/makefile.beos
@@ -31,7 +31,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 2.  You should not
 # have to change it.
 PNGMAJ = 2
-PNGMIN = 1.0.5q
+PNGMIN = 1.0.5s
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # where make install puts libpng.a, libpng.so*, and png.h
diff --git a/scripts/makefile.dec b/scripts/makefile.dec
index 7a00e47..4183ab8 100644
--- a/scripts/makefile.dec
+++ b/scripts/makefile.dec
@@ -14,7 +14,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 2.  You should not
 # have to change it.
 PNGMAJ = 2
-PNGMIN = 1.0.5q
+PNGMIN = 1.0.5s
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 CC=cc
diff --git a/scripts/makefile.gcmmx b/scripts/makefile.gcmmx
index 4f17231..45e37de 100644
--- a/scripts/makefile.gcmmx
+++ b/scripts/makefile.gcmmx
@@ -24,8 +24,8 @@
 
 # for pgcc version 2.95.1, -O3 is buggy; don't use it.
 
-CFLAGS=-DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 $(ALIGN) \
-	-funroll-loops -fomit-frame-pointer	# $(WARNMORE) -g -DPNG_DEBUG=5
+CFLAGS=-DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 $(ALIGN) -funroll-loops \
+        -fomit-frame-pointer  # $(WARNMORE) -g -DPNG_DEBUG=5
 LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
 
 RANLIB=ranlib
@@ -34,7 +34,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 2.  You should not
 # have to change it.
 PNGMAJ = 2
-PNGMIN = 1.0.5q
+PNGMIN = 1.0.5s
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
@@ -74,7 +74,8 @@
 	./pngtest
 
 install: libpng.a libpng.so.$(PNGVER)
-	-@mkdir $(INCPATH) $(LIBPATH)
+ 	-@if [ ! -d $(INCPATH)  ]; then mkdir $(INCPATH); fi
+ 	-@if [ ! -d $(LIBPATH) ]; then mkdir $(LIBPATH); fi
 	cp png.h pngconf.h $(INCPATH)
 	chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
 	cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
diff --git a/scripts/makefile.linux b/scripts/makefile.linux
index 8796904..008d1eb 100644
--- a/scripts/makefile.linux
+++ b/scripts/makefile.linux
@@ -34,7 +34,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 2.  You should not
 # have to change it.
 PNGMAJ = 2
-PNGMIN = 1.0.5q
+PNGMIN = 1.0.5s
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
@@ -74,7 +74,8 @@
 	./pngtest
 
 install: libpng.a libpng.so.$(PNGVER)
-	-@mkdir $(INCPATH) $(LIBPATH)
+ 	-@if [ ! -d $(INCPATH)  ]; then mkdir $(INCPATH); fi
+ 	-@if [ ! -d $(LIBPATH) ]; then mkdir $(LIBPATH); fi
 	cp png.h pngconf.h $(INCPATH)
 	chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
 	cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
diff --git a/scripts/makefile.sco b/scripts/makefile.sco
index 4e94029..41aadec 100644
--- a/scripts/makefile.sco
+++ b/scripts/makefile.sco
@@ -25,7 +25,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 2.  You should not
 # have to change it.
 PNGMAJ = 2
-PNGMIN = 1.0.5q
+PNGMIN = 1.0.5s
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.solaris b/scripts/makefile.solaris
index 922b6af..3245029 100644
--- a/scripts/makefile.solaris
+++ b/scripts/makefile.solaris
@@ -31,7 +31,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 2.  You should not
 # have to change it.
 PNGMAJ = 2
-PNGMIN = 1.0.5q
+PNGMIN = 1.0.5s
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/pngdef.pas b/scripts/pngdef.pas
index 832b7f3..ff3ac48 100644
--- a/scripts/pngdef.pas
+++ b/scripts/pngdef.pas
@@ -363,6 +363,9 @@
 function png_get_rowbytes(png_ptr: png_structp; info_ptr: png_infop):
              png_uint_32;
              stdcall;
+function png_get_rows(png_ptr: png_structp; info_ptr: png_infop):
+             png_bytepp;
+             stdcall;
 function png_get_sBIT(png_ptr: png_structp; info_ptr: png_infop;
              var sig_bits: png_color_8p): png_uint_32;
              stdcall;
@@ -539,6 +542,9 @@
              stdcall;
 procedure png_set_rgb_to_gray(png_ptr: png_structp; int: error_action);
              stdcall;
+procedure png_set_rows(png_ptr: png_structp; info_ptr: png_infop;
+             row_pointers: png_bytepp);
+             stdcall;
 procedure png_set_sBIT(png_ptr: png_structp; info_ptr: png_infop;
              sig_bits: png_color_8p);
              stdcall;
@@ -617,32 +623,18 @@
              name: png_charpp; compression_type: int *; profile: png_charpp;
              proflen: png_int_32): png_bytep;
              stdcall;
-procedure png_get_spalettes(png_ptr: png_structp;
+procedure png_get_sPLT(png_ptr: png_structp;
              info_ptr: png_infop;  entries: png_spalette_pp): png_uint_32;
              stdcall;
-procedure png_free_pCAL(png_ptr: png_structp; info_ptr: png_infop);
-             stdcall;
-procedure png_free_sCAL(png_ptr: png_structp; info_ptr: png_infop);
-             stdcall;
 procedure png_set_iCCP(png_ptr: png_structp; info_ptr: png_infop;
              name: png_charp; compression_type: int; profile: png_charp;
              proflen: int);
              stdcall;
-procedure png_free_hIST(png_ptr: png_structp; info_ptr: png_infop);
+procedure png_free_data(png_ptr: png_structp; info_ptr: png_infop; num: int);
              stdcall;
-procedure png_free_iCCP(png_ptr: png_structp; info_ptr: png_infop);
-             stdcall;
-procedure png_free_PLTE(png_ptr: png_structp; info_ptr: png_infop);
-             stdcall;
-procedure png_free_text(png_ptr: png_structp; info_ptr: png_infop);
-             stdcall;
-procedure png_free_tRNS(png_ptr: png_structp; info_ptr: png_infop);
-             stdcall;
-procedure png_set_spalettes(png_ptr: png_structp; info_ptr: png_infop;
+procedure png_set_sPLT(png_ptr: png_structp; info_ptr: png_infop;
              entries: png_spalette_p; nentries: int);
              stdcall;
-procedure png_free_sPLT(png_ptr: png_structp; info_ptr: png_infop);
-             stdcall;
 
 implementation
 
@@ -684,6 +676,7 @@
 function png_get_pixels_per_meter; external pngDLL;
 function png_get_progressive_ptr; external pngDLL;
 function png_get_rowbytes; external pngDLL;
+function png_get_rows; external pngDLL;
 function png_get_sBIT; external pngDLL;
 function png_get_sRGB; external pngDLL;
 function png_get_signature; external pngDLL;
@@ -741,6 +734,7 @@
 procedure png_set_read_fn; external pngDLL;
 procedure png_set_read_status_fn; external pngDLL;
 procedure png_set_read_user_transform_fn; external pngDLL;
+procedure png_set_rows; external pngDLL;
 procedure png_set_sBIT; external pngDLL;
 procedure png_set_sRGB; external pngDLL;
 procedure png_set_sRGB_gAMA_and_cHRM; external pngDLL;
@@ -771,16 +765,9 @@
 procedure png_write_row; external pngDLL;
 procedure png_write_rows; external pngDLL;
 procedure png_get_iCCP; external pngDLL;
-procedure png_get_spalettes; external pngDLL;
-procedure png_free_pCAL; external pngDLL;
+procedure png_get_sPLT; external pngDLL;
 procedure png_set_iCCP; external pngDLL;
-procedure png_free_hIST; external pngDLL;
-procedure png_free_iCCP; external pngDLL;
-procedure png_free_PLTE; external pngDLL;
-procedure png_free_sCAL; external pngDLL;
-procedure png_free_text; external pngDLL;
-procedure png_free_tRNS; external pngDLL;
-procedure png_set_spalettes; external pngDLL;
-procedure png_free_sPLT; external pngDLL;
+procedure png_set_sPLT; external pngDLL;
+procedure png_free_data; external pngDLL;
 
 end.
diff --git a/scripts/pngos2.def b/scripts/pngos2.def
index ce5735f..c3ff7f5 100644
--- a/scripts/pngos2.def
+++ b/scripts/pngos2.def
@@ -31,6 +31,7 @@
   png_set_bgr
   png_set_gray_to_rgb
   png_set_rgb_to_gray
+  png_set_rows
   png_build_grayscale_palette
   png_set_strip_alpha
   png_set_swap_alpha
@@ -120,6 +121,7 @@
   png_get_pixels_per_meter
   png_get_pixel_aspect_ratio
   png_get_rgb_to_gray_status
+  png_get_rows
   png_get_x_offset_pixels
   png_get_y_offset_pixels
   png_get_x_offset_microns
@@ -291,17 +293,10 @@
 ; png_pass_height
   png_get_iCCP 
   png_get_sCAL
-  png_get_spalettes 
+  png_get_sPLT 
   png_set_iCCP 
-  png_set_spalettes 
-  png_free_hIST 
-  png_free_iCCP 
-  png_free_pCAL 
-  png_free_PLTE 
-  png_free_sCAL
-  png_free_sPLT 
-  png_free_text 
-  png_free_tRNS 
+  png_set_sPLT 
+  png_free_data
 
   png_IHDR
   png_IDAT