mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng16] Fixed build warnings (MSVC, GCC, GCC v3). Cygwin GCC with default
options declares 'index' as a global, causing a warning if it is used as a local variable. GCC 64-bit warns about assigning a (size_t) (unsigned 64-bit) to an (int) (signed 32-bit). MSVC, however, warns about using the unary '-' operator on an unsigned value (even though it is well defined by ANSI-C to be ~x+1). The padding calculation was changed to use a different method. Removed the tests on png_ptr->pass.
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
434801a39c
commit
29a6ba01a7
58
pngtrans.c
58
pngtrans.c
@@ -625,11 +625,16 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
void /* PRIVATE */
|
||||
png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
|
||||
png_ptr->num_palette_max >= 0 &&
|
||||
((png_ptr->interlaced && png_ptr->pass == 6) ||
|
||||
(!png_ptr->interlaced && png_ptr->pass == 0)))
|
||||
if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
|
||||
png_ptr->num_palette_max >= 0)
|
||||
{
|
||||
/* Calculations moved outside switch in an attempt to stop different
|
||||
* compiler warnings. 'padding' is in *bits* within the last byte, it is
|
||||
* an 'int' because pixel_depth becomes an 'int' in the expression below,
|
||||
* and this calculation is used because it avoids warnings that other
|
||||
* forms produced on either GCC or MSVC.
|
||||
*/
|
||||
int padding = (-row_info->pixel_depth * row_info->width) & 7;
|
||||
png_bytep rp = png_ptr->row_buf + 1 + row_info->rowbytes;
|
||||
|
||||
switch (row_info->bit_depth)
|
||||
@@ -639,8 +644,6 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
/* 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)
|
||||
@@ -653,29 +656,27 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
|
||||
case 2:
|
||||
{
|
||||
int padding = 2*(4*row_info->rowbytes - png_ptr->width);
|
||||
|
||||
for (; rp > png_ptr->row_buf; rp--)
|
||||
{
|
||||
int index = ((*rp >> padding) & 0x03);
|
||||
int i = ((*rp >> padding) & 0x03);
|
||||
|
||||
if (index > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = index;
|
||||
if (i > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = i;
|
||||
|
||||
index = (((*rp >> padding) >> 2) & 0x03);
|
||||
i = (((*rp >> padding) >> 2) & 0x03);
|
||||
|
||||
if (index > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = index;
|
||||
if (i > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = i;
|
||||
|
||||
index = (((*rp >> padding) >> 4) & 0x03);
|
||||
i = (((*rp >> padding) >> 4) & 0x03);
|
||||
|
||||
if (index > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = index;
|
||||
if (i > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = i;
|
||||
|
||||
index = (((*rp >> padding) >> 6) & 0x03);
|
||||
i = (((*rp >> padding) >> 6) & 0x03);
|
||||
|
||||
if (index > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = index;
|
||||
if (i > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = i;
|
||||
|
||||
padding = 0;
|
||||
}
|
||||
@@ -685,19 +686,17 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
|
||||
case 4:
|
||||
{
|
||||
int padding = 4*(2*row_info->rowbytes - png_ptr->width);
|
||||
|
||||
for (; rp > png_ptr->row_buf; rp--)
|
||||
{
|
||||
int index = ((*rp >> padding) & 0x0f);
|
||||
int i = ((*rp >> padding) & 0x0f);
|
||||
|
||||
if (index > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = index;
|
||||
if (i > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = i;
|
||||
|
||||
index = (((*rp >> padding) >> 4) & 0x0f);
|
||||
i = (((*rp >> padding) >> 4) & 0x0f);
|
||||
|
||||
if (index > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = index;
|
||||
if (i > png_ptr->num_palette_max)
|
||||
png_ptr->num_palette_max = i;
|
||||
|
||||
padding = 0;
|
||||
}
|
||||
@@ -715,6 +714,9 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user