Imported from libpng-1.0.1b.tar

This commit is contained in:
Glenn Randers-Pehrson 1998-05-02 12:52:25 -05:00
parent 896239be20
commit 1d96361273
29 changed files with 837 additions and 710 deletions

View File

@ -1,11 +1,12 @@
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 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. within a few weeks by a public version or by another test version.
Changes since the last release: Changes since the last public release:
libpng-1.0.1a:
Optimized Paeth calculations by replacing abs() function calls with intrinsics Optimized Paeth calculations by replacing abs() function calls with intrinsics
plus other loop optimizations. Improves avg decoding speed by about 20 percent. plus other loop optimizations. Improves avg decoding speed by about 20 percent.
Commented out i386istic "align" compiler flags in makefile.lnx. Commented out i386istic "align" compiler flags in makefile.lnx.
@ -19,6 +20,15 @@ Changes since the last release:
Moved a misplaced pngrutil code block that truncates tRNS if it has more 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. 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). 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 Send comments/corrections/commendations to
png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu

11
CHANGES
View File

@ -300,4 +300,13 @@ version 1.0.1a [April 21, 1998]
Moved a misplaced pngrutil code block that truncates tRNS if it has more 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. 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). 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.

View File

@ -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". The "ptime->date % 31" is wrong, should be "ptime->date % 32".
STATUS: Fixed in libpng-1.0.1a 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

View File

@ -1,4 +1,4 @@
.TH LIBPNG 3 "April 21, 1998" .TH LIBPNG 3 "May 2, 1998"
.SH NAME .SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library libpng \- Portable Network Graphics (PNG) Reference Library
.SH SYNOPSIS .SH SYNOPSIS
@ -396,7 +396,7 @@ Following is a copy of the libpng.txt file that accompanies libpng.
.SH LIBPNG.TXT .SH LIBPNG.TXT
libpng.txt - A description on how to use and modify libpng 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 Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu> <randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson 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. 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. Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (randeg@alumni.rpi.edu). Currently maintained by Glenn Randers-Pehrson (randeg@alumni.rpi.edu).

View File

@ -1,6 +1,6 @@
libpng.txt - A description on how to use and modify libpng 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 Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu> <randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson Copyright (c) 1998, Glenn Randers-Pehrson

View File

@ -1,4 +1,4 @@
.TH LIBPNGPF 3 "April 21, 1998" .TH LIBPNGPF 3 "May 2, 1998"
.SH NAME .SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library libpng \- Portable Network Graphics (PNG) Reference Library
(private functions) (private functions)

2
png.5
View File

@ -1,4 +1,4 @@
.TH PNG 5 "April 21, 1998" .TH PNG 5 "May 2, 1998"
.SH NAME .SH NAME
png \- Portable Network Graphics (PNG) format png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION .SH DESCRIPTION

6
png.c
View File

@ -1,12 +1,12 @@
/* png.c - location for general purpose libpng functions /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@ -16,7 +16,7 @@
/* Version information for C files. This had better match the version /* Version information for C files. This had better match the version
* string defined in png.h. * 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. */ /* Place to hold the signature string for a PNG file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};

61
png.h
View File

@ -1,12 +1,12 @@
/* png.h - header file for PNG reference library /* 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. * For conditions of distribution and use, see the COPYRIGHT NOTICE below.
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998 Glenn Randers-Pehrson * Copyright (c) 1998 Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* Note about libpng version numbers: * Note about libpng version numbers:
* *
@ -18,7 +18,7 @@
* *
* source png.h png.h shared-lib * source png.h png.h shared-lib
* version string int version * version string int version
* ------- ------ ------ ---------- * ------- ------ ----- ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89 * 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.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.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
@ -32,16 +32,17 @@
* 1.0.0 1.0.0 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.1 1.0.1 10001 2.1.0
* 1.0.1a 1.0.1a 10002 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 * Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be * and patch numbers; the shared-library major version number will be
* used for changes in backward compatibility, as it is intended. * used for changes in backward compatibility, as it is intended. The
* The PNG_PNGLIB_VER macro, which is not used within libpng but * PNG_PNGLIB_VER macro, which is not used within libpng but is available
* is available for applications, is an unsigned integer of the form * for applications, is an unsigned integer of the form xyyzz corresponding
* xyyzz corresponding to the source version x.y.z (leading zeros in y and z). * 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 * See libpng.txt or libpng.3 for more information. The PNG specification
* available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> * 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> * and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
* *
* Contributing Authors: * Contributing Authors:
@ -118,7 +119,7 @@ extern "C" {
*/ */
/* Version information for png.h - this should match the version in png.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. /* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros. * 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) #define png_debug2(l, m, p1, p2)
#endif /* (PNG_DEBUG > 0) */ #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 /* 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 * shouldn't be used unless you are writing code to add or replace some
* functionality in libpng. More information about most functions can * 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_FREE_HIST 0x4000
#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L #define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
#define PNG_FLAG_WROTE_tIME 0x10000L #define PNG_FLAG_WROTE_tIME 0x10000L
#define PNG_FLAG_BACKGROUND_IS_GRAY 0x20000L
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN) PNG_FLAG_CRC_ANCILLARY_NOWARN)

View File

@ -1,12 +1,12 @@
/* pngconf.h - machine configurable file for libpng /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * 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 /* Any machine specific code is near the front of this file, so if you

View File

@ -1,12 +1,12 @@
/* pngerror.c - stub functions for i/o and memory allocation /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* This file provides a location for all error handling. Users which * This file provides a location for all error handling. Users which
* need special error handling are expected to write replacement functions * need special error handling are expected to write replacement functions

View File

@ -1,12 +1,12 @@
/* pngget.c - retrieval of values from info struct /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL

View File

@ -1,12 +1,12 @@
/* pngmem.c - stub functions for memory allocation /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* This file provides a location for all memory allocation. Users who * This file provides a location for all memory allocation. Users who
* need special memory handling are expected to modify the code in this file * need special memory handling are expected to modify the code in this file

View File

@ -1,12 +1,12 @@
/* pngpread.c - read a png file in push mode /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL

View File

@ -1,12 +1,12 @@
/* pngread.c - read a PNG file /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* This file contains routines that an application calls directly to * This file contains routines that an application calls directly to
* read a PNG file or stream. * 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 */ /* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr); 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 defined(PNG_READ_INTERLACING_SUPPORTED)
/* if interlaced and we do not need a new row, combine row and return */ /* if interlaced and we do not need a new row, combine row and return */
@ -488,6 +520,15 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
/* save jump buffer and error functions */ /* save jump buffer and error functions */
rp = row; rp = row;
dp = display_row; dp = display_row;
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++) for (i = 0; i < num_rows; i++)
{ {
png_bytep rptr; png_bytep rptr;
@ -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 defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table != NULL) if (png_ptr->gamma_16_table != NULL)
{ {
int i,istop; int i;
istop = (1 << (8 - png_ptr->gamma_shift)); int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++) for (i = 0; i < istop; i++)
{ {
png_free(png_ptr, png_ptr->gamma_16_table[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); png_free(png_ptr, png_ptr->gamma_16_table);
if (png_ptr->gamma_16_from_1 != NULL) if (png_ptr->gamma_16_from_1 != NULL)
{ {
int i,istop; int i;
istop = (1 << (8 - png_ptr->gamma_shift)); int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++) for (i = 0; i < istop; i++)
{ {
png_free(png_ptr, png_ptr->gamma_16_from_1[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); png_free(png_ptr, png_ptr->gamma_16_from_1);
if (png_ptr->gamma_16_to_1 != NULL) if (png_ptr->gamma_16_to_1 != NULL)
{ {
int i,istop; int i;
istop = (1 << (8 - png_ptr->gamma_shift)); int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++) for (i = 0; i < istop; i++)
{ {
png_free(png_ptr, png_ptr->gamma_16_to_1[i]); png_free(png_ptr, png_ptr->gamma_16_to_1[i]);

View File

@ -1,12 +1,12 @@
/* pngrio.c - functions for data input /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* This file provides a location for all input. Users which need * This file provides a location for all input. Users which need
* special handling are expected to write a function which has the same * special handling are expected to write a function which has the same

View File

@ -1,12 +1,12 @@
/* pngrtran.c - transforms the data in a row for PNG readers /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* This file contains functions optionally called by an application * This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG. * in order to tell libpng how to handle data when reading a PNG.
@ -17,46 +17,6 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #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. */ /* Set the action on getting a CRC error for an ancillary or critical chunk. */
void void
png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) 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_ptr->transformations |= PNG_BACKGROUND;
png_memcpy(&(png_ptr->background), background_color, png_memcpy(&(png_ptr->background), background_color, sizeof(png_color_16));
sizeof(png_color_16));
png_ptr->background_gamma = (float)background_gamma; png_ptr->background_gamma = (float)background_gamma;
png_ptr->background_gamma_type = (png_byte)(background_gamma_code); png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0); 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 #endif
@ -447,9 +417,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{ {
if (hash[i] != NULL) if (hash[i] != NULL)
{ {
png_dsortp p; png_dsortp p = hash[i];
p = hash[i];
while (p) while (p)
{ {
png_dsortp t; png_dsortp t;
@ -478,17 +446,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
if (full_dither) if (full_dither)
{ {
int i; int i;
int total_bits, num_red, num_green, num_blue;
png_size_t num_entries;
png_bytep distance; png_bytep distance;
int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
PNG_DITHER_BLUE_BITS; PNG_DITHER_BLUE_BITS;
int num_red = (1 << PNG_DITHER_RED_BITS);
num_red = (1 << PNG_DITHER_RED_BITS); int num_green = (1 << PNG_DITHER_GREEN_BITS);
num_green = (1 << PNG_DITHER_GREEN_BITS); int num_blue = (1 << PNG_DITHER_BLUE_BITS);
num_blue = (1 << PNG_DITHER_BLUE_BITS); png_size_t num_entries = ((png_size_t)1 << total_bits);
num_entries = ((png_size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr, png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
(png_uint_32)(num_entries * sizeof (png_byte))); (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++) for (i = 0; i < num_palette; i++)
{ {
int r, g, b, ir, ig, ib; int ir, ig, ib;
int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS)); int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS)); int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
for (ir = 0; ir < num_red; ir++) 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++) 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++) for (ib = 0; ib < num_blue; ib++)
{ {
int d_index, db, dmax, d; int d_index = index_g | ib;
int db = abs(ib - b);
d_index = index_g | ib; int dmax = ((dm > db) ? dm : db);
db = abs(ib - b); int d = dmax + dt + db;
dmax = ((dm > db) ? dm : db);
d = dmax + dt + db;
if (d < (int)distance[d_index]) 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 void
png_init_read_transformations(png_structp png_ptr) 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"); 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 defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->transformations & PNG_BACKGROUND_EXPAND) 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. */ /* expand background chunk. */
switch (png_ptr->bit_depth) switch (png_ptr->bit_depth)
@ -694,12 +652,10 @@ png_init_read_transformations(png_structp png_ptr)
{ {
if (color_type == PNG_COLOR_TYPE_PALETTE) if (color_type == PNG_COLOR_TYPE_PALETTE)
{ {
int num_palette, i;
png_color back, back_1; png_color back, back_1;
png_colorp palette; png_colorp palette = png_ptr->palette;
int num_palette = png_ptr->num_palette;
palette = png_ptr->palette; int i;
num_palette = png_ptr->num_palette;
if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
{ {
@ -796,11 +752,9 @@ png_init_read_transformations(png_structp png_ptr)
else else
/* color_type != PNG_COLOR_TYPE_PALETTE */ /* color_type != PNG_COLOR_TYPE_PALETTE */
{ {
double g, gs, m; double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
double g = 1.0;
m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1); double gs = 1.0;
g = 1.0;
gs = 1.0;
switch (png_ptr->background_gamma_type) switch (png_ptr->background_gamma_type)
{ {
@ -850,11 +804,9 @@ png_init_read_transformations(png_structp png_ptr)
#endif #endif
if (color_type == PNG_COLOR_TYPE_PALETTE) if (color_type == PNG_COLOR_TYPE_PALETTE)
{ {
int num_palette, i; png_colorp palette = png_ptr->palette;
png_colorp palette; int num_palette = png_ptr->num_palette;
int i;
palette = png_ptr->palette;
num_palette = png_ptr->num_palette;
for (i = 0; i < num_palette; 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 && if (png_ptr->transformations & PNG_BACKGROUND &&
color_type == PNG_COLOR_TYPE_PALETTE) color_type == PNG_COLOR_TYPE_PALETTE)
{ {
int i,istop; int i;
int istop = (int)png_ptr->num_trans;
png_color back; 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.red = (png_byte)png_ptr->background.red;
back.green = (png_byte)png_ptr->background.green; back.green = (png_byte)png_ptr->background.green;
back.blue = (png_byte)png_ptr->background.blue; back.blue = (png_byte)png_ptr->background.blue;
istop = (int)png_ptr->num_trans;
for (i = 0; i < istop; i++) for (i = 0; i < istop; i++)
{ {
if (png_ptr->trans[i] == 0) 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) 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_composite(palette[i].red, palette[i].red,
png_ptr->trans[i], back.red); png_ptr->trans[i], back.red);
png_composite(palette[i].green, palette[i].green, 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) && if ((png_ptr->transformations & PNG_SHIFT) &&
color_type == PNG_COLOR_TYPE_PALETTE) color_type == PNG_COLOR_TYPE_PALETTE)
{ {
png_uint_16 i,istop; png_uint_16 i;
int sr, sg, sb; 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) if (sr < 0 || sr > 8)
sr = 0; sr = 0;
sg = 8 - png_ptr->sig_bit.green;
if (sg < 0 || sg > 8) if (sg < 0 || sg > 8)
sg = 0; sg = 0;
sb = 8 - png_ptr->sig_bit.blue;
if (sb < 0 || sb > 8) if (sb < 0 || sb > 8)
sb = 0; sb = 0;
istop = png_ptr->num_palette;
for (i = 0; i < istop; i++) for (i = 0; i < istop; i++)
{ {
png_ptr->palette[i].red >>= sr; 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; info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
#endif #endif
#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;
}
#endif
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
info_ptr->channels++; info_ptr->channels++;
#if defined(PNG_READ_FILLER_SUPPORTED)
/* 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
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
info_ptr->bit_depth); info_ptr->bit_depth);
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3); 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); PNG_FLAG_FILLER_AFTER);
#endif #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 defined(PNG_READ_BACKGROUND_SUPPORTED)
if ((png_ptr->transformations & PNG_BACKGROUND) && if ((png_ptr->transformations & PNG_BACKGROUND) &&
((png_ptr->num_trans != 0 ) || ((png_ptr->num_trans != 0 ) ||
@ -1146,7 +1131,9 @@ png_do_read_transformations(png_structp png_ptr)
#endif #endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) #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); png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
@ -1205,17 +1192,16 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth < 8) if (row_info->bit_depth < 8)
#endif #endif
{ {
png_uint_32 shift, i; png_uint_32 i;
png_uint_32 row_width=row_info->width; png_uint_32 row_width=row_info->width;
png_bytep sp, dp;
switch (row_info->bit_depth) switch (row_info->bit_depth)
{ {
case 1: case 1:
{ {
sp = row + (png_size_t)((row_width - 1) >> 3); png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
dp = row + (png_size_t)row_width - 1; png_bytep dp = row + (png_size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 7); png_uint_32 shift = 7 - (int)((row_width + 7) & 7);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*dp = (png_byte)((*sp >> shift) & 0x1); *dp = (png_byte)((*sp >> shift) & 0x1);
@ -1234,9 +1220,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
case 2: case 2:
{ {
sp = row + (png_size_t)((row_width - 1) >> 2); png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)row_width - 1; png_bytep dp = row + (png_size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 3)) << 1); png_uint_32 shift = (int)((3 - ((row_width + 3) & 3)) << 1);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*dp = (png_byte)((*sp >> shift) & 0x3); *dp = (png_byte)((*sp >> shift) & 0x3);
@ -1254,9 +1240,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
} }
case 4: case 4:
{ {
sp = row + (png_size_t)((row_width - 1) >> 1); png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
dp = row + (png_size_t)row_width - 1; png_bytep dp = row + (png_size_t)row_width - 1;
shift = (int)((1 - ((row_width + 1) & 1)) << 2); png_uint_32 shift = (int)((1 - ((row_width + 1) & 1)) << 2);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*dp = (png_byte)((*sp >> shift) & 0xf); *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) row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{ {
int shift[4]; int shift[4];
int channels, c; int channels = 0;
png_uint_16 value; int c;
png_uint_16 value = 0;
png_uint_32 row_width = row_info->width; png_uint_32 row_width = row_info->width;
channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR) if (row_info->color_type & PNG_COLOR_MASK_COLOR)
{ {
shift[channels++] = row_info->bit_depth - sig_bits->red; 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; shift[channels++] = row_info->bit_depth - sig_bits->alpha;
} }
value = 0;
for (c = 0; c < channels; c++) for (c = 0; c < channels; c++)
{ {
if (shift[c] <= 0) 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: case 2:
{ {
png_bytep bp; 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++) for (bp = row, i = 0; i < istop; i++, bp++)
{ {
*bp >>= 1; *bp >>= 1;
@ -1348,12 +1332,11 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 4: case 4:
{ {
png_bytep bp; png_bytep bp;
png_byte mask; png_uint_32 i;
png_uint_32 i,istop; png_uint_32 istop = row_info->rowbytes;
png_byte mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
(png_byte)((int)0xf >> shift[0]); (png_byte)((int)0xf >> shift[0]);
istop = row_info->rowbytes;
for (bp = row, i = 0; i < istop; i++, bp++) for (bp = row, i = 0; i < istop; i++, bp++)
{ {
*bp >>= shift[0]; *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_bytep bp;
png_uint_32 i; 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 (bp = row, i = 0; i < row_width; i++)
{ {
for (c = 0; c < cstop; c++, bp++) 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_bytep bp;
png_size_t i; 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 (bp = row, i = 0; i < row_width; i++)
{ {
for (c = 0; c < cstop; c++, bp += 2) 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) if (row_info->bit_depth == 16)
#endif #endif
{ {
png_bytep sp, dp; png_bytep sp = row;
png_uint_32 i, istop; 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++) for (i = 0; i<istop; i++, sp += 2, dp++)
{ {
#if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED) #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 */ /* This converts from RGBA to ARGB */
if (row_info->bit_depth == 8) 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_byte save;
png_uint_32 i; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save = *(--sp); 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 */ /* This converts from RRGGBBAA to AARRGGBB */
else else
{ {
png_bytep sp, dp; png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_byte save[2]; png_byte save[2];
png_uint_32 i; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save[0] = *(--sp); 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 */ /* This converts from GA to AG */
if (row_info->bit_depth == 8) 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_byte save;
png_uint_32 i; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save = *(--sp); 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 */ /* This converts from GGAA to AAGG */
else else
{ {
png_bytep sp, dp; png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_byte save[2]; png_byte save[2];
png_uint_32 i; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save[0] = *(--sp); 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 */ /* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8) 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; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = 255 - *(--sp); *(--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 */ /* This inverts the alpha channel in RRGGBBAA */
else else
{ {
png_bytep sp, dp; png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_uint_32 i; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = 255 - *(--sp); *(--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 */ /* This inverts the alpha channel in GA */
if (row_info->bit_depth == 8) 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; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = 255 - *(--sp); *(--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 */ /* This inverts the alpha channel in GGAA */
else else
{ {
png_bytep sp, dp; png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_uint_32 i; png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = 255 - *(--sp); *(--dp) = 255 - *(--sp);
@ -1634,7 +1617,6 @@ void
png_do_read_filler(png_row_infop row_info, png_bytep row, png_do_read_filler(png_row_infop row_info, png_bytep row,
png_uint_32 filler, png_uint_32 flags) png_uint_32 filler, png_uint_32 flags)
{ {
png_bytep sp, dp;
png_uint_32 i; png_uint_32 i;
png_uint_32 row_width = row_info->width; 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 */ /* This changes the data from G to GX */
if (flags & PNG_FLAG_FILLER_AFTER) if (flags & PNG_FLAG_FILLER_AFTER)
{ {
sp = row + (png_size_t)row_width; png_bytep sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = low_filler; *(--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 */ /* This changes the data from G to XG */
else else
{ {
sp = row + (png_size_t)row_width; png_bytep sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--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 */ /* This changes the data from GG to GGXX */
if (flags & PNG_FLAG_FILLER_AFTER) if (flags & PNG_FLAG_FILLER_AFTER)
{ {
sp = row + (png_size_t)row_width; png_bytep sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = hi_filler; *(--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 */ /* This changes the data from GG to XXGG */
else else
{ {
sp = row + (png_size_t)row_width; png_bytep sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--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 */ /* This changes the data from RGB to RGBX */
if (flags & PNG_FLAG_FILLER_AFTER) if (flags & PNG_FLAG_FILLER_AFTER)
{ {
sp = row + (png_size_t)row_width * 3; png_bytep sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = low_filler; *(--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 */ /* This changes the data from RGB to XRGB */
else else
{ {
sp = row + (png_size_t)row_width * 3; png_bytep sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--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 */ /* This changes the data from RRGGBB to RRGGBBXX */
if (flags & PNG_FLAG_FILLER_AFTER) if (flags & PNG_FLAG_FILLER_AFTER)
{ {
sp = row + (png_size_t)row_width * 3; png_bytep sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = hi_filler; *(--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 */ /* This changes the data from RRGGBB to XXRRGGBB */
else else
{ {
sp = row + (png_size_t)row_width * 3; png_bytep sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width; png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--dp) = *(--sp);
@ -1804,7 +1786,6 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
void void
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{ {
png_bytep sp, dp;
png_uint_32 i; png_uint_32 i;
png_uint_32 row_width = row_info->width; 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) if (row_info->bit_depth == 8)
{ {
sp = row + (png_size_t)row_width - 1; png_bytep sp = row + (png_size_t)row_width - 1;
dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (png_size_t)row_width * 2;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *sp; *(dp--) = *sp;
@ -1831,8 +1812,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
} }
else else
{ {
sp = row + (png_size_t)row_width * 2 - 1; png_bytep sp = row + (png_size_t)row_width * 2 - 1;
dp = sp + (png_size_t)row_width * 4; png_bytep dp = sp + (png_size_t)row_width * 4;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *sp; *(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) if (row_info->bit_depth == 8)
{ {
sp = row + (png_size_t)row_width * 2 - 1; png_bytep sp = row + (png_size_t)row_width * 2 - 1;
dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (png_size_t)row_width * 2;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *(sp--); *(dp--) = *(sp--);
@ -1863,8 +1844,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
} }
else else
{ {
sp = row + (png_size_t)row_width * 4 - 1; png_bytep sp = row + (png_size_t)row_width * 4 - 1;
dp = sp + (png_size_t)row_width * 4; png_bytep dp = sp + (png_size_t)row_width * 4;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *(sp--); *(dp--) = *(sp--);
@ -2348,11 +2329,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
sp = row; sp = row;
for (i = 0; i < row_width; i++, sp += 6) 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);
r = ((png_uint_16)(*sp) << 8) + *(sp + 1); png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
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 && if (r == trans_values->red && g == trans_values->green &&
b == trans_values->blue) b == trans_values->blue)
{ {
@ -2366,8 +2345,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
} }
else else
{ {
png_uint_16 v; png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; 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; sp = row;
for (i = 0; i < row_width; i++, sp += 6) 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 && if (r == trans_values->red && g == trans_values->green &&
b == trans_values->blue) b == trans_values->blue)
{ {
@ -2417,9 +2394,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 2, dp++) 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) if (a == 0xff)
{ {
*dp = gamma_table[*sp]; *dp = gamma_table[*sp];
@ -2446,9 +2422,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 2, dp++) for (i = 0; i < row_width; i++, sp += 2, dp++)
{ {
png_byte a; png_byte a = *(sp + 1);
a = *(sp + 1);
if (a == 0xff) if (a == 0xff)
{ {
*dp = *sp; *dp = *sp;
@ -2474,9 +2449,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 2) 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) if (a == (png_uint_16)0xffff)
{ {
png_uint_16 v; png_uint_16 v;
@ -2510,9 +2484,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 2) 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) if (a == (png_uint_16)0xffff)
{ {
png_memcpy(dp, sp, 2); png_memcpy(dp, sp, 2);
@ -2548,9 +2520,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 3) 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) if (a == 0xff)
{ {
*dp = gamma_table[*sp]; *dp = gamma_table[*sp];
@ -2587,9 +2558,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 3) 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) if (a == 0xff)
{ {
*dp = *sp; *dp = *sp;
@ -2623,10 +2593,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 8, dp += 6) for (i = 0; i < row_width; i++, sp += 8, dp += 6)
{ {
png_uint_16 a; png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
<< 8) + (png_uint_16)(*(sp + 7)));
a = (png_uint_16)(((png_uint_16)(*(sp + 6)) << 8) +
(png_uint_16)(*(sp + 7)));
if (a == (png_uint_16)0xffff) if (a == (png_uint_16)0xffff)
{ {
png_uint_16 v; png_uint_16 v;
@ -2680,10 +2648,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row; dp = row;
for (i = 0; i < row_width; i++, sp += 8, dp += 6) for (i = 0; i < row_width; i++, sp += 8, dp += 6)
{ {
png_uint_16 a; png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
<< 8) + (png_uint_16)(*(sp + 7)));
a = (png_uint_16)(((png_uint_16)(*(sp + 6)) << 8) +
(png_uint_16)(*(sp + 7)));
if (a == (png_uint_16)0xffff) if (a == (png_uint_16)0xffff)
{ {
png_memcpy(dp, sp, 6); png_memcpy(dp, sp, 6);
@ -2699,11 +2665,13 @@ png_do_background(png_row_infop row_info, png_bytep row,
} }
else else
{ {
png_uint_16 r, g, b, v; png_uint_16 v;
r = ((png_uint_16)(*sp) << 8) + *(sp + 1); png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3); png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8)
b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5); + *(sp + 3);
png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8)
+ *(sp + 5);
png_composite_16(v, r, a, background->red); png_composite_16(v, r, a, background->red);
*dp = (png_byte)((v >> 8) & 0xff); *dp = (png_byte)((v >> 8) & 0xff);
@ -2820,9 +2788,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row; sp = row;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
png_uint_16 v; png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
sp += 2; sp += 2;
@ -2854,9 +2820,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row; sp = row;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
png_uint_16 v; png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
sp += 4; sp += 4;
@ -2910,9 +2874,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row; sp = row;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
png_uint_16 v; png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
sp += 2; sp += 2;

View File

@ -1,12 +1,12 @@
/* pngrutil.c - utilities to read a PNG file /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* This file contains routines which are only called from within * This file contains routines which are only called from within
* libpng itself during the course of reading an image. * libpng itself during the course of reading an image.
@ -20,9 +20,7 @@
png_uint_32 png_uint_32
png_get_uint_32(png_bytep buf) png_get_uint_32(png_bytep buf)
{ {
png_uint_32 i; png_uint_32 i = ((png_uint_32)(*buf) << 24) +
i = ((png_uint_32)(*buf) << 24) +
((png_uint_32)(*(buf + 1)) << 16) + ((png_uint_32)(*(buf + 1)) << 16) +
((png_uint_32)(*(buf + 2)) << 8) + ((png_uint_32)(*(buf + 2)) << 8) +
(png_uint_32)(*(buf + 3)); (png_uint_32)(*(buf + 3));
@ -37,9 +35,7 @@ png_get_uint_32(png_bytep buf)
png_int_32 png_int_32
png_get_int_32(png_bytep buf) png_get_int_32(png_bytep buf)
{ {
png_int_32 i; png_int_32 i = ((png_int_32)(*buf) << 24) +
i = ((png_int_32)(*buf) << 24) +
((png_int_32)(*(buf + 1)) << 16) + ((png_int_32)(*(buf + 1)) << 16) +
((png_int_32)(*(buf + 2)) << 8) + ((png_int_32)(*(buf + 2)) << 8) +
(png_int_32)(*(buf + 3)); (png_int_32)(*(buf + 3));
@ -52,9 +48,7 @@ png_get_int_32(png_bytep buf)
png_uint_16 png_uint_16
png_get_uint_16(png_bytep buf) png_get_uint_16(png_bytep buf)
{ {
png_uint_16 i; png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
(png_uint_16)(*(buf + 1))); (png_uint_16)(*(buf + 1)));
return (i); return (i);
@ -76,16 +70,16 @@ png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
int int
png_crc_finish(png_structp png_ptr, png_uint_32 skip) 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) for (i = skip; i > istop; i -= istop)
{ {
png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
} }
if (i) 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)) if (png_crc_error(png_ptr))
@ -1500,16 +1494,14 @@ png_combine_row(png_structp png_ptr, png_bytep row,
{ {
case 1: case 1:
{ {
png_bytep sp; png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp; png_bytep dp = row;
int s_inc, s_start, s_end; int s_inc, s_start, s_end;
int m; int m = 0x80;
int shift; 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 defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP) if (png_ptr->transformations & PNG_PACKSWAP)
{ {
@ -1527,8 +1519,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
shift = s_start; shift = s_start;
istop = png_ptr->width; for (i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{ {
if (m & mask) if (m & mask)
{ {
@ -1557,17 +1548,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
} }
case 2: case 2:
{ {
png_bytep sp; png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp; png_bytep dp = row;
int s_start, s_end, s_inc; int s_start, s_end, s_inc;
int m; int m = 0x80;
int shift; int shift;
png_uint_32 i,istop; png_uint_32 i;
png_uint_32 row_width = png_ptr->width;
int value; int value;
sp = png_ptr->row_buf + 1;
dp = row;
m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP) if (png_ptr->transformations & PNG_PACKSWAP)
{ {
@ -1585,8 +1574,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
shift = s_start; shift = s_start;
istop = png_ptr->width; for (i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{ {
if (m & mask) if (m & mask)
{ {
@ -1612,17 +1600,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
} }
case 4: case 4:
{ {
png_bytep sp; png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp; png_bytep dp = row;
int s_start, s_end, s_inc; int s_start, s_end, s_inc;
int m; int m = 0x80;
int shift; int shift;
png_uint_32 i,istop; png_uint_32 i;
png_uint_32 row_width = png_ptr->width;
int value; int value;
sp = png_ptr->row_buf + 1;
dp = row;
m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED) #if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP) if (png_ptr->transformations & PNG_PACKSWAP)
{ {
@ -1639,8 +1625,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
} }
shift = s_start; shift = s_start;
istop = png_ptr->width; for (i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{ {
if (m & mask) if (m & mask)
{ {
@ -1666,19 +1651,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
} }
default: default:
{ {
png_bytep sp; png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp; png_bytep dp = row;
png_size_t pixel_bytes; png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
png_uint_32 i, istop; png_uint_32 i;
png_byte m; png_uint_32 row_width = png_ptr->width;
png_byte m = 0x80;
pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
sp = png_ptr->row_buf + 1; for (i = 0; i < row_width; i++)
dp = row;
m = 0x80;
istop = png_ptr->width;
for (i = 0; i < istop; i++)
{ {
if (m & mask) if (m & mask)
{ {
@ -1715,15 +1696,15 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{ {
case 1: 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 sshift, dshift;
int s_start, s_end, s_inc; int s_start, s_end, s_inc;
int jstop = png_pass_inc[pass];
png_byte v; png_byte v;
png_uint_32 i; 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 defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP) 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; s_inc = 1;
} }
jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--) for (i = row_info->width; i; i--)
{ {
v = (png_byte)((*sp >> sshift) & 0x1); 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: 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 sshift, dshift;
int s_start, s_end, s_inc; int s_start, s_end, s_inc;
int jstop = png_pass_inc[pass];
png_uint_32 i; 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 defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP) 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; s_inc = 2;
} }
jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--) for (i = row_info->width; i; i--)
{ {
png_byte v; png_byte v;
@ -1829,14 +1807,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
} }
case 4: 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 sshift, dshift;
int s_start, s_end, s_inc; int s_start, s_end, s_inc;
png_uint_32 i; 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 defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP) 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; s_inc = 4;
} }
jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--) for (i = row_info->width; i; i--)
{ {
png_byte v; png_byte v = (png_byte)((*sp >> sshift) & 0xf);
int j; int j;
v = (png_byte)((*sp >> sshift) & 0xf);
for (j = 0; j < jstop; j++) for (j = 0; j < jstop; j++)
{ {
*dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff); *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: 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; 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--) for (i = row_info->width; i; i--)
{ {
png_byte v[8]; 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; break;
case PNG_FILTER_VALUE_SUB: case PNG_FILTER_VALUE_SUB:
{ {
png_uint_32 i, istop; png_uint_32 i;
int bpp; png_uint_32 istop = row_info->rowbytes;
png_bytep rp; png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
png_bytep lp; png_bytep rp = row + bpp;
png_bytep lp = row;
bpp = (row_info->pixel_depth + 7) / 8; for (i = bpp; i < istop; i++)
istop = row_info->rowbytes;
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
i < istop; i++, rp++, lp++)
{ {
*rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff); *rp++ = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
} }
break; break;
} }
case PNG_FILTER_VALUE_UP: case PNG_FILTER_VALUE_UP:
{ {
png_uint_32 i, istop; png_uint_32 i;
png_bytep rp; png_uint_32 istop = row_info->rowbytes;
png_bytep pp; png_bytep rp = row;
png_bytep pp = prev_row;
istop = row_info->rowbytes; for (i = 0; i < istop; i++)
for (i = 0, rp = row, pp = prev_row; i < istop; i++, rp++, pp++)
{ {
*rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff); *rp++ = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
} }
break; break;
} }
case PNG_FILTER_VALUE_AVG: case PNG_FILTER_VALUE_AVG:
{ {
png_uint_32 i, istop; png_uint_32 i;
int bpp; png_bytep rp = row;
png_bytep rp; png_bytep pp = prev_row;
png_bytep pp; png_bytep lp = row;
png_bytep lp; png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
png_uint_32 istop = row_info->rowbytes;
bpp = (row_info->pixel_depth + 7) / 8; for (i = 0; i < bpp; i++)
istop = (png_uint_32)bpp;
for (i = 0, rp = row, pp = prev_row; i < istop; i++, rp++, pp++)
{ {
*rp = (png_byte)(((int)(*rp) + *rp++ = (png_byte)(((int)(*rp) +
((int)(*pp) / 2)) & 0xff); ((int)(*pp++) / 2)) & 0xff);
} }
istop = row_info->rowbytes; for (lp = row; i < istop; i++)
for (lp = row; i < istop; i++, rp++,
lp++, pp++)
{ {
*rp = (png_byte)(((int)(*rp) + *rp++ = (png_byte)(((int)(*rp) +
(int)(*pp + *lp) / 2) & 0xff); (int)(*pp++ + *lp++) / 2) & 0xff);
} }
break; break;
} }
case PNG_FILTER_VALUE_PAETH: case PNG_FILTER_VALUE_PAETH:
{ {
int bpp; png_uint_32 i;
png_uint_32 i, istop; png_bytep rp = row;
png_bytep rp; png_bytep pp = prev_row;
png_bytep pp; png_bytep lp = row;
png_bytep lp; png_bytep cp = prev_row;
png_bytep cp; png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
png_uint_32 istop=row_info->rowbytes;
bpp = (row_info->pixel_depth + 7) / 8; for (i = 0; i < bpp; i++)
#ifndef PNG_SLOW_PAETH
istop=bpp;
for (i = 0, rp = row, pp = prev_row; i < istop;
i++, rp++, pp++)
{ {
*rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff); *rp++ = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
} }
istop=row_info->rowbytes; for ( ; i < istop; i++) /* use leftover i,rp,pp */
for (lp = row, cp = prev_row; i < istop; /* use leftover i,rp,pp */
i++, rp++, pp++, lp++, cp++)
{ {
int a, b, c, pa, pb, pc, p; int a, b, c, pa, pb, pc, p;
a = *lp; a = *lp++;
b = *pp; b = *pp++;
c = *cp; c = *cp++;
p = b - c;
pc = a - c;
p = a + b - c;
#ifdef PNG_USE_ABS #ifdef PNG_USE_ABS
pa = abs(p - a); pa = abs(p);
pb = abs(p - b); pb = abs(pc);
pc = abs(p - c); pc = abs(p + pc);
#else #else
pa = p > a ? p - a : a - p; pa = p < 0 ? -p : p;
pb = p > b ? p - b : b - p; pb = pc < 0 ? -pc : pc;
pc = p > c ? p - c : c - p; pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif #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; p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
*rp = (png_byte)(((int)(*rp) + p) & 0xff); *rp++ = (png_byte)(((int)(*rp) + p) & 0xff);
} }
#else /* PNG_SLOW_PAETH */
for (i = 0, rp = row, pp = prev_row,
lp = row - bpp, cp = prev_row - bpp,
istop = row_info->rowbytes; i < istop; i++, rp++, pp++, lp++, cp++)
{
int a, b, c, pa, pb, pc, p;
b = *pp;
if (i >= (png_uint_32)bpp)
{
c = *cp;
a = *lp;
}
else
{
a = c = 0;
}
p = a + b - c;
pa = abs(p - a);
pb = abs(p - b);
pc = abs(p - c);
if (pa <= pb && pa <= pc)
p = a;
else if (pb <= pc)
p = b;
else
p = c;
*rp = (png_byte)(((int)(*rp) + p) & 0xff);
}
#endif /* PNG_SLOW_PAETH */
break; break;
} }
default: 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: case PNG_FILTER_VALUE_SUB:
{ {
png_uint_32 i; png_uint_32 i;
int bpp; int bpp = (row_info->pixel_depth + 7) / 8;
png_bytep rp; png_bytep rp;
png_bytep lp; png_bytep lp;
bpp = (row_info->pixel_depth + 7) / 8;
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row; for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
i < row_info->rowbytes; i++, rp++, lp++) 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: case PNG_FILTER_VALUE_AVG:
{ {
png_uint_32 i; png_uint_32 i;
int bpp; int bpp = (row_info->pixel_depth + 7) / 8;
png_bytep rp; png_bytep rp;
png_bytep pp; png_bytep pp;
png_bytep lp; png_bytep lp;
bpp = (row_info->pixel_depth + 7) / 8;
for (i = 0, rp = row, pp = prev_row; for (i = 0, rp = row, pp = prev_row;
i < (png_uint_32)bpp; i++, rp++, pp++) 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: case PNG_FILTER_VALUE_PAETH:
{ {
int bpp; int bpp = (row_info->pixel_depth + 7) / 8;
png_uint_32 i; png_uint_32 i;
png_bytep rp; png_bytep rp;
png_bytep pp; png_bytep pp;
png_bytep lp; png_bytep lp;
png_bytep cp; png_bytep cp;
bpp = (row_info->pixel_depth + 7) / 8;
for (i = 0, rp = row, pp = prev_row, for (i = 0, rp = row, pp = prev_row,
lp = row - bpp, cp = prev_row - bpp; lp = row - bpp, cp = prev_row - bpp;
i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++) i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++)

View File

@ -1,12 +1,12 @@
/* pngset.c - storage of image information into info struct /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * 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 * The functions here are used during reads to store data from the file
* into the info struct, and during writes to store application data * into the info struct, and during writes to store application data

View File

@ -1,12 +1,12 @@
/* pngtest.c - a simple test program to test libpng /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * 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 * 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 * compares the two files. If the files are identical, this shows that

View File

@ -1,12 +1,12 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers) /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@ -142,12 +142,13 @@ png_do_invert(png_row_infop row_info, png_bytep row)
#endif #endif
row_info->color_type == PNG_COLOR_TYPE_GRAY) row_info->color_type == PNG_COLOR_TYPE_GRAY)
{ {
png_bytep rp; png_bytep rp = row;
png_uint_32 i; 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 #endif
row_info->bit_depth == 16) row_info->bit_depth == 16)
{ {
png_bytep rp; png_bytep rp = row;
png_uint_32 i; png_uint_32 i;
png_uint_32 istop= row_info->width * row_info->channels;
for (i = 0, rp = row; for (i = 0; i < istop; i++, rp += 2)
i < row_info->width * row_info->channels;
i++, rp += 2)
{ {
png_byte t = *rp; png_byte t = *rp;
*rp = *(rp + 1); *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 sp=row;
png_bytep dp=row; png_bytep dp=row;
png_uint_32 width=row_info->width; png_uint_32 row_width=row_info->width;
png_uint_32 i; png_uint_32 i;
if (row_info->channels == 4) 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) if (flags & PNG_FLAG_FILLER_AFTER)
{ {
dp+=3; sp+=4; dp+=3; sp+=4;
for (i = 1; i < width; i++) for (i = 1; i < row_width; i++)
{ {
*dp++ = *sp++; *dp++ = *sp++;
*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 */ /* This converts from XRGB or ARGB to RGB */
else else
{ {
for (i = 0; i < width; i++) for (i = 0; i < row_width; i++)
{ {
sp++; sp++;
*dp++ = *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->pixel_depth = 24;
row_info->rowbytes = width * 3; row_info->rowbytes = row_width * 3;
} }
else /* if (row_info->bit_depth == 16) */ 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 */ /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
sp += 8; dp += 6; 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): /* This could be (although memcpy is probably slower):
png_memcpy(dp, sp, 6); 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 else
{ {
/* This converts from XXRRGGBB or AARRGGBB to RRGGBB */ /* 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): /* This could be (although memcpy is probably slower):
png_memcpy(dp, sp, 6); 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->pixel_depth = 48;
row_info->rowbytes = width * 6; row_info->rowbytes = row_width * 6;
} }
row_info->channels = 3; row_info->channels = 3;
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; 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 */ /* This converts from GX or GA to G */
if (flags & PNG_FLAG_FILLER_AFTER) if (flags & PNG_FLAG_FILLER_AFTER)
{ {
for (i = 0; i < width; i++) for (i = 0; i < row_width; i++)
{ {
*dp++ = *sp++; *dp++ = *sp++;
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 */ /* This converts from XG or AG to G */
else else
{ {
for (i = 0; i < width; i++) for (i = 0; i < row_width; i++)
{ {
sp++; sp++;
*dp++ = *sp++; *dp++ = *sp++;
} }
} }
row_info->pixel_depth = 8; row_info->pixel_depth = 8;
row_info->rowbytes = width; row_info->rowbytes = row_width;
} }
else /* if (row_info->bit_depth == 16) */ 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 */ /* This converts from GGXX or GGAA to GG */
sp += 4; dp += 2; sp += 4; dp += 2;
for (i = 1; i < width; i++) for (i = 1; i < row_width; i++)
{ {
*dp++ = *sp++; *dp++ = *sp++;
*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 else
{ {
/* This converts from XXGG or AAGG to GG */ /* This converts from XXGG or AAGG to GG */
for (i = 0; i < width; i++) for (i = 0; i < row_width; i++)
{ {
sp += 2; sp += 2;
*dp++ = *sp++; *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->pixel_depth = 16;
row_info->rowbytes = width * 2; row_info->rowbytes = row_width * 2;
} }
row_info->channels = 1; row_info->channels = 1;
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
@ -487,7 +487,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
#endif #endif
(row_info->color_type & PNG_COLOR_MASK_COLOR)) (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->bit_depth == 8)
{ {
if (row_info->color_type == PNG_COLOR_TYPE_RGB) 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_bytep rp;
png_uint_32 i; 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; png_byte save = *rp;
*rp = *(rp + 2); *rp = *(rp + 2);
@ -507,7 +507,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
png_bytep rp; png_bytep rp;
png_uint_32 i; 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; png_byte save = *rp;
*rp = *(rp + 2); *rp = *(rp + 2);
@ -522,7 +522,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
png_bytep rp; png_bytep rp;
png_uint_32 i; 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; png_byte save = *rp;
*rp = *(rp + 4); *rp = *(rp + 4);
@ -537,7 +537,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
png_bytep rp; png_bytep rp;
png_uint_32 i; 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; png_byte save = *rp;
*rp = *(rp + 4); *rp = *(rp + 4);

View File

@ -1,12 +1,12 @@
/* pngwio.c - functions for data output /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
* *
* This file provides a location for all output. Users which need * This file provides a location for all output. Users which need
* special handling are expected to write functions which have the same * special handling are expected to write functions which have the same

View File

@ -1,12 +1,12 @@
/* pngwrite.c - general routines to write a PNG file /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
*/ */
/* get internal access to png.h */ /* 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 */ /* initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0) 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); png_write_start_row(png_ptr);
} }

View File

@ -1,12 +1,12 @@
/* pngwtran.c - transforms the data in a row for PNG writers /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
*/ */
#define PNG_INTERNAL #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; png_bytep sp, dp;
int mask, v; int mask, v;
png_uint_32 i, istop; png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row; sp = row;
dp = row; dp = row;
mask = 0x80; mask = 0x80;
v = 0; v = 0;
istop = row_info->width; for (i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{ {
if (*sp != 0) if (*sp != 0)
v |= mask; 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; png_bytep sp, dp;
int shift, v; int shift, v;
png_uint_32 i, istop; png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row; sp = row;
dp = row; dp = row;
shift = 6; shift = 6;
v = 0; v = 0;
istop = row_info->width; for (i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{ {
png_byte value; 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; png_bytep sp, dp;
int shift, v; int shift, v;
png_uint_32 i, istop; png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row; sp = row;
dp = row; dp = row;
shift = 4; shift = 4;
v = 0; v = 0;
istop = row_info->width; for (i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{ {
png_byte value; 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) row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{ {
int shift_start[4], shift_dec[4]; int shift_start[4], shift_dec[4];
png_uint_32 channels; int channels;
channels = 0; channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR) 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 */ /* with low row depths, could only be grayscale, so one channel */
if (row_info->bit_depth < 8) if (row_info->bit_depth < 8)
{ {
png_bytep bp; png_bytep bp = row;
png_uint_32 i, istop; png_uint_32 i;
png_byte mask; png_byte mask;
png_uint_32 row_bytes = row_info->rowbytes;
if (bit_depth->gray == 1 && row_info->bit_depth == 2) if (bit_depth->gray == 1 && row_info->bit_depth == 2)
mask = 0x55; mask = 0x55;
@ -260,8 +261,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
else else
mask = 0xff; mask = 0xff;
istop = row_info->rowbytes; for (i = 0; i < row_bytes; i++, bp++)
for (bp = row, i = 0; i < istop; i++, bp++)
{ {
png_uint_16 v; png_uint_16 v;
int j; 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) else if (row_info->bit_depth == 8)
{ {
png_bytep bp; png_bytep bp = row;
png_uint_32 i, istop; png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width; for (i = 0; i < row_width; i++)
for (bp = row, i = 0; i < istop; i++)
{ {
png_uint_32 c; int c;
for (c = 0; c < channels; c++, bp++) 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 else
{ {
png_bytep bp; 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 < row_width; i++)
for (bp = row, i = 0; i < istop; i++)
{ {
png_uint_32 c; int c;
for (c = 0; c < channels; c++, bp += 2) 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) if (row_info->bit_depth == 8)
{ {
png_bytep sp, dp; 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 < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
png_byte save = *(sp++); png_byte save = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
@ -368,10 +367,10 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
else else
{ {
png_bytep sp, dp; 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 < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
png_byte save[2]; png_byte save[2];
save[0] = *(sp++); 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_bytep sp, dp;
png_uint_32 i; png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width; for (i = 0, sp = dp = row; i < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
png_byte save = *(sp++); png_byte save = *(sp++);
*(dp++) = *(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_bytep sp, dp;
png_uint_32 i; png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width; for (i = 0, sp = dp = row; i < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
png_byte save[2]; png_byte save[2];
save[0] = *(sp++); 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) if (row_info->bit_depth == 8)
{ {
png_bytep sp, dp; 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 < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
@ -456,10 +454,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
else else
{ {
png_bytep sp, dp; 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 < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(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) if (row_info->bit_depth == 8)
{ {
png_bytep sp, dp; 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 < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = 255 - *(sp++); *(dp++) = 255 - *(sp++);
@ -491,10 +489,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
else else
{ {
png_bytep sp, dp; 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 < row_width; i++)
for (i = 0, sp = dp = row; i < istop; i++)
{ {
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);

View File

@ -1,12 +1,12 @@
/* pngwutil.c - utilities to write a PNG file /* 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 * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson * Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998 * May 2, 1998
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@ -1251,13 +1251,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
int shift; int shift;
int d; int d;
int value; int value;
png_uint_32 i, istop; png_uint_32 i;
png_uint_32 row_width = row_info->width;
dp = row; dp = row;
d = 0; d = 0;
shift = 7; shift = 7;
istop = row_info->width; for (i = png_pass_start[pass]; i < row_width;
for (i = png_pass_start[pass]; i < istop;
i += png_pass_inc[pass]) i += png_pass_inc[pass])
{ {
sp = row + (png_size_t)(i >> 3); 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 shift;
int d; int d;
int value; int value;
png_uint_32 i, istop; png_uint_32 i;
png_uint_32 row_width = row_info->width;
dp = row; dp = row;
shift = 6; shift = 6;
d = 0; d = 0;
istop = row_info->width; for (i = png_pass_start[pass]; i < row_width;
for (i = png_pass_start[pass]; i < istop;
i += png_pass_inc[pass]) i += png_pass_inc[pass])
{ {
sp = row + (png_size_t)(i >> 2); 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 shift;
int d; int d;
int value; int value;
png_uint_32 i, istop; png_uint_32 i;
png_uint_32 row_width = row_info->width;
dp = row; dp = row;
shift = 4; shift = 4;
d = 0; d = 0;
istop = row_info->width; for (i = png_pass_start[pass]; i < row_width;
for (i = png_pass_start[pass]; i < istop;
i += png_pass_inc[pass]) i += png_pass_inc[pass])
{ {
sp = row + (png_size_t)(i >> 1); 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 sp;
png_bytep dp; 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; png_size_t pixel_bytes;
/* start at the beginning */ /* 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); pixel_bytes = (row_info->pixel_depth >> 3);
/* loop through the row, only looking at the pixels that /* loop through the row, only looking at the pixels that
matter */ matter */
istop = row_info->width; for (i = png_pass_start[pass]; i < row_width;
for (i = png_pass_start[pass]; i < istop;
i += png_pass_inc[pass]) i += png_pass_inc[pass])
{ {
/* find out where the original pixel is */ /* 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_bytep prev_row, best_row, row_buf;
png_uint_32 mins, bpp; png_uint_32 mins, bpp;
png_byte filter_to_do = png_ptr->do_filter; 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"); png_debug(1, "in png_write_find_filter\n");
/* find out how many bytes offset each pixel is */ /* 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_bytep rp;
png_uint_32 sum = 0; png_uint_32 sum = 0;
png_uint_32 i,istop; png_uint_32 i;
int j;
int v; int v;
istop = row_info->rowbytes; for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
for (i = 0, rp = row_buf + 1; i < istop; i++, rp++)
{ {
v = *rp; v = *rp;
sum += (v < 128) ? v : 256 - v; 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 */ sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
/* Reduce the sum if we match any of the previous rows */ /* Reduce the sum if we match any of the previous rows */
istop = (png_uint_32)png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; 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 */ /* it's the only filter so no testing is needed */
{ {
png_bytep rp, lp, dp; 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; for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
i++, rp++, dp++) i++, rp++, dp++)
{ {
*dp = *rp; *dp = *rp;
} }
istop = row_info->rowbytes; for (lp = row_buf + 1; i < row_bytes;
for (lp = row_buf + 1; i < istop;
i++, rp++, lp++, dp++) i++, rp++, lp++, dp++)
{ {
*dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); *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_bytep rp, dp, lp;
png_uint_32 sum = 0, lmins = mins; png_uint_32 sum = 0, lmins = mins;
png_uint_32 i, istop; png_uint_32 i;
int j;
int v; int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #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; lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >> lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
@ -1562,14 +1565,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK; sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->inv_filter_weights[i]) >> sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; 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) if (filter_to_do == PNG_FILTER_UP)
{ {
png_bytep rp, dp, pp; 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, 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++) i++, rp++, pp++, dp++)
{ {
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); *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_bytep rp, dp, pp;
png_uint_32 sum = 0, lmins = mins; png_uint_32 sum = 0, lmins = mins;
png_uint_32 i, istop; png_uint_32 i;
int j;
int v; int v;
@ -1624,14 +1626,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK; lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >> lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
@ -1648,12 +1649,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
} }
#endif #endif
istop = row_info->rowbytes;
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, 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++)
i++, rp++, pp++, dp++)
{ {
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
sum += (v < 128) ? v : 256 - v; 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; sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; 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) if (filter_to_do == PNG_FILTER_AVG)
{ {
png_bytep rp, dp, pp, lp; 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, 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 < row_bytes; i++)
for (lp = row_buf + 1; i < istop; i++, rp++, pp++, lp++, dp++)
{ {
*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; 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_bytep rp, dp, pp, lp;
png_uint_32 sum = 0, lmins = mins; png_uint_32 sum = 0, lmins = mins;
png_uint_32 i,istop; png_uint_32 i;
int j;
int v; int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #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; lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >> lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
@ -1756,16 +1754,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif #endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, 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; sum += (v < 128) ? v : 256 - v;
} }
istop = row_info->rowbytes; for (lp = row_buf + 1; i < row_bytes; i++)
for (lp = row_buf + 1; i < istop; i++, rp++, pp++, lp++, dp++)
{ {
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; 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; sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; 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) if (filter_to_do == PNG_FILTER_PAETH)
{ {
png_bytep rp, dp, pp, cp, lp; 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, 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 < row_bytes; i++)
for (lp = row_buf + 1, cp = prev_row + 1; i < istop;
i++, rp++, pp++, lp++, dp++, cp++)
{ {
int a, b, c, pa, pb, pc, p; int a, b, c, pa, pb, pc, p;
b = *pp; b = *pp++;
c = *cp; c = *cp++;
a = *lp; a = *lp++;
p = a + b - c; p = b - c;
pc = a - c;
#ifdef PNG_USE_ABS #ifdef PNG_USE_ABS
pa = abs(p - a); pa = abs(p);
pb = abs(p - b); pb = abs(pc);
pc = abs(p - c); pc = abs(p + pc);
#else #else
pa = p > a ? p - a : a - p; pa = p < 0 ? -p : p;
pb = p > b ? p - b : b - p; pb = pc < 0 ? -pc : pc;
pc = p > c ? p - c : c - p; pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif #endif
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; 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; 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_bytep rp, dp, pp, cp, lp;
png_uint_32 sum = 0, lmins = mins; png_uint_32 sum = 0, lmins = mins;
png_uint_32 i, istop; png_uint_32 i;
int j;
int v; int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #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; lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >> lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
@ -1890,38 +1886,36 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif #endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, 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; sum += (v < 128) ? v : 256 - v;
} }
istop = row_info->rowbytes; for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
for (lp = row_buf + 1, cp = prev_row + 1; i < istop;
i++, rp++, pp++, lp++, dp++, cp++)
{ {
int a, b, c, pa, pb, pc, p; int a, b, c, pa, pb, pc, p;
b = *pp; b = *pp++;
c = *cp; c = *cp++;
a = *lp; a = *lp++;
p = a + b - c;
#ifndef PNG_SLOW_PAETH #ifndef PNG_SLOW_PAETH
p = b - c;
pc = a - c;
#ifdef PNG_USE_ABS #ifdef PNG_USE_ABS
pa = abs(p - a); pa = abs(p);
pb = abs(p - b); pb = abs(pc);
pc = abs(p - c); pc = abs(p + pc);
#else #else
pa = p > a ? p - a : a - p; pa = p < 0 ? -p : p;
pb = p > b ? p - b : b - p; pb = pc < 0 ? -pc : pc;
pc = p > c ? p - c : c - p; pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif #endif
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
#else /* PNG_SLOW_PAETH */ #else /* PNG_SLOW_PAETH */
p = a + b - c;
pa = abs(p - a); pa = abs(p - a);
pb = abs(p - b); pb = abs(p - b);
pc = abs(p - c); pc = abs(p - c);
@ -1933,7 +1927,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
p = c; p = c;
#endif /* PNG_SLOW_PAETH */ #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; 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; sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = png_ptr->num_prev_filters; for (j = 0; j < num_p_filters; j++)
for (i = 0; i < istop; i++)
{ {
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; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; 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 */ /* Save the type of filter we picked this time for future calculations */
if (png_ptr->num_prev_filters > 0) if (png_ptr->num_prev_filters > 0)
{ {
int i, istop; int j;
for (j = 1; j < num_p_filters; j++)
istop = (int)png_ptr->num_prev_filters;
for (i = 1; i < istop; i++)
{ {
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 #endif
} }

View File

@ -29,7 +29,7 @@ RANLIB=ranlib
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not # read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it. # have to change it.
PNGMAJ = 2 PNGMAJ = 2
PNGMIN = 1.0.1a PNGMIN = 1.0.1b
PNGVER = $(PNGMAJ).$(PNGMIN) PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h # where make install puts libpng.a, libpng.so*, and png.h

View File

@ -29,7 +29,7 @@ RANLIB=echo
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not # read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it. # have to change it.
PNGMAJ = 2 PNGMAJ = 2
PNGMIN = 1.0.1a PNGMIN = 1.0.1b
PNGVER = $(PNGMAJ).$(PNGMIN) PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h # where make install puts libpng.a, libpng.so*, and png.h

97
scripts/makefile.sco Normal file
View File

@ -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

View File

@ -11,7 +11,7 @@ ZLIBINC=../zlib
CC=cc CC=cc
WARNMORE=-fullwarn 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 LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
RANLIB=echo RANLIB=echo