Imported from libpng-1.0.1a.tar
diff --git a/ANNOUNCE b/ANNOUNCE
new file mode 100644
index 0000000..520d799
--- /dev/null
+++ b/ANNOUNCE
@@ -0,0 +1,26 @@
+
+Libpng 1.0.1a April 21, 1998
+
+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.
+
+Changes since the last release:
+
+   Optimized Paeth calculations by replacing abs() function calls with intrinsics
+   plus other loop optimizations. Improves avg decoding speed by about 20 percent.
+   Commented out i386istic "align" compiler flags in makefile.lnx.
+   Reduced the default warning level in some makefiles, to make them consistent.
+   Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
+   Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
+   Added grayscale and 16-bit capability to png_do_read_filler().
+   Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
+     too large when writing an image with bit_depth < 8 (Bob Dellaca).
+   Corrected some bugs in the experimental weighted filtering heuristics.
+   Moved a misplaced pngrutil code block that truncates tRNS if it has more
+     than num_palette entries -- test was done before num_palette was defined.
+   Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
+
+Send comments/corrections/commendations to
+png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu
+
+Glenn R-P
diff --git a/CHANGES b/CHANGES
index 9cb33a1..a56c3b3 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,288 +1,303 @@
 CHANGES - changes for libpng
 
 version 0.2
-   added reader into png.h
-   fixed small problems in stub file
+  added reader into png.h
+  fixed small problems in stub file
 version 0.3
-   added pull reader
-   split up pngwrite.c to several files
-   added pnglib.txt
-   added example.c
-   cleaned up writer, adding a few new tranformations
-   fixed some bugs in writer
-   interfaced with zlib 0.5
-   added K&R support
-   added check for 64 KB blocks for 16 bit machines
+  added pull reader
+  split up pngwrite.c to several files
+  added pnglib.txt
+  added example.c
+  cleaned up writer, adding a few new tranformations
+  fixed some bugs in writer
+  interfaced with zlib 0.5
+  added K&R support
+  added check for 64 KB blocks for 16 bit machines
 version 0.4
-   cleaned up code and commented code
-   simplified time handling into png_time
-   created png_color_16 and png_color_8 to handle color needs
-   cleaned up color type defines
-   fixed various bugs
-   made various names more consistant
-   interfaced with zlib 0.71
-   cleaned up zTXt reader and writer (using zlib's Reset functions)
-   split transformations into pngrtran.c and pngwtran.c
+  cleaned up code and commented code
+  simplified time handling into png_time
+  created png_color_16 and png_color_8 to handle color needs
+  cleaned up color type defines
+  fixed various bugs
+  made various names more consistant
+  interfaced with zlib 0.71
+  cleaned up zTXt reader and writer (using zlib's Reset functions)
+  split transformations into pngrtran.c and pngwtran.c
 version 0.5
-   interfaced with zlib 0.8
-   fixed many reading and writing bugs
-   saved using 3 spaces instead of tabs
+  interfaced with zlib 0.8
+  fixed many reading and writing bugs
+  saved using 3 spaces instead of tabs
 version 0.6
-   added png_large_malloc() and png_large_free()
-   added png_size_t
-   cleaned up some compiler warnings
-   added png_start_read_image()
+  added png_large_malloc() and png_large_free()
+  added png_size_t
+  cleaned up some compiler warnings
+  added png_start_read_image()
 version 0.7
-   cleaned up lots of bugs
-   finished dithering and other stuff
-   added test program
-   changed name from pnglib to libpng
+  cleaned up lots of bugs
+  finished dithering and other stuff
+  added test program
+  changed name from pnglib to libpng
 version 0.71 [June, 1995]
-   changed pngtest.png for zlib 0.93
-   fixed error in libpng.txt and example.c
+  changed pngtest.png for zlib 0.93
+  fixed error in libpng.txt and example.c
 version 0.8
-   cleaned up some bugs
-   added png_set_filler()
-   split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
-   added #define's to remove unwanted code
-   moved png_info_init() to png.c
-   added old_size into png_realloc()
-   added functions to manually set filtering and compression info
-   changed compression parameters based on image type
-   optimized filter selection code
-   added version info
-   changed external functions passing floats to doubles (k&r problems?)
-   put all the configurable stuff in pngconf.h
-   enabled png_set_shift to work with paletted images on read
-   added png_read_update_info() - updates info structure with
-      transformations
+  cleaned up some bugs
+  added png_set_filler()
+  split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
+  added #define's to remove unwanted code
+  moved png_info_init() to png.c
+  added old_size into png_realloc()
+  added functions to manually set filtering and compression info
+  changed compression parameters based on image type
+  optimized filter selection code
+  added version info
+  changed external functions passing floats to doubles (k&r problems?)
+  put all the configurable stuff in pngconf.h
+  enabled png_set_shift to work with paletted images on read
+  added png_read_update_info() - updates info structure with
+     transformations
 version 0.81 [August, 1995]
-   incorporated Tim Wegner's medium model code (thanks, Tim)
+  incorporated Tim Wegner's medium model code (thanks, Tim)
 version 0.82 [September, 1995]
-   [unspecified changes]
+  [unspecified changes]
 version 0.85 [December, 1995]
-   added more medium model code (almost everything's a far)
-   added i/o, error, and memory callback functions
-   fixed some bugs (16 bit, 4 bit interlaced, etc.)
-   added first run progressive reader (barely tested)
+  added more medium model code (almost everything's a far)
+  added i/o, error, and memory callback functions
+  fixed some bugs (16 bit, 4 bit interlaced, etc.)
+  added first run progressive reader (barely tested)
 version 0.86 [January, 1996]
-   fixed bugs
-   improved documentation
+  fixed bugs
+  improved documentation
 version 0.87 [January, 1996]
-   fixed medium model bugs
-   fixed other bugs introduced in 0.85 and 0.86
-   added some minor documentation
+  fixed medium model bugs
+  fixed other bugs introduced in 0.85 and 0.86
+  added some minor documentation
 version 0.88 [January, 1996]
-   fixed progressive bugs
-   replaced tabs with spaces
-   cleaned up documentation
-   added callbacks for read/write and warning/error functions
+  fixed progressive bugs
+  replaced tabs with spaces
+  cleaned up documentation
+  added callbacks for read/write and warning/error functions
 version 0.89 [July, 1996]
-   added new initialization API to make libpng work better with shared libs
-      we now have png_create_read_struct(), png_create_write_struct(),
-      png_create_info_struct(), png_destroy_read_struct(), and
-      png_destroy_write_struct() instead of the separate calls to
-      malloc and png_read_init(), png_info_init(), and png_write_init()
-   changed warning/error callback functions to fix bug - this means you
-      should use the new initialization API if you were using the old
-      png_set_message_fn() calls, and that the old API no longer exists
-      so that people are aware that they need to change their code
-   changed filter selection API to allow selection of multiple filters
-      since it didn't work in previous versions of libpng anyways
-   optimized filter selection code    
-   fixed png_set_background() to allow using an arbitrary RGB color for
-      paletted images
-   fixed gamma and background correction for paletted images, so
-      png_correct_palette is not needed unless you are correcting an
-      external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
-      in pngconf.h) - if nobody uses this, it may disappear in the future.
-   fixed bug with Borland 64K memory allocation (Alexander Lehmann)
-   fixed bug in interlace handling (Smarasderagd, I think)
-   added more error checking for writing and image to reduce invalid files
-   separated read and write functions so that they won't both be linked
-      into a binary when only reading or writing functionality is used
-   new pngtest image also has interlacing and zTXt
-   updated documentation to reflect new API
+  added new initialization API to make libpng work better with shared libs
+     we now have png_create_read_struct(), png_create_write_struct(),
+     png_create_info_struct(), png_destroy_read_struct(), and
+     png_destroy_write_struct() instead of the separate calls to
+     malloc and png_read_init(), png_info_init(), and png_write_init()
+  changed warning/error callback functions to fix bug - this means you
+     should use the new initialization API if you were using the old
+     png_set_message_fn() calls, and that the old API no longer exists
+     so that people are aware that they need to change their code
+  changed filter selection API to allow selection of multiple filters
+     since it didn't work in previous versions of libpng anyways
+  optimized filter selection code    
+  fixed png_set_background() to allow using an arbitrary RGB color for
+     paletted images
+  fixed gamma and background correction for paletted images, so
+     png_correct_palette is not needed unless you are correcting an
+     external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
+     in pngconf.h) - if nobody uses this, it may disappear in the future.
+  fixed bug with Borland 64K memory allocation (Alexander Lehmann)
+  fixed bug in interlace handling (Smarasderagd, I think)
+  added more error checking for writing and image to reduce invalid files
+  separated read and write functions so that they won't both be linked
+     into a binary when only reading or writing functionality is used
+  new pngtest image also has interlacing and zTXt
+  updated documentation to reflect new API
 version 0.90 [January, 1997]
-   made CRC errors/warnings on critical and ancillary chunks configurable
-   libpng will use the zlib CRC routines by (compile-time) default
-   changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)
-   added external C++ wrapper statements to png.h (Gilles Dauphin)
-   allow PNG file to be read when some or all of file signature has already
-      been read from the beginning of the stream.  ****This affects the size
-      of info_struct and invalidates all programs that use a shared libpng****
-   fixed png_filler() declarations
-   fixed? background color conversions
-   fixed order of error function pointers to match documentation
-   current chunk name is now available in png_struct to reduce the number
-      of nearly identical error messages (will simplify multi-lingual
-      support when available)
-   try to get ready for unknown-chunk callback functions:
-      - previously read critical chunks are flagged, so the chunk handling
-        routines can determine if the chunk is in the right place
-      - all chunk handling routines have the same prototypes, so we will
-        be able to handle all chunks via a callback mechanism
-   try to fix Linux "setjmp" buffer size problems
+  made CRC errors/warnings on critical and ancillary chunks configurable
+  libpng will use the zlib CRC routines by (compile-time) default
+  changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)
+  added external C++ wrapper statements to png.h (Gilles Dauphin)
+  allow PNG file to be read when some or all of file signature has already
+     been read from the beginning of the stream.  ****This affects the size
+     of info_struct and invalidates all programs that use a shared libpng****
+  fixed png_filler() declarations
+  fixed? background color conversions
+  fixed order of error function pointers to match documentation
+  current chunk name is now available in png_struct to reduce the number
+     of nearly identical error messages (will simplify multi-lingual
+     support when available)
+  try to get ready for unknown-chunk callback functions:
+     - previously read critical chunks are flagged, so the chunk handling
+       routines can determine if the chunk is in the right place
+     - all chunk handling routines have the same prototypes, so we will
+       be able to handle all chunks via a callback mechanism
+  try to fix Linux "setjmp" buffer size problems
 version 0.95 [March, 1997]
-   fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
-   fixed bug in PNG file signature compares when start != 0
-   changed parameter type of png_set_filler(...filler...) from png_byte
-      to png_uint_32
-   added test for MACOS to ensure that both math.h and fp.h are not #included
-   added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)
-   added "packswap" transformation, which changes the endianness of
-      packed-pixel bytes (Kevin Bracey)
-   added "strip_alpha" transformation, which removes the alpha channel of
-      input images without using it (not neccesarily a good idea)
-   added "swap_alpha" transformation, which puts the alpha channel in front
-      of the color bytes instead of after
-   removed all implicit variable tests which assume NULL == 0 (I think)
-   changed several variables to "png_size_t" to show 16/32-bit limitations
-   added new pCAL chunk read/write support
-   added experimental filter selection weighting (Greg Roelofs)
-   removed old png_set_rgbx() and png_set_xrgb() functions that have been
-      obsolete for about 2 years now (use png_set_filler() instead)
-   added macros to read 16- and 32-bit ints directly from buffer, to be
-      used only on those systems that support it (namely PowerPC and 680x0)
-      With some testing, this may become the default for MACOS/PPC systems.
-   only calculate CRC on data if we are going to use it
-   added macros for zTXt compression type PNG_zTXt_COMPRESSION_???
-   added macros for simple libpng debugging output selectable at compile time
-   removed PNG_READ_END_MODE in progressive reader (Smarasderagd)
-   more description of info_struct in libpng.txt and png.h
-   more instructions in example.c
-   more chunk types tested in pngtest.c
-   renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be
-      png_set_<chunk>.  We now have corresponding png_get_<chunk>
-      functions in pngget.c to get infomation in info_ptr.  This isolates
-      the application from the internal organization of png_info_struct
-      (good for shared library implementations).
+  fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
+  fixed bug in PNG file signature compares when start != 0
+  changed parameter type of png_set_filler(...filler...) from png_byte
+     to png_uint_32
+  added test for MACOS to ensure that both math.h and fp.h are not #included
+  added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)
+  added "packswap" transformation, which changes the endianness of
+     packed-pixel bytes (Kevin Bracey)
+  added "strip_alpha" transformation, which removes the alpha channel of
+     input images without using it (not neccesarily a good idea)
+  added "swap_alpha" transformation, which puts the alpha channel in front
+     of the color bytes instead of after
+  removed all implicit variable tests which assume NULL == 0 (I think)
+  changed several variables to "png_size_t" to show 16/32-bit limitations
+  added new pCAL chunk read/write support
+  added experimental filter selection weighting (Greg Roelofs)
+  removed old png_set_rgbx() and png_set_xrgb() functions that have been
+     obsolete for about 2 years now (use png_set_filler() instead)
+  added macros to read 16- and 32-bit ints directly from buffer, to be
+     used only on those systems that support it (namely PowerPC and 680x0)
+     With some testing, this may become the default for MACOS/PPC systems.
+  only calculate CRC on data if we are going to use it
+  added macros for zTXt compression type PNG_zTXt_COMPRESSION_???
+  added macros for simple libpng debugging output selectable at compile time
+  removed PNG_READ_END_MODE in progressive reader (Smarasderagd)
+  more description of info_struct in libpng.txt and png.h
+  more instructions in example.c
+  more chunk types tested in pngtest.c
+  renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be
+     png_set_<chunk>.  We now have corresponding png_get_<chunk>
+     functions in pngget.c to get infomation in info_ptr.  This isolates
+     the application from the internal organization of png_info_struct
+     (good for shared library implementations).
 version 0.96 [May, 1997]
-   fixed serious bug with < 8bpp images introduced in 0.95
-   fixed 256-color transparency bug (Greg Roelofs)
-   fixed up documentation (Greg Roelofs, Laszlo Nyul)
-   fixed "error" in pngconf.h for Linux setjmp() behaviour
-   fixed DOS medium model support (Tim Wegner)
-   fixed png_check_keyword() for case with error in static string text
-   added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
-   added typecasts to quiet compiler errors
-   added more debugging info
+  fixed serious bug with < 8bpp images introduced in 0.95
+  fixed 256-color transparency bug (Greg Roelofs)
+  fixed up documentation (Greg Roelofs, Laszlo Nyul)
+  fixed "error" in pngconf.h for Linux setjmp() behaviour
+  fixed DOS medium model support (Tim Wegner)
+  fixed png_check_keyword() for case with error in static string text
+  added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
+  added typecasts to quiet compiler errors
+  added more debugging info
 version 0.97 [January, 1998]
-   removed PNG_USE_OWN_CRC capability
-   relocated png_set_crc_action from pngrutil.c to pngrtran.c
-   fixed typecasts of "new_key", etc. (Andreas Dilger)
-   added RFC 1152 [sic] date support
-   fixed bug in gamma handling of 4-bit grayscale
-   added 2-bit grayscale gamma handling (Glenn R-P)
-   added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
-   minor corrections in libpng.txt
-   added simple sRGB support (Glenn R-P)
-   easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
-      all configurable options can be selected from command-line instead
-      of having to edit pngconf.h (Glenn R-P)
-   fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
-   added more conditions for png_do_background, to avoid changing
-      black pixels to background when a background is supplied and
-      no pixels are transparent
-   repaired PNG_NO_STDIO behaviour
-   tested NODIV support and made it default behaviour (Greg Roelofs)
-   added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
-   regularized version numbering scheme and bumped shared-library major
-      version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs)
+  removed PNG_USE_OWN_CRC capability
+  relocated png_set_crc_action from pngrutil.c to pngrtran.c
+  fixed typecasts of "new_key", etc. (Andreas Dilger)
+  added RFC 1152 [sic] date support
+  fixed bug in gamma handling of 4-bit grayscale
+  added 2-bit grayscale gamma handling (Glenn R-P)
+  added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
+  minor corrections in libpng.txt
+  added simple sRGB support (Glenn R-P)
+  easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
+     all configurable options can be selected from command-line instead
+     of having to edit pngconf.h (Glenn R-P)
+  fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
+  added more conditions for png_do_background, to avoid changing
+     black pixels to background when a background is supplied and
+     no pixels are transparent
+  repaired PNG_NO_STDIO behaviour
+  tested NODIV support and made it default behaviour (Greg Roelofs)
+  added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
+  regularized version numbering scheme and bumped shared-library major
+     version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs)
 version 0.98 [January, 1998]
-   cleaned up some typos in libpng.txt and in code documentation
-   fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
-   cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
-   changed recommendation about file_gamma for PC images to .51 from .45,
-      in example.c and libpng.txt, added comments to distinguish between
-      screen_gamma, viewing_gamma, and display_gamma.
-   changed all references to RFC1152 to read RFC1123 and changed the
-      PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
-   added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
-   changed srgb_intent from png_byte to int to avoid compiler bugs
+  cleaned up some typos in libpng.txt and in code documentation
+  fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
+  cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
+  changed recommendation about file_gamma for PC images to .51 from .45,
+     in example.c and libpng.txt, added comments to distinguish between
+     screen_gamma, viewing_gamma, and display_gamma.
+  changed all references to RFC1152 to read RFC1123 and changed the
+     PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
+  added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
+  changed srgb_intent from png_byte to int to avoid compiler bugs
 version 0.99 [January 30, 1998]
-   free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
-   fixed a longstanding "packswap" bug in pngtrans.c
-   fixed some inconsistencies in pngconf.h that prevented compiling with
-      PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
-   fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
-   changed recommendation about file_gamma for PC images to .50 from .51 in
-      example.c and libpng.txt, and changed file_gamma for sRGB images to .45
-   added a number of functions to access information from the png structure
-      png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
-   added TARGET_MACOS similar to zlib-1.0.8
-   define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
-   added type casting to all png_malloc() function calls
+  free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
+  fixed a longstanding "packswap" bug in pngtrans.c
+  fixed some inconsistencies in pngconf.h that prevented compiling with
+     PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
+  fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
+  changed recommendation about file_gamma for PC images to .50 from .51 in
+     example.c and libpng.txt, and changed file_gamma for sRGB images to .45
+  added a number of functions to access information from the png structure
+     png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
+  added TARGET_MACOS similar to zlib-1.0.8
+  define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
+  added type casting to all png_malloc() function calls
 version 0.99a [January 31, 1998]
-   Added type casts and parentheses to all returns that return a value.(Tim W.)
+  Added type casts and parentheses to all returns that return a value.(Tim W.)
 version 0.99b [February 4, 1998]
-   Added type cast png_uint_32 on malloc function calls where needed.
-   Changed type of num_hist from png_uint_32 to int (same as num_palette).
-   Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
-   Renamed makefile.elf to makefile.lnx.
+  Added type cast png_uint_32 on malloc function calls where needed.
+  Changed type of num_hist from png_uint_32 to int (same as num_palette).
+  Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
+  Renamed makefile.elf to makefile.lnx.
 version 0.99c [February 7, 1998]
-   More type casting.  Removed erroneous overflow test in pngmem.c.
-   Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.
-   Added UNIX manual pages libpng.3 (incorporating libpng.txt) and  png.5.
+  More type casting.  Removed erroneous overflow test in pngmem.c.
+  Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.
+  Added UNIX manual pages libpng.3 (incorporating libpng.txt) and  png.5.
 version 0.99d [February 11, 1998]
-   Renamed "far_to_near()" "png_far_to_near()"
-   Revised libpng.3
-   Version 99c "buffered" operations didn't work as intended.  Replaced them
-     with png_memcpy_check() and png_memset_check().
-   Added many "if (png_ptr == NULL) return" to quell compiler warnings about
-     unused png_ptr, mostly in pngget.c and pngset.c.
-   Check for overlength tRNS chunk present when indexed-color PLTE is read.
-   Cleaned up spelling errors in libpng.3/libpng.txt
-   Corrected a problem with png_get_tRNS() which returned undefined trans array
+  Renamed "far_to_near()" "png_far_to_near()"
+  Revised libpng.3
+  Version 99c "buffered" operations didn't work as intended.  Replaced them
+    with png_memcpy_check() and png_memset_check().
+  Added many "if (png_ptr == NULL) return" to quell compiler warnings about
+    unused png_ptr, mostly in pngget.c and pngset.c.
+  Check for overlength tRNS chunk present when indexed-color PLTE is read.
+  Cleaned up spelling errors in libpng.3/libpng.txt
+  Corrected a problem with png_get_tRNS() which returned undefined trans array
 version 0.99e [February 28, 1998]
-   Corrected png_get_tRNS() again.
-   Add parentheses for easier reading of pngget.c, fixed "||" should be "&&".
-   Touched up example.c to make more of it compileable, although the entire
-     file still can't be compiled (Willem van Schaik)
-   Fixed a bug in png_do_shift() (Bryan Tsai)
-   Added a space in png.h prototype for png_write_chunk_start()
-   Replaced pngtest.png with one created with zlib 1.1.1
-   Changed pngtest to report PASS even when file size is different (Jean-loup G.)
-   Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)
+  Corrected png_get_tRNS() again.
+  Add parentheses for easier reading of pngget.c, fixed "||" should be "&&".
+  Touched up example.c to make more of it compileable, although the entire
+    file still can't be compiled (Willem van Schaik)
+  Fixed a bug in png_do_shift() (Bryan Tsai)
+  Added a space in png.h prototype for png_write_chunk_start()
+  Replaced pngtest.png with one created with zlib 1.1.1
+  Changed pngtest to report PASS even when file size is different (Jean-loup G.)
+  Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)
 version 0.99f [March 5, 1998]
-   Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)
-   Moved makefiles into a "scripts" directory, and added INSTALL instruction file
-   Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok)
-   Added pointers to "note on libpng versions" in makefile.lnx and README
-   Added row callback feature when reading and writing nonprogressive rows
-      and added a test of this feature in pngtest.c
-   Added user transform callbacks, with test of the feature in pngtest.c
+  Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)
+  Moved makefiles into a "scripts" directory, and added INSTALL instruction file
+  Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok)
+  Added pointers to "note on libpng versions" in makefile.lnx and README
+  Added row callback feature when reading and writing nonprogressive rows
+     and added a test of this feature in pngtest.c
+  Added user transform callbacks, with test of the feature in pngtest.c
 version 0.99g [March 6, 1998, morning]
-   Minor changes to pngtest.c to suppress compiler warnings.
-   Removed "beta" language from documentation.
+  Minor changes to pngtest.c to suppress compiler warnings.
+  Removed "beta" language from documentation.
 version 0.99h [March 6, 1998, evening]
-   Minor changes to previous minor changes to pngtest.c 
-   Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED
-   and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro
+  Minor changes to previous minor changes to pngtest.c 
+  Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED
+  and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro
 version 1.00 [March 7, 1998]
-   Changed several typedefs in pngrutil.c
-   Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)
-   replaced "while(1)" with "for(;;)"
-   added PNGARG() to prototypes in pngtest.c and removed some prototypes
-   updated some of the makefiles (Tom Lane)
-   changed some typedefs (s_start, etc.) in pngrutil.c
-   fixed dimensions of "short_months" array in pngwrite.c
-   Replaced ansi2knr.c with the one from jpeg-v6
+  Changed several typedefs in pngrutil.c
+  Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)
+  replaced "while(1)" with "for(;;)"
+  added PNGARG() to prototypes in pngtest.c and removed some prototypes
+  updated some of the makefiles (Tom Lane)
+  changed some typedefs (s_start, etc.) in pngrutil.c
+  fixed dimensions of "short_months" array in pngwrite.c
+  Replaced ansi2knr.c with the one from jpeg-v6
 version 1.0.0 [March 8, 1998]
-   Changed name from 1.00 to 1.0.0 (Adam Costello)
-   Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert)
+  Changed name from 1.00 to 1.0.0 (Adam Costello)
+  Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert)
 version 1.0.0a [March 9, 1998]
-   Fixed three bugs in pngrtran.c to make gamma+background handling consistent
-   (Greg Roelofs)
-   Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz
-   for major, minor, and bugfix releases.  This is 10001. (Adam Costello,
-   Tom Lane)
-   Make months range from 1-12 in png_convert_to_rfc1123
+  Fixed three bugs in pngrtran.c to make gamma+background handling consistent
+  (Greg Roelofs)
+  Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz
+  for major, minor, and bugfix releases.  This is 10001. (Adam Costello,
+  Tom Lane)
+  Make months range from 1-12 in png_convert_to_rfc1123
 version 1.0.0b [March 13, 1998]
-   Quieted compiler complaints about two empty "for" loops in pngrutil.c
-   Minor changes to makefile.s2x
-   Removed #ifdef/#endif around a png_free() in pngread.c
+  Quieted compiler complaints about two empty "for" loops in pngrutil.c
+  Minor changes to makefile.s2x
+  Removed #ifdef/#endif around a png_free() in pngread.c
 version 1.0.1 [March 14, 1998]
-   Changes makefile.s2x to reduce security risk of using a relative pathname
-   Fixed some typos in the documentation (Greg).
-   Fixed a problem with value of "channels" returned by png_read_update_info()
+  Changed makefile.s2x to reduce security risk of using a relative pathname
+  Fixed some typos in the documentation (Greg).
+  Fixed a problem with value of "channels" returned by png_read_update_info()
+version 1.0.1a [April 21, 1998]
+  Optimized Paeth calculations by replacing abs() function calls with intrinsics
+  plus other loop optimizations. Improves avg decoding speed by about 20%.
+  Commented out i386istic "align" compiler flags in makefile.lnx.
+  Reduced the default warning level in some makefiles, to make them consistent.
+  Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
+  Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
+  Added grayscale and 16-bit capability to png_do_read_filler().
+  Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
+    too large when writing an image with bit_depth < 8 (Bob Dellaca).
+  Corrected some bugs in the experimental weighted filtering heuristics.
+  Moved a misplaced pngrutil code block that truncates tRNS if it has more
+    than num_palette entries -- test was done before num_palette was defined.
+  Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
+  Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen)
diff --git a/INSTALL b/INSTALL
index 4978740..803e9fb 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
 
-Installing libpng version 1.0.1 March 15, 1998
+Installing libpng version %VER% %DATE%
 
 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.1 or "lpng100" and "zlib-1.1.1"
+might be called "libpng-%VER% or "lpng100" and "zlib-1.1.1"
 or "zlib111") so that you have directories called "zlib" and "libpng".
 
 Your directory structure should look like this:
diff --git a/KNOWNBUG b/KNOWNBUG
new file mode 100644
index 0000000..205f5fd
--- /dev/null
+++ b/KNOWNBUG
@@ -0,0 +1,113 @@
+
+Known bugs and suggested enhancements in libpng-1.0.1
+
+1. March 13, 1998 -- BUG -- pngtrans.c:
+
+   row_info->channels should be updated --
+   row_info->color_type should be updated --
+
+   STATUS: I think this is all fixed in libpng-1.0.1a but needs
+   to be tested.
+
+2. March 14, 1998 -- ENHANCEMENT -- Glenn
+
+   We should add the G>GA, G>GX, G>AG, and G>XG transformations
+   in png_do_read_filler()
+
+   STATUS:  Implemented in libpng-1.0.1a
+
+3. March 14, 1998 -- BUG? -- Greg Roelofs
+
+   pngrtran.c:  if-test for channels/FILLER may be incorrect
+
+   STATUS: Under investigation
+
+4. March 15, 1998 -- BUG -- Kevin Bracey
+
+   pngwtran.c:
+      line 306: loop should count to row_info->width, not to
+             row_info->width*row_info->channnels
+
+   STATUS: Fixed in libpng-1.0.1a
+
+5. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
+
+   Loops need to be optimized everywhere
+
+   a. Make them count down instead of up -- Kevin Bracey
+   
+      Optimizing compilers don't need this, and making
+      the change would be error prone -- Tom Lane, Glenn R-P
+
+      Question whether i-- or --i is better.
+
+      STATUS: Under investigation.
+
+   b. Remove products and structure members from loop tests -- Glenn R-P
+
+      Can be accomplished without messing with loop guts.  This
+      was shown to be effective on optimized SGI compiler:
+
+              replace
+                  png_uint_32 i;
+                  for(i=0; i < s->a*s->b; i++)
+              with
+                  png_uint_32 i, count;
+                  istop = s->a*s->b;
+                  for(i=0; i<istop; i++)
+
+      STATUS: Mostly done in libpng-1.0.1a, done for all important loops.
+
+   c. Replace abs() with intrinsic ternary operations in Paeth
+      filtering -- Glenn R-P
+
+      STATUS: Done in libpng-1.0.1a
+      (can be restored to original behavior with #define PNG_USE_ABS)
+
+   d. In pngwutil.c, make separate simple loops to use when filter 
+      heuristic sums aren't needed. -- Glenn R-P
+
+      STATUS: Done in libpng-1.0.1a
+
+6. April 6, 1998 -- BUG -- bug in pngset.c (rowbytes too large) -- Bob Dellaca
+
+   pngset.c has a bug, introduced in version 0.99c, that sets rowbytes
+     too large when writing an image with bit_depth < 8
+
+   STATUS: Fixed in libpng-1.0.1a
+              
+7. April 10, 1998 -- BUG -- pngwutil weighted filtering bugs -- Glenn R-P
+
+   pngwutil.c has some bugs in the experimental weighted filter
+   algorithm (PNG_FILTER_XXX should be PNG_FILTER_VALUE_XXX in
+   several places)
+
+   STATUS: Andreas concurs.  Fixed in libpng-1.0.1a
+
+8. April 10, 1998 -- ENHANCEMENT -- run-time selection of malloc function
+   -- Bob Dellaca
+
+   pngmem.c currently provides a compile-time option to replace
+   png_malloc() and png_free().  It's been requested that these
+   be made possible at run time, via calls to new png_set_malloc_fn()
+   and png_set_free_fn() functions.
+
+   STATUS: Will do in libpng-1.0.1b
+
+9. April 11, 1998 -- BUG -- incorrect truncation of tRNS data in
+   illegal PNG file where tRNS precedes PLTE -- Larry Reeve
+
+   There is a misplaced pngrutil code block that truncates tRNS if it has
+   more than num_palette entries -- test was done before num_palette was
+   defined.  Although the PNG file is illegal, it shouldn't crash apps.
+   There is a simple fix; just moving the test to the point after
+   num_palette has been defined.
+
+   STATUS: Fixed in libpng-1.0.1a
+
+10. April 16, 1998 -- BUG -- incorrect operation of png_convert_to_rfc1123
+   with 31st day of the month -- Steve Eddins
+
+   The "ptime->date % 31" is wrong, should be "ptime->date % 32".
+
+   STATUS: Fixed in libpng-1.0.1a
diff --git a/README b/README
index ea463cd..e2c4ffe 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng 1.0.1 (shared library 2.1)
+README for libpng %VER% (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.
diff --git a/TODO b/TODO
index 562859a..21f963a 100644
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@
 
 fix problem with C++ and EXTERN "C"
 add "grayscale->palette" transformation and "palette->grayscale" detection
-add "grayscale" -> "grayscale+alpha" and "grayscale+FILLER" transformations
 improved dithering
 multi-lingual error and warning message support
 sPLT chunk handling
diff --git a/ansi2knr.c b/ansi2knr.c
index 4e05fc2..dfb29a2 100644
--- a/ansi2knr.c
+++ b/ansi2knr.c
@@ -1,7 +1,9 @@
 /* ansi2knr.c */
-/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
 
-/*
+/* Convert ANSI C function definitions to K&R ("traditional C") syntax
+Copyright (C) 1989 Aladdin Enterprises.  All rights reserved.
+Copyright (C) 1988 Richard M. Stallman
+
 ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
 WARRANTY.  No author or distributor accepts responsibility to anyone for the
 consequences of using it or for whether it serves any particular purpose or
@@ -12,12 +14,12 @@
 but only under the conditions described in the GPL.  A copy of this license
 is supposed to have been given to you along with ansi2knr so you can know
 your rights and responsibilities.  It should be in a file named COPYLEFT.
-[In the IJG distribution, the GPL appears below, not in a separate file.]
+[In the LIBPNG distribution, the GPL appears below, not in a separate file.]
 Among other things, the copyright notice and this notice must be preserved
 on all copies.
 
 We explicitly state here what we believe is already implied by the GPL: if
-the ansi2knr program is distributed as a separate set of sources and a
+the ansi2knr program is distributed as a separate source file and a
 separate executable file which are aggregated on a storage medium together
 with another program, this in itself does not bring the other program under
 the GPL, nor does the mere fact that such a program or the procedures for
@@ -27,7 +29,7 @@
 
 /*
 ---------- Here is the GNU GPL file COPYLEFT, referred to above ----------
------ These terms do NOT apply to the JPEG software itself; see README ------
+----- These terms do NOT apply to the LIBPNG software itself; see README ------
 
 		    GHOSTSCRIPT GENERAL PUBLIC LICENSE
 		    (Clarified 11 Feb 1988)
diff --git a/libpng.3 b/libpng.3
index 88d8c96..34866ba 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,4 +1,4 @@
-.TH LIBPNG 3 "March 15, 1998"
+.TH LIBPNG 3 "April 21, 1998"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library
 .SH SYNOPSIS
@@ -396,7 +396,7 @@
 .SH LIBPNG.TXT
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.0.1 March 15, 1998
+ libpng version 1.0.1a April 21, 1998
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alumni.rpi.edu>
  Copyright (c) 1998, Glenn Randers-Pehrson
@@ -872,11 +872,14 @@
 For example, 4 bit/pixel paletted or grayscale data will be returned
 2 pixels/byte with the leftmost pixel in the high-order bits of the
 byte, unless png_set_packing() is called.  8-bit RGB data will be stored
-in RGBRGBRGB format unless png_set_filler() is called to insert filler
+in RGB RGB RGB format unless png_set_filler() is called to insert filler
 bytes, either before or after each RGB triplet.  16-bit RGB data will
-be returned RRGGBBRRGGBB, with the most significant byte of the color
+be returned RRGGBB RRGGBB, with the most significant byte of the color
 value first, unless png_set_strip_16() is called to transform it to
-regular RGBRGB triplets.
+regular RGB RGB triplets, or png_set_filler() is called to insert
+filler bytes, either before or after each RRGGBB triplet.  Similarly,
+8-bit or 16-bit grayscale data can be modified with png_set_filler()
+or png_set_strip_16().
 
 The following code transforms grayscale images of less than 8 to 8 bits,
 changes paletted images to RGB, and adds a full alpha channel if there is
@@ -952,7 +955,7 @@
         PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr,
         filler, PNG_FILLER_BEFORE);
 
-where "filler" is the number to fill with, and the location is
+where "filler" is the 8 or 16-bit number to fill with, and the location is
 either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
 you want the filler before the RGB or after.  This transformation
 does not affect images that already have full alpha channels.
@@ -1412,6 +1415,8 @@
      */
  }
 
+
+
 .SH IV. Writing
 
 Much of this is very similar to reading.  However, everything of
@@ -1504,9 +1509,9 @@
 speed/compression ratio. The second parameter to png_set_filter() is
 the filter method, for which the only valid value is '0' (as of the
 October 1996 PNG specification, version 1.0).  The third parameter is a
-flag that indicates
-which filter type(s) are to be tested for each scanline.  See the
-Compression Library for details on the specific filter types.
+flag that indicates which filter type(s) are to be tested for each
+scanline.  See the Compression Library for details on the specific filter
+types.
 
     
     /* turn on or off filtering, and/or choose
@@ -1780,8 +1785,9 @@
 make sure to only enable a transformation if it will be valid for the
 data.  For example, don't swap red and blue on grayscale data.
 
-PNG files store RGB pixels packed into 3 bytes.  This code tells
-the library to expect input data with 4 bytes per pixel
+PNG files store RGB pixels packed into 3 or 6 bytes.  This code tells
+the library to expand the input data to 4 or 8 bytes per pixel
+(or expand 1 or 2-byte grayscale data to 2 or 4 bytes per pixel).
 
     png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
 
@@ -1899,11 +1905,11 @@
 
 where row_pointers is:
 
-    png_bytef *row_pointers[height];
+    png_byte *row_pointers[height];
 
 You can point to void or char or whatever you use for pixels.
 
-If you can't want to write the whole image at once, you can
+If you don't want to write the whole image at once, you can
 use png_write_rows() instead.  If the file is not interlaced,
 this is simple:
 
@@ -2366,7 +2372,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
   
-Libpng version 1.0.1 March 15, 1998:
+Libpng version 1.0.1a April 21, 1998:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (randeg@alumni.rpi.edu).
 
diff --git a/libpng.txt b/libpng.txt
index df8f4e6..f0a5f6e 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.1 March 15, 1998
+ libpng version 1.0.1a April 21, 1998
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alumni.rpi.edu>
  Copyright (c) 1998, Glenn Randers-Pehrson
@@ -22,7 +22,7 @@
  Copyright (c) 1995 Frank J. T. Wojcik
  December 18, 1995 && January 20, 1996
 
-Introduction
+I. Introduction
 
 This file describes how to use and modify the PNG reference library
 (known as libpng) for your own use.  There are five sections to this
@@ -476,11 +476,14 @@
 For example, 4 bit/pixel paletted or grayscale data will be returned
 2 pixels/byte with the leftmost pixel in the high-order bits of the
 byte, unless png_set_packing() is called.  8-bit RGB data will be stored
-in RGBRGBRGB format unless png_set_filler() is called to insert filler
+in RGB RGB RGB format unless png_set_filler() is called to insert filler
 bytes, either before or after each RGB triplet.  16-bit RGB data will
-be returned RRGGBBRRGGBB, with the most significant byte of the color
+be returned RRGGBB RRGGBB, with the most significant byte of the color
 value first, unless png_set_strip_16() is called to transform it to
-regular RGBRGB triplets.
+regular RGB RGB triplets, or png_set_filler() is called to insert
+filler bytes, either before or after each RRGGBB triplet.  Similarly,
+8-bit or 16-bit grayscale data can be modified with png_set_filler()
+or png_set_strip_16().
 
 The following code transforms grayscale images of less than 8 to 8 bits,
 changes paletted images to RGB, and adds a full alpha channel if there is
@@ -556,7 +559,7 @@
         PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr,
         filler, PNG_FILLER_BEFORE);
 
-where "filler" is the number to fill with, and the location is
+where "filler" is the 8 or 16-bit number to fill with, and the location is
 either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
 you want the filler before the RGB or after.  This transformation
 does not affect images that already have full alpha channels.
@@ -1110,9 +1113,9 @@
 speed/compression ratio. The second parameter to png_set_filter() is
 the filter method, for which the only valid value is '0' (as of the
 October 1996 PNG specification, version 1.0).  The third parameter is a
-flag that indicates
-which filter type(s) are to be tested for each scanline.  See the
-Compression Library for details on the specific filter types.
+flag that indicates which filter type(s) are to be tested for each
+scanline.  See the Compression Library for details on the specific filter
+types.
 
     
     /* turn on or off filtering, and/or choose
@@ -1386,8 +1389,9 @@
 make sure to only enable a transformation if it will be valid for the
 data.  For example, don't swap red and blue on grayscale data.
 
-PNG files store RGB pixels packed into 3 bytes.  This code tells
-the library to expect input data with 4 bytes per pixel
+PNG files store RGB pixels packed into 3 or 6 bytes.  This code tells
+the library to expand the input data to 4 or 8 bytes per pixel
+(or expand 1 or 2-byte grayscale data to 2 or 4 bytes per pixel).
 
     png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
 
@@ -1505,11 +1509,11 @@
 
 where row_pointers is:
 
-    png_bytef *row_pointers[height];
+    png_byte *row_pointers[height];
 
 You can point to void or char or whatever you use for pixels.
 
-If you can't want to write the whole image at once, you can
+If you don't want to write the whole image at once, you can
 use png_write_rows() instead.  If the file is not interlaced,
 this is simple:
 
@@ -1886,4 +1890,3 @@
 png_set_error_fn(), which is essentially the same function, but with a
 new name to force compilation errors with applications that try to use
 the old method.
-
diff --git a/libpngpf.3 b/libpngpf.3
index 7ba582e..387f898 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "March 15, 1998"
+.TH LIBPNGPF 3 "April 21, 1998"
 .SH NAME
 libpng \- Portable Network Graphics (PNG) Reference Library
 (private functions)
diff --git a/png.5 b/png.5
index 30244aa..5ba2495 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "March 15, 1998"
+.TH PNG 5 "April 21, 1998"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 127b47b..513212a 100644
--- a/png.c
+++ b/png.c
@@ -1,12 +1,12 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 #define PNG_INTERNAL
@@ -16,7 +16,7 @@
 /* Version information for C files.  This had better match the version
  * string defined in png.h.
  */
-char png_libpng_ver[12] = "1.0.1";
+char png_libpng_ver[12] = "1.0.1a";
 
 /* Place to hold the signature string for a PNG file. */
 png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
diff --git a/png.h b/png.h
index 36541e9..b84a787 100644
--- a/png.h
+++ b/png.h
@@ -1,12 +1,12 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * For conditions of distribution and use, see the COPYRIGHT NOTICE below.
  * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  * Copyright (c) 1996, 1997 Andreas Dilger
  * Copyright (c) 1998 Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * Note about libpng version numbers:
  *
@@ -31,6 +31,7 @@
  *      1.00                      1.00       100  2.1.0 [int should be 10000]
  *      1.0.0                     1.0.0      100  2.1.0 [int should be 10000]
  *      1.0.1                     1.0.1    10001  2.1.0
+ *      1.0.1a                    1.0.1a   10002  2.1.0
  *
  *    Henceforth the source version will match the shared-library minor
  *    and patch numbers; the shared-library major version number will be
@@ -38,10 +39,9 @@
  *    The PNG_PNGLIB_VER macro, which is not used within libpng but
  *    is available for applications, is an unsigned integer of the form
  *    xyyzz corresponding to the source version x.y.z (leading zeros in y and z).
- *    
  *
- * See libpng.txt for more information.  The PNG specification is available
- * as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
+ * See libpng.txt or libpng.3 for more information.  The PNG specification is
+ * available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
  * and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
  *
  * Contributing Authors:
@@ -118,14 +118,14 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.0.1"
+#define PNG_LIBPNG_VER_STRING "1.0.1a"
 
 /* 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    10001  /* 1.0.1 */
+#define PNG_LIBPNG_VER    10002  /* 1.0.2 */
 
 /* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
 #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
@@ -589,7 +589,7 @@
    png_byte sig_bytes;        /* magic bytes read/written from start of file */
 
 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
-   png_byte filler;           /* filler byte for 24->32-bit pixel expansion */
+   png_uint_16 filler;           /* filler bytes for pixel expansion */
 #endif /* PNG_READ_FILLER_SUPPORTED */
 #if defined(PNG_READ_bKGD_SUPPORTED)
    png_byte background_gamma_type;
@@ -1590,7 +1590,7 @@
 #endif /* PNG_READ_pCAL_SUPPORTED */
 PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
 PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
-#endif /* PNG_BIG_ENDIAN_GET_SUPPORTED */
+#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
 
 /* Initialize png_ptr struct for reading, and allocate any other memory.
  * (old interface - NOT DLL EXPORTED).
diff --git a/pngconf.h b/pngconf.h
index 675f292..cf92132 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,12 +1,12 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 /* Any machine specific code is near the front of this file, so if you
diff --git a/pngerror.c b/pngerror.c
index 9bf58a4..4d22113 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -1,12 +1,12 @@
 
 /* pngerror.c - stub functions for i/o and memory allocation
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * This file provides a location for all error handling.  Users which
  * need special error handling are expected to write replacement functions
diff --git a/pngget.c b/pngget.c
index eb2f64f..0dab0dd 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,12 +1,12 @@
 
 /* pngget.c - retrieval of values from info struct
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 #define PNG_INTERNAL
diff --git a/pngmem.c b/pngmem.c
index 2fa3627..2c0537f 100644
--- a/pngmem.c
+++ b/pngmem.c
@@ -1,14 +1,14 @@
 
 /* pngmem.c - stub functions for memory allocation
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
- * This file provides a location for all memory allocation.  Users which
+ * This file provides a location for all memory allocation.  Users who
  * need special memory handling are expected to modify the code in this file
  * to meet their needs.  See the instructions at each function.
  */
diff --git a/pngpread.c b/pngpread.c
index 0f0d466..5a1812b 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1,12 +1,12 @@
 
 /* pngpread.c - read a png file in push mode
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 #define PNG_INTERNAL
@@ -446,13 +446,13 @@
    {
       if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
       {
-         png_size_t i;
+         png_size_t i,istop;
          png_bytep sp;
          png_bytep dp;
 
+         istop = png_ptr->save_buffer_size;
          for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
-            i < png_ptr->save_buffer_size;
-            i++, sp++, dp++)
+            i < istop; i++, sp++, dp++)
          {
             *dp = *sp;
          }
diff --git a/pngread.c b/pngread.c
index 1618b73..70a2af5 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,12 +1,12 @@
 
 /* pngread.c - read a PNG file
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * This file contains routines that an application calls directly to
  * read a PNG file or stream.
@@ -125,7 +125,7 @@
 /* Read the information before the actual image data.  This has been
  * changed in v0.90 to allow reading a file that already has the magic
  * bytes read from the stream.  You can tell libpng how many bytes have
- * been read from the beginning of the stream (up to the maxumum of 8)
+ * been read from the beginning of the stream (up to the maximum of 8)
  * via png_set_sig_bytes(), and we will only check the remaining bytes
  * here.  The application can then have access to the signature bytes we
  * read if it is determined that this isn't a valid PNG file.
@@ -522,7 +522,7 @@
 void
 png_read_image(png_structp png_ptr, png_bytepp image)
 {
-   png_uint_32 i;
+   png_uint_32 i,image_height;
    int pass, j;
    png_bytepp rp;
 
@@ -530,12 +530,13 @@
    /* save jump buffer and error functions */
    pass = png_set_interlace_handling(png_ptr);
 
-   png_ptr->num_rows = png_ptr->height; /* Make sure this is set correctly */
+   image_height=png_ptr->height;
+   png_ptr->num_rows = image_height; /* Make sure this is set correctly */
 
    for (j = 0; j < pass; j++)
    {
       rp = image;
-      for (i = 0; i < png_ptr->height; i++)
+      for (i = 0; i < image_height; i++)
       {
          png_read_row(png_ptr, *rp, NULL);
          rp++;
@@ -728,8 +729,9 @@
 #if defined(PNG_READ_GAMMA_SUPPORTED)
    if (png_ptr->gamma_16_table != NULL)
    {
-      int i;
-      for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
+      int i,istop;
+      istop = (1 << (8 - png_ptr->gamma_shift));
+      for (i = 0; i < istop; i++)
       {
          png_free(png_ptr, png_ptr->gamma_16_table[i]);
       }
@@ -739,8 +741,9 @@
    png_free(png_ptr, png_ptr->gamma_16_table);
    if (png_ptr->gamma_16_from_1 != NULL)
    {
-      int i;
-      for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
+      int i,istop;
+      istop = (1 << (8 - png_ptr->gamma_shift));
+      for (i = 0; i < istop; i++)
       {
          png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
       }
@@ -748,8 +751,9 @@
    png_free(png_ptr, png_ptr->gamma_16_from_1);
    if (png_ptr->gamma_16_to_1 != NULL)
    {
-      int i;
-      for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
+      int i,istop;
+      istop = (1 << (8 - png_ptr->gamma_shift));
+      for (i = 0; i < istop; i++)
       {
          png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
       }
diff --git a/pngrio.c b/pngrio.c
index 7adb48f..d0a4646 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -1,12 +1,12 @@
 
 /* pngrio.c - functions for data input
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * This file provides a location for all input.  Users which need
  * special handling are expected to write a function which has the same
diff --git a/pngrtran.c b/pngrtran.c
index 885af53..1b925a7 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,12 +1,12 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * This file contains functions optionally called by an application 
  * in order to tell libpng how to handle data when reading a PNG.
@@ -670,8 +670,9 @@
            {
            /* invert the alpha channel (in tRNS) unless the pixels are 
               going to be expanded, in which case leave it for later */
-              int i;
-              for (i=0; i<(int)png_ptr->num_trans; i++)
+              int i,istop;
+              istop=(int)png_ptr->num_trans;
+              for (i=0; i<istop; i++)
                  png_ptr->trans[i] = 255 - png_ptr->trans[i];
            }
         }
@@ -872,7 +873,7 @@
    if (png_ptr->transformations & PNG_BACKGROUND &&
        color_type == PNG_COLOR_TYPE_PALETTE)
    {
-      int i;
+      int i,istop;
       png_color back;
       png_colorp palette;
 
@@ -881,7 +882,8 @@
       back.green = (png_byte)png_ptr->background.green;
       back.blue  = (png_byte)png_ptr->background.blue;
 
-      for (i = 0; i < (int)png_ptr->num_trans; i++)
+      istop = (int)png_ptr->num_trans;
+      for (i = 0; i < istop; i++)
       {
          if (png_ptr->trans[i] == 0)
          {
@@ -904,7 +906,7 @@
    if ((png_ptr->transformations & PNG_SHIFT) &&
       color_type == PNG_COLOR_TYPE_PALETTE)
    {
-      png_uint_16 i;
+      png_uint_16 i,istop;
       int sr, sg, sb;
 
       sr = 8 - png_ptr->sig_bit.red;
@@ -916,7 +918,8 @@
       sb = 8 - png_ptr->sig_bit.blue;
       if (sb < 0 || sb > 8)
          sb = 0;
-      for (i = 0; i < png_ptr->num_palette; i++)
+      istop = png_ptr->num_palette;
+      for (i = 0; i < istop; i++)
       {
          png_ptr->palette[i].red >>= sr;
          png_ptr->palette[i].green >>= sg;
@@ -1006,11 +1009,14 @@
 #endif
 
 #if defined(PNG_READ_FILLER_SUPPORTED)
-   if ((png_ptr->transformations & PNG_FILLER) &&
-       info_ptr->color_type & PNG_COLOR_TYPE_RGB &&
-       info_ptr->channels == 3)
+   if (png_ptr->transformations & PNG_FILLER)
    {
-      info_ptr->channels = 4;
+       if((info_ptr->color_type & PNG_COLOR_TYPE_RGB) &&
+          info_ptr->channels == 3)
+             info_ptr->channels = 4;
+       if((info_ptr->color_type & PNG_COLOR_TYPE_GRAY) &&
+          info_ptr->channels == 1)
+             info_ptr->channels = 2;
    }
 #endif
 
@@ -1200,16 +1206,17 @@
 #endif
    {
       png_uint_32 shift, i;
+      png_uint_32 row_width=row_info->width;
       png_bytep sp, dp;
 
       switch (row_info->bit_depth)
       {
          case 1:
          {
-            sp = row + (png_size_t)((row_info->width - 1) >> 3);
-            dp = row + (png_size_t)row_info->width - 1;
-            shift = 7 - (int)((row_info->width + 7) & 7);
-            for (i = 0; i < row_info->width; i++)
+            sp = row + (png_size_t)((row_width - 1) >> 3);
+            dp = row + (png_size_t)row_width - 1;
+            shift = 7 - (int)((row_width + 7) & 7);
+            for (i = 0; i < row_width; i++)
             {
                *dp = (png_byte)((*sp >> shift) & 0x1);
                if (shift == 7)
@@ -1227,10 +1234,10 @@
          case 2:
          {
 
-            sp = row + (png_size_t)((row_info->width - 1) >> 2);
-            dp = row + (png_size_t)row_info->width - 1;
-            shift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
-            for (i = 0; i < row_info->width; i++)
+            sp = row + (png_size_t)((row_width - 1) >> 2);
+            dp = row + (png_size_t)row_width - 1;
+            shift = (int)((3 - ((row_width + 3) & 3)) << 1);
+            for (i = 0; i < row_width; i++)
             {
                *dp = (png_byte)((*sp >> shift) & 0x3);
                if (shift == 6)
@@ -1247,10 +1254,10 @@
          }
          case 4:
          {
-            sp = row + (png_size_t)((row_info->width - 1) >> 1);
-            dp = row + (png_size_t)row_info->width - 1;
-            shift = (int)((1 - ((row_info->width + 1) & 1)) << 2);
-            for (i = 0; i < row_info->width; i++)
+            sp = row + (png_size_t)((row_width - 1) >> 1);
+            dp = row + (png_size_t)row_width - 1;
+            shift = (int)((1 - ((row_width + 1) & 1)) << 2);
+            for (i = 0; i < row_width; i++)
             {
                *dp = (png_byte)((*sp >> shift) & 0xf);
                if (shift == 4)
@@ -1268,7 +1275,7 @@
       }
       row_info->bit_depth = 8;
       row_info->pixel_depth = (png_byte)(8 * row_info->channels);
-      row_info->rowbytes = row_info->width * row_info->channels;
+      row_info->rowbytes = row_width * row_info->channels;
    }
 }
 #endif
@@ -1292,6 +1299,7 @@
       int shift[4];
       int channels, c;
       png_uint_16 value;
+      png_uint_32 row_width = row_info->width;
 
       channels = 0;
       if (row_info->color_type & PNG_COLOR_MASK_COLOR)
@@ -1327,9 +1335,10 @@
          case 2:
          {
             png_bytep bp;
-            png_uint_32 i;
+            png_uint_32 i,istop;
 
-            for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++)
+            istop = row_info->rowbytes;
+            for (bp = row, i = 0; i < istop; i++, bp++)
             {
                *bp >>= 1;
                *bp &= 0x55;
@@ -1340,11 +1349,12 @@
          {
             png_bytep bp;
             png_byte mask;
-            png_uint_32 i;
+            png_uint_32 i,istop;
 
             mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
                (png_byte)((int)0xf >> shift[0]);
-            for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++)
+            istop = row_info->rowbytes;
+            for (bp = row, i = 0; i < istop; i++, bp++)
             {
                *bp >>= shift[0];
                *bp &= mask;
@@ -1355,10 +1365,12 @@
          {
             png_bytep bp;
             png_uint_32 i;
+            int cstop;
 
-            for (bp = row, i = 0; i < row_info->width; i++)
+            cstop=(int)row_info->channels;
+            for (bp = row, i = 0; i < row_width; i++)
             {
-               for (c = 0; c < (int)row_info->channels; c++, bp++)
+               for (c = 0; c < cstop; c++, bp++)
                {
                   *bp >>= shift[c];
                }
@@ -1369,10 +1381,12 @@
          {
             png_bytep bp;
             png_size_t i;
+            int cstop;
 
-            for (bp = row, i = 0; i < row_info->width; i++)
+            cstop=(int)row_info->channels;
+            for (bp = row, i = 0; i < row_width; i++)
             {
-               for (c = 0; c < (int)row_info->channels; c++, bp += 2)
+               for (c = 0; c < cstop; c++, bp += 2)
                {
                   value = (png_uint_16)((*bp << 8) + *(bp + 1));
                   value >>= shift[c];
@@ -1400,37 +1414,39 @@
 #endif
    {
       png_bytep sp, dp;
-      png_uint_32 i;
+      png_uint_32 i, istop;
 
       sp = row;
       dp = row;
-      for (i = 0; i < row_info->width * row_info->channels; i++, sp += 2, dp++)
+      istop = row_info->width * row_info->channels;
+      for (i = 0; i<istop; i++, sp += 2, dp++)
       {
 #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
-         /* This does a more accurate scaling of the 16-bit color
-          * value, rather than a simple low-byte truncation.
-          *
-          * What the ideal calculation should be:
-         *dp = (((((png_uint_32)(*sp) << 8) |
-                   (png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L;
+      /* This does a more accurate scaling of the 16-bit color
+       * value, rather than a simple low-byte truncation.
+       *
+       * What the ideal calculation should be:
+       *   *dp = (((((png_uint_32)(*sp) << 8) |
+       *          (png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L;
+       *
+       * GRR: no, I think this is what it really should be:
+       *   *dp = (((((png_uint_32)(*sp) << 8) |
+       *           (png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L;
+       *
+       * GRR: here's the exact calculation with shifts:
+       *   temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L;
+       *   *dp = (temp - (temp >> 8)) >> 8;
+       *
+       * Approximate calculation with shift/add instead of multiply/divide:
+       *   *dp = ((((png_uint_32)(*sp) << 8) |
+       *          (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8;
+       *
+       * What we actually do to avoid extra shifting and conversion:
+       */
 
-
-          * GRR: no, I think this is what it really should be:
-         *dp = (((((png_uint_32)(*sp) << 8) |
-                   (png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L;
-
-          * GRR: here's the exact calculation with shifts:
-         temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L;
-         *dp = (temp - (temp >> 8)) >> 8;
-
-
-          * Approximate calculation with shift/add instead of multiply/divide:
-         *dp = ((((png_uint_32)(*sp) << 8) |
-                  (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8;
-
-          * What we actually do to avoid extra shifting and conversion: */
          *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
 #else
+       /* Simply discard the low order byte */
          *dp = *sp;
 #endif
       }
@@ -1450,6 +1466,7 @@
    if (row != NULL && row_info != NULL)
 #endif
    {
+      png_uint_32 row_width = row_info->width;
       if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
       {
          /* This converts from RGBA to ARGB */
@@ -1458,9 +1475,8 @@
             png_bytep sp, dp;
             png_byte save;
             png_uint_32 i;
-
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                save = *(--sp);
                *(--dp) = *(--sp);
@@ -1475,9 +1491,8 @@
             png_bytep sp, dp;
             png_byte save[2];
             png_uint_32 i;
-
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                save[0] = *(--sp);
                save[1] = *(--sp);
@@ -1500,9 +1515,8 @@
             png_bytep sp, dp;
             png_byte save;
             png_uint_32 i;
-
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                save = *(--sp);
                *(--dp) = *(--sp);
@@ -1516,8 +1530,8 @@
             png_byte save[2];
             png_uint_32 i;
 
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                save[0] = *(--sp);
                save[1] = *(--sp);
@@ -1541,6 +1555,7 @@
    if (row != NULL && row_info != NULL)
 #endif
    {
+      png_uint_32 row_width = row_info->width;
       if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
       {
          /* This inverts the alpha channel in RGBA */
@@ -1549,8 +1564,8 @@
             png_bytep sp, dp;
             png_uint_32 i;
 
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                *(--dp) = 255 - *(--sp);
                *(--dp) = *(--sp);
@@ -1564,8 +1579,8 @@
             png_bytep sp, dp;
             png_uint_32 i;
 
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                *(--dp) = 255 - *(--sp);
                *(--dp) = 255 - *(--sp);
@@ -1586,8 +1601,8 @@
             png_bytep sp, dp;
             png_uint_32 i;
 
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                *(--dp) = 255 - *(--sp);
                *(--dp) = *(--sp);
@@ -1599,8 +1614,8 @@
             png_bytep sp, dp;
             png_uint_32 i;
 
-            for (i = 0, sp = dp = row + row_info->rowbytes;
-               i < row_info->width; i++)
+            sp = dp = row + row_info->rowbytes;
+            for (i = 0; i < row_width; i++)
             {
                *(--dp) = 255 - *(--sp);
                *(--dp) = 255 - *(--sp);
@@ -1621,50 +1636,166 @@
 {
    png_bytep sp, dp;
    png_uint_32 i;
+   png_uint_32 row_width = row_info->width;
+
+   png_byte hi_filler = (png_byte)((filler>>8) & 0xf);
+   png_byte low_filler = (png_byte)(filler & 0xf);
 
    png_debug(1, "in png_do_read_filler\n");
    if (
 #if defined(PNG_USELESS_TESTS_SUPPORTED)
        row != NULL  && row_info != NULL &&
 #endif
-       row_info->color_type == PNG_COLOR_TYPE_RGB && row_info->bit_depth == 8)
+       row_info->color_type == PNG_COLOR_TYPE_GRAY)
    {
-      /* This changes the data from RGB to RGBX */
-      if (flags & PNG_FLAG_FILLER_AFTER)
+      if(row_info->bit_depth == 8)
       {
-         for (i = 1, sp = row + (png_size_t)row_info->width * 3,
-            dp = row + (png_size_t)row_info->width * 4;
-            i < row_info->width;
-            i++)
+         /* This changes the data from G to GX */
+         if (flags & PNG_FLAG_FILLER_AFTER)
          {
-            *(--dp) = (png_byte)filler;
-            *(--dp) = *(--sp);
-            *(--dp) = *(--sp);
-            *(--dp) = *(--sp);
+            sp = row + (png_size_t)row_width;
+            dp =  sp + (png_size_t)row_width;
+            for (i = 1; i < row_width; i++)
+            {
+               *(--dp) = low_filler;
+               *(--dp) = *(--sp);
+            }
+            row_info->channels = 2;
+            row_info->pixel_depth = 16;
+            row_info->rowbytes = row_width * 2;
          }
-         *(--dp) = (png_byte)filler;
-         row_info->channels = 4;
-         row_info->pixel_depth = 32;
-         row_info->rowbytes = row_info->width * 4;
+      /* This changes the data from G to XG */
+         else
+         {
+            sp = row + (png_size_t)row_width;
+            dp = sp  + (png_size_t)row_width;
+            for (i = 0; i < row_width; i++)
+            {
+               *(--dp) = *(--sp);
+               *(--dp) = low_filler;
+            }
+            row_info->channels = 2;
+            row_info->pixel_depth = 16;
+            row_info->rowbytes = row_width * 2;
+         }
       }
+      else if(row_info->bit_depth == 16)
+      {
+         /* This changes the data from GG to GGXX */
+         if (flags & PNG_FLAG_FILLER_AFTER)
+         {
+            sp = row + (png_size_t)row_width;
+            dp = sp  + (png_size_t)row_width;
+            for (i = 1; i < row_width; i++)
+            {
+               *(--dp) = hi_filler;
+               *(--dp) = low_filler;
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+            }
+            row_info->channels = 2;
+            row_info->pixel_depth = 32;
+            row_info->rowbytes = row_width * 2;
+         }
+         /* This changes the data from GG to XXGG */
+         else
+         {
+            sp = row + (png_size_t)row_width;
+            dp = sp  + (png_size_t)row_width;
+            for (i = 0; i < row_width; i++)
+            {
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = hi_filler;
+               *(--dp) = low_filler;
+            }
+            row_info->channels = 2;
+            row_info->pixel_depth = 16;
+            row_info->rowbytes = row_width * 2;
+         }
+      }
+   } /* COLOR_TYPE == GRAY */
+   else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
+   {
+      if(row_info->bit_depth == 8)
+      {
+         /* This changes the data from RGB to RGBX */
+         if (flags & PNG_FLAG_FILLER_AFTER)
+         {
+            sp = row + (png_size_t)row_width * 3;
+            dp = sp  + (png_size_t)row_width;
+            for (i = 1; i < row_width; i++)
+            {
+               *(--dp) = low_filler;
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+            }
+            row_info->channels = 4;
+            row_info->pixel_depth = 32;
+            row_info->rowbytes = row_width * 4;
+         }
       /* This changes the data from RGB to XRGB */
-      else
-      {
-         for (i = 0, sp = row + (png_size_t)row_info->width * 3,
-            dp = row + (png_size_t)row_info->width * 4;
-            i < row_info->width;
-            i++)
+         else
          {
-            *(--dp) = *(--sp);
-            *(--dp) = *(--sp);
-            *(--dp) = *(--sp);
-            *(--dp) = (png_byte)filler;
+            sp = row + (png_size_t)row_width * 3;
+            dp = sp + (png_size_t)row_width;
+            for (i = 0; i < row_width; i++)
+            {
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = low_filler;
+            }
+            row_info->channels = 4;
+            row_info->pixel_depth = 32;
+            row_info->rowbytes = row_width * 4;
          }
-         row_info->channels = 4;
-         row_info->pixel_depth = 32;
-         row_info->rowbytes = row_info->width * 4;
       }
-   }
+      else if(row_info->bit_depth == 16)
+      {
+         /* This changes the data from RRGGBB to RRGGBBXX */
+         if (flags & PNG_FLAG_FILLER_AFTER)
+         {
+            sp = row + (png_size_t)row_width * 3;
+            dp = sp  + (png_size_t)row_width;
+            for (i = 1; i < row_width; i++)
+            {
+               *(--dp) = hi_filler;
+               *(--dp) = low_filler;
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+            }
+            row_info->channels = 4;
+            row_info->pixel_depth = 64;
+            row_info->rowbytes = row_width * 4;
+         }
+         /* This changes the data from RRGGBB to XXRRGGBB */
+         else
+         {
+            sp = row + (png_size_t)row_width * 3;
+            dp = sp  + (png_size_t)row_width;
+            for (i = 0; i < row_width; i++)
+            {
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = *(--sp);
+               *(--dp) = hi_filler;
+               *(--dp) = low_filler;
+            }
+            row_info->channels = 4;
+            row_info->pixel_depth = 64;
+            row_info->rowbytes = row_width * 4;
+         }
+      }
+   } /* COLOR_TYPE == RGB */
 }
 #endif
 
@@ -1675,6 +1806,7 @@
 {
    png_bytep sp, dp;
    png_uint_32 i;
+   png_uint_32 row_width = row_info->width;
 
    png_debug(1, "in png_do_gray_to_rgb\n");
    if (row_info->bit_depth >= 8 &&
@@ -1687,10 +1819,9 @@
       {
          if (row_info->bit_depth == 8)
          {
-            for (i = 0, sp = row + (png_size_t)row_info->width - 1,
-               dp = row + (png_size_t)row_info->width * 3 - 1;
-               i < row_info->width;
-               i++)
+            sp = row + (png_size_t)row_width - 1;
+            dp = sp  + (png_size_t)row_width * 2;
+            for (i = 0; i < row_width; i++)
             {
                *(dp--) = *sp;
                *(dp--) = *sp;
@@ -1700,10 +1831,9 @@
          }
          else
          {
-            for (i = 0, sp = row + (png_size_t)row_info->width * 2 - 1,
-               dp = row + (png_size_t)row_info->width * 6 - 1;
-               i < row_info->width;
-               i++)
+            sp = row + (png_size_t)row_width * 2 - 1;
+            dp = sp  + (png_size_t)row_width * 4;
+            for (i = 0; i < row_width; i++)
             {
                *(dp--) = *sp;
                *(dp--) = *(sp - 1);
@@ -1720,10 +1850,9 @@
       {
          if (row_info->bit_depth == 8)
          {
-            for (i = 0, sp = row + (png_size_t)row_info->width * 2 - 1,
-               dp = row + (png_size_t)row_info->width * 4 - 1;
-               i < row_info->width;
-               i++)
+            sp = row + (png_size_t)row_width * 2 - 1;
+            dp = sp  + (png_size_t)row_width * 2;
+            for (i = 0; i < row_width; i++)
             {
                *(dp--) = *(sp--);
                *(dp--) = *sp;
@@ -1734,10 +1863,9 @@
          }
          else
          {
-            for (i = 0, sp = row + (png_size_t)row_info->width * 4 - 1,
-               dp = row + (png_size_t)row_info->width * 8 - 1;
-               i < row_info->width;
-               i++)
+            sp = row + (png_size_t)row_width * 4 - 1;
+            dp = sp  + (png_size_t)row_width * 4;
+            for (i = 0; i < row_width; i++)
             {
                *(dp--) = *(sp--);
                *(dp--) = *(sp--);
@@ -1756,7 +1884,7 @@
       row_info->color_type |= PNG_COLOR_MASK_COLOR;
       row_info->pixel_depth = (png_byte)(row_info->channels *
          row_info->bit_depth);
-      row_info->rowbytes = ((row_info->width *
+      row_info->rowbytes = ((row_width *
          row_info->pixel_depth + 7) >> 3);
    }
 }
@@ -2008,6 +2136,7 @@
 {
    png_bytep sp, dp;
    png_uint_32 i;
+   png_uint_32 row_width=row_info->width;
    int shift;
 
    png_debug(1, "in png_do_background\n");
@@ -2028,7 +2157,7 @@
                {
                   sp = row;
                   shift = 7;
-                  for (i = 0; i < row_info->width; i++)
+                  for (i = 0; i < row_width; i++)
                   {
                      if ((png_uint_16)((*sp >> shift) & 0x1)
                         == trans_values->gray)
@@ -2050,7 +2179,7 @@
                {
                   sp = row;
                   shift = 6;
-                  for (i = 0; i < row_info->width; i++)
+                  for (i = 0; i < row_width; i++)
                   {
                      if ((png_uint_16)((*sp >> shift) & 0x3)
                          == trans_values->gray)
@@ -2072,7 +2201,7 @@
                {
                   sp = row;
                   shift = 4;
-                  for (i = 0; i < row_info->width; i++)
+                  for (i = 0; i < row_width; i++)
                   {
                      if ((png_uint_16)((*sp >> shift) & 0xf)
                          == trans_values->gray)
@@ -2095,7 +2224,8 @@
 #if defined(PNG_READ_GAMMA_SUPPORTED)
                   if (gamma_table != NULL)
                   {
-                     for (i = 0, sp = row; i < row_info->width; i++, sp++)
+                     sp = row;
+                     for (i = 0; i < row_width; i++, sp++)
                      {
                         if (*sp == trans_values->gray)
                         {
@@ -2110,7 +2240,8 @@
                   else
 #endif
                   {
-                     for (i = 0, sp = row; i < row_info->width; i++, sp++)
+                     sp = row;
+                     for (i = 0; i < row_width; i++, sp++)
                      {
                         if (*sp == trans_values->gray)
                         {
@@ -2125,7 +2256,8 @@
 #if defined(PNG_READ_GAMMA_SUPPORTED)
                   if (gamma_16 != NULL)
                   {
-                     for (i = 0, sp = row; i < row_info->width; i++, sp += 2)
+                     sp = row;
+                     for (i = 0; i < row_width; i++, sp += 2)
                      {
                         png_uint_16 v;
 
@@ -2147,7 +2279,8 @@
                   else
 #endif
                   {
-                     for (i = 0, sp = row; i < row_info->width; i++, sp += 2)
+                     sp = row;
+                     for (i = 0; i < row_width; i++, sp += 2)
                      {
                         png_uint_16 v;
 
@@ -2171,7 +2304,8 @@
 #if defined(PNG_READ_GAMMA_SUPPORTED)
                if (gamma_table != NULL)
                {
-                  for (i = 0, sp = row; i < row_info->width; i++, sp += 3)
+                  sp = row;
+                  for (i = 0; i < row_width; i++, sp += 3)
                   {
                      if (*sp == trans_values->red &&
                         *(sp + 1) == trans_values->green &&
@@ -2192,7 +2326,8 @@
                else
 #endif
                {
-                  for (i = 0, sp = row; i < row_info->width; i++, sp += 3)
+                  sp = row;
+                  for (i = 0; i < row_width; i++, sp += 3)
                   {
                      if (*sp == trans_values->red &&
                         *(sp + 1) == trans_values->green &&
@@ -2210,7 +2345,8 @@
 #if defined(PNG_READ_GAMMA_SUPPORTED)
                if (gamma_16 != NULL)
                {
-                  for (i = 0, sp = row; i < row_info->width; i++, sp += 6)
+                  sp = row;
+                  for (i = 0; i < row_width; i++, sp += 6)
                   {
                      png_uint_16 r, g, b;
 
@@ -2246,7 +2382,8 @@
                else
 #endif
                {
-                  for (i = 0, sp = row; i < row_info->width; i++, sp += 6)
+                  sp = row;
+                  for (i = 0; i < row_width; i++, sp += 6)
                   {
                      png_uint_16 r, g, b;
 
@@ -2276,8 +2413,9 @@
                if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
                    gamma_table != NULL)
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 2, dp++)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 2, dp++)
                   {
                      png_uint_16 a;
 
@@ -2304,8 +2442,9 @@
                else
 #endif
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 2, dp++)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 2, dp++)
                   {
                      png_byte a;
 
@@ -2331,8 +2470,9 @@
                if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
                    gamma_16_to_1 != NULL)
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 4, dp += 2)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 4, dp += 2)
                   {
                      png_uint_16 a;
 
@@ -2366,8 +2506,9 @@
                else
 #endif
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 4, dp += 2)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 4, dp += 2)
                   {
                      png_uint_16 a;
 
@@ -2403,8 +2544,9 @@
                if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
                    gamma_table != NULL)
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 4, dp += 3)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 4, dp += 3)
                   {
                      png_byte a;
 
@@ -2441,8 +2583,9 @@
                else
 #endif
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 4, dp += 3)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 4, dp += 3)
                   {
                      png_byte a;
 
@@ -2476,8 +2619,9 @@
                if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
                    gamma_16_to_1 != NULL)
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 8, dp += 6)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 8, dp += 6)
                   {
                      png_uint_16 a;
 
@@ -2532,8 +2676,9 @@
                else
 #endif
                {
-                  for (i = 0, sp = row, dp = row;
-                     i < row_info->width; i++, sp += 8, dp += 6)
+                  sp = row;
+                  dp = row;
+                  for (i = 0; i < row_width; i++, sp += 8, dp += 6)
                   {
                      png_uint_16 a;
 
@@ -2583,7 +2728,7 @@
          row_info->channels--;
          row_info->pixel_depth = (png_byte)(row_info->channels *
             row_info->bit_depth);
-         row_info->rowbytes = ((row_info->width *
+         row_info->rowbytes = ((row_width *
             row_info->pixel_depth + 7) >> 3);
       }
    }
@@ -2604,6 +2749,7 @@
 {
    png_bytep sp;
    png_uint_32 i;
+   png_uint_32 row_width=row_info->width;
 
    png_debug(1, "in png_do_gamma\n");
    if (
@@ -2619,7 +2765,8 @@
          {
             if (row_info->bit_depth == 8)
             {
-               for (i = 0, sp = row; i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   *sp = gamma_table[*sp];
                   sp++;
@@ -2631,7 +2778,8 @@
             }
             else /* if (row_info->bit_depth == 16) */
             {
-               for (i = 0, sp = row; i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   png_uint_16 v;
 
@@ -2655,8 +2803,8 @@
          {
             if (row_info->bit_depth == 8)
             {
-               for (i = 0, sp = row;
-                  i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   *sp = gamma_table[*sp];
                   sp++;
@@ -2669,8 +2817,8 @@
             }
             else /* if (row_info->bit_depth == 16) */
             {
-               for (i = 0, sp = row;
-                  i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   png_uint_16 v;
 
@@ -2694,8 +2842,8 @@
          {
             if (row_info->bit_depth == 8)
             {
-               for (i = 0, sp = row;
-                  i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   *sp = gamma_table[*sp];
                   sp += 2;
@@ -2703,8 +2851,8 @@
             }
             else /* if (row_info->bit_depth == 16) */
             {
-               for (i = 0, sp = row;
-                  i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   png_uint_16 v;
 
@@ -2720,7 +2868,8 @@
          {
             if (row_info->bit_depth == 2)
             {
-               for (i = 0, sp = row; i < row_info->width; i += 4)
+               sp = row;
+               for (i = 0; i < row_width; i += 4)
                {
                   int a = *sp & 0xc0;
                   int b = *sp & 0x30;
@@ -2736,7 +2885,8 @@
             }
             if (row_info->bit_depth == 4)
             {
-               for (i = 0, sp = row; i < row_info->width; i += 2)
+               sp = row;
+               for (i = 0; i < row_width; i += 2)
                {
                   int msb = *sp & 0xf0;
                   int lsb = *sp & 0x0f;
@@ -2748,7 +2898,8 @@
             }
             else if (row_info->bit_depth == 8)
             {
-               for (i = 0, sp = row; i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   *sp = gamma_table[*sp];
                   sp++;
@@ -2756,7 +2907,8 @@
             }
             else if (row_info->bit_depth == 16)
             {
-               for (i = 0, sp = row; i < row_info->width; i++)
+               sp = row;
+               for (i = 0; i < row_width; i++)
                {
                   png_uint_16 v;
 
@@ -2784,6 +2936,7 @@
    int shift, value;
    png_bytep sp, dp;
    png_uint_32 i;
+   png_uint_32 row_width=row_info->width;
 
    png_debug(1, "in png_do_expand_palette\n");
    if (
@@ -2798,10 +2951,10 @@
          {
             case 1:
             {
-               sp = row + (png_size_t)((row_info->width - 1) >> 3);
-               dp = row + (png_size_t)row_info->width - 1;
-               shift = 7 - (int)((row_info->width + 7) & 7);
-               for (i = 0; i < row_info->width; i++)
+               sp = row + (png_size_t)((row_width - 1) >> 3);
+               dp = row + (png_size_t)row_width - 1;
+               shift = 7 - (int)((row_width + 7) & 7);
+               for (i = 0; i < row_width; i++)
                {
                   if ((*sp >> shift) & 0x1)
                      *dp = 1;
@@ -2821,10 +2974,10 @@
             }
             case 2:
             {
-               sp = row + (png_size_t)((row_info->width - 1) >> 2);
-               dp = row + (png_size_t)row_info->width - 1;
-               shift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
-               for (i = 0; i < row_info->width; i++)
+               sp = row + (png_size_t)((row_width - 1) >> 2);
+               dp = row + (png_size_t)row_width - 1;
+               shift = (int)((3 - ((row_width + 3) & 3)) << 1);
+               for (i = 0; i < row_width; i++)
                {
                   value = (*sp >> shift) & 0x3;
                   *dp = (png_byte)value;
@@ -2842,10 +2995,10 @@
             }
             case 4:
             {
-               sp = row + (png_size_t)((row_info->width - 1) >> 1);
-               dp = row + (png_size_t)row_info->width - 1;
-               shift = (int)((row_info->width & 1) << 2);
-               for (i = 0; i < row_info->width; i++)
+               sp = row + (png_size_t)((row_width - 1) >> 1);
+               dp = row + (png_size_t)row_width - 1;
+               shift = (int)((row_width & 1) << 2);
+               for (i = 0; i < row_width; i++)
                {
                   value = (*sp >> shift) & 0xf;
                   *dp = (png_byte)value;
@@ -2864,7 +3017,7 @@
          }
          row_info->bit_depth = 8;
          row_info->pixel_depth = 8;
-         row_info->rowbytes = row_info->width;
+         row_info->rowbytes = row_width;
       }
       switch (row_info->bit_depth)
       {
@@ -2872,10 +3025,10 @@
          {
             if (trans != NULL)
             {
-               sp = row + (png_size_t)row_info->width - 1;
-               dp = row + (png_size_t)(row_info->width << 2) - 1;
+               sp = row + (png_size_t)row_width - 1;
+               dp = row + (png_size_t)(row_width << 2) - 1;
 
-               for (i = 0; i < row_info->width; i++)
+               for (i = 0; i < row_width; i++)
                {
                   if ((int)(*sp) >= num_trans)
                      *dp-- = 0xff;
@@ -2888,16 +3041,16 @@
                }
                row_info->bit_depth = 8;
                row_info->pixel_depth = 32;
-               row_info->rowbytes = row_info->width * 4;
+               row_info->rowbytes = row_width * 4;
                row_info->color_type = 6;
                row_info->channels = 4;
             }
             else
             {
-               sp = row + (png_size_t)row_info->width - 1;
-               dp = row + (png_size_t)(row_info->width * 3) - 1;
+               sp = row + (png_size_t)row_width - 1;
+               dp = row + (png_size_t)(row_width * 3) - 1;
 
-               for (i = 0; i < row_info->width; i++)
+               for (i = 0; i < row_width; i++)
                {
                   *dp-- = palette[*sp].blue;
                   *dp-- = palette[*sp].green;
@@ -2906,7 +3059,7 @@
                }
                row_info->bit_depth = 8;
                row_info->pixel_depth = 24;
-               row_info->rowbytes = row_info->width * 3;
+               row_info->rowbytes = row_width * 3;
                row_info->color_type = 2;
                row_info->channels = 3;
             }
@@ -2926,6 +3079,7 @@
    int shift, value;
    png_bytep sp, dp;
    png_uint_32 i;
+   png_uint_32 row_width=row_info->width;
 
    png_debug(1, "in png_do_expand\n");
 #if defined(PNG_USELESS_TESTS_SUPPORTED)
@@ -2943,10 +3097,10 @@
                case 1:
                {
                   gray *= 0xff;
-                  sp = row + (png_size_t)((row_info->width - 1) >> 3);
-                  dp = row + (png_size_t)row_info->width - 1;
-                  shift = 7 - (int)((row_info->width + 7) & 7);
-                  for (i = 0; i < row_info->width; i++)
+                  sp = row + (png_size_t)((row_width - 1) >> 3);
+                  dp = row + (png_size_t)row_width - 1;
+                  shift = 7 - (int)((row_width + 7) & 7);
+                  for (i = 0; i < row_width; i++)
                   {
                      if ((*sp >> shift) & 0x1)
                         *dp = 0xff;
@@ -2967,10 +3121,10 @@
                case 2:
                {
                   gray *= 0x55;
-                  sp = row + (png_size_t)((row_info->width - 1) >> 2);
-                  dp = row + (png_size_t)row_info->width - 1;
-                  shift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
-                  for (i = 0; i < row_info->width; i++)
+                  sp = row + (png_size_t)((row_width - 1) >> 2);
+                  dp = row + (png_size_t)row_width - 1;
+                  shift = (int)((3 - ((row_width + 3) & 3)) << 1);
+                  for (i = 0; i < row_width; i++)
                   {
                      value = (*sp >> shift) & 0x3;
                      *dp = (png_byte)(value | (value << 2) | (value << 4) |
@@ -2990,10 +3144,10 @@
                case 4:
                {
                   gray *= 0x11;
-                  sp = row + (png_size_t)((row_info->width - 1) >> 1);
-                  dp = row + (png_size_t)row_info->width - 1;
-                  shift = (int)((1 - ((row_info->width + 1) & 1)) << 2);
-                  for (i = 0; i < row_info->width; i++)
+                  sp = row + (png_size_t)((row_width - 1) >> 1);
+                  dp = row + (png_size_t)row_width - 1;
+                  shift = (int)((1 - ((row_width + 1) & 1)) << 2);
+                  for (i = 0; i < row_width; i++)
                   {
                      value = (*sp >> shift) & 0xf;
                      *dp = (png_byte)(value | (value << 4));
@@ -3012,16 +3166,16 @@
             }
             row_info->bit_depth = 8;
             row_info->pixel_depth = 8;
-            row_info->rowbytes = row_info->width;
+            row_info->rowbytes = row_width;
          }
 
          if (trans_value != NULL)
          {
             if (row_info->bit_depth == 8)
             {
-               sp = row + (png_size_t)row_info->width - 1;
-               dp = row + (png_size_t)(row_info->width << 1) - 1;
-               for (i = 0; i < row_info->width; i++)
+               sp = row + (png_size_t)row_width - 1;
+               dp = row + (png_size_t)(row_width << 1) - 1;
+               for (i = 0; i < row_width; i++)
                {
                   if (*sp == gray)
                      *dp-- = 0;
@@ -3034,7 +3188,7 @@
             {
                sp = row + row_info->rowbytes - 1;
                dp = row + (row_info->rowbytes << 1) - 1;
-               for (i = 0; i < row_info->width; i++)
+               for (i = 0; i < row_width; i++)
                {
                   if (((png_uint_16)*(sp) |
                      ((png_uint_16)*(sp - 1) << 8)) == gray)
@@ -3055,7 +3209,7 @@
             row_info->channels = 2;
             row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
             row_info->rowbytes =
-               ((row_info->width * row_info->pixel_depth) >> 3);
+               ((row_width * row_info->pixel_depth) >> 3);
          }
       }
       else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
@@ -3063,8 +3217,8 @@
          if (row_info->bit_depth == 8)
          {
             sp = row + (png_size_t)row_info->rowbytes - 1;
-            dp = row + (png_size_t)(row_info->width << 2) - 1;
-            for (i = 0; i < row_info->width; i++)
+            dp = row + (png_size_t)(row_width << 2) - 1;
+            for (i = 0; i < row_width; i++)
             {
                if (*(sp - 2) == trans_value->red &&
                   *(sp - 1) == trans_value->green &&
@@ -3080,8 +3234,8 @@
          else if (row_info->bit_depth == 16)
          {
             sp = row + row_info->rowbytes - 1;
-            dp = row + (png_size_t)(row_info->width << 3) - 1;
-            for (i = 0; i < row_info->width; i++)
+            dp = row + (png_size_t)(row_width << 3) - 1;
+            for (i = 0; i < row_width; i++)
             {
                if ((((png_uint_16)*(sp - 4) |
                   ((png_uint_16)*(sp - 5) << 8)) == trans_value->red) &&
@@ -3110,7 +3264,7 @@
          row_info->channels = 4;
          row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
          row_info->rowbytes =
-            ((row_info->width * row_info->pixel_depth) >> 3);
+            ((row_width * row_info->pixel_depth) >> 3);
       }
    }
 }
@@ -3123,6 +3277,7 @@
 {
    png_bytep sp, dp;
    png_uint_32 i;
+   png_uint_32 row_width=row_info->width;
 
    png_debug(1, "in png_do_dither\n");
 #if defined(PNG_USELESS_TESTS_SUPPORTED)
@@ -3135,7 +3290,7 @@
          int r, g, b, p;
          sp = row;
          dp = row;
-         for (i = 0; i < row_info->width; i++)
+         for (i = 0; i < row_width; i++)
          {
             r = *sp++;
             g = *sp++;
@@ -3163,7 +3318,7 @@
          row_info->channels = 1;
          row_info->pixel_depth = row_info->bit_depth;
          row_info->rowbytes =
-             ((row_info->width * row_info->pixel_depth + 7) >> 3);
+             ((row_width * row_info->pixel_depth + 7) >> 3);
       }
       else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
          palette_lookup != NULL && row_info->bit_depth == 8)
@@ -3171,7 +3326,7 @@
          int r, g, b, p;
          sp = row;
          dp = row;
-         for (i = 0; i < row_info->width; i++)
+         for (i = 0; i < row_width; i++)
          {
             r = *sp++;
             g = *sp++;
@@ -3193,13 +3348,13 @@
          row_info->channels = 1;
          row_info->pixel_depth = row_info->bit_depth;
          row_info->rowbytes =
-            ((row_info->width * row_info->pixel_depth + 7) >> 3);
+            ((row_width * row_info->pixel_depth + 7) >> 3);
       }
       else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
          dither_lookup && row_info->bit_depth == 8)
       {
          sp = row;
-         for (i = 0; i < row_info->width; i++, sp++)
+         for (i = 0; i < row_width; i++, sp++)
          {
             *sp = dither_lookup[*sp];
          }
diff --git a/pngrutil.c b/pngrutil.c
index 1c37906..c9291d3 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,12 +1,12 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * This file contains routines which are only called from within
  * libpng itself during the course of reading an image.
@@ -76,9 +76,10 @@
 int
 png_crc_finish(png_structp png_ptr, png_uint_32 skip)
 {
-   png_uint_32 i;
+   png_uint_32 i,istop;
 
-   for (i = skip; i > (png_uint_32)png_ptr->zbuf_size; i -= png_ptr->zbuf_size)
+   istop = (png_uint_32)png_ptr->zbuf_size;
+   for (i = skip; i > istop; i -= istop)
    {
       png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
    }
@@ -258,20 +259,6 @@
 
    png_ptr->mode |= PNG_HAVE_PLTE;
 
-#if defined (PNG_READ_tRNS_SUPPORTED)
-   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
-   {
-      if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
-      {
-         if (png_ptr->num_trans > png_ptr->num_palette)
-         {
-            png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
-            png_ptr->num_trans = png_ptr->num_palette;
-         }
-      }
-   }
-#endif
-
 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
    if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
    {
@@ -349,6 +336,21 @@
    png_ptr->palette = palette;
    png_ptr->num_palette = (png_uint_16)num;
    png_set_PLTE(png_ptr, info_ptr, palette, num);
+
+#if defined (PNG_READ_tRNS_SUPPORTED)
+   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+   {
+      if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
+      {
+         if (png_ptr->num_trans > png_ptr->num_palette)
+         {
+            png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
+            png_ptr->num_trans = png_ptr->num_palette;
+         }
+      }
+   }
+#endif
+
 }
 
 void
@@ -758,6 +760,12 @@
          png_crc_finish(png_ptr, length);
          return;
       }
+      if (length == 0)
+      {
+         png_warning(png_ptr, "Zero length tRNS chunk");
+         png_crc_finish(png_ptr, length);
+         return;
+      }
 
       png_ptr->trans = (png_bytep)png_malloc(png_ptr, length);
       png_ptr->flags |= PNG_FLAG_FREE_TRANS;
@@ -1075,7 +1083,7 @@
    purpose[slength] = 0x00; /* null terminate the last string */
 
    png_debug(3, "Finding end of pCAL purpose string\n");
-   for (buf = purpose; *buf != '\0'; buf++)
+   for (buf = purpose; *buf; buf++)
       /* empty loop */ ;
 
    endptr = purpose + slength;
@@ -1113,7 +1121,7 @@
       png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
    }
 
-   for (buf = units; *buf != 0x00; buf++)
+   for (buf = units; *buf; buf++)
       /* Empty loop to move past the units string. */ ;
 
    png_debug(3, "Allocating pCAL parameters array\n");
@@ -1497,7 +1505,7 @@
             int s_inc, s_start, s_end;
             int m;
             int shift;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
             sp = png_ptr->row_buf + 1;
             dp = row;
@@ -1519,7 +1527,8 @@
 
             shift = s_start;
 
-            for (i = 0; i < png_ptr->width; i++)
+            istop = png_ptr->width;
+            for (i = 0; i < istop; i++)
             {
                if (m & mask)
                {
@@ -1553,7 +1562,7 @@
             int s_start, s_end, s_inc;
             int m;
             int shift;
-            png_uint_32 i;
+            png_uint_32 i,istop;
             int value;
 
             sp = png_ptr->row_buf + 1;
@@ -1576,7 +1585,8 @@
 
             shift = s_start;
 
-            for (i = 0; i < png_ptr->width; i++)
+            istop = png_ptr->width;
+            for (i = 0; i < istop; i++)
             {
                if (m & mask)
                {
@@ -1607,7 +1617,7 @@
             int s_start, s_end, s_inc;
             int m;
             int shift;
-            png_uint_32 i;
+            png_uint_32 i,istop;
             int value;
 
             sp = png_ptr->row_buf + 1;
@@ -1629,7 +1639,8 @@
             }
             shift = s_start;
 
-            for (i = 0; i < png_ptr->width; i++)
+            istop = png_ptr->width;
+            for (i = 0; i < istop; i++)
             {
                if (m & mask)
                {
@@ -1658,7 +1669,7 @@
             png_bytep sp;
             png_bytep dp;
             png_size_t pixel_bytes;
-            png_uint_32 i;
+            png_uint_32 i, istop;
             png_byte m;
 
             pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
@@ -1666,7 +1677,8 @@
             sp = png_ptr->row_buf + 1;
             dp = row;
             m = 0x80;
-            for (i = 0; i < png_ptr->width; i++)
+            istop = png_ptr->width;
+            for (i = 0; i < istop; i++)
             {
                if (m & mask)
                {
@@ -1708,7 +1720,7 @@
             int s_start, s_end, s_inc;
             png_byte v;
             png_uint_32 i;
-            int j;
+            int j, jstop;
 
             sp = row + (png_size_t)((row_info->width - 1) >> 3);
             dp = row + (png_size_t)((final_width - 1) >> 3);
@@ -1731,10 +1743,11 @@
                 s_inc = 1;
             }
 
+            jstop = png_pass_inc[pass];
             for (i = row_info->width; i; i--)
             {
                v = (png_byte)((*sp >> sshift) & 0x1);
-               for (j = 0; j < png_pass_inc[pass]; j++)
+               for (j = 0; j < jstop; j++)
                {
                   *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
                   *dp |= (png_byte)(v << dshift);
@@ -1762,6 +1775,7 @@
             int sshift, dshift;
             int s_start, s_end, s_inc;
             png_uint_32 i;
+            int jstop;
 
             sp = row + (png_uint_32)((row_info->width - 1) >> 2);
             dp = row + (png_uint_32)((final_width - 1) >> 2);
@@ -1784,13 +1798,14 @@
                s_inc = 2;
             }
 
+            jstop = png_pass_inc[pass];
             for (i = row_info->width; i; i--)
             {
                png_byte v;
                int j;
 
                v = (png_byte)((*sp >> sshift) & 0x3);
-               for (j = 0; j < png_pass_inc[pass]; j++)
+               for (j = 0; j < jstop; j++)
                {
                   *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
                   *dp |= (png_byte)(v << dshift);
@@ -1818,6 +1833,7 @@
             int sshift, dshift;
             int s_start, s_end, s_inc;
             png_uint_32 i;
+            int jstop;
 
             sp = row + (png_size_t)((row_info->width - 1) >> 1);
             dp = row + (png_size_t)((final_width - 1) >> 1);
@@ -1840,13 +1856,14 @@
                s_inc = 4;
             }
 
+            jstop = png_pass_inc[pass];
             for (i = row_info->width; i; i--)
             {
                png_byte v;
                int j;
 
                v = (png_byte)((*sp >> sshift) & 0xf);
-               for (j = 0; j < png_pass_inc[pass]; j++)
+               for (j = 0; j < jstop; j++)
                {
                   *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
                   *dp |= (png_byte)(v << dshift);
@@ -1872,19 +1889,21 @@
          {
             png_bytep sp, dp;
             png_uint_32 i;
+            int jstop;
             png_size_t pixel_bytes;
 
             pixel_bytes = (row_info->pixel_depth >> 3);
 
             sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
             dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
+            jstop = png_pass_inc[pass];
             for (i = row_info->width; i; i--)
             {
                png_byte v[8];
                int j;
 
                png_memcpy(v, sp, pixel_bytes);
-               for (j = 0; j < png_pass_inc[pass]; j++)
+               for (j = 0; j < jstop; j++)
                {
                   png_memcpy(dp, v, pixel_bytes);
                   dp -= pixel_bytes;
@@ -1901,6 +1920,165 @@
 }
 #endif
 
+#ifndef PNG_READ_SLOW_FILTERING
+void
+png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
+   png_bytep prev_row, int filter)
+{
+   png_debug(1, "in png_read_filter_row\n");
+   png_debug2(2,"row = %d, filter = %d\n", png_ptr->row_number, filter);
+
+
+   switch (filter)
+   {
+      case PNG_FILTER_VALUE_NONE:
+         break;
+      case PNG_FILTER_VALUE_SUB:
+      {
+         png_uint_32 i, istop;
+         int bpp;
+         png_bytep rp;
+         png_bytep lp;
+
+         bpp = (row_info->pixel_depth + 7) / 8;
+         istop = row_info->rowbytes;
+         for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
+            i < istop; i++, rp++, lp++)
+         {
+            *rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
+         }
+         break;
+      }
+      case PNG_FILTER_VALUE_UP:
+      {
+         png_uint_32 i, istop;
+         png_bytep rp;
+         png_bytep pp;
+
+         istop = row_info->rowbytes;
+         for (i = 0, rp = row, pp = prev_row; i < istop; i++, rp++, pp++)
+         {
+            *rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
+         }
+         break;
+      }
+      case PNG_FILTER_VALUE_AVG:
+      {
+         png_uint_32 i, istop;
+         int bpp;
+         png_bytep rp;
+         png_bytep pp;
+         png_bytep lp;
+
+         bpp = (row_info->pixel_depth + 7) / 8;
+         istop = (png_uint_32)bpp;
+         for (i = 0, rp = row, pp = prev_row; i < istop; i++, rp++, pp++)
+         {
+            *rp = (png_byte)(((int)(*rp) +
+               ((int)(*pp) / 2)) & 0xff);
+         }
+        
+         istop = row_info->rowbytes;
+         for (lp = row; i < istop; i++, rp++,
+             lp++, pp++)
+         {
+            *rp = (png_byte)(((int)(*rp) +
+               (int)(*pp + *lp) / 2) & 0xff);
+         }
+         break;
+      }
+      case PNG_FILTER_VALUE_PAETH:
+      {
+         int bpp;
+         png_uint_32 i, istop;
+         png_bytep rp;
+         png_bytep pp;
+         png_bytep lp;
+         png_bytep cp;
+
+         bpp = (row_info->pixel_depth + 7) / 8;
+#ifndef PNG_SLOW_PAETH
+         istop=bpp;
+         for (i = 0, rp = row, pp = prev_row; i < istop;
+                 i++, rp++, pp++)
+         {
+            *rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
+         }
+
+         istop=row_info->rowbytes;
+         for (lp = row, cp = prev_row; i < istop;   /* use leftover i,rp,pp */
+                 i++, rp++, pp++, lp++, cp++)
+         {
+            int a, b, c, pa, pb, pc, p;
+
+            a = *lp;
+            b = *pp;
+            c = *cp;
+
+            p = a + b - c;
+#ifdef PNG_USE_ABS
+            pa = abs(p - a);
+            pb = abs(p - b);
+            pc = abs(p - c);
+#else
+            pa = p > a ? p - a : a - p;
+            pb = p > b ? p - b : b - p;
+            pc = p > c ? p - c : c - p;
+#endif
+
+            /*
+               if (pa <= pb && pa <= pc)
+                  p = a;
+               else if (pb <= pc)
+                  p = b;
+               else
+                  p = c;
+             */
+
+            p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+
+            *rp = (png_byte)(((int)(*rp) + p) & 0xff);
+         }
+#else /* PNG_SLOW_PAETH */
+         for (i = 0, rp = row, pp = prev_row,
+            lp = row - bpp, cp = prev_row - bpp, 
+            istop = row_info->rowbytes; i < istop; i++, rp++, pp++, lp++, cp++)
+         {
+            int a, b, c, pa, pb, pc, p;
+
+            b = *pp;
+            if (i >= (png_uint_32)bpp)
+            {
+               c = *cp;
+               a = *lp;
+            }
+            else
+            {
+               a = c = 0;
+            }
+            p = a + b - c;
+            pa = abs(p - a);
+            pb = abs(p - b);
+            pc = abs(p - c);
+
+            if (pa <= pb && pa <= pc)
+               p = a;
+            else if (pb <= pc)
+               p = b;
+            else
+               p = c;
+
+            *rp = (png_byte)(((int)(*rp) + p) & 0xff);
+         }
+#endif /* PNG_SLOW_PAETH */
+         break;
+      }
+      default:
+         png_error(png_ptr, "Bad adaptive filter type");
+         break;
+   }
+}
+#else /* PNG_READ_SLOW_FILTERING */
 void
 png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
    png_bytep prev_row, int filter)
@@ -2010,6 +2188,7 @@
          break;
    }
 }
+#endif /* PNG_READ_SLOW_FILTERING */
 
 void
 png_read_finish_row(png_structp png_ptr)
@@ -2186,8 +2365,20 @@
 #if defined(PNG_READ_FILLER_SUPPORTED)
    if (png_ptr->transformations & (PNG_FILLER))
    {
-      if (max_pixel_depth < 32)
-         max_pixel_depth = 32;
+      if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
+      {
+         if (max_pixel_depth <= 8)
+            max_pixel_depth = 16;
+         else
+            max_pixel_depth = 32;
+      }
+      else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
+      {
+         if (max_pixel_depth <= 32)
+            max_pixel_depth = 32;
+         else
+            max_pixel_depth = 64;
+      }
    }
 #endif
 
@@ -2216,7 +2407,7 @@
       for interlacing */
    rowbytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
    /* calculate the maximum bytes needed, adding a byte and a pixel
-      for safety sake */
+      for safety's sake */
    rowbytes = ((rowbytes * (png_uint_32)max_pixel_depth + 7) >> 3) +
       1 + ((max_pixel_depth + 7) >> 3);
 #ifdef PNG_MAX_MALLOC_64K
diff --git a/pngset.c b/pngset.c
index aa85f24..da4d82b 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,12 +1,12 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * The functions here are used during reads to store data from the file
  * into the info struct, and during writes to store application data
@@ -108,13 +108,14 @@
 
    /* check for overflow */
    rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;
-   info_ptr->rowbytes = info_ptr->width * rowbytes_per_pixel;
    if (( width > (png_uint_32)2147483647L/rowbytes_per_pixel))
    {
       png_warning(png_ptr,
          "Width too large to process image data; rowbytes will overflow.");
       info_ptr->rowbytes = (png_size_t)0;
    }
+   else
+      info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3;
 }
 
 #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
diff --git a/pngtest.c b/pngtest.c
index 22cbcb3..58e2b37 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,12 +1,12 @@
 
 /* pngtest.c - a simple test program to test libpng
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * This program reads in a PNG image, writes it out again, and then
  * compares the two files.  If the files are identical, this shows that
@@ -81,12 +81,12 @@
 
 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
 /* example of using user transform callback (we don't transform anything,
-   but merely count the black pixels) */
+   but merely count the zero samples) */
 
-static png_uint_32 black_pixels;
+static png_uint_32 zero_samples;
 
 void
-count_black_pixels(png_structp png_ptr, png_row_infop row_info, png_bytep data)
+count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
 {
    png_bytep dp = data;
    if(png_ptr == NULL)return; 
@@ -100,60 +100,66 @@
     *  png_byte pixel_depth   bits per pixel (depth*channels)
     */
 
-    /* counts the number of black pixels (or zero pixels if color_type is 3 */
+    /* counts the number of zero samples (or zero pixels if color_type is 3 */
 
     if(row_info->color_type == 0 || row_info->color_type == 3)
     {
        int pos=0;
-       png_uint_32 n;
-       for (n=0; n<row_info->width; n++)
+       png_uint_32 n, nstop;
+       for (n=0, nstop=row_info->width; n<nstop; n++)
        {
           if(row_info->bit_depth == 1)
-             if(((*dp << pos++ )& 0x80) == 0) black_pixels++;
+          {
+             if(((*dp << pos++ )& 0x80) == 0) zero_samples++;
              if(pos == 8)
              {
-                pos=0;
+                pos = 0;
                 dp++;
              }
+          }
           if(row_info->bit_depth == 2)
-             if(((*dp << (pos+=2))& 0xc0) == 0) black_pixels++;
+          {
+             if(((*dp << (pos+=2))& 0xc0) == 0) zero_samples++;
              if(pos == 8)
              {
-                pos=0;
+                pos = 0;
                 dp++;
              }
+          }
           if(row_info->bit_depth == 4)
-             if(((*dp << (pos+=4))& 0xf0) == 0) black_pixels++;
+          {
+             if(((*dp << (pos+=4))& 0xf0) == 0) zero_samples++;
              if(pos == 8)
              {
-                pos=0;
+                pos = 0;
                 dp++;
              }
+          }
           if(row_info->bit_depth == 8)
-             if(*dp++ == 0) black_pixels++;
+             if(*dp++ == 0) zero_samples++;
           if(row_info->bit_depth == 16)
           {
-             if((*dp | *(dp+1)) == 0) black_pixels++;
+             if((*dp | *(dp+1)) == 0) zero_samples++;
              dp+=2;
           }
        }
     }
     else /* other color types */
     {
-       png_uint_32 n;
+       png_uint_32 n, nstop;
        int channel;
        int color_channels = row_info->channels;
        if(row_info->color_type > 3)color_channels--;
 
-       for (n=0; n<row_info->width; n++)
+       for (n=0, nstop=row_info->width; n<nstop; n++)
        {
           for (channel = 0; channel < color_channels; channel++)
           {
              if(row_info->bit_depth == 8)
-                if(*dp++ == 0) black_pixels++;
+                if(*dp++ == 0) zero_samples++;
              if(row_info->bit_depth == 16)
              {
-                if((*dp | *(dp+1)) == 0) black_pixels++;
+                if((*dp | *(dp+1)) == 0) zero_samples++;
                 dp+=2;
              }
           }
@@ -563,8 +569,8 @@
    }
 
 #  if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
-     black_pixels=0;
-     png_set_write_user_transform_fn(write_ptr, count_black_pixels);
+     zero_samples=0;
+     png_set_write_user_transform_fn(write_ptr, count_zero_samples);
 #  endif
 
    png_debug(0, "Reading info struct\n");
@@ -948,7 +954,7 @@
          kerror = test_one_file(argv[i], outname);
          if (kerror == 0) 
 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
-            fprintf(STDERR, " PASS (%lu black pixels)\n",black_pixels);
+            fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
 #else
             fprintf(STDERR, " PASS\n");
 #endif
@@ -994,7 +1000,7 @@
          {
             if(verbose == 1 || i == 2)
 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
-                fprintf(STDERR, " PASS (%lu black pixels)\n",black_pixels);
+                fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
 #else
                 fprintf(STDERR, " PASS\n");
 #endif
diff --git a/pngtrans.c b/pngtrans.c
index d38dbd1..e8b9a19 100644
--- a/pngtrans.c
+++ b/pngtrans.c
@@ -1,12 +1,12 @@
 
 /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 #define PNG_INTERNAL
@@ -100,12 +100,6 @@
       png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
    else
       png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
-
-   /* This should probably go in the "do_filler" routine */
-   if (png_ptr->color_type == PNG_COLOR_TYPE_RGB && png_ptr->bit_depth == 8)
-   {
-      png_ptr->usr_channels = 4;
-   }
 }
 #endif
 
@@ -172,14 +166,13 @@
        row_info->bit_depth == 16)
    {
       png_bytep rp;
-      png_byte t;
       png_uint_32 i;
 
       for (i = 0, rp = row;
          i < row_info->width * row_info->channels;
          i++, rp += 2)
       {
-         t = *rp;
+         png_byte t = *rp;
          *rp = *(rp + 1);
          *(rp + 1) = t;
       }
@@ -338,6 +331,11 @@
       if (row_info->color_type == PNG_COLOR_TYPE_RGB ||
           row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 */
+      png_bytep sp=row;
+      png_bytep dp=row;
+      png_uint_32 width=row_info->width;
+      png_uint_32 i;
+
       if (row_info->channels == 4)
       {
          if (row_info->bit_depth == 8)
@@ -345,10 +343,8 @@
             /* This converts from RGBX or RGBA to RGB */
             if (flags & PNG_FLAG_FILLER_AFTER)
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
-               for (i = 1, sp = row + 4, dp = row + 3; i < row_info->width; i++)
+               dp+=3; sp+=4;
+               for (i = 1; i < width; i++)
                {
                   *dp++ = *sp++;
                   *dp++ = *sp++;
@@ -359,10 +355,7 @@
             /* This converts from XRGB or ARGB to RGB */
             else
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
-               for (i = 0, sp = row, dp = row; i < row_info->width; i++)
+               for (i = 0; i < width; i++)
                {
                   sp++;
                   *dp++ = *sp++;
@@ -371,17 +364,15 @@
                }
             }
             row_info->pixel_depth = 24;
-            row_info->rowbytes = row_info->width * 3;
+            row_info->rowbytes = width * 3;
          }
          else /* if (row_info->bit_depth == 16) */
          {
             if (flags & PNG_FLAG_FILLER_AFTER)
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
                /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
-               for (i = 1, sp = row + 8, dp = row + 6; i < row_info->width; i++)
+               sp += 8; dp += 6;
+               for (i = 1; i < width; i++)
                {
                   /* This could be (although memcpy is probably slower):
                   png_memcpy(dp, sp, 6);
@@ -399,17 +390,15 @@
             }
             else
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
                /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
-               for (i = 0, sp = row + 2, dp = row; i < row_info->width; i++)
+               for (i = 0; i < width; i++)
                {
                   /* This could be (although memcpy is probably slower):
                   png_memcpy(dp, sp, 6);
                   sp += 8;
                   dp += 6;
                   */
+                  sp+=2;
                   *dp++ = *sp++;
                   *dp++ = *sp++;
                   *dp++ = *sp++;
@@ -419,9 +408,10 @@
                }
             }
             row_info->pixel_depth = 48;
-            row_info->rowbytes = row_info->width * 6;
+            row_info->rowbytes = width * 6;
          }
          row_info->channels = 3;
+         row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
       }
 /*
       else if (row_info->color_type == PNG_COLOR_TYPE_GRAY ||
@@ -434,10 +424,7 @@
             /* This converts from GX or GA to G */
             if (flags & PNG_FLAG_FILLER_AFTER)
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
-               for (i = 1, sp = row + 2, dp = row + 1; i < row_info->width; i++)
+               for (i = 0; i < width; i++)
                {
                   *dp++ = *sp++;
                   sp++;
@@ -446,27 +433,22 @@
             /* This converts from XG or AG to G */
             else
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
-               for (i = 0, sp = row, dp = row; i < row_info->width; i++)
+               for (i = 0; i < width; i++)
                {
                   sp++;
                   *dp++ = *sp++;
                }
             }
             row_info->pixel_depth = 8;
-            row_info->rowbytes = row_info->width;
+            row_info->rowbytes = width;
          }
          else /* if (row_info->bit_depth == 16) */
          {
             if (flags & PNG_FLAG_FILLER_AFTER)
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
                /* This converts from GGXX or GGAA to GG */
-               for (i = 1, sp = row + 4, dp = row + 2; i < row_info->width; i++)
+               sp += 4; dp += 2;
+               for (i = 1; i < width; i++)
                {
                   *dp++ = *sp++;
                   *dp++ = *sp++;
@@ -475,11 +457,8 @@
             }
             else
             {
-               png_bytep sp, dp;
-               png_uint_32 i;
-
                /* This converts from XXGG or AAGG to GG */
-               for (i = 0, sp = row, dp = row; i < row_info->width; i++)
+               for (i = 0; i < width; i++)
                {
                   sp += 2;
                   *dp++ = *sp++;
@@ -487,9 +466,10 @@
                }
             }
             row_info->pixel_depth = 16;
-            row_info->rowbytes = row_info->width * 2;
+            row_info->rowbytes = width * 2;
          }
          row_info->channels = 1;
+         row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
       }
    }
 }
@@ -507,17 +487,17 @@
 #endif
        (row_info->color_type & PNG_COLOR_MASK_COLOR))
    {
+      png_uint_32 width = row_info->width;
       if (row_info->bit_depth == 8)
       {
          if (row_info->color_type == PNG_COLOR_TYPE_RGB)
          {
             png_bytep rp;
-            png_byte save;
             png_uint_32 i;
 
-            for (i = 0, rp = row; i < row_info->width; i++, rp += 3)
+            for (i = 0, rp = row; i < width; i++, rp += 3)
             {
-               save = *rp;
+               png_byte save = *rp;
                *rp = *(rp + 2);
                *(rp + 2) = save;
             }
@@ -525,12 +505,11 @@
          else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
          {
             png_bytep rp;
-            png_byte save;
             png_uint_32 i;
 
-            for (i = 0, rp = row; i < row_info->width; i++, rp += 4)
+            for (i = 0, rp = row; i < width; i++, rp += 4)
             {
-               save = *rp;
+               png_byte save = *rp;
                *rp = *(rp + 2);
                *(rp + 2) = save;
             }
@@ -541,33 +520,31 @@
          if (row_info->color_type == PNG_COLOR_TYPE_RGB)
          {
             png_bytep rp;
-            png_byte save[2];
             png_uint_32 i;
 
-            for (i = 0, rp = row; i < row_info->width; i++, rp += 6)
+            for (i = 0, rp = row; i < width; i++, rp += 6)
             {
-               save[0] = *rp;
-               save[1] = *(rp + 1);
+               png_byte save = *rp;
                *rp = *(rp + 4);
+               *(rp + 4) = save;
+               save = *(rp + 1);
                *(rp + 1) = *(rp + 5);
-               *(rp + 4) = save[0];
-               *(rp + 5) = save[1];
+               *(rp + 5) = save;
             }
          }
          else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
          {
             png_bytep rp;
-            png_byte save[2];
             png_uint_32 i;
 
-            for (i = 0, rp = row; i < row_info->width; i++, rp += 8)
+            for (i = 0, rp = row; i < width; i++, rp += 8)
             {
-               save[0] = *rp;
-               save[1] = *(rp + 1);
+               png_byte save = *rp;
                *rp = *(rp + 4);
+               *(rp + 4) = save;
+               save = *(rp + 1);
                *(rp + 1) = *(rp + 5);
-               *(rp + 4) = save[0];
-               *(rp + 5) = save[1];
+               *(rp + 5) = save;
             }
          }
       }
diff --git a/pngwio.c b/pngwio.c
index 444a123..40d2a98 100644
--- a/pngwio.c
+++ b/pngwio.c
@@ -1,12 +1,12 @@
 
 /* pngwio.c - functions for data output
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  *
  * This file provides a location for all output.  Users which need
  * special handling are expected to write functions which have the same
diff --git a/pngwrite.c b/pngwrite.c
index 9980027..b3444df 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,12 +1,12 @@
    
 /* pngwrite.c - general routines to write a PNG file
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 /* get internal access to png.h */
@@ -239,7 +239,7 @@
    {
       char near_time_buf[29];
       sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
-               ptime->day % 31, short_months[ptime->month - 1],
+               ptime->day % 32, short_months[(ptime->month - 1) % 12],
                ptime->year, ptime->hour % 24, ptime->minute % 60,
                ptime->second % 61);
       png_memcpy(png_ptr->time_buffer, near_time_buf,
@@ -247,7 +247,7 @@
    }
 #else
    sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
-               ptime->day % 31, short_months[ptime->month - 1],
+               ptime->day % 32, short_months[(ptime->month - 1) % 12],
                ptime->year, ptime->hour % 24, ptime->minute % 60,
                ptime->second % 61);
 #endif
diff --git a/pngwtran.c b/pngwtran.c
index d85e015..2fd4a75 100644
--- a/pngwtran.c
+++ b/pngwtran.c
@@ -1,12 +1,12 @@
 
 /* pngwtran.c - transforms the data in a row for PNG writers
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 #define PNG_INTERNAL
@@ -96,13 +96,15 @@
          {
             png_bytep sp, dp;
             int mask, v;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
             sp = row;
             dp = row;
             mask = 0x80;
             v = 0;
-            for (i = 0; i < row_info->width; i++)
+           
+            istop = row_info->width;
+            for (i = 0; i < istop; i++)
             {
                if (*sp != 0)
                   v |= mask;
@@ -125,13 +127,14 @@
          {
             png_bytep sp, dp;
             int shift, v;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
             sp = row;
             dp = row;
             shift = 6;
             v = 0;
-            for (i = 0; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0; i < istop; i++)
             {
                png_byte value;
 
@@ -156,13 +159,14 @@
          {
             png_bytep sp, dp;
             int shift, v;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
             sp = row;
             dp = row;
             shift = 4;
             v = 0;
-            for (i = 0; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0; i < istop; i++)
             {
                png_byte value;
 
@@ -246,7 +250,7 @@
       if (row_info->bit_depth < 8)
       {
          png_bytep bp;
-         png_uint_32 i;
+         png_uint_32 i, istop;
          png_byte mask;
 
          if (bit_depth->gray == 1 && row_info->bit_depth == 2)
@@ -256,7 +260,8 @@
          else
             mask = 0xff;
 
-         for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++)
+         istop = row_info->rowbytes;
+         for (bp = row, i = 0; i < istop; i++, bp++)
          {
             png_uint_16 v;
             int j;
@@ -275,9 +280,10 @@
       else if (row_info->bit_depth == 8)
       {
          png_bytep bp;
-         png_uint_32 i;
+         png_uint_32 i, istop;
 
-         for (bp = row, i = 0; i < row_info->width; i++)
+         istop = row_info->width;
+         for (bp = row, i = 0; i < istop; i++)
          {
             png_uint_32 c;
 
@@ -301,9 +307,10 @@
       else
       {
          png_bytep bp;
-         png_uint_32 i;
+         png_uint_32 i, istop;
 
-         for (bp = row, i = 0; i < row_info->width * row_info->channels; i++)
+         istop = row_info->width;
+         for (bp = row, i = 0; i < istop; i++)
          {
             png_uint_32 c;
 
@@ -345,12 +352,12 @@
          if (row_info->bit_depth == 8)
          {
             png_bytep sp, dp;
-            png_byte save;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
-               save = *(sp++);
+               png_byte save = *(sp++);
                *(dp++) = *(sp++);
                *(dp++) = *(sp++);
                *(dp++) = *(sp++);
@@ -361,11 +368,12 @@
          else
          {
             png_bytep sp, dp;
-            png_byte save[2];
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
+               png_byte save[2];
                save[0] = *(sp++);
                save[1] = *(sp++);
                *(dp++) = *(sp++);
@@ -385,12 +393,12 @@
          if (row_info->bit_depth == 8)
          {
             png_bytep sp, dp;
-            png_byte save;
             png_uint_32 i;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
-               save = *(sp++);
+               png_byte save = *(sp++);
                *(dp++) = *(sp++);
                *(dp++) = save;
             }
@@ -399,11 +407,12 @@
          else
          {
             png_bytep sp, dp;
-            png_byte save[2];
             png_uint_32 i;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
+               png_byte save[2];
                save[0] = *(sp++);
                save[1] = *(sp++);
                *(dp++) = *(sp++);
@@ -432,9 +441,10 @@
          if (row_info->bit_depth == 8)
          {
             png_bytep sp, dp;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
                *(dp++) = *(sp++);
                *(dp++) = *(sp++);
@@ -446,9 +456,10 @@
          else
          {
             png_bytep sp, dp;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
                *(dp++) = *(sp++);
                *(dp++) = *(sp++);
@@ -467,9 +478,10 @@
          if (row_info->bit_depth == 8)
          {
             png_bytep sp, dp;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
                *(dp++) = *(sp++);
                *(dp++) = 255 - *(sp++);
@@ -479,9 +491,10 @@
          else
          {
             png_bytep sp, dp;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
-            for (i = 0, sp = dp = row; i < row_info->width; i++)
+            istop = row_info->width;
+            for (i = 0, sp = dp = row; i < istop; i++)
             {
                *(dp++) = *(sp++);
                *(dp++) = *(sp++);
diff --git a/pngwutil.c b/pngwutil.c
index 492bde7..8d56232 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,12 +1,12 @@
 
 /* pngwutil.c - utilities to write a PNG file
  *
- * libpng 1.0.1
+ * libpng 1.0.1a
  * 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
  * Copyright (c) 1998, Glenn Randers-Pehrson
- * March 15, 1998
+ * April 21, 1998
  */
 
 #define PNG_INTERNAL
@@ -1241,7 +1241,7 @@
    if (pass < 6)
 #endif
    {
-      /* each pixel depth is handled seperately */
+      /* each pixel depth is handled separately */
       switch (row_info->pixel_depth)
       {
          case 1:
@@ -1251,12 +1251,13 @@
             int shift;
             int d;
             int value;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
             dp = row;
             d = 0;
             shift = 7;
-            for (i = png_pass_start[pass]; i < row_info->width;
+            istop = row_info->width;
+            for (i = png_pass_start[pass]; i < istop;
                i += png_pass_inc[pass])
             {
                sp = row + (png_size_t)(i >> 3);
@@ -1284,12 +1285,13 @@
             int shift;
             int d;
             int value;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
             dp = row;
             shift = 6;
             d = 0;
-            for (i = png_pass_start[pass]; i < row_info->width;
+            istop = row_info->width;
+            for (i = png_pass_start[pass]; i < istop;
                i += png_pass_inc[pass])
             {
                sp = row + (png_size_t)(i >> 2);
@@ -1316,12 +1318,13 @@
             int shift;
             int d;
             int value;
-            png_uint_32 i;
+            png_uint_32 i, istop;
 
             dp = row;
             shift = 4;
             d = 0;
-            for (i = png_pass_start[pass]; i < row_info->width;
+            istop = row_info->width;
+            for (i = png_pass_start[pass]; i < istop;
                i += png_pass_inc[pass])
             {
                sp = row + (png_size_t)(i >> 1);
@@ -1345,7 +1348,7 @@
          {
             png_bytep sp;
             png_bytep dp;
-            png_uint_32 i;
+            png_uint_32 i, istop;
             png_size_t pixel_bytes;
 
             /* start at the beginning */
@@ -1354,7 +1357,8 @@
             pixel_bytes = (row_info->pixel_depth >> 3);
             /* loop through the row, only looking at the pixels that
                matter */
-            for (i = png_pass_start[pass]; i < row_info->width;
+            istop = row_info->width;
+            for (i = png_pass_start[pass]; i < istop;
                i += png_pass_inc[pass])
             {
                /* find out where the original pixel is */
@@ -1392,6 +1396,7 @@
 {
    png_bytep prev_row, best_row, row_buf;
    png_uint_32 mins, bpp;
+   png_byte filter_to_do = png_ptr->do_filter;
 
    png_debug(1, "in png_write_find_filter\n");
    /* find out how many bytes offset each pixel is */
@@ -1405,7 +1410,7 @@
     * smallest value when summing the absolute values of the distances
     * from zero using anything >= 128 as negative numbers.  This is known
     * as the "minimum sum of absolute differences" heuristic.  Other
-    * heuristics are the "weighted minumum sum of absolute differences"
+    * heuristics are the "weighted minimum sum of absolute differences"
     * (experimental and can in theory improve compression), and the "zlib
     * predictive" method (not implemented in libpng 0.95), which does test
     * compressions of lines using different filter methods, and then chooses
@@ -1413,18 +1418,20 @@
     * computationally expensive).
     */
 
+
    /* We don't need to test the 'no filter' case if this is the only filter
     * that has been chosen, as it doesn't actually do anything to the data.
     */
-   if (png_ptr->do_filter & PNG_FILTER_NONE &&
-       png_ptr->do_filter != PNG_FILTER_NONE)
+   if (filter_to_do & PNG_FILTER_NONE &&
+       filter_to_do != PNG_FILTER_NONE)
    {
       png_bytep rp;
       png_uint_32 sum = 0;
-      png_uint_32 i;
+      png_uint_32 i,istop;
       int v;
 
-      for (i = 0, rp = row_buf + 1; i < row_info->rowbytes; i++, rp++)
+      istop = row_info->rowbytes;
+      for (i = 0, rp = row_buf + 1; i < istop; i++, rp++)
       {
          v = *rp;
          sum += (v < 128) ? v : 256 - v;
@@ -1438,9 +1445,10 @@
          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
 
          /* Reduce the sum if we match any of the previous rows */
-         for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
+         istop = (png_uint_32)png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
-            if (png_ptr->prev_filters[i] == PNG_FILTER_NONE)
+            if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_NONE)
             {
                sumlo = (sumlo * png_ptr->filter_weights[i]) >>
                   PNG_WEIGHT_SHIFT;
@@ -1468,15 +1476,34 @@
    }
 
    /* sub filter */
-   if (png_ptr->do_filter & PNG_FILTER_SUB)
+   if (filter_to_do == PNG_FILTER_SUB)
+   /* it's the only filter so no testing is needed */
+   {
+      png_bytep rp, lp, dp;
+      png_uint_32 i,istop;
+      for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
+           i++, rp++, dp++)
+      {
+         *dp = *rp;
+      }
+      istop = row_info->rowbytes;
+      for (lp = row_buf + 1; i < istop;
+         i++, rp++, lp++, dp++)
+      {
+         *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
+      }
+      best_row = png_ptr->sub_row;
+   }
+
+   else if (filter_to_do & PNG_FILTER_SUB)
    {
       png_bytep rp, dp, lp;
       png_uint_32 sum = 0, lmins = mins;
-      png_uint_32 i;
+      png_uint_32 i, istop;
       int v;
 
 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
-      /* We temporarily increase the "minumum sum" by the factor we
+      /* We temporarily increase the "minimum sum" by the factor we
        * would reduce the sum of this filter, so that we can do the
        * early exit comparison without scaling the sum each time.
        */
@@ -1486,7 +1513,8 @@
          lmlo = lmins & PNG_LOMASK;
          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
+         istop = (png_uint_32)png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
             if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
             {
@@ -1534,7 +1562,8 @@
          sumlo = sum & PNG_LOMASK;
          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
+         istop = (png_uint_32)png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
             if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
             {
@@ -1565,13 +1594,29 @@
    }
 
    /* up filter */
-   if (png_ptr->do_filter & PNG_FILTER_UP)
+   if (filter_to_do == PNG_FILTER_UP)
+   {
+      png_bytep rp, dp, pp;
+      png_uint_32 i, istop;
+
+      istop = row_info->rowbytes;
+      for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
+           pp = prev_row + 1; i < istop;
+           i++, rp++, pp++, dp++)
+      {
+         *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
+      }
+      best_row = png_ptr->up_row;
+   }
+
+   else if (filter_to_do & PNG_FILTER_UP)
    {
       png_bytep rp, dp, pp;
       png_uint_32 sum = 0, lmins = mins;
-      png_uint_32 i;
+      png_uint_32 i, istop;
       int v;
 
+
 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
       if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
       {
@@ -1579,7 +1624,8 @@
          lmlo = lmins & PNG_LOMASK;
          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
+         istop = (png_uint_32)png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
             if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
             {
@@ -1602,8 +1648,9 @@
       }
 #endif
 
+      istop = row_info->rowbytes;
       for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
-           pp = prev_row + 1; i < row_info->rowbytes;
+           pp = prev_row + 1; i < istop;
            i++, rp++, pp++, dp++)
       {
          v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
@@ -1621,9 +1668,10 @@
          sumlo = sum & PNG_LOMASK;
          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
+         istop = (png_uint_32)png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
-            if (png_ptr->prev_filters[i] == PNG_FILTER_UP)
+            if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
             {
                sumlo = (sumlo * png_ptr->filter_weights[i]) >>
                   PNG_WEIGHT_SHIFT;
@@ -1652,11 +1700,28 @@
    }
 
    /* avg filter */
-   if (png_ptr->do_filter & PNG_FILTER_AVG)
+   if (filter_to_do == PNG_FILTER_AVG)
+   {
+      png_bytep rp, dp, pp, lp;
+      png_uint_32 i,istop;
+      for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
+           pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
+      {
+         *dp = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
+      }
+      istop = row_info->rowbytes;
+      for (lp = row_buf + 1; i < istop; i++, rp++, pp++, lp++, dp++)
+      {
+         *dp = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
+      }
+      best_row = png_ptr->avg_row;
+   }
+
+   else if (filter_to_do & PNG_FILTER_AVG)
    {
       png_bytep rp, dp, pp, lp;
       png_uint_32 sum = 0, lmins = mins;
-      png_uint_32 i;
+      png_uint_32 i,istop;
       int v;
 
 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1666,7 +1731,8 @@
          lmlo = lmins & PNG_LOMASK;
          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
+         istop = (png_uint_32)png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
             if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_AVG)
             {
@@ -1696,8 +1762,8 @@
 
          sum += (v < 128) ? v : 256 - v;
       }
-      for (lp = row_buf + 1; i < row_info->rowbytes;
-           i++, rp++, pp++, lp++, dp++)
+      istop = row_info->rowbytes;
+      for (lp = row_buf + 1; i < istop; i++, rp++, pp++, lp++, dp++)
       {
          v = *dp = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
 
@@ -1714,9 +1780,10 @@
          sumlo = sum & PNG_LOMASK;
          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < png_ptr->num_prev_filters; i++)
+         istop = png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
-            if (png_ptr->prev_filters[i] == PNG_FILTER_NONE)
+            if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_NONE)
             {
                sumlo = (sumlo * png_ptr->filter_weights[i]) >>
                   PNG_WEIGHT_SHIFT;
@@ -1745,11 +1812,50 @@
    }
 
    /* Paeth filter */
-   if (png_ptr->do_filter & PNG_FILTER_PAETH)
+   if (filter_to_do == PNG_FILTER_PAETH)
+   {
+      png_bytep rp, dp, pp, cp, lp;
+      png_uint_32 i, istop;
+      for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
+           pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
+      {
+         *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
+      }
+
+      istop = row_info->rowbytes;
+      for (lp = row_buf + 1, cp = prev_row + 1; i < istop;
+           i++, rp++, pp++, lp++, dp++, cp++)
+      {
+         int a, b, c, pa, pb, pc, p;
+
+         b = *pp;
+         c = *cp;
+         a = *lp;
+
+         p = a + b - c;
+
+#ifdef PNG_USE_ABS
+         pa = abs(p - a);
+         pb = abs(p - b);
+         pc = abs(p - c);
+#else
+         pa = p > a ? p - a : a - p;
+         pb = p > b ? p - b : b - p;
+         pc = p > c ? p - c : c - p;
+#endif
+
+         p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+
+         *dp = (png_byte)(((int)*rp - p) & 0xff);
+      }
+      best_row = png_ptr->paeth_row;
+   }
+
+   else if (filter_to_do & PNG_FILTER_PAETH)
    {
       png_bytep rp, dp, pp, cp, lp;
       png_uint_32 sum = 0, lmins = mins;
-      png_uint_32 i;
+      png_uint_32 i, istop;
       int v;
 
 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1759,7 +1865,8 @@
          lmlo = lmins & PNG_LOMASK;
          lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < png_ptr->num_prev_filters; i++)
+         istop = png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
             if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_PAETH)
             {
@@ -1783,13 +1890,15 @@
 #endif
 
       for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
-           pp = prev_row + 1; (unsigned)i < bpp; i++, rp++, pp++, dp++)
+           pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
       {
          v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
 
          sum += (v < 128) ? v : 256 - v;
       }
-      for (lp = row_buf + 1, cp = prev_row + 1; i < row_info->rowbytes;
+
+      istop = row_info->rowbytes;
+      for (lp = row_buf + 1, cp = prev_row + 1; i < istop;
            i++, rp++, pp++, lp++, dp++, cp++)
       {
          int a, b, c, pa, pb, pc, p;
@@ -1799,16 +1908,30 @@
          a = *lp;
 
          p = a + b - c;
+
+#ifndef PNG_SLOW_PAETH
+#ifdef PNG_USE_ABS
          pa = abs(p - a);
          pb = abs(p - b);
          pc = abs(p - c);
+#else
+         pa = p > a ? p - a : a - p;
+         pb = p > b ? p - b : b - p;
+         pc = p > c ? p - c : c - p;
+#endif
 
+         p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+#else /* PNG_SLOW_PAETH */
+         pa = abs(p - a);
+         pb = abs(p - b);
+         pc = abs(p - c);
          if (pa <= pb && pa <= pc)
             p = a;
          else if (pb <= pc)
             p = b;
          else
             p = c;
+#endif /* PNG_SLOW_PAETH */
 
          v = *dp = (png_byte)(((int)*rp - p) & 0xff);
 
@@ -1825,9 +1948,10 @@
          sumlo = sum & PNG_LOMASK;
          sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
 
-         for (i = 0; i < png_ptr->num_prev_filters; i++)
+         istop =  png_ptr->num_prev_filters;
+         for (i = 0; i < istop; i++)
          {
-            if (png_ptr->prev_filters[i] == PNG_FILTER_PAETH)
+            if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_PAETH)
             {
                sumlo = (sumlo * png_ptr->filter_weights[i]) >>
                   PNG_WEIGHT_SHIFT;
@@ -1855,15 +1979,17 @@
    }
 
    /* Do the actual writing of the filtered row data from the chosen filter. */
+
    png_write_filtered_row(png_ptr, best_row);
 
 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
    /* Save the type of filter we picked this time for future calculations */
    if (png_ptr->num_prev_filters > 0)
    {
-      int i;
+      int i, istop;
 
-      for (i = 1; i < (int)png_ptr->num_prev_filters; i++)
+      istop = (int)png_ptr->num_prev_filters;
+      for (i = 1; i < istop; i++)
       {
          png_ptr->prev_filters[i] = png_ptr->prev_filters[i - 1];
       }
diff --git a/scripts/makefile.lnx b/scripts/makefile.lnx
index 3d1a76a..2cbf84f 100644
--- a/scripts/makefile.lnx
+++ b/scripts/makefile.lnx
@@ -11,11 +11,16 @@
 ZLIBLIB=../zlib
 ZLIBINC=../zlib
 
+ALIGN=
+# For I-386:
+#ALIGN=-malign-loops=2 -malign-functions=2
+
 WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
          -Wmissing-declarations -Wtraditional -Wcast-align \
          -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
-CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops -malign-loops=2 \
-       -malign-functions=2 #$(WARNMORE) -g -DPNG_DEBUG=5
+
+CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops \
+     $(ALIGN) #$(WARNMORE) -g -DPNG_DEBUG=5
 LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
 
 RANLIB=ranlib
@@ -24,7 +29,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
+PNGMIN = 1.0.1a
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # where make install puts libpng.a, libpng.so*, and png.h
diff --git a/scripts/makefile.s2x b/scripts/makefile.s2x
index 163f363..9ed0743 100644
--- a/scripts/makefile.s2x
+++ b/scripts/makefile.s2x
@@ -20,7 +20,7 @@
          -Wmissing-declarations -Wtraditional -Wcast-align \
          -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
 CFLAGS=-I$(ZLIBINC) -Wall -O3 \
-      #$(WARNMORE) -g -DPNG_DEBUG=5
+      # $(WARNMORE) -g -DPNG_DEBUG=5
 LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng -lz -lm
 
 #RANLIB=ranlib
@@ -29,7 +29,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
+PNGMIN = 1.0.1a
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # where make install puts libpng.a, libpng.so*, and png.h
diff --git a/scripts/makefile.sgi b/scripts/makefile.sgi
index 965cf91..c2be939 100644
--- a/scripts/makefile.sgi
+++ b/scripts/makefile.sgi
@@ -10,7 +10,8 @@
 
 CC=cc
 
-CFLAGS=-I$(ZLIBINC) -O -fullwarn # -g -DPNG_DEBUG=1
+WARNMORE=-fullwarn
+CFLAGS=-I$(ZLIBINC) -O # $(WARNMORE) -g -DPNG_DEBUG=5
 LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
 
 RANLIB=echo
diff --git a/scripts/makefile.std b/scripts/makefile.std
index 7cc6059..ddb5a29 100644
--- a/scripts/makefile.std
+++ b/scripts/makefile.std
@@ -9,7 +9,7 @@
 ZLIBINC=../zlib
 
 CC=cc
-CFLAGS=-I$(ZLIBINC) -O # -g -DPNG_DEBUG=1
+CFLAGS=-I$(ZLIBINC) -O # -g -DPNG_DEBUG=5
 LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
 
 #RANLIB=echo
diff --git a/scripts/makefile.sun b/scripts/makefile.sun
index 975ca17..1f96f22 100644
--- a/scripts/makefile.sun
+++ b/scripts/makefile.sun
@@ -13,7 +13,7 @@
          -Wmissing-declarations -Wtraditional -Wcast-align \
          -Wstrict-prototypes -Wmissing-prototypes
 CC=gcc
-CFLAGS=-I$(ZLIBINC) -O $(WARNMORE) -DPNG_DEBUG=4
+CFLAGS=-I$(ZLIBINC) -O # $(WARNMORE) -DPNG_DEBUG=5
 LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
 
 RANLIB=ranlib
diff --git a/scripts/makefile.wat b/scripts/makefile.wat
index a715acb..cf004db 100644
--- a/scripts/makefile.wat
+++ b/scripts/makefile.wat
@@ -1,5 +1,5 @@
 # Makefile for libpng
-# Watcom 10a and later 32-bit protected mode flat memory model
+# Watcom 10.0a and later 32-bit protected mode flat memory model
 
 # Adapted by Pawel Mrochen, based on makefile.msc
 # For conditions of distribution and use, see copyright notice in png.h
@@ -7,9 +7,9 @@
 
 # To use, do "wmake -f makefile.wat"
 
-# ------------- Watcom 10a and later -------------
+# ------------- Watcom 10.0a and later -------------
 MODEL=-mf
-CFLAGS= $(MODEL) -fpi87 -fp5 -5r -oaeilmnrt -s -zp4 -i=..\zlib
+CFLAGS= $(MODEL) -5r -fp5 -fpi87 -oneatx -zp8 -i=..\zlib
 CC=wcc386
 LD=wcl386
 LIB=wlib -b -c
@@ -75,9 +75,9 @@
 	$(CC) $(CFLAGS) $*.c $(ERRFILE)
 
 libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
-	$(LIB) -n libpng.lib +$(OBJS1)
-	$(LIB) libpng.lib +$(OBJS2)
-	$(LIB) libpng.lib +$(OBJS3)
+	$(LIB) -n libpng.lib $(OBJS1)
+	$(LIB) libpng.lib $(OBJS2)
+	$(LIB) libpng.lib $(OBJS3)
 
 pngtest.exe: pngtest.obj libpng.lib
 	$(LD) $(LDFLAGS) pngtest.obj libpng.lib ..\zlib\zlib.lib