Compare commits

...

2 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
d0dce40075 Imported from libpng-1.0.1c.tar 2009-04-06 16:04:25 -05:00
Glenn Randers-Pehrson
1d96361273 Imported from libpng-1.0.1b.tar 2009-04-06 16:04:25 -05:00
31 changed files with 1140 additions and 840 deletions

View File

@@ -1,24 +1,47 @@
Libpng 1.0.1a April 21, 1998
Libpng 1.0.1c May 9, 1998
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
Changes since the last release:
Changes since the last public release:
Optimized Paeth calculations by replacing abs() function calls with intrinsics
plus other loop optimizations. Improves avg decoding speed by about 20 percent.
Commented out i386istic "align" compiler flags in makefile.lnx.
Reduced the default warning level in some makefiles, to make them consistent.
Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
Added grayscale and 16-bit capability to png_do_read_filler().
Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
too large when writing an image with bit_depth < 8 (Bob Dellaca).
Corrected some bugs in the experimental weighted filtering heuristics.
Moved a misplaced pngrutil code block that truncates tRNS if it has more
than num_palette entries -- test was done before num_palette was defined.
Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
version 1.0.1a [April 21, 1998]
Optimized Paeth calculations by replacing abs() function calls with intrinsics
plus other loop optimizations. Improves avg decoding speed by about 20%.
Commented out i386istic "align" compiler flags in makefile.lnx.
Reduced the default warning level in some makefiles, to make them consistent.
Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
Added grayscale and 16-bit capability to png_do_read_filler().
Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
too large when writing an image with bit_depth < 8 (Bob Dellaca).
Corrected some bugs in the experimental weighted filtering heuristics.
Moved a misplaced pngrutil code block that truncates tRNS if it has more
than num_palette entries -- test was done before num_palette was defined.
Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen).
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.
Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran.
Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)
version 1.0.1c [May 9, 1998]
Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
filler bytes should have been 0xff instead of 0xf.
Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
Moved PNG_WRIGHT_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
for consistency, in pngconf.h
Added individual "ifndef PNG_NO_CAPABILITY" for the capabilities in pngconf.h
to make it easier to remove unwanted capabilities via the compile line
Send comments/corrections/commendations to
png-implement@dworkin.wustl.edu or to randeg@alumni.rpi.edu

23
CHANGES
View File

@@ -300,4 +300,25 @@ version 1.0.1a [April 21, 1998]
Moved a misplaced pngrutil code block that truncates tRNS if it has more
than num_palette entries -- test was done before num_palette was defined.
Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen)
Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen).
version 1.0.1b [May 2, 1998]
Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
Relocated the png_composite macros from pngrtran.c to png.h (Greg).
Added makefile.sco (contributed by Mike Hopkirk).
Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a.
Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
More work on the Paeth-filtering, achieving imperceptible speedup (A Kleinert).
More work on loop optimization which may help when compiled with C++ compilers.
Added warnings when people try to use transforms they've defined out.
Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran.
Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)
version 1.0.1c [May 9, 1998]
Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
filler bytes should have been 0xff instead of 0xf.
Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
Moved PNG_WRIGHT_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
for consistency, in pngconf.h
Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier
to remove unwanted capabilities via the compile line

View File

@@ -20,7 +20,8 @@ Known bugs and suggested enhancements in libpng-1.0.1
pngrtran.c: if-test for channels/FILLER may be incorrect
STATUS: Under investigation
STATUS: Under investigation. Appears to be working correctly
in libpng-1.0.1c.
4. March 15, 1998 -- BUG -- Kevin Bracey
@@ -52,11 +53,12 @@ Known bugs and suggested enhancements in libpng-1.0.1
png_uint_32 i;
for(i=0; i < s->a*s->b; i++)
with
png_uint_32 i, count;
png_uint_32 i, istop;
istop = s->a*s->b;
for(i=0; i<istop; i++)
STATUS: Mostly done in libpng-1.0.1a, done for all important loops.
More done in libpng-1.0.1b.
c. Replace abs() with intrinsic ternary operations in Paeth
filtering -- Glenn R-P
@@ -92,7 +94,7 @@ Known bugs and suggested enhancements in libpng-1.0.1
be made possible at run time, via calls to new png_set_malloc_fn()
and png_set_free_fn() functions.
STATUS: Will do in libpng-1.0.1b
STATUS: Under consideration
9. April 11, 1998 -- BUG -- incorrect truncation of tRNS data in
illegal PNG file where tRNS precedes PLTE -- Larry Reeve
@@ -111,3 +113,46 @@ Known bugs and suggested enhancements in libpng-1.0.1
The "ptime->date % 31" is wrong, should be "ptime->date % 32".
STATUS: Fixed in libpng-1.0.1a
11. April 21, 1998 -- ENHANCEMENT -- relocation of composite macros
png_composite() and png_composite_16() relocated to png.h
STATUS: Done in libpng-1.0.1b
12. April 22, 1998 -- ENHANCEMENT -- makefile.sco
Mike Hopkirk contributed a makefile for SCO osr5 and sco UW7
STATUS: Added to libpng-1.0.1b distribution
13: April 30, 1998 -- ENHANCEMENT -- warnings
When people define out some of the read transformations and then
try to use them, the request is silently ignored. It was suggested
that a warning be issued in such cases.
STATUS: Done in libpng-1.0.1b
14. May 2, 1998 -- BUG -- incorrect mask for filler bytes
In pngrtran.c, png_do_filler(), the masks for hi_filler and low_filler
should be 0xff instead of 0xf
STATUS: Fixed in libpng-1.0.1c
15. May 3, 1998 -- BUG -- buffer overflow in png_do_read_filler()
In pngrutil.c, max_pixel_depth needs to be set to 32 when using
png_do_read_filler with palette images.
STATUS: Fixed in libpng-1.0.1c (see also items 1 and 3 above).
16. May 3, 1998 -- BUG -- type definitions wrong on error functions -- Tom Lane
In png_create_xxx_struct(), the error functions should have typedef
png_voidp instead of (void *). Needs to be corrected in the functions,
the prototypes in png.h, the example.c file, and libpng.txt and libpng.3
STATUS: Fixed in libpng-1.0.1c

2
TODO
View File

@@ -1,7 +1,9 @@
TODO - list of things to do for libpng
fix problem with C++ and EXTERN "C"
add capability to set user malloc/free functions at run time
add "grayscale->palette" transformation and "palette->grayscale" detection
color to gray transformation
improved dithering
multi-lingual error and warning message support
sPLT chunk handling

View File

@@ -83,7 +83,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
* was compiled with a compatible version of the library. REQUIRED
*/
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
if (png_ptr == NULL)
{
@@ -362,7 +362,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
* linked libraries.
*/
*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
if (*png_ptr == NULL)
{
@@ -498,7 +498,7 @@ void write_png(char *file_name /* , ... other image information ... */)
* in case we are using dynamically linked libraries. REQUIRED.
*/
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
if (png_ptr == NULL)
{

View File

@@ -1,4 +1,4 @@
.TH LIBPNG 3 "April 21, 1998"
.TH LIBPNG 3 "May 9, 1998"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library
.SH SYNOPSIS
@@ -396,7 +396,7 @@ Following is a copy of the libpng.txt file that accompanies libpng.
.SH LIBPNG.TXT
libpng.txt - A description on how to use and modify libpng
libpng version 1.0.1a April 21, 1998
libpng version 1.0.1c May 9, 1998
Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson
@@ -539,7 +539,7 @@ be NULL if the default error handlers are to be used). See the section
on Changes to Libpng below regarding the old initialization functions.
png_structp png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return;
@@ -974,21 +974,19 @@ RGB. This code will do that conversion:
png_set_gray_to_rgb(png_ptr);
If you have a grayscale and you are using png_set_expand() to change to
a higher bit-depth you must indicate if the supplied background gray
is supplied in the original file bit depth (need_expand = 1) or in the
expanded bit depth (need_expand = 0). Similarly, if you are reading
a paletted image, you must indicate if you have supplied the background
as a palette index that needs to be expanded (need_expand = 1). You can
also specify an RGB triplet that isn't in the palette when setting your
background for a paletted image.
a higher bit-depth, you must either supply the background color as a gray
value at the original file bit-depth (need_expand = 1) or else supply the
background color as an RGB triplet at the final, expanded bit depth
(need_expand = 0). Similarly, if you are reading a paletted image, you
must either supply the background color as a palette index (need_expand = 1)
or as an RGB triplet that may or may not be in the palette (need_expand = 0).
png_color_16 my_background;
png_color_16p image_background;
if (png_get_bKGD(png_ptr, info_ptr,
&image_background))
png_set_background(png_ptr, image_background),
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
png_set_background(png_ptr, image_background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
@@ -1271,7 +1269,7 @@ png_infop info_ptr;
initialize_png_reader()
{
png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return -1;
@@ -1443,7 +1441,7 @@ both "png_ptr"; you can call them anything you like, such as
"read_ptr" and "write_ptr". Look at pngtest.c, for example.
png_structp png_ptr = png_create_write_struct
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return;
@@ -2223,19 +2221,23 @@ Removing unwanted object code:
There are a bunch of #define's in pngconf.h that control what parts of
libpng are compiled. All the defines end in _SUPPORTED. If you are
never going to use an ability, you can change the #define to #undef
before recompiling libpng and save yourself code and data space.
You can also turn a number of them off en masse with a compiler directive
that defines PNG_READ[or WRITE]_TRANSFORMS_NOT_SUPPORTED, or
PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED, or all four,
never going to use a capability, you can change the #define to #undef
before recompiling libpng and save yourself code and data space, or
you can turn off individual capabilities with defines that begin with
PNG_NO_.
You can also turn all of the transforms and ancillary chunk capabilities
off en masse with compiler directives that define
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
or all four,
along with directives to turn on any of the capabilities that you do
want. The PNG_READ[or WRITE]_TRANSFORMS_NOT_SUPPORTED directives disable
want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
the extra transformations but still leave the library fully capable of reading
and writing PNG files with all known public chunks [except for sPLT].
Use of the PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED directive
Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
produces a library that is incapable of reading or writing ancillary chunks.
If you are not using the progressive reading capability, you can
turn that off with PNG_PROGRESSIVE_READ_NOT_SUPPORTED (don't confuse
turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
this with the INTERLACING capability, which you'll still have).
All the reading and writing specific code are in separate files, so the
@@ -2372,7 +2374,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.0.1a April 21, 1998:
Libpng version 1.0.1c May 9, 1998:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
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 version 1.0.1a April 21, 1998
libpng version 1.0.1c May 9, 1998
Updated and distributed by Glenn Randers-Pehrson
<randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson
@@ -143,7 +143,7 @@ be NULL if the default error handlers are to be used). See the section
on Changes to Libpng below regarding the old initialization functions.
png_structp png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return;
@@ -578,21 +578,19 @@ RGB. This code will do that conversion:
png_set_gray_to_rgb(png_ptr);
If you have a grayscale and you are using png_set_expand() to change to
a higher bit-depth you must indicate if the supplied background gray
is supplied in the original file bit depth (need_expand = 1) or in the
expanded bit depth (need_expand = 0). Similarly, if you are reading
a paletted image, you must indicate if you have supplied the background
as a palette index that needs to be expanded (need_expand = 1). You can
also specify an RGB triplet that isn't in the palette when setting your
background for a paletted image.
a higher bit-depth, you must either supply the background color as a gray
value at the original file bit-depth (need_expand = 1) or else supply the
background color as an RGB triplet at the final, expanded bit depth
(need_expand = 0). Similarly, if you are reading a paletted image, you
must either supply the background color as a palette index (need_expand = 1)
or as an RGB triplet that may or may not be in the palette (need_expand = 0).
png_color_16 my_background;
png_color_16p image_background;
if (png_get_bKGD(png_ptr, info_ptr,
&image_background))
png_set_background(png_ptr, image_background),
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
png_set_background(png_ptr, image_background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
@@ -875,7 +873,7 @@ png_infop info_ptr;
initialize_png_reader()
{
png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return -1;
@@ -1047,7 +1045,7 @@ both "png_ptr"; you can call them anything you like, such as
"read_ptr" and "write_ptr". Look at pngtest.c, for example.
png_structp png_ptr = png_create_write_struct
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return;
@@ -1827,19 +1825,23 @@ Removing unwanted object code:
There are a bunch of #define's in pngconf.h that control what parts of
libpng are compiled. All the defines end in _SUPPORTED. If you are
never going to use an ability, you can change the #define to #undef
before recompiling libpng and save yourself code and data space.
You can also turn a number of them off en masse with a compiler directive
that defines PNG_READ[or WRITE]_TRANSFORMS_NOT_SUPPORTED, or
PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED, or all four,
never going to use a capability, you can change the #define to #undef
before recompiling libpng and save yourself code and data space, or
you can turn off individual capabilities with defines that begin with
PNG_NO_.
You can also turn all of the transforms and ancillary chunk capabilities
off en masse with compiler directives that define
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
or all four,
along with directives to turn on any of the capabilities that you do
want. The PNG_READ[or WRITE]_TRANSFORMS_NOT_SUPPORTED directives disable
want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
the extra transformations but still leave the library fully capable of reading
and writing PNG files with all known public chunks [except for sPLT].
Use of the PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED directive
Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
produces a library that is incapable of reading or writing ancillary chunks.
If you are not using the progressive reading capability, you can
turn that off with PNG_PROGRESSIVE_READ_NOT_SUPPORTED (don't confuse
turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
this with the INTERLACING capability, which you'll still have).
All the reading and writing specific code are in separate files, so the

View File

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

2
png.5
View File

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

6
png.c
View File

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

92
png.h
View File

@@ -1,12 +1,12 @@
/* png.h - header file for PNG reference library
*
* libpng 1.0.1a
* libpng 1.0.1c
* For conditions of distribution and use, see the COPYRIGHT NOTICE below.
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998 Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*
* Note about libpng version numbers:
*
@@ -18,30 +18,32 @@
*
* source png.h png.h shared-lib
* version string int version
* ------- ------ ------ ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
* 0.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [int should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
* 1.0.1 1.0.1 10001 2.1.0
* 1.0.1a 1.0.1a 10002 2.1.0
* ------- ------ ----- ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
* 0.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [int should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
* 1.0.1 1.0.1 10001 2.1.0
* 1.0.1a 1.0.1a 10002 2.1.0.1a
* 1.0.1b 1.0.1b 10002 2.1.0.1b
* 1.0.1c 1.0.1c 10002 2.1.0.1c
*
* Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be
* used for changes in backward compatibility, as it is intended.
* The PNG_PNGLIB_VER macro, which is not used within libpng but
* is available for applications, is an unsigned integer of the form
* xyyzz corresponding to the source version x.y.z (leading zeros in y and z).
* used for changes in backward compatibility, as it is intended. The
* PNG_PNGLIB_VER macro, which is not used within libpng but is available
* for applications, is an unsigned integer of the form xyyzz corresponding
* to the source version x.y.z (leading zeros in y and z).
*
* See libpng.txt or libpng.3 for more information. The PNG specification is
* available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
* See libpng.txt or libpng.3 for more information. The PNG specification
* is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
* and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
*
* Contributing Authors:
@@ -118,7 +120,7 @@ extern "C" {
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.0.1a"
#define PNG_LIBPNG_VER_STRING "1.0.1c"
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros.
@@ -710,12 +712,12 @@ extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
extern PNG_EXPORT(png_structp,png_create_read_struct)
PNGARG((png_const_charp user_png_ver, voidp error_ptr,
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn));
/* Allocate and initialize png_ptr struct for reading, and any other memory */
extern PNG_EXPORT(png_structp,png_create_write_struct)
PNGARG((png_const_charp user_png_ver, voidp error_ptr,
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn));
/* Write a PNG chunk - size, type, (optional) data, CRC. */
@@ -1443,6 +1445,45 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#define png_debug2(l, m, p1, p2)
#endif /* (PNG_DEBUG > 0) */
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
/* With these routines, we avoid an integer divide, which will be slower on
* many machines. However, it does take more operations than the corresponding
* divide method, so it may be slower on some RISC systems. There are two
* shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
*
* Note that the rounding factors are NOT supposed to be the same! 128 and
* 32768 are correct for the NODIV code; 127 and 32767 are correct for the
* standard method.
*
* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
*/
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
# define png_composite(composite, fg, alpha, bg) \
{ png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
(png_uint_16)(bg)*(png_uint_16)(255 - \
(png_uint_16)(alpha)) + (png_uint_16)128); \
(composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
# define png_composite_16(composite, fg, alpha, bg) \
{ png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
(png_uint_32)(bg)*(png_uint_32)(65535L - \
(png_uint_32)(alpha)) + (png_uint_32)32768L); \
(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
#else /* standard method using integer division */
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
# define png_composite(composite, fg, alpha, bg) \
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
(png_uint_16)127) / 255)
# define png_composite_16(composite, fg, alpha, bg) \
(composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
(png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
(png_uint_32)32767) / (png_uint_32)65535L)
#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
/* These next functions are used internally in the code. They generally
* shouldn't be used unless you are writing code to add or replace some
* functionality in libpng. More information about most functions can
@@ -1525,6 +1566,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#define PNG_FLAG_FREE_HIST 0x4000
#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
#define PNG_FLAG_WROTE_tIME 0x10000L
#define PNG_FLAG_BACKGROUND_IS_GRAY 0x20000L
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)

156
pngconf.h
View File

@@ -1,12 +1,12 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng 1.0.1a
* libpng 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*/
/* Any machine specific code is near the front of this file, so if you
@@ -237,72 +237,139 @@ __dont__ include it again
/* Any transformations you will not be using can be undef'ed here */
/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user
to turn it off with "*TRANSFORMS_NOT_SUPPORTED" on the compile line,
then pick and choose which ones to define without having to edit
this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED if you
only want to have a png-compliant reader/writer but don't need
to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS
on the compile line, then pick and choose which ones to define without
having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED
if you only want to have a png-compliant reader/writer but don't need
any of the extra transformations. This saves about 80 kbytes in a
typical installation of the library.
typical installation of the library. (PNG_NO_* form added in version
1.0.1c, for consistency)
*/
#ifndef PNG_READ_TRANSFORMS_NOT_SUPPORTED
#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
!defined(PNG_NO_READ_TRANSFORMS)
#define PNG_READ_TRANSFORMS_SUPPORTED
#endif
#ifndef PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
#if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
!defined(PNG_NO_WRITE_TRANSFORMS)
#define PNG_WRITE_TRANSFORMS_SUPPORTED
#endif
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
#ifndef PNG_NO_READ_EXPAND
#define PNG_READ_EXPAND_SUPPORTED
#endif
#ifndef PNG_NO_READ_SHIFT
#define PNG_READ_SHIFT_SUPPORTED
#endif
#ifndef PNG_NO_READ_PACK
#define PNG_READ_PACK_SUPPORTED
#endif
#ifndef PNG_NO_READ_BGR
#define PNG_READ_BGR_SUPPORTED
#endif
#ifndef PNG_NO_READ_SWAP
#define PNG_READ_SWAP_SUPPORTED
#endif
#ifndef PNG_NO_READ_PACKSWAP
#define PNG_READ_PACKSWAP_SUPPORTED
#endif
#ifndef PNG_NO_READ_INVERT
#define PNG_READ_INVERT_SUPPORTED
#endif
#ifndef PNG_NO_READ_DITHER
#define PNG_READ_DITHER_SUPPORTED
#endif
#ifndef PNG_NO_READ_BACKGROUND
#define PNG_READ_BACKGROUND_SUPPORTED
#endif
#ifndef PNG_NO_READ_16_TO_8
#define PNG_READ_16_TO_8_SUPPORTED
#endif
#ifndef PNG_NO_READ_FILLER
#define PNG_READ_FILLER_SUPPORTED
#endif
#ifndef PNG_NO_READ_GAMMA
#define PNG_READ_GAMMA_SUPPORTED
#endif
#ifndef PNG_NO_READ_GRAY_TO_RGB
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#endif
#ifndef PNG_NO_READ_SWAP_ALPHA
#define PNG_READ_SWAP_ALPHA_SUPPORTED
#endif
#ifndef PNG_NO_READ_INVERT_ALPHA
#define PNG_READ_INVERT_ALPHA_SUPPORTED
#endif
#ifndef PNG_NO_READ_STRIP_ALPHA
#define PNG_READ_STRIP_ALPHA_SUPPORTED
#endif
#ifndef PNG_NO_READ_USER_TRANSFORM
#define PNG_READ_USER_TRANSFORM_SUPPORTED
#endif
/* the following aren't implemented yet
#define PNG_READ_RGB_TO_GRAY_SUPPORTED
*/
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
#ifndef PNG_PROGRESSIVE_READ_NOT_SUPPORTED /* if you don't do progressive */
#if !defined(PNG_NO_PROGRESSIVE_READ) && \
!defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
#define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
#endif /* about interlacing capability! You'll */
/* still have interlacing unless you change the following line: */
#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
#ifndef PNG_NO_READ_COMPOSITED_NODIV
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel and SGI */
#endif
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
#ifndef PNG_NO_WRITE_SHIFT
#define PNG_WRITE_SHIFT_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_PACK
#define PNG_WRITE_PACK_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_BGR
#define PNG_WRITE_BGR_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_SWAP
#define PNG_WRITE_SWAP_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_PACKSWAP
#define PNG_WRITE_PACKSWAP_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_INVERT
#define PNG_WRITE_INVERT_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_FILLER
#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
#define PNG_WRITE_FLUSH_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_SWAP_ALPHA
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_INVERT_ALPHA
#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_USER_TRANSFORM
#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
#endif
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
encoders, but can cause trouble
if left undefined */
#if !defined(PNG_NO_STDIO)
#ifndef PNG_NO_WRITE_WEIGHTED_FILTER
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif
#ifndef PNG_NO_WRITE_FLUSH
#define PNG_WRITE_FLUSH_SUPPORTED
#endif
#ifndef PNG_NO_STDIO
#define PNG_TIME_RFC1123_SUPPORTED
#endif
@@ -322,7 +389,7 @@ __dont__ include it again
* png_get_x_offset_microns()
* png_get_y_offset_microns()
*/
#if !defined(PNG_NO_EASY_ACCESS)
#ifndef PNG_NO_EASY_ACCESS
#define PNG_EASY_ACCESS_SUPPORTED
#endif
@@ -351,45 +418,100 @@ __dont__ include it again
* a bit smaller.
*/
#ifndef PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
#if !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
!defined(PNG_NO_READ_ANCILLARY_CHUNKS)
#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#endif
#ifndef PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
#if !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
!defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#endif
#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#ifndef PNG_NO_PNG_READ_bKGD
#define PNG_READ_bKGD_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_cHRM
#define PNG_READ_cHRM_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_gAMA
#define PNG_READ_gAMA_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_hIST
#define PNG_READ_hIST_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_oFFs
#define PNG_READ_oFFs_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_pCAL
#define PNG_READ_pCAL_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_pHYs
#define PNG_READ_pHYs_SUPPORTED
#endif
#ifndef PNG_NO_READ_sBIT
#define PNG_READ_sBIT_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_sRGB
#define PNG_READ_sRGB_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_tEXt
#define PNG_READ_tEXt_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_tIME
#define PNG_READ_tIME_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_tRNS
#define PNG_READ_tRNS_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_zTXt
#define PNG_READ_zTXt_SUPPORTED
#endif
#ifndef PNG_NO_PNG_READ_OPT_PLTE
#define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the optional */
/* PLTE chunk in RGB and RGBA images */
#endif /* PLTE chunk in RGB and RGBA images */
#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#ifndef PNG_NO_PNG_WRITE_bKGD
#define PNG_WRITE_bKGD_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_cHRM
#define PNG_WRITE_cHRM_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_gAMA
#define PNG_WRITE_gAMA_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_hIST
#define PNG_WRITE_hIST_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_oFFs
#define PNG_WRITE_oFFs_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_pCAL
#define PNG_WRITE_pCAL_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_pHYs
#define PNG_WRITE_pHYs_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_sBIT
#define PNG_WRITE_sBIT_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_sRGB
#define PNG_WRITE_sRGB_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_tEXt
#define PNG_WRITE_tEXt_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_tIME
#define PNG_WRITE_tIME_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_tRNS
#define PNG_WRITE_tRNS_SUPPORTED
#endif
#ifndef PNG_NO_PNG_WRITE_zTXt
#define PNG_WRITE_zTXt_SUPPORTED
#endif
#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
/* need the time information for reading tIME chunks */

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,12 +1,12 @@
/* pngread.c - read a PNG file
*
* libpng 1.0.1a
* 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*
* This file contains routines that an application calls directly to
* read a PNG file or stream.
@@ -17,7 +17,7 @@
/* Create a PNG structure for reading, and allocate any memory needed. */
png_structp
png_create_read_struct(png_const_charp user_png_ver, voidp error_ptr,
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn)
{
png_structp png_ptr;
@@ -82,7 +82,7 @@ png_create_read_struct(png_const_charp user_png_ver, voidp error_ptr,
}
/* Initialize PNG structure for reading, and allocate any memory needed.
This interface is depreciated in favour of the png_create_read_struct(),
This interface is deprecated in favour of the png_create_read_struct(),
and it will eventually disappear. */
void
png_read_init(png_structp png_ptr)
@@ -279,6 +279,38 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{
/* check for transforms that have been set but were defined out */
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_MONO)
png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
if (png_ptr->transformations & PNG_FILLER)
png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
if (png_ptr->transformations & PNG_PACK)
png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
if (png_ptr->transformations & PNG_SHIFT)
png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
if (png_ptr->transformations & PNG_BGR)
png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
#endif
}
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* if interlaced and we do not need a new row, combine row and return */
@@ -488,25 +520,34 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
/* save jump buffer and error functions */
rp = row;
dp = display_row;
for (i = 0; i < num_rows; i++)
{
png_bytep rptr;
png_bytep dptr;
if (rp != NULL)
rptr = *rp;
else
rptr = NULL;
if (dp != NULL)
dptr = *dp;
else
dptr = NULL;
png_read_row(png_ptr, rptr, dptr);
if (row != NULL)
rp++;
if (display_row != NULL)
dp++;
}
if(rp != NULL && dp != NULL)
for (i = 0; i < num_rows; i++)
{
png_bytep rptr = *rp++;
png_bytep dptr = *dp++;
png_read_row(png_ptr, rptr, dptr);
}
else
for (i = 0; i < num_rows; i++)
{
png_bytep rptr;
png_bytep dptr;
if (rp != NULL)
rptr = *rp;
else
rptr = NULL;
if (dp != NULL)
dptr = *dp;
else
dptr = NULL;
png_read_row(png_ptr, rptr, dptr);
if (row != NULL)
rp++;
if (display_row != NULL)
dp++;
}
}
/* Read the entire image. If the image has an alpha channel or a tRNS
@@ -729,8 +770,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
#if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table != NULL)
{
int i,istop;
istop = (1 << (8 - png_ptr->gamma_shift));
int i;
int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_table[i]);
@@ -741,8 +782,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_16_table);
if (png_ptr->gamma_16_from_1 != NULL)
{
int i,istop;
istop = (1 << (8 - png_ptr->gamma_shift));
int i;
int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
@@ -751,8 +792,8 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_16_from_1);
if (png_ptr->gamma_16_to_1 != NULL)
{
int i,istop;
istop = (1 << (8 - png_ptr->gamma_shift));
int i;
int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_to_1[i]);

View File

@@ -1,12 +1,12 @@
/* pngrio.c - functions for data input
*
* libpng 1.0.1a
* libpng 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*
* This file provides a location for all input. Users which need
* 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
*
* libpng 1.0.1a
* 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*
* This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG.
@@ -17,46 +17,6 @@
#define PNG_INTERNAL
#include "png.h"
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
/* With these routines, we avoid an integer divide, which will be slower on
* many machines. However, it does take more operations than the corresponding
* divide method, so it may be slower on some RISC systems. There are two
* shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
*
* Note that the rounding factors are NOT supposed to be the same! 128 and
* 32768 are correct for the NODIV code; 127 and 32767 are correct for the
* standard method.
*
* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
*/
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
# define png_composite(composite, fg, alpha, bg) \
{ png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
(png_uint_16)(bg)*(png_uint_16)(255 - \
(png_uint_16)(alpha)) + (png_uint_16)128); \
(composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
# define png_composite_16(composite, fg, alpha, bg) \
{ png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
(png_uint_32)(bg)*(png_uint_32)(65535L - \
(png_uint_32)(alpha)) + (png_uint_32)32768L); \
(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
#else /* standard method using integer division */
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
# define png_composite(composite, fg, alpha, bg) \
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
(png_uint_16)127) / 255)
# define png_composite_16(composite, fg, alpha, bg) \
(composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
(png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
(png_uint_32)32767) / (png_uint_32)65535L)
#endif /* ?PNG_READ_COMPOSITE_NODIV_SUPPORTED */
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
void
png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
@@ -125,11 +85,21 @@ png_set_background(png_structp png_ptr,
}
png_ptr->transformations |= PNG_BACKGROUND;
png_memcpy(&(png_ptr->background), background_color,
sizeof(png_color_16));
png_memcpy(&(png_ptr->background), background_color, sizeof(png_color_16));
png_ptr->background_gamma = (float)background_gamma;
png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
/* Note: if need_expand is set and color_type is either RGB or RGB_ALPHA
* (in which case need_expand is superfluous anyway), the background color
* might actually be gray yet not be flagged as such. This is not a problem
* for the current code, which uses PNG_FLAG_BACKGROUND_IS_GRAY only to
* decide when to do the png_do_gray_to_rgb() transformation.
*/
if ((need_expand && !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) ||
(!need_expand && background_color->red == background_color->green &&
background_color->red == background_color->blue))
png_ptr->flags |= PNG_FLAG_BACKGROUND_IS_GRAY;
}
#endif
@@ -447,9 +417,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
if (hash[i] != NULL)
{
png_dsortp p;
p = hash[i];
png_dsortp p = hash[i];
while (p)
{
png_dsortp t;
@@ -478,17 +446,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
if (full_dither)
{
int i;
int total_bits, num_red, num_green, num_blue;
png_size_t num_entries;
png_bytep distance;
total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
PNG_DITHER_BLUE_BITS;
num_red = (1 << PNG_DITHER_RED_BITS);
num_green = (1 << PNG_DITHER_GREEN_BITS);
num_blue = (1 << PNG_DITHER_BLUE_BITS);
num_entries = ((png_size_t)1 << total_bits);
int num_red = (1 << PNG_DITHER_RED_BITS);
int num_green = (1 << PNG_DITHER_GREEN_BITS);
int num_blue = (1 << PNG_DITHER_BLUE_BITS);
png_size_t num_entries = ((png_size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
(png_uint_32)(num_entries * sizeof (png_byte)));
@@ -502,34 +466,29 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (i = 0; i < num_palette; i++)
{
int r, g, b, ir, ig, ib;
r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
int ir, ig, ib;
int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
for (ir = 0; ir < num_red; ir++)
{
int dr, index_r;
int dr = abs(ir - r);
int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
dr = abs(ir - r);
index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
for (ig = 0; ig < num_green; ig++)
{
int dg, dt, dm, index_g;
int dg = abs(ig - g);
int dt = dr + dg;
int dm = ((dr > dg) ? dr : dg);
int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
dg = abs(ig - g);
dt = dr + dg;
dm = ((dr > dg) ? dr : dg);
index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
for (ib = 0; ib < num_blue; ib++)
{
int d_index, db, dmax, d;
d_index = index_g | ib;
db = abs(ib - b);
dmax = ((dm > db) ? dm : db);
d = dmax + dt + db;
int d_index = index_g | ib;
int db = abs(ib - b);
int dmax = ((dm > db) ? dm : db);
int d = dmax + dt + db;
if (d < (int)distance[d_index])
{
@@ -617,15 +576,17 @@ png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
void
png_init_read_transformations(png_structp png_ptr)
{
int color_type;
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if(png_ptr == NULL) return;
#endif
png_debug(1, "in png_init_read_transformations\n");
color_type = png_ptr->color_type;
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
{
if (color_type == PNG_COLOR_TYPE_GRAY)
int color_type = png_ptr->color_type;
if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
{
/* expand background chunk. */
switch (png_ptr->bit_depth)
@@ -694,12 +655,10 @@ png_init_read_transformations(png_structp png_ptr)
{
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
int num_palette, i;
png_color back, back_1;
png_colorp palette;
palette = png_ptr->palette;
num_palette = png_ptr->num_palette;
png_colorp palette = png_ptr->palette;
int num_palette = png_ptr->num_palette;
int i;
if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
{
@@ -796,11 +755,9 @@ png_init_read_transformations(png_structp png_ptr)
else
/* color_type != PNG_COLOR_TYPE_PALETTE */
{
double g, gs, m;
m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
g = 1.0;
gs = 1.0;
double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
double g = 1.0;
double gs = 1.0;
switch (png_ptr->background_gamma_type)
{
@@ -850,11 +807,9 @@ png_init_read_transformations(png_structp png_ptr)
#endif
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
int num_palette, i;
png_colorp palette;
palette = png_ptr->palette;
num_palette = png_ptr->num_palette;
png_colorp palette = png_ptr->palette;
int num_palette = png_ptr->num_palette;
int i;
for (i = 0; i < num_palette; i++)
{
@@ -873,16 +828,15 @@ png_init_read_transformations(png_structp png_ptr)
if (png_ptr->transformations & PNG_BACKGROUND &&
color_type == PNG_COLOR_TYPE_PALETTE)
{
int i,istop;
int i;
int istop = (int)png_ptr->num_trans;
png_color back;
png_colorp palette;
png_colorp palette = png_ptr->palette;
palette = png_ptr->palette;
back.red = (png_byte)png_ptr->background.red;
back.green = (png_byte)png_ptr->background.green;
back.blue = (png_byte)png_ptr->background.blue;
istop = (int)png_ptr->num_trans;
for (i = 0; i < istop; i++)
{
if (png_ptr->trans[i] == 0)
@@ -891,6 +845,7 @@ png_init_read_transformations(png_structp png_ptr)
}
else if (png_ptr->trans[i] != 0xff)
{
/* The png_composite() macro is defined in png.h */
png_composite(palette[i].red, palette[i].red,
png_ptr->trans[i], back.red);
png_composite(palette[i].green, palette[i].green,
@@ -906,19 +861,18 @@ png_init_read_transformations(png_structp png_ptr)
if ((png_ptr->transformations & PNG_SHIFT) &&
color_type == PNG_COLOR_TYPE_PALETTE)
{
png_uint_16 i,istop;
int sr, sg, sb;
png_uint_16 i;
png_uint_16 istop = png_ptr->num_palette;
int sr = 8 - png_ptr->sig_bit.red;
int sg = 8 - png_ptr->sig_bit.green;
int sb = 8 - png_ptr->sig_bit.blue;
sr = 8 - png_ptr->sig_bit.red;
if (sr < 0 || sr > 8)
sr = 0;
sg = 8 - png_ptr->sig_bit.green;
if (sg < 0 || sg > 8)
sg = 0;
sb = 8 - png_ptr->sig_bit.blue;
if (sb < 0 || sb > 8)
sb = 0;
istop = png_ptr->num_palette;
for (i = 0; i < istop; i++)
{
png_ptr->palette[i].red >>= sr;
@@ -1008,23 +962,19 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
#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)
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->bit_depth);
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
}
@@ -1077,6 +1027,44 @@ png_do_read_transformations(png_structp png_ptr)
PNG_FLAG_FILLER_AFTER);
#endif
/*
From Andreas Dilger e-mail to png-implement, 26 March 1998:
In most cases, the "simple transparency" should be done prior to doing
gray-to-RGB, or you will have to test 3x as many bytes to check if a
pixel is transparent. You would also need to make sure that the
transparency information is upgraded to RGB.
To summarize, the current flow is:
- Gray + simple transparency -> compare 1 or 2 gray bytes and composite
with background "in place" if transparent,
convert to RGB if necessary
- Gray + alpha -> composite with gray background and remove alpha bytes,
convert to RGB if necessary
To support RGB backgrounds for gray images we need:
- Gray + simple transparency -> convert to RGB + simple transparency, compare
3 or 6 bytes and composite with background
"in place" if transparent (3x compare/pixel
compared to doing composite with gray bkgrnd)
- Gray + alpha -> convert to RGB + alpha, composite with background and
remove alpha bytes (3x float operations/pixel
compared with composite on gray background)
Greg's change will do this. The reason it wasn't done before is for
performance, as this increases the per-pixel operations. If we would check
in advance if the background was gray or RGB, and position the gray-to-RGB
transform appropriately, then it would save a lot of work/time.
*/
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* if gray -> RGB, do so now only if background is non-gray; else do later
* for performance reasons */
if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
!(png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
if ((png_ptr->transformations & PNG_BACKGROUND) &&
((png_ptr->num_trans != 0 ) ||
@@ -1146,7 +1134,9 @@ png_do_read_transformations(png_structp png_ptr)
#endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
/* if gray -> RGB, do so now only if we did not do so above */
if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY)
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
@@ -1205,17 +1195,16 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth < 8)
#endif
{
png_uint_32 shift, i;
png_uint_32 i;
png_uint_32 row_width=row_info->width;
png_bytep sp, dp;
switch (row_info->bit_depth)
{
case 1:
{
sp = row + (png_size_t)((row_width - 1) >> 3);
dp = row + (png_size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 7);
png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
png_bytep dp = row + (png_size_t)row_width - 1;
png_uint_32 shift = 7 - (int)((row_width + 7) & 7);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x1);
@@ -1234,9 +1223,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
case 2:
{
sp = row + (png_size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 3)) << 1);
png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
png_bytep dp = row + (png_size_t)row_width - 1;
png_uint_32 shift = (int)((3 - ((row_width + 3) & 3)) << 1);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x3);
@@ -1254,9 +1243,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
}
case 4:
{
sp = row + (png_size_t)((row_width - 1) >> 1);
dp = row + (png_size_t)row_width - 1;
shift = (int)((1 - ((row_width + 1) & 1)) << 2);
png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
png_bytep dp = row + (png_size_t)row_width - 1;
png_uint_32 shift = (int)((1 - ((row_width + 1) & 1)) << 2);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0xf);
@@ -1297,11 +1286,11 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{
int shift[4];
int channels, c;
png_uint_16 value;
int channels = 0;
int c;
png_uint_16 value = 0;
png_uint_32 row_width = row_info->width;
channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
{
shift[channels++] = row_info->bit_depth - sig_bits->red;
@@ -1317,8 +1306,6 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
shift[channels++] = row_info->bit_depth - sig_bits->alpha;
}
value = 0;
for (c = 0; c < channels; c++)
{
if (shift[c] <= 0)
@@ -1335,64 +1322,55 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 2:
{
png_bytep bp;
png_uint_32 i,istop;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
istop = row_info->rowbytes;
for (bp = row, i = 0; i < istop; i++, bp++)
for (bp = row, i = 0; i < istop; i++)
{
*bp >>= 1;
*bp &= 0x55;
*bp++ &= 0x55;
}
break;
}
case 4:
{
png_bytep bp;
png_byte mask;
png_uint_32 i,istop;
mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
png_byte mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
(png_byte)((int)0xf >> shift[0]);
istop = row_info->rowbytes;
for (bp = row, i = 0; i < istop; i++, bp++)
for (bp = row, i = 0; i < istop; i++)
{
*bp >>= shift[0];
*bp &= mask;
*bp++ &= mask;
}
break;
}
case 8:
{
png_bytep bp;
png_bytep bp = row;
png_uint_32 i;
int cstop;
png_uint_32 istop = row_width * channels;
cstop=(int)row_info->channels;
for (bp = row, i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{
for (c = 0; c < cstop; c++, bp++)
{
*bp >>= shift[c];
}
*bp++ >>= shift[i%channels];
}
break;
}
case 16:
{
png_bytep bp;
png_size_t i;
int cstop;
png_bytep bp = row;
png_uint_32 i;
png_uint_32 istop = channels * row_width;
cstop=(int)row_info->channels;
for (bp = row, i = 0; i < row_width; i++)
for (i = 0; i < istop; i++)
{
for (c = 0; c < cstop; c++, bp += 2)
{
value = (png_uint_16)((*bp << 8) + *(bp + 1));
value >>= shift[c];
*bp = (png_byte)(value >> 8);
*(bp + 1) = (png_byte)(value & 0xff);
}
value = (png_uint_16)((*bp << 8) + *(bp + 1));
value >>= shift[i%channels];
*bp++ = (png_byte)(value >> 8);
*bp++ = (png_byte)(value & 0xff);
}
break;
}
@@ -1413,12 +1391,11 @@ png_do_chop(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 16)
#endif
{
png_bytep sp, dp;
png_uint_32 i, istop;
png_bytep sp = row;
png_bytep dp = row;
png_uint_32 i;
png_uint_32 istop = row_info->width * row_info->channels;
sp = row;
dp = row;
istop = row_info->width * row_info->channels;
for (i = 0; i<istop; i++, sp += 2, dp++)
{
#if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
@@ -1472,10 +1449,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from RGBA to ARGB */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_byte save;
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
save = *(--sp);
@@ -1488,10 +1466,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from RRGGBBAA to AARRGGBB */
else
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_byte save[2];
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
save[0] = *(--sp);
@@ -1512,10 +1491,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from GA to AG */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_byte save;
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
save = *(--sp);
@@ -1526,11 +1506,11 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
/* This converts from GGAA to AAGG */
else
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_byte save[2];
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
save[0] = *(--sp);
@@ -1561,10 +1541,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1576,10 +1556,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in RRGGBBAA */
else
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1598,10 +1578,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in GA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1611,10 +1591,10 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
/* This inverts the alpha channel in GGAA */
else
{
png_bytep sp, dp;
png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp;
png_uint_32 i;
sp = dp = row + row_info->rowbytes;
for (i = 0; i < row_width; i++)
{
*(--dp) = 255 - *(--sp);
@@ -1634,12 +1614,11 @@ void
png_do_read_filler(png_row_infop row_info, png_bytep row,
png_uint_32 filler, png_uint_32 flags)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
png_byte hi_filler = (png_byte)((filler>>8) & 0xf);
png_byte low_filler = (png_byte)(filler & 0xf);
png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
png_byte low_filler = (png_byte)(filler & 0xff);
png_debug(1, "in png_do_read_filler\n");
if (
@@ -1653,8 +1632,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from G to GX */
if (flags & PNG_FLAG_FILLER_AFTER)
{
sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = low_filler;
@@ -1667,8 +1646,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from G to XG */
else
{
sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1684,8 +1663,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from GG to GGXX */
if (flags & PNG_FLAG_FILLER_AFTER)
{
sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = hi_filler;
@@ -1700,8 +1679,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from GG to XXGG */
else
{
sp = row + (png_size_t)row_width;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1722,8 +1701,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from RGB to RGBX */
if (flags & PNG_FLAG_FILLER_AFTER)
{
sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width * 3;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = low_filler;
@@ -1738,8 +1717,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from RGB to XRGB */
else
{
sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width * 3;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1757,8 +1736,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from RRGGBB to RRGGBBXX */
if (flags & PNG_FLAG_FILLER_AFTER)
{
sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width * 3;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 1; i < row_width; i++)
{
*(--dp) = hi_filler;
@@ -1777,8 +1756,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
/* This changes the data from RRGGBB to XXRRGGBB */
else
{
sp = row + (png_size_t)row_width * 3;
dp = sp + (png_size_t)row_width;
png_bytep sp = row + (png_size_t)row_width * 3;
png_bytep dp = sp + (png_size_t)row_width;
for (i = 0; i < row_width; i++)
{
*(--dp) = *(--sp);
@@ -1804,7 +1783,6 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
void
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
@@ -1819,8 +1797,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{
if (row_info->bit_depth == 8)
{
sp = row + (png_size_t)row_width - 1;
dp = sp + (png_size_t)row_width * 2;
png_bytep sp = row + (png_size_t)row_width - 1;
png_bytep dp = sp + (png_size_t)row_width * 2;
for (i = 0; i < row_width; i++)
{
*(dp--) = *sp;
@@ -1831,8 +1809,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
}
else
{
sp = row + (png_size_t)row_width * 2 - 1;
dp = sp + (png_size_t)row_width * 4;
png_bytep sp = row + (png_size_t)row_width * 2 - 1;
png_bytep dp = sp + (png_size_t)row_width * 4;
for (i = 0; i < row_width; i++)
{
*(dp--) = *sp;
@@ -1850,8 +1828,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{
if (row_info->bit_depth == 8)
{
sp = row + (png_size_t)row_width * 2 - 1;
dp = sp + (png_size_t)row_width * 2;
png_bytep sp = row + (png_size_t)row_width * 2 - 1;
png_bytep dp = sp + (png_size_t)row_width * 2;
for (i = 0; i < row_width; i++)
{
*(dp--) = *(sp--);
@@ -1863,8 +1841,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
}
else
{
sp = row + (png_size_t)row_width * 4 - 1;
dp = sp + (png_size_t)row_width * 4;
png_bytep sp = row + (png_size_t)row_width * 4 - 1;
png_bytep dp = sp + (png_size_t)row_width * 4;
for (i = 0; i < row_width; i++)
{
*(dp--) = *(sp--);
@@ -2348,11 +2326,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++, sp += 6)
{
png_uint_16 r, g, b;
r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
if (r == trans_values->red && g == trans_values->green &&
b == trans_values->blue)
{
@@ -2366,8 +2342,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else
{
png_uint_16 v;
v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
@@ -2385,11 +2360,10 @@ png_do_background(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++, sp += 6)
{
png_uint_16 r, g, b;
png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
if (r == trans_values->red && g == trans_values->green &&
b == trans_values->blue)
{
@@ -2417,9 +2391,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 2, dp++)
{
png_uint_16 a;
png_uint_16 a = *(sp + 1);
a = *(sp + 1);
if (a == 0xff)
{
*dp = gamma_table[*sp];
@@ -2446,9 +2419,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 2, dp++)
{
png_byte a;
png_byte a = *(sp + 1);
a = *(sp + 1);
if (a == 0xff)
{
*dp = *sp;
@@ -2474,9 +2446,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 2)
{
png_uint_16 a;
png_uint_16 a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
if (a == (png_uint_16)0xffff)
{
png_uint_16 v;
@@ -2510,9 +2481,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 2)
{
png_uint_16 a;
a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
png_uint_16 a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
if (a == (png_uint_16)0xffff)
{
png_memcpy(dp, sp, 2);
@@ -2548,9 +2517,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 3)
{
png_byte a;
png_byte a = *(sp + 3);
a = *(sp + 3);
if (a == 0xff)
{
*dp = gamma_table[*sp];
@@ -2587,9 +2555,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 4, dp += 3)
{
png_byte a;
png_byte a = *(sp + 3);
a = *(sp + 3);
if (a == 0xff)
{
*dp = *sp;
@@ -2623,10 +2590,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 8, dp += 6)
{
png_uint_16 a;
a = (png_uint_16)(((png_uint_16)(*(sp + 6)) << 8) +
(png_uint_16)(*(sp + 7)));
png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
<< 8) + (png_uint_16)(*(sp + 7)));
if (a == (png_uint_16)0xffff)
{
png_uint_16 v;
@@ -2680,10 +2645,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
dp = row;
for (i = 0; i < row_width; i++, sp += 8, dp += 6)
{
png_uint_16 a;
a = (png_uint_16)(((png_uint_16)(*(sp + 6)) << 8) +
(png_uint_16)(*(sp + 7)));
png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
<< 8) + (png_uint_16)(*(sp + 7)));
if (a == (png_uint_16)0xffff)
{
png_memcpy(dp, sp, 6);
@@ -2699,11 +2662,13 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else
{
png_uint_16 r, g, b, v;
png_uint_16 v;
r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8)
+ *(sp + 3);
png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8)
+ *(sp + 5);
png_composite_16(v, r, a, background->red);
*dp = (png_byte)((v >> 8) & 0xff);
@@ -2820,9 +2785,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++)
{
png_uint_16 v;
v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
sp += 2;
@@ -2854,9 +2817,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++)
{
png_uint_16 v;
v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
sp += 4;
@@ -2910,9 +2871,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp = row;
for (i = 0; i < row_width; i++)
{
png_uint_16 v;
v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
sp += 2;

View File

@@ -1,12 +1,12 @@
/* pngrutil.c - utilities to read a PNG file
*
* libpng 1.0.1a
* 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*
* This file contains routines which are only called from within
* libpng itself during the course of reading an image.
@@ -20,9 +20,7 @@
png_uint_32
png_get_uint_32(png_bytep buf)
{
png_uint_32 i;
i = ((png_uint_32)(*buf) << 24) +
png_uint_32 i = ((png_uint_32)(*buf) << 24) +
((png_uint_32)(*(buf + 1)) << 16) +
((png_uint_32)(*(buf + 2)) << 8) +
(png_uint_32)(*(buf + 3));
@@ -37,9 +35,7 @@ png_get_uint_32(png_bytep buf)
png_int_32
png_get_int_32(png_bytep buf)
{
png_int_32 i;
i = ((png_int_32)(*buf) << 24) +
png_int_32 i = ((png_int_32)(*buf) << 24) +
((png_int_32)(*(buf + 1)) << 16) +
((png_int_32)(*(buf + 2)) << 8) +
(png_int_32)(*(buf + 3));
@@ -52,9 +48,7 @@ png_get_int_32(png_bytep buf)
png_uint_16
png_get_uint_16(png_bytep buf)
{
png_uint_16 i;
i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
(png_uint_16)(*(buf + 1)));
return (i);
@@ -76,16 +70,16 @@ png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
int
png_crc_finish(png_structp png_ptr, png_uint_32 skip)
{
png_uint_32 i,istop;
png_size_t i;
png_size_t istop = png_ptr->zbuf_size;
istop = (png_uint_32)png_ptr->zbuf_size;
for (i = skip; i > istop; i -= istop)
for (i = (png_size_t)skip; i > istop; i -= istop)
{
png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
}
if (i)
{
png_crc_read(png_ptr, png_ptr->zbuf, (png_size_t)i);
png_crc_read(png_ptr, png_ptr->zbuf, i);
}
if (png_crc_error(png_ptr))
@@ -1500,16 +1494,14 @@ png_combine_row(png_structp png_ptr, png_bytep row,
{
case 1:
{
png_bytep sp;
png_bytep dp;
png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp = row;
int s_inc, s_start, s_end;
int m;
int m = 0x80;
int shift;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = png_ptr->width;
sp = png_ptr->row_buf + 1;
dp = row;
m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
{
@@ -1527,8 +1519,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
shift = s_start;
istop = png_ptr->width;
for (i = 0; i < istop; i++)
for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1557,17 +1548,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
case 2:
{
png_bytep sp;
png_bytep dp;
png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp = row;
int s_start, s_end, s_inc;
int m;
int m = 0x80;
int shift;
png_uint_32 i,istop;
png_uint_32 i;
png_uint_32 row_width = png_ptr->width;
int value;
sp = png_ptr->row_buf + 1;
dp = row;
m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
{
@@ -1585,8 +1574,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
shift = s_start;
istop = png_ptr->width;
for (i = 0; i < istop; i++)
for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1612,17 +1600,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
case 4:
{
png_bytep sp;
png_bytep dp;
png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp = row;
int s_start, s_end, s_inc;
int m;
int m = 0x80;
int shift;
png_uint_32 i,istop;
png_uint_32 i;
png_uint_32 row_width = png_ptr->width;
int value;
sp = png_ptr->row_buf + 1;
dp = row;
m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
{
@@ -1639,8 +1625,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
shift = s_start;
istop = png_ptr->width;
for (i = 0; i < istop; i++)
for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1666,19 +1651,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
}
default:
{
png_bytep sp;
png_bytep dp;
png_size_t pixel_bytes;
png_uint_32 i, istop;
png_byte m;
png_bytep sp = png_ptr->row_buf + 1;
png_bytep dp = row;
png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
png_uint_32 i;
png_uint_32 row_width = png_ptr->width;
png_byte m = 0x80;
pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
sp = png_ptr->row_buf + 1;
dp = row;
m = 0x80;
istop = png_ptr->width;
for (i = 0; i < istop; i++)
for (i = 0; i < row_width; i++)
{
if (m & mask)
{
@@ -1715,15 +1696,15 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{
case 1:
{
png_bytep sp, dp;
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
int sshift, dshift;
int s_start, s_end, s_inc;
int jstop = png_pass_inc[pass];
png_byte v;
png_uint_32 i;
int j, jstop;
int j;
sp = row + (png_size_t)((row_info->width - 1) >> 3);
dp = row + (png_size_t)((final_width - 1) >> 3);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
@@ -1743,7 +1724,6 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
s_inc = 1;
}
jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--)
{
v = (png_byte)((*sp >> sshift) & 0x1);
@@ -1771,14 +1751,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
case 2:
{
png_bytep sp, dp;
png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
int sshift, dshift;
int s_start, s_end, s_inc;
int jstop = png_pass_inc[pass];
png_uint_32 i;
int jstop;
sp = row + (png_uint_32)((row_info->width - 1) >> 2);
dp = row + (png_uint_32)((final_width - 1) >> 2);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
@@ -1798,7 +1777,6 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
s_inc = 2;
}
jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--)
{
png_byte v;
@@ -1829,14 +1807,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
case 4:
{
png_bytep sp, dp;
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
int sshift, dshift;
int s_start, s_end, s_inc;
png_uint_32 i;
int jstop;
int jstop = png_pass_inc[pass];
sp = row + (png_size_t)((row_info->width - 1) >> 1);
dp = row + (png_size_t)((final_width - 1) >> 1);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
@@ -1856,13 +1833,11 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
s_inc = 4;
}
jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--)
{
png_byte v;
png_byte v = (png_byte)((*sp >> sshift) & 0xf);
int j;
v = (png_byte)((*sp >> sshift) & 0xf);
for (j = 0; j < jstop; j++)
{
*dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
@@ -1887,16 +1862,12 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
}
default:
{
png_bytep sp, dp;
png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
int jstop = png_pass_inc[pass];
png_uint_32 i;
int jstop;
png_size_t pixel_bytes;
pixel_bytes = (row_info->pixel_depth >> 3);
sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
jstop = png_pass_inc[pass];
for (i = row_info->width; i; i--)
{
png_byte v[8];
@@ -1935,95 +1906,87 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
break;
case PNG_FILTER_VALUE_SUB:
{
png_uint_32 i, istop;
int bpp;
png_bytep rp;
png_bytep lp;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
png_bytep rp = row + bpp;
png_bytep lp = row;
bpp = (row_info->pixel_depth + 7) / 8;
istop = row_info->rowbytes;
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
i < istop; i++, rp++, lp++)
for (i = bpp; i < istop; i++)
{
*rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
*rp++ = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
}
break;
}
case PNG_FILTER_VALUE_UP:
{
png_uint_32 i, istop;
png_bytep rp;
png_bytep pp;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
png_bytep rp = row;
png_bytep pp = prev_row;
istop = row_info->rowbytes;
for (i = 0, rp = row, pp = prev_row; i < istop; i++, rp++, pp++)
for (i = 0; i < istop; i++)
{
*rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
*rp++ = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
}
break;
}
case PNG_FILTER_VALUE_AVG:
{
png_uint_32 i, istop;
int bpp;
png_bytep rp;
png_bytep pp;
png_bytep lp;
png_uint_32 i;
png_bytep rp = row;
png_bytep pp = prev_row;
png_bytep lp = row;
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
png_uint_32 istop = row_info->rowbytes;
bpp = (row_info->pixel_depth + 7) / 8;
istop = (png_uint_32)bpp;
for (i = 0, rp = row, pp = prev_row; i < istop; i++, rp++, pp++)
for (i = 0; i < bpp; i++)
{
*rp = (png_byte)(((int)(*rp) +
((int)(*pp) / 2)) & 0xff);
*rp++ = (png_byte)(((int)(*rp) +
((int)(*pp++) / 2)) & 0xff);
}
istop = row_info->rowbytes;
for (lp = row; i < istop; i++, rp++,
lp++, pp++)
for (lp = row; i < istop; i++)
{
*rp = (png_byte)(((int)(*rp) +
(int)(*pp + *lp) / 2) & 0xff);
*rp++ = (png_byte)(((int)(*rp) +
(int)(*pp++ + *lp++) / 2) & 0xff);
}
break;
}
case PNG_FILTER_VALUE_PAETH:
{
int bpp;
png_uint_32 i, istop;
png_bytep rp;
png_bytep pp;
png_bytep lp;
png_bytep cp;
png_uint_32 i;
png_bytep rp = row;
png_bytep pp = prev_row;
png_bytep lp = row;
png_bytep cp = prev_row;
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
png_uint_32 istop=row_info->rowbytes;
bpp = (row_info->pixel_depth + 7) / 8;
#ifndef PNG_SLOW_PAETH
istop=bpp;
for (i = 0, rp = row, pp = prev_row; i < istop;
i++, rp++, pp++)
for (i = 0; i < bpp; i++)
{
*rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
*rp++ = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
}
istop=row_info->rowbytes;
for (lp = row, cp = prev_row; i < istop; /* use leftover i,rp,pp */
i++, rp++, pp++, lp++, cp++)
for ( ; i < istop; i++) /* use leftover i,rp,pp */
{
int a, b, c, pa, pb, pc, p;
a = *lp;
b = *pp;
c = *cp;
a = *lp++;
b = *pp++;
c = *cp++;
p = b - c;
pc = a - c;
p = a + b - c;
#ifdef PNG_USE_ABS
pa = abs(p - a);
pb = abs(p - b);
pc = abs(p - c);
pa = abs(p);
pb = abs(pc);
pc = abs(p + pc);
#else
pa = p > a ? p - a : a - p;
pb = p > b ? p - b : b - p;
pc = p > c ? p - c : c - p;
pa = p < 0 ? -p : p;
pb = pc < 0 ? -pc : pc;
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
/*
@@ -2037,40 +2000,8 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
*rp = (png_byte)(((int)(*rp) + p) & 0xff);
*rp++ = (png_byte)(((int)(*rp) + p) & 0xff);
}
#else /* PNG_SLOW_PAETH */
for (i = 0, rp = row, pp = prev_row,
lp = row - bpp, cp = prev_row - bpp,
istop = row_info->rowbytes; i < istop; i++, rp++, pp++, lp++, cp++)
{
int a, b, c, pa, pb, pc, p;
b = *pp;
if (i >= (png_uint_32)bpp)
{
c = *cp;
a = *lp;
}
else
{
a = c = 0;
}
p = a + b - c;
pa = abs(p - a);
pb = abs(p - b);
pc = abs(p - c);
if (pa <= pb && pa <= pc)
p = a;
else if (pb <= pc)
p = b;
else
p = c;
*rp = (png_byte)(((int)(*rp) + p) & 0xff);
}
#endif /* PNG_SLOW_PAETH */
break;
}
default:
@@ -2094,11 +2025,10 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
case PNG_FILTER_VALUE_SUB:
{
png_uint_32 i;
int bpp;
int bpp = (row_info->pixel_depth + 7) / 8;
png_bytep rp;
png_bytep lp;
bpp = (row_info->pixel_depth + 7) / 8;
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
i < row_info->rowbytes; i++, rp++, lp++)
{
@@ -2122,12 +2052,11 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
case PNG_FILTER_VALUE_AVG:
{
png_uint_32 i;
int bpp;
int bpp = (row_info->pixel_depth + 7) / 8;
png_bytep rp;
png_bytep pp;
png_bytep lp;
bpp = (row_info->pixel_depth + 7) / 8;
for (i = 0, rp = row, pp = prev_row;
i < (png_uint_32)bpp; i++, rp++, pp++)
{
@@ -2143,14 +2072,13 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
}
case PNG_FILTER_VALUE_PAETH:
{
int bpp;
int bpp = (row_info->pixel_depth + 7) / 8;
png_uint_32 i;
png_bytep rp;
png_bytep pp;
png_bytep lp;
png_bytep cp;
bpp = (row_info->pixel_depth + 7) / 8;
for (i = 0, rp = row, pp = prev_row,
lp = row - bpp, cp = prev_row - bpp;
i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++)
@@ -2297,7 +2225,7 @@ void
png_read_start_row(png_structp png_ptr)
{
int max_pixel_depth;
png_uint_32 rowbytes;
png_uint_32 row_bytes;
png_debug(1, "in png_read_start_row\n");
png_ptr->zstream.avail_in = 0;
@@ -2315,10 +2243,10 @@ png_read_start_row(png_structp png_ptr)
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
rowbytes = ((png_ptr->iwidth *
row_bytes = ((png_ptr->iwidth *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
png_ptr->irowbytes = (png_size_t)rowbytes;
if((png_uint_32)png_ptr->irowbytes != rowbytes)
png_ptr->irowbytes = (png_size_t)row_bytes;
if((png_uint_32)png_ptr->irowbytes != row_bytes)
png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
}
else
@@ -2365,7 +2293,9 @@ png_read_start_row(png_structp png_ptr)
#if defined(PNG_READ_FILLER_SUPPORTED)
if (png_ptr->transformations & (PNG_FILLER))
{
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
max_pixel_depth = 32;
else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
{
if (max_pixel_depth <= 8)
max_pixel_depth = 16;
@@ -2405,16 +2335,16 @@ png_read_start_row(png_structp png_ptr)
/* align the width on the next larger 8 pixels. Mainly used
for interlacing */
rowbytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
/* calculate the maximum bytes needed, adding a byte and a pixel
for safety's sake */
rowbytes = ((rowbytes * (png_uint_32)max_pixel_depth + 7) >> 3) +
row_bytes = ((row_bytes * (png_uint_32)max_pixel_depth + 7) >> 3) +
1 + ((max_pixel_depth + 7) >> 3);
#ifdef PNG_MAX_MALLOC_64K
if (rowbytes > (png_uint_32)65536L)
if (row_bytes > (png_uint_32)65536L)
png_error(png_ptr, "This image requires a row greater than 64KB");
#endif
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, rowbytes);
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, row_bytes);
#ifdef PNG_MAX_MALLOC_64K
if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)

View File

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

View File

@@ -1,12 +1,12 @@
/* pngtest.c - a simple test program to test libpng
*
* libpng 1.0.1a
* libpng 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*
* This program reads in a PNG image, writes it out again, and then
* compares the two files. If the files are identical, this shows that

View File

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

View File

@@ -1,12 +1,12 @@
/* pngwio.c - functions for data output
*
* libpng 1.0.1a
* libpng 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*
* This file provides a location for all output. Users which need
* 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
*
* libpng 1.0.1a
* 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*/
/* get internal access to png.h */
@@ -281,7 +281,7 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
/* Initialize png_ptr structure, and allocate any memory needed */
png_structp
png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn)
{
png_structp png_ptr;
@@ -422,6 +422,36 @@ png_write_row(png_structp png_ptr, png_bytep row)
/* initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{
/* check for transforms that have been set but were defined out */
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_MONO)
png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
#endif
#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
if (png_ptr->transformations & PNG_FILLER)
png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
#endif
#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
#endif
#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
if (png_ptr->transformations & PNG_PACK)
png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
#endif
#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
if (png_ptr->transformations & PNG_SHIFT)
png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
#endif
#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
if (png_ptr->transformations & PNG_BGR)
png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
#endif
#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
#endif
png_write_start_row(png_ptr);
}

View File

@@ -1,12 +1,12 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 1.0.1a
* 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*/
#define PNG_INTERNAL
@@ -96,15 +96,15 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_bytep sp, dp;
int mask, v;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
mask = 0x80;
v = 0;
istop = row_info->width;
for (i = 0; i < istop; i++)
for (i = 0; i < row_width; i++)
{
if (*sp != 0)
v |= mask;
@@ -127,14 +127,14 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_bytep sp, dp;
int shift, v;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
shift = 6;
v = 0;
istop = row_info->width;
for (i = 0; i < istop; i++)
for (i = 0; i < row_width; i++)
{
png_byte value;
@@ -159,14 +159,14 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_bytep sp, dp;
int shift, v;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
shift = 4;
v = 0;
istop = row_info->width;
for (i = 0; i < istop; i++)
for (i = 0; i < row_width; i++)
{
png_byte value;
@@ -218,9 +218,8 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{
int shift_start[4], shift_dec[4];
png_uint_32 channels;
int channels = 0;
channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
{
shift_start[channels] = row_info->bit_depth - bit_depth->red;
@@ -249,9 +248,10 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
/* with low row depths, could only be grayscale, so one channel */
if (row_info->bit_depth < 8)
{
png_bytep bp;
png_uint_32 i, istop;
png_bytep bp = row;
png_uint_32 i;
png_byte mask;
png_uint_32 row_bytes = row_info->rowbytes;
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
mask = 0x55;
@@ -260,8 +260,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
else
mask = 0xff;
istop = row_info->rowbytes;
for (bp = row, i = 0; i < istop; i++, bp++)
for (i = 0; i < row_bytes; i++, bp++)
{
png_uint_16 v;
int j;
@@ -279,58 +278,51 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
}
else if (row_info->bit_depth == 8)
{
png_bytep bp;
png_uint_32 i, istop;
png_bytep bp = row;
png_uint_32 i;
png_uint_32 istop = channels * row_info->width;
istop = row_info->width;
for (bp = row, i = 0; i < istop; i++)
for (i = 0; i < istop; i++, bp++)
{
png_uint_32 c;
for (c = 0; c < channels; c++, bp++)
png_uint_16 v;
int j;
int c = (int)(i%channels);
v = *bp;
*bp = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
{
png_uint_16 v;
int j;
v = *bp;
*bp = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
{
if (j > 0)
*bp |= (png_byte)((v << j) & 0xff);
else
*bp |= (png_byte)((v >> (-j)) & 0xff);
}
if (j > 0)
*bp |= (png_byte)((v << j) & 0xff);
else
*bp |= (png_byte)((v >> (-j)) & 0xff);
}
}
}
else
{
png_bytep bp;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 istop = channels * row_info->width;
istop = row_info->width;
for (bp = row, i = 0; i < istop; i++)
{
png_uint_32 c;
int c = (int)(i%channels);
png_uint_16 value, v;
int j;
for (c = 0; c < channels; c++, bp += 2)
v = ((png_uint_16)(*bp) << 8) + *(bp + 1);
value = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
{
png_uint_16 value, v;
int j;
v = ((png_uint_16)(*bp) << 8) + *(bp + 1);
value = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
{
if (j > 0)
value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
else
value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
}
*bp = (png_byte)(value >> 8);
*(bp + 1) = (png_byte)(value & 0xff);
if (j > 0)
value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
else
value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
}
*bp++ = (png_byte)(value >> 8);
*bp++ = (png_byte)(value & 0xff);
}
}
}
@@ -352,10 +344,9 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i, istop;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save = *(sp++);
*(dp++) = *(sp++);
@@ -368,10 +359,10 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
else
{
png_bytep sp, dp;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save[2];
save[0] = *(sp++);
@@ -394,9 +385,9 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save = *(sp++);
*(dp++) = *(sp++);
@@ -408,9 +399,9 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save[2];
save[0] = *(sp++);
@@ -441,10 +432,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i, istop;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
@@ -456,10 +446,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
else
{
png_bytep sp, dp;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
@@ -478,10 +468,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
@@ -491,10 +481,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
else
{
png_bytep sp, dp;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
istop = row_info->width;
for (i = 0, sp = dp = row; i < istop; i++)
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);

View File

@@ -1,12 +1,12 @@
/* pngwutil.c - utilities to write a PNG file
*
* libpng 1.0.1a
* 1.0.1c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* April 21, 1998
* May 9, 1998
*/
#define PNG_INTERNAL
@@ -1251,13 +1251,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
int shift;
int d;
int value;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
dp = row;
d = 0;
shift = 7;
istop = row_info->width;
for (i = png_pass_start[pass]; i < istop;
for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 3);
@@ -1285,13 +1285,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
int shift;
int d;
int value;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
dp = row;
shift = 6;
d = 0;
istop = row_info->width;
for (i = png_pass_start[pass]; i < istop;
for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 2);
@@ -1318,13 +1318,13 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
int shift;
int d;
int value;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
dp = row;
shift = 4;
d = 0;
istop = row_info->width;
for (i = png_pass_start[pass]; i < istop;
for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 1);
@@ -1348,7 +1348,8 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
{
png_bytep sp;
png_bytep dp;
png_uint_32 i, istop;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
png_size_t pixel_bytes;
/* start at the beginning */
@@ -1357,8 +1358,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
pixel_bytes = (row_info->pixel_depth >> 3);
/* loop through the row, only looking at the pixels that
matter */
istop = row_info->width;
for (i = png_pass_start[pass]; i < istop;
for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass])
{
/* find out where the original pixel is */
@@ -1397,6 +1397,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_bytep prev_row, best_row, row_buf;
png_uint_32 mins, bpp;
png_byte filter_to_do = png_ptr->do_filter;
png_uint_32 row_bytes = row_info->rowbytes;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
int num_p_filters = (int)png_ptr->num_prev_filters;
#endif
png_debug(1, "in png_write_find_filter\n");
/* find out how many bytes offset each pixel is */
@@ -1427,11 +1431,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp;
png_uint_32 sum = 0;
png_uint_32 i,istop;
png_uint_32 i;
int v;
istop = row_info->rowbytes;
for (i = 0, rp = row_buf + 1; i < istop; i++, rp++)
for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
{
v = *rp;
sum += (v < 128) ? v : 256 - v;
@@ -1441,18 +1444,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
png_uint_32 sumhi, sumlo;
int j;
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
/* Reduce the sum if we match any of the previous rows */
istop = (png_uint_32)png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_NONE)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
{
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1480,14 +1483,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* it's the only filter so no testing is needed */
{
png_bytep rp, lp, dp;
png_uint_32 i,istop;
png_uint_32 i;
for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
i++, rp++, dp++)
{
*dp = *rp;
}
istop = row_info->rowbytes;
for (lp = row_buf + 1; i < istop;
for (lp = row_buf + 1; i < row_bytes;
i++, rp++, lp++, dp++)
{
*dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
@@ -1499,7 +1501,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, lp;
png_uint_32 sum = 0, lmins = mins;
png_uint_32 i, istop;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1509,18 +1511,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
*/
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 lmhi, lmlo;
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
{
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1558,18 +1560,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 sumhi, sumlo;
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
{
sumlo = (sumlo * png_ptr->inv_filter_weights[i]) >>
sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->inv_filter_weights[i]) >>
sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1597,11 +1599,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (filter_to_do == PNG_FILTER_UP)
{
png_bytep rp, dp, pp;
png_uint_32 i, istop;
png_uint_32 i;
istop = row_info->rowbytes;
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
pp = prev_row + 1; i < istop;
pp = prev_row + 1; i < row_bytes;
i++, rp++, pp++, dp++)
{
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
@@ -1613,25 +1614,25 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp;
png_uint_32 sum = 0, lmins = mins;
png_uint_32 i, istop;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 lmhi, lmlo;
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
{
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1648,12 +1649,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
}
#endif
istop = row_info->rowbytes;
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
pp = prev_row + 1; i < istop;
i++, rp++, pp++, dp++)
pp = prev_row + 1; i < row_bytes; i++)
{
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
sum += (v < 128) ? v : 256 - v;
@@ -1664,18 +1663,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 sumhi, sumlo;
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
{
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1703,16 +1702,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (filter_to_do == PNG_FILTER_AVG)
{
png_bytep rp, dp, pp, lp;
png_uint_32 i,istop;
png_uint_32 i;
for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
pp = prev_row + 1; i < bpp; i++)
{
*dp = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
*dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
}
istop = row_info->rowbytes;
for (lp = row_buf + 1; i < istop; i++, rp++, pp++, lp++, dp++)
for (lp = row_buf + 1; i < row_bytes; i++)
{
*dp = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
*dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
& 0xff);
}
best_row = png_ptr->avg_row;
}
@@ -1721,24 +1720,24 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, lp;
png_uint_32 sum = 0, lmins = mins;
png_uint_32 i,istop;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 lmhi, lmlo;
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = (png_uint_32)png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_AVG)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
{
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1756,16 +1755,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
pp = prev_row + 1; i < bpp; i++)
{
v = *dp = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
sum += (v < 128) ? v : 256 - v;
}
istop = row_info->rowbytes;
for (lp = row_buf + 1; i < istop; i++, rp++, pp++, lp++, dp++)
for (lp = row_buf + 1; i < row_bytes; i++)
{
v = *dp = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
v = *dp++ =
(png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
sum += (v < 128) ? v : 256 - v;
@@ -1776,18 +1775,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 sumhi, sumlo;
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_NONE)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
{
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1815,38 +1814,37 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (filter_to_do == PNG_FILTER_PAETH)
{
png_bytep rp, dp, pp, cp, lp;
png_uint_32 i, istop;
png_uint_32 i;
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
pp = prev_row + 1; i < bpp; i++)
{
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
*dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
}
istop = row_info->rowbytes;
for (lp = row_buf + 1, cp = prev_row + 1; i < istop;
i++, rp++, pp++, lp++, dp++, cp++)
for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
{
int a, b, c, pa, pb, pc, p;
b = *pp;
c = *cp;
a = *lp;
b = *pp++;
c = *cp++;
a = *lp++;
p = a + b - c;
p = b - c;
pc = a - c;
#ifdef PNG_USE_ABS
pa = abs(p - a);
pb = abs(p - b);
pc = abs(p - c);
pa = abs(p);
pb = abs(pc);
pc = abs(p + pc);
#else
pa = p > a ? p - a : a - p;
pb = p > b ? p - b : b - p;
pc = p > c ? p - c : c - p;
pa = p < 0 ? -p : p;
pb = pc < 0 ? -pc : pc;
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
*dp = (png_byte)(((int)*rp - p) & 0xff);
*dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
}
best_row = png_ptr->paeth_row;
}
@@ -1855,24 +1853,24 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, cp, lp;
png_uint_32 sum = 0, lmins = mins;
png_uint_32 i, istop;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 lmhi, lmlo;
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
istop = png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_PAETH)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
{
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1890,38 +1888,36 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
pp = prev_row + 1; i < bpp; i++)
{
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
sum += (v < 128) ? v : 256 - v;
}
istop = row_info->rowbytes;
for (lp = row_buf + 1, cp = prev_row + 1; i < istop;
i++, rp++, pp++, lp++, dp++, cp++)
for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
{
int a, b, c, pa, pb, pc, p;
b = *pp;
c = *cp;
a = *lp;
p = a + b - c;
b = *pp++;
c = *cp++;
a = *lp++;
#ifndef PNG_SLOW_PAETH
p = b - c;
pc = a - c;
#ifdef PNG_USE_ABS
pa = abs(p - a);
pb = abs(p - b);
pc = abs(p - c);
pa = abs(p);
pb = abs(pc);
pc = abs(p + pc);
#else
pa = p > a ? p - a : a - p;
pb = p > b ? p - b : b - p;
pc = p > c ? p - c : c - p;
pa = p < 0 ? -p : p;
pb = pc < 0 ? -pc : pc;
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
#else /* PNG_SLOW_PAETH */
p = a + b - c;
pa = abs(p - a);
pb = abs(p - b);
pc = abs(p - c);
@@ -1933,7 +1929,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
p = c;
#endif /* PNG_SLOW_PAETH */
v = *dp = (png_byte)(((int)*rp - p) & 0xff);
v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
sum += (v < 128) ? v : 256 - v;
@@ -1944,18 +1940,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
{
int j;
png_uint_32 sumhi, sumlo;
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
istop = png_ptr->num_prev_filters;
for (i = 0; i < istop; i++)
for (j = 0; j < num_p_filters; j++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_PAETH)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
{
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT;
}
}
@@ -1986,14 +1982,12 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* Save the type of filter we picked this time for future calculations */
if (png_ptr->num_prev_filters > 0)
{
int i, istop;
istop = (int)png_ptr->num_prev_filters;
for (i = 1; i < istop; i++)
int j;
for (j = 1; j < num_p_filters; j++)
{
png_ptr->prev_filters[i] = png_ptr->prev_filters[i - 1];
png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
}
png_ptr->prev_filters[i] = best_row[0];
png_ptr->prev_filters[j] = best_row[0];
}
#endif
}

View File

@@ -20,7 +20,7 @@ WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops \
$(ALIGN) #$(WARNMORE) -g -DPNG_DEBUG=5
$(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
RANLIB=ranlib
@@ -29,7 +29,7 @@ RANLIB=ranlib
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.1a
PNGMIN = 1.0.1c
PNGVER = $(PNGMAJ).$(PNGMIN)
# 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
# have to change it.
PNGMAJ = 2
PNGMIN = 1.0.1a
PNGMIN = 1.0.1c
PNGVER = $(PNGMAJ).$(PNGMIN)
# 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.1c
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
WARNMORE=-fullwarn
CFLAGS=-I$(ZLIBINC) -O # $(WARNMORE) -g -DPNG_DEBUG=5
CFLAGS=-I$(ZLIBINC) -O $(WARNMORE) # -g -DPNG_DEBUG=5
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
RANLIB=echo