/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
- * libpng 1.2.7 - September 12, 2004
+ * Last changed in libpng 1.2.30 [August 15, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2004 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 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.)
*/
#define PNG_INTERNAL
#include "png.h"
+#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* turn on BGR-to-RGB mapping */
void PNGAPI
png_set_bgr(png_structp png_ptr)
{
- png_debug(1, "in png_set_bgr\n");
+ png_debug(1, "in png_set_bgr");
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_BGR;
}
#endif
void PNGAPI
png_set_swap(png_structp png_ptr)
{
- png_debug(1, "in png_set_swap\n");
+ png_debug(1, "in png_set_swap");
+ if (png_ptr == NULL) return;
if (png_ptr->bit_depth == 16)
png_ptr->transformations |= PNG_SWAP_BYTES;
}
void PNGAPI
png_set_packing(png_structp png_ptr)
{
- png_debug(1, "in png_set_packing\n");
+ png_debug(1, "in png_set_packing");
+ if (png_ptr == NULL) return;
if (png_ptr->bit_depth < 8)
{
png_ptr->transformations |= PNG_PACK;
void PNGAPI
png_set_packswap(png_structp png_ptr)
{
- png_debug(1, "in png_set_packswap\n");
+ png_debug(1, "in png_set_packswap");
+ if (png_ptr == NULL) return;
if (png_ptr->bit_depth < 8)
png_ptr->transformations |= PNG_PACKSWAP;
}
void PNGAPI
png_set_shift(png_structp png_ptr, png_color_8p true_bits)
{
- png_debug(1, "in png_set_shift\n");
+ png_debug(1, "in png_set_shift");
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_SHIFT;
png_ptr->shift = *true_bits;
}
int PNGAPI
png_set_interlace_handling(png_structp png_ptr)
{
- png_debug(1, "in png_set_interlace handling\n");
- if (png_ptr->interlaced)
+ png_debug(1, "in png_set_interlace handling");
+ if (png_ptr && png_ptr->interlaced)
{
png_ptr->transformations |= PNG_INTERLACE;
return (7);
void PNGAPI
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{
- png_debug(1, "in png_set_filler\n");
+ png_debug(1, "in png_set_filler");
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_FILLER;
png_ptr->filler = (png_byte)filler;
if (filler_loc == PNG_FILLER_AFTER)
void PNGAPI
png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{
- png_debug(1, "in png_set_add_alpha\n");
+ png_debug(1, "in png_set_add_alpha");
+ if (png_ptr == NULL) return;
png_set_filler(png_ptr, filler, filler_loc);
png_ptr->transformations |= PNG_ADD_ALPHA;
}
void PNGAPI
png_set_swap_alpha(png_structp png_ptr)
{
- png_debug(1, "in png_set_swap_alpha\n");
+ png_debug(1, "in png_set_swap_alpha");
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_SWAP_ALPHA;
}
#endif
void PNGAPI
png_set_invert_alpha(png_structp png_ptr)
{
- png_debug(1, "in png_set_invert_alpha\n");
+ png_debug(1, "in png_set_invert_alpha");
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_INVERT_ALPHA;
}
#endif
void PNGAPI
png_set_invert_mono(png_structp png_ptr)
{
- png_debug(1, "in png_set_invert_mono\n");
+ png_debug(1, "in png_set_invert_mono");
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_INVERT_MONO;
}
void /* PRIVATE */
png_do_invert(png_row_infop row_info, png_bytep row)
{
- png_debug(1, "in png_do_invert\n");
+ png_debug(1, "in png_do_invert");
/* This test removed from libpng version 1.0.13 and 1.2.0:
* if (row_info->bit_depth == 1 &&
*/
void /* PRIVATE */
png_do_swap(png_row_infop row_info, png_bytep row)
{
- png_debug(1, "in png_do_swap\n");
+ png_debug(1, "in png_do_swap");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
-static png_byte onebppswaptable[256] = {
+static PNG_CONST png_byte onebppswaptable[256] = {
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
-static png_byte twobppswaptable[256] = {
+static PNG_CONST png_byte twobppswaptable[256] = {
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
};
-static png_byte fourbppswaptable[256] = {
+static PNG_CONST png_byte fourbppswaptable[256] = {
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
void /* PRIVATE */
png_do_packswap(png_row_infop row_info, png_bytep row)
{
- png_debug(1, "in png_do_packswap\n");
+ png_debug(1, "in png_do_packswap");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
end = row + row_info->rowbytes;
if (row_info->bit_depth == 1)
- table = onebppswaptable;
+ table = (png_bytep)onebppswaptable;
else if (row_info->bit_depth == 2)
- table = twobppswaptable;
+ table = (png_bytep)twobppswaptable;
else if (row_info->bit_depth == 4)
- table = fourbppswaptable;
+ table = (png_bytep)fourbppswaptable;
else
return;
void /* PRIVATE */
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
{
- png_debug(1, "in png_do_strip_filler\n");
+ png_debug(1, "in png_do_strip_filler");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
png_uint_32 row_width=row_info->width;
png_uint_32 i;
- if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
+ if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
+ (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
+ (flags & PNG_FLAG_STRIP_ALPHA))) &&
row_info->channels == 4)
{
if (row_info->bit_depth == 8)
}
row_info->channels = 3;
}
- else if (row_info->color_type == PNG_COLOR_TYPE_GRAY &&
+ else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
+ (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
+ (flags & PNG_FLAG_STRIP_ALPHA))) &&
row_info->channels == 2)
{
if (row_info->bit_depth == 8)
}
row_info->channels = 1;
}
+ if (flags & PNG_FLAG_STRIP_ALPHA)
+ row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
}
}
#endif
void /* PRIVATE */
png_do_bgr(png_row_infop row_info, png_bytep row)
{
- png_debug(1, "in png_do_bgr\n");
+ png_debug(1, "in png_do_bgr");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
png_set_user_transform_info(png_structp png_ptr, png_voidp
user_transform_ptr, int user_transform_depth, int user_transform_channels)
{
- png_debug(1, "in png_set_user_transform_info\n");
+ png_debug(1, "in png_set_user_transform_info");
+ if (png_ptr == NULL) return;
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
png_ptr->user_transform_ptr = user_transform_ptr;
png_ptr->user_transform_depth = (png_byte)user_transform_depth;
png_ptr->user_transform_channels = (png_byte)user_transform_channels;
#else
- if(user_transform_ptr || user_transform_depth || user_transform_channels)
+ if (user_transform_ptr || user_transform_depth || user_transform_channels)
png_warning(png_ptr,
"This version of libpng does not support user transform info");
#endif
png_voidp PNGAPI
png_get_user_transform_ptr(png_structp png_ptr)
{
+ if (png_ptr == NULL) return (NULL);
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
return ((png_voidp)png_ptr->user_transform_ptr);
#else
- if(png_ptr)
- return (NULL);
return (NULL);
#endif
}
+#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */