mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng17] 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.
This commit is contained in:
parent
3d7f3bbab7
commit
fb1305faeb
12
ANNOUNCE
12
ANNOUNCE
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Libpng 1.7.0beta31 - February 5, 2014
|
Libpng 1.7.0beta31 - February 6, 2014
|
||||||
|
|
||||||
This is not intended to be a public release. It will be replaced
|
This is not intended to be a public release. It will be replaced
|
||||||
within a few weeks by a public version or by another test version.
|
within a few weeks by a public version or by another test version.
|
||||||
@ -504,7 +504,7 @@ Version 1.7.0beta30 [February 2, 2014]
|
|||||||
the program by virtue of exhaustively testing all the transforms is
|
the program by virtue of exhaustively testing all the transforms is
|
||||||
very slow.
|
very slow.
|
||||||
|
|
||||||
Version 1.7.0beta31 [February 5, 2014]
|
Version 1.7.0beta31 [February 6, 2014]
|
||||||
Make png_read_png() and png_write_png() prototypes in png.h depend
|
Make png_read_png() and png_write_png() prototypes in png.h depend
|
||||||
upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
|
upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
|
||||||
Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
|
Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
|
||||||
@ -524,6 +524,14 @@ Version 1.7.0beta31 [February 5, 2014]
|
|||||||
PAETH filtering code from libpng-1.7.0beta24/pngrutil.c. Deleted
|
PAETH filtering code from libpng-1.7.0beta24/pngrutil.c. Deleted
|
||||||
the other instance of "c = b;" which is the one that triggered a
|
the other instance of "c = b;" which is the one that triggered a
|
||||||
scan-build warning.
|
scan-build warning.
|
||||||
|
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
|
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||||
(subscription required; visit
|
(subscription required; visit
|
||||||
|
10
CHANGES
10
CHANGES
@ -4793,7 +4793,7 @@ Version 1.7.0beta30 [February 2, 2014]
|
|||||||
the program by virtue of exhaustively testing all the transforms is
|
the program by virtue of exhaustively testing all the transforms is
|
||||||
very slow.
|
very slow.
|
||||||
|
|
||||||
Version 1.7.0beta31 [February 5, 2014]
|
Version 1.7.0beta31 [February 6, 2014]
|
||||||
Make png_read_png() and png_write_png() prototypes in png.h depend
|
Make png_read_png() and png_write_png() prototypes in png.h depend
|
||||||
upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
|
upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
|
||||||
Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
|
Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
|
||||||
@ -4813,6 +4813,14 @@ Version 1.7.0beta31 [February 5, 2014]
|
|||||||
PAETH filtering code from libpng-1.7.0beta24/pngrutil.c. Deleted
|
PAETH filtering code from libpng-1.7.0beta24/pngrutil.c. Deleted
|
||||||
the other instance of "c = b;" which is the one that triggered a
|
the other instance of "c = b;" which is the one that triggered a
|
||||||
scan-build warning.
|
scan-build warning.
|
||||||
|
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
|
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||||
(subscription required; visit
|
(subscription required; visit
|
||||||
|
12
png.h
12
png.h
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
/* png.h - header file for PNG reference library
|
/* png.h - header file for PNG reference library
|
||||||
*
|
*
|
||||||
* libpng version 1.7.0beta31 - February 5, 2014
|
* libpng version 1.7.0beta31 - February 6, 2014
|
||||||
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
|
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
|
||||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||||
@ -11,7 +11,7 @@
|
|||||||
* Authors and maintainers:
|
* Authors and maintainers:
|
||||||
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
|
* 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.89c, June 1996, through 0.96, May 1997: Andreas Dilger
|
||||||
* libpng versions 0.97, January 1998, through 1.7.0beta31 - February 5, 2014: Glenn
|
* libpng versions 0.97, January 1998, through 1.7.0beta31 - February 6, 2014: Glenn
|
||||||
* See also "Contributing Authors", below.
|
* See also "Contributing Authors", below.
|
||||||
*
|
*
|
||||||
* Note about libpng version numbers:
|
* Note about libpng version numbers:
|
||||||
@ -200,7 +200,7 @@
|
|||||||
*
|
*
|
||||||
* This code is released under the libpng license.
|
* This code is released under the libpng license.
|
||||||
*
|
*
|
||||||
* libpng versions 1.2.6, August 15, 2004, through 1.7.0beta31, February 5, 2014, are
|
* libpng versions 1.2.6, August 15, 2004, through 1.7.0beta31, February 6, 2014, are
|
||||||
* Copyright (c) 2004, 2006-2013 Glenn Randers-Pehrson, and are
|
* Copyright (c) 2004, 2006-2013 Glenn Randers-Pehrson, and are
|
||||||
* distributed according to the same disclaimer and license as libpng-1.2.5
|
* distributed according to the same disclaimer and license as libpng-1.2.5
|
||||||
* with the following individual added to the list of Contributing Authors:
|
* with the following individual added to the list of Contributing Authors:
|
||||||
@ -312,7 +312,7 @@
|
|||||||
* Y2K compliance in libpng:
|
* Y2K compliance in libpng:
|
||||||
* =========================
|
* =========================
|
||||||
*
|
*
|
||||||
* February 5, 2014
|
* February 6, 2014
|
||||||
*
|
*
|
||||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||||
* an official declaration.
|
* an official declaration.
|
||||||
@ -380,7 +380,7 @@
|
|||||||
/* Version information for png.h - this should match the version in png.c */
|
/* Version information for png.h - this should match the version in png.c */
|
||||||
#define PNG_LIBPNG_VER_STRING "1.7.0beta31"
|
#define PNG_LIBPNG_VER_STRING "1.7.0beta31"
|
||||||
#define PNG_HEADER_VERSION_STRING \
|
#define PNG_HEADER_VERSION_STRING \
|
||||||
" libpng version 1.7.0beta31 - February 5, 2014\n"
|
" libpng version 1.7.0beta31 - February 6, 2014\n"
|
||||||
|
|
||||||
#define PNG_LIBPNG_VER_SONUM 17
|
#define PNG_LIBPNG_VER_SONUM 17
|
||||||
#define PNG_LIBPNG_VER_DLLNUM 17
|
#define PNG_LIBPNG_VER_DLLNUM 17
|
||||||
@ -2620,7 +2620,7 @@ PNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr,
|
|||||||
|
|
||||||
#ifdef PNG_INFO_IMAGE_SUPPORTED
|
#ifdef PNG_INFO_IMAGE_SUPPORTED
|
||||||
/* The "params" pointer is currently not used and is for future expansion. */
|
/* The "params" pointer is currently not used and is for future expansion. */
|
||||||
#ifdef PNG_READ_SUPPORTED
|
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||||
PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr,
|
PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr,
|
||||||
int transforms, png_voidp params));
|
int transforms, png_voidp params));
|
||||||
#endif
|
#endif
|
||||||
|
84
pngread.c
84
pngread.c
@ -1001,8 +1001,6 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
|
|||||||
int transforms,
|
int transforms,
|
||||||
voidp params)
|
voidp params)
|
||||||
{
|
{
|
||||||
int row;
|
|
||||||
|
|
||||||
if (png_ptr == NULL || info_ptr == NULL)
|
if (png_ptr == NULL || info_ptr == NULL)
|
||||||
return;
|
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()");
|
png_error(png_ptr, "Image is too high to process with png_read_png()");
|
||||||
|
|
||||||
/* -------------- image transformations start here ------------------- */
|
/* -------------- 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.
|
/* Tell libpng to strip 16-bit/color files down to 8 bits per color.
|
||||||
*/
|
*/
|
||||||
if (transforms & PNG_TRANSFORM_SCALE_16)
|
if (transforms & PNG_TRANSFORM_SCALE_16)
|
||||||
{
|
|
||||||
/* Added at libpng-1.5.4. "strip_16" produces the same result that it
|
/* 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.
|
* 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);
|
png_set_scale_16(png_ptr);
|
||||||
}
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_SCALE_16 not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
|
|
||||||
/* If both SCALE and STRIP are required pngrtran will effectively cancel the
|
/* 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
|
* latter by doing SCALE first. This is ok and allows apps not to check for
|
||||||
* which is supported to get the right answer.
|
* which is supported to get the right answer.
|
||||||
*/
|
*/
|
||||||
if (transforms & PNG_TRANSFORM_STRIP_16)
|
if (transforms & PNG_TRANSFORM_STRIP_16)
|
||||||
|
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
|
||||||
png_set_strip_16(png_ptr);
|
png_set_strip_16(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_16 not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
|
||||||
/* Strip alpha bytes from the input data without combining with
|
/* Strip alpha bytes from the input data without combining with
|
||||||
* the background (not recommended).
|
* the background (not recommended).
|
||||||
*/
|
*/
|
||||||
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
|
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
|
||||||
|
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||||
png_set_strip_alpha(png_ptr);
|
png_set_strip_alpha(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_ALPHA not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PNG_READ_PACK_SUPPORTED)
|
|
||||||
/* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
|
/* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
|
||||||
* byte into separate bytes (useful for paletted and grayscale images).
|
* byte into separate bytes (useful for paletted and grayscale images).
|
||||||
*/
|
*/
|
||||||
if (transforms & PNG_TRANSFORM_PACKING)
|
if (transforms & PNG_TRANSFORM_PACKING)
|
||||||
|
#ifdef PNG_READ_PACK_SUPPORTED
|
||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
|
||||||
/* Change the order of packed pixels to least significant bit first
|
/* Change the order of packed pixels to least significant bit first
|
||||||
* (not useful if you are using png_set_packing).
|
* (not useful if you are using png_set_packing).
|
||||||
*/
|
*/
|
||||||
if (transforms & PNG_TRANSFORM_PACKSWAP)
|
if (transforms & PNG_TRANSFORM_PACKSWAP)
|
||||||
|
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
||||||
png_set_packswap(png_ptr);
|
png_set_packswap(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
|
||||||
/* Expand paletted colors into true RGB triplets
|
/* Expand paletted colors into true RGB triplets
|
||||||
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
|
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
|
||||||
* Expand paletted or RGB images with transparency to full alpha
|
* Expand paletted or RGB images with transparency to full alpha
|
||||||
* channels so the data will be available as RGBA quartets.
|
* channels so the data will be available as RGBA quartets.
|
||||||
*/
|
*/
|
||||||
if (transforms & PNG_TRANSFORM_EXPAND)
|
if (transforms & PNG_TRANSFORM_EXPAND)
|
||||||
if ((png_ptr->bit_depth < 8) ||
|
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
|
|
||||||
(info_ptr->valid & PNG_INFO_tRNS))
|
|
||||||
png_set_expand(png_ptr);
|
png_set_expand(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* We don't handle background color or gamma transformation or quantizing.
|
/* 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
|
/* Invert monochrome files to have 0 as white and 1 as black
|
||||||
*/
|
*/
|
||||||
if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
||||||
|
#ifdef PNG_READ_INVERT_SUPPORTED
|
||||||
png_set_invert_mono(png_ptr);
|
png_set_invert_mono(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_SHIFT_SUPPORTED
|
|
||||||
/* If you want to shift the pixel values from the range [0,255] or
|
/* 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
|
* [0,65535] to the original [0,7] or [0,31], or whatever range the
|
||||||
* colors were originally in:
|
* colors were originally in:
|
||||||
*/
|
*/
|
||||||
if ((transforms & PNG_TRANSFORM_SHIFT) && (info_ptr->valid & PNG_INFO_sBIT))
|
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);
|
png_set_shift(png_ptr, &info_ptr->sig_bit);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_BGR_SUPPORTED
|
|
||||||
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
|
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
|
||||||
if (transforms & PNG_TRANSFORM_BGR)
|
if (transforms & PNG_TRANSFORM_BGR)
|
||||||
|
#ifdef PNG_READ_BGR_SUPPORTED
|
||||||
png_set_bgr(png_ptr);
|
png_set_bgr(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
|
|
||||||
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
||||||
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
||||||
|
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
|
||||||
png_set_swap_alpha(png_ptr);
|
png_set_swap_alpha(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_READ_SWAP_SUPPORTED
|
|
||||||
/* Swap bytes of 16-bit files to least significant byte first */
|
/* Swap bytes of 16-bit files to least significant byte first */
|
||||||
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
||||||
|
#ifdef PNG_READ_SWAP_SUPPORTED
|
||||||
png_set_swap(png_ptr);
|
png_set_swap(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Added at libpng-1.2.41 */
|
/* Added at libpng-1.2.41 */
|
||||||
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
|
|
||||||
/* Invert the alpha channel from opacity to transparency */
|
/* Invert the alpha channel from opacity to transparency */
|
||||||
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
||||||
|
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
|
||||||
png_set_invert_alpha(png_ptr);
|
png_set_invert_alpha(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Added at libpng-1.2.41 */
|
/* Added at libpng-1.2.41 */
|
||||||
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
|
||||||
/* Expand grayscale image to RGB */
|
/* Expand grayscale image to RGB */
|
||||||
if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
|
if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
|
||||||
|
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||||
png_set_gray_to_rgb(png_ptr);
|
png_set_gray_to_rgb(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_GRAY_TO_RGB not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Added at libpng-1.5.4 */
|
/* Added at libpng-1.5.4 */
|
||||||
#ifdef PNG_READ_EXPAND_16_SUPPORTED
|
|
||||||
if (transforms & PNG_TRANSFORM_EXPAND_16)
|
if (transforms & PNG_TRANSFORM_EXPAND_16)
|
||||||
|
#ifdef PNG_READ_EXPAND_16_SUPPORTED
|
||||||
png_set_expand_16(png_ptr);
|
png_set_expand_16(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND_16 not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* We don't handle adding filler bytes */
|
/* 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;
|
png_uint_32 iptr;
|
||||||
|
|
||||||
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
|
info_ptr->row_pointers = png_voidcast(png_bytepp, png_malloc(png_ptr,
|
||||||
info_ptr->height * (sizeof (png_bytep)));
|
info_ptr->height * (sizeof (png_bytep))));
|
||||||
|
|
||||||
for (iptr=0; iptr<info_ptr->height; iptr++)
|
for (iptr=0; iptr<info_ptr->height; iptr++)
|
||||||
info_ptr->row_pointers[iptr] = NULL;
|
info_ptr->row_pointers[iptr] = NULL;
|
||||||
|
|
||||||
info_ptr->free_me |= PNG_FREE_ROWS;
|
info_ptr->free_me |= PNG_FREE_ROWS;
|
||||||
|
|
||||||
for (row = 0; row < (int)info_ptr->height; row++)
|
for (iptr = 0; iptr < info_ptr->height; iptr++)
|
||||||
info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
|
info_ptr->row_pointers[iptr] = png_voidcast(png_bytep,
|
||||||
png_get_rowbytes(png_ptr, info_ptr));
|
png_malloc(png_ptr, info_ptr->rowbytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
png_read_image(png_ptr, info_ptr->row_pointers);
|
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 */
|
/* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||||
png_read_end(png_ptr, info_ptr);
|
png_read_end(png_ptr, info_ptr);
|
||||||
|
|
||||||
PNG_UNUSED(transforms) /* Quiet compiler warnings */
|
|
||||||
PNG_UNUSED(params)
|
PNG_UNUSED(params)
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /* PNG_INFO_IMAGE_SUPPORTED */
|
#endif /* PNG_INFO_IMAGE_SUPPORTED */
|
||||||
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
|
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
|
||||||
|
62
pngwrite.c
62
pngwrite.c
@ -1532,81 +1532,117 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
|
|||||||
if (png_ptr == NULL || info_ptr == NULL)
|
if (png_ptr == NULL || info_ptr == NULL)
|
||||||
return;
|
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. */
|
/* Write the file header information. */
|
||||||
png_write_info(png_ptr, info_ptr);
|
png_write_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
/* ------ these transformations don't touch the info structure ------- */
|
/* ------ these transformations don't touch the info structure ------- */
|
||||||
|
|
||||||
#ifdef PNG_WRITE_INVERT_SUPPORTED
|
|
||||||
/* Invert monochrome pixels */
|
/* Invert monochrome pixels */
|
||||||
if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
||||||
|
#ifdef PNG_WRITE_INVERT_SUPPORTED
|
||||||
png_set_invert_mono(png_ptr);
|
png_set_invert_mono(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
|
||||||
/* Shift the pixels up to a legal bit depth and fill in
|
/* Shift the pixels up to a legal bit depth and fill in
|
||||||
* as appropriate to correctly scale the image.
|
* as appropriate to correctly scale the image.
|
||||||
*/
|
*/
|
||||||
if ((transforms & PNG_TRANSFORM_SHIFT)
|
if (transforms & PNG_TRANSFORM_SHIFT)
|
||||||
&& (info_ptr->valid & PNG_INFO_sBIT))
|
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||||
|
if (info_ptr->valid & PNG_INFO_sBIT)
|
||||||
png_set_shift(png_ptr, &info_ptr->sig_bit);
|
png_set_shift(png_ptr, &info_ptr->sig_bit);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
|
||||||
/* Pack pixels into bytes */
|
/* Pack pixels into bytes */
|
||||||
if (transforms & PNG_TRANSFORM_PACKING)
|
if (transforms & PNG_TRANSFORM_PACKING)
|
||||||
|
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
|
||||||
/* Swap location of alpha bytes from ARGB to RGBA */
|
/* Swap location of alpha bytes from ARGB to RGBA */
|
||||||
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
||||||
|
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||||
png_set_swap_alpha(png_ptr);
|
png_set_swap_alpha(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported");
|
||||||
#endif
|
#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
|
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||||
/* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */
|
|
||||||
if (transforms & PNG_TRANSFORM_STRIP_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");
|
||||||
|
|
||||||
|
/* Continue if ignored - this is the pre-1.6.10 behavior */
|
||||||
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
|
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
|
||||||
|
}
|
||||||
|
|
||||||
else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
|
else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
|
||||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_FILLER not supported");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PNG_WRITE_BGR_SUPPORTED
|
|
||||||
/* Flip BGR pixels to RGB */
|
/* Flip BGR pixels to RGB */
|
||||||
if (transforms & PNG_TRANSFORM_BGR)
|
if (transforms & PNG_TRANSFORM_BGR)
|
||||||
|
#ifdef PNG_WRITE_BGR_SUPPORTED
|
||||||
png_set_bgr(png_ptr);
|
png_set_bgr(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
|
||||||
/* Swap bytes of 16-bit files to most significant byte first */
|
/* Swap bytes of 16-bit files to most significant byte first */
|
||||||
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
||||||
|
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||||
png_set_swap(png_ptr);
|
png_set_swap(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
|
||||||
/* Swap bits of 1, 2, 4 bit packed pixel formats */
|
/* Swap bits of 1, 2, 4 bit packed pixel formats */
|
||||||
if (transforms & PNG_TRANSFORM_PACKSWAP)
|
if (transforms & PNG_TRANSFORM_PACKSWAP)
|
||||||
|
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||||
png_set_packswap(png_ptr);
|
png_set_packswap(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
|
||||||
/* Invert the alpha channel from opacity to transparency */
|
/* Invert the alpha channel from opacity to transparency */
|
||||||
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
||||||
|
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||||
png_set_invert_alpha(png_ptr);
|
png_set_invert_alpha(png_ptr);
|
||||||
|
#else
|
||||||
|
png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ----------------------- end of transformations ------------------- */
|
/* ----------------------- end of transformations ------------------- */
|
||||||
|
|
||||||
/* Write the bits */
|
/* 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 */
|
/* It is REQUIRED to call this to finish writing the rest of the file */
|
||||||
png_write_end(png_ptr, info_ptr);
|
png_write_end(png_ptr, info_ptr);
|
||||||
|
|
||||||
PNG_UNUSED(transforms) /* Quiet compiler warnings */
|
|
||||||
PNG_UNUSED(params)
|
PNG_UNUSED(params)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user