libpng/pngwtran.c

566 lines
16 KiB
C
Raw Normal View History

1995-07-20 03:43:20 -04:00
1997-05-16 03:46:07 -04:00
/* pngwtran.c - transforms the data in a row for PNG writers
1998-01-01 08:13:13 -05:00
*
* Last changed in libpng 1.5.0 [March 9, 2010]
2010-01-01 11:29:06 -05:00
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
2000-06-04 15:29:29 -04:00
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
1998-01-01 08:13:13 -05:00
*/
1995-07-20 03:43:20 -04:00
2006-08-19 14:59:24 -04:00
#include "pngpriv.h"
1995-07-20 03:43:20 -04:00
#ifdef PNG_WRITE_SUPPORTED
1998-06-14 15:43:31 -04:00
/* Transform the data according to the user's wishes. The order of
1998-01-01 08:13:13 -05:00
* transformations is significant.
*/
2000-05-06 15:09:57 -04:00
void /* PRIVATE */
1995-12-19 04:22:19 -05:00
png_do_write_transformations(png_structp png_ptr)
1995-07-20 03:43:20 -04:00
{
2008-08-05 08:44:42 -04:00
png_debug(1, "in png_do_write_transformations");
1998-03-07 07:06:55 -05:00
1999-12-10 10:43:02 -05:00
if (png_ptr == NULL)
return;
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1998-03-07 07:06:55 -05:00
if (png_ptr->transformations & PNG_USER_TRANSFORM)
2008-07-10 10:13:13 -04:00
if (png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* User write transform
function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
/* png_uint_32 width; width of row */
/* png_uint_32 rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
1998-03-07 07:06:55 -05:00
#endif
#ifdef PNG_WRITE_FILLER_SUPPORTED
2004-11-26 18:28:09 -05:00
if (png_ptr->transformations & PNG_FILLER)
1997-05-16 03:46:07 -04:00
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->flags);
1995-09-26 06:22:39 -04:00
#endif
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
1998-01-30 22:45:12 -05:00
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_PACK_SUPPORTED
1995-07-20 03:43:20 -04:00
if (png_ptr->transformations & PNG_PACK)
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
(png_uint_32)png_ptr->bit_depth);
1995-09-26 06:22:39 -04:00
#endif
#ifdef PNG_WRITE_SWAP_SUPPORTED
1998-12-29 12:47:59 -05:00
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_SHIFT_SUPPORTED
1995-07-20 03:43:20 -04:00
if (png_ptr->transformations & PNG_SHIFT)
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->shift));
1995-09-26 06:22:39 -04:00
#endif
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
1998-02-28 08:00:24 -05:00
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
2006-02-20 23:09:05 -05:00
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#ifdef PNG_WRITE_BGR_SUPPORTED
1995-07-20 03:43:20 -04:00
if (png_ptr->transformations & PNG_BGR)
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
1995-09-26 06:22:39 -04:00
#endif
#ifdef PNG_WRITE_INVERT_SUPPORTED
1995-07-20 03:43:20 -04:00
if (png_ptr->transformations & PNG_INVERT_MONO)
png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
}
#ifdef PNG_WRITE_PACK_SUPPORTED
1998-01-01 08:13:13 -05:00
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
* row_info bit depth should be 8 (one pixel per byte). The channels
* should be 1 (this only happens on grayscale and paletted images).
*/
2000-05-06 15:09:57 -04:00
void /* PRIVATE */
1997-05-16 03:46:07 -04:00
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
1995-07-20 03:43:20 -04:00
{
2008-08-05 08:44:42 -04:00
png_debug(1, "in png_do_pack");
1997-05-16 03:46:07 -04:00
if (row_info->bit_depth == 8 &&
1995-07-20 03:43:20 -04:00
row_info->channels == 1)
{
1997-05-16 03:46:07 -04:00
switch ((int)bit_depth)
1995-07-20 03:43:20 -04:00
{
case 1:
{
1997-05-16 03:46:07 -04:00
png_bytep sp, dp;
int mask, v;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
1995-07-20 03:43:20 -04:00
sp = row;
dp = row;
mask = 0x80;
v = 0;
1998-12-29 12:47:59 -05:00
1998-05-02 13:52:25 -04:00
for (i = 0; i < row_width; i++)
1995-07-20 03:43:20 -04:00
{
1997-05-16 03:46:07 -04:00
if (*sp != 0)
1995-07-20 03:43:20 -04:00
v |= mask;
sp++;
if (mask > 1)
mask >>= 1;
else
{
mask = 0x80;
1996-01-26 02:38:47 -05:00
*dp = (png_byte)v;
dp++;
1995-07-20 03:43:20 -04:00
v = 0;
}
}
if (mask != 0x80)
1996-01-26 02:38:47 -05:00
*dp = (png_byte)v;
1995-07-20 03:43:20 -04:00
break;
}
case 2:
{
1997-05-16 03:46:07 -04:00
png_bytep sp, dp;
int shift, v;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
1995-07-20 03:43:20 -04:00
sp = row;
dp = row;
shift = 6;
v = 0;
1998-05-02 13:52:25 -04:00
for (i = 0; i < row_width; i++)
1995-07-20 03:43:20 -04:00
{
1997-05-16 03:46:07 -04:00
png_byte value;
2000-02-05 00:40:16 -05:00
value = (png_byte)(*sp & 0x03);
1995-07-20 03:43:20 -04:00
v |= (value << shift);
if (shift == 0)
{
shift = 6;
1996-01-26 02:38:47 -05:00
*dp = (png_byte)v;
1995-07-20 03:43:20 -04:00
dp++;
v = 0;
}
else
shift -= 2;
sp++;
}
if (shift != 6)
1996-01-26 02:38:47 -05:00
*dp = (png_byte)v;
1995-07-20 03:43:20 -04:00
break;
}
case 4:
{
1997-05-16 03:46:07 -04:00
png_bytep sp, dp;
int shift, v;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
1995-07-20 03:43:20 -04:00
sp = row;
dp = row;
shift = 4;
v = 0;
1998-05-02 13:52:25 -04:00
for (i = 0; i < row_width; i++)
1995-07-20 03:43:20 -04:00
{
1997-05-16 03:46:07 -04:00
png_byte value;
2000-02-05 00:40:16 -05:00
value = (png_byte)(*sp & 0x0f);
1995-07-20 03:43:20 -04:00
v |= (value << shift);
if (shift == 0)
{
shift = 4;
1996-01-26 02:38:47 -05:00
*dp = (png_byte)v;
1995-07-20 03:43:20 -04:00
dp++;
v = 0;
}
else
shift -= 4;
sp++;
}
if (shift != 4)
1996-01-26 02:38:47 -05:00
*dp = (png_byte)v;
1995-07-20 03:43:20 -04:00
break;
}
}
1997-05-16 03:46:07 -04:00
row_info->bit_depth = (png_byte)bit_depth;
row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
2004-08-04 07:34:52 -04:00
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
row_info->width);
1995-07-20 03:43:20 -04:00
}
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
#ifdef PNG_WRITE_SHIFT_SUPPORTED
1998-01-01 08:13:13 -05:00
/* Shift pixel values to take advantage of whole range. Pass the
* true number of bits in bit_depth. The row should be packed
* according to row_info->bit_depth. Thus, if you had a row of
* bit depth 4, but the pixels only had values from 0 to 7, you
* would pass 3 as bit_depth, and this routine would translate the
* data to 0 to 15.
*/
2000-05-06 15:09:57 -04:00
void /* PRIVATE */
1995-12-19 04:22:19 -05:00
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
1995-07-20 03:43:20 -04:00
{
2008-08-05 08:44:42 -04:00
png_debug(1, "in png_do_shift");
1997-05-16 03:46:07 -04:00
if (
1995-07-20 03:43:20 -04:00
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{
int shift_start[4], shift_dec[4];
1998-05-09 11:02:29 -04:00
int channels = 0;
1995-07-20 03:43:20 -04:00
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
{
shift_start[channels] = row_info->bit_depth - bit_depth->red;
shift_dec[channels] = bit_depth->red;
channels++;
shift_start[channels] = row_info->bit_depth - bit_depth->green;
shift_dec[channels] = bit_depth->green;
channels++;
shift_start[channels] = row_info->bit_depth - bit_depth->blue;
shift_dec[channels] = bit_depth->blue;
channels++;
}
else
{
shift_start[channels] = row_info->bit_depth - bit_depth->gray;
shift_dec[channels] = bit_depth->gray;
channels++;
}
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
{
shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
shift_dec[channels] = bit_depth->alpha;
channels++;
}
2009-05-20 13:45:29 -04:00
/* With low row depths, could only be grayscale, so one channel */
1995-07-20 03:43:20 -04:00
if (row_info->bit_depth < 8)
{
1998-05-02 13:52:25 -04:00
png_bytep bp = row;
png_uint_32 i;
1995-07-20 03:43:20 -04:00
png_byte mask;
1998-05-02 13:52:25 -04:00
png_uint_32 row_bytes = row_info->rowbytes;
1995-07-20 03:43:20 -04:00
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
mask = 0x55;
else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
mask = 0x11;
else
mask = 0xff;
1998-05-02 13:52:25 -04:00
for (i = 0; i < row_bytes; i++, bp++)
1995-07-20 03:43:20 -04:00
{
1997-05-16 03:46:07 -04:00
png_uint_16 v;
int j;
1995-07-20 03:43:20 -04:00
v = *bp;
*bp = 0;
for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
{
if (j > 0)
*bp |= (png_byte)((v << j) & 0xff);
else
*bp |= (png_byte)((v >> (-j)) & mask);
}
}
}
else if (row_info->bit_depth == 8)
{
1998-05-02 13:52:25 -04:00
png_bytep bp = row;
png_uint_32 i;
1998-05-09 11:02:29 -04:00
png_uint_32 istop = channels * row_info->width;
1995-07-20 03:43:20 -04:00
1998-05-09 11:02:29 -04:00
for (i = 0; i < istop; i++, bp++)
1995-07-20 03:43:20 -04:00
{
1998-05-09 11:02:29 -04:00
png_uint_16 v;
int j;
int c = (int)(i%channels);
1995-07-20 03:43:20 -04:00
1998-05-09 11:02:29 -04:00
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);
1995-07-20 03:43:20 -04:00
}
}
}
else
{
1995-12-19 04:22:19 -05:00
png_bytep bp;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
1998-05-09 11:02:29 -04:00
png_uint_32 istop = channels * row_info->width;
1995-07-20 03:43:20 -04:00
1998-05-09 11:02:29 -04:00
for (bp = row, i = 0; i < istop; i++)
1995-07-20 03:43:20 -04:00
{
1998-05-09 11:02:29 -04:00
int c = (int)(i%channels);
png_uint_16 value, v;
int j;
1995-07-20 03:43:20 -04:00
1999-10-14 08:43:10 -04:00
v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
1998-05-09 11:02:29 -04:00
value = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
1995-07-20 03:43:20 -04:00
{
1998-05-09 11:02:29 -04:00
if (j > 0)
value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
else
value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
1995-07-20 03:43:20 -04:00
}
1998-05-09 11:02:29 -04:00
*bp++ = (png_byte)(value >> 8);
*bp++ = (png_byte)(value & 0xff);
1995-07-20 03:43:20 -04:00
}
}
}
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
2000-05-06 15:09:57 -04:00
void /* PRIVATE */
1997-05-16 03:46:07 -04:00
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
1995-07-20 03:43:20 -04:00
{
2008-08-05 08:44:42 -04:00
png_debug(1, "in png_do_write_swap_alpha");
1995-07-20 03:43:20 -04:00
{
1997-05-16 03:46:07 -04:00
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1995-07-20 03:43:20 -04:00
{
1997-05-16 03:46:07 -04:00
if (row_info->bit_depth == 8)
{
/* This converts from ARGB to RGBA */
1997-05-16 03:46:07 -04:00
png_bytep sp, dp;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
1997-05-16 03:46:07 -04:00
{
1998-04-21 16:03:57 -04:00
png_byte save = *(sp++);
1997-05-16 03:46:07 -04:00
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = save;
}
}
else
1995-09-26 06:22:39 -04:00
{
/* This converts from AARRGGBB to RRGGBBAA */
1997-05-16 03:46:07 -04:00
png_bytep sp, dp;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
1997-05-16 03:46:07 -04:00
1998-05-02 13:52:25 -04:00
for (i = 0, sp = dp = row; i < row_width; i++)
1997-05-16 03:46:07 -04:00
{
1998-04-21 16:03:57 -04:00
png_byte save[2];
1997-05-16 03:46:07 -04:00
save[0] = *(sp++);
save[1] = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = save[0];
*(dp++) = save[1];
}
1995-09-26 06:22:39 -04:00
}
}
1997-05-16 03:46:07 -04:00
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1995-07-20 03:43:20 -04:00
{
1997-05-16 03:46:07 -04:00
if (row_info->bit_depth == 8)
{
/* This converts from AG to GA */
1997-05-16 03:46:07 -04:00
png_bytep sp, dp;
png_uint_32 i;
1998-05-02 13:52:25 -04:00
png_uint_32 row_width = row_info->width;
1995-09-26 06:22:39 -04:00
1998-05-02 13:52:25 -04:00
for (i = 0, sp = dp = row; i < row_width; i++)
1997-05-16 03:46:07 -04:00
{
1998-04-21 16:03:57 -04:00
png_byte save = *(sp++);
1997-05-16 03:46:07 -04:00
*(dp++) = *(sp++);
*(dp++) = save;
}
}
else
1995-09-26 06:22:39 -04:00
{
/* This converts from AAGG to GGAA */
1997-05-16 03:46:07 -04:00
png_bytep sp, dp;
png_uint_32 i;
1998-05-02 13:52:25 -04:00
png_uint_32 row_width = row_info->width;
1997-05-16 03:46:07 -04:00
1998-05-02 13:52:25 -04:00
for (i = 0, sp = dp = row; i < row_width; i++)
1997-05-16 03:46:07 -04:00
{
1998-04-21 16:03:57 -04:00
png_byte save[2];
1997-05-16 03:46:07 -04:00
save[0] = *(sp++);
save[1] = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = save[0];
*(dp++) = save[1];
}
1995-09-26 06:22:39 -04:00
}
1995-07-20 03:43:20 -04:00
}
}
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
2000-05-06 15:09:57 -04:00
void /* PRIVATE */
1998-01-16 23:06:18 -05:00
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
{
2008-08-05 08:44:42 -04:00
png_debug(1, "in png_do_write_invert_alpha");
1998-01-16 23:06:18 -05:00
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
if (row_info->bit_depth == 8)
{
/* This inverts the alpha channel in RGBA */
1998-01-16 23:06:18 -05:00
png_bytep sp, dp;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
1998-01-16 23:06:18 -05:00
{
2009-05-20 13:45:29 -04:00
/* Does nothing
1998-01-16 23:06:18 -05:00
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
2006-02-20 23:09:05 -05:00
*/
sp+=3; dp = sp;
1999-10-14 08:43:10 -04:00
*(dp++) = (png_byte)(255 - *(sp++));
1998-01-16 23:06:18 -05:00
}
}
else
{
/* This inverts the alpha channel in RRGGBBAA */
1998-01-16 23:06:18 -05:00
png_bytep sp, dp;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
1998-01-16 23:06:18 -05:00
1998-05-02 13:52:25 -04:00
for (i = 0, sp = dp = row; i < row_width; i++)
1998-01-16 23:06:18 -05:00
{
2009-05-20 13:45:29 -04:00
/* Does nothing
1998-01-16 23:06:18 -05:00
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
2006-02-20 23:09:05 -05:00
*/
sp+=6; dp = sp;
1999-10-14 08:43:10 -04:00
*(dp++) = (png_byte)(255 - *(sp++));
*(dp++) = (png_byte)(255 - *(sp++));
1998-01-16 23:06:18 -05:00
}
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
if (row_info->bit_depth == 8)
{
/* This inverts the alpha channel in GA */
1998-01-16 23:06:18 -05:00
png_bytep sp, dp;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
1998-01-16 23:06:18 -05:00
1998-05-02 13:52:25 -04:00
for (i = 0, sp = dp = row; i < row_width; i++)
1998-01-16 23:06:18 -05:00
{
*(dp++) = *(sp++);
1999-10-14 08:43:10 -04:00
*(dp++) = (png_byte)(255 - *(sp++));
1998-01-16 23:06:18 -05:00
}
}
else
{
/* This inverts the alpha channel in GGAA */
1998-01-16 23:06:18 -05:00
png_bytep sp, dp;
1998-05-02 13:52:25 -04:00
png_uint_32 i;
png_uint_32 row_width = row_info->width;
1998-01-16 23:06:18 -05:00
1998-05-02 13:52:25 -04:00
for (i = 0, sp = dp = row; i < row_width; i++)
1998-01-16 23:06:18 -05:00
{
2009-05-20 13:45:29 -04:00
/* Does nothing
1998-01-16 23:06:18 -05:00
*(dp++) = *(sp++);
*(dp++) = *(sp++);
2006-02-20 23:09:05 -05:00
*/
sp+=2; dp = sp;
1999-10-14 08:43:10 -04:00
*(dp++) = (png_byte)(255 - *(sp++));
*(dp++) = (png_byte)(255 - *(sp++));
1998-01-16 23:06:18 -05:00
}
}
}
}
}
#endif
2000-12-15 09:54:42 -05:00
#ifdef PNG_MNG_FEATURES_SUPPORTED
2009-05-20 13:45:29 -04:00
/* Undoes intrapixel differencing */
2000-12-15 09:54:42 -05:00
void /* PRIVATE */
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
{
2008-08-05 08:44:42 -04:00
png_debug(1, "in png_do_write_intrapixel");
2000-12-15 09:54:42 -05:00
if (
(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);
2000-12-15 09:54:42 -05:00
}
}
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);
2008-07-10 10:13:13 -04:00
png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
*(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);
2000-12-15 09:54:42 -05:00
}
}
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
2001-05-07 15:52:45 -04:00
#endif /* PNG_WRITE_SUPPORTED */