提交 414d7b5f 编写于 作者: J John Bowler 提交者: Glenn Randers-Pehrson

[libpng16] Backport recent changes from libpng-1.7.0beta30 and beta31.

上级 685dff48
......@@ -27,6 +27,33 @@ Other information:
Changes since the last public release (1.6.9):
Version 1.6.10beta01 [February 6, 2014]
Backported changes from libpng-1.7.0beta30 and beta31:
Fixed a large number of instances where PNGCBAPI was omitted from
function definitions.
Added pngimage test program for png_read_png() and png_write_png()
with two new test scripts.
Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
png_set_packing() in png_read_png().
Fixed combination of ~alpha with shift. On read invert alpha, processing
occurred after shift processing, which causes the final values to be
outside the range that should be produced by the shift. Reversing the
order on read makes the two transforms work together correctly and mirrors
the order used on write.
Do not read invalid sBIT chunks. Previously libpng only checked sBIT
values on write, so a malicious PNG writer could therefore cause
the read code to return an invalid sBIT chunk, which might lead to
application errors or crashes. Such chunks are now skipped (with
chunk_benign_error).
Make png_read_png() and png_write_png() prototypes in png.h depend
upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
Support builds with unsupported PNG_TRANSFORM_* values. All of the
PNG_TRANSFORM_* values are always defined in png.h and, because they
are used for both read and write in some cases, it is not reliable
to #if out ones that are totally unsupported. This change adds error
detection in png_read_image() and png_write_image() to do a
png_app_error() if the app requests something that cannot be done
and it adds corresponding code to pngimage.c to handle such options
by not attempting to test them.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
......@@ -35,3 +62,4 @@ to subscribe)
or to glennrp at users.sourceforge.net
Glenn R-P
#endif
......@@ -4801,6 +4801,33 @@ Version 1.6.9rc02 [January 30, 2014]
Version 1.6.9 [February 6, 2014]
Version 1.6.10beta01 [February 6, 2014]
Backported changes from libpng-1.7.0beta30 and beta31:
Fixed a large number of instances where PNGCBAPI was omitted from
function definitions.
Added pngimage test program for png_read_png() and png_write_png()
with two new test scripts.
Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
png_set_packing() in png_read_png().
Fixed combination of ~alpha with shift. On read invert alpha, processing
occurred after shift processing, which causes the final values to be
outside the range that should be produced by the shift. Reversing the
order on read makes the two transforms work together correctly and mirrors
the order used on write.
Do not read invalid sBIT chunks. Previously libpng only checked sBIT
values on write, so a malicious PNG writer could therefore cause
the read code to return an invalid sBIT chunk, which might lead to
application errors or crashes. Such chunks are now skipped (with
chunk_benign_error).
Make png_read_png() and png_write_png() prototypes in png.h depend
upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
Support builds with unsupported PNG_TRANSFORM_* values. All of the
PNG_TRANSFORM_* values are always defined in png.h and, because they
are used for both read and write in some cases, it is not reliable
to #if out ones that are totally unsupported. This change adds error
detection in png_read_image() and png_write_image() to do a
png_app_error() if the app requests something that cannot be done
and it adds corresponding code to pngimage.c to handle such options
by not attempting to test them.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
......
......@@ -7,7 +7,7 @@ PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
ACLOCAL_AMFLAGS = -I scripts
# test programs - run on make check, make distcheck
check_PROGRAMS= pngtest pngunknown pngstest pngvalid
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage
# Utilities - installed
bin_PROGRAMS= pngfix png-fix-itxt
......@@ -34,6 +34,9 @@ pngstest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngunknown_SOURCES = contrib/libtests/pngunknown.c
pngunknown_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngimage_SOURCES = contrib/libtests/pngimage.c
pngimage_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngfix_SOURCES = contrib/tools/pngfix.c
pngfix_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
......@@ -59,7 +62,8 @@ TESTS =\
tests/pngstest-4a16 tests/pngstest-6a08 tests/pngstest-6a16\
tests/pngstest-error tests/pngunknown-IDAT\
tests/pngunknown-discard tests/pngunknown-if-safe tests/pngunknown-sAPI\
tests/pngunknown-sTER tests/pngunknown-save tests/pngunknown-vpAg
tests/pngunknown-sTER tests/pngunknown-save tests/pngunknown-vpAg\
tests/pngimage-quick tests/pngimage-full
# These tests are expected, and required, to fail:
XFAIL_TESTS = tests/pngstest-error
......@@ -212,6 +216,7 @@ pngtest.o: pnglibconf.h
contrib/libtests/makepng.o: pnglibconf.h
contrib/libtests/pngstest.o: pnglibconf.h
contrib/libtests/pngunknown.o: pnglibconf.h
contrib/libtests/pngimage.o: pnglibconf.h
contrib/libtests/pngvalid.o: pnglibconf.h
contrib/libtests/readpng.o: pnglibconf.h
contrib/libtests/tarith.o: pnglibconf.h
......
此差异已折叠。
......@@ -439,7 +439,7 @@ display_rc(const display *d, int strict)
}
/* libpng error and warning callbacks */
PNG_FUNCTION(void, error, (png_structp png_ptr, const char *message),
PNG_FUNCTION(void, (PNGCBAPI error), (png_structp png_ptr, const char *message),
static PNG_NORETURN)
{
display *d = (display*)png_get_error_ptr(png_ptr);
......@@ -448,7 +448,7 @@ PNG_FUNCTION(void, error, (png_structp png_ptr, const char *message),
display_exit(d);
}
static void
static void PNGCBAPI
warning(png_structp png_ptr, const char *message)
{
display *d = (display*)png_get_error_ptr(png_ptr);
......@@ -490,7 +490,7 @@ get_valid(display *d, png_infop info_ptr)
}
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
static int
static int PNGCBAPI
read_callback(png_structp pp, png_unknown_chunkp pc)
{
/* This function mimics the behavior of png_set_keep_unknown_chunks by
......
......@@ -926,7 +926,7 @@ internal_error(png_store *ps, png_const_charp message)
#endif /* PNG_READ_SUPPORTED */
/* Functions to use as PNG callbacks. */
static void
static void PNGCBAPI
store_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */
{
png_const_structp pp = ppIn;
......@@ -942,7 +942,7 @@ store_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */
}
}
static void
static void PNGCBAPI
store_warning(png_structp ppIn, png_const_charp message)
{
png_const_structp pp = ppIn;
......@@ -1093,7 +1093,7 @@ store_image_check(PNG_CONST png_store* ps, png_const_structp pp, int iImage)
}
#endif /* PNG_READ_SUPPORTED */
static void
static void PNGCBAPI
store_write(png_structp ppIn, png_bytep pb, png_size_t st)
{
png_const_structp pp = ppIn;
......@@ -1121,7 +1121,7 @@ store_write(png_structp ppIn, png_bytep pb, png_size_t st)
}
}
static void
static void PNGCBAPI
store_flush(png_structp ppIn)
{
UNUSED(ppIn) /*DOES NOTHING*/
......@@ -1215,7 +1215,7 @@ store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
}
}
static void
static void PNGCBAPI
store_read(png_structp ppIn, png_bytep pb, png_size_t st)
{
png_const_structp pp = ppIn;
......@@ -1408,7 +1408,7 @@ store_pool_delete(png_store *ps, store_pool *pool)
}
/* The memory callbacks: */
static png_voidp
static png_voidp PNGCBAPI
store_malloc(png_structp ppIn, png_alloc_size_t cb)
{
png_const_structp pp = ppIn;
......@@ -1457,7 +1457,7 @@ store_malloc(png_structp ppIn, png_alloc_size_t cb)
return new;
}
static void
static void PNGCBAPI
store_free(png_structp ppIn, png_voidp memory)
{
png_const_structp pp = ppIn;
......@@ -2676,7 +2676,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
}
/* The callback: */
static void
static void PNGCBAPI
modifier_read(png_structp ppIn, png_bytep pb, png_size_t st)
{
png_const_structp pp = ppIn;
......@@ -4680,7 +4680,7 @@ standard_info_imp(standard_display *dp, png_structp pp, png_infop pi,
standard_info_part2(dp, pp, pi, nImages);
}
static void
static void PNGCBAPI
standard_info(png_structp pp, png_infop pi)
{
standard_display *dp = voidcast(standard_display*,
......@@ -4692,7 +4692,7 @@ standard_info(png_structp pp, png_infop pi)
standard_info_imp(dp, pp, pi, 1 /*only one image*/);
}
static void
static void PNGCBAPI
progressive_row(png_structp ppIn, png_bytep new_row, png_uint_32 y, int pass)
{
png_const_structp pp = ppIn;
......@@ -5006,7 +5006,7 @@ standard_image_validate(standard_display *dp, png_const_structp pp, int iImage,
dp->ps->validated = 1;
}
static void
static void PNGCBAPI
standard_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
......@@ -5841,7 +5841,7 @@ transform_info_imp(transform_display *dp, png_structp pp, png_infop pi)
}
}
static void
static void PNGCBAPI
transform_info(png_structp pp, png_infop pi)
{
transform_info_imp(voidcast(transform_display*, png_get_progressive_ptr(pp)),
......@@ -6048,7 +6048,7 @@ transform_image_validate(transform_display *dp, png_const_structp pp,
dp->this.ps->validated = 1;
}
static void
static void PNGCBAPI
transform_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
......@@ -7865,7 +7865,7 @@ gamma_info_imp(gamma_display *dp, png_structp pp, png_infop pi)
standard_info_part2(&dp->this, pp, pi, 1 /*images*/);
}
static void
static void PNGCBAPI
gamma_info(png_structp pp, png_infop pi)
{
gamma_info_imp(voidcast(gamma_display*, png_get_progressive_ptr(pp)), pp,
......@@ -8829,7 +8829,7 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
dp->this.ps->validated = 1;
}
static void
static void PNGCBAPI
gamma_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
......
......@@ -3159,13 +3159,13 @@ read_chunk(struct file *file)
/* This returns a file* from a png_struct in an implementation specific way. */
static struct file *get_control(png_const_structrp png_ptr);
static void
static void PNGCBAPI
error_handler(png_structp png_ptr, png_const_charp message)
{
stop(get_control(png_ptr), LIBPNG_ERROR_CODE, message);
}
static void
static void PNGCBAPI
warning_handler(png_structp png_ptr, png_const_charp message)
{
struct file *file = get_control(png_ptr);
......@@ -3177,7 +3177,7 @@ warning_handler(png_structp png_ptr, png_const_charp message)
/* Read callback - this is where the work gets done to check the stream before
* passing it to libpng
*/
static void
static void PNGCBAPI
read_callback(png_structp png_ptr, png_bytep buffer, size_t count)
/* Return 'count' bytes to libpng in 'buffer' */
{
......
......@@ -2520,11 +2520,15 @@ PNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr,
#ifdef PNG_INFO_IMAGE_SUPPORTED
/* The "params" pointer is currently not used and is for future expansion. */
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr,
int transforms, png_voidp params));
#endif
#ifdef PNG_WRITE_SUPPORTED
PNG_EXPORT(179, void, png_write_png, (png_structrp png_ptr, png_inforp info_ptr,
int transforms, png_voidp params));
#endif
#endif
PNG_EXPORT(180, png_const_charp, png_get_copyright,
(png_const_structrp png_ptr));
......
......@@ -876,8 +876,8 @@ png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
* possible to implement without setjmp support just so long as there is some
* way to handle the error return here:
*/
PNG_FUNCTION(void /* PRIVATE */,
png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
PNG_NORETURN)
{
const png_const_structrp png_ptr = png_nonconst_ptr;
......@@ -912,7 +912,7 @@ png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
}
#ifdef PNG_WARNINGS_SUPPORTED
void /* PRIVATE */
void /* PRIVATE */ PNGCBAPI
png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
{
const png_const_structrp png_ptr = png_nonconst_ptr;
......
......@@ -254,6 +254,11 @@
extern PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)
#endif
#ifndef PNG_INTERNAL_CALLBACK
# define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\
extern PNG_FUNCTION(type, (PNGCBAPI name), args, PNG_EMPTY attributes)
#endif
/* If floating or fixed point APIs are disabled they may still be compiled
* internally. To handle this make sure they are declared as the appropriate
* internal extern function (otherwise the symbol prefixing stuff won't work and
......@@ -1883,11 +1888,11 @@ typedef struct png_control
* errors that might occur. Returns true on success, false on failure (either
* of the function or as a result of a png_error.)
*/
PNG_INTERNAL_FUNCTION(void,png_safe_error,(png_structp png_ptr,
PNG_INTERNAL_CALLBACK(void,png_safe_error,(png_structp png_ptr,
png_const_charp error_message),PNG_NORETURN);
#ifdef PNG_WARNINGS_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_safe_warning,(png_structp png_ptr,
PNG_INTERNAL_CALLBACK(void,png_safe_warning,(png_structp png_ptr,
png_const_charp warning_message),PNG_EMPTY);
#else
# define png_safe_warning 0/*dummy argument*/
......
......@@ -1001,8 +1001,6 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
int transforms,
voidp params)
{
int row;
if (png_ptr == NULL || info_ptr == NULL)
return;
......@@ -1014,120 +1012,149 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
png_error(png_ptr, "Image is too high to process with png_read_png()");
/* -------------- image transformations start here ------------------- */
/* libpng 1.6.10: add code to cause a png_app_error if a selected TRANSFORM
* is not implemented. This will only happen in de-configured (non-default)
* libpng builds. The results can be unexpected - png_read_png may return
* short or mal-formed rows because the transform is skipped.
*/
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
/* Tell libpng to strip 16-bit/color files down to 8 bits per color.
*/
if (transforms & PNG_TRANSFORM_SCALE_16)
{
/* Added at libpng-1.5.4. "strip_16" produces the same result that it
* did in earlier versions, while "scale_16" is now more accurate.
*/
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png_ptr);
}
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SCALE_16 not supported");
#endif
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
/* If both SCALE and STRIP are required pngrtran will effectively cancel the
* latter by doing SCALE first. This is ok and allows apps not to check for
* which is supported to get the right answer.
*/
if (transforms & PNG_TRANSFORM_STRIP_16)
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
png_set_strip_16(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_16 not supported");
#endif
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
/* Strip alpha bytes from the input data without combining with
* the background (not recommended).
*/
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
png_set_strip_alpha(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_ALPHA not supported");
#endif
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
/* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
if (transforms & PNG_TRANSFORM_PACKING)
#ifdef PNG_READ_PACK_SUPPORTED
png_set_packing(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported");
#endif
#ifdef PNG_READ_PACKSWAP_SUPPORTED
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing).
*/
if (transforms & PNG_TRANSFORM_PACKSWAP)
#ifdef PNG_READ_PACKSWAP_SUPPORTED
png_set_packswap(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported");
#endif
#ifdef PNG_READ_EXPAND_SUPPORTED
/* Expand paletted colors into true RGB triplets
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
* Expand paletted or RGB images with transparency to full alpha
* channels so the data will be available as RGBA quartets.
*/
if (transforms & PNG_TRANSFORM_EXPAND)
if ((png_ptr->bit_depth < 8) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
(info_ptr->valid & PNG_INFO_tRNS))
png_set_expand(png_ptr);
#ifdef PNG_READ_EXPAND_SUPPORTED
png_set_expand(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND not supported");
#endif
/* We don't handle background color or gamma transformation or quantizing.
*/
#ifdef PNG_READ_INVERT_SUPPORTED
/* Invert monochrome files to have 0 as white and 1 as black
*/
if (transforms & PNG_TRANSFORM_INVERT_MONO)
#ifdef PNG_READ_INVERT_SUPPORTED
png_set_invert_mono(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported");
#endif
#ifdef PNG_READ_SHIFT_SUPPORTED
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if ((transforms & PNG_TRANSFORM_SHIFT) && (info_ptr->valid & PNG_INFO_sBIT))
png_set_shift(png_ptr, &info_ptr->sig_bit);
if (transforms & PNG_TRANSFORM_SHIFT)
#ifdef PNG_READ_SHIFT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sBIT)
png_set_shift(png_ptr, &info_ptr->sig_bit);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
#endif
#ifdef PNG_READ_BGR_SUPPORTED
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
if (transforms & PNG_TRANSFORM_BGR)
#ifdef PNG_READ_BGR_SUPPORTED
png_set_bgr(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported");
#endif
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
png_set_swap_alpha(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported");
#endif
#ifdef PNG_READ_SWAP_SUPPORTED
/* Swap bytes of 16-bit files to least significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
#ifdef PNG_READ_SWAP_SUPPORTED
png_set_swap(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
#endif
/* Added at libpng-1.2.41 */
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
png_set_invert_alpha(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported");
#endif
/* Added at libpng-1.2.41 */
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
/* Expand grayscale image to RGB */
if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
png_set_gray_to_rgb(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_GRAY_TO_RGB not supported");
#endif
/* Added at libpng-1.5.4 */
#ifdef PNG_READ_EXPAND_16_SUPPORTED
if (transforms & PNG_TRANSFORM_EXPAND_16)
#ifdef PNG_READ_EXPAND_16_SUPPORTED
png_set_expand_16(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND_16 not supported");
#endif
/* We don't handle adding filler bytes */
......@@ -1150,16 +1177,17 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
{
png_uint_32 iptr;
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
info_ptr->height * (sizeof (png_bytep)));
info_ptr->row_pointers = png_voidcast(png_bytepp, png_malloc(png_ptr,
info_ptr->height * (sizeof (png_bytep))));
for (iptr=0; iptr<info_ptr->height; iptr++)
info_ptr->row_pointers[iptr] = NULL;
info_ptr->free_me |= PNG_FREE_ROWS;
for (row = 0; row < (int)info_ptr->height; row++)
info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr));
for (iptr = 0; iptr < info_ptr->height; iptr++)
info_ptr->row_pointers[iptr] = png_voidcast(png_bytep,
png_malloc(png_ptr, info_ptr->rowbytes));
}
png_read_image(png_ptr, info_ptr->row_pointers);
......@@ -1168,9 +1196,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
PNG_UNUSED(transforms) /* Quiet compiler warnings */
PNG_UNUSED(params)
}
#endif /* PNG_INFO_IMAGE_SUPPORTED */
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
......
......@@ -1363,12 +1363,12 @@ png_init_read_transformations(png_structrp png_ptr)
* 12) PNG_EXPAND_16
* 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
* 14) PNG_INVERT_MONO
* 15) PNG_SHIFT
* 16) PNG_PACK
* 17) PNG_BGR
* 18) PNG_PACKSWAP
* 19) PNG_FILLER (includes PNG_ADD_ALPHA)
* 20) PNG_INVERT_ALPHA
* 15) PNG_INVERT_ALPHA
* 16) PNG_SHIFT
* 17) PNG_PACK
* 18) PNG_BGR
* 19) PNG_PACKSWAP
* 20) PNG_FILLER (includes PNG_ADD_ALPHA)
* 21) PNG_SWAP_ALPHA
* 22) PNG_SWAP_BYTES
* 23) PNG_USER_TRANSFORM [must be last]
......@@ -4907,6 +4907,11 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
png_do_invert(row_info, png_ptr->row_buf + 1);
#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_SHIFT_SUPPORTED
if (png_ptr->transformations & PNG_SHIFT)
png_do_unshift(row_info, png_ptr->row_buf + 1,
......@@ -4941,11 +4946,6 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
(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);
......
......@@ -1112,13 +1112,12 @@ png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
void /* PRIVATE */
png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
unsigned int truelen;
unsigned int truelen, i;
png_byte sample_depth;
png_byte buf[4];
png_debug(1, "in png_handle_sBIT");
buf[0] = buf[1] = buf[2] = buf[3] = 0;
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_chunk_error(png_ptr, "missing IHDR");
......@@ -1137,10 +1136,16 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
truelen = 3;
sample_depth = 8;
}
else
{
truelen = png_ptr->channels;
sample_depth = png_ptr->bit_depth;
}
if (length != truelen || length > 4)
{
......@@ -1149,11 +1154,19 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
return;
}
buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;
png_crc_read(png_ptr, buf, truelen);
if (png_crc_finish(png_ptr, 0))
return;
for (i=0; i<truelen; ++i)
if (buf[i] == 0 || buf[i] > sample_depth)
{
png_chunk_benign_error(png_ptr, "invalid");
return;
}
if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
{
png_ptr->sig_bit.red = buf[0];
......
......@@ -1546,81 +1546,117 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
if ((info_ptr->valid & PNG_INFO_IDAT) == 0)
{
png_app_error(png_ptr, "no rows for png_write_image to write");
return;
}
/* Write the file header information. */
png_write_info(png_ptr, info_ptr);
/* ------ these transformations don't touch the info structure ------- */
#ifdef PNG_WRITE_INVERT_SUPPORTED
/* Invert monochrome pixels */
if (transforms & PNG_TRANSFORM_INVERT_MONO)
#ifdef PNG_WRITE_INVERT_SUPPORTED
png_set_invert_mono(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported");
#endif
#ifdef PNG_WRITE_SHIFT_SUPPORTED
/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
&& (info_ptr->valid & PNG_INFO_sBIT))
png_set_shift(png_ptr, &info_ptr->sig_bit);
if (transforms & PNG_TRANSFORM_SHIFT)
#ifdef PNG_WRITE_SHIFT_SUPPORTED
if (info_ptr->valid & PNG_INFO_sBIT)
png_set_shift(png_ptr, &info_ptr->sig_bit);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
#endif
#ifdef PNG_WRITE_PACK_SUPPORTED
/* Pack pixels into bytes */
if (transforms & PNG_TRANSFORM_PACKING)
png_set_packing(png_ptr);
#ifdef PNG_WRITE_PACK_SUPPORTED
png_set_packing(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported");
#endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
/* Swap location of alpha bytes from ARGB to RGBA */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
png_set_swap_alpha(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported");
#endif
/* Remove a filler (X) from XRGB/RGBX/AG/GA into to convert it into
* RGB, note that the code expects the input color type to be G or RGB; no
* alpha channel.
*/
if (transforms &
(PNG_TRANSFORM_STRIP_FILLER_AFTER|PNG_TRANSFORM_STRIP_FILLER_BEFORE))
{
#ifdef PNG_WRITE_FILLER_SUPPORTED
/* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */
if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
{
if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
png_app_error(png_ptr,
"PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported");
else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
/* Continue if ignored - this is the pre-1.6.10 behavior */
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
}
else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_FILLER not supported");
#endif
}
#ifdef PNG_WRITE_BGR_SUPPORTED
/* Flip BGR pixels to RGB */
if (transforms & PNG_TRANSFORM_BGR)
#ifdef PNG_WRITE_BGR_SUPPORTED
png_set_bgr(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported");
#endif
#ifdef PNG_WRITE_SWAP_SUPPORTED
/* Swap bytes of 16-bit files to most significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
#ifdef PNG_WRITE_SWAP_SUPPORTED
png_set_swap(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
#endif
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
/* Swap bits of 1, 2, 4 bit packed pixel formats */
if (transforms & PNG_TRANSFORM_PACKSWAP)
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
png_set_packswap(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported");
#endif
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
png_set_invert_alpha(png_ptr);
#else
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported");
#endif
/* ----------------------- end of transformations ------------------- */
/* Write the bits */
if (info_ptr->valid & PNG_INFO_IDAT)
png_write_image(png_ptr, info_ptr->row_pointers);
png_write_image(png_ptr, info_ptr->row_pointers);
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end(png_ptr, info_ptr);
PNG_UNUSED(transforms) /* Quiet compiler warnings */
PNG_UNUSED(params)
}
#endif
......
......@@ -15,5 +15,8 @@
#define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\
PNG_DFN "@" name "@"
#define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\
PNG_DFN "@" name "@"
#define PNGPREFIX_H /* self generation */
#include "../pngpriv.h"
#!/bin/sh
exec ./pngimage --exhaustive --log "${srcdir}/contrib/pngsuite/"*.png
#!/bin/sh
exec ./pngimage --log "${srcdir}/contrib/pngsuite/"*.png
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册