From 6d35722f7073c2caf9e73b5b6453563d71de2258 Mon Sep 17 00:00:00 2001 From: John Bowler Date: Sun, 6 Jan 2013 17:57:40 -0600 Subject: [PATCH] [libpng15] Updated pngvalid.c from libpng16 --- contrib/libtests/pngvalid.c | 582 +++++++++++++++++++++++++++--------- 1 file changed, 447 insertions(+), 135 deletions(-) diff --git a/contrib/libtests/pngvalid.c b/contrib/libtests/pngvalid.c index c4578c213..81477ef8b 100644 --- a/contrib/libtests/pngvalid.c +++ b/contrib/libtests/pngvalid.c @@ -1,8 +1,8 @@ /* pngvalid.c - validate libpng by constructing then reading png files. * - * Last changed in libpng 1.5.8 [February 1, 2012] - * Copyright (c) 2012 Glenn Randers-Pehrson + * Last changed in libpng 1.5.14 [%RDATE%] + * Copyright (c) 2013 Glenn Randers-Pehrson * Written by John Cunningham Bowler * * This code is released under the libpng license. @@ -24,8 +24,13 @@ #define _GNU_SOURCE 1 /* For the floating point exception extension */ #include +#include -#ifdef HAVE_FEENABLEEXCEPT +#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H) +# include +#endif + +#ifdef HAVE_FEENABLEEXCEPT /* from config.h, if included */ # include #endif @@ -38,6 +43,8 @@ # include "../../png.h" #endif +#ifdef PNG_WRITE_SUPPORTED /* else pngvalid can do nothing */ + #if PNG_LIBPNG_VER < 10500 /* This deliberately lacks the PNG_CONST. */ typedef png_byte *png_const_bytep; @@ -74,7 +81,14 @@ typedef png_byte *png_const_bytep; ((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1)) #endif -#include "zlib.h" /* For crc32 */ +#if PNG_LIBPNG_VER < 10600 + /* 1.6.0 constifies many APIs, the following exists to allow pngvalid to be + * compiled against earlier versions. + */ +# define png_const_structp png_structp +#endif + +#include /* For crc32 */ #include /* For floating point constants */ #include /* For malloc */ @@ -93,7 +107,11 @@ typedef png_byte *png_const_bytep; #endif /***************************** EXCEPTION HANDLING *****************************/ -#include "../visupng/cexcept.h" +#ifdef PNG_FREESTANDING_TESTS +# include +#else +# include "../visupng/cexcept.h" +#endif #ifdef __cplusplus # define this not_the_cpp_this @@ -159,6 +177,7 @@ static PNG_CONST char *colour_types[8] = "grayscale with alpha", invalid, "truecolour with alpha", invalid }; +#ifdef PNG_READ_SUPPORTED /* Convert a double precision value to fixed point. */ static png_fixed_point fix(double d) @@ -166,12 +185,14 @@ fix(double d) d = floor(d * PNG_FP_1 + .5); return (png_fixed_point)d; } +#endif /* PNG_READ_SUPPORTED */ /* Generate random bytes. This uses a boring repeatable algorithm and it * is implemented here so that it gives the same set of numbers on every * architecture. It's a linear congruential generator (Knuth or Sedgewick * "Algorithms") but it comes from the 'feedback taps' table in Horowitz and - * Hill, "The Art of Electronics". + * Hill, "The Art of Electronics" (Pseudo-Random Bit Sequences and Noise + * Generation.) */ static void make_random_bytes(png_uint_32* seed, void* pv, size_t size) @@ -204,6 +225,7 @@ make_four_random_bytes(png_uint_32* seed, png_bytep bytes) make_random_bytes(seed, bytes, 4); } +#ifdef PNG_READ_SUPPORTED static void randomize(void *pv, size_t size) { @@ -223,6 +245,7 @@ random_mod(unsigned int max) return x % max; /* 0 .. max-1 */ } +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED static int random_choice(void) { @@ -232,6 +255,8 @@ random_choice(void) return x & 1; } +#endif +#endif /* PNG_READ_SUPPORTED */ /* A numeric ID based on PNG file characteristics. The 'do_interlace' field * simply records whether pngvalid did the interlace itself or whether it @@ -450,6 +475,7 @@ pixel_copy(png_bytep toBuffer, png_uint_32 toIndex, memmove(toBuffer+(toIndex>>3), fromBuffer+(fromIndex>>3), pixelSize>>3); } +#ifdef PNG_READ_SUPPORTED /* Copy a complete row of pixels, taking into account potential partial * bytes at the end. */ @@ -515,6 +541,7 @@ pixel_cmp(png_const_bytep pa, png_const_bytep pb, png_uint_32 bit_width) return 1+where; } } +#endif /* PNG_READ_SUPPORTED */ /*************************** BASIC PNG FILE WRITING ***************************/ /* A png_store takes data from the sequential writer or provides data @@ -625,6 +652,7 @@ store_pool_mark(png_bytep mark) make_four_random_bytes(store_seed, mark); } +#ifdef PNG_READ_SUPPORTED /* Use this for random 32 bit values; this function makes sure the result is * non-zero. */ @@ -644,6 +672,7 @@ random_32(void) return result; } } +#endif /* PNG_READ_SUPPORTED */ static void store_pool_init(png_store *ps, store_pool *pool) @@ -779,7 +808,7 @@ store_storefile(png_store *ps, png_uint_32 id) /* Generate an error message (in the given buffer) */ static size_t -store_message(png_store *ps, png_structp pp, char *buffer, size_t bufsize, +store_message(png_store *ps, png_const_structp pp, char *buffer, size_t bufsize, size_t pos, PNG_CONST char *msg) { if (pp != NULL && pp == ps->pread) @@ -819,7 +848,7 @@ store_message(png_store *ps, png_structp pp, char *buffer, size_t bufsize, /* Verbose output to the error stream: */ static void -store_verbose(png_store *ps, png_structp pp, png_const_charp prefix, +store_verbose(png_store *ps, png_const_structp pp, png_const_charp prefix, png_const_charp message) { char buffer[512]; @@ -834,7 +863,8 @@ store_verbose(png_store *ps, png_structp pp, png_const_charp prefix, /* Log an error or warning - the relevant count is always incremented. */ static void -store_log(png_store* ps, png_structp pp, png_const_charp message, int is_error) +store_log(png_store* ps, png_const_structp pp, png_const_charp message, + int is_error) { /* The warning is copied to the error buffer if there are no errors and it is * the first warning. The error is copied to the error buffer if it is the @@ -848,6 +878,7 @@ store_log(png_store* ps, png_structp pp, png_const_charp message, int is_error) store_verbose(ps, pp, is_error ? "error: " : "warning: ", message); } +#ifdef PNG_READ_SUPPORTED /* Internal error function, called with a png_store but no libpng stuff. */ static void internal_error(png_store *ps, png_const_charp message) @@ -860,11 +891,13 @@ internal_error(png_store *ps, png_const_charp message) Throw ps; } } +#endif /* PNG_READ_SUPPORTED */ /* Functions to use as PNG callbacks. */ static void -store_error(png_structp pp, png_const_charp message) /* PNG_NORETURN */ +store_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */ { + png_const_structp pp = ppIn; png_store *ps = voidcast(png_store*, png_get_error_ptr(pp)); if (!ps->expect_error) @@ -878,8 +911,9 @@ store_error(png_structp pp, png_const_charp message) /* PNG_NORETURN */ } static void -store_warning(png_structp pp, png_const_charp message) +store_warning(png_structp ppIn, png_const_charp message) { + png_const_structp pp = ppIn; png_store *ps = voidcast(png_store*, png_get_error_ptr(pp)); if (!ps->expect_warning) @@ -893,7 +927,7 @@ store_warning(png_structp pp, png_const_charp message) */ /* Return a single row from the correct image. */ static png_bytep -store_image_row(PNG_CONST png_store* ps, png_structp pp, int nImage, +store_image_row(PNG_CONST png_store* ps, png_const_structp pp, int nImage, png_uint_32 y) { png_size_t coffset = (nImage * ps->image_h + y) * (ps->cb_row + 5) + 2; @@ -908,7 +942,7 @@ store_image_row(PNG_CONST png_store* ps, png_structp pp, int nImage, } static void -store_image_free(png_store *ps, png_structp pp) +store_image_free(png_store *ps, png_const_structp pp) { if (ps->image != NULL) { @@ -930,8 +964,8 @@ store_image_free(png_store *ps, png_structp pp) } static void -store_ensure_image(png_store *ps, png_structp pp, int nImages, png_size_t cbRow, - png_uint_32 cRows) +store_ensure_image(png_store *ps, png_const_structp pp, int nImages, + png_size_t cbRow, png_uint_32 cRows) { png_size_t cb = nImages * cRows * (cbRow + 5); @@ -995,8 +1029,9 @@ store_ensure_image(png_store *ps, png_structp pp, int nImages, png_size_t cbRow, } } +#ifdef PNG_READ_SUPPORTED static void -store_image_check(PNG_CONST png_store* ps, png_structp pp, int iImage) +store_image_check(PNG_CONST png_store* ps, png_const_structp pp, int iImage) { png_const_bytep image = ps->image; @@ -1024,10 +1059,12 @@ store_image_check(PNG_CONST png_store* ps, png_structp pp, int iImage) } } } +#endif /* PNG_READ_SUPPORTED */ static void -store_write(png_structp pp, png_bytep pb, png_size_t st) +store_write(png_structp ppIn, png_bytep pb, png_size_t st) { + png_const_structp pp = ppIn; png_store *ps = voidcast(png_store*, png_get_io_ptr(pp)); if (ps->pwrite != pp) @@ -1053,11 +1090,12 @@ store_write(png_structp pp, png_bytep pb, png_size_t st) } static void -store_flush(png_structp pp) +store_flush(png_structp ppIn) { - UNUSED(pp) /*DOES NOTHING*/ + UNUSED(ppIn) /*DOES NOTHING*/ } +#ifdef PNG_READ_SUPPORTED static size_t store_read_buffer_size(png_store *ps) { @@ -1146,8 +1184,9 @@ store_read_imp(png_store *ps, png_bytep pb, png_size_t st) } static void -store_read(png_structp pp, png_bytep pb, png_size_t st) +store_read(png_structp ppIn, png_bytep pb, png_size_t st) { + png_const_structp pp = ppIn; png_store *ps = voidcast(png_store*, png_get_io_ptr(pp)); if (ps == NULL || ps->pread != pp) @@ -1174,6 +1213,7 @@ store_progressive_read(png_store *ps, png_structp pp, png_infop pi) } while (store_read_buffer_next(ps)); } +#endif /* PNG_READ_SUPPORTED */ /* The caller must fill this in: */ static store_palette_entry * @@ -1200,6 +1240,7 @@ store_write_palette(png_store *ps, int npalette) return ps->palette; } +#ifdef PNG_READ_SUPPORTED static store_palette_entry * store_current_palette(png_store *ps, int *npalette) { @@ -1213,6 +1254,7 @@ store_current_palette(png_store *ps, int *npalette) *npalette = ps->current->npalette; return ps->current->palette; } +#endif /* PNG_READ_SUPPORTED */ /***************************** MEMORY MANAGEMENT*** ***************************/ /* A store_memory is simply the header for an allocated block of memory. The @@ -1235,7 +1277,7 @@ typedef struct store_memory * all the memory. */ static void -store_pool_error(png_store *ps, png_structp pp, PNG_CONST char *msg) +store_pool_error(png_store *ps, png_const_structp pp, PNG_CONST char *msg) { if (pp != NULL) png_error(pp, msg); @@ -1248,7 +1290,7 @@ store_pool_error(png_store *ps, png_structp pp, PNG_CONST char *msg) } static void -store_memory_free(png_structp pp, store_pool *pool, store_memory *memory) +store_memory_free(png_const_structp pp, store_pool *pool, store_memory *memory) { /* Note that pp may be NULL (see store_pool_delete below), the caller has * found 'memory' in pool->list *and* unlinked this entry, so this is a valid @@ -1334,8 +1376,9 @@ store_pool_delete(png_store *ps, store_pool *pool) /* The memory callbacks: */ static png_voidp -store_malloc(png_structp pp, png_alloc_size_t cb) +store_malloc(png_structp ppIn, png_alloc_size_t cb) { + png_const_structp pp = ppIn; store_pool *pool = voidcast(store_pool*, png_get_mem_ptr(pp)); store_memory *new = voidcast(store_memory*, malloc(cb + (sizeof *new) + (sizeof pool->mark))); @@ -1382,8 +1425,9 @@ store_malloc(png_structp pp, png_alloc_size_t cb) } static void -store_free(png_structp pp, png_voidp memory) +store_free(png_structp ppIn, png_voidp memory) { + png_const_structp pp = ppIn; store_pool *pool = voidcast(store_pool*, png_get_mem_ptr(pp)); store_memory *this = voidcast(store_memory*, memory), **test; @@ -1485,25 +1529,29 @@ set_store_for_write(png_store *ps, png_infopp ppi, } /* Cleanup when finished reading (either due to error or in the success case). + * This routine exists even when there is no read support to make the code + * tidier (avoid a mass of ifdefs) and so easier to maintain. */ static void store_read_reset(png_store *ps) { - if (ps->pread != NULL) - { - anon_context(ps); - - Try - png_destroy_read_struct(&ps->pread, &ps->piread, NULL); - - Catch_anonymous +# ifdef PNG_READ_SUPPORTED + if (ps->pread != NULL) { - /* error already output: continue */ - } + anon_context(ps); - ps->pread = NULL; - ps->piread = NULL; - } + Try + png_destroy_read_struct(&ps->pread, &ps->piread, NULL); + + Catch_anonymous + { + /* error already output: continue */ + } + + ps->pread = NULL; + ps->piread = NULL; + } +# endif /* Always do this to be safe. */ store_pool_delete(ps, &ps->read_memory_pool); @@ -1514,6 +1562,7 @@ store_read_reset(png_store *ps) ps->validated = 0; } +#ifdef PNG_READ_SUPPORTED static void store_read_set(png_store *ps, png_uint_32 id) { @@ -1591,6 +1640,7 @@ set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id, return ps->pread; } +#endif /* PNG_READ_SUPPORTED */ /* The overall cleanup of a store simply calls the above then removes all the * saved files. This does not delete the store itself. @@ -1630,18 +1680,6 @@ typedef struct CIE_color double X, Y, Z; } CIE_color; -static double -chromaticity_x(CIE_color c) -{ - return c.X / (c.X + c.Y + c.Z); -} - -static double -chromaticity_y(CIE_color c) -{ - return c.Y / (c.X + c.Y + c.Z); -} - typedef struct color_encoding { /* A description of an (R,G,B) encoding of color (as defined above); this @@ -1654,6 +1692,19 @@ typedef struct color_encoding CIE_color red, green, blue; /* End points */ } color_encoding; +#ifdef PNG_READ_SUPPORTED +static double +chromaticity_x(CIE_color c) +{ + return c.X / (c.X + c.Y + c.Z); +} + +static double +chromaticity_y(CIE_color c) +{ + return c.Y / (c.X + c.Y + c.Z); +} + static CIE_color white_point(PNG_CONST color_encoding *encoding) { @@ -1666,6 +1717,7 @@ white_point(PNG_CONST color_encoding *encoding) return white; } +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED static void normalize_color_encoding(color_encoding *encoding) { @@ -1685,6 +1737,7 @@ normalize_color_encoding(color_encoding *encoding) encoding->blue.Z /= whiteY; } } +#endif static size_t safecat_color_encoding(char *buffer, size_t bufsize, size_t pos, @@ -1725,6 +1778,7 @@ safecat_color_encoding(char *buffer, size_t bufsize, size_t pos, return pos; } +#endif /* PNG_READ_SUPPORTED */ typedef struct png_modifier { @@ -1918,6 +1972,7 @@ modifier_init(png_modifier *pm) * to a calculation - not a digitization operation - unless the following API is * called directly. */ +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED static double digitize(PNG_CONST png_modifier *pm, double value, int sample_depth, int do_round) { @@ -1942,7 +1997,10 @@ static double digitize(PNG_CONST png_modifier *pm, double value, if (do_round) value += .5; return floor(value)/digitization_factor; } +#endif +#if (defined PNG_READ_GAMMA_SUPPORTED) ||\ + (defined PNG_READ_RGB_TO_GRAY_SUPPORTED) static double abserr(PNG_CONST png_modifier *pm, int in_depth, int out_depth) { /* Absolute error permitted in linear values - affected by the bit depth of @@ -1954,7 +2012,9 @@ static double abserr(PNG_CONST png_modifier *pm, int in_depth, int out_depth) else return pm->maxabs8; } +#endif +#ifdef PNG_READ_GAMMA_SUPPORTED static double calcerr(PNG_CONST png_modifier *pm, int in_depth, int out_depth) { /* Error in the linear composition arithmetic - only relevant when @@ -2071,6 +2131,7 @@ static int output_quantization_factor(PNG_CONST png_modifier *pm, int in_depth, else return 1; } +#endif /* PNG_READ_GAMMA_SUPPORTED */ /* One modification structure must be provided for each chunk to be modified (in * fact more than one can be provided if multiple separate changes are desired @@ -2123,6 +2184,7 @@ modification_init(png_modification *pmm) modification_reset(pmm); } +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED static void modifier_current_encoding(PNG_CONST png_modifier *pm, color_encoding *ce) { @@ -2134,6 +2196,7 @@ modifier_current_encoding(PNG_CONST png_modifier *pm, color_encoding *ce) ce->gamma = pm->current_gamma; } +#endif static size_t safecat_current_encoding(char *buffer, size_t bufsize, size_t pos, @@ -2537,8 +2600,9 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st) /* The callback: */ static void -modifier_read(png_structp pp, png_bytep pb, png_size_t st) +modifier_read(png_structp ppIn, png_bytep pb, png_size_t st) { + png_const_structp pp = ppIn; png_modifier *pm = voidcast(png_modifier*, png_get_io_ptr(pp)); if (pm == NULL || pm->this.pread != pp) @@ -2758,6 +2822,7 @@ srgb_modification_init(srgb_modification *me, png_modifier *pm, png_byte intent) pm->modifications = &me->this; } +#ifdef PNG_READ_GAMMA_SUPPORTED typedef struct sbit_modification { png_modification this; @@ -2824,6 +2889,7 @@ sbit_modification_init(sbit_modification *me, png_modifier *pm, png_byte sbit) me->this.next = pm->modifications; pm->modifications = &me->this; } +#endif /* PNG_READ_GAMMA_SUPPORTED */ #endif /* PNG_READ_TRANSFORMS_SUPPORTED */ /***************************** STANDARD PNG FILES *****************************/ @@ -2885,9 +2951,9 @@ make_standard_palette(png_store* ps, int npalette, int do_tRNS) */ for (; i<8; ++i) { - values[i][1] = (i&1) ? 255 : 0; - values[i][2] = (i&2) ? 255 : 0; - values[i][3] = (i&4) ? 255 : 0; + values[i][1] = (png_byte)((i&1) ? 255U : 0U); + values[i][2] = (png_byte)((i&2) ? 255U : 0U); + values[i][3] = (png_byte)((i&4) ? 255U : 0U); } /* Then add 62 grays (one quarter of the remaining 256 slots). */ @@ -2971,6 +3037,7 @@ make_standard_palette(png_store* ps, int npalette, int do_tRNS) /* Initialize a standard palette on a write stream. The 'do_tRNS' argument * indicates whether or not to also set the tRNS chunk. */ +/* TODO: the png_structp here can probably be 'const' in the future */ static void init_standard_palette(png_store *ps, png_structp pp, png_infop pi, int npalette, int do_tRNS) @@ -3019,7 +3086,7 @@ init_standard_palette(png_store *ps, png_structp pp, png_infop pi, int npalette, * API to determine this prior to 1.5, so we need an inquiry function: */ static int -npasses_from_interlace_type(png_structp pp, int interlace_type) +npasses_from_interlace_type(png_const_structp pp, int interlace_type) { switch (interlace_type) { @@ -3035,7 +3102,7 @@ npasses_from_interlace_type(png_structp pp, int interlace_type) } static unsigned int -bit_size(png_structp pp, png_byte colour_type, png_byte bit_depth) +bit_size(png_const_structp pp, png_byte colour_type, png_byte bit_depth) { switch (colour_type) { @@ -3060,7 +3127,8 @@ bit_size(png_structp pp, png_byte colour_type, png_byte bit_depth) #define SIZE_HEIGHTMAX 16 /* Maximum range of size images */ static size_t -transform_rowsize(png_structp pp, png_byte colour_type, png_byte bit_depth) +transform_rowsize(png_const_structp pp, png_byte colour_type, + png_byte bit_depth) { return (TRANSFORM_WIDTH * bit_size(pp, colour_type, bit_depth)) / 8; } @@ -3071,7 +3139,7 @@ transform_rowsize(png_structp pp, png_byte colour_type, png_byte bit_depth) #define transform_width(pp, colour_type, bit_depth) TRANSFORM_WIDTH static png_uint_32 -transform_height(png_structp pp, png_byte colour_type, png_byte bit_depth) +transform_height(png_const_structp pp, png_byte colour_type, png_byte bit_depth) { switch (bit_size(pp, colour_type, bit_depth)) { @@ -3100,11 +3168,12 @@ transform_height(png_structp pp, png_byte colour_type, png_byte bit_depth) } } +#ifdef PNG_READ_SUPPORTED /* The following can only be defined here, now we have the definitions * of the transform image sizes. */ static png_uint_32 -standard_width(png_structp pp, png_uint_32 id) +standard_width(png_const_structp pp, png_uint_32 id) { png_uint_32 width = WIDTH_FROM_ID(id); UNUSED(pp) @@ -3116,7 +3185,7 @@ standard_width(png_structp pp, png_uint_32 id) } static png_uint_32 -standard_height(png_structp pp, png_uint_32 id) +standard_height(png_const_structp pp, png_uint_32 id) { png_uint_32 height = HEIGHT_FROM_ID(id); @@ -3127,7 +3196,7 @@ standard_height(png_structp pp, png_uint_32 id) } static png_uint_32 -standard_rowsize(png_structp pp, png_uint_32 id) +standard_rowsize(png_const_structp pp, png_uint_32 id) { png_uint_32 width = standard_width(pp, id); @@ -3135,9 +3204,10 @@ standard_rowsize(png_structp pp, png_uint_32 id) width *= bit_size(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id)); return (width + 7) / 8; } +#endif /* PNG_READ_SUPPORTED */ static void -transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX], +transform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX], png_byte colour_type, png_byte bit_depth, png_uint_32 y) { png_uint_32 v = y << 7; @@ -3146,20 +3216,20 @@ transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX], switch (bit_size(pp, colour_type, bit_depth)) { case 1: - while (i<128/8) buffer[i] = v & 0xff, v += 17, ++i; + while (i<128/8) buffer[i] = (png_byte)(v & 0xff), v += 17, ++i; return; case 2: - while (i<128/4) buffer[i] = v & 0xff, v += 33, ++i; + while (i<128/4) buffer[i] = (png_byte)(v & 0xff), v += 33, ++i; return; case 4: - while (i<128/2) buffer[i] = v & 0xff, v += 65, ++i; + while (i<128/2) buffer[i] = (png_byte)(v & 0xff), v += 65, ++i; return; case 8: /* 256 bytes total, 128 bytes in each row set as follows: */ - while (i<128) buffer[i] = v & 0xff, ++v, ++i; + while (i<128) buffer[i] = (png_byte)(v & 0xff), ++v, ++i; return; case 16: @@ -3167,7 +3237,12 @@ transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX], * GA case as well as the 16 bit G case. */ while (i<128) - buffer[2*i] = (v>>8) & 0xff, buffer[2*i+1] = v & 0xff, ++v, ++i; + { + buffer[2*i] = (png_byte)((v>>8) & 0xff); + buffer[2*i+1] = (png_byte)(v & 0xff); + ++v; + ++i; + } return; @@ -3176,9 +3251,9 @@ transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX], while (i<128) { /* Three bytes per pixel, r, g, b, make b by r^g */ - buffer[3*i+0] = (v >> 8) & 0xff; - buffer[3*i+1] = v & 0xff; - buffer[3*i+2] = ((v >> 8) ^ v) & 0xff; + buffer[3*i+0] = (png_byte)((v >> 8) & 0xff); + buffer[3*i+1] = (png_byte)(v & 0xff); + buffer[3*i+2] = (png_byte)(((v >> 8) ^ v) & 0xff); ++v; ++i; } @@ -3189,10 +3264,10 @@ transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX], /* 65535 pixels, r, g, b, a; just replicate */ while (i<128) { - buffer[4*i+0] = (v >> 8) & 0xff; - buffer[4*i+1] = v & 0xff; - buffer[4*i+2] = (v >> 8) & 0xff; - buffer[4*i+3] = v & 0xff; + buffer[4*i+0] = (png_byte)((v >> 8) & 0xff); + buffer[4*i+1] = (png_byte)(v & 0xff); + buffer[4*i+2] = (png_byte)((v >> 8) & 0xff); + buffer[4*i+3] = (png_byte)(v & 0xff); ++v; ++i; } @@ -3206,14 +3281,14 @@ transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX], while (i<128) { png_uint_32 t = v++; - buffer[6*i+0] = (t >> 8) & 0xff; - buffer[6*i+1] = t & 0xff; + buffer[6*i+0] = (png_byte)((t >> 8) & 0xff); + buffer[6*i+1] = (png_byte)(t & 0xff); t *= 257; - buffer[6*i+2] = (t >> 8) & 0xff; - buffer[6*i+3] = t & 0xff; + buffer[6*i+2] = (png_byte)((t >> 8) & 0xff); + buffer[6*i+3] = (png_byte)(t & 0xff); t *= 17; - buffer[6*i+4] = (t >> 8) & 0xff; - buffer[6*i+5] = t & 0xff; + buffer[6*i+4] = (png_byte)((t >> 8) & 0xff); + buffer[6*i+5] = (png_byte)(t & 0xff); ++i; } @@ -3224,15 +3299,15 @@ transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX], while (i<128) { png_uint_32 t = v++; - buffer[8*i+0] = (t >> 8) & 0xff; - buffer[8*i+1] = t & 0xff; - buffer[8*i+4] = (t >> 8) & 0xff; - buffer[8*i+5] = t & 0xff; + buffer[8*i+0] = (png_byte)((t >> 8) & 0xff); + buffer[8*i+1] = (png_byte)(t & 0xff); + buffer[8*i+4] = (png_byte)((t >> 8) & 0xff); + buffer[8*i+5] = (png_byte)(t & 0xff); t *= 257; - buffer[8*i+2] = (t >> 8) & 0xff; - buffer[8*i+3] = t & 0xff; - buffer[8*i+6] = (t >> 8) & 0xff; - buffer[8*i+7] = t & 0xff; + buffer[8*i+2] = (png_byte)((t >> 8) & 0xff); + buffer[8*i+3] = (png_byte)(t & 0xff); + buffer[8*i+6] = (png_byte)((t >> 8) & 0xff); + buffer[8*i+7] = (png_byte)(t & 0xff); ++i; } return; @@ -3282,6 +3357,11 @@ make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); #ifdef PNG_TEXT_SUPPORTED +# if (defined PNG_READ_zTXt_SUPPORTED) && (defined PNG_WRITE_zTXt_SUPPORTED) +# define TEXT_COMPRESSION PNG_TEXT_COMPRESSION_zTXt +# else +# define TEXT_COMPRESSION PNG_TEXT_COMPRESSION_NONE +# endif { static char key[] = "image name"; /* must be writeable */ size_t pos; @@ -3291,7 +3371,7 @@ make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, /* Use a compressed text string to test the correct interaction of text * compression and IDAT compression. */ - text.compression = PNG_TEXT_COMPRESSION_zTXt; + text.compression = TEXT_COMPRESSION; text.key = key; /* Yuck: the text must be writable! */ pos = safecat(copy, sizeof copy, 0, ps->wname); @@ -3349,7 +3429,7 @@ make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, /* Use a compressed text string to test the correct interaction of text * compression and IDAT compression. */ - text.compression = PNG_TEXT_COMPRESSION_zTXt; + text.compression = TEXT_COMPRESSION; text.key = key; text.text = comment; text.text_length = (sizeof comment)-1; @@ -3433,6 +3513,7 @@ interlace_row(png_bytep buffer, png_const_bytep imageRow, } } +#ifdef PNG_READ_SUPPORTED static void deinterlace_row(png_bytep buffer, png_const_bytep row, unsigned int pixel_size, png_uint_32 w, int pass) @@ -3453,6 +3534,7 @@ deinterlace_row(png_bytep buffer, png_const_bytep row, ++xin; } } +#endif /* PNG_READ_SUPPORTED */ /* Build a single row for the 'size' test images; this fills in only the * first bit_width bits of the sample row. @@ -3510,6 +3592,30 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, png_set_IHDR(pp, pi, w, h, bit_depth, colour_type, interlace_type, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); +#ifdef PNG_TEXT_SUPPORTED + { + static char key[] = "image name"; /* must be writeable */ + size_t pos; + png_text text; + char copy[FILE_NAME_SIZE]; + + /* Use a compressed text string to test the correct interaction of text + * compression and IDAT compression. + */ + text.compression = TEXT_COMPRESSION; + text.key = key; + /* Yuck: the text must be writable! */ + pos = safecat(copy, sizeof copy, 0, ps->wname); + text.text = copy; + text.text_length = pos; + text.itxt_length = 0; + text.lang = 0; + text.lang_key = 0; + + png_set_text(pp, pi, &text, 1); + } +#endif + if (colour_type == 3) /* palette */ init_standard_palette(ps, pp, pi, 1U << bit_depth, 0/*do tRNS*/); @@ -3587,6 +3693,27 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, } } +#ifdef PNG_TEXT_SUPPORTED + { + static char key[] = "end marker"; + static char comment[] = "end"; + png_text text; + + /* Use a compressed text string to test the correct interaction of text + * compression and IDAT compression. + */ + text.compression = TEXT_COMPRESSION; + text.key = key; + text.text = comment; + text.text_length = (sizeof comment)-1; + text.itxt_length = 0; + text.lang = 0; + text.lang_key = 0; + + png_set_text(pp, pi, &text, 1); + } +#endif + png_write_end(pp, pi); /* And store this under the appropriate id, then clean up. */ @@ -3651,10 +3778,11 @@ make_size_images(png_store *ps) make_size(ps, 6, 3, WRITE_BDHI); } +#ifdef PNG_READ_SUPPORTED /* Return a row based on image id and 'y' for checking: */ static void -standard_row(png_structp pp, png_byte std[STANDARD_ROWMAX], png_uint_32 id, - png_uint_32 y) +standard_row(png_const_structp pp, png_byte std[STANDARD_ROWMAX], + png_uint_32 id, png_uint_32 y) { if (WIDTH_FROM_ID(id) == 0) transform_row(pp, std, COL_FROM_ID(id), DEPTH_FROM_ID(id), y); @@ -3662,12 +3790,16 @@ standard_row(png_structp pp, png_byte std[STANDARD_ROWMAX], png_uint_32 id, size_row(std, WIDTH_FROM_ID(id) * bit_size(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id)), y); } +#endif /* PNG_READ_SUPPORTED */ /* Tests - individual test cases */ /* Like 'make_standard' but errors are deliberately introduced into the calls * to ensure that they get detected - it should not be possible to write an * invalid image with libpng! */ +/* TODO: the 'set' functions can probably all be made to take a + * png_const_structp rather than a modifiable one. + */ #ifdef PNG_WARNINGS_SUPPORTED static void sBIT0_error_fn(png_structp pp, png_infop pi) @@ -3884,6 +4016,9 @@ perform_formatting_test(png_store *volatile ps) { png_const_charp correct = "29 Aug 2079 13:53:60 +0000"; png_const_charp result; +# if PNG_LIBPNG_VER >= 10600 + char timestring[29]; +# endif png_structp pp; png_time pt; @@ -3901,7 +4036,15 @@ perform_formatting_test(png_store *volatile ps) pt.minute = 53; pt.second = 60; /* a leap second */ - result = png_convert_to_rfc1123(pp, &pt); +# if PNG_LIBPNG_VER < 10600 + result = png_convert_to_rfc1123(pp, &pt); +# else + if (png_convert_to_rfc1123_buffer(timestring, &pt)) + result = timestring; + + else + result = NULL; +# endif if (result == NULL) png_error(pp, "png_convert_to_rfc1123 failed"); @@ -3932,6 +4075,7 @@ perform_formatting_test(png_store *volatile ps) #endif } +#ifdef PNG_READ_SUPPORTED /* Because we want to use the same code in both the progressive reader and the * sequential reader it is necessary to deal with the fact that the progressive * reader callbacks only have one parameter (png_get_progressive_ptr()), so this @@ -4060,7 +4204,8 @@ standard_palette_init(standard_display *dp) * palette (it does not check for a transparent colour in the non-palette case.) */ static int -read_palette(store_palette palette, int *npalette, png_structp pp, png_infop pi) +read_palette(store_palette palette, int *npalette, png_const_structp pp, + png_infop pi) { png_colorp pal; png_bytep trans_alpha; @@ -4151,7 +4296,8 @@ read_palette(store_palette palette, int *npalette, png_structp pp, png_infop pi) * non-transform case). */ static void -standard_palette_validate(standard_display *dp, png_structp pp, png_infop pi) +standard_palette_validate(standard_display *dp, png_const_structp pp, + png_infop pi) { int npalette; store_palette palette; @@ -4345,8 +4491,8 @@ standard_info_part1(standard_display *dp, png_structp pp, png_infop pi) * image. */ static void -standard_info_part2(standard_display *dp, png_structp pp, png_infop pi, - int nImages) +standard_info_part2(standard_display *dp, png_const_structp pp, + png_const_infop pi, int nImages) { /* Record cbRow now that it can be found. */ dp->pixel_size = bit_size(pp, png_get_color_type(pp, pi), @@ -4404,8 +4550,9 @@ standard_info(png_structp pp, png_infop pi) } static void -progressive_row(png_structp pp, png_bytep new_row, png_uint_32 y, int pass) +progressive_row(png_structp ppIn, png_bytep new_row, png_uint_32 y, int pass) { + png_const_structp pp = ppIn; PNG_CONST standard_display *dp = voidcast(standard_display*, png_get_progressive_ptr(pp)); @@ -4523,8 +4670,122 @@ sequential_row(standard_display *dp, png_structp pp, png_infop pi, png_read_end(pp, pi); } +#ifdef PNG_TEXT_SUPPORTED static void -standard_row_validate(standard_display *dp, png_structp pp, +standard_check_text(png_const_structp pp, png_const_textp tp, + png_const_charp keyword, png_const_charp text) +{ + char msg[1024]; + size_t pos = safecat(msg, sizeof msg, 0, "text: "); + size_t ok; + + pos = safecat(msg, sizeof msg, pos, keyword); + pos = safecat(msg, sizeof msg, pos, ": "); + ok = pos; + + if (tp->compression != TEXT_COMPRESSION) + { + char buf[64]; + + sprintf(buf, "compression [%d->%d], ", TEXT_COMPRESSION, + tp->compression); + pos = safecat(msg, sizeof msg, pos, buf); + } + + if (tp->key == NULL || strcmp(tp->key, keyword) != 0) + { + pos = safecat(msg, sizeof msg, pos, "keyword \""); + if (tp->key != NULL) + { + pos = safecat(msg, sizeof msg, pos, tp->key); + pos = safecat(msg, sizeof msg, pos, "\", "); + } + + else + pos = safecat(msg, sizeof msg, pos, "null, "); + } + + if (tp->text == NULL) + pos = safecat(msg, sizeof msg, pos, "text lost, "); + + else + { + if (tp->text_length != strlen(text)) + { + char buf[64]; + sprintf(buf, "text length changed[%lu->%lu], ", + (unsigned long)strlen(text), (unsigned long)tp->text_length); + pos = safecat(msg, sizeof msg, pos, buf); + } + + if (strcmp(tp->text, text) != 0) + { + pos = safecat(msg, sizeof msg, pos, "text becomes \""); + pos = safecat(msg, sizeof msg, pos, tp->text); + pos = safecat(msg, sizeof msg, pos, "\" (was \""); + pos = safecat(msg, sizeof msg, pos, text); + pos = safecat(msg, sizeof msg, pos, "\"), "); + } + } + + if (tp->itxt_length != 0) + pos = safecat(msg, sizeof msg, pos, "iTXt length set, "); + + if (tp->lang != NULL) + { + pos = safecat(msg, sizeof msg, pos, "iTXt language \""); + pos = safecat(msg, sizeof msg, pos, tp->lang); + pos = safecat(msg, sizeof msg, pos, "\", "); + } + + if (tp->lang_key != NULL) + { + pos = safecat(msg, sizeof msg, pos, "iTXt keyword \""); + pos = safecat(msg, sizeof msg, pos, tp->lang_key); + pos = safecat(msg, sizeof msg, pos, "\", "); + } + + if (pos > ok) + { + msg[pos-2] = '\0'; /* Remove the ", " at the end */ + png_error(pp, msg); + } +} + +static void +standard_text_validate(standard_display *dp, png_const_structp pp, + png_const_infop pi, int check_end) +{ + png_textp tp = NULL; + png_uint_32 num_text = png_get_text(pp, pi, &tp, NULL); + + if (num_text == 2 && tp != NULL) + { + standard_check_text(pp, tp, "image name", dp->ps->current->name); + + /* This exists because prior to 1.6 the progressive reader left the + * png_struct z_stream unreset at the end of the image, so subsequent + * attempts to use it simply returns Z_STREAM_END. + */ + if (check_end) + standard_check_text(pp, tp+1, "end marker", "end"); + } + + else + { + char msg[64]; + + sprintf(msg, "expected two text items, got %lu", + (unsigned long)num_text); + png_error(pp, msg); + } +} +#else +# define standard_text_validate(dp,pp,pi,check_end) ((void)0) +#endif + +static void +standard_row_validate(standard_display *dp, png_const_structp pp, int iImage, int iDisplay, png_uint_32 y) { int where; @@ -4554,8 +4815,8 @@ standard_row_validate(standard_display *dp, png_structp pp, dp->bit_width)) != 0) { char msg[64]; - sprintf(msg, "PNG image row[%d][%d] changed from %.2x to %.2x", y, - where-1, std[where-1], + sprintf(msg, "PNG image row[%lu][%d] changed from %.2x to %.2x", + (unsigned long)y, where-1, std[where-1], store_image_row(dp->ps, pp, iImage, y)[where-1]); png_error(pp, msg); } @@ -4572,15 +4833,15 @@ standard_row_validate(standard_display *dp, png_structp pp, dp->bit_width)) != 0) { char msg[64]; - sprintf(msg, "display row[%d][%d] changed from %.2x to %.2x", y, - where-1, std[where-1], + sprintf(msg, "display row[%lu][%d] changed from %.2x to %.2x", + (unsigned long)y, where-1, std[where-1], store_image_row(dp->ps, pp, iDisplay, y)[where-1]); png_error(pp, msg); } } static void -standard_image_validate(standard_display *dp, png_structp pp, int iImage, +standard_image_validate(standard_display *dp, png_const_structp pp, int iImage, int iDisplay) { png_uint_32 y; @@ -4599,8 +4860,9 @@ standard_image_validate(standard_display *dp, png_structp pp, int iImage, } static void -standard_end(png_structp pp, png_infop pi) +standard_end(png_structp ppIn, png_infop pi) { + png_const_structp pp = ppIn; standard_display *dp = voidcast(standard_display*, png_get_progressive_ptr(pp)); @@ -4609,6 +4871,8 @@ standard_end(png_structp pp, png_infop pi) /* Validate the image - progressive reading only produces one variant for * interlaced images. */ + standard_text_validate(dp, pp, pi, + PNG_LIBPNG_VER >= 10600/*check_end: see comments above*/); standard_image_validate(dp, pp, 0, -1); } @@ -4678,7 +4942,10 @@ standard_test(png_store* PNG_CONST psIn, png_uint_32 PNG_CONST id, * image is correct. */ if (!d.speed) + { + standard_text_validate(&d, pp, pi, 1/*check_end*/); standard_image_validate(&d, pp, 0, 1); + } else d.ps->validated = 1; } @@ -5107,7 +5374,7 @@ typedef struct image_transform * reporting via png_error and png_warning. */ void (*mod)(PNG_CONST struct image_transform *this, image_pixel *that, - png_structp pp, PNG_CONST struct transform_display *display); + png_const_structp pp, PNG_CONST struct transform_display *display); /* Add this transform to the list and return true if the transform is * meaningful for this colour type and bit depth - if false then the @@ -5202,7 +5469,7 @@ sample_scale(double sample_value, unsigned int scale) static void image_transform_mod_end(PNG_CONST image_transform *this, image_pixel *that, - png_structp pp, PNG_CONST transform_display *display) + png_const_structp pp, PNG_CONST transform_display *display) { PNG_CONST unsigned int scale = (1U<sample_depth)-1; @@ -5431,7 +5698,7 @@ transform_info(png_structp pp, png_infop pi) } static void -transform_range_check(png_structp pp, unsigned int r, unsigned int g, +transform_range_check(png_const_structp pp, unsigned int r, unsigned int g, unsigned int b, unsigned int a, unsigned int in_digitized, double in, unsigned int out, png_byte sample_depth, double err, double limit, PNG_CONST char *name, double digitization_error) @@ -5474,7 +5741,8 @@ transform_range_check(png_structp pp, unsigned int r, unsigned int g, } static void -transform_image_validate(transform_display *dp, png_structp pp, png_infop pi) +transform_image_validate(transform_display *dp, png_const_structp pp, + png_infop pi) { /* Constants for the loop below: */ PNG_CONST png_store* PNG_CONST ps = dp->this.ps; @@ -5632,8 +5900,9 @@ transform_image_validate(transform_display *dp, png_structp pp, png_infop pi) } static void -transform_end(png_structp pp, png_infop pi) +transform_end(png_structp ppIn, png_infop pi) { + png_const_structp pp = ppIn; transform_display *dp = voidcast(transform_display*, png_get_progressive_ptr(pp)); @@ -5754,6 +6023,7 @@ image_transform_default_ini(PNG_CONST image_transform *this, this->next->ini(this->next, that); } +#ifdef PNG_READ_BACKGROUND_SUPPORTED static int image_transform_default_add(image_transform *this, PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) @@ -5766,6 +6036,7 @@ image_transform_default_add(image_transform *this, return 1; } +#endif #ifdef PNG_READ_EXPAND_SUPPORTED /* png_set_palette_to_rgb */ @@ -5779,7 +6050,8 @@ image_transform_png_set_palette_to_rgb_set(PNG_CONST image_transform *this, static void image_transform_png_set_palette_to_rgb_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { if (that->colour_type == PNG_COLOR_TYPE_PALETTE) image_pixel_convert_PLTE(that); @@ -5816,7 +6088,8 @@ image_transform_png_set_tRNS_to_alpha_set(PNG_CONST image_transform *this, static void image_transform_png_set_tRNS_to_alpha_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { /* LIBPNG BUG: this always forces palette images to RGB. */ if (that->colour_type == PNG_COLOR_TYPE_PALETTE) @@ -5873,7 +6146,8 @@ image_transform_png_set_gray_to_rgb_set(PNG_CONST image_transform *this, static void image_transform_png_set_gray_to_rgb_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { /* NOTE: we can actually pend the tRNS processing at this point because we * can correctly recognize the original pixel value even though we have @@ -5931,7 +6205,8 @@ image_transform_png_set_expand_set(PNG_CONST image_transform *this, static void image_transform_png_set_expand_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { /* The general expand case depends on what the colour type is: */ if (that->colour_type == PNG_COLOR_TYPE_PALETTE) @@ -5980,7 +6255,7 @@ image_transform_png_set_expand_gray_1_2_4_to_8_set( static void image_transform_png_set_expand_gray_1_2_4_to_8_mod( - PNG_CONST image_transform *this, image_pixel *that, png_structp pp, + PNG_CONST image_transform *this, image_pixel *that, png_const_structp pp, PNG_CONST transform_display *display) { image_transform_png_set_expand_mod(this, that, pp, display); @@ -6011,7 +6286,8 @@ image_transform_png_set_expand_16_set(PNG_CONST image_transform *this, static void image_transform_png_set_expand_16_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { /* Expect expand_16 to expand everything to 16 bits as a result of also * causing 'expand' to happen. @@ -6058,7 +6334,8 @@ image_transform_png_set_scale_16_set(PNG_CONST image_transform *this, static void image_transform_png_set_scale_16_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { if (that->bit_depth == 16) { @@ -6101,7 +6378,8 @@ image_transform_png_set_strip_16_set(PNG_CONST image_transform *this, static void image_transform_png_set_strip_16_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { if (that->bit_depth == 16) { @@ -6167,7 +6445,8 @@ image_transform_png_set_strip_alpha_set(PNG_CONST image_transform *this, static void image_transform_png_set_strip_alpha_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA) that->colour_type = PNG_COLOR_TYPE_GRAY; @@ -6499,7 +6778,8 @@ image_transform_png_set_rgb_to_gray_set(PNG_CONST image_transform *this, static void image_transform_png_set_rgb_to_gray_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { if ((that->colour_type & PNG_COLOR_MASK_COLOR) != 0) { @@ -6750,7 +7030,8 @@ image_transform_png_set_background_set(PNG_CONST image_transform *this, static void image_transform_png_set_background_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { /* Check for tRNS first: */ if (that->have_tRNS && that->colour_type != PNG_COLOR_TYPE_PALETTE) @@ -7000,7 +7281,8 @@ image_transform_png_set_@_set(PNG_CONST image_transform *this, static void image_transform_png_set_@_mod(PNG_CONST image_transform *this, - image_pixel *that, png_structp pp, PNG_CONST transform_display *display) + image_pixel *that, png_const_structp pp, + PNG_CONST transform_display *display) { this->next->mod(this->next, that, pp, display); } @@ -7303,7 +7585,7 @@ gamma_info(png_structp pp, png_infop pi) */ typedef struct validate_info { - png_structp pp; + png_const_structp pp; gamma_display *dp; png_byte sbit; int use_input_precision; @@ -7333,7 +7615,7 @@ typedef struct validate_info validate_info; static void -init_validate_info(validate_info *vi, gamma_display *dp, png_struct *pp, +init_validate_info(validate_info *vi, gamma_display *dp, png_const_structp pp, int in_depth, int out_depth) { PNG_CONST unsigned int outmax = (1U<= 0 && alpha < 1); - /*FALL THROUGH*/ +# ifdef PNG_READ_BACKGROUND_SUPPORTED + case PNG_BACKGROUND_GAMMA_SCREEN: + case PNG_BACKGROUND_GAMMA_FILE: + case PNG_BACKGROUND_GAMMA_UNIQUE: + use_background = (alpha >= 0 && alpha < 1); + /*FALL THROUGH*/ +# endif # ifdef PNG_READ_ALPHA_MODE_SUPPORTED case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD: case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN: @@ -8046,7 +8335,8 @@ gamma_component_validate(PNG_CONST char *name, PNG_CONST validate_info *vi, } static void -gamma_image_validate(gamma_display *dp, png_structp pp, png_infop pi) +gamma_image_validate(gamma_display *dp, png_const_structp pp, + png_infop pi) { /* Get some constants derived from the input and output file formats: */ PNG_CONST png_store* PNG_CONST ps = dp->this.ps; @@ -8225,7 +8515,8 @@ gamma_image_validate(gamma_display *dp, png_structp pp, png_infop pi) char msg[64]; /* No transform is expected on the threshold tests. */ - sprintf(msg, "gamma: below threshold row %d changed", y); + sprintf(msg, "gamma: below threshold row %lu changed", + (unsigned long)y); png_error(pp, msg); } @@ -8235,8 +8526,9 @@ gamma_image_validate(gamma_display *dp, png_structp pp, png_infop pi) } static void -gamma_end(png_structp pp, png_infop pi) +gamma_end(png_structp ppIn, png_infop pi) { + png_const_structp pp = ppIn; gamma_display *dp = voidcast(gamma_display*, png_get_progressive_ptr(pp)); if (!dp->this.speed) @@ -8801,7 +9093,9 @@ perform_gamma_test(png_modifier *pm, int summary) /* Save certain values for the temporary overrides below. */ unsigned int calculations_use_input_precision = pm->calculations_use_input_precision; - double maxout8 = pm->maxout8; +# ifdef PNG_READ_BACKGROUND_SUPPORTED + double maxout8 = pm->maxout8; +# endif /* First some arbitrary no-transform tests: */ if (!pm->this.speed && pm->test_gamma_threshold) @@ -8920,6 +9214,7 @@ perform_gamma_test(png_modifier *pm, int summary) #endif } #endif /* PNG_READ_GAMMA_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ /* INTERLACE MACRO VALIDATION */ /* This is copied verbatim from the specification, it is simply the pass @@ -9369,7 +9664,7 @@ static void signal_handler(int signum) } /* main program */ -int main(int argc, PNG_CONST char **argv) +int main(int argc, char **argv) { volatile int summary = 1; /* Print the error summary at the end */ volatile int memstats = 0; /* Print memory statistics at the end */ @@ -9728,7 +10023,9 @@ int main(int argc, PNG_CONST char **argv) { perform_interlace_macro_validation(); perform_formatting_test(&pm.this); - perform_standard_test(&pm); +# ifdef PNG_READ_SUPPORTED + perform_standard_test(&pm); +# endif perform_error_test(&pm); } @@ -9736,7 +10033,9 @@ int main(int argc, PNG_CONST char **argv) if (pm.test_size) { make_size_images(&pm.this); - perform_size_test(&pm); +# ifdef PNG_READ_SUPPORTED + perform_size_test(&pm); +# endif } #ifdef PNG_READ_TRANSFORMS_SUPPORTED @@ -9829,7 +10128,20 @@ int main(int argc, PNG_CONST char **argv) exit(1); } } + + else + { + fprintf(stderr, "%s: open failed\n", touch); + exit(1); + } } return 0; } +#else /* write not supported */ +int main(void) +{ + fprintf(stderr, "pngvalid: no write support in libpng, all tests skipped\n"); + return 0; +} +#endif