X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/75b6e0a0aba793c6b739689b4414c1a2d8fcb041..d3e780ecdf69233c872d51216eedbc64a1b6db25:/src/png/pngwtran.c diff --git a/src/png/pngwtran.c b/src/png/pngwtran.c index 76cf3a3e5d..1ce2a6d447 100644 --- a/src/png/pngwtran.c +++ b/src/png/pngwtran.c @@ -1,24 +1,28 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * libpng 1.0.3 - January 14, 1999 + * libpng 1.2.5rc3 - September 18, 2002 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. - * Copyright (c) 1996, 1997 Andreas Dilger - * Copyright (c) 1998, 1999 Glenn Randers-Pehrson + * Copyright (c) 1998-2002 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" +#ifdef PNG_WRITE_SUPPORTED /* Transform the data according to the user's wishes. The order of * transformations is significant. */ -void +void /* PRIVATE */ png_do_write_transformations(png_structp png_ptr) { png_debug(1, "in png_do_write_transformations\n"); + if (png_ptr == NULL) + return; + #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) if (png_ptr->transformations & PNG_USER_TRANSFORM) if(png_ptr->write_user_transform_fn != NULL) @@ -79,7 +83,7 @@ png_do_write_transformations(png_structp png_ptr) * 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 +void /* PRIVATE */ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) { png_debug(1, "in png_do_pack\n"); @@ -137,7 +141,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) { png_byte value; - value = (png_byte)(*sp & 0x3); + value = (png_byte)(*sp & 0x03); v |= (value << shift); if (shift == 0) { @@ -169,7 +173,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) { png_byte value; - value = (png_byte)(*sp & 0xf); + value = (png_byte)(*sp & 0x0f); v |= (value << shift); if (shift == 0) @@ -205,7 +209,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 +void /* PRIVATE */ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) { png_debug(1, "in png_do_shift\n"); @@ -311,7 +315,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) png_uint_16 value, v; int j; - v = ((png_uint_16)(*bp) << 8) + *(bp + 1); + v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); value = 0; for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) { @@ -329,7 +333,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) #endif #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) -void +void /* PRIVATE */ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_write_swap_alpha\n"); @@ -417,7 +421,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) #endif #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) -void +void /* PRIVATE */ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { png_debug(1, "in png_do_write_invert_alpha\n"); @@ -438,7 +442,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) *(dp++) = *(sp++); *(dp++) = *(sp++); *(dp++) = *(sp++); - *(dp++) = 255 - *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); } } /* This inverts the alpha channel in RRGGBBAA */ @@ -456,8 +460,8 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) *(dp++) = *(sp++); *(dp++) = *(sp++); *(dp++) = *(sp++); - *(dp++) = 255 - *(sp++); - *(dp++) = 255 - *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); } } } @@ -473,7 +477,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) for (i = 0, sp = dp = row; i < row_width; i++) { *(dp++) = *(sp++); - *(dp++) = 255 - *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); } } /* This inverts the alpha channel in GGAA */ @@ -487,11 +491,73 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { *(dp++) = *(sp++); *(dp++) = *(sp++); - *(dp++) = 255 - *(sp++); - *(dp++) = 255 - *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); } } } } } #endif + +#if defined(PNG_MNG_FEATURES_SUPPORTED) +/* undoes intrapixel differencing */ +void /* PRIVATE */ +png_do_write_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_intrapixel\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + (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); + } + } + 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)&0xffff; + png_uint_32 blue=(s2-s1)&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 */ +#endif /* PNG_WRITE_SUPPORTED */