X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0299c17dc878540bf190c290392db241b425ad..25889d3c43f537fea00a2b7d6df7bd7e63e113f8:/src/png/pngwtran.c diff --git a/src/png/pngwtran.c b/src/png/pngwtran.c index df224c88ee..76cf3a3e5d 100644 --- a/src/png/pngwtran.c +++ b/src/png/pngwtran.c @@ -1,18 +1,17 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * libpng 1.0.1 + * libpng 1.0.3 - January 14, 1999 * 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, Glenn Randers-Pehrson - * March 15, 1998 + * Copyright (c) 1998, 1999 Glenn Randers-Pehrson */ #define PNG_INTERNAL -#include "../png/png.h" +#include "png.h" -/* Transform the data according to the users wishes. The order of +/* Transform the data according to the user's wishes. The order of * transformations is significant. */ void @@ -48,15 +47,15 @@ png_do_write_transformations(png_structp png_ptr) png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1, (png_uint_32)png_ptr->bit_depth); #endif +#if defined(PNG_WRITE_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif #if defined(PNG_WRITE_SHIFT_SUPPORTED) if (png_ptr->transformations & PNG_SHIFT) png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, &(png_ptr->shift)); #endif -#if defined(PNG_WRITE_SWAP_SUPPORTED) - if (png_ptr->transformations & PNG_SWAP_BYTES) - png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); -#endif #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) if (png_ptr->transformations & PNG_INVERT_ALPHA) png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); @@ -97,12 +96,14 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) png_bytep sp, dp; int mask, v; png_uint_32 i; + png_uint_32 row_width = row_info->width; sp = row; dp = row; mask = 0x80; v = 0; - for (i = 0; i < row_info->width; i++) + + for (i = 0; i < row_width; i++) { if (*sp != 0) v |= mask; @@ -126,12 +127,13 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) png_bytep sp, dp; int shift, v; png_uint_32 i; + png_uint_32 row_width = row_info->width; sp = row; dp = row; shift = 6; v = 0; - for (i = 0; i < row_info->width; i++) + for (i = 0; i < row_width; i++) { png_byte value; @@ -157,12 +159,13 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) png_bytep sp, dp; int shift, v; png_uint_32 i; + png_uint_32 row_width = row_info->width; sp = row; dp = row; shift = 4; v = 0; - for (i = 0; i < row_info->width; i++) + for (i = 0; i < row_width; i++) { png_byte value; @@ -214,9 +217,8 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) row_info->color_type != PNG_COLOR_TYPE_PALETTE) { int shift_start[4], shift_dec[4]; - png_uint_32 channels; + int channels = 0; - channels = 0; if (row_info->color_type & PNG_COLOR_MASK_COLOR) { shift_start[channels] = row_info->bit_depth - bit_depth->red; @@ -245,9 +247,10 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) /* with low row depths, could only be grayscale, so one channel */ if (row_info->bit_depth < 8) { - png_bytep bp; + png_bytep bp = row; png_uint_32 i; png_byte mask; + png_uint_32 row_bytes = row_info->rowbytes; if (bit_depth->gray == 1 && row_info->bit_depth == 2) mask = 0x55; @@ -256,7 +259,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) else mask = 0xff; - for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++) + for (i = 0; i < row_bytes; i++, bp++) { png_uint_16 v; int j; @@ -274,27 +277,25 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) } else if (row_info->bit_depth == 8) { - png_bytep bp; + png_bytep bp = row; png_uint_32 i; + png_uint_32 istop = channels * row_info->width; - for (bp = row, i = 0; i < row_info->width; i++) + for (i = 0; i < istop; i++, bp++) { - png_uint_32 c; - for (c = 0; c < channels; c++, bp++) - { - png_uint_16 v; - int j; + png_uint_16 v; + int j; + int c = (int)(i%channels); - v = *bp; - *bp = 0; - for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) - { - if (j > 0) - *bp |= (png_byte)((v << j) & 0xff); - else - *bp |= (png_byte)((v >> (-j)) & 0xff); - } + v = *bp; + *bp = 0; + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + *bp |= (png_byte)((v << j) & 0xff); + else + *bp |= (png_byte)((v >> (-j)) & 0xff); } } } @@ -302,28 +303,25 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) { png_bytep bp; png_uint_32 i; + png_uint_32 istop = channels * row_info->width; - for (bp = row, i = 0; i < row_info->width * row_info->channels; i++) + for (bp = row, i = 0; i < istop; i++) { - png_uint_32 c; + int c = (int)(i%channels); + png_uint_16 value, v; + int j; - for (c = 0; c < channels; c++, bp += 2) + v = ((png_uint_16)(*bp) << 8) + *(bp + 1); + value = 0; + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) { - png_uint_16 value, v; - int j; - - v = ((png_uint_16)(*bp) << 8) + *(bp + 1); - value = 0; - for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) - { - if (j > 0) - value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); - else - value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); - } - *bp = (png_byte)(value >> 8); - *(bp + 1) = (png_byte)(value & 0xff); + if (j > 0) + value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); + else + value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); } + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)(value & 0xff); } } } @@ -345,12 +343,11 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) if (row_info->bit_depth == 8) { png_bytep sp, dp; - png_byte save; png_uint_32 i; - - for (i = 0, sp = dp = row; i < row_info->width; i++) + png_uint_32 row_width = row_info->width; + for (i = 0, sp = dp = row; i < row_width; i++) { - save = *(sp++); + png_byte save = *(sp++); *(dp++) = *(sp++); *(dp++) = *(sp++); *(dp++) = *(sp++); @@ -361,11 +358,12 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) else { png_bytep sp, dp; - png_byte save[2]; png_uint_32 i; + png_uint_32 row_width = row_info->width; - for (i = 0, sp = dp = row; i < row_info->width; i++) + for (i = 0, sp = dp = row; i < row_width; i++) { + png_byte save[2]; save[0] = *(sp++); save[1] = *(sp++); *(dp++) = *(sp++); @@ -385,12 +383,12 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) if (row_info->bit_depth == 8) { png_bytep sp, dp; - png_byte save; png_uint_32 i; + png_uint_32 row_width = row_info->width; - for (i = 0, sp = dp = row; i < row_info->width; i++) + for (i = 0, sp = dp = row; i < row_width; i++) { - save = *(sp++); + png_byte save = *(sp++); *(dp++) = *(sp++); *(dp++) = save; } @@ -399,11 +397,12 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) else { png_bytep sp, dp; - png_byte save[2]; png_uint_32 i; + png_uint_32 row_width = row_info->width; - for (i = 0, sp = dp = row; i < row_info->width; i++) + for (i = 0, sp = dp = row; i < row_width; i++) { + png_byte save[2]; save[0] = *(sp++); save[1] = *(sp++); *(dp++) = *(sp++); @@ -433,8 +432,8 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { png_bytep sp, dp; png_uint_32 i; - - for (i = 0, sp = dp = row; i < row_info->width; i++) + png_uint_32 row_width = row_info->width; + for (i = 0, sp = dp = row; i < row_width; i++) { *(dp++) = *(sp++); *(dp++) = *(sp++); @@ -447,8 +446,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { png_bytep sp, dp; png_uint_32 i; + png_uint_32 row_width = row_info->width; - for (i = 0, sp = dp = row; i < row_info->width; i++) + for (i = 0, sp = dp = row; i < row_width; i++) { *(dp++) = *(sp++); *(dp++) = *(sp++); @@ -468,8 +468,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { png_bytep sp, dp; png_uint_32 i; + png_uint_32 row_width = row_info->width; - for (i = 0, sp = dp = row; i < row_info->width; i++) + for (i = 0, sp = dp = row; i < row_width; i++) { *(dp++) = *(sp++); *(dp++) = 255 - *(sp++); @@ -480,8 +481,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) { png_bytep sp, dp; png_uint_32 i; + png_uint_32 row_width = row_info->width; - for (i = 0, sp = dp = row; i < row_info->width; i++) + for (i = 0, sp = dp = row; i < row_width; i++) { *(dp++) = *(sp++); *(dp++) = *(sp++);