Skip to content

Commit

Permalink
Replace the remaining uses of PNG_CONST with const
Browse files Browse the repository at this point in the history
In v1.6.0, compiler support for const became a requirement.
It should be used consistently. To maintain backwards compatibility,
PNG_CONST is still maintained in deprecated form.
  • Loading branch information
ctruta committed Aug 19, 2018
1 parent 58eedce commit 1ef8882
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 76 deletions.
6 changes: 3 additions & 3 deletions contrib/examples/pngpixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ component(png_const_bytep row, png_uint_32 x, unsigned int c,
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels);
png_uint_32 bit_offset_lo = bit_depth * ((x & 0x3f) * channels + c);

row = (png_const_bytep)(((PNG_CONST png_byte (*)[8])row) + bit_offset_hi);
row = (png_const_bytep)(((const png_byte (*)[8])row) + bit_offset_hi);
row += bit_offset_lo >> 3;
bit_offset_lo &= 0x07;

Expand Down Expand Up @@ -73,7 +73,7 @@ static void
print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
png_uint_32 x)
{
PNG_CONST unsigned int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
const unsigned int bit_depth = png_get_bit_depth(png_ptr, info_ptr);

switch (png_get_color_type(png_ptr, info_ptr))
{
Expand All @@ -87,7 +87,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
*/
case PNG_COLOR_TYPE_PALETTE:
{
PNG_CONST int index = component(row, x, 0, bit_depth, 1);
const int index = component(row, x, 0, bit_depth, 1);
png_colorp palette = NULL;
int num_palette = 0;

Expand Down
2 changes: 1 addition & 1 deletion contrib/gregbook/readpng2.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int readpng2_init(mainprog_info *mainprog_ptr)
/* These byte strings were copied from png.h. If a future version
* of readpng2.c recognizes more chunks, add them to this list.
*/
static PNG_CONST png_byte chunks_to_process[] = {
static const png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
103, 65, 77, 65, '\0', /* gAMA */
115, 82, 71, 66, '\0', /* sRGB */
Expand Down
2 changes: 1 addition & 1 deletion contrib/libtests/pngstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ print_opts(png_uint_32 opts)
*/
#define FORMAT_COUNT 64
#define FORMAT_MASK 0x3f
static PNG_CONST char * PNG_CONST format_names[FORMAT_COUNT] =
static const char * const format_names[FORMAT_COUNT] =
{
"sRGB-gray",
"sRGB-gray+alpha",
Expand Down
2 changes: 1 addition & 1 deletion contrib/libtests/pngunknown.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)

#if PNG_LIBPNG_VER < 10500
/* This deliberately lacks the PNG_CONST. */
/* This deliberately lacks the const. */
typedef png_byte *png_const_bytep;

/* This is copied from 1.5.1 png.h: */
Expand Down
6 changes: 3 additions & 3 deletions contrib/tools/makesRGB.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ main(int argc, char **argv)

if (!test_only)
{
printf("PNG_CONST png_uint_16 png_sRGB_table[256] =\n{\n ");
printf("const png_uint_16 png_sRGB_table[256] =\n{\n ");
for (i=0; i<255; )
{
do
Expand All @@ -401,7 +401,7 @@ main(int argc, char **argv)
printf("%d\n};\n\n", png_sRGB_table[i]);


printf("PNG_CONST png_uint_16 png_sRGB_base[512] =\n{\n ");
printf("const png_uint_16 png_sRGB_base[512] =\n{\n ");
for (i=0; i<511; )
{
do
Expand All @@ -413,7 +413,7 @@ main(int argc, char **argv)
}
printf("%d\n};\n\n", png_sRGB_base[i]);

printf("PNG_CONST png_byte png_sRGB_delta[512] =\n{\n ");
printf("const png_byte png_sRGB_delta[512] =\n{\n ");
for (i=0; i<511; )
{
do
Expand Down
2 changes: 1 addition & 1 deletion libpng-manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4870,7 +4870,7 @@ to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
There are changes of form in png.h, including new and changed macros to
declare parts of the API. Some API functions with arguments that are
pointers to data not modified within the function have been corrected to
declare these arguments with PNG_CONST.
declare these arguments with const.

Much of the internal use of C macros to control the library build has also
changed and some of this is visible in the exported header files, in
Expand Down
2 changes: 1 addition & 1 deletion libpng.3
Original file line number Diff line number Diff line change
Expand Up @@ -5389,7 +5389,7 @@ to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
There are changes of form in png.h, including new and changed macros to
declare parts of the API. Some API functions with arguments that are
pointers to data not modified within the function have been corrected to
declare these arguments with PNG_CONST.
declare these arguments with const.

Much of the internal use of C macros to control the library build has also
changed and some of this is visible in the exported header files, in
Expand Down
20 changes: 10 additions & 10 deletions png.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ png_save_int_32(png_bytep buf, png_int_32 i)
int PNGAPI
png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime)
{
static PNG_CONST char short_months[12][4] =
static const char short_months[12][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

Expand Down Expand Up @@ -3970,18 +3970,18 @@ png_gamma_correct(png_structrp png_ptr, unsigned int value,
*/
static void
png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
const unsigned int shift, const png_fixed_point gamma_val)
{
/* Various values derived from 'shift': */
PNG_CONST unsigned int num = 1U << (8U - shift);
const unsigned int num = 1U << (8U - shift);
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
/* CSE the division and work round wacky GCC warnings (see the comments
* in png_gamma_8bit_correct for where these come from.)
*/
PNG_CONST double fmax = 1./(((png_int_32)1 << (16U - shift))-1);
const double fmax = 1./(((png_int_32)1 << (16U - shift))-1);
#endif
PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);
const unsigned int max = (1U << (16U - shift))-1U;
const unsigned int max_by_2 = 1U << (15U-shift);
unsigned int i;

png_uint_16pp table = *ptable =
Expand Down Expand Up @@ -4047,10 +4047,10 @@ png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
*/
static void
png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
const unsigned int shift, const png_fixed_point gamma_val)
{
PNG_CONST unsigned int num = 1U << (8U - shift);
PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
const unsigned int num = 1U << (8U - shift);
const unsigned int max = (1U << (16U - shift))-1U;
unsigned int i;
png_uint_32 last;

Expand Down Expand Up @@ -4115,7 +4115,7 @@ png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
*/
static void
png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,
PNG_CONST png_fixed_point gamma_val)
const png_fixed_point gamma_val)
{
unsigned int i;
png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);
Expand Down
5 changes: 2 additions & 3 deletions pngconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@

#endif /* PNG_BUILDING_SYMBOL_TABLE */

/* Prior to 1.6.0 it was possible to turn off 'const' in declarations using
* PNG_NO_CONST; this is no longer supported except for data declarations which
* apparently still cause problems in 2011 on some compilers.
/* Prior to 1.6.0, it was possible to turn off 'const' in declarations,
* using PNG_NO_CONST. This is no longer supported.
*/
#define PNG_CONST const /* backward compatibility only */

Expand Down
2 changes: 1 addition & 1 deletion pngerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
* if the character is invalid.
*/
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
static PNG_CONST char png_digit[16] = {
static const char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'
};
Expand Down
10 changes: 5 additions & 5 deletions pngpread.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,20 +972,20 @@ png_read_push_finish_row(png_structrp png_ptr)
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */

/* Start of interlace block */
static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};

/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};

/* Start of interlace block in the y direction */
static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
static const png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};

/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
static const png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};

/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
#endif

Expand Down
4 changes: 2 additions & 2 deletions pngread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
* errors (which are unfortunately quite common.)
*/
{
static PNG_CONST png_byte chunks_to_process[] = {
static const png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
103, 65, 77, 65, '\0', /* gAMA */
Expand Down Expand Up @@ -3946,7 +3946,7 @@ png_image_read_direct(png_voidp argument)
*/
if (linear != 0)
{
PNG_CONST png_uint_16 le = 0x0001;
const png_uint_16 le = 0x0001;

if ((*(png_const_bytep) & le) != 0)
png_set_swap(png_ptr);
Expand Down
20 changes: 10 additions & 10 deletions pngrtran.c
Original file line number Diff line number Diff line change
Expand Up @@ -2995,11 +2995,11 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
(row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
PNG_CONST png_uint_32 bc = 32768 - rc - gc;
PNG_CONST png_uint_32 row_width = row_info->width;
PNG_CONST int have_alpha =
const png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
const png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
const png_uint_32 bc = 32768 - rc - gc;
const png_uint_32 row_width = row_info->width;
const int have_alpha =
(row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;

if (row_info->bit_depth == 8)
Expand Down Expand Up @@ -4143,11 +4143,11 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
if (row_info->bit_depth == 8)
{
PNG_CONST png_bytep table = png_ptr->gamma_from_1;
const png_bytep table = png_ptr->gamma_from_1;

if (table != NULL)
{
PNG_CONST int step =
const int step =
(row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;

/* The alpha channel is the last component: */
Expand All @@ -4162,12 +4162,12 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)

else if (row_info->bit_depth == 16)
{
PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1;
PNG_CONST int gamma_shift = png_ptr->gamma_shift;
const png_uint_16pp table = png_ptr->gamma_16_from_1;
const int gamma_shift = png_ptr->gamma_shift;

if (table != NULL)
{
PNG_CONST int step =
const int step =
(row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;

/* The alpha channel is the last component: */
Expand Down
22 changes: 11 additions & 11 deletions pngrutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -3363,7 +3363,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
* then pass:
*/
static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
{
/* Little-endian byte masks for PACKSWAP */
{ S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },
Expand All @@ -3374,7 +3374,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* display_mask has only three entries for the odd passes, so index by
* pass>>1.
*/
static PNG_CONST png_uint_32 display_mask[2][3][3] =
static const png_uint_32 display_mask[2][3][3] =
{
/* Little-endian byte masks for PACKSWAP */
{ B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },
Expand Down Expand Up @@ -3687,7 +3687,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Offset to next interlace block */
static PNG_CONST unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};

png_debug(1, "in png_do_read_interlace");
if (row != NULL && row_info != NULL)
Expand Down Expand Up @@ -4329,16 +4329,16 @@ png_read_finish_row(png_structrp png_ptr)
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */

/* Start of interlace block */
static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};

/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};

/* Start of interlace block in the y direction */
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};

/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};

png_debug(1, "in png_read_finish_row");
png_ptr->row_number++;
Expand Down Expand Up @@ -4394,16 +4394,16 @@ png_read_start_row(png_structrp png_ptr)
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */

/* Start of interlace block */
static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};

/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};

/* Start of interlace block in the y direction */
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};

/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};

unsigned int max_pixel_depth;
size_t row_bytes;
Expand Down
2 changes: 1 addition & 1 deletion pngset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
/* Ignore all unknown chunks and all chunks recognized by
* libpng except for IHDR, PLTE, tRNS, IDAT, and IEND
*/
static PNG_CONST png_byte chunks_to_ignore[] = {
static const png_byte chunks_to_ignore[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
101, 88, 73, 102, '\0', /* eXIf */
Expand Down
14 changes: 7 additions & 7 deletions pngtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,13 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, size_t length)
*/
typedef struct
{
PNG_CONST char *file_name;
const char *file_name;
} pngtest_error_parameters;

static void PNGCBAPI
pngtest_warning(png_structp png_ptr, png_const_charp message)
{
PNG_CONST char *name = "UNKNOWN (ERROR!)";
const char *name = "UNKNOWN (ERROR!)";
pngtest_error_parameters *test =
(pngtest_error_parameters*)png_get_error_ptr(png_ptr);

Expand Down Expand Up @@ -850,7 +850,7 @@ pngtest_check_text_support(png_structp png_ptr, png_textp text_ptr,

/* Test one file */
static int
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
test_one_file(const char *inname, const char *outname)
{
static png_FILE_p fpin;
static png_FILE_p fpout; /* "static" prevents setjmp corruption */
Expand Down Expand Up @@ -1809,11 +1809,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)

/* Input and output filenames */
#ifdef RISCOS
static PNG_CONST char *inname = "pngtest/png";
static PNG_CONST char *outname = "pngout/png";
static const char *inname = "pngtest/png";
static const char *outname = "pngout/png";
#else
static PNG_CONST char *inname = "pngtest.png";
static PNG_CONST char *outname = "pngout.png";
static const char *inname = "pngtest.png";
static const char *outname = "pngout.png";
#endif

int
Expand Down
Loading

0 comments on commit 1ef8882

Please sign in to comment.