Bug 669863. Update libpng to version 1.4.8. r=joe

This commit is contained in:
Glenn Randers-Pehrson 2011-07-29 14:30:00 -04:00
parent bcba3f61d1
commit a18535e97a
17 changed files with 210 additions and 132 deletions

View File

@ -2791,9 +2791,40 @@ version 1.4.6 [April 8, 2011]
version 1.4.7rc01 [April 9, 2011]
Relocated misplaced new declarations in pngwutil.c.
version 1.4.7 [April 10, 2011]
version 1.4.7 [April 9, 2011]
Disabled PNG_PEDANTIC_WARNINGS for all MSC versions as in libpng-1.4.5.
version 1.4.8beta01 [June 4, 2011]
Undef "_ALL_SOURCE" for AIX, to prevent "jmpbuf" from being redefined.
Copied png_debug macros from pngpriv.h into pngtest.c and removed
"#include pngpriv.h" from pngtest.c, to avoid setting a bad example.
Pass "" instead of '\0' to png_default_error() in png_err(). This mistake
was introduced in libpng-1.2.20beta01.
Check for up->location !PNG_AFTER_IDAT when writing unknown chunks
before IDAT.
Ported bugfix in pngrtran.c from 1.5.3: when expanding a paletted image,
always expand to RGBA if transparency is present.
version 1.4.8beta02 [June 5, 2011]
Ported bugfix in pngrtran.c from 1.5.3: Ensure coefficients are OK for
png_rgb_to_gray_fixed().
version 1.4.8beta03 [June 6, 2011]
Check for integer overflow in png_set_rgb_to_gray().
version 1.4.8beta04 [June 7, 2011]
Fixed uninitialized memory read in png_format_buffer() (Bug report by
Frank Busse, related to CVE-2004-0421).
version 1.4.8beta05 [June 19, 2011]
Fixed error in "ACCURATE" 16-to-8 scaling (John Bowler).
Check for sCAL chunk too short.
version 1.4.8rc01 [June 30, 2011]
No changes.
version 1.4.8 [July 7, 2011]
No changes.
Send comments/corrections/commendations to glennrp at users.sourceforge.net
or to png-mng-implement at lists.sf.net (subscription required; visit

View File

@ -10,7 +10,7 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.4.7, April 10, 2011, are
libpng versions 1.2.6, August 15, 2004, through 1.4.8, July 7, 2011, are
Copyright (c) 2004, 2006-2010 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors
@ -108,4 +108,4 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
April 10, 2011
July 7, 2011

View File

@ -1,6 +1,8 @@
Changes made to pristine png source by mozilla.org developers.
2011/07/20 -- Synced with libpng-1.4.8 (bug #669863).
2011/04/08 -- Synced with libpng-1.4.7 (bug #624133).
2010/06/30 -- Synced with libpng-1.4.3 (bug #564792).

View File

@ -1,4 +1,4 @@
README for libpng version 1.4.7 - April 10, 2011 (shared library 14.0)
README for libpng version 1.4.8 - July 7, 2011 (shared library 14.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
@ -114,19 +114,16 @@ given in previous versions of this document. He and Andreas will
read mail addressed to the png-implement list, however.
Please do not send general questions about PNG. Send them to
the (png-list at ccrc.wustl.edu, subscription required, write to
majordomo at ccrc.wustl.edu with "subscribe png-list" in your message).
On the other hand,
please do not send libpng questions to that address, send them to me
or to the png-implement list. I'll
get them in the end anyway. If you have a question about something
png-mng-misc at lists.sf.net (subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-misc to
subscribe). If you have a question about something
in the PNG specification that is related to using libpng, send it
to me. Send me any questions that start with "I was using libpng,
and ...". If in doubt, send questions to me. I'll bounce them
to others, if necessary.
Please do not send suggestions on how to change PNG. We have
been discussing PNG for nine years now, and it is official and
been discussing PNG for sixteen years now, and it is official and
finished. If you have suggestions for libpng, however, I'll
gladly listen. Even if your suggestion is not used immediately,
it may be used later.
@ -185,9 +182,9 @@ Files in this distribution:
makefile.std => Generic UNIX makefile (cc, creates static
libpng.a)
makefile.elf => Linux/ELF makefile symbol versioning,
(gcc, creates libpng14.so.14.1.4.7)
(gcc, creates libpng14.so.14.1.4.8)
makefile.linux => Linux/ELF makefile
(gcc, creates libpng14.so.14.1.4.7)
(gcc, creates libpng14.so.14.1.4.8)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
ansi2knr (Requires ansi2knr.c from
@ -209,12 +206,12 @@ Files in this distribution:
makefile.openbsd => OpenBSD makefile
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
makefile.sggcc => Silicon Graphics
(gcc, creates libpng14.so.14.1.4.7)
(gcc, creates libpng14.so.14.1.4.8)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile
(gcc, creates libpng14.so.14.1.4.7)
(gcc, creates libpng14.so.14.1.4.8)
makefile.so9 => Solaris 9 makefile
(gcc, creates libpng14.so.14.1.4.7)
(gcc, creates libpng14.so.14.1.4.8)
makefile.32sunu => Sun Ultra 32-bit makefile
makefile.64sunu => Sun Ultra 64-bit makefile
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc

View File

@ -1,9 +1,9 @@
libpng.txt - A description on how to use and modify libpng
libpng version 1.4.3 - June 26, 2010
libpng version 1.4.8 - July 7, 2011
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2009 Glenn Randers-Pehrson
Copyright (c) 1998-2010 Glenn Randers-Pehrson
This document is released under the libpng license.
For conditions of distribution and use, see the disclaimer
@ -11,9 +11,9 @@ libpng.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.4.3 - June 26, 2010
libpng versions 0.97, January 1998, through 1.4.8 - July 7, 2011
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2009 Glenn Randers-Pehrson
Copyright (c) 1998-2010 Glenn Randers-Pehrson
libpng 1.0 beta 6 version 0.96 May 28, 1997
Updated and distributed by Andreas Dilger
@ -278,7 +278,7 @@ Setting up callback code
You can set up a callback function to handle any unknown chunks in the
input stream. You must supply the function
read_chunk_callback(png_ptr ptr,
read_chunk_callback(png_structp png_ptr,
png_unknown_chunkp chunk);
{
/* The unknown chunk structure contains your
@ -324,8 +324,8 @@ called after each row has been read, which you can use to control
a progress meter or the like. It's demonstrated in pngtest.c.
You must supply a function
void read_row_callback(png_ptr ptr, png_uint_32 row,
int pass);
void read_row_callback(png_structp png_ptr,
png_uint_32 row, int pass);
{
/* put your code here */
}
@ -576,15 +576,17 @@ in until png_read_end() has read the chunk data following the image.
PNG_COLOR_MASK_COLOR
PNG_COLOR_MASK_ALPHA
interlace_type - (PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7)
compression_type - (must be PNG_COMPRESSION_TYPE_BASE
for PNG 1.0)
filter_method - (must be PNG_FILTER_TYPE_BASE
for PNG 1.0, and can also be
PNG_INTRAPIXEL_DIFFERENCING if
the PNG datastream is embedded in
a MNG-1.0 datastream)
compression_type - (must be PNG_COMPRESSION_TYPE_BASE
for PNG 1.0)
interlace_type - (PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7)
Any or all of interlace_type, compression_type, or
filter_method can be NULL if you are
@ -605,11 +607,11 @@ in until png_read_end() has read the chunk data following the image.
info_ptr);
color_type = png_get_color_type(png_ptr,
info_ptr);
filter_method = png_get_filter_type(png_ptr,
interlace_type = png_get_interlace_type(png_ptr,
info_ptr);
compression_type = png_get_compression_type(png_ptr,
info_ptr);
interlace_type = png_get_interlace_type(png_ptr,
filter_method = png_get_filter_type(png_ptr,
info_ptr);
channels = png_get_channels(png_ptr, info_ptr);
@ -658,14 +660,14 @@ pointer into the info_ptr is returned for any complex types.
png_get_iCCP(png_ptr, info_ptr, &name,
&compression_type, &profile, &proflen);
name - The profile name.
compression - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
name - The profile name.
compression_type - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
sig_bit - the number of significant bits for
@ -678,11 +680,11 @@ pointer into the info_ptr is returned for any complex types.
&num_trans, &trans_color);
trans_alpha - array of alpha (transparency)
entries for palette (PNG_INFO_tRNS)
num_trans - number of transparent entries
(PNG_INFO_tRNS)
trans_color - graylevel or color sample values of
the single transparent color for
non-paletted images (PNG_INFO_tRNS)
num_trans - number of transparent entries
(PNG_INFO_tRNS)
png_get_hIST(png_ptr, info_ptr, &hist);
(PNG_INFO_hIST)
@ -903,7 +905,7 @@ things.
As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
added. It expands the sample depth without changing tRNS to alpha.
As of libpng version 1.4.3, not all possible expansions are supported.
As of libpng version 1.4.8, not all possible expansions are supported.
In the following table, the 01 means grayscale with depth<8, 31 means
indexed with depth<8, other numerals represent the color type, "T" means
@ -1233,8 +1235,8 @@ with
You must supply the function
void read_transform_fn(png_ptr ptr, row_info_ptr
row_info, png_bytep data)
void read_transform_fn(png_structp png_ptr, png_row_infop
row_info, png_bytep data)
See pngtest.c for a working example. Your function will be called
after all of the other transformations have been processed.
@ -1757,7 +1759,7 @@ called after each row has been written, which you can use to control
a progress meter or the like. It's demonstrated in pngtest.c.
You must supply a function
void write_row_callback(png_ptr, png_uint_32 row,
void write_row_callback(png_structp png_ptr, png_uint_32 row,
int pass);
{
/* put your code here */
@ -1932,14 +1934,14 @@ width, height, bit_depth, and color_type must be the same in each call.
png_set_iCCP(png_ptr, info_ptr, name, compression_type,
profile, proflen);
name - The profile name.
compression - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
name - The profile name.
compression_type - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
png_set_sBIT(png_ptr, info_ptr, sig_bit);
sig_bit - the number of significant bits for
@ -2314,7 +2316,7 @@ with
You must supply the function
void write_transform_fn(png_ptr ptr, row_info_ptr
void write_transform_fn(png_structp png_ptr, png_row_infop
row_info, png_bytep data)
See pngtest.c for a working example. Your function will be called
@ -3122,6 +3124,12 @@ deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
png_set_expand_gray_1_2_4_to_8() because the former function also
expanded palette images.
Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
were added and are used by default instead of the corresponding
functions. Unfortunately,
from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
function) incorrectly returned a value of type png_uint_32.
We changed the prototype for png_malloc() from
png_malloc(png_structp png_ptr, png_uint_32 size)
to
@ -3149,7 +3157,8 @@ The png_zalloc() function no longer zeroes out the memory that it
allocates.
Support for dithering was disabled by default in libpng-1.4.0, because
been well tested and doesn't actually "dither". The code was not
it has not been well tested and doesn't actually "dither".
The code was not
removed, however, and could be enabled by building libpng with
PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
was reenabled, but the function was renamed png_set_quantize() to
@ -3272,9 +3281,10 @@ above the comment that says
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
The names of all exported functions and variables begin
with "png_", and all publicly visible C preprocessor
macros begin with "PNG_".
To avoid polluting the global namespace, the names of all exported
functions and variables begin with "png_", and all publicly visible C
preprocessor macros begin with "PNG_". We request that applications that
use libpng *not* begin any of their own symbols with either of these strings.
We put a space after each comma and after each semicolon
in "for" statments, and we put spaces before and after each
@ -3297,13 +3307,13 @@ Other rules can be inferred by inspecting the libpng source.
XIII. Y2K Compliance in libpng
June 26, 2010
July 7, 2011
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.4.3 are Y2K compliant. It is my belief that earlier
upward through 1.4.8 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer that

View File

@ -17,7 +17,7 @@
#include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_4_7 Your_png_h_is_not_version_1_4_7;
typedef version_1_4_8 Your_png_h_is_not_version_1_4_8;
/* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another
@ -547,13 +547,13 @@ png_get_copyright(png_const_structp png_ptr)
#else
#ifdef __STDC__
return ((png_charp) PNG_STRING_NEWLINE \
"libpng version 1.4.7 - April 10, 2011" PNG_STRING_NEWLINE \
"libpng version 1.4.8 - July 7, 2011" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE);
#else
return ((png_charp) "libpng version 1.4.7 - April 10, 2011\
return ((png_charp) "libpng version 1.4.8 - July 7, 2011\
Copyright (c) 1998-2010 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.");

View File

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.4.7 - April 10, 2011
* libpng version 1.4.8 - July 7, 2011
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -11,7 +11,7 @@
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.4.7 - April 10, 2011: Glenn
* libpng versions 0.97, January 1998, through 1.4.8 - July 7, 2011: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@ -158,6 +158,9 @@
* 1.4.6 14 10406 14.so.14.6[.0]
* 1.4.7rc01 14 10407 14.so.14.7[.0]
* 1.4.7 14 10407 14.so.14.7[.0]
* 1.4.8beta01-05 14 10408 14.so.14.8[.0]
* 1.4.8rc01 14 10408 14.so.14.8[.0]
* 1.4.8 14 10408 14.so.14.8[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@ -189,7 +192,7 @@
*
* This code is released under the libpng license.
*
* libpng versions 1.2.6, August 15, 2004, through 1.4.7, April 10, 2011, are
* libpng versions 1.2.6, August 15, 2004, through 1.4.8, July 7, 2011, are
* Copyright (c) 2004, 2006-2010 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors:
@ -301,13 +304,13 @@
* Y2K compliance in libpng:
* =========================
*
* April 10, 2011
* July 7, 2011
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.4.7 are Y2K compliant. It is my belief that earlier
* upward through 1.4.8 are Y2K compliant. It is my belief that earlier
* versions were also Y2K compliant.
*
* Libpng only has three year fields. One is a 2-byte unsigned integer
@ -363,9 +366,9 @@
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.4.7"
#define PNG_LIBPNG_VER_STRING "1.4.8"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.4.7 - April 10, 2011\n"
" libpng version 1.4.8 - July 7, 2011\n"
#define PNG_LIBPNG_VER_SONUM 14
#define PNG_LIBPNG_VER_DLLNUM 14
@ -373,7 +376,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 4
#define PNG_LIBPNG_VER_RELEASE 7
#define PNG_LIBPNG_VER_RELEASE 8
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
*/
@ -403,7 +406,7 @@
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
*/
#define PNG_LIBPNG_VER 10407 /* 1.4.7 */
#define PNG_LIBPNG_VER 10408 /* 1.4.8 */
#ifndef PNG_VERSION_INFO_ONLY
/* Include the compression library's header */
@ -1545,7 +1548,7 @@ struct png_struct_def
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
typedef png_structp version_1_4_7;
typedef png_structp version_1_4_8;
typedef png_struct FAR * FAR * png_structpp;

View File

@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.4.7 - April 10, 2011
* libpng version 1.4.8 - July 7, 2011
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@ -1,7 +1,7 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* Last changed in libpng 1.4.6 [March 8, 2011]
* Last changed in libpng 1.4.8 [July 7, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -87,12 +87,17 @@ png_error(png_structp png_ptr, png_const_charp error_message)
void PNGAPI
png_err(png_structp png_ptr)
{
/* Prior to 1.4.8 the error_fn received a NULL pointer, expressed
* erroneously as '\0', instead of the empty string "". This was
* apparently an error, introduced in libpng-1.2.20, and png_default_error
* will crash in this case.
*/
if (png_ptr != NULL && png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_ptr, '\0');
(*(png_ptr->error_fn))(png_ptr, "");
/* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */
png_default_error(png_ptr, '\0');
png_default_error(png_ptr, "");
}
#endif /* PNG_ERROR_TEXT_SUPPORTED */
@ -181,8 +186,13 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
{
buffer[iout++] = ':';
buffer[iout++] = ' ';
png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);
buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';
iin = 0;
while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0')
buffer[iout++] = error_message[iin++];
/* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */
buffer[iout] = '\0';
}
}

View File

@ -1,7 +1,7 @@
/* pngget.c - retrieval of values from info struct
*
* Last changed in libpng 1.4.6 [April 10, 2011]
* Last changed in libpng 1.4.6 [April 8, 2010]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)

View File

@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation
*
* Last changed in libpng 1.4.6 [April 10, 2011]
* Last changed in libpng 1.4.6 [April 8, 2010]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)

View File

@ -1,7 +1,7 @@
/* pngpriv.h - private declarations for use inside libpng
*
* libpng version 1.4.7 - April 10, 2011
* libpng version 1.4.8 - July 7, 2011
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@ -26,6 +26,15 @@
#ifndef PNG_VERSION_INFO_ONLY
#if defined(_AIX) && defined(_ALL_SOURCE)
/* On AIX if _ALL_SOURCE is defined standard header files (including
* stdlib.h) define identifiers that are not permitted by the ANSI and
* POSIX standards. In particular 'jmpbuf' is #defined and this will
* prevent compilation of libpng. The following prevents this:
*/
# undef _ALL_SOURCE
#endif
#include <stdlib.h>
#ifndef PNG_EXTERN

View File

@ -1,7 +1,7 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* Last changed in libpng 1.4.6 [%RDATE%]
* Last changed in libpng 1.4.8 [July 7, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -660,10 +660,21 @@ void PNGAPI
png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
double green)
{
int red_fixed = (int)((float)red*100000.0 + 0.5);
int green_fixed = (int)((float)green*100000.0 + 0.5);
int red_fixed, green_fixed;
if (png_ptr == NULL)
return;
if (red > 21474.83647 || red < -21474.83648 ||
green > 21474.83647 || green < -21474.83648)
{
png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
red_fixed = -1;
green_fixed = -1;
}
else
{
red_fixed = (int)((float)red*100000.0 + 0.5);
green_fixed = (int)((float)green*100000.0 + 0.5);
}
png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
}
#endif
@ -703,27 +714,38 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
}
#endif
{
png_uint_16 red_int, green_int;
if (red < 0 || green < 0)
{
red_int = 6968; /* .212671 * 32768 + .5 */
green_int = 23434; /* .715160 * 32768 + .5 */
}
else if (red + green < 100000L)
if (red >= 0 && green >= 0 && red + green <= 100000L)
{
png_uint_16 red_int, green_int;
red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
png_ptr->rgb_to_gray_red_coeff = red_int;
png_ptr->rgb_to_gray_green_coeff = green_int;
png_ptr->rgb_to_gray_blue_coeff =
(png_uint_16)(32768 - red_int - green_int);
}
else
{
png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
red_int = 6968;
green_int = 23434;
if (red >= 0 && green >= 0)
png_warning(png_ptr,
"ignoring out of range rgb_to_gray coefficients");
/* Use the defaults, from the cHRM chunk if set, else the built in Rec
* 709 values (which correspond to sRGB, so we don't have to worry
* about the sRGB chunk!)
*/
if (png_ptr->rgb_to_gray_red_coeff == 0 &&
png_ptr->rgb_to_gray_green_coeff == 0 &&
png_ptr->rgb_to_gray_blue_coeff == 0)
{
png_ptr->rgb_to_gray_red_coeff = 6968; /* .212671 * 32768 + .5 */
png_ptr->rgb_to_gray_green_coeff = 23434; /* .715160 * 32768 + .5 */
png_ptr->rgb_to_gray_blue_coeff = 2366;
}
}
png_ptr->rgb_to_gray_red_coeff = red_int;
png_ptr->rgb_to_gray_green_coeff = green_int;
png_ptr->rgb_to_gray_blue_coeff =
(png_uint_16)(32768 - red_int - green_int);
}
}
#endif
@ -1181,8 +1203,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (png_ptr->num_trans &&
(png_ptr->transformations & PNG_EXPAND_tRNS))
if (png_ptr->num_trans)
info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else
info_ptr->color_type = PNG_COLOR_TYPE_RGB;
@ -1778,32 +1799,18 @@ png_do_chop(png_row_infop row_info, png_bytep row)
for (i = 0; i<istop; i++, sp += 2, dp++)
{
#ifdef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
/* This does a more accurate scaling of the 16-bit color
* value, rather than a simple low-byte truncation.
*
* What the ideal calculation should be:
* *dp = (((((png_uint_32)(*sp) << 8) |
* (png_uint_32)(*(sp + 1))) * 255 + 127)
* / (png_uint_32)65535L;
*
* GRR: no, I think this is what it really should be:
* *dp = (((((png_uint_32)(*sp) << 8) |
* (png_uint_32)(*(sp + 1))) + 128L)
* / (png_uint_32)257L;
*
* GRR: here's the exact calculation with shifts:
* temp = (((png_uint_32)(*sp) << 8) |
* (png_uint_32)(*(sp + 1))) + 128L;
* *dp = (temp - (temp >> 8)) >> 8;
*
* Approximate calculation with shift/add instead of multiply/divide:
* *dp = ((((png_uint_32)(*sp) << 8) |
* (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8;
*
* What we actually do to avoid extra shifting and conversion:
*/
*dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
/* This does a more accurate scaling of the 16-bit color
* value, rather than a simple low-byte truncation.
*
* Prior to libpng-1.4.8 and 1.5.4, the calculation here was
* incorrect, so if you used ACCURATE_SCALE you will now see
* a slightly different result. In libpng-1.5.4 and
* later you will need to use the new png_set_scale_16_to_8()
* API to obtain accurate 16-to-8 scaling.
*/
png_int_32 tmp = *sp; /* must be signed! */
tmp += (((int)sp[1] - tmp + 128) * 65535) >> 24;
*dp = (png_byte)tmp;
#else
/* Simply discard the low order byte */
*dp = *sp;

View File

@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file
*
* Last changed in libpng 1.4.6 [March 8, 2011]
* Last changed in libpng 1.4.8 [July 7, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -1866,6 +1866,14 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return;
}
/* Need unit type, width, \0, height: minimum 4 bytes */
else if (length < 4)
{
png_warning(png_ptr, "sCAL chunk too short");
png_crc_finish(png_ptr, length);
return;
}
png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)",
(unsigned long)(length + 1));
png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);

View File

@ -1,7 +1,7 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* Last changed in libpng 1.4.6 [April 10, 2011]
* Last changed in libpng 1.4.6 [ April 8, 2010]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)

View File

@ -1,7 +1,7 @@
/* pngwrite.c - general routines to write a PNG file
*
* Last changed in libpng 1.4.6 [March 8, 2011]
* Last changed in libpng 1.4.8 [July 7, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -299,6 +299,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
if (keep != PNG_HANDLE_CHUNK_NEVER &&
up->location && (up->location & PNG_HAVE_PLTE) &&
!(up->location & PNG_HAVE_IDAT) &&
!(up->location & PNG_AFTER_IDAT) &&
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
@ -1419,7 +1420,7 @@ png_write_png(png_structp png_ptr, png_infop info_ptr,
#endif
#ifdef PNG_WRITE_FILLER_SUPPORTED
/* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */
/* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */
if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)

View File

@ -1,8 +1,8 @@
/* pngwutil.c - utilities to write a PNG file
*
* Last changed in libpng 1.4.1 [February 25, 2010]
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
* Last changed in libpng 1.4.8 [July 7, 2011]
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -695,7 +695,7 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
/* Compute the maximum possible length of the datastream */
/* Number of pixels, plus for each row a filter byte and possible
/* Number of pixels, plus for each row a filter byte
* and possibly a padding byte, so increase the maximum
* size to account for these.
*/