Bug 952505 - Update bundled libpng to version 1.6.9. r=jmuizelaar

This commit is contained in:
Glenn Randers-Pehrson 2014-02-25 08:40:53 -05:00
Родитель 9d5a6c1114
Коммит 3370e71bfa
28 изменённых файлов: 1043 добавлений и 949 удалений

Просмотреть файл

@ -51,7 +51,7 @@ _SUBDIR_CONFIG_ARGS="$ac_configure_args"
dnl Set the version number of the libs included with mozilla
dnl ========================================================
MOZJPEG=62
MOZPNG=10607
MOZPNG=10609
NSPR_VERSION=4
NSS_VERSION=3

Просмотреть файл

@ -4712,6 +4712,93 @@ Version 1.6.7rc02 [November 7, 2013]
checking macros take an unsigned char argument, not a signed char.
Version 1.6.7 [November 14, 2013]
No changes.
Version 1.6.8beta01 [November 24, 2013]
Moved prototype for png_handle_unknown() in pngpriv.h outside of
the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block.
Added "-Wall" to CFLAGS in contrib/pngminim/*/makefile
Conditionally compile some unused functions reported by -Wall in
pngminim.
Fixed 'minimal' builds. Various obviously useful minimal configurations
don't build because of missing contrib/libtests test programs and
overly complex dependencies in scripts/pnglibconf.dfa. This change
adds contrib/conftest/*.dfa files that can be used in automatic build
scripts to ensure that these configurations continue to build.
Enabled WRITE_INVERT and WRITE_PACK in contrib/pngminim/encoder.
Fixed pngvalid 'fail' function declaration on the Intel C Compiler.
This reverts to the previous 'static' implementation and works round
the 'unused static function' warning by using PNG_UNUSED().
Version 1.6.8beta02 [November 30, 2013]
Removed or marked PNG_UNUSED some harmless "dead assignments" reported
by clang scan-build.
Changed tabs to 3 spaces in png_debug macros and changed '"%s"m'
to '"%s" m' to improve portability among compilers.
Changed png_free_default() to free() in pngtest.c
Version 1.6.8rc01 [December 12, 2013]
Tidied up pngfix inits and fixed pngtest no-write builds.
Version 1.6.8rc02 [December 14, 2013]
Handle zero-length PLTE chunk or NULL palette with png_error()
instead of png_chunk_report(), which by default issues a warning
rather than an error, leading to later reading from a NULL pointer
(png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954
and VU#650142. Libpng-1.6.1 through 1.6.7 are vulnerable.
Libpng-1.6.0 and earlier do not have this bug.
Version 1.6.8 [December 19, 2013]
No changes.
Version 1.6.9beta01 [December 26, 2013]
Bookkeeping: Moved functions around (no changes). Moved transform
function definitions before the place where they are called so that
they can be masde static. Move the intrapixel functions and the
grayscale palette builder out of the png?tran.c files. The latter
isn't a transform function and is no longer used internally, and the
former MNG specific functions are better placed in pngread/pngwrite.c
Made transform implementation functions static. This makes the internal
functions called by png_do_{read|write}_transformations static. On an
x86-64 DLL build (Gentoo Linux) this reduces the size of the text
segment of the DLL by 1208 bytes, about 0.6%. It also simplifies
maintenance by removing the declarations from pngpriv.h and allowing
easier changes to the internal interfaces.
Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69
in the tar distributions.
Version 1.6.9beta02 [January 1, 2014]
Added checks for libpng 1.5 to pngvalid.c. This supports the use of
this version of pngvalid in libpng 1.5
Merged with pngvalid.c from libpng-1.7 changes to create a single
pngvalid.c
Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner).
Merged pngrio.c, pngtrans.c, pngwio.c, and pngerror.c with libpng-1.7.0
Merged libpng-1.7.0 changes to make no-interlace configurations work
with test programs.
Revised pngvalid.c to support libpng 1.5, which does not support the
PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when appropriate in
pngvalid.c
Allow unversioned links created on install to be disabled in configure.
In configure builds 'make install' changes/adds links like png.h
and libpng.a to point to the newly installed, versioned, files (e.g.
libpng17/png.h and libpng17.a). Three new configure options and some
rearrangement of Makefile.am allow creation of these links to be disabled.
Version 1.6.9beta03 [January 10, 2014]
Removed potentially misleading warning from png_check_IHDR().
Version 1.6.9beta04 [January 20, 2014]
Updated scripts/makefile.* to use CPPFLAGS (Cosmin).
Added clang attribute support (Cosmin).
Version 1.6.9rc01 [January 28, 2014]
No changes.
Version 1.6.9rc02 [January 30, 2014]
Quiet an uninitialized memory warning from VC2013 in png_get_png().
Version 1.6.9 [February 6, 2014]
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

Просмотреть файл

@ -10,8 +10,8 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.6.7, November 14, 2013, are
Copyright (c) 2004, 2006-2013 Glenn Randers-Pehrson, and are
libpng versions 1.2.6, August 15, 2004, through 1.6.9, February 6, 2014, are
Copyright (c) 2004, 2006-2014 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
November 14, 2013
February 6, 2014

Просмотреть файл

@ -1,6 +1,16 @@
Changes made to pristine png source by mozilla.org developers.
2014/02/18 -- Exposed png_error(), etc. redefinitions to applications
(moved them from pngpriv.h to png.h).
2014/02/18 -- Disabled PNG_FIXED_POINT_SUPPORTED in mozpngconf.h (we
don't need both FIXED and FLOATING_POINT support).
2014/02/15 -- Synced with libpng-1.6.9 (bug #952505).
2014/02/11 -- Fixed crash with empty PLTE, CVE-2013-6954 (bug #945912)
2013/12/11 -- Enable ARM support (bug #832390).
2013/11/17 -- Synced with libpng-1.6.7 (bug #938740).

Просмотреть файл

@ -1,4 +1,4 @@
README for libpng version 1.6.7 - November 14, 2013 (shared library 16.0)
README for libpng version 1.6.9 - February 6, 2014 (shared library 16.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
@ -121,7 +121,7 @@ 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 eighteen years now, and it is official and
been discussing PNG for nineteen 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.

Просмотреть файл

@ -278,7 +278,7 @@ Index: png.h
===================================================================
--- png.h
+++ png.h
@@ -448,6 +448,10 @@
@@ -454,6 +454,10 @@
# include "pnglibconf.h"
#endif
@ -289,7 +289,7 @@ Index: png.h
#ifndef PNG_VERSION_INFO_ONLY
/* Machine specific configuration. */
# include "pngconf.h"
@@ -538,6 +542,17 @@
@@ -544,6 +548,17 @@
* See pngconf.h for base types that vary by machine/system
*/
@ -307,7 +307,7 @@ Index: png.h
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
@@ -858,6 +873,10 @@
@@ -864,6 +879,10 @@
#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
#define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */
@ -318,7 +318,7 @@ Index: png.h
/* This is used for the transformation routines, as some of them
* change these values for the row. It also should enable using
@@ -895,6 +914,10 @@
@@ -901,6 +920,10 @@
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));
typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));
@ -329,7 +329,7 @@ Index: png.h
/* The following callback receives png_uint_32 row_number, int pass for the
* png_bytep data of the row. When transforming an interlaced image the
@@ -3298,6 +3321,75 @@
@@ -3304,6 +3327,75 @@
* END OF HARDWARE OPTIONS
******************************************************************************/
@ -405,7 +405,7 @@ Index: png.h
/* Maintainer: Put new public prototypes here ^, in libpng.3, and project
* defs, scripts/pnglibconf.h, and scripts/pnglibconf.h.prebuilt
*/
@@ -3307,7 +3399,11 @@
@@ -3313,7 +3405,11 @@
* scripts/symbols.def as well.
*/
#ifdef PNG_EXPORT_LAST_ORDINAL
@ -421,7 +421,7 @@ Index: pngpriv.h
===================================================================
--- pngpriv.h
+++ pngpriv.h
@@ -544,6 +544,10 @@
@@ -550,6 +550,10 @@
#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
/* 0x4000 (unused) */
#define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */
@ -432,7 +432,7 @@ Index: pngpriv.h
/* Flags for the transformations the PNG library does on the image data */
#define PNG_BGR 0x0001
@@ -765,6 +769,16 @@
@@ -771,6 +775,16 @@
#define png_tRNS PNG_U32(116, 82, 78, 83)
#define png_zTXt PNG_U32(122, 84, 88, 116)
@ -449,9 +449,9 @@ Index: pngpriv.h
/* The following will work on (signed char*) strings, whereas the get_uint_32
* macro will fail on top-bit-set values because of the sign extension.
*/
@@ -1559,6 +1573,49 @@
png_bytep row),PNG_EMPTY);
#endif
@@ -1451,6 +1465,49 @@
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+#ifdef PNG_APNG_SUPPORTED
+PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr,
@ -581,7 +581,7 @@ Index: pngwrite.c
#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
if (png_ptr->num_palette_max > png_ptr->num_palette)
png_benign_error(png_ptr, "Wrote palette index exceeding num_palette");
@@ -2327,4 +2336,42 @@
@@ -2397,4 +2406,42 @@
}
#endif /* PNG_STDIO_SUPPORTED */
#endif /* SIMPLIFIED_WRITE */
@ -750,8 +750,8 @@ Index: pngpread.c
png_push_have_info(png_ptr, info_ptr);
@@ -530,6 +636,30 @@
}
#endif
+#ifdef PNG_READ_APNG_SUPPORTED
+ else if (chunk_name == png_acTL)
+ {
@ -1059,7 +1059,7 @@ Index: pngrutil.c
===================================================================
--- pngrutil.c
+++ pngrutil.c
@@ -821,6 +821,11 @@
@@ -826,6 +826,11 @@
filter_type = buf[11];
interlace_type = buf[12];
@ -1071,7 +1071,7 @@ Index: pngrutil.c
/* Set internal variables */
png_ptr->width = width;
png_ptr->height = height;
@@ -2695,6 +2700,179 @@
@@ -2700,6 +2705,179 @@
}
#endif
@ -1251,7 +1251,7 @@ Index: pngrutil.c
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
static int
@@ -3953,6 +4131,38 @@
@@ -3957,6 +4135,38 @@
uInt avail_in;
png_bytep buffer;
@ -1290,7 +1290,7 @@ Index: pngrutil.c
while (png_ptr->idat_size == 0)
{
png_crc_finish(png_ptr, 0);
@@ -3964,6 +4174,7 @@
@@ -3968,6 +4178,7 @@
if (png_ptr->chunk_name != png_IDAT)
png_error(png_ptr, "Not enough image data");
}
@ -1298,7 +1298,7 @@ Index: pngrutil.c
avail_in = png_ptr->IDAT_read_size;
@@ -4027,6 +4238,9 @@
@@ -4031,6 +4242,9 @@
png_ptr->mode |= PNG_AFTER_IDAT;
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
@ -1308,7 +1308,7 @@ Index: pngrutil.c
if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
png_chunk_benign_error(png_ptr, "Extra compressed data");
@@ -4472,4 +4686,80 @@
@@ -4476,4 +4690,80 @@
png_ptr->flags |= PNG_FLAG_ROW_INIT;
}

Просмотреть файл

@ -90,7 +90,7 @@ safe_read(png_structp png_ptr, int fd, void *buffer_in, size_t nbytes)
if (errno != EINTR)
{
png_warning(png_ptr, "/proc read failed");
return 0; /* I.e. a permanent failure */
return 0; /* I.e., a permanent failure */
}
}

Просмотреть файл

@ -3,7 +3,7 @@
*
* Copyright (c) 2013 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011.
* Last changed in libpng 1.6.7 [November 14, 2013]
* Last changed in libpng 1.6.8 [December 19, 2013]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -17,7 +17,8 @@
#define MOZ_PNG_HAVE_ARM_NEON
/* This is required to get the symbol renames, which are #defines, and also
* includes the definition (or not) of PNG_ARM_NEON_OPT.
* includes the definition (or not) of PNG_ARM_NEON_OPT and
* PNG_ARM_NEON_IMPLEMENTATION.
*/
#define PNG_VERSION_INFO_ONLY
#include "../pngpriv.h"

Просмотреть файл

@ -5,7 +5,7 @@
* Written by James Yu <james.yu at linaro.org>, October 2013.
* Based on filter_neon.S, written by Mans Rullgard, 2011.
*
* Last changed in libpng 1.6.7 [November 14, 2013]
* Last changed in libpng 1.6.8 [December 19, 2013]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -15,13 +15,13 @@
#include "../pngpriv.h"
/* This code requires -mfpu=neon on the command line: */
#if PNG_ARM_NEON_IMPLEMENTATION == 1 /* intrinsics code */
#if PNG_ARM_NEON_IMPLEMENTATION == 1 /* intrinsics code from pngpriv.h */
#include <arm_neon.h>
/* libpng row pointers are not necessarily aligned to any particular boundary,
* however this code will only work with appropriate alignment. arm/arm_init.c
* checks for this (and will not compile unless it is done), this code uses
* checks for this (and will not compile unless it is done). This code uses
* variants of png_aligncast to avoid compiler warnings.
*/
#define png_ptr(type,pointer) png_aligncast(type *,pointer)

Просмотреть файл

@ -1,9 +1,9 @@
libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.6.7 - November 14, 2013
libpng version 1.6.9 - February 6, 2014
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2013 Glenn Randers-Pehrson
Copyright (c) 1998-2014 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-manual.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.6.7 - November 14, 2013
libpng versions 0.97, January 1998, through 1.6.9 - February 6, 2014
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2013 Glenn Randers-Pehrson
Copyright (c) 1998-2014 Glenn Randers-Pehrson
libpng 1.0 beta 6 version 0.96 May 28, 1997
Updated and distributed by Andreas Dilger
@ -4393,6 +4393,9 @@ png_set_error_fn(), which is essentially the same function, but with a new
name to force compilation errors with applications that try to use the old
method.
Support for the sCAL, iCCP, iTXt, and sPLT chunks was added at libpng-1.0.6;
however, iTXt support was not enabled by default.
Starting with version 1.0.7, you can find out which version of the library
you are using at run-time:
@ -4621,12 +4624,13 @@ XI. Changes to Libpng from version 1.4.x to 1.5.x
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.
The incorrect macro was removed from libpng-1.4.5.
Checking for invalid palette index on read or write was added at libpng
1.5.10. When an invalid index is found, libpng issues a benign error.
This is enabled by default because this condition is an error according
to the PNG specification, Clause 11.3.2, but the error can be ignored in
each png_ptr with
Checking for invalid palette index on write was added at libpng
1.5.10. If a pixel contains an invalid (out-of-range) index libpng issues
a benign error. This is enabled by default because this condition is an
error according to the PNG specification, Clause 11.3.2, but the error can
be ignored in each png_ptr with
png_set_check_for_invalid_index(png_ptr, allowed);
@ -4725,7 +4729,10 @@ and the accuracy of PNG fixed point values is insufficient for
representation of these values. Consequently a "string" API
(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
arbitrary sCAL chunks in the absence of either the floating point API or
internal floating point calculations.
internal floating point calculations. Starting with libpng-1.5.0, both
of these functions are present when PNG_sCAL_SUPPORTED is defined. Prior
to libpng-1.5.0, their presence also depended upon PNG_FIXED_POINT_SUPPORTED
being defined and PNG_FLOATING_POINT_SUPPORTED not being defined.
Applications no longer need to include the optional distribution header
file pngusr.h or define the corresponding macros during application
@ -4745,11 +4752,6 @@ reset by pngusr.h or by explicit settings on the compiler command line.
These settings may produce compiler warnings or errors in 1.5.0 because
of macro redefinition.
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. libpng 1.5.0
is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
did not exist.)
Applications can now choose whether to use these macros or to call the
corresponding function by defining PNG_USE_READ_MACROS or
PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
@ -4767,7 +4769,10 @@ option was off by default, and slightly inaccurate scaling occurred.
This option can no longer be turned off, and the choice of accurate
or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
API for accurate scaling or the old png_set_strip_16_to_8() API for simple
chopping.
chopping. In libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
macro became PNG_READ_SCALE_16_TO_8_SUPPORTED, and the PNG_READ_16_TO_8
macro became PNG_READ_STRIP_16_TO_8_SUPPORTED, to enable the two
png_set_*_16_to_8() functions separately.
Prior to libpng-1.5.4, the png_set_user_limits() function could only be
used to reduce the width and height limits from the value of
@ -5051,18 +5056,19 @@ The machine-generated configure files are no longer included in branches
libpng16 and later of the GIT repository. They continue to be included
in the tarball releases, however.
Libpng-1.6.0 and later use the CMF bytes at the beginning of the IDAT stream
to set the size of the sliding window for reading instead of using the default
32-kbyte sliding window size. It was discovered that there are hundreds of PNG
files in the wild that have incorrect CMF bytes that cause libpng to now issue
a "too far back" error and reject the file. Libpng-1.6.3 provides a way to
revert to the libpng-1.5.x behavior (ignoring the CMF bytes and using a
Libpng-1.6.0 through 1.6.2 used the CMF bytes at the beginning of the IDAT
stream to set the size of the sliding window for reading instead of using the
default 32-kbyte sliding window size. It was discovered that there are
hundreds of PNG files in the wild that have incorrect CMF bytes that caused
libpng to issue a "too far back" error and reject the file. Libpng-1.6.3 and
later calculate their own safe CMF from the image dimensions, provide a way
to revert to the libpng-1.5.x behavior (ignoring the CMF bytes and using a
32-kbyte sliding window), by using
png_set_option(png_ptr, PNG_MAXIMUM_INFLATE_WINDOW,
PNG_OPTION_ON);
and provides a tool (contrib/tools/pngfix) for optimizing the CMF bytes
and provide a tool (contrib/tools/pngfix) for optimizing the CMF bytes
correctly.
Libpng-1.6.0 and libpng-1.6.1 wrote uncompressed iTXt chunks with the wrong
@ -5232,13 +5238,13 @@ Other rules can be inferred by inspecting the libpng source.
XVI. Y2K Compliance in libpng
November 14, 2013
February 6, 2014
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.6.7 are Y2K compliant. It is my belief that earlier
upward through 1.6.9 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has two year fields. One is a 2-byte unsigned integer

Просмотреть файл

@ -47,8 +47,8 @@
# define PNG_ARM_NEON_OPT 0
#endif
#define PNG_BENIGN_READ_ERRORS_SUPPORTED
#define PNG_READ_SUPPORTED
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_APNG_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
@ -73,8 +73,6 @@
#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
#define PNG_EASY_ACCESS_SUPPORTED
#define PNG_READ_BGR_SUPPORTED
#define PNG_BENIGN_READ_ERRORS_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#define PNG_READ_STRIP_16_TO_8_SUPPORTED
@ -93,7 +91,9 @@
#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
#define PNG_APNG_SUPPORTED
#define PNG_ALLOW_BENIGN_ERRORS
#define PNG_BENIGN_ERRORS_SUPPORTED
#define PNG_BENIGN_READ_ERRORS_SUPPORTED
#define PNG_cHRM_SUPPORTED
#define PNG_COLORSPACE_SUPPORTED
#define PNG_gAMA_SUPPORTED
@ -103,11 +103,9 @@
#define PNG_tRNS_SUPPORTED
#define PNG_16BIT_SUPPORTED
#define PNG_CHECK_cHRM_SUPPORTED
#define PNG_FIXED_POINT_SUPPORTED
#define PNG_FLOATING_ARITHMETIC_SUPPORTED
#define PNG_FLOATING_POINT_SUPPORTED
#define PNG_POINTER_INDEXING_SUPPORTED
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_SETJMP_SUPPORTED
#define PNG_STDIO_SUPPORTED
#define PNG_TEXT_SUPPORTED

Просмотреть файл

@ -1,8 +1,8 @@
/* png.c - location for general purpose libpng functions
*
* Last changed in libpng 1.6.2 [April 25, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -14,7 +14,7 @@
#include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_6_7 Your_png_h_is_not_version_1_6_7;
typedef png_libpng_version_1_6_9 Your_png_h_is_not_version_1_6_9;
/* 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
@ -201,6 +201,7 @@ png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver)
pos = png_safecat(m, (sizeof m), pos, user_png_ver);
pos = png_safecat(m, (sizeof m), pos, " but running with ");
pos = png_safecat(m, (sizeof m), pos, png_libpng_ver);
PNG_UNUSED(pos)
png_warning(png_ptr, m);
#endif
@ -259,6 +260,10 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
*/
# ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(&create_struct, mem_ptr, malloc_fn, free_fn);
# else
PNG_UNUSED(mem_ptr)
PNG_UNUSED(malloc_fn)
PNG_UNUSED(free_fn)
# endif
/* (*error_fn) can return control to the caller after the error_ptr is set,
@ -768,14 +773,14 @@ png_get_copyright(png_const_structrp png_ptr)
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
"libpng version 1.6.7 - November 14, 2013" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2013 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"libpng version 1.6.9 - February 6, 2014" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2014 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 "libpng version 1.6.7 - November 14, 2013\
Copyright (c) 1998-2013 Glenn Randers-Pehrson\
return "libpng version 1.6.9 - February 6, 2014\
Copyright (c) 1998-2014 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
# endif
@ -821,6 +826,63 @@ png_get_header_version(png_const_structrp png_ptr)
#endif
}
#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
/* NOTE: this routine is not used internally! */
/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth
* large of png_color. This lets grayscale images be treated as
* paletted. Most useful for gamma correction and simplification
* of code. This API is not used internally.
*/
void PNGAPI
png_build_grayscale_palette(int bit_depth, png_colorp palette)
{
int num_palette;
int color_inc;
int i;
int v;
png_debug(1, "in png_do_build_grayscale_palette");
if (palette == NULL)
return;
switch (bit_depth)
{
case 1:
num_palette = 2;
color_inc = 0xff;
break;
case 2:
num_palette = 4;
color_inc = 0x55;
break;
case 4:
num_palette = 16;
color_inc = 0x11;
break;
case 8:
num_palette = 256;
color_inc = 1;
break;
default:
num_palette = 0;
color_inc = 0;
break;
}
for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
{
palette[i].red = (png_byte)v;
palette[i].green = (png_byte)v;
palette[i].blue = (png_byte)v;
}
}
#endif
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
int PNGAPI
png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name)
@ -1722,6 +1784,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
# endif
/* The 'reason' is an arbitrary message, allow +79 maximum 195 */
pos = png_safecat(message, (sizeof message), pos, reason);
PNG_UNUSED(pos)
/* This is recoverable, but make it unconditionally an app_error on write to
* avoid writing invalid ICC profiles into PNG files. (I.e. we handle them
@ -2410,14 +2473,6 @@ png_check_IHDR(png_const_structrp png_ptr,
error = 1;
}
if (width > (PNG_UINT_32_MAX
>> 3) /* 8-byte RGBA pixels */
- 48 /* bigrowbuf hack */
- 1 /* filter byte */
- 7*8 /* rounding of width to multiple of 8 pixels */
- 8) /* extra max_pixel_depth pad */
png_warning(png_ptr, "Width is too large for libpng to process pixels");
/* Check other values */
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
bit_depth != 8 && bit_depth != 16)
@ -3091,11 +3146,15 @@ png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
if (r > 2147483647. || r < -2147483648.)
png_fixed_error(png_ptr, text);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(text)
# endif
return (png_fixed_point)r;
}
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || \
#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_COLORSPACE_SUPPORTED) ||\
defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
/* muldiv functions */
/* This API takes signed arguments and rounds the result to the nearest
@ -3268,27 +3327,29 @@ png_gamma_significant(png_fixed_point gamma_val)
#endif
#ifdef PNG_READ_GAMMA_SUPPORTED
# ifdef PNG_16BIT_SUPPORTED
/* A local convenience routine. */
static png_fixed_point
png_product2(png_fixed_point a, png_fixed_point b)
{
/* The required result is 1/a * 1/b; the following preserves accuracy. */
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
double r = a * 1E-5;
r *= b;
r = floor(r+.5);
if (r <= 2147483647. && r >= -2147483648.)
return (png_fixed_point)r;
#else
# else
png_fixed_point res;
if (png_muldiv(&res, a, b, 100000))
return res;
#endif
# endif
return 0; /* overflow */
}
# endif /* 16BIT */
/* The inverse of the above. */
png_fixed_point
@ -3593,6 +3654,7 @@ png_exp8bit(png_fixed_point lg2)
return (png_byte)((x + 0x7fffffU) >> 24);
}
#ifdef PNG_16BIT_SUPPORTED
static png_uint_16
png_exp16bit(png_fixed_point lg2)
{
@ -3603,6 +3665,7 @@ png_exp16bit(png_fixed_point lg2)
x -= x >> 16;
return (png_uint_16)((x + 32767U) >> 16);
}
#endif /* 16BIT */
#endif /* FLOATING_ARITHMETIC */
png_byte
@ -3628,6 +3691,7 @@ png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val)
return (png_byte)value;
}
#ifdef PNG_16BIT_SUPPORTED
png_uint_16
png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
{
@ -3650,6 +3714,7 @@ png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
return (png_uint_16)value;
}
#endif /* 16BIT */
/* This does the right thing based on the bit_depth field of the
* png_struct, interpreting values as 8-bit or 16-bit. While the result
@ -3663,10 +3728,16 @@ png_gamma_correct(png_structrp png_ptr, unsigned int value,
if (png_ptr->bit_depth == 8)
return png_gamma_8bit_correct(value, gamma_val);
#ifdef PNG_16BIT_SUPPORTED
else
return png_gamma_16bit_correct(value, gamma_val);
#else
/* should not reach this */
return 0;
#endif /* 16BIT */
}
#ifdef PNG_16BIT_SUPPORTED
/* Internal function to build a single 16-bit table - the table consists of
* 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount
* to shift the input values right (or 16-number_of_signifiant_bits).
@ -3805,6 +3876,7 @@ png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
last++;
}
}
#endif /* 16BIT */
/* Build a single 8-bit table: same as the 16-bit case but much simpler (and
* typically much faster). Note that libpng currently does no sBIT processing
@ -3833,6 +3905,7 @@ png_destroy_gamma_table(png_structrp png_ptr)
png_free(png_ptr, png_ptr->gamma_table);
png_ptr->gamma_table = NULL;
#ifdef PNG_16BIT_SUPPORTED
if (png_ptr->gamma_16_table != NULL)
{
int i;
@ -3844,6 +3917,7 @@ png_destroy_gamma_table(png_structrp png_ptr)
png_free(png_ptr, png_ptr->gamma_16_table);
png_ptr->gamma_16_table = NULL;
}
#endif /* 16BIT */
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
@ -3853,6 +3927,7 @@ png_destroy_gamma_table(png_structrp png_ptr)
png_free(png_ptr, png_ptr->gamma_to_1);
png_ptr->gamma_to_1 = NULL;
#ifdef PNG_16BIT_SUPPORTED
if (png_ptr->gamma_16_from_1 != NULL)
{
int i;
@ -3875,6 +3950,7 @@ png_destroy_gamma_table(png_structrp png_ptr)
png_free(png_ptr, png_ptr->gamma_16_to_1);
png_ptr->gamma_16_to_1 = NULL;
}
#endif /* 16BIT */
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
}
@ -3920,6 +3996,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
}
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
}
#ifdef PNG_16BIT_SUPPORTED
else
{
png_byte shift, sig_bit;
@ -3976,24 +4053,20 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
png_ptr->gamma_shift = shift;
#ifdef PNG_16BIT_SUPPORTED
/* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now
* PNG_COMPOSE). This effectively smashed the background calculation for
* 16-bit output because the 8-bit table assumes the result will be reduced
* to 8 bits.
*/
if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8))
#endif
png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma) : PNG_FP_1);
#ifdef PNG_16BIT_SUPPORTED
else
png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma,
png_ptr->screen_gamma) : PNG_FP_1);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
@ -4013,6 +4086,7 @@ png_build_gamma_table(png_structrp png_ptr, int bit_depth)
}
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
}
#endif /* 16BIT */
}
#endif /* READ_GAMMA */

Просмотреть файл

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.6.7 - November 14, 2013
* libpng version 1.6.9 - February 6, 2014
* Copyright (c) 1998-2013 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.6.7 - November 14, 2013: Glenn
* libpng versions 0.97, January 1998, through 1.6.9 - February 6, 2014: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@ -184,8 +184,14 @@
* 1.6.5 16 10605 16.so.16.5[.0]
* 1.6.6 16 10606 16.so.16.6[.0]
* 1.6.7beta01-04 16 10607 16.so.16.7[.0]
* 1.6.7rc01-02 16 10607 16.so.16.7[.0]
* 1.6.7rc01-03 16 10607 16.so.16.7[.0]
* 1.6.7 16 10607 16.so.16.7[.0]
* 1.6.8beta01-02 16 10608 16.so.16.8[.0]
* 1.6.8rc01-02 16 10608 16.so.16.8[.0]
* 1.6.8 16 10608 16.so.16.8[.0]
* 1.6.9beta01-04 16 10609 16.so.16.9[.0]
* 1.6.9rc01-02 16 10609 16.so.16.9[.0]
* 1.6.9 16 10609 16.so.16.9[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@ -217,7 +223,7 @@
*
* This code is released under the libpng license.
*
* libpng versions 1.2.6, August 15, 2004, through 1.6.7, November 14, 2013, are
* libpng versions 1.2.6, August 15, 2004, through 1.6.9, February 6, 2014, are
* Copyright (c) 2004, 2006-2013 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:
@ -329,13 +335,13 @@
* Y2K compliance in libpng:
* =========================
*
* November 14, 2013
* February 6, 2014
*
* 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.6.7 are Y2K compliant. It is my belief that
* upward through 1.6.9 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant.
*
* Libpng only has two year fields. One is a 2-byte unsigned integer
@ -395,9 +401,9 @@
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.7"
#define PNG_LIBPNG_VER_STRING "1.6.9"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.6.7 - November 14, 2013\n"
" libpng version 1.6.9 - February 6, 2014\n"
#define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16
@ -405,7 +411,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 6
#define PNG_LIBPNG_VER_RELEASE 7
#define PNG_LIBPNG_VER_RELEASE 9
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
@ -436,7 +442,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 10607 /* 1.6.7 */
#define PNG_LIBPNG_VER 10609 /* 1.6.9 */
/* Library configuration: these options cannot be changed after
* the library has been built.
@ -547,7 +553,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
typedef char* png_libpng_version_1_6_7;
typedef char* png_libpng_version_1_6_9;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
*
@ -2007,6 +2013,8 @@ PNG_EXPORTA(103, void, png_chunk_error, (png_const_structrp png_ptr,
#else
/* Fatal error in PNG image of libpng - can't continue */
PNG_EXPORTA(104, void, png_err, (png_const_structrp png_ptr), PNG_NORETURN);
# define png_error(s1,s2) png_err(s1)
# define png_chunk_error(s1,s2) png_err(s1)
#endif
#ifdef PNG_WARNINGS_SUPPORTED
@ -2017,6 +2025,9 @@ PNG_EXPORT(105, void, png_warning, (png_const_structrp png_ptr,
/* Non-fatal error in libpng, chunk name is prepended to message. */
PNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr,
png_const_charp warning_message));
#else
# define png_warning(s1,s2) ((void)(s1))
# define png_chunk_warning(s1,s2) ((void)(s1))
#endif
#ifdef PNG_BENIGN_ERRORS_SUPPORTED

Просмотреть файл

@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.6.7 - November 14, 2013
* libpng version 1.6.9 - February 6, 2014
*
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@ -361,7 +361,31 @@
* version 1.2.41. Disabling these removes the warnings but may also produce
* less efficient code.
*/
# if defined(__GNUC__)
# if defined(__clang__)
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
# endif
# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__)
# define PNG_NORETURN __attribute__((__noreturn__))
# endif
# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__)
# define PNG_ALLOCATED __attribute__((__malloc__))
# endif
# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__)
# define PNG_DEPRECATED __attribute__((__deprecated__))
# endif
# if !defined(PNG_PRIVATE)
# if __has_extension(attribute_unavailable_with_message)
# define PNG_PRIVATE __attribute__((__unavailable__(\
"This function is not exported by libpng.")))
# endif
# endif
# ifndef PNG_RESTRICT
# define PNG_RESTRICT __restrict
# endif
# elif defined(__GNUC__)
# ifndef PNG_USE_RESULT
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
# endif
@ -384,12 +408,12 @@
__attribute__((__deprecated__))
# endif
# endif
# if ((__GNUC__ != 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
# ifndef PNG_RESTRICT
# define PNG_RESTRICT __restrict
# endif
# endif /* __GNUC__ == 3.0 */
# endif /* __GNUC__ >= 3 */
# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */
# endif /* __GNUC__ >= 3 */
# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
# ifndef PNG_USE_RESULT
@ -419,7 +443,7 @@
# ifndef PNG_RESTRICT
# define PNG_RESTRICT __restrict
# endif
# endif /* _MSC_VER */
# endif
#endif /* PNG_PEDANTIC_WARNINGS */
#ifndef PNG_DEPRECATED
@ -440,6 +464,7 @@
#ifndef PNG_RESTRICT
# define PNG_RESTRICT /* The C99 "restrict" feature */
#endif
#ifndef PNG_FP_EXPORT /* A floating point API. */
# ifdef PNG_FLOATING_POINT_SUPPORTED
# define PNG_FP_EXPORT(ordinal, type, name, args)\

Просмотреть файл

@ -1,11 +1,11 @@
/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
*
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* Copyright (c) 1998-2013 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.)
*
* Last changed in libpng 1.5.0 [January 6, 2011]
* Last changed in libpng 1.6.8 [December 19, 2013]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -25,7 +25,7 @@
* (actually ((void)0)).
*
* level: level of detail of message, starting at 0. A level 'n'
* message is preceded by 'n' tab characters (not implemented
* message is preceded by 'n' 3-space indentations (not implemented
* on Microsoft compilers unless PNG_DEBUG_FILE is also
* defined, to allow debug DLL compilation with no standard IO).
* message: a printf(3) style text string. A trailing '\n' is added
@ -77,32 +77,29 @@
# endif /* PNG_DEBUG_FILE */
# if (PNG_DEBUG > 1)
/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on
* non-ISO compilers
*/
# ifdef __STDC__
# ifndef png_debug
# define png_debug(l,m) \
do { \
int num_tabs=l; \
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
(num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \
} while (0)
# endif
# ifndef png_debug1
# define png_debug1(l,m,p1) \
do { \
int num_tabs=l; \
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \
} while (0)
# endif
# ifndef png_debug2
# define png_debug2(l,m,p1,p2) \
do { \
int num_tabs=l; \
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\
} while (0)
# endif
# else /* __STDC __ */

Просмотреть файл

@ -1,7 +1,7 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* Last changed in libpng 1.6.1 [March 28, 2013]
* Last changed in libpng 1.6.8 [December 19, 2013]
* Copyright (c) 1998-2013 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.)
@ -382,6 +382,10 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
# endif
png_error(png_ptr, error_message);
}
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
}
void /* PRIVATE */
@ -391,6 +395,10 @@ png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
png_warning(png_ptr, error_message);
else
png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
}
void /* PRIVATE */
@ -400,6 +408,10 @@ png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
png_warning(png_ptr, error_message);
else
png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
}
#endif /* BENIGN_ERRORS */
@ -416,7 +428,8 @@ static PNG_CONST char png_digit[16] = {
};
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited be profile_error in png.c */
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
#if defined(PNG_WARNINGS_SUPPORTED) || \
(defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))
static void /* PRIVATE */
png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
error_message)
@ -506,6 +519,10 @@ png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
else
png_chunk_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
}
#endif
#endif /* PNG_READ_SUPPORTED */
@ -513,6 +530,10 @@ png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
void /* PRIVATE */
png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
{
# ifndef PNG_WARNINGS_SUPPORTED
PNG_UNUSED(message)
# endif
/* This is always supported, but for just read or just write it
* unconditionally does the right thing.
*/
@ -740,7 +761,12 @@ png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val);
#endif
/* Here if not setjmp support or if png_ptr is null. */
/* If control reaches this point, png_longjmp() must not return. The only
* choice is to terminate the whole process (or maybe the thread); to do
* this the ANSI-C abort() function is used unless a different method is
* implemented by overriding the default configuration setting for
* PNG_ABORT().
*/
PNG_ABORT();
}

Просмотреть файл

@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation
*
* Last changed in libpng 1.6.0 [February 14, 2013]
* Last changed in libpng 1.6.8 [December 19, 2013]
* Copyright (c) 1998-2013 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.)
@ -73,9 +73,10 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
* to implement a user memory handler. This checks to be sure it isn't
* called with big numbers.
*/
#ifdef PNG_USER_MEM_SUPPORTED
#ifndef PNG_USER_MEM_SUPPORTED
PNG_UNUSED(png_ptr)
#endif
if (size > 0 && size <= PNG_SIZE_MAX
# ifdef PNG_MAX_MALLOC_64K
&& size <= 65536U
@ -95,6 +96,8 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
return NULL;
}
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\
defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)
/* This is really here only to work round a spurious warning in GCC 4.6 and 4.7
* that arises because of the checks in png_realloc_array that are repeated in
* png_malloc_array.
@ -156,6 +159,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
return NULL; /* error */
}
#endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */
/* Various functions that have different error handling are derived from this.
* png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate

Просмотреть файл

@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode
*
* Last changed in libpng 1.6.0 [February 14, 2013]
* Last changed in libpng 1.6.8 [December 19, 2013]
* Copyright (c) 1998-2013 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.)
@ -185,7 +185,7 @@ void /* PRIVATE */
png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
{
png_uint_32 chunk_name;
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
int keep; /* unknown handling method */
#endif
@ -374,7 +374,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_push_have_end(png_ptr, info_ptr);
}
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -388,8 +388,8 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
if (chunk_name == png_PLTE)
png_ptr->mode |= PNG_HAVE_PLTE;
}
#endif
else if (chunk_name == png_PLTE)
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
@ -634,8 +634,8 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
#ifdef PNG_READ_APNG_SUPPORTED
else if (chunk_name == png_acTL)
{
@ -658,8 +658,8 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
}
#endif /* PNG_READ_APNG_SUPPORTED */
#endif /* PNG_READ_APNG_SUPPORTED */
else
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)

Просмотреть файл

@ -2,11 +2,11 @@
/* pngpriv.h - private declarations for use inside libpng
*
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Copyright (c) 1998-2014 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.)
*
* Last changed in libpng 1.6.7 [November 14, 2013]
* Last changed in libpng 1.6.9 [February 6, 2014]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -114,9 +114,15 @@
* typically the target FPU. If the FPU has been set to NEON (-mfpu=neon
* with GCC) then the compiler will define __ARM_NEON__ and we can rely
* unconditionally on NEON instructions not crashing, otherwise we must
* disable use of NEON instructions:
* disable use of NEON instructions.
*
* NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they
* can only be turned on automatically if that is supported too. If
* PNG_ARM_NEON_OPT is set in CPPFLAGS (to >0) then arm/arm_init.c will fail
* to compile with an appropriate #error if ALIGNED_MEMORY has been turned
* off.
*/
# ifdef __ARM_NEON__
# if defined(__ARM_NEON__) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
# define PNG_ARM_NEON_OPT 2
# else
# define PNG_ARM_NEON_OPT 0
@ -131,7 +137,7 @@
/* By default the 'intrinsics' code in arm/filter_neon_intrinsics.c is used
* if possible - if __ARM_NEON__ is set and the compiler version is not known
* to be broken. This is control by PNG_ARM_NEON_IMPLEMENTATION which can
* to be broken. This is controlled by PNG_ARM_NEON_IMPLEMENTATION which can
* be:
*
* 1 The intrinsics code (the default with __ARM_NEON__)
@ -369,8 +375,6 @@
#ifdef PNG_WARNINGS_SUPPORTED
# define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;
#else
# define png_warning(s1,s2) ((void)(s1))
# define png_chunk_warning(s1,s2) ((void)(s1))
# define png_warning_parameter(p,number,string) ((void)0)
# define png_warning_parameter_unsigned(p,number,format,value) ((void)0)
# define png_warning_parameter_signed(p,number,format,value) ((void)0)
@ -378,8 +382,6 @@
# define PNG_WARNING_PARAMETERS(p)
#endif
#ifndef PNG_ERROR_TEXT_SUPPORTED
# define png_error(s1,s2) png_err(s1)
# define png_chunk_error(s1,s2) png_err(s1)
# define png_fixed_error(s1,s2) png_err(s1)
#endif
@ -1234,7 +1236,7 @@ PNG_INTERNAL_FUNCTION(void,png_read_finish_IDAT,(png_structrp png_ptr),
PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr),
PNG_EMPTY);
/* Finish a row while reading, dealing with interlacing passes, etc. */
#endif
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
/* Initialize the row buffers, etc. */
PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY);
@ -1245,32 +1247,7 @@ PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY);
#endif
/* These are the functions that do the transformations */
#ifdef PNG_READ_FILLER_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_read_filler,(png_row_infop row_info,
png_bytep row, png_uint_32 filler, png_uint_32 flags),PNG_EMPTY);
#endif
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_read_swap_alpha,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_write_swap_alpha,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_read_invert_alpha,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_write_invert_alpha,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
/* Shared transform functions, defined in pngtran.c */
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
PNG_INTERNAL_FUNCTION(void,png_do_strip_channel,(png_row_infop row_info,
@ -1290,96 +1267,16 @@ PNG_INTERNAL_FUNCTION(void,png_do_packswap,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
PNG_INTERNAL_FUNCTION(int,png_do_rgb_to_gray,(png_structrp png_ptr,
png_row_infop row_info, png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_gray_to_rgb,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_PACK_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_unpack,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_SHIFT_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_unshift,(png_row_infop row_info,
png_bytep row, png_const_color_8p sig_bits),PNG_EMPTY);
#endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
PNG_INTERNAL_FUNCTION(void,png_do_invert,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_scale_16_to_8,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_chop,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_READ_QUANTIZE_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_quantize,(png_row_infop row_info,
png_bytep row, png_const_bytep palette_lookup,
png_const_bytep quantize_lookup),PNG_EMPTY);
# ifdef PNG_CORRECT_PALETTE_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_correct_palette,(png_structrp png_ptr,
png_colorp palette, int num_palette),PNG_EMPTY);
# endif
#endif
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
PNG_INTERNAL_FUNCTION(void,png_do_bgr,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_WRITE_PACK_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_pack,(png_row_infop row_info,
png_bytep row, png_uint_32 bit_depth),PNG_EMPTY);
#endif
#ifdef PNG_WRITE_SHIFT_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_shift,(png_row_infop row_info,
png_bytep row, png_const_color_8p bit_depth),PNG_EMPTY);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
PNG_INTERNAL_FUNCTION(void,png_do_compose,(png_row_infop row_info,
png_bytep row, png_structrp png_ptr),PNG_EMPTY);
#endif
#ifdef PNG_READ_GAMMA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_gamma,(png_row_infop row_info,
png_bytep row, png_structrp png_ptr),PNG_EMPTY);
#endif
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_encode_alpha,(png_row_infop row_info,
png_bytep row, png_structrp png_ptr),PNG_EMPTY);
#endif
#ifdef PNG_READ_EXPAND_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_expand_palette,(png_row_infop row_info,
png_bytep row, png_const_colorp palette, png_const_bytep trans,
int num_trans),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_do_expand,(png_row_infop row_info,
png_bytep row, png_const_color_16p trans_color),PNG_EMPTY);
#endif
#ifdef PNG_READ_EXPAND_16_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_expand_16,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
/* The following decodes the appropriate chunks, and does error correction,
* then calls the appropriate callback for the chunk if it is valid.
*/
@ -1488,16 +1385,14 @@ PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
* just skips the chunk or errors out if it is critical.
*/
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\
defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
PNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling,
(png_const_structrp png_ptr, png_uint_32 chunk_name),PNG_EMPTY);
/* Exactly as the API png_handle_as_unknown() except that the argument is a
* 32-bit chunk name, not a string.
*/
#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */
#endif /* PNG_SET_UNKNOWN_CHUNKS_SUPPORTED */
/* Handle the transformations for reading and writing */
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
@ -1568,13 +1463,6 @@ PNG_INTERNAL_FUNCTION(void,png_push_read_iTXt,(png_structrp png_ptr,
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#ifdef PNG_MNG_FEATURES_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_do_read_intrapixel,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_do_write_intrapixel,(png_row_infop row_info,
png_bytep row),PNG_EMPTY);
#endif
#ifdef PNG_APNG_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr,
png_uint_32 width, png_uint_32 height,
@ -1959,7 +1847,7 @@ PNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string,
png_size_t size),PNG_EMPTY);
#endif /* pCAL || sCAL */
#if defined(PNG_READ_GAMMA_SUPPORTED) ||\
#if defined(PNG_GAMMA_SUPPORTED) ||\
defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
/* Added at libpng version 1.5.0 */
/* This is a utility to provide a*times/div (rounded) and indicate

Просмотреть файл

@ -1,8 +1,8 @@
/* pngread.c - read a PNG file
*
* Last changed in libpng 1.6.1 [March 28, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -385,6 +385,72 @@ png_start_read_image(png_structrp png_ptr)
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Undoes intrapixel differencing,
* NOTE: this is apparently only supported in the 'sequential' reader.
*/
static void
png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_read_intrapixel");
if (
(row_info->color_type & PNG_COLOR_MASK_COLOR))
{
int bytes_per_pixel;
png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
*(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff);
*(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff);
}
}
else if (row_info->bit_depth == 16)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
png_uint_32 red = (s0 + s1 + 65536) & 0xffff;
png_uint_32 blue = (s2 + s1 + 65536) & 0xffff;
*(rp ) = (png_byte)((red >> 8) & 0xff);
*(rp + 1) = (png_byte)(red & 0xff);
*(rp + 4) = (png_byte)((blue >> 8) & 0xff);
*(rp + 5) = (png_byte)(blue & 0xff);
}
}
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
void PNGAPI
png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
{
@ -569,7 +635,6 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
}
#endif
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
if (png_ptr->transformations)
png_do_read_transformations(png_ptr, &row_info);
@ -1084,7 +1149,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
if (transforms & PNG_TRANSFORM_EXPAND)
if ((png_ptr->bit_depth < 8) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
(info_ptr->valid & PNG_INFO_tRNS))
png_set_expand(png_ptr);
#endif
@ -1103,14 +1168,8 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
{
png_color_8p sig_bit;
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
png_set_shift(png_ptr, sig_bit);
}
if ((transforms & PNG_TRANSFORM_SHIFT) && (info_ptr->valid & PNG_INFO_sBIT))
png_set_shift(png_ptr, &info_ptr->sig_bit);
#endif
#ifdef PNG_READ_BGR_SUPPORTED
@ -1205,12 +1264,11 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Arguments to png_image_finish_read: */
/* Encoding of PNG data (used by the color-map code) */
/* TODO: change these, dang, ANSI-C reserves the 'E' namespace. */
# define E_NOTSET 0 /* File encoding not yet known */
# define E_sRGB 1 /* 8-bit encoded to sRGB gamma */
# define E_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
# define E_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
# define E_LINEAR8 4 /* 8-bit linear: only from a file value */
# define P_NOTSET 0 /* File encoding not yet known */
# define P_sRGB 1 /* 8-bit encoded to sRGB gamma */
# define P_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
# define P_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
# define P_LINEAR8 4 /* 8-bit linear: only from a file value */
/* Color-map processing: after libpng has run on the PNG image further
* processing may be needed to conver the data to color-map indicies.
@ -1241,7 +1299,7 @@ typedef struct
png_voidp first_row;
ptrdiff_t row_bytes; /* step between rows */
int file_encoding; /* E_ values above */
png_fixed_point gamma_to_linear; /* For E_FILE, reciprocal of gamma */
png_fixed_point gamma_to_linear; /* For P_FILE, reciprocal of gamma */
int colormap_processing; /* PNG_CMAP_ values above */
} png_image_read_control;
@ -1373,7 +1431,7 @@ png_image_read_header(png_voidp argument)
#ifdef PNG_COLORSPACE_SUPPORTED
/* Does the colorspace match sRGB? If there is no color endpoint
* (colorant) information assume yes, otherwise require the
* 'ENDPOINTS_MATCHE_sRGB' colorspace flag to have been set. If the
* 'ENDPOINTS_MATCHP_sRGB' colorspace flag to have been set. If the
* colorspace has been determined to be invalid ignore it.
*/
if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags
@ -1562,17 +1620,24 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
*
* Or image data handling:
*
* tRNS, bKGD, gAMA, cHRM, sRGB, iCCP and sBIT.
* tRNS, bKGD, gAMA, cHRM, sRGB, [iCCP] and sBIT.
*
* This provides a small performance improvement and eliminates any
* potential vulnerability to security problems in the unused chunks.
*
* At present the iCCP chunk data isn't used, so iCCP chunk can be ignored
* too. This allows the simplified API to be compiled without iCCP support,
* however if the support is there the chunk is still checked to detect
* errors (which are unfortunately quite common.)
*/
{
static PNG_CONST png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
103, 65, 77, 65, '\0', /* gAMA */
# ifdef PNG_READ_iCCP_SUPPORTED
105, 67, 67, 80, '\0', /* iCCP */
# endif
115, 66, 73, 84, '\0', /* sBIT */
115, 82, 71, 66, '\0', /* sRGB */
};
@ -1609,25 +1674,25 @@ set_file_encoding(png_image_read_control *display)
{
if (png_gamma_not_sRGB(g))
{
display->file_encoding = E_FILE;
display->file_encoding = P_FILE;
display->gamma_to_linear = png_reciprocal(g);
}
else
display->file_encoding = E_sRGB;
display->file_encoding = P_sRGB;
}
else
display->file_encoding = E_LINEAR8;
display->file_encoding = P_LINEAR8;
}
static unsigned int
decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
{
if (encoding == E_FILE) /* double check */
if (encoding == P_FILE) /* double check */
encoding = display->file_encoding;
if (encoding == E_NOTSET) /* must be the file encoding */
if (encoding == P_NOTSET) /* must be the file encoding */
{
set_file_encoding(display);
encoding = display->file_encoding;
@ -1635,18 +1700,18 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
switch (encoding)
{
case E_FILE:
case P_FILE:
value = png_gamma_16bit_correct(value*257, display->gamma_to_linear);
break;
case E_sRGB:
case P_sRGB:
value = png_sRGB_table[value];
break;
case E_LINEAR:
case P_LINEAR:
break;
case E_LINEAR8:
case P_LINEAR8:
value *= 257;
break;
@ -1665,9 +1730,9 @@ png_colormap_compose(png_image_read_control *display,
png_uint_32 background, int encoding)
{
/* The file value is composed on the background, the background has the given
* encoding and so does the result, the file is encoded with E_FILE and the
* encoding and so does the result, the file is encoded with P_FILE and the
* file and alpha are 8-bit values. The (output) encoding will always be
* E_LINEAR or E_sRGB.
* P_LINEAR or P_sRGB.
*/
png_uint_32 f = decode_gamma(display, foreground, foreground_encoding);
png_uint_32 b = decode_gamma(display, background, encoding);
@ -1677,7 +1742,7 @@ png_colormap_compose(png_image_read_control *display,
*/
f = f * alpha + b * (255-alpha);
if (encoding == E_LINEAR)
if (encoding == P_LINEAR)
{
/* Scale to 65535; divide by 255, approximately (in fact this is extremely
* accurate, it divides by 255.00000005937181414556, with no overflow.)
@ -1687,13 +1752,13 @@ png_colormap_compose(png_image_read_control *display,
f = (f+32768) >> 16;
}
else /* E_sRGB */
else /* P_sRGB */
f = PNG_sRGB_FROM_LINEAR(f);
return f;
}
/* NOTE: E_LINEAR values to this routine must be 16-bit, but E_FILE values must
/* NOTE: P_LINEAR values to this routine must be 16-bit, but P_FILE values must
* be 8-bit.
*/
static void
@ -1703,7 +1768,7 @@ png_create_colormap_entry(png_image_read_control *display,
{
png_imagep image = display->image;
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) ?
E_LINEAR : E_sRGB;
P_LINEAR : P_sRGB;
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
(red != green || green != blue);
@ -1713,18 +1778,18 @@ png_create_colormap_entry(png_image_read_control *display,
/* Update the cache with whether the file gamma is significantly different
* from sRGB.
*/
if (encoding == E_FILE)
if (encoding == P_FILE)
{
if (display->file_encoding == E_NOTSET)
if (display->file_encoding == P_NOTSET)
set_file_encoding(display);
/* Note that the cached value may be E_FILE too, but if it is then the
/* Note that the cached value may be P_FILE too, but if it is then the
* gamma_to_linear member has been set.
*/
encoding = display->file_encoding;
}
if (encoding == E_FILE)
if (encoding == P_FILE)
{
png_fixed_point g = display->gamma_to_linear;
@ -1732,10 +1797,10 @@ png_create_colormap_entry(png_image_read_control *display,
green = png_gamma_16bit_correct(green*257, g);
blue = png_gamma_16bit_correct(blue*257, g);
if (convert_to_Y || output_encoding == E_LINEAR)
if (convert_to_Y || output_encoding == P_LINEAR)
{
alpha *= 257;
encoding = E_LINEAR;
encoding = P_LINEAR;
}
else
@ -1743,11 +1808,11 @@ png_create_colormap_entry(png_image_read_control *display,
red = PNG_sRGB_FROM_LINEAR(red * 255);
green = PNG_sRGB_FROM_LINEAR(green * 255);
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
encoding = E_sRGB;
encoding = P_sRGB;
}
}
else if (encoding == E_LINEAR8)
else if (encoding == P_LINEAR8)
{
/* This encoding occurs quite frequently in test cases because PngSuite
* includes a gAMA 1.0 chunk with most images.
@ -1756,10 +1821,10 @@ png_create_colormap_entry(png_image_read_control *display,
green *= 257;
blue *= 257;
alpha *= 257;
encoding = E_LINEAR;
encoding = P_LINEAR;
}
else if (encoding == E_sRGB && (convert_to_Y || output_encoding == E_LINEAR))
else if (encoding == P_sRGB && (convert_to_Y || output_encoding == P_LINEAR))
{
/* The values are 8-bit sRGB values, but must be converted to 16-bit
* linear.
@ -1768,11 +1833,11 @@ png_create_colormap_entry(png_image_read_control *display,
green = png_sRGB_table[green];
blue = png_sRGB_table[blue];
alpha *= 257;
encoding = E_LINEAR;
encoding = P_LINEAR;
}
/* This is set if the color isn't gray but the output is. */
if (encoding == E_LINEAR)
if (encoding == P_LINEAR)
{
if (convert_to_Y)
{
@ -1780,7 +1845,7 @@ png_create_colormap_entry(png_image_read_control *display,
png_uint_32 y = (png_uint_32)6968 * red + (png_uint_32)23434 * green +
(png_uint_32)2366 * blue;
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
y = (y + 16384) >> 15;
else
@ -1789,19 +1854,19 @@ png_create_colormap_entry(png_image_read_control *display,
y = (y + 128) >> 8;
y *= 255;
y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7);
encoding = E_sRGB;
encoding = P_sRGB;
}
blue = red = green = y;
}
else if (output_encoding == E_sRGB)
else if (output_encoding == P_sRGB)
{
red = PNG_sRGB_FROM_LINEAR(red * 255);
green = PNG_sRGB_FROM_LINEAR(green * 255);
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
alpha = PNG_DIV257(alpha);
encoding = E_sRGB;
encoding = P_sRGB;
}
}
@ -1810,7 +1875,7 @@ png_create_colormap_entry(png_image_read_control *display,
/* Store the value. */
{
# ifdef PNG_FORMAT_BGR_SUPPORTED
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else
@ -1822,7 +1887,7 @@ png_create_colormap_entry(png_image_read_control *display,
# define bgr 0
# endif
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
png_uint_16p entry = png_voidcast(png_uint_16p, display->colormap);
@ -1877,7 +1942,7 @@ png_create_colormap_entry(png_image_read_control *display,
}
}
else /* output encoding is E_sRGB */
else /* output encoding is P_sRGB */
{
png_bytep entry = png_voidcast(png_bytep, display->colormap);
@ -1919,7 +1984,7 @@ make_gray_file_colormap(png_image_read_control *display)
unsigned int i;
for (i=0; i<256; ++i)
png_create_colormap_entry(display, i, i, i, i, 255, E_FILE);
png_create_colormap_entry(display, i, i, i, i, 255, P_FILE);
return i;
}
@ -1930,7 +1995,7 @@ make_gray_colormap(png_image_read_control *display)
unsigned int i;
for (i=0; i<256; ++i)
png_create_colormap_entry(display, i, i, i, i, 255, E_sRGB);
png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB);
return i;
}
@ -1969,13 +2034,13 @@ make_ga_colormap(png_image_read_control *display)
while (i < 231)
{
unsigned int gray = (i * 256 + 115) / 231;
png_create_colormap_entry(display, i++, gray, gray, gray, 255, E_sRGB);
png_create_colormap_entry(display, i++, gray, gray, gray, 255, P_sRGB);
}
/* 255 is used here for the component values for consistency with the code
* that undoes premultiplication in pngwrite.c.
*/
png_create_colormap_entry(display, i++, 255, 255, 255, 0, E_sRGB);
png_create_colormap_entry(display, i++, 255, 255, 255, 0, P_sRGB);
for (a=1; a<5; ++a)
{
@ -1983,7 +2048,7 @@ make_ga_colormap(png_image_read_control *display)
for (g=0; g<6; ++g)
png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,
E_sRGB);
P_sRGB);
}
return i;
@ -2007,7 +2072,7 @@ make_rgb_colormap(png_image_read_control *display)
for (b=0; b<6; ++b)
png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,
E_sRGB);
P_sRGB);
}
}
@ -2030,11 +2095,11 @@ png_image_read_colormap(png_voidp argument)
const png_structrp png_ptr = image->opaque->png_ptr;
const png_uint_32 output_format = image->format;
const int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) ?
E_LINEAR : E_sRGB;
P_LINEAR : P_sRGB;
unsigned int cmap_entries;
unsigned int output_processing; /* Output processing option */
unsigned int data_encoding = E_NOTSET; /* Encoding libpng must produce */
unsigned int data_encoding = P_NOTSET; /* Encoding libpng must produce */
/* Background information; the background color and the index of this color
* in the color-map if it exists (else 256).
@ -2054,7 +2119,7 @@ png_image_read_colormap(png_voidp argument)
png_ptr->num_trans > 0) /* alpha in input */ &&
((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) /* no alpha in output */)
{
if (output_encoding == E_LINEAR) /* compose on black */
if (output_encoding == P_LINEAR) /* compose on black */
back_b = back_g = back_r = 0;
else if (display->background == NULL /* no way to remove it */)
@ -2078,7 +2143,7 @@ png_image_read_colormap(png_voidp argument)
}
}
else if (output_encoding == E_LINEAR)
else if (output_encoding == P_LINEAR)
back_b = back_r = back_g = 65535;
else
@ -2136,7 +2201,7 @@ png_image_read_colormap(png_voidp argument)
trans = png_ptr->trans_color.gray;
if ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0)
back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
}
/* png_create_colormap_entry just takes an RGBA and writes the
@ -2154,7 +2219,7 @@ png_image_read_colormap(png_voidp argument)
*/
if (i != trans)
png_create_colormap_entry(display, i, val, val, val, 255,
E_FILE/*8-bit with file gamma*/);
P_FILE/*8-bit with file gamma*/);
/* Else this entry is transparent. The colors don't matter if
* there is an alpha channel (back_alpha == 0), but it does no
@ -2170,7 +2235,7 @@ png_image_read_colormap(png_voidp argument)
}
/* We need libpng to preserve the original encoding. */
data_encoding = E_FILE;
data_encoding = P_FILE;
/* The rows from libpng, while technically gray values, are now also
* color-map indicies; however, they may need to be expanded to 1
@ -2199,7 +2264,7 @@ png_image_read_colormap(png_voidp argument)
* ensuring that the corresponding gray level matches the background
* color exactly.
*/
data_encoding = E_sRGB;
data_encoding = P_sRGB;
if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "gray[16] color-map: too few entries");
@ -2223,7 +2288,7 @@ png_image_read_colormap(png_voidp argument)
png_color_16 c;
png_uint_32 gray = back_g;
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
@ -2231,7 +2296,7 @@ png_image_read_colormap(png_voidp argument)
* matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 65535, E_LINEAR);
back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@ -2252,7 +2317,7 @@ png_image_read_colormap(png_voidp argument)
break;
}
back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
}
/* output_processing means that the libpng-processed row will be
@ -2289,7 +2354,7 @@ png_image_read_colormap(png_voidp argument)
* worry about tRNS matching - tRNS is ignored if there is an alpha
* channel.
*/
data_encoding = E_sRGB;
data_encoding = P_sRGB;
if (output_format & PNG_FORMAT_FLAG_ALPHA)
{
@ -2332,13 +2397,13 @@ png_image_read_colormap(png_voidp argument)
cmap_entries = make_gray_colormap(display);
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
/* And make sure the corresponding palette entry matches. */
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 65535, E_LINEAR);
back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the sRGB
@ -2369,7 +2434,7 @@ png_image_read_colormap(png_voidp argument)
{
png_uint_32 gray = (i * 256 + 115) / 231;
png_create_colormap_entry(display, i++, gray, gray, gray,
255, E_sRGB);
255, P_sRGB);
}
/* NOTE: this preserves the full precision of the application
@ -2377,7 +2442,7 @@ png_image_read_colormap(png_voidp argument)
*/
background_index = i;
png_create_colormap_entry(display, i++, back_r, back_g, back_b,
output_encoding == E_LINEAR ? 65535U : 255U, output_encoding);
output_encoding == P_LINEAR ? 65535U : 255U, output_encoding);
/* For non-opaque input composite on the sRGB background - this
* requires inverting the encoding for each component. The input
@ -2387,7 +2452,7 @@ png_image_read_colormap(png_voidp argument)
* represents. Consequently 'G' is always sRGB encoded, while
* 'A' is linear. We need the linear background colors.
*/
if (output_encoding == E_sRGB) /* else already linear */
if (output_encoding == P_sRGB) /* else already linear */
{
/* This may produce a value not exactly matching the
* background, but that's ok because these numbers are only
@ -2417,7 +2482,7 @@ png_image_read_colormap(png_voidp argument)
png_create_colormap_entry(display, i++,
PNG_sRGB_FROM_LINEAR(gray + back_rx),
PNG_sRGB_FROM_LINEAR(gray + back_gx),
PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, E_sRGB);
PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);
}
}
@ -2444,7 +2509,7 @@ png_image_read_colormap(png_voidp argument)
*/
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
-1);
data_encoding = E_sRGB;
data_encoding = P_sRGB;
/* The output will now be one or two 8-bit gray or gray+alpha
* channels. The more complex case arises when the input has alpha.
@ -2489,7 +2554,7 @@ png_image_read_colormap(png_voidp argument)
png_gamma_not_sRGB(png_ptr->colorspace.gamma))
{
cmap_entries = make_gray_file_colormap(display);
data_encoding = E_FILE;
data_encoding = P_FILE;
}
else
@ -2508,18 +2573,18 @@ png_image_read_colormap(png_voidp argument)
* it. Achieve this simply by ensuring that the entry
* selected for the background really is the background color.
*/
if (data_encoding == E_FILE) /* from the fixup above */
if (data_encoding == P_FILE) /* from the fixup above */
{
/* The app supplied a gray which is in output_encoding, we
* need to convert it to a value of the input (E_FILE)
* need to convert it to a value of the input (P_FILE)
* encoding then set this palette entry to the required
* output encoding.
*/
if (output_encoding == E_sRGB)
gray = png_sRGB_table[gray]; /* now E_LINEAR */
if (output_encoding == P_sRGB)
gray = png_sRGB_table[gray]; /* now P_LINEAR */
gray = PNG_DIV257(png_gamma_16bit_correct(gray,
png_ptr->colorspace.gamma)); /* now E_FILE */
png_ptr->colorspace.gamma)); /* now P_FILE */
/* And make sure the corresponding palette entry contains
* exactly the required sRGB value.
@ -2528,14 +2593,14 @@ png_image_read_colormap(png_voidp argument)
back_g, 0/*unused*/, output_encoding);
}
else if (output_encoding == E_LINEAR)
else if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
/* And make sure the corresponding palette entry matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 0/*unused*/, E_LINEAR);
back_g, 0/*unused*/, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@ -2565,7 +2630,7 @@ png_image_read_colormap(png_voidp argument)
* to do it once and using PNG_DIV51 on the 6x6x6 reduced RGB cube.
* Consequently we always want libpng to produce sRGB data.
*/
data_encoding = E_sRGB;
data_encoding = P_sRGB;
/* Is there any transparency or alpha? */
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
@ -2585,7 +2650,7 @@ png_image_read_colormap(png_voidp argument)
/* Add a transparent entry. */
png_create_colormap_entry(display, cmap_entries, 255, 255,
255, 0, E_sRGB);
255, 0, P_sRGB);
/* This is stored as the background index for the processing
* algorithm.
@ -2606,7 +2671,7 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
r, g, b, 128, E_sRGB);
r, g, b, 128, P_sRGB);
}
}
@ -2635,7 +2700,7 @@ png_image_read_colormap(png_voidp argument)
png_create_colormap_entry(display, cmap_entries, back_r,
back_g, back_b, 0/*unused*/, output_encoding);
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
r = PNG_sRGB_FROM_LINEAR(back_r * 255);
g = PNG_sRGB_FROM_LINEAR(back_g * 255);
@ -2675,11 +2740,11 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
png_colormap_compose(display, r, E_sRGB, 128,
png_colormap_compose(display, r, P_sRGB, 128,
back_r, output_encoding),
png_colormap_compose(display, g, E_sRGB, 128,
png_colormap_compose(display, g, P_sRGB, 128,
back_g, output_encoding),
png_colormap_compose(display, b, E_sRGB, 128,
png_colormap_compose(display, b, P_sRGB, 128,
back_b, output_encoding),
0/*unused*/, output_encoding);
}
@ -2738,7 +2803,7 @@ png_image_read_colormap(png_voidp argument)
num_trans = 0;
output_processing = PNG_CMAP_NONE;
data_encoding = E_FILE; /* Don't change from color-map indicies */
data_encoding = P_FILE; /* Don't change from color-map indicies */
cmap_entries = png_ptr->num_palette;
if (cmap_entries > 256)
cmap_entries = 256;
@ -2760,13 +2825,13 @@ png_image_read_colormap(png_voidp argument)
* on the sRGB color in 'back'.
*/
png_create_colormap_entry(display, i,
png_colormap_compose(display, colormap[i].red, E_FILE,
png_colormap_compose(display, colormap[i].red, P_FILE,
trans[i], back_r, output_encoding),
png_colormap_compose(display, colormap[i].green, E_FILE,
png_colormap_compose(display, colormap[i].green, P_FILE,
trans[i], back_g, output_encoding),
png_colormap_compose(display, colormap[i].blue, E_FILE,
png_colormap_compose(display, colormap[i].blue, P_FILE,
trans[i], back_b, output_encoding),
output_encoding == E_LINEAR ? trans[i] * 257U :
output_encoding == P_LINEAR ? trans[i] * 257U :
trans[i],
output_encoding);
}
@ -2775,7 +2840,7 @@ png_image_read_colormap(png_voidp argument)
else
png_create_colormap_entry(display, i, colormap[i].red,
colormap[i].green, colormap[i].blue,
i < num_trans ? trans[i] : 255U, E_FILE/*8-bit*/);
i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/);
}
/* The PNG data may have indicies packed in fewer than 8 bits, it
@ -2803,12 +2868,12 @@ png_image_read_colormap(png_voidp argument)
png_error(png_ptr, "bad data option (internal error)");
break;
case E_sRGB:
case P_sRGB:
/* Change to 8-bit sRGB */
png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);
/* FALL THROUGH */
case E_FILE:
case P_FILE:
if (png_ptr->bit_depth > 8)
png_set_scale_16(png_ptr);
break;
@ -2885,7 +2950,6 @@ png_image_read_and_map(png_voidp argument)
break;
default:
passes = 0;
png_error(png_ptr, "unknown interlace type");
}
@ -3204,7 +3268,6 @@ png_image_read_composite(png_voidp argument)
break;
default:
passes = 0;
png_error(png_ptr, "unknown interlace type");
}
@ -3353,11 +3416,15 @@ png_image_read_background(png_voidp argument)
break;
default:
passes = 0;
png_error(png_ptr, "unknown interlace type");
}
switch (png_get_bit_depth(png_ptr, info_ptr))
/* Use direct access to info_ptr here because otherwise the simplified API
* would require PNG_EASY_ACCESS_SUPPORTED (just for this.) Note this is
* checking the value after libpng expansions, not the original value in the
* PNG.
*/
switch (info_ptr->bit_depth)
{
default:
png_error(png_ptr, "unexpected bit depth");
@ -3505,8 +3572,10 @@ png_image_read_background(png_voidp argument)
unsigned int outchannels = 1+preserve_alpha;
int swap_alpha = 0;
if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
swap_alpha = 1;
# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
swap_alpha = 1;
# endif
for (pass = 0; pass < passes; ++pass)
{

Просмотреть файл

@ -1,8 +1,8 @@
/* pngrio.c - functions for data input
*
* Last changed in libpng 1.6.0 [February 14, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -102,6 +102,7 @@ png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
png_ptr->read_data_fn = read_data_fn;
#endif
#ifdef PNG_WRITE_SUPPORTED
/* It is an error to write to a read device */
if (png_ptr->write_data_fn != NULL)
{
@ -110,6 +111,7 @@ png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
"Can't set both read_data_fn and write_data_fn in the"
" same structure");
}
#endif
#ifdef PNG_WRITE_FLUSH_SUPPORTED
png_ptr->output_flush_fn = NULL;

Просмотреть файл

@ -1,8 +1,8 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* Last changed in libpng 1.6.4 [August 21, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -1134,7 +1134,7 @@ png_init_palette_transformations(png_structrp png_ptr)
if (!input_has_alpha)
{
/* Any alpha means background and associative alpha processing is
* required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA
* required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA
* and ENCODE_ALPHA are irrelevant.
*/
png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
@ -1199,7 +1199,7 @@ png_init_rgb_transformations(png_structrp png_ptr)
if (!input_has_alpha)
{
/* Any alpha means background and associative alpha processing is
* required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA
* required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA
* and ENCODE_ALPHA are irrelevant.
*/
# ifdef PNG_READ_ALPHA_MODE_SUPPORTED
@ -1942,6 +1942,9 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
info_ptr->bit_depth = 8;
info_ptr->num_trans = 0;
if (png_ptr->palette == NULL)
png_error (png_ptr, "Palette is NULL in indexed image");
}
else
{
@ -2120,303 +2123,6 @@ defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
#endif
}
/* Transform the row. The order of transformations is significant,
* and is very touchy. If you add a transformation, take care to
* decide how it fits in with the other transformations here.
*/
void /* PRIVATE */
png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
{
png_debug(1, "in png_do_read_transformations");
if (png_ptr->row_buf == NULL)
{
/* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this
* error is incredibly rare and incredibly easy to debug without this
* information.
*/
png_error(png_ptr, "NULL row buffer");
}
/* The following is debugging; prior to 1.5.4 the code was never compiled in;
* in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro
* PNG_WARN_UNINITIALIZED_ROW removed. In 1.6 the new flag is set only for
* all transformations, however in practice the ROW_INIT always gets done on
* demand, if necessary.
*/
if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
!(png_ptr->flags & PNG_FLAG_ROW_INIT))
{
/* Application has failed to call either png_read_start_image() or
* png_read_update_info() after setting transforms that expand pixels.
* This check added to libpng-1.2.19 (but not enabled until 1.5.4).
*/
png_error(png_ptr, "Uninitialized row");
}
#ifdef PNG_READ_EXPAND_SUPPORTED
if (png_ptr->transformations & PNG_EXPAND)
{
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
png_do_expand_palette(row_info, png_ptr->row_buf + 1,
png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
}
else
{
if (png_ptr->num_trans &&
(png_ptr->transformations & PNG_EXPAND_tRNS))
png_do_expand(row_info, png_ptr->row_buf + 1,
&(png_ptr->trans_color));
else
png_do_expand(row_info, png_ptr->row_buf + 1,
NULL);
}
}
#endif
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
!(png_ptr->transformations & PNG_COMPOSE) &&
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
0 /* at_start == false, because SWAP_ALPHA happens later */);
#endif
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
{
int rgb_error =
png_do_rgb_to_gray(png_ptr, row_info,
png_ptr->row_buf + 1);
if (rgb_error)
{
png_ptr->rgb_to_gray_status=1;
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
PNG_RGB_TO_GRAY_WARN)
png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
PNG_RGB_TO_GRAY_ERR)
png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
}
}
#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.
*/
#ifdef 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->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
if (png_ptr->transformations & PNG_COMPOSE)
png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);
#endif
#ifdef PNG_READ_GAMMA_SUPPORTED
if ((png_ptr->transformations & PNG_GAMMA) &&
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
/* Because RGB_TO_GRAY does the gamma transform. */
!(png_ptr->transformations & PNG_RGB_TO_GRAY) &&
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
/* Because PNG_COMPOSE does the gamma transform if there is something to
* do (if there is an alpha channel or transparency.)
*/
!((png_ptr->transformations & PNG_COMPOSE) &&
((png_ptr->num_trans != 0) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
#endif
/* Because png_init_read_transformations transforms the palette, unless
* RGB_TO_GRAY will do the transform.
*/
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
#endif
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
(png_ptr->transformations & PNG_COMPOSE) &&
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
0 /* at_start == false, because SWAP_ALPHA happens later */);
#endif
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
if ((png_ptr->transformations & PNG_ENCODE_ALPHA) &&
(row_info->color_type & PNG_COLOR_MASK_ALPHA))
png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);
#endif
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
if (png_ptr->transformations & PNG_SCALE_16_TO_8)
png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
/* There is no harm in doing both of these because only one has any effect,
* by putting the 'scale' option first if the app asks for scale (either by
* calling the API or in a TRANSFORM flag) this is what happens.
*/
if (png_ptr->transformations & PNG_16_TO_8)
png_do_chop(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_QUANTIZE_SUPPORTED
if (png_ptr->transformations & PNG_QUANTIZE)
{
png_do_quantize(row_info, png_ptr->row_buf + 1,
png_ptr->palette_lookup, png_ptr->quantize_index);
if (row_info->rowbytes == 0)
png_error(png_ptr, "png_do_quantize returned rowbytes=0");
}
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
#ifdef PNG_READ_EXPAND_16_SUPPORTED
/* Do the expansion now, after all the arithmetic has been done. Notice
* that previous transformations can handle the PNG_EXPAND_16 flag if this
* is efficient (particularly true in the case of gamma correction, where
* better accuracy results faster!)
*/
if (png_ptr->transformations & PNG_EXPAND_16)
png_do_expand_16(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
/* NOTE: moved here in 1.5.4 (from much later in this list.) */
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_INVERT_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_MONO)
png_do_invert(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_SHIFT_SUPPORTED
if (png_ptr->transformations & PNG_SHIFT)
png_do_unshift(row_info, png_ptr->row_buf + 1,
&(png_ptr->shift));
#endif
#ifdef PNG_READ_PACK_SUPPORTED
if (png_ptr->transformations & PNG_PACK)
png_do_unpack(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Added at libpng-1.5.10 */
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
png_ptr->num_palette_max >= 0)
png_do_check_palette_indexes(png_ptr, row_info);
#endif
#ifdef PNG_READ_BGR_SUPPORTED
if (png_ptr->transformations & PNG_BGR)
png_do_bgr(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_FILLER_SUPPORTED
if (png_ptr->transformations & PNG_FILLER)
png_do_read_filler(row_info, png_ptr->row_buf + 1,
(png_uint_32)png_ptr->filler, png_ptr->flags);
#endif
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_16BIT_SUPPORTED
#ifdef PNG_READ_SWAP_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(row_info, png_ptr->row_buf + 1);
#endif
#endif
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
if (png_ptr->transformations & PNG_USER_TRANSFORM)
{
if (png_ptr->read_user_transform_fn != NULL)
(*(png_ptr->read_user_transform_fn)) /* User read transform function */
(png_ptr, /* png_ptr */
row_info, /* row_info: */
/* png_uint_32 width; width of row */
/* png_size_t rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
if (png_ptr->user_transform_depth)
row_info->bit_depth = png_ptr->user_transform_depth;
if (png_ptr->user_transform_channels)
row_info->channels = png_ptr->user_transform_channels;
#endif
row_info->pixel_depth = (png_byte)(row_info->bit_depth *
row_info->channels);
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);
}
#endif
}
#ifdef PNG_READ_PACK_SUPPORTED
/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
* without changing the actual values. Thus, if you had a row with
@ -2424,7 +2130,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
* the numbers 0 or 1. If you would rather they contain 0 and 255, use
* png_do_shift() after this.
*/
void /* PRIVATE */
static void
png_do_unpack(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_unpack");
@ -2522,7 +2228,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
* a row of bit depth 8, but only 5 are significant, this will shift
* the values back to 0 through 31.
*/
void /* PRIVATE */
static void
png_do_unshift(png_row_infop row_info, png_bytep row,
png_const_color_8p sig_bits)
{
@ -2661,7 +2367,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row,
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
/* Scale rows of bit depth 16 down to 8 accurately */
void /* PRIVATE */
static void
png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_scale_16_to_8");
@ -2719,7 +2425,7 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
#endif
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
void /* PRIVATE */
static void
/* Simply discard the low byte. This was the default behavior prior
* to libpng-1.5.4.
*/
@ -2747,7 +2453,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
#endif
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
void /* PRIVATE */
static void
png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_read_swap_alpha");
@ -2844,7 +2550,7 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
#endif
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
void /* PRIVATE */
static void
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{
png_uint_32 row_width;
@ -2946,7 +2652,7 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
#ifdef PNG_READ_FILLER_SUPPORTED
/* Add filler channel if we have RGB color */
void /* PRIVATE */
static void
png_do_read_filler(png_row_infop row_info, png_bytep row,
png_uint_32 filler, png_uint_32 flags)
{
@ -3133,7 +2839,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
/* Expand grayscale files to RGB, with or without alpha */
void /* PRIVATE */
static void
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{
png_uint_32 i;
@ -3272,7 +2978,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
* calculated to make the sum 32768. This will result in different rounding
* to that used above.
*/
int /* PRIVATE */
static int
png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
{
@ -3466,73 +3172,14 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
return rgb_error;
}
#endif
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth
* large of png_color. This lets grayscale images be treated as
* paletted. Most useful for gamma correction and simplification
* of code. This API is not used internally.
*/
void PNGAPI
png_build_grayscale_palette(int bit_depth, png_colorp palette)
{
int num_palette;
int color_inc;
int i;
int v;
png_debug(1, "in png_do_build_grayscale_palette");
if (palette == NULL)
return;
switch (bit_depth)
{
case 1:
num_palette = 2;
color_inc = 0xff;
break;
case 2:
num_palette = 4;
color_inc = 0x55;
break;
case 4:
num_palette = 16;
color_inc = 0x11;
break;
case 8:
num_palette = 256;
color_inc = 1;
break;
default:
num_palette = 0;
color_inc = 0;
break;
}
for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
{
palette[i].red = (png_byte)v;
palette[i].green = (png_byte)v;
palette[i].blue = (png_byte)v;
}
}
#endif
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
/* Replace any alpha or transparency with the supplied background color.
* "background" is already in the screen gamma, while "background_1" is
* at a gamma of 1.0. Paletted files have already been taken care of.
*/
void /* PRIVATE */
static void
png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
#ifdef PNG_READ_GAMMA_SUPPORTED
@ -4272,7 +3919,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
* is 16, use gamma_16_table and gamma_shift. Build these with
* build_gamma_table().
*/
void /* PRIVATE */
static void
png_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
png_const_bytep gamma_table = png_ptr->gamma_table;
@ -4473,7 +4120,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
* linear.) Called only with color types that have an alpha channel. Needs the
* from_1 tables.
*/
void /* PRIVATE */
static void
png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
png_uint_32 row_width = row_info->width;
@ -4539,7 +4186,7 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
/* Expands a palette row to an RGB or RGBA row depending
* upon whether you supply trans and num_trans.
*/
void /* PRIVATE */
static void
png_do_expand_palette(png_row_infop row_info, png_bytep row,
png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
{
@ -4692,7 +4339,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
/* If the bit depth < 8, it is expanded to 8. Also, if the already
* expanded transparency value is supplied, an alpha channel is built.
*/
void /* PRIVATE */
static void
png_do_expand(png_row_infop row_info, png_bytep row,
png_const_color_16p trans_color)
{
@ -4922,7 +4569,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
/* If the bit depth is 8 and the color type is not a palette type expand the
* whole row to 16 bits. Has no effect otherwise.
*/
void /* PRIVATE */
static void
png_do_expand_16(png_row_infop row_info, png_bytep row)
{
if (row_info->bit_depth == 8 &&
@ -4950,7 +4597,7 @@ png_do_expand_16(png_row_infop row_info, png_bytep row)
#endif
#ifdef PNG_READ_QUANTIZE_SUPPORTED
void /* PRIVATE */
static void
png_do_quantize(png_row_infop row_info, png_bytep row,
png_const_bytep palette_lookup, png_const_bytep quantize_lookup)
{
@ -5042,69 +4689,303 @@ png_do_quantize(png_row_infop row_info, png_bytep row,
}
}
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Undoes intrapixel differencing */
/* Transform the row. The order of transformations is significant,
* and is very touchy. If you add a transformation, take care to
* decide how it fits in with the other transformations here.
*/
void /* PRIVATE */
png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
{
png_debug(1, "in png_do_read_intrapixel");
png_debug(1, "in png_do_read_transformations");
if (
(row_info->color_type & PNG_COLOR_MASK_COLOR))
if (png_ptr->row_buf == NULL)
{
int bytes_per_pixel;
png_uint_32 row_width = row_info->width;
/* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this
* error is incredibly rare and incredibly easy to debug without this
* information.
*/
png_error(png_ptr, "NULL row buffer");
}
if (row_info->bit_depth == 8)
/* The following is debugging; prior to 1.5.4 the code was never compiled in;
* in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro
* PNG_WARN_UNINITIALIZED_ROW removed. In 1.6 the new flag is set only for
* all transformations, however in practice the ROW_INIT always gets done on
* demand, if necessary.
*/
if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
!(png_ptr->flags & PNG_FLAG_ROW_INIT))
{
/* Application has failed to call either png_read_start_image() or
* png_read_update_info() after setting transforms that expand pixels.
* This check added to libpng-1.2.19 (but not enabled until 1.5.4).
*/
png_error(png_ptr, "Uninitialized row");
}
#ifdef PNG_READ_EXPAND_SUPPORTED
if (png_ptr->transformations & PNG_EXPAND)
{
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
*(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff);
*(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff);
}
png_do_expand_palette(row_info, png_ptr->row_buf + 1,
png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
}
else if (row_info->bit_depth == 16)
else
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
if (png_ptr->num_trans &&
(png_ptr->transformations & PNG_EXPAND_tRNS))
png_do_expand(row_info, png_ptr->row_buf + 1,
&(png_ptr->trans_color));
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
png_uint_32 red = (s0 + s1 + 65536) & 0xffff;
png_uint_32 blue = (s2 + s1 + 65536) & 0xffff;
*(rp ) = (png_byte)((red >> 8) & 0xff);
*(rp + 1) = (png_byte)(red & 0xff);
*(rp + 4) = (png_byte)((blue >> 8) & 0xff);
*(rp + 5) = (png_byte)(blue & 0xff);
}
png_do_expand(row_info, png_ptr->row_buf + 1,
NULL);
}
}
#endif
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
!(png_ptr->transformations & PNG_COMPOSE) &&
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
0 /* at_start == false, because SWAP_ALPHA happens later */);
#endif
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
{
int rgb_error =
png_do_rgb_to_gray(png_ptr, row_info,
png_ptr->row_buf + 1);
if (rgb_error)
{
png_ptr->rgb_to_gray_status=1;
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
PNG_RGB_TO_GRAY_WARN)
png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
PNG_RGB_TO_GRAY_ERR)
png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
}
}
#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.
*/
#ifdef 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->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
if (png_ptr->transformations & PNG_COMPOSE)
png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);
#endif
#ifdef PNG_READ_GAMMA_SUPPORTED
if ((png_ptr->transformations & PNG_GAMMA) &&
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
/* Because RGB_TO_GRAY does the gamma transform. */
!(png_ptr->transformations & PNG_RGB_TO_GRAY) &&
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
/* Because PNG_COMPOSE does the gamma transform if there is something to
* do (if there is an alpha channel or transparency.)
*/
!((png_ptr->transformations & PNG_COMPOSE) &&
((png_ptr->num_trans != 0) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
#endif
/* Because png_init_read_transformations transforms the palette, unless
* RGB_TO_GRAY will do the transform.
*/
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
#endif
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
(png_ptr->transformations & PNG_COMPOSE) &&
(row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
0 /* at_start == false, because SWAP_ALPHA happens later */);
#endif
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
if ((png_ptr->transformations & PNG_ENCODE_ALPHA) &&
(row_info->color_type & PNG_COLOR_MASK_ALPHA))
png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);
#endif
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
if (png_ptr->transformations & PNG_SCALE_16_TO_8)
png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
/* There is no harm in doing both of these because only one has any effect,
* by putting the 'scale' option first if the app asks for scale (either by
* calling the API or in a TRANSFORM flag) this is what happens.
*/
if (png_ptr->transformations & PNG_16_TO_8)
png_do_chop(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_QUANTIZE_SUPPORTED
if (png_ptr->transformations & PNG_QUANTIZE)
{
png_do_quantize(row_info, png_ptr->row_buf + 1,
png_ptr->palette_lookup, png_ptr->quantize_index);
if (row_info->rowbytes == 0)
png_error(png_ptr, "png_do_quantize returned rowbytes=0");
}
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
#ifdef PNG_READ_EXPAND_16_SUPPORTED
/* Do the expansion now, after all the arithmetic has been done. Notice
* that previous transformations can handle the PNG_EXPAND_16 flag if this
* is efficient (particularly true in the case of gamma correction, where
* better accuracy results faster!)
*/
if (png_ptr->transformations & PNG_EXPAND_16)
png_do_expand_16(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
/* NOTE: moved here in 1.5.4 (from much later in this list.) */
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_INVERT_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_MONO)
png_do_invert(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_SHIFT_SUPPORTED
if (png_ptr->transformations & PNG_SHIFT)
png_do_unshift(row_info, png_ptr->row_buf + 1,
&(png_ptr->shift));
#endif
#ifdef PNG_READ_PACK_SUPPORTED
if (png_ptr->transformations & PNG_PACK)
png_do_unpack(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Added at libpng-1.5.10 */
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
png_ptr->num_palette_max >= 0)
png_do_check_palette_indexes(png_ptr, row_info);
#endif
#ifdef PNG_READ_BGR_SUPPORTED
if (png_ptr->transformations & PNG_BGR)
png_do_bgr(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_FILLER_SUPPORTED
if (png_ptr->transformations & PNG_FILLER)
png_do_read_filler(row_info, png_ptr->row_buf + 1,
(png_uint_32)png_ptr->filler, png_ptr->flags);
#endif
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_READ_16BIT_SUPPORTED
#ifdef PNG_READ_SWAP_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(row_info, png_ptr->row_buf + 1);
#endif
#endif
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
if (png_ptr->transformations & PNG_USER_TRANSFORM)
{
if (png_ptr->read_user_transform_fn != NULL)
(*(png_ptr->read_user_transform_fn)) /* User read transform function */
(png_ptr, /* png_ptr */
row_info, /* row_info: */
/* png_uint_32 width; width of row */
/* png_size_t rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
if (png_ptr->user_transform_depth)
row_info->bit_depth = png_ptr->user_transform_depth;
if (png_ptr->user_transform_channels)
row_info->channels = png_ptr->user_transform_channels;
#endif
row_info->pixel_depth = (png_byte)(row_info->bit_depth *
row_info->channels);
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);
}
#endif
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
#endif /* PNG_READ_SUPPORTED */

Просмотреть файл

@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file
*
* Last changed in libpng 1.6.7 [November 14, 2013]
* Last changed in libpng 1.6.8 [December 19, 2013]
* Copyright (c) 1998-2013 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.)
@ -278,6 +278,10 @@ png_crc_error(png_structrp png_ptr)
return (0);
}
#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\
defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\
defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_SEQUENTIAL_READ_SUPPORTED)
/* Manage the read buffer; this simply reallocates the buffer if it is not small
* enough (or if it is not allocated). The routine returns a pointer to the
* buffer; if an error occurs and 'warn' is set the routine returns NULL, else
@ -325,6 +329,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
return buffer;
}
#endif /* PNG_READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|SEQUENTIAL_READ */
/* png_inflate_claim: claim the zstream for some nefarious purpose that involves
* decompression. Returns Z_OK on success, else a zlib error code. It checks
@ -4049,7 +4054,6 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
if (pb < pa) pa = pb, a = b;
if (pc < pa) a = c;
c = b;
a += *row;
*row++ = (png_byte)a;
}

Просмотреть файл

@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
* Last changed in libpng 1.6.3 [July 18, 2013]
* Last changed in libpng 1.6.8 [December 19, 2013]
* Copyright (c) 1998-2013 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.)
@ -532,7 +532,7 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
# endif
))
{
png_chunk_error(png_ptr, "Invalid palette");
png_error(png_ptr, "Invalid palette");
return;
}

Просмотреть файл

@ -1,8 +1,8 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* Last changed in libpng 1.6.2 [April 25, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -57,7 +57,9 @@ png_set_packing(png_structrp png_ptr)
if (png_ptr->bit_depth < 8)
{
png_ptr->transformations |= PNG_PACK;
png_ptr->usr_bit_depth = 8;
# ifdef PNG_WRITE_SUPPORTED
png_ptr->usr_bit_depth = 8;
# endif
}
}
#endif

Просмотреть файл

@ -1,8 +1,8 @@
/* pngwio.c - functions for data output
*
* Last changed in libpng 1.6.0 [February 14, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -149,8 +149,11 @@ png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
# else
png_ptr->output_flush_fn = output_flush_fn;
# endif
#else
PNG_UNUSED(output_flush_fn)
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
#ifdef PNG_READ_SUPPORTED
/* It is an error to read while writing a png file */
if (png_ptr->read_data_fn != NULL)
{
@ -160,5 +163,6 @@ png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
"Can't set both read_data_fn and write_data_fn in the"
" same structure");
}
#endif
}
#endif /* PNG_WRITE_SUPPORTED */

Просмотреть файл

@ -1,8 +1,8 @@
/* pngwrite.c - general routines to write a PNG file
*
* Last changed in libpng 1.6.2 [April 25, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -616,6 +616,71 @@ png_write_image(png_structrp png_ptr, png_bytepp image)
}
}
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Performs intrapixel differencing */
static void
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_intrapixel");
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
{
int bytes_per_pixel;
png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
*(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff);
*(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff);
}
}
#ifdef PNG_WRITE_16BIT_SUPPORTED
else if (row_info->bit_depth == 16)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
*(rp ) = (png_byte)((red >> 8) & 0xff);
*(rp + 1) = (png_byte)(red & 0xff);
*(rp + 4) = (png_byte)((blue >> 8) & 0xff);
*(rp + 5) = (png_byte)(blue & 0xff);
}
}
#endif /* PNG_WRITE_16BIT_SUPPORTED */
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
/* Called by user to write a row of image data */
void PNGAPI
png_write_row(png_structrp png_ptr, png_const_bytep row)
@ -1647,14 +1712,16 @@ png_write_image_16bit(png_voidp argument)
if (image->format & PNG_FORMAT_FLAG_ALPHA)
{
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
else
else
# endif
aindex = channels;
}
@ -1803,14 +1870,16 @@ png_write_image_8bit(png_voidp argument)
png_bytep row_end;
int aindex;
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
else
else
# endif
aindex = channels;
/* Use row_end in place of a loop counter: */
@ -1890,7 +1959,8 @@ png_image_set_PLTE(png_image_write_control *display)
const png_uint_32 format = image->format;
const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
# ifdef PNG_FORMAT_BGR_SUPPORTED
# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
const int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else

Просмотреть файл

@ -1,8 +1,8 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* Last changed in libpng 1.6.0 [February 14, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* Last changed in libpng 1.6.9 [February 6, 2014]
* Copyright (c) 1998-2014 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.)
*
@ -14,90 +14,14 @@
#include "pngpriv.h"
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
/* Transform the data according to the user's wishes. The order of
* transformations is significant.
*/
void /* PRIVATE */
png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
{
png_debug(1, "in png_do_write_transformations");
if (png_ptr == NULL)
return;
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
if (png_ptr->transformations & PNG_USER_TRANSFORM)
if (png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* User write transform
function */
(png_ptr, /* png_ptr */
row_info, /* row_info: */
/* png_uint_32 width; width of row */
/* png_size_t rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#endif
#ifdef PNG_WRITE_FILLER_SUPPORTED
if (png_ptr->transformations & PNG_FILLER)
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
#endif
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_PACK_SUPPORTED
if (png_ptr->transformations & PNG_PACK)
png_do_pack(row_info, png_ptr->row_buf + 1,
(png_uint_32)png_ptr->bit_depth);
#endif
#ifdef PNG_WRITE_SWAP_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_SHIFT_SUPPORTED
if (png_ptr->transformations & PNG_SHIFT)
png_do_shift(row_info, png_ptr->row_buf + 1,
&(png_ptr->shift));
#endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_BGR_SUPPORTED
if (png_ptr->transformations & PNG_BGR)
png_do_bgr(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_INVERT_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_MONO)
png_do_invert(row_info, png_ptr->row_buf + 1);
#endif
}
#ifdef PNG_WRITE_PACK_SUPPORTED
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
* row_info bit depth should be 8 (one pixel per byte). The channels
* should be 1 (this only happens on grayscale and paletted images).
*/
void /* PRIVATE */
static void
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_debug(1, "in png_do_pack");
@ -242,7 +166,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
* would pass 3 as bit_depth, and this routine would translate the
* data to 0 to 15.
*/
void /* PRIVATE */
static void
png_do_shift(png_row_infop row_info, png_bytep row,
png_const_color_8p bit_depth)
{
@ -381,7 +305,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
#endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
void /* PRIVATE */
static void
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_swap_alpha");
@ -475,7 +399,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
#endif
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
void /* PRIVATE */
static void
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_invert_alpha");
@ -568,70 +492,81 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
}
}
#endif
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Undoes intrapixel differencing */
/* Transform the data according to the user's wishes. The order of
* transformations is significant.
*/
void /* PRIVATE */
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
{
png_debug(1, "in png_do_write_intrapixel");
png_debug(1, "in png_do_write_transformations");
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
{
int bytes_per_pixel;
png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)
{
png_bytep rp;
png_uint_32 i;
if (png_ptr == NULL)
return;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
if (png_ptr->transformations & PNG_USER_TRANSFORM)
if (png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* User write transform
function */
(png_ptr, /* png_ptr */
row_info, /* row_info: */
/* png_uint_32 width; width of row */
/* png_size_t rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#endif
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
#ifdef PNG_WRITE_FILLER_SUPPORTED
if (png_ptr->transformations & PNG_FILLER)
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
#endif
else
return;
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(row_info, png_ptr->row_buf + 1);
#endif
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
*(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff);
*(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff);
}
}
#ifdef PNG_WRITE_PACK_SUPPORTED
if (png_ptr->transformations & PNG_PACK)
png_do_pack(row_info, png_ptr->row_buf + 1,
(png_uint_32)png_ptr->bit_depth);
#endif
#ifdef PNG_WRITE_16BIT_SUPPORTED
else if (row_info->bit_depth == 16)
{
png_bytep rp;
png_uint_32 i;
#ifdef PNG_WRITE_SWAP_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(row_info, png_ptr->row_buf + 1);
#endif
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
#ifdef PNG_WRITE_SHIFT_SUPPORTED
if (png_ptr->transformations & PNG_SHIFT)
png_do_shift(row_info, png_ptr->row_buf + 1,
&(png_ptr->shift));
#endif
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
#endif
else
return;
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
#endif
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
*(rp ) = (png_byte)((red >> 8) & 0xff);
*(rp + 1) = (png_byte)(red & 0xff);
*(rp + 4) = (png_byte)((blue >> 8) & 0xff);
*(rp + 5) = (png_byte)(blue & 0xff);
}
}
#endif /* PNG_WRITE_16BIT_SUPPORTED */
}
#ifdef PNG_WRITE_BGR_SUPPORTED
if (png_ptr->transformations & PNG_BGR)
png_do_bgr(row_info, png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_INVERT_SUPPORTED
if (png_ptr->transformations & PNG_INVERT_MONO)
png_do_invert(row_info, png_ptr->row_buf + 1);
#endif
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#endif /* PNG_WRITE_SUPPORTED */