/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* pngwtran.c - transforms the data in a row for PNG writers
*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed:
*
* Last changed in libpng 1.5.4 [July 7, 2011]
* Copyright (c) 1998-2011 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.)
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/
#include "pngpriv.h"
#ifdef PNG_WRITE_SUPPORTED
/* Transform the data according to the user's wishes. The order of
* transformations is significant.
*/
void /* PRIVATE */
{
return;
function */
(png_ptr, /* png_ptr */
/* png_uint_32 width; width of row */
/* png_size_t 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) */
#endif
#ifdef PNG_WRITE_FILLER_SUPPORTED
#endif
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
#endif
#ifdef PNG_WRITE_PACK_SUPPORTED
#endif
#ifdef PNG_WRITE_SWAP_SUPPORTED
#endif
#ifdef PNG_WRITE_SHIFT_SUPPORTED
#endif
#endif
#endif
#ifdef PNG_WRITE_BGR_SUPPORTED
#endif
#ifdef PNG_WRITE_INVERT_SUPPORTED
#endif
}
#ifdef PNG_WRITE_PACK_SUPPORTED
/* 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).
*/
void /* PRIVATE */
{
{
switch ((int)bit_depth)
{
case 1:
{
int mask, v;
png_uint_32 i;
mask = 0x80;
v = 0;
for (i = 0; i < row_width; i++)
{
if (*sp != 0)
v |= mask;
sp++;
if (mask > 1)
mask >>= 1;
else
{
mask = 0x80;
dp++;
v = 0;
}
}
if (mask != 0x80)
break;
}
case 2:
{
int shift, v;
png_uint_32 i;
shift = 6;
v = 0;
for (i = 0; i < row_width; i++)
{
if (shift == 0)
{
shift = 6;
dp++;
v = 0;
}
else
shift -= 2;
sp++;
}
if (shift != 6)
break;
}
case 4:
{
int shift, v;
png_uint_32 i;
shift = 4;
v = 0;
for (i = 0; i < row_width; i++)
{
if (shift == 0)
{
shift = 4;
dp++;
v = 0;
}
else
shift -= 4;
sp++;
}
if (shift != 4)
break;
}
default:
break;
}
}
}
#endif
#ifdef PNG_WRITE_SHIFT_SUPPORTED
/* 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.
*/
void /* PRIVATE */
{
{
int channels = 0;
{
channels++;
channels++;
channels++;
}
else
{
channels++;
}
{
channels++;
}
/* With low row depths, could only be grayscale, so one channel */
{
png_size_t i;
mask = 0x55;
mask = 0x11;
else
mask = 0xff;
{
png_uint_16 v;
int j;
v = *bp;
*bp = 0;
{
if (j > 0)
else
}
}
}
{
png_uint_32 i;
{
png_uint_16 v;
int j;
int c = (int)(i%channels);
v = *bp;
*bp = 0;
{
if (j > 0)
else
}
}
}
else
{
png_uint_32 i;
{
int c = (int)(i%channels);
int j;
value = 0;
{
if (j > 0)
else
}
}
}
}
}
#endif
void /* PRIVATE */
{
{
{
{
/* This converts from ARGB to RGBA */
png_uint_32 i;
{
}
}
#ifdef PNG_WRITE_16BIT_SUPPORTED
else
{
/* This converts from AARRGGBB to RRGGBBAA */
png_uint_32 i;
{
}
}
#endif /* PNG_WRITE_16BIT_SUPPORTED */
}
{
{
/* This converts from AG to GA */
png_uint_32 i;
{
}
}
#ifdef PNG_WRITE_16BIT_SUPPORTED
else
{
/* This converts from AAGG to GGAA */
png_uint_32 i;
{
}
}
#endif /* PNG_WRITE_16BIT_SUPPORTED */
}
}
}
#endif
void /* PRIVATE */
{
{
{
{
/* This inverts the alpha channel in RGBA */
png_uint_32 i;
{
/* Does nothing
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*/
}
}
#ifdef PNG_WRITE_16BIT_SUPPORTED
else
{
/* This inverts the alpha channel in RRGGBBAA */
png_uint_32 i;
{
/* Does nothing
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*/
}
}
#endif /* PNG_WRITE_16BIT_SUPPORTED */
}
{
{
/* This inverts the alpha channel in GA */
png_uint_32 i;
{
}
}
#ifdef PNG_WRITE_16BIT_SUPPORTED
else
{
/* This inverts the alpha channel in GGAA */
png_uint_32 i;
{
/* Does nothing
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*/
}
}
#endif /* PNG_WRITE_16BIT_SUPPORTED */
}
}
}
#endif
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Undoes intrapixel differencing */
void /* PRIVATE */
{
{
int bytes_per_pixel;
{
png_uint_32 i;
bytes_per_pixel = 3;
bytes_per_pixel = 4;
else
return;
{
}
}
#ifdef PNG_WRITE_16BIT_SUPPORTED
{
png_uint_32 i;
bytes_per_pixel = 6;
bytes_per_pixel = 8;
else
return;
{
}
}
#endif /* PNG_WRITE_16BIT_SUPPORTED */
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
#endif /* PNG_WRITE_SUPPORTED */