[libng16] Added palette-index checking while writing.

Relocated palette-index checking function from pngrutil.c to pngtrans.c
This commit is contained in:
Glenn Randers-Pehrson
2012-03-02 22:10:15 -06:00
parent 8e92cd51c6
commit eeb1bb678d
10 changed files with 156 additions and 115 deletions

View File

@@ -2296,101 +2296,8 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Added at libpng-1.5.10 */
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (png_ptr->num_palette < (1 << png_ptr->bit_depth) &&
((png_ptr->interlaced && png_ptr->pass == 6) ||
(!png_ptr->interlaced && png_ptr->pass == 0)))
{
png_bytep rp = png_ptr->row_buf + 1 + row_info->rowbytes;
switch (row_info->bit_depth)
{
case 1:
{
/* in this case, all bytes must be 0 so we don't need
* to unpack the pixels except for the rightmost one.
*/
int padding = 8*row_info->rowbytes - png_ptr->width;
for (; rp > png_ptr->row_buf; rp--)
{
if (*rp >> padding != 0)
png_ptr->num_palette_max = 1;
padding = 0;
}
break;
}
case 2:
{
int padding = 2*(4*row_info->rowbytes - png_ptr->width);
for (; rp > png_ptr->row_buf; rp--)
{
int index = ((*rp >> padding) & 0x03);
if (index > png_ptr->num_palette_max)
png_ptr->num_palette_max = index;
index = (((*rp >> padding) >> 2) & 0x03);
if (index > png_ptr->num_palette_max)
png_ptr->num_palette_max = index;
index = (((*rp >> padding) >> 4) & 0x03);
if (index > png_ptr->num_palette_max)
png_ptr->num_palette_max = index;
index = (((*rp >> padding) >> 6) & 0x03);
if (index > png_ptr->num_palette_max)
png_ptr->num_palette_max = index;
padding = 0;
}
break;
}
case 4:
{
int padding = 4*(2*row_info->rowbytes - png_ptr->width);
for (; rp > png_ptr->row_buf; rp--)
{
int index = ((*rp >> padding) & 0x0f);
if (index > png_ptr->num_palette_max)
png_ptr->num_palette_max = index;
index = (((*rp >> padding) >> 4) & 0x0f);
if (index > png_ptr->num_palette_max)
png_ptr->num_palette_max = index;
padding = 0;
}
break;
}
case 8:
{
for (; rp > png_ptr->row_buf; rp--)
{
if (*rp >= png_ptr->num_palette_max)
png_ptr->num_palette_max = *rp;
}
break;
}
}
}
}
png_do_check_palette_indexes(png_ptr, row_info);
#endif
#ifdef PNG_READ_BGR_SUPPORTED