summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ANNOUNCE40
-rw-r--r--CHANGES11
-rw-r--r--KNOWNBUG20
-rw-r--r--libpng.36
-rw-r--r--libpng.txt2
-rw-r--r--libpngpf.32
-rw-r--r--png.52
-rw-r--r--png.c6
-rw-r--r--png.h87
-rw-r--r--pngconf.h4
-rw-r--r--pngerror.c4
-rw-r--r--pngget.c4
-rw-r--r--pngmem.c4
-rw-r--r--pngpread.c4
-rw-r--r--pngread.c95
-rw-r--r--pngrio.c4
-rw-r--r--pngrtran.c432
-rw-r--r--pngrutil.c276
-rw-r--r--pngset.c4
-rw-r--r--pngtest.c4
-rw-r--r--pngtrans.c54
-rw-r--r--pngwio.c4
-rw-r--r--pngwrite.c34
-rw-r--r--pngwtran.c96
-rw-r--r--pngwutil.c247
-rw-r--r--scripts/makefile.lnx4
-rw-r--r--scripts/makefile.s2x2
-rw-r--r--scripts/makefile.sco97
-rw-r--r--scripts/makefile.sgi2
29 files changed, 839 insertions, 712 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index 520d7998b..5f7effbb4 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,24 +1,34 @@
-Libpng 1.0.1a April 21, 1998
+Libpng 1.0.1b May 2, 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:
+Changes since the last public 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).
+libpng-1.0.1a:
+ 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).
+libpng-1.0.1b:
+ Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
+ Relocated the png_composite macros from pngrtran.c to png.h (Greg).
+ Added makefile.sco (contributed by Mike Hopkirk).
+ Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a.
+ Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
+ More work on the Paeth-filtering, achieving imperceptible speedup (A Kleinert).
+ More work on loop optimization which may help when compiled with C++ compilers.
+ Added warnings when people try to use transforms they've defined out.
Send comments/corrections/commendations to
png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu
diff --git a/CHANGES b/CHANGES
index a56c3b303..42a901d84 100644
--- a/CHANGES
+++ b/CHANGES
@@ -300,4 +300,13 @@ version 1.0.1a [April 21, 1998]
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)
+ Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen).
+version 1.0.1b [May 2, 1998]
+ Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
+ Relocated the png_composite macros from pngrtran.c to png.h (Greg).
+ Added makefile.sco (contributed by Mike Hopkirk).
+ Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a.
+ Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
+ More work on the Paeth-filtering, achieving imperceptible speedup (A Kleinert).
+ More work on loop optimization which may help when compiled with C++ compilers.
+ Added warnings when people try to use transforms they've defined out.
diff --git a/KNOWNBUG b/KNOWNBUG
index 205f5fd3d..64ab68da9 100644
--- a/KNOWNBUG
+++ b/KNOWNBUG
@@ -111,3 +111,23 @@ Known bugs and suggested enhancements in libpng-1.0.1
The "ptime->date % 31" is wrong, should be "ptime->date % 32".
STATUS: Fixed in libpng-1.0.1a
+
+11. April 21, 1998 -- ENHANCEMENT -- relocation of composite macros
+
+ png_composite() and png_composite_16() relocated to png.h
+
+ STATUS: Done in libpng-1.0.1b
+
+12. April 22, 1998 -- ENHANCEMENT -- makefile.sco
+
+ Mike Hopkirk contributed a makefile for SCO osr5 and sco UW7
+
+ STATUS: Added to libpng-1.0.1b distribution
+
+13: April 30, 1998 -- ENHANCEMENT -- warnings
+
+ When people define out some of the read transformations and then
+ try to use them, the request is silently ignored. It was suggested
+ that a warning be issued in such cases.
+
+ STATUS: Done in libpng-1.0.1b
diff --git a/libpng.3 b/libpng.3
index 34866ba91..eecbdaf33 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,4 +1,4 @@
-.TH LIBPNG 3 "April 21, 1998"
+.TH LIBPNG 3 "May 2, 1998"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library
.SH SYNOPSIS
@@ -396,7 +396,7 @@ Following is a copy of the libpng.txt file that accompanies libpng.
.SH LIBPNG.TXT
libpng.txt - A description on how to use and modify libpng
- libpng version 1.0.1a April 21, 1998
+ libpng version 1.0.1b May 2, 1998
Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson
@@ -2372,7 +2372,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
-Libpng version 1.0.1a April 21, 1998:
+Libpng version 1.0.1b May 2, 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 f0a5f6ee0..02ac83cfd 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.1a April 21, 1998
+ libpng version 1.0.1b May 2, 1998
Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson
diff --git a/libpngpf.3 b/libpngpf.3
index 387f89834..9c69fb5cf 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,4 +1,4 @@
-.TH LIBPNGPF 3 "April 21, 1998"
+.TH LIBPNGPF 3 "May 2, 1998"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library
(private functions)
diff --git a/png.5 b/png.5
index 5ba249503..60d392c2b 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "April 21, 1998"
+.TH PNG 5 "May 2, 1998"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION
diff --git a/png.c b/png.c
index 513212af8..d76aee2b1 100644
--- a/png.c
+++ b/png.c
@@ -1,12 +1,12 @@
/* png.c - location for general purpose libpng functions
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 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.1a";
+char png_libpng_ver[12] = "1.0.1b";
/* 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 b84a78744..3f509b5c0 100644
--- a/png.h
+++ b/png.h
@@ -1,12 +1,12 @@
/* png.h - header file for PNG reference library
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*
* Note about libpng version numbers:
*
@@ -18,30 +18,31 @@
*
* source png.h png.h shared-lib
* version string int version
- * ------- ------ ------ ----------
- * 0.89c ("1.0 beta 3") 0.89 89 1.0.89
- * 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
- * 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
- * 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
- * 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
- * 0.97c 0.97 97 2.0.97
- * 0.98 0.98 98 2.0.98
- * 0.99 0.99 98 2.0.99
- * 0.99a-m 0.99 99 2.0.99
- * 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
+ * ------- ------ ----- ----------
+ * 0.89c ("1.0 beta 3") 0.89 89 1.0.89
+ * 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
+ * 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
+ * 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
+ * 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
+ * 0.97c 0.97 97 2.0.97
+ * 0.98 0.98 98 2.0.98
+ * 0.99 0.99 98 2.0.99
+ * 0.99a-m 0.99 99 2.0.99
+ * 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
+ * 1.0.1b 1.0.1b 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
- * used for changes in backward compatibility, as it is intended.
- * 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).
+ * used for changes in backward compatibility, as it is intended. 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 or libpng.3 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,7 +119,7 @@ extern "C" {
*/
/* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.0.1a"
+#define PNG_LIBPNG_VER_STRING "1.0.1b"
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros.
@@ -1443,6 +1444,45 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#define png_debug2(l, m, p1, p2)
#endif /* (PNG_DEBUG > 0) */
+#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
+/* With these routines, we avoid an integer divide, which will be slower on
+ * many machines. However, it does take more operations than the corresponding
+ * divide method, so it may be slower on some RISC systems. There are two
+ * shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
+ *
+ * Note that the rounding factors are NOT supposed to be the same! 128 and
+ * 32768 are correct for the NODIV code; 127 and 32767 are correct for the
+ * standard method.
+ *
+ * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
+ */
+
+ /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
+# define png_composite(composite, fg, alpha, bg) \
+ { png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
+ (png_uint_16)(bg)*(png_uint_16)(255 - \
+ (png_uint_16)(alpha)) + (png_uint_16)128); \
+ (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
+# define png_composite_16(composite, fg, alpha, bg) \
+ { png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
+ (png_uint_32)(bg)*(png_uint_32)(65535L - \
+ (png_uint_32)(alpha)) + (png_uint_32)32768L); \
+ (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
+
+#else /* standard method using integer division */
+
+ /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
+# define png_composite(composite, fg, alpha, bg) \
+ (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
+ (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
+ (png_uint_16)127) / 255)
+# define png_composite_16(composite, fg, alpha, bg) \
+ (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
+ (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
+ (png_uint_32)32767) / (png_uint_32)65535L)
+
+#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
+
/* These next functions are used internally in the code. They generally
* shouldn't be used unless you are writing code to add or replace some
* functionality in libpng. More information about most functions can
@@ -1525,6 +1565,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#define PNG_FLAG_FREE_HIST 0x4000
#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
#define PNG_FLAG_WROTE_tIME 0x10000L
+#define PNG_FLAG_BACKGROUND_IS_GRAY 0x20000L
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)
diff --git a/pngconf.h b/pngconf.h
index cf9213289..74f393762 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,12 +1,12 @@
/* pngconf.h - machine configurable file for libpng
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*/
/* Any machine specific code is near the front of this file, so if you
diff --git a/pngerror.c b/pngerror.c
index 4d221139d..0e801245d 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -1,12 +1,12 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 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 0dab0dda4..dd7b5c4c7 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,12 +1,12 @@
/* pngget.c - retrieval of values from info struct
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*/
#define PNG_INTERNAL
diff --git a/pngmem.c b/pngmem.c
index 2c0537f7e..bc8fb4b5b 100644
--- a/pngmem.c
+++ b/pngmem.c
@@ -1,12 +1,12 @@
/* pngmem.c - stub functions for memory allocation
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*
* This file provides a location for all memory allocation. Users who
* need special memory handling are expected to modify the code in this file
diff --git a/pngpread.c b/pngpread.c
index 5a1812be3..87c4b0178 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1,12 +1,12 @@
/* pngpread.c - read a png file in push mode
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*/
#define PNG_INTERNAL
diff --git a/pngread.c b/pngread.c
index 70a2af5de..402c382db 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,12 +1,12 @@
/* pngread.c - read a PNG file
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*
* This file contains routines that an application calls directly to
* read a PNG file or stream.
@@ -279,6 +279,38 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
+ if (png_ptr->row_number == 0 && png_ptr->pass == 0)
+ {
+ /* check for transforms that have been set but were defined out */
+#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
+ if (png_ptr->transformations & PNG_INVERT_MONO)
+ png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
+#endif
+#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
+ if (png_ptr->transformations & PNG_FILLER)
+ png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
+#endif
+#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
+#endif
+#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACK)
+ png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
+#endif
+#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
+ if (png_ptr->transformations & PNG_SHIFT)
+ png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
+#endif
+#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
+ if (png_ptr->transformations & PNG_BGR)
+ png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
+#endif
+#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_SWAP_BYTES)
+ png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
+#endif
+ }
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* if interlaced and we do not need a new row, combine row and return */
@@ -488,25 +520,34 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
/* save jump buffer and error functions */
rp = row;
dp = display_row;
- for (i = 0; i < num_rows; i++)
- {
- png_bytep rptr;
- png_bytep dptr;
-
- if (rp != NULL)
- rptr = *rp;
- else
- rptr = NULL;
- if (dp != NULL)
- dptr = *dp;
- else
- dptr = NULL;
- png_read_row(png_ptr, rptr, dptr);
- if (row != NULL)
- rp++;
- if (display_row != NULL)
- dp++;
- }
+ if(rp != NULL && dp != NULL)
+ for (i = 0; i < num_rows; i++)
+ {
+ png_bytep rptr = *rp++;
+ png_bytep dptr = *dp++;
+
+ png_read_row(png_ptr, rptr, dptr);
+ }
+ else
+ for (i = 0; i < num_rows; i++)
+ {
+ png_bytep rptr;
+ png_bytep dptr;
+
+ if (rp != NULL)
+ rptr = *rp;
+ else
+ rptr = NULL;
+ if (dp != NULL)
+ dptr = *dp;
+ else
+ dptr = NULL;
+ png_read_row(png_ptr, rptr, dptr);
+ if (row != NULL)
+ rp++;
+ if (display_row != NULL)
+ dp++;
+ }
}
/* Read the entire image. If the image has an alpha channel or a tRNS
@@ -729,8 +770,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
#if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table != NULL)
{
- int i,istop;
- istop = (1 << (8 - png_ptr->gamma_shift));
+ int i;
+ int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_table[i]);
@@ -741,8 +782,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_16_table);
if (png_ptr->gamma_16_from_1 != NULL)
{
- int i,istop;
- istop = (1 << (8 - png_ptr->gamma_shift));
+ int i;
+ int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
@@ -751,8 +792,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_16_from_1);
if (png_ptr->gamma_16_to_1 != NULL)
{
- int i,istop;
- istop = (1 << (8 - png_ptr->gamma_shift));
+ int i;
+ int 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 d0a4646ce..5d723d09c 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -1,12 +1,12 @@
/* pngrio.c - functions for data input
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 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 1b925a7fd..157ba2baa 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.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*
* This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG.
@@ -17,46 +17,6 @@
#define PNG_INTERNAL
#include "png.h"
-#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
-/* With these routines, we avoid an integer divide, which will be slower on
- * many machines. However, it does take more operations than the corresponding
- * divide method, so it may be slower on some RISC systems. There are two
- * shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
- *
- * Note that the rounding factors are NOT supposed to be the same! 128 and
- * 32768 are correct for the NODIV code; 127 and 32767 are correct for the
- * standard method.
- *
- * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
- */
-
- /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
-# define png_composite(composite, fg, alpha, bg) \
- { png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
- (png_uint_16)(bg)*(png_uint_16)(255 - \
- (png_uint_16)(alpha)) + (png_uint_16)128); \
- (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
-# define png_composite_16(composite, fg, alpha, bg) \
- { png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
- (png_uint_32)(bg)*(png_uint_32)(65535L - \
- (png_uint_32)(alpha)) + (png_uint_32)32768L); \
- (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
-
-#else /* standard method using integer division */
-
- /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
-# define png_composite(composite, fg, alpha, bg) \
- (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
- (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
- (png_uint_16)127) / 255)
-# define png_composite_16(composite, fg, alpha, bg) \
- (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
- (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
- (png_uint_32)32767) / (png_uint_32)65535L)
-
-#endif /* ?PNG_READ_COMPOSITE_NODIV_SUPPORTED */
-
-
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
void
png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
@@ -125,11 +85,21 @@ png_set_background(png_structp png_ptr,
}
png_ptr->transformations |= PNG_BACKGROUND;
- png_memcpy(&(png_ptr->background), background_color,
- sizeof(png_color_16));
+ png_memcpy(&(png_ptr->background), background_color, sizeof(png_color_16));
png_ptr->background_gamma = (float)background_gamma;
png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
+
+ /* Note: if need_expand is set and color_type is either RGB or RGB_ALPHA
+ * (in which case need_expand is superfluous anyway), the background color
+ * might actually be gray yet not be flagged as such. This is not a problem
+ * for the current code, which uses PNG_FLAG_BACKGROUND_IS_GRAY only to
+ * decide when to do the png_do_gray_to_rgb() transformation.
+ */
+ if ((need_expand && !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) ||
+ (!need_expand && background_color->red == background_color->green &&
+ background_color->red == background_color->blue))
+ png_ptr->flags |= PNG_FLAG_BACKGROUND_IS_GRAY;
}
#endif
@@ -447,9 +417,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
if (hash[i] != NULL)
{
- png_dsortp p;
-
- p = hash[i];
+ png_dsortp p = hash[i];
while (p)
{
png_dsortp t;
@@ -478,17 +446,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
if (full_dither)
{
int i;
- int total_bits, num_red, num_green, num_blue;
- png_size_t num_entries;
png_bytep distance;
-
- total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
+ int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
PNG_DITHER_BLUE_BITS;
-
- num_red = (1 << PNG_DITHER_RED_BITS);
- num_green = (1 << PNG_DITHER_GREEN_BITS);
- num_blue = (1 << PNG_DITHER_BLUE_BITS);
- num_entries = ((png_size_t)1 << total_bits);
+ int num_red = (1 << PNG_DITHER_RED_BITS);
+ int num_green = (1 << PNG_DITHER_GREEN_BITS);
+ int num_blue = (1 << PNG_DITHER_BLUE_BITS);
+ png_size_t num_entries = ((png_size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
(png_uint_32)(num_entries * sizeof (png_byte)));
@@ -502,34 +466,29 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (i = 0; i < num_palette; i++)
{
- int r, g, b, ir, ig, ib;
-
- r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
- g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
- b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
+ int ir, ig, ib;
+ int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
+ int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
+ int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
for (ir = 0; ir < num_red; ir++)
{
- int dr, index_r;
+ int dr = abs(ir - r);
+ int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
- dr = abs(ir - r);
- index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
for (ig = 0; ig < num_green; ig++)
{
- int dg, dt, dm, index_g;
+ int dg = abs(ig - g);
+ int dt = dr + dg;
+ int dm = ((dr > dg) ? dr : dg);
+ int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
- dg = abs(ig - g);
- dt = dr + dg;
- dm = ((dr > dg) ? dr : dg);
- index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
for (ib = 0; ib < num_blue; ib++)
{
- int d_index, db, dmax, d;
-
- d_index = index_g | ib;
- db = abs(ib - b);
- dmax = ((dm > db) ? dm : db);
- d = dmax + dt + db;
+ int d_index = index_g | ib;
+ int db = abs(ib - b);
+ int dmax = ((dm > db) ? dm : db);
+ int d = dmax + dt + db;
if (d < (int)distance[d_index])
{
@@ -617,15 +576,14 @@ png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
void
png_init_read_transformations(png_structp png_ptr)
{
- int color_type;
+ int color_type = png_ptr->color_type;
png_debug(1, "in png_init_read_transformations\n");
- color_type = png_ptr->color_type;
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
{
- if (color_type == PNG_COLOR_TYPE_GRAY)
+ if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
{
/* expand background chunk. */
switch (png_ptr->bit_depth)
@@ -694,12 +652,10 @@ png_init_read_transformations(png_structp png_ptr)
{
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
- int num_palette, i;
png_color back, back_1;
- png_colorp palette;
-
- palette = png_ptr->palette;
- num_palette = png_ptr->num_palette;
+ png_colorp palette = png_ptr->palette;
+ int num_palette = png_ptr->num_palette;
+ int i;
if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
{
@@ -796,11 +752,9 @@ png_init_read_transformations(png_structp png_ptr)
else
/* color_type != PNG_COLOR_TYPE_PALETTE */
{
- double g, gs, m;
-
- m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
- g = 1.0;
- gs = 1.0;
+ double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
+ double g = 1.0;
+ double gs = 1.0;
switch (png_ptr->background_gamma_type)
{
@@ -850,11 +804,9 @@ png_init_read_transformations(png_structp png_ptr)
#endif
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
- int num_palette, i;
- png_colorp palette;
-
- palette = png_ptr->palette;
- num_palette = png_ptr->num_palette;
+ png_colorp palette = png_ptr->palette;
+ int num_palette = png_ptr->num_palette;
+ int i;
for (i = 0; i < num_palette; i++)
{
@@ -873,16 +825,15 @@ png_init_read_transformations(png_structp png_ptr)
if (png_ptr->transformations & PNG_BACKGROUND &&
color_type == PNG_COLOR_TYPE_PALETTE)
{
- int i,istop;
+ int i;
+ int istop = (int)png_ptr->num_trans;
png_color back;
- png_colorp palette;
+ png_colorp palette = png_ptr->palette;
- palette = png_ptr->palette;
back.red = (png_byte)png_ptr->background.red;
back.green = (png_byte)png_ptr->background.green;
back.blue = (png_byte)png_ptr->background.blue;
- istop = (int)png_ptr->num_trans;
for (i = 0; i < istop; i++)
{
if (png_ptr->trans[i] == 0)
@@ -891,6 +842,7 @@ png_init_read_transformations(png_structp png_ptr)
}
else if (png_ptr->trans[i] != 0xff)
{
+ /* The png_composite() macro is defined in png.h */
png_composite(palette[i].red, palette[i].red,
png_ptr->trans[i], back.red);
png_composite(palette[i].green, palette[i].green,
@@ -906,19 +858,18 @@ png_init_read_transformations(png_structp png_ptr)
if ((png_ptr->transformations & PNG_SHIFT) &&
color_type == PNG_COLOR_TYPE_PALETTE)
{
- png_uint_16 i,istop;
- int sr, sg, sb;
+ png_uint_16 i;
+ png_uint_16 istop = png_ptr->num_palette;
+ int sr = 8 - png_ptr->sig_bit.red;
+ int sg = 8 - png_ptr->sig_bit.green;
+ int sb = 8 - png_ptr->sig_bit.blue;
- sr = 8 - png_ptr->sig_bit.red;
if (sr < 0 || sr > 8)
sr = 0;
- sg = 8 - png_ptr->sig_bit.green;
if (sg < 0 || sg > 8)
sg = 0;
- sb = 8 - png_ptr->sig_bit.blue;
if (sb < 0 || sb > 8)
sb = 0;
- istop = png_ptr->num_palette;
for (i = 0; i < istop; i++)
{
png_ptr->palette[i].red >>= sr;
@@ -1008,23 +959,19 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
#endif
+ if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
+ info_ptr->channels++;
+
#if defined(PNG_READ_FILLER_SUPPORTED)
- if (png_ptr->transformations & PNG_FILLER)
- {
- 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;
- }
+ /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */
+ if (png_ptr->transformations & PNG_FILLER &&
+ (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
+ info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
+ ++info_ptr->channels;
#endif
- if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
- info_ptr->channels++;
info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
info_ptr->bit_depth);
-
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
}
@@ -1077,6 +1024,44 @@ png_do_read_transformations(png_structp png_ptr)
PNG_FLAG_FILLER_AFTER);
#endif
+/*
+From Andreas Dilger e-mail to png-implement, 26 March 1998:
+
+ In most cases, the "simple transparency" should be done prior to doing
+ gray-to-RGB, or you will have to test 3x as many bytes to check if a
+ pixel is transparent. You would also need to make sure that the
+ transparency information is upgraded to RGB.
+
+ To summarize, the current flow is:
+ - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
+ with background "in place" if transparent,
+ convert to RGB if necessary
+ - Gray + alpha -> composite with gray background and remove alpha bytes,
+ convert to RGB if necessary
+
+ To support RGB backgrounds for gray images we need:
+ - Gray + simple transparency -> convert to RGB + simple transparency, compare
+ 3 or 6 bytes and composite with background
+ "in place" if transparent (3x compare/pixel
+ compared to doing composite with gray bkgrnd)
+ - Gray + alpha -> convert to RGB + alpha, composite with background and
+ remove alpha bytes (3x float operations/pixel
+ compared with composite on gray background)
+
+ Greg's change will do this. The reason it wasn't done before is for
+ performance, as this increases the per-pixel operations. If we would check
+ in advance if the background was gray or RGB, and position the gray-to-RGB
+ transform appropriately, then it would save a lot of work/time.
+ */
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+ /* if gray -> RGB, do so now only if background is non-gray; else do later
+ * for performance reasons */
+ if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
+ !(png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY))
+ png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
if ((png_ptr->transformations & PNG_BACKGROUND) &&
((png_ptr->num_trans != 0 ) ||
@@ -1146,7 +1131,9 @@ png_do_read_transformations(png_structp png_ptr)
#endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
- if (png_ptr->transformations & PNG_GRAY_TO_RGB)
+ /* if gray -> RGB, do so now only if we did not do so above */
+ if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
+ png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY)
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
@@ -1205,17 +1192,16 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth < 8)
#endif
{
- png_uint_32 shift, i;
+ png_uint_32 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_width - 1) >> 3);
- dp = row + (png_size_t)row_width - 1;
- shift = 7 - (int)((row_width + 7) & 7);
+ png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
+ png_bytep dp = row + (png_size_t)row_width - 1;
+ png_uint_32 shift = 7 - (int)((row_width + 7) & 7);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x1);
@@ -1234,9 +1220,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
case 2:
{
- 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);
+ png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
+ png_bytep dp = row + (png_size_t)row_width - 1;
+ png_uint_32 shift = (int)((3 - ((row_width + 3) & 3)) << 1);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x3);
@@ -1254,9 +1240,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
}
case 4:
{
- 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);
+ png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
+ png_bytep dp = row + (png_size_t)row_width - 1;
+ png_uint_32 shift = (int)((1 - ((row_width + 1) & 1)) << 2);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0xf);
@@ -1297,11 +1283,11 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{
int shift[4];
- int channels, c;
- png_uint_16 value;
+ int channels = 0;
+ int c;
+ png_uint_16 value = 0;
png_uint_32 row_width = row_info->width;
- channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
{
shift[channels++] = row_info->bit_depth - sig_bits->red;
@@ -1317,8 +1303,6 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
shift[channels++] = row_info->bit_depth - sig_bits->alpha;
}
- value = 0;
-
for (c = 0; c < channels; c++)
{
if (shift[c] <= 0)
@@ -1335,9 +1319,9 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 2:
{
png_bytep bp;
- png_uint_32 i,istop;
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
- istop = row_info->rowbytes;
for (bp = row, i = 0; i < istop; i++, bp++)
{
*bp >>= 1;
@@ -1348,12 +1332,11 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 4:
{
png_bytep bp;
- png_byte mask;
- png_uint_32 i,istop;
-
- mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+ png_byte mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
(png_byte)((int)0xf >> shift[0]);
- istop = row_info->rowbytes;
+
for (bp = row, i = 0; i < istop; i++, bp++)
{
*bp >>= shift[0];
@@ -1365,9 +1348,8 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
{
png_bytep bp;
png_uint_32 i;
- int cstop;
+ int cstop=(int)row_info->channels;
- cstop=(int)row_info->channels;
for (bp = row, i = 0; i < row_width; i++)
{
for (c = 0; c < cstop; c++, bp++)
@@ -1381,9 +1363,8 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
{
png_bytep bp;
png_size_t i;
- int cstop;
+ int cstop=(int)row_info->channels;
- cstop=(int)row_info->channels;
for (bp = row, i = 0; i < row_width; i++)
{
for (c = 0; c < cstop; c++, bp += 2)
@@ -1413,12 +1394,11 @@ png_do_chop(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 16)
#endif
{
- png_bytep sp, dp;
- png_uint_32 i, istop;
+ png_bytep sp = row;
+ png_bytep dp = row;
+ png_uint_32 i;
+ png_uint_32 istop = row_info->width * row_info->channels;
- sp = row;
- dp = row;
- 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)
@@ -1472,10 +1452,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from RGBA to ARGB */
if (row_info->bit_depth == 8)
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_byte save;
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
+
for (i = 0; i < row_width; i++)
{
save = *(--sp);
@@ -1488,10 +1469,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from RRGGBBAA to AARRGGBB */
else
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_byte save[2];
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
+
for (i = 0; i < row_width; i++)
{
save[0] = *(--sp);
@@ -1512,10 +1494,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from GA to AG */
if (row_info->bit_depth == 8)
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_byte save;
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
+
for (i = 0; i < row_width; i++)
{
save = *(--sp);
@@ -1526,11 +1509,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from GGAA to AAGG */
else
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_byte save[2];
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
save[0] = *(--sp);
@@ -1561,10 +1544,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8)
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1576,10 +1559,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in RRGGBBAA */
else
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1598,10 +1581,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in GA */
if (row_info->bit_depth == 8)
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1611,10 +1594,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in GGAA */
else
{
- png_bytep sp, dp;
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
png_uint_32 i;
- sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1634,7 +1617,6 @@ void
png_do_read_filler(png_row_infop row_info, png_bytep row,
png_uint_32 filler, png_uint_32 flags)
{
- png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
@@ -1653,8 +1635,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from G to GX */
if (flags & PNG_FLAG_FILLER_AFTER)
{
- sp = row + (png_size_t)row_width;
- dp = sp + (png_size_t)row_width;
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = low_filler;
@@ -1667,8 +1649,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from G to XG */
else
{
- sp = row + (png_size_t)row_width;
- dp = sp + (png_size_t)row_width;
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1684,8 +1666,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* 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;
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = hi_filler;
@@ -1700,8 +1682,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from GG to XXGG */
else
{
- sp = row + (png_size_t)row_width;
- dp = sp + (png_size_t)row_width;
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1722,8 +1704,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* 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;
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = low_filler;
@@ -1738,8 +1720,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from RGB to XRGB */
else
{
- sp = row + (png_size_t)row_width * 3;
- dp = sp + (png_size_t)row_width;
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1757,8 +1739,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* 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;
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = hi_filler;
@@ -1777,8 +1759,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from RRGGBB to XXRRGGBB */
else
{
- sp = row + (png_size_t)row_width * 3;
- dp = sp + (png_size_t)row_width;
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1804,7 +1786,6 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
void
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{
- png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
@@ -1819,8 +1800,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{
if (row_info->bit_depth == 8)
{
- sp = row + (png_size_t)row_width - 1;
- dp = sp + (png_size_t)row_width * 2;
+ png_bytep sp = row + (png_size_t)row_width - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 2;
for (i = 0; i < row_width; i++)
{
*(dp--) = *sp;
@@ -1831,8 +1812,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
}
else
{
- sp = row + (png_size_t)row_width * 2 - 1;
- dp = sp + (png_size_t)row_width * 4;
+ png_bytep sp = row + (png_size_t)row_width * 2 - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 4;
for (i = 0; i < row_width; i++)
{
*(dp--) = *sp;
@@ -1850,8 +1831,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{
if (row_info->bit_depth == 8)
{
- sp = row + (png_size_t)row_width * 2 - 1;
- dp = sp + (png_size_t)row_width * 2;
+ png_bytep sp = row + (png_size_t)row_width * 2 - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 2;
for (i = 0; i < row_width; i++)
{
*(dp--) = *(sp--);
@@ -1863,8 +1844,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
}
else
{
- sp = row + (png_size_t)row_width * 4 - 1;
- dp = sp + (png_size_t)row_width * 4;
+ png_bytep sp = row + (png_size_t)row_width * 4 - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 4;
for (i = 0; i < row_width; i++)
{
*(dp--) = *(sp--);
@@ -2348,11 +2329,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++, sp += 6)
{
- png_uint_16 r, g, b;
-
- r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
- g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
- b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
+ png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
+ png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
+ png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
if (r == trans_values->red && g == trans_values->green &&
b == trans_values->blue)
{
@@ -2366,8 +2345,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else
{
- png_uint_16 v;
- v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
+ png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
@@ -2385,11 +2363,10 @@ png_do_background(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++, sp += 6)
{
- png_uint_16 r, g, b;
+ png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
+ png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
+ png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
- r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
- g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
- b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
if (r == trans_values->red && g == trans_values->green &&
b == trans_values->blue)
{
@@ -2417,9 +2394,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 2, dp++)
{
- png_uint_16 a;
+ png_uint_16 a = *(sp + 1);
- a = *(sp + 1);
if (a == 0xff)
{
*dp = gamma_table[*sp];
@@ -2446,9 +2422,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 2, dp++)
{
- png_byte a;
+ png_byte a = *(sp + 1);
- a = *(sp + 1);
if (a == 0xff)
{
*dp = *sp;
@@ -2474,9 +2449,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 2)
{
- png_uint_16 a;
+ png_uint_16 a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
- a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
if (a == (png_uint_16)0xffff)
{
png_uint_16 v;
@@ -2510,9 +2484,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 2)
{
- png_uint_16 a;
-
- a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
+ png_uint_16 a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
if (a == (png_uint_16)0xffff)
{
png_memcpy(dp, sp, 2);
@@ -2548,9 +2520,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 3)
{
- png_byte a;
+ png_byte a = *(sp + 3);
- a = *(sp + 3);
if (a == 0xff)
{
*dp = gamma_table[*sp];
@@ -2587,9 +2558,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 3)
{
- png_byte a;
+ png_byte a = *(sp + 3);
- a = *(sp + 3);
if (a == 0xff)
{
*dp = *sp;
@@ -2623,10 +2593,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 8, dp += 6)
{
- png_uint_16 a;
-
- a = (png_uint_16)(((png_uint_16)(*(sp + 6)) << 8) +
- (png_uint_16)(*(sp + 7)));
+ png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
+ << 8) + (png_uint_16)(*(sp + 7)));
if (a == (png_uint_16)0xffff)
{
png_uint_16 v;
@@ -2680,10 +2648,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 8, dp += 6)
{
- png_uint_16 a;
-
- a = (png_uint_16)(((png_uint_16)(*(sp + 6)) << 8) +
- (png_uint_16)(*(sp + 7)));
+ png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
+ << 8) + (png_uint_16)(*(sp + 7)));
if (a == (png_uint_16)0xffff)
{
png_memcpy(dp, sp, 6);
@@ -2699,11 +2665,13 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else
{
- png_uint_16 r, g, b, v;
+ png_uint_16 v;
- r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
- g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
- b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
+ png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
+ png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8)
+ + *(sp + 3);
+ png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8)
+ + *(sp + 5);
png_composite_16(v, r, a, background->red);
*dp = (png_byte)((v >> 8) & 0xff);
@@ -2820,9 +2788,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++)
{
- png_uint_16 v;
-
- v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
sp += 2;
@@ -2854,9 +2820,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++)
{
- png_uint_16 v;
-
- v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
sp += 4;
@@ -2910,9 +2874,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++)
{
- png_uint_16 v;
-
- v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
sp += 2;
diff --git a/pngrutil.c b/pngrutil.c
index c9291d3e0..d4f0d740a 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,12 +1,12 @@
/* pngrutil.c - utilities to read a PNG file
*
- * libpng 1.0.1a
+ * 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*
* This file contains routines which are only called from within
* libpng itself during the course of reading an image.
@@ -20,9 +20,7 @@
png_uint_32
png_get_uint_32(png_bytep buf)
{
- png_uint_32 i;
-
- i = ((png_uint_32)(*buf) << 24) +
+ png_uint_32 i = ((png_uint_32)(*buf) << 24) +
((png_uint_32)(*(buf + 1)) << 16) +
((png_uint_32)(*(buf + 2)) << 8) +
(png_uint_32)(*(buf + 3));
@@ -37,9 +35,7 @@ png_get_uint_32(png_bytep buf)
png_int_32
png_get_int_32(png_bytep buf)
{
- png_int_32 i;
-
- i = ((png_int_32)(*buf) << 24) +
+ png_int_32 i = ((png_int_32)(*buf) << 24) +
((png_int_32)(*(buf + 1)) << 16) +
((png_int_32)(*(buf + 2)) << 8) +
(png_int_32)(*(buf + 3));
@@ -52,9 +48,7 @@ png_get_int_32(png_bytep buf)
png_uint_16
png_get_uint_16(png_bytep buf)
{
- png_uint_16 i;
-
- i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
+ png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
(png_uint_16)(*(buf + 1)));
return (i);
@@ -76,16 +70,16 @@ png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
int
png_crc_finish(png_structp png_ptr, png_uint_32 skip)
{
- png_uint_32 i,istop;
+ png_size_t i;
+ png_size_t istop = 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);
}
if (i)
{
- png_crc_read(png_ptr, png_ptr->zbuf, (png_size_t)i);
+ png_crc_read(png_ptr, png_ptr->zbuf, i);
}
if (png_crc_error(png_ptr))
@@ -1500,16 +1494,14 @@ png_combine_row(png_structp png_ptr, png_bytep row,
{
case 1:
{
- png_bytep sp;
- png_bytep dp;
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
int s_inc, s_start, s_end;
- int m;
+ int m = 0x80;
int shift;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
{
@@ -1527,8 +1519,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
shift = s_start;
- istop = png_ptr->width;
- for (i = 0; i < istop; i++)
+ for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1557,17 +1548,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
case 2:
{
- png_bytep sp;
- png_bytep dp;
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
int s_start, s_end, s_inc;
- int m;
+ int m = 0x80;
int shift;
- png_uint_32 i,istop;
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
int value;
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
{
@@ -1585,8 +1574,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
shift = s_start;
- istop = png_ptr->width;
- for (i = 0; i < istop; i++)
+ for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1612,17 +1600,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
case 4:
{
- png_bytep sp;
- png_bytep dp;
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
int s_start, s_end, s_inc;
- int m;
+ int m = 0x80;
int shift;
- png_uint_32 i,istop;
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
int value;
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
{
@@ -1639,8 +1625,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
shift = s_start;
- istop = png_ptr->width;
- for (i = 0; i < istop; i++)
+ for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1666,19 +1651,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
default:
{
- png_bytep sp;
- png_bytep dp;
- png_size_t pixel_bytes;
- png_uint_32 i, istop;
- png_byte m;
-
- pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
-
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
- istop = png_ptr->width;
- for (i = 0; i < istop; i++)
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
+ png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
+ png_byte m = 0x80;
+
+
+ for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1715,15 +1696,15 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{
case 1:
{
- png_bytep sp, dp;
+ png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
+ png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
int sshift, dshift;
int s_start, s_end, s_inc;
+ int jstop = png_pass_inc[pass];
png_byte v;
png_uint_32 i;
- int j, jstop;
+ int j;
- sp = row + (png_size_t)((row_info->width - 1) >> 3);
- dp = row + (png_size_t)((final_width - 1) >> 3);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
@@ -1743,7 +1724,6 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
s_inc = 1;
}
- jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--)
{
v = (png_byte)((*sp >> sshift) & 0x1);
@@ -1771,14 +1751,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
case 2:
{
- png_bytep sp, dp;
+ png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
+ png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
int sshift, dshift;
int s_start, s_end, s_inc;
+ int jstop = png_pass_inc[pass];
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);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
@@ -1798,7 +1777,6 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
s_inc = 2;
}
- jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--)
{
png_byte v;
@@ -1829,14 +1807,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
case 4:
{
- png_bytep sp, dp;
+ png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
+ png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
int sshift, dshift;
int s_start, s_end, s_inc;
png_uint_32 i;
- int jstop;
+ int jstop = png_pass_inc[pass];
- sp = row + (png_size_t)((row_info->width - 1) >> 1);
- dp = row + (png_size_t)((final_width - 1) >> 1);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
@@ -1856,13 +1833,11 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
s_inc = 4;
}
- jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--)
{
- png_byte v;
+ png_byte v = (png_byte)((*sp >> sshift) & 0xf);
int j;
- v = (png_byte)((*sp >> sshift) & 0xf);
for (j = 0; j < jstop; j++)
{
*dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
@@ -1887,16 +1862,12 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
default:
{
- png_bytep sp, dp;
+ png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
+ png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
+ png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
+ int jstop = png_pass_inc[pass];
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];
@@ -1935,95 +1906,87 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
break;
case PNG_FILTER_VALUE_SUB:
{
- png_uint_32 i, istop;
- int bpp;
- png_bytep rp;
- png_bytep lp;
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
+ png_bytep rp = row + bpp;
+ png_bytep lp = row;
- 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++)
+ for (i = bpp; i < istop; i++)
{
- *rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
+ *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;
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
- istop = row_info->rowbytes;
- for (i = 0, rp = row, pp = prev_row; i < istop; i++, rp++, pp++)
+ for (i = 0; i < istop; i++)
{
- *rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
+ *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;
+ png_uint_32 i;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
+ png_bytep lp = row;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
+ png_uint_32 istop = row_info->rowbytes;
- 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++)
+ for (i = 0; i < bpp; i++)
{
- *rp = (png_byte)(((int)(*rp) +
- ((int)(*pp) / 2)) & 0xff);
+ *rp++ = (png_byte)(((int)(*rp) +
+ ((int)(*pp++) / 2)) & 0xff);
}
- istop = row_info->rowbytes;
- for (lp = row; i < istop; i++, rp++,
- lp++, pp++)
+ for (lp = row; i < istop; i++)
{
- *rp = (png_byte)(((int)(*rp) +
- (int)(*pp + *lp) / 2) & 0xff);
+ *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++)
+ png_uint_32 i;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
+ png_bytep lp = row;
+ png_bytep cp = prev_row;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
+ png_uint_32 istop=row_info->rowbytes;
+
+ for (i = 0; i < bpp; i++)
{
- *rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
+ *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++)
+ for ( ; i < istop; i++) /* use leftover i,rp,pp */
{
int a, b, c, pa, pb, pc, p;
- a = *lp;
- b = *pp;
- c = *cp;
+ a = *lp++;
+ b = *pp++;
+ c = *cp++;
+
+ p = b - c;
+ pc = a - c;
- p = a + b - c;
#ifdef PNG_USE_ABS
- pa = abs(p - a);
- pb = abs(p - b);
- pc = abs(p - c);
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
#else
- pa = p > a ? p - a : a - p;
- pb = p > b ? p - b : b - p;
- pc = p > c ? p - c : c - p;
+ pa = p < 0 ? -p : p;
+ pb = pc < 0 ? -pc : pc;
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
/*
@@ -2037,40 +2000,8 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
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);
+ *rp++ = (png_byte)(((int)(*rp) + p) & 0xff);
}
-#endif /* PNG_SLOW_PAETH */
break;
}
default:
@@ -2094,11 +2025,10 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
case PNG_FILTER_VALUE_SUB:
{
png_uint_32 i;
- int bpp;
+ int bpp = (row_info->pixel_depth + 7) / 8;
png_bytep rp;
png_bytep lp;
- bpp = (row_info->pixel_depth + 7) / 8;
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
i < row_info->rowbytes; i++, rp++, lp++)
{
@@ -2122,12 +2052,11 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
case PNG_FILTER_VALUE_AVG:
{
png_uint_32 i;
- int bpp;
+ int bpp = (row_info->pixel_depth + 7) / 8;
png_bytep rp;
png_bytep pp;
png_bytep lp;
- bpp = (row_info->pixel_depth + 7) / 8;
for (i = 0, rp = row, pp = prev_row;
i < (png_uint_32)bpp; i++, rp++, pp++)
{
@@ -2143,14 +2072,13 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
}
case PNG_FILTER_VALUE_PAETH:
{
- int bpp;
+ int bpp = (row_info->pixel_depth + 7) / 8;
png_uint_32 i;
png_bytep rp;
png_bytep pp;
png_bytep lp;
png_bytep cp;
- bpp = (row_info->pixel_depth + 7) / 8;
for (i = 0, rp = row, pp = prev_row,
lp = row - bpp, cp = prev_row - bpp;
i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++)
diff --git a/pngset.c b/pngset.c
index da4d82b2a..9eb606ae8 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,12 +1,12 @@
/* pngset.c - storage of image information into info struct
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 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
diff --git a/pngtest.c b/pngtest.c
index 58e2b37b2..f267061fe 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,12 +1,12 @@
/* pngtest.c - a simple test program to test libpng
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 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
diff --git a/pngtrans.c b/pngtrans.c
index e8b9a1914..294088d37 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.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*/
#define PNG_INTERNAL
@@ -142,12 +142,13 @@ png_do_invert(png_row_infop row_info, png_bytep row)
#endif
row_info->color_type == PNG_COLOR_TYPE_GRAY)
{
- png_bytep rp;
+ png_bytep rp = row;
png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
- for (i = 0, rp = row; i < row_info->rowbytes; i++, rp++)
+ for (i = 0; i < istop; i++)
{
- *rp = (png_byte)(~(*rp));
+ *rp++ = (png_byte)(~(*rp));
}
}
}
@@ -165,12 +166,11 @@ png_do_swap(png_row_infop row_info, png_bytep row)
#endif
row_info->bit_depth == 16)
{
- png_bytep rp;
+ png_bytep rp = row;
png_uint_32 i;
+ png_uint_32 istop= row_info->width * row_info->channels;
- for (i = 0, rp = row;
- i < row_info->width * row_info->channels;
- i++, rp += 2)
+ for (i = 0; i < istop; i++, rp += 2)
{
png_byte t = *rp;
*rp = *(rp + 1);
@@ -333,7 +333,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
*/
png_bytep sp=row;
png_bytep dp=row;
- png_uint_32 width=row_info->width;
+ png_uint_32 row_width=row_info->width;
png_uint_32 i;
if (row_info->channels == 4)
@@ -344,7 +344,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
if (flags & PNG_FLAG_FILLER_AFTER)
{
dp+=3; sp+=4;
- for (i = 1; i < width; i++)
+ for (i = 1; i < row_width; i++)
{
*dp++ = *sp++;
*dp++ = *sp++;
@@ -355,7 +355,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
/* This converts from XRGB or ARGB to RGB */
else
{
- for (i = 0; i < width; i++)
+ for (i = 0; i < row_width; i++)
{
sp++;
*dp++ = *sp++;
@@ -364,7 +364,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
}
}
row_info->pixel_depth = 24;
- row_info->rowbytes = width * 3;
+ row_info->rowbytes = row_width * 3;
}
else /* if (row_info->bit_depth == 16) */
{
@@ -372,7 +372,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
{
/* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
sp += 8; dp += 6;
- for (i = 1; i < width; i++)
+ for (i = 1; i < row_width; i++)
{
/* This could be (although memcpy is probably slower):
png_memcpy(dp, sp, 6);
@@ -391,7 +391,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
else
{
/* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
- for (i = 0; i < width; i++)
+ for (i = 0; i < row_width; i++)
{
/* This could be (although memcpy is probably slower):
png_memcpy(dp, sp, 6);
@@ -408,7 +408,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
}
}
row_info->pixel_depth = 48;
- row_info->rowbytes = width * 6;
+ row_info->rowbytes = row_width * 6;
}
row_info->channels = 3;
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
@@ -424,7 +424,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
/* This converts from GX or GA to G */
if (flags & PNG_FLAG_FILLER_AFTER)
{
- for (i = 0; i < width; i++)
+ for (i = 0; i < row_width; i++)
{
*dp++ = *sp++;
sp++;
@@ -433,14 +433,14 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
/* This converts from XG or AG to G */
else
{
- for (i = 0; i < width; i++)
+ for (i = 0; i < row_width; i++)
{
sp++;
*dp++ = *sp++;
}
}
row_info->pixel_depth = 8;
- row_info->rowbytes = width;
+ row_info->rowbytes = row_width;
}
else /* if (row_info->bit_depth == 16) */
{
@@ -448,7 +448,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
{
/* This converts from GGXX or GGAA to GG */
sp += 4; dp += 2;
- for (i = 1; i < width; i++)
+ for (i = 1; i < row_width; i++)
{
*dp++ = *sp++;
*dp++ = *sp++;
@@ -458,7 +458,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
else
{
/* This converts from XXGG or AAGG to GG */
- for (i = 0; i < width; i++)
+ for (i = 0; i < row_width; i++)
{
sp += 2;
*dp++ = *sp++;
@@ -466,7 +466,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
}
}
row_info->pixel_depth = 16;
- row_info->rowbytes = width * 2;
+ row_info->rowbytes = row_width * 2;
}
row_info->channels = 1;
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
@@ -487,7 +487,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
#endif
(row_info->color_type & PNG_COLOR_MASK_COLOR))
{
- png_uint_32 width = row_info->width;
+ png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
@@ -495,7 +495,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
png_bytep rp;
png_uint_32 i;
- for (i = 0, rp = row; i < width; i++, rp += 3)
+ for (i = 0, rp = row; i < row_width; i++, rp += 3)
{
png_byte save = *rp;
*rp = *(rp + 2);
@@ -507,7 +507,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
png_bytep rp;
png_uint_32 i;
- for (i = 0, rp = row; i < width; i++, rp += 4)
+ for (i = 0, rp = row; i < row_width; i++, rp += 4)
{
png_byte save = *rp;
*rp = *(rp + 2);
@@ -522,7 +522,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
png_bytep rp;
png_uint_32 i;
- for (i = 0, rp = row; i < width; i++, rp += 6)
+ for (i = 0, rp = row; i < row_width; i++, rp += 6)
{
png_byte save = *rp;
*rp = *(rp + 4);
@@ -537,7 +537,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
png_bytep rp;
png_uint_32 i;
- for (i = 0, rp = row; i < width; i++, rp += 8)
+ for (i = 0, rp = row; i < row_width; i++, rp += 8)
{
png_byte save = *rp;
*rp = *(rp + 4);
diff --git a/pngwio.c b/pngwio.c
index 40d2a98ea..3a91041c5 100644
--- a/pngwio.c
+++ b/pngwio.c
@@ -1,12 +1,12 @@
/* pngwio.c - functions for data output
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 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 b3444dfa6..16975ed67 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,12 +1,12 @@
/* pngwrite.c - general routines to write a PNG file
*
- * libpng 1.0.1a
+ * libpng 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*/
/* get internal access to png.h */
@@ -422,6 +422,36 @@ png_write_row(png_structp png_ptr, png_bytep row)
/* initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{
+ /* check for transforms that have been set but were defined out */
+#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
+ if (png_ptr->transformations & PNG_INVERT_MONO)
+ png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
+#endif
+#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
+ if (png_ptr->transformations & PNG_FILLER)
+ png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
+#endif
+#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
+#endif
+#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACK)
+ png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
+#endif
+#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
+ if (png_ptr->transformations & PNG_SHIFT)
+ png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
+#endif
+#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
+ if (png_ptr->transformations & PNG_BGR)
+ png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
+#endif
+#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_SWAP_BYTES)
+ png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
+#endif
+
png_write_start_row(png_ptr);
}
diff --git a/pngwtran.c b/pngwtran.c
index 2fd4a7533..c6a420189 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.1a
+ * 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*/
#define PNG_INTERNAL
@@ -96,15 +96,15 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_bytep sp, dp;
int mask, v;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
mask = 0x80;
v = 0;
- istop = row_info->width;
- for (i = 0; i < istop; i++)
+ for (i = 0; i < row_width; i++)
{
if (*sp != 0)
v |= mask;
@@ -127,14 +127,14 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_bytep sp, dp;
int shift, v;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
shift = 6;
v = 0;
- istop = row_info->width;
- for (i = 0; i < istop; i++)
+ for (i = 0; i < row_width; i++)
{
png_byte value;
@@ -159,14 +159,14 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_bytep sp, dp;
int shift, v;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
shift = 4;
v = 0;
- istop = row_info->width;
- for (i = 0; i < istop; i++)
+ for (i = 0; i < row_width; i++)
{
png_byte value;
@@ -218,7 +218,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{
int shift_start[4], shift_dec[4];
- png_uint_32 channels;
+ int channels;
channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
@@ -249,9 +249,10 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
/* with low row depths, could only be grayscale, so one channel */
if (row_info->bit_depth < 8)
{
- png_bytep bp;
- png_uint_32 i, istop;
+ png_bytep bp = row;
+ png_uint_32 i;
png_byte mask;
+ png_uint_32 row_bytes = row_info->rowbytes;
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
mask = 0x55;
@@ -260,8 +261,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
else
mask = 0xff;
- istop = row_info->rowbytes;
- for (bp = row, i = 0; i < istop; i++, bp++)
+ for (i = 0; i < row_bytes; i++, bp++)
{
png_uint_16 v;
int j;
@@ -279,13 +279,13 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
}
else if (row_info->bit_depth == 8)
{
- png_bytep bp;
- png_uint_32 i, istop;
+ png_bytep bp = row;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (bp = row, i = 0; i < istop; i++)
+ for (i = 0; i < row_width; i++)
{
- png_uint_32 c;
+ int c;
for (c = 0; c < channels; c++, bp++)
{
@@ -307,12 +307,12 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
else
{
png_bytep bp;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (bp = row, i = 0; i < istop; i++)
+ for (bp = row, i = 0; i < row_width; i++)
{
- png_uint_32 c;
+ int c;
for (c = 0; c < channels; c++, bp += 2)
{
@@ -352,10 +352,9 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
- png_uint_32 i, istop;
-
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save = *(sp++);
*(dp++) = *(sp++);
@@ -368,10 +367,10 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
else
{
png_bytep sp, dp;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save[2];
save[0] = *(sp++);
@@ -394,9 +393,9 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{
png_bytep sp, dp;
png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save = *(sp++);
*(dp++) = *(sp++);
@@ -408,9 +407,9 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{
png_bytep sp, dp;
png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save[2];
save[0] = *(sp++);
@@ -441,10 +440,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
- png_uint_32 i, istop;
-
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
@@ -456,10 +454,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
else
{
png_bytep sp, dp;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
@@ -478,10 +476,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
@@ -491,10 +489,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
else
{
png_bytep sp, dp;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
- istop = row_info->width;
- for (i = 0, sp = dp = row; i < istop; i++)
+ for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
diff --git a/pngwutil.c b/pngwutil.c
index 8d56232e2..5355bfb2f 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,12 +1,12 @@
/* pngwutil.c - utilities to write a PNG file
*
- * libpng 1.0.1a
+ * 1.0.1b
* 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
- * April 21, 1998
+ * May 2, 1998
*/
#define PNG_INTERNAL
@@ -1251,13 +1251,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
int shift;
int d;
int value;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
dp = row;
d = 0;
shift = 7;
- istop = row_info->width;
- for (i = png_pass_start[pass]; i < istop;
+ for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 3);
@@ -1285,13 +1285,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
int shift;
int d;
int value;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
dp = row;
shift = 6;
d = 0;
- istop = row_info->width;
- for (i = png_pass_start[pass]; i < istop;
+ for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 2);
@@ -1318,13 +1318,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
int shift;
int d;
int value;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
dp = row;
shift = 4;
d = 0;
- istop = row_info->width;
- for (i = png_pass_start[pass]; i < istop;
+ for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 1);
@@ -1348,7 +1348,8 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
{
png_bytep sp;
png_bytep dp;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
png_size_t pixel_bytes;
/* start at the beginning */
@@ -1357,8 +1358,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
pixel_bytes = (row_info->pixel_depth >> 3);
/* loop through the row, only looking at the pixels that
matter */
- istop = row_info->width;
- for (i = png_pass_start[pass]; i < istop;
+ for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
/* find out where the original pixel is */
@@ -1397,6 +1397,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_bytep prev_row, best_row, row_buf;
png_uint_32 mins, bpp;
png_byte filter_to_do = png_ptr->do_filter;
+ png_uint_32 row_bytes = row_info->rowbytes;
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ int num_p_filters = (int)png_ptr->num_prev_filters;
+#endif
png_debug(1, "in png_write_find_filter\n");
/* find out how many bytes offset each pixel is */
@@ -1427,11 +1431,11 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp;
png_uint_32 sum = 0;
- png_uint_32 i,istop;
+ png_uint_32 i;
+ int j;
int v;
- istop = row_info->rowbytes;
- for (i = 0, rp = row_buf + 1; i < istop; i++, rp++)
+ for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
{
v = *rp;
sum += (v < 128) ? v : 256 - v;
@@ -1445,14 +1449,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
/* Reduce the sum if we match any of the previous rows */
- istop = (png_uint_32)png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_NONE)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
{
- sumlo = (sumlo * png_ptr->filter_weights[i]) >>
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- sumhi = (sumhi * png_ptr->filter_weights[i]) >>
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1480,14 +1483,14 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* it's the only filter so no testing is needed */
{
png_bytep rp, lp, dp;
- png_uint_32 i,istop;
+ png_uint_32 i;
+ int j;
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;
+ for (lp = row_buf + 1; i < row_bytes;
i++, rp++, lp++, dp++)
{
*dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
@@ -1499,7 +1502,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, lp;
png_uint_32 sum = 0, lmins = mins;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ int j;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1513,14 +1517,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
- istop = (png_uint_32)png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
{
- lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1562,14 +1565,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
- istop = (png_uint_32)png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
{
- sumlo = (sumlo * png_ptr->inv_filter_weights[i]) >>
+ sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- sumhi = (sumhi * png_ptr->inv_filter_weights[i]) >>
+ sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1597,11 +1599,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (filter_to_do == PNG_FILTER_UP)
{
png_bytep rp, dp, pp;
- png_uint_32 i, istop;
+ png_uint_32 i;
- istop = row_info->rowbytes;
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
- pp = prev_row + 1; i < istop;
+ pp = prev_row + 1; i < row_bytes;
i++, rp++, pp++, dp++)
{
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
@@ -1613,7 +1614,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp;
png_uint_32 sum = 0, lmins = mins;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ int j;
int v;
@@ -1624,14 +1626,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
- istop = (png_uint_32)png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
{
- lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1648,12 +1649,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
}
#endif
- 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++)
+ pp = prev_row + 1; i < row_bytes; i++)
{
- v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
+ v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
sum += (v < 128) ? v : 256 - v;
@@ -1668,14 +1667,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
- istop = (png_uint_32)png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
{
- sumlo = (sumlo * png_ptr->filter_weights[i]) >>
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- sumhi = (sumhi * png_ptr->filter_weights[i]) >>
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1703,16 +1701,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (filter_to_do == PNG_FILTER_AVG)
{
png_bytep rp, dp, pp, lp;
- png_uint_32 i,istop;
+ png_uint_32 i;
for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
- pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
+ pp = prev_row + 1; i < bpp; i++)
{
- *dp = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
+ *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++)
+ for (lp = row_buf + 1; i < row_bytes; i++)
{
- *dp = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
+ *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
+ & 0xff);
}
best_row = png_ptr->avg_row;
}
@@ -1721,7 +1719,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, lp;
png_uint_32 sum = 0, lmins = mins;
- png_uint_32 i,istop;
+ png_uint_32 i;
+ int j;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1731,14 +1730,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
- istop = (png_uint_32)png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_AVG)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
{
- lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1756,16 +1754,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
- pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
+ pp = prev_row + 1; i < bpp; i++)
{
- v = *dp = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
+ v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
sum += (v < 128) ? v : 256 - v;
}
- istop = row_info->rowbytes;
- for (lp = row_buf + 1; i < istop; i++, rp++, pp++, lp++, dp++)
+ for (lp = row_buf + 1; i < row_bytes; i++)
{
- v = *dp = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
+ v = *dp++ =
+ (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
sum += (v < 128) ? v : 256 - v;
@@ -1780,14 +1778,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
- istop = png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_NONE)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
{
- sumlo = (sumlo * png_ptr->filter_weights[i]) >>
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- sumhi = (sumhi * png_ptr->filter_weights[i]) >>
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1815,38 +1812,37 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (filter_to_do == PNG_FILTER_PAETH)
{
png_bytep rp, dp, pp, cp, lp;
- png_uint_32 i, istop;
+ png_uint_32 i;
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
- pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
+ pp = prev_row + 1; i < bpp; i++)
{
- *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
+ *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++)
+ for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
{
int a, b, c, pa, pb, pc, p;
- b = *pp;
- c = *cp;
- a = *lp;
+ b = *pp++;
+ c = *cp++;
+ a = *lp++;
- p = a + b - c;
+ p = b - c;
+ pc = a - c;
#ifdef PNG_USE_ABS
- pa = abs(p - a);
- pb = abs(p - b);
- pc = abs(p - c);
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
#else
- pa = p > a ? p - a : a - p;
- pb = p > b ? p - b : b - p;
- pc = p > c ? p - c : c - p;
+ pa = p < 0 ? -p : p;
+ pb = pc < 0 ? -pc : pc;
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
- *dp = (png_byte)(((int)*rp - p) & 0xff);
+ *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
}
best_row = png_ptr->paeth_row;
}
@@ -1855,7 +1851,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, cp, lp;
png_uint_32 sum = 0, lmins = mins;
- png_uint_32 i, istop;
+ png_uint_32 i;
+ int j;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1865,14 +1862,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
- istop = png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_PAETH)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
{
- lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1890,38 +1886,36 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
- pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
+ pp = prev_row + 1; i < bpp; i++)
{
- v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
+ v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
sum += (v < 128) ? v : 256 - v;
}
- istop = row_info->rowbytes;
- for (lp = row_buf + 1, cp = prev_row + 1; i < istop;
- i++, rp++, pp++, lp++, dp++, cp++)
+ for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
{
int a, b, c, pa, pb, pc, p;
- b = *pp;
- c = *cp;
- a = *lp;
-
- p = a + b - c;
+ b = *pp++;
+ c = *cp++;
+ a = *lp++;
#ifndef PNG_SLOW_PAETH
+ p = b - c;
+ pc = a - c;
#ifdef PNG_USE_ABS
- pa = abs(p - a);
- pb = abs(p - b);
- pc = abs(p - c);
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
#else
- pa = p > a ? p - a : a - p;
- pb = p > b ? p - b : b - p;
- pc = p > c ? p - c : c - p;
+ pa = p < 0 ? -p : p;
+ pb = pc < 0 ? -pc : pc;
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
-
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
#else /* PNG_SLOW_PAETH */
+ p = a + b - c;
pa = abs(p - a);
pb = abs(p - b);
pc = abs(p - c);
@@ -1933,7 +1927,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
p = c;
#endif /* PNG_SLOW_PAETH */
- v = *dp = (png_byte)(((int)*rp - p) & 0xff);
+ v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
sum += (v < 128) ? v : 256 - v;
@@ -1948,14 +1942,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
- istop = png_ptr->num_prev_filters;
- for (i = 0; i < istop; i++)
+ for (j = 0; j < num_p_filters; j++)
{
- if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_PAETH)
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
{
- sumlo = (sumlo * png_ptr->filter_weights[i]) >>
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
- sumhi = (sumhi * png_ptr->filter_weights[i]) >>
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1986,14 +1979,12 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* Save the type of filter we picked this time for future calculations */
if (png_ptr->num_prev_filters > 0)
{
- int i, istop;
-
- istop = (int)png_ptr->num_prev_filters;
- for (i = 1; i < istop; i++)
+ int j;
+ for (j = 1; j < num_p_filters; j++)
{
- png_ptr->prev_filters[i] = png_ptr->prev_filters[i - 1];
+ png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
}
- png_ptr->prev_filters[i] = best_row[0];
+ png_ptr->prev_filters[j] = best_row[0];
}
#endif
}
diff --git a/scripts/makefile.lnx b/scripts/makefile.lnx
index 2cbf84f35..0ad1663e0 100644
--- a/scripts/makefile.lnx
+++ b/scripts/makefile.lnx
@@ -20,7 +20,7 @@ WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops \
- $(ALIGN) #$(WARNMORE) -g -DPNG_DEBUG=5
+ $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
RANLIB=ranlib
@@ -29,7 +29,7 @@ RANLIB=ranlib
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
-PNGMIN = 1.0.1a
+PNGMIN = 1.0.1b
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 9ed074336..2d4afc445 100644
--- a/scripts/makefile.s2x
+++ b/scripts/makefile.s2x
@@ -29,7 +29,7 @@ RANLIB=echo
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
-PNGMIN = 1.0.1a
+PNGMIN = 1.0.1b
PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h
diff --git a/scripts/makefile.sco b/scripts/makefile.sco
new file mode 100644
index 000000000..635451b99
--- /dev/null
+++ b/scripts/makefile.sco
@@ -0,0 +1,97 @@
+# makefile for SCO OSr5 ELF and Unixware 7 with Native cc
+# Contributed by Mike Hopkirk (hops@sco.com) modified from Makefile.lnx
+# force ELF build dynamic linking, SONAME setting in lib and RPATH in app
+# Copyright (C) 1996, 1997 Andreas Dilger
+# Copyright (C) 1998 Greg Roelofs
+# For conditions of distribution and use, see copyright notice in png.h
+
+CC=cc
+
+# Where the zlib library and include files are located
+#ZLIBLIB=/usr/local/lib
+#ZLIBINC=/usr/local/include
+ZLIBLIB=../zlib
+ZLIBINC=../zlib
+
+CFLAGS= -dy -belf -I$(ZLIBINC) -O3
+LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
+
+#RANLIB=ranlib
+RANLIB=echo
+
+# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
+# have to change it.
+PNGMAJ = 2
+PNGMIN = 1.0.1b
+PNGVER = $(PNGMAJ).$(PNGMIN)
+
+# where make install puts libpng.a, libpng.so*, and png.h
+prefix=/usr/local
+INCPATH=$(prefix)/include
+LIBPATH=$(prefix)/lib
+
+OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
+ pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
+ pngwtran.o pngmem.o pngerror.o pngpread.o
+
+OBJSDLL = $(OBJS:.o=.pic.o)
+
+.SUFFIXES: .c .o .pic.o
+
+.c.pic.o:
+ $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c
+
+all: libpng.a libpng.so pngtest
+
+libpng.a: $(OBJS)
+ ar rc $@ $(OBJS)
+ $(RANLIB) $@
+
+libpng.so: libpng.so.$(PNGMAJ)
+ ln -sf libpng.so.$(PNGMAJ) libpng.so
+
+libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
+ ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
+
+libpng.so.$(PNGVER): $(OBJSDLL)
+ $(CC) -G -Wl,-h,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
+ $(OBJSDLL)
+
+pngtest: pngtest.o libpng.so
+ LD_RUN_PATH=.:$(ZLIBLIB) $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
+
+test: pngtest
+ ./pngtest
+
+install: libpng.a libpng.so.$(PNGVER)
+ -@mkdir $(INCPATH) $(LIBPATH)
+ cp png.h pngconf.h $(INCPATH)
+ chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
+ cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
+ chmod 755 $(LIBPATH)/libpng.so.$(PNGVER)
+ -@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
+ (cd $(LIBPATH); ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
+ ln -sf libpng.so.$(PNGMAJ) libpng.so)
+
+clean:
+ /bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+png.o png.pic.o: png.h pngconf.h
+pngerror.o pngerror.pic.o: png.h pngconf.h
+pngrio.o pngrio.pic.o: png.h pngconf.h
+pngwio.o pngwio.pic.o: png.h pngconf.h
+pngmem.o pngmem.pic.o: png.h pngconf.h
+pngset.o pngset.pic.o: png.h pngconf.h
+pngget.o pngget.pic.o: png.h pngconf.h
+pngread.o pngread.pic.o: png.h pngconf.h
+pngrtran.o pngrtran.pic.o: png.h pngconf.h
+pngrutil.o pngrutil.pic.o: png.h pngconf.h
+pngtrans.o pngtrans.pic.o: png.h pngconf.h
+pngwrite.o pngwrite.pic.o: png.h pngconf.h
+pngwtran.o pngwtran.pic.o: png.h pngconf.h
+pngwutil.o pngwutil.pic.o: png.h pngconf.h
+pngpread.o pngpread.pic.o: png.h pngconf.h
+
+pngtest.o: png.h pngconf.h
diff --git a/scripts/makefile.sgi b/scripts/makefile.sgi
index c2be939e4..ec7fd3091 100644
--- a/scripts/makefile.sgi
+++ b/scripts/makefile.sgi
@@ -11,7 +11,7 @@ ZLIBINC=../zlib
CC=cc
WARNMORE=-fullwarn
-CFLAGS=-I$(ZLIBINC) -O # $(WARNMORE) -g -DPNG_DEBUG=5
+CFLAGS=-I$(ZLIBINC) -O $(WARNMORE) # -g -DPNG_DEBUG=5
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
RANLIB=echo