update libpng

update libpng, the repo now requires a vcpkg setup for integrating but skipping the install step should allow it to work for windows an linux, mac might need more
This commit is contained in:
marauder2k7 2025-12-31 20:11:14 +00:00
parent c593d860a0
commit 5d644b4ffb
300 changed files with 25573 additions and 17698 deletions

View file

@ -2,8 +2,6 @@
#
# Copyright (c) 2013 John Cunningham Bowler
#
# Last changed in libpng 1.6.0 [February 14, 2013]
#
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h

View file

@ -3,8 +3,6 @@
/* Copyright: */
#define COPYRIGHT "\251 2013,2015 John Cunningham Bowler"
/*
* Last changed in libpng 1.6.20 [November 24, 2015]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -299,25 +297,28 @@ generate_palette(png_colorp palette, png_bytep trans, int bit_depth,
unsigned int x, y;
volatile unsigned int ip = 0;
for (x=0; x<size; ++x) for (y=0; y<size; ++y)
for (x=0; x<size; ++x)
{
ip = x + (size * y);
for (y=0; y<size; ++y)
{
ip = x + (size * y);
/* size is at most 16, so the scaled value below fits in 16 bits
*/
# define interp(pos, c1, c2) ((pos * c1) + ((size-pos) * c2))
# define xyinterp(x, y, c1, c2, c3, c4) (((size * size / 2) +\
(interp(x, c1, c2) * y + (size-y) * interp(x, c3, c4))) /\
(size*size))
/* size is at most 16, so the scaled value below fits in 16 bits
*/
# define interp(pos, c1, c2) ((pos * c1) + ((size-pos) * c2))
# define xyinterp(x, y, c1, c2, c3, c4) (((size * size / 2) +\
(interp(x, c1, c2) * y + (size-y) * interp(x, c3, c4))) /\
(size*size))
set_color(palette+ip, trans+ip,
/* color: green, red,blue,white */
xyinterp(x, y, 0, 255, 0, 255),
xyinterp(x, y, 255, 0, 0, 255),
xyinterp(x, y, 0, 0, 255, 255),
/* alpha: 0, 102, 204, 255) */
xyinterp(x, y, 0, 102, 204, 255),
gamma_table);
set_color(palette+ip, trans+ip,
/* color: green, red,blue,white */
xyinterp(x, y, 0, 255, 0, 255),
xyinterp(x, y, 255, 0, 0, 255),
xyinterp(x, y, 0, 0, 255, 255),
/* alpha: 0, 102, 204, 255) */
xyinterp(x, y, 0, 102, 204, 255),
gamma_table);
}
}
return ip+1;
@ -396,7 +397,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
image_size_of_type(color_type, bit_depth, colors, small)-1;
png_uint_32 depth_max = (1U << bit_depth)-1; /* up to 65536 */
if (colors[0] == 0) if (small)
if (colors[0] == 0 && small)
{
unsigned int pixel_depth = pixel_depth_of_type(color_type, bit_depth);
@ -495,7 +496,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
case 32:
case 48:
case 64:
/* The rows are filled by an alogorithm similar to the above, in the
/* The rows are filled by an algorithm similar to the above, in the
* first row pixel bytes are all equal, increasing from 0 by 1 for
* each pixel. In the second row the bytes within a pixel are
* incremented 1,3,5,7,... from the previous row byte. Using an odd
@ -858,10 +859,13 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
{
unsigned int i;
if (real_gamma == 45455) for (i=0; i<256; ++i)
if (real_gamma == 45455)
{
gamma_table[i] = (png_byte)i;
conv = 1.;
for (i=0; i<256; ++i)
{
gamma_table[i] = (png_byte)i;
conv = 1.;
}
}
else
@ -1430,10 +1434,13 @@ find_parameters(png_const_charp what, png_charp param, png_charp *list,
for (i=0; *param && i<nparams; ++i)
{
list[i] = param;
while (*++param) if (*param == '\n' || *param == ':')
while (*++param)
{
*param++ = 0; /* Terminate last parameter */
break; /* And start a new one. */
if (*param == '\n' || *param == ':')
{
*param++ = 0; /* Terminate last parameter */
break; /* And start a new one. */
}
}
}
@ -1869,7 +1876,7 @@ main(int argc, char **argv)
}
}
/* small and colors are incomparible (will probably crash if both are used at
/* small and colors are incompatible (will probably crash if both are used at
* the same time!)
*/
if (small && colors[0] != 0)

View file

@ -1,9 +1,8 @@
/* pngimage.c
*
* Copyright (c) 2021-2025 Cosmin Truta
* Copyright (c) 2015,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.24 [August 4, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -12,6 +11,7 @@
* using png_read_png and then write with png_write_png. Test all possible
* transforms.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@ -39,7 +39,7 @@
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
#if defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
@ -317,11 +317,10 @@ transform_name(int t)
t &= -t; /* first set bit */
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{
if ((transform_info[i].transform & t) != 0)
return transform_info[i].name;
}
for (i=0; i<TTABLE_SIZE; ++i)
if (transform_info[i].name != NULL)
if ((transform_info[i].transform & t) != 0)
return transform_info[i].name;
return "invalid transform";
}
@ -338,13 +337,16 @@ validate_T(void)
{
unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
for (i=0; i<TTABLE_SIZE; ++i)
{
if (transform_info[i].when & TRANSFORM_R)
read_transforms |= transform_info[i].transform;
if (transform_info[i].name != NULL)
{
if (transform_info[i].when & TRANSFORM_R)
read_transforms |= transform_info[i].transform;
if (transform_info[i].when & TRANSFORM_W)
write_transforms |= transform_info[i].transform;
if (transform_info[i].when & TRANSFORM_W)
write_transforms |= transform_info[i].transform;
}
}
/* Reversible transforms are those which are supported on both read and
@ -540,6 +542,7 @@ typedef enum
struct display
{
jmp_buf error_return; /* Where to go to on error */
error_level error_code; /* Set before longjmp */
const char *filename; /* The name of the original file */
const char *operation; /* Operation being performed */
@ -760,7 +763,10 @@ display_log(struct display *dp, error_level level, const char *fmt, ...)
/* Errors cause this routine to exit to the fail code */
if (level > APP_FAIL || (level > ERRORS && !(dp->options & CONTINUE)))
{
dp->error_code = level;
longjmp(dp->error_return, level);
}
}
/* error handler callbacks for libpng */
@ -962,21 +968,24 @@ update_display(struct display *dp)
int bd = dp->bit_depth;
unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
for (i=0; i<TTABLE_SIZE; ++i)
{
int transform = transform_info[i].transform;
if (transform_info[i].name != NULL)
{
int transform = transform_info[i].transform;
if ((transform_info[i].valid_chunks == 0 ||
(transform_info[i].valid_chunks & chunks) != 0) &&
(transform_info[i].color_mask_required & ct) ==
transform_info[i].color_mask_required &&
(transform_info[i].color_mask_absent & ct) == 0 &&
(transform_info[i].bit_depths & bd) != 0 &&
(transform_info[i].when & TRANSFORM_R) != 0)
active |= transform;
if ((transform_info[i].valid_chunks == 0 ||
(transform_info[i].valid_chunks & chunks) != 0) &&
(transform_info[i].color_mask_required & ct) ==
transform_info[i].color_mask_required &&
(transform_info[i].color_mask_absent & ct) == 0 &&
(transform_info[i].bit_depths & bd) != 0 &&
(transform_info[i].when & TRANSFORM_R) != 0)
active |= transform;
else if ((transform_info[i].when & TRANSFORM_R) != 0)
inactive |= transform;
else if ((transform_info[i].when & TRANSFORM_R) != 0)
inactive |= transform;
}
}
/* Some transforms appear multiple times in the table; the 'active' status
@ -1000,8 +1009,9 @@ compare_read(struct display *dp, int applied_transforms)
int interlace_method, compression_method, filter_method;
const char *e = NULL;
png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth,
&color_type, &interlace_method, &compression_method, &filter_method);
if (!png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth,
&color_type, &interlace_method, &compression_method, &filter_method))
display_log(dp, LIBPNG_BUG, "png_get_IHDR failed");
# define C(item) if (item != dp->item) \
display_log(dp, APP_WARNING, "IHDR " #item "(%lu) changed to %lu",\
@ -1012,7 +1022,12 @@ compare_read(struct display *dp, int applied_transforms)
C(height);
C(bit_depth);
C(color_type);
C(interlace_method);
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* If write interlace has been disabled, the PNG file is still
* written correctly, but as a regular (not-interlaced) PNG.
*/
C(interlace_method);
# endif
C(compression_method);
C(filter_method);
@ -1081,8 +1096,9 @@ compare_read(struct display *dp, int applied_transforms)
size_t x;
/* Find the first error */
for (x=0; x<rowbytes-1; ++x) if (row[x] != orig[x])
break;
for (x=0; x<rowbytes-1; ++x)
if (row[x] != orig[x])
break;
display_log(dp, APP_FAIL,
"byte(%lu,%lu) changed 0x%.2x -> 0x%.2x",
@ -1137,6 +1153,7 @@ compare_read(struct display *dp, int applied_transforms)
display_log(dp, LIBPNG_ERROR, "invalid colour type %d",
color_type);
/*NOTREACHED*/
memset(sig_bits, 0, sizeof(sig_bits));
bpp = 0;
break;
}
@ -1198,7 +1215,7 @@ compare_read(struct display *dp, int applied_transforms)
sig_bits[0] = (png_byte)b;
break;
case 4: /* Relicate twice */
case 4: /* Replicate twice */
/* Value is 1, 2, 3 or 4 */
b = 0xf & ((0xf << 4) >> sig_bits[0]);
b |= b << 4;
@ -1557,18 +1574,19 @@ static int
do_test(struct display *dp, const char *file)
/* Exists solely to isolate the setjmp clobbers */
{
int ret = setjmp(dp->error_return);
dp->error_code = VERBOSE; /* The "lowest" level */
if (ret == 0)
if (setjmp(dp->error_return) == 0)
{
test_one_file(dp, file);
return 0;
}
else if (ret < ERRORS) /* shouldn't longjmp on warnings */
display_log(dp, INTERNAL_ERROR, "unexpected return code %d", ret);
else if (dp->error_code < ERRORS) /* shouldn't longjmp on warnings */
display_log(dp, INTERNAL_ERROR, "unexpected return code %d",
dp->error_code);
return ret;
return dp->error_code;
}
int
@ -1668,7 +1686,11 @@ main(int argc, char **argv)
int ret = do_test(&d, argv[i]);
if (ret > QUIET) /* abort on user or internal error */
{
display_clean(&d);
display_destroy(&d);
return 99;
}
}
/* Here on any return, including failures, except user/internal issues
@ -1686,8 +1708,9 @@ main(int argc, char **argv)
printf("%s: pngimage ", pass ? "PASS" : "FAIL");
for (j=1; j<option_end; ++j) if (j != ilog)
printf("%s ", argv[j]);
for (j=1; j<option_end; ++j)
if (j != ilog)
printf("%s ", argv[j]);
printf("%s\n", d.filename);
}

View file

@ -1,7 +1,6 @@
/*-
* pngstest.c
/* pngstest.c
*
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2021-2025 Cosmin Truta
* Copyright (c) 2013-2017 John Cunningham Bowler
*
* This code is released under the libpng license.
@ -10,8 +9,9 @@
*
* Test for the PNG 'simplified' APIs.
*/
#define _ISOC90_SOURCE 1
#define MALLOC_CHECK_ 2/*glibc facility: turn on debugging*/
#define MALLOC_CHECK_ 2 /*glibc facility: turn on debugging*/
#include <stddef.h>
#include <stdlib.h>
@ -37,7 +37,7 @@
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
#if defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
@ -595,7 +595,8 @@ newimage(Image *image)
memset(image, 0, sizeof *image);
}
/* Reset the image to be read again - only needs to rewind the FILE* at present.
/* Reset the image to be read again - only needs to rewind the FILE object at
* present.
*/
static void
resetimage(Image *image)
@ -1150,7 +1151,7 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
*
* 2) Remove color by mapping to grayscale. (Grayscale to color is a no-op.)
*
* 3) Convert between 8-bit and 16-bit components. (Both directtions are
* 3) Convert between 8-bit and 16-bit components. (Both directions are
* relevant.)
*
* This gives the following base format conversion matrix:
@ -2701,7 +2702,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
{
if ((a->opts & ACCUMULATE) == 0)
{
char pindex[9];
char pindex[16];
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
(unsigned long)a->image.colormap_entries);
logerror(a, a->file_name, ": bad pixel index: ", pindex);
@ -2712,12 +2713,12 @@ compare_two_images(Image *a, Image *b, int via_linear,
else if (y >= b->image.colormap_entries)
{
if ((b->opts & ACCUMULATE) == 0)
{
char pindex[9];
{
char pindex[16];
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
(unsigned long)b->image.colormap_entries);
logerror(b, b->file_name, ": bad pixel index: ", pindex);
}
}
result = 0;
}
@ -2820,8 +2821,11 @@ compare_two_images(Image *a, Image *b, int via_linear,
bchannels = component_loc(bloc, formatb);
/* Hence the btoa array. */
for (i=0; i<4; ++i) if (bloc[i] < 4)
btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */
for (i=0; i<4; ++i)
{
if (bloc[i] < 4)
btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */
}
if (alpha_added)
alpha_added = bloc[0]; /* location of alpha channel in image b */
@ -3209,10 +3213,10 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
else if (image->opts & USE_FILE)
{
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
static int counter = 0;
static unsigned int counter = 0;
char name[32];
sprintf(name, "%s%d.png", tmpf, ++counter);
sprintf(name, "%s%u.png", tmpf, ++counter);
if (png_image_write_to_file(&image->image, name, convert_to_8bit,
image->buffer+16, (png_int_32)image->stride, image->colormap))
@ -3496,7 +3500,7 @@ main(int argc, char **argv)
int retval = 0;
int c;
#if PNG_LIBPNG_VER >= 10700
#if PNG_LIBPNG_VER == 10700
/* This error should not exist in 1.7 or later: */
opts |= GBG_ERROR;
#endif

View file

@ -1,7 +1,6 @@
/* pngunknown.c - test the read side unknown chunk handling
*
* Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 2021-2025 Cosmin Truta
* Copyright (c) 2015,2017 Glenn Randers-Pehrson
* Written by John Cunningham Bowler
*
@ -33,7 +32,7 @@
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
#if defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
@ -55,48 +54,7 @@
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) ||\
defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
#if PNG_LIBPNG_VER < 10500
/* This deliberately lacks the const. */
typedef png_byte *png_const_bytep;
/* This is copied from 1.5.1 png.h: */
#define PNG_INTERLACE_ADAM7_PASSES 7
#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)
#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)
#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
-1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
-1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
(((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
#define PNG_COL_FROM_PASS_COL(xIn, pass) \
(((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
#define PNG_PASS_MASK(pass,off) ( \
((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \
((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))
#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
/* These are needed too for the default build: */
#define PNG_WRITE_16BIT_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
/* This comes from pnglibconf.h after 1.5: */
#define PNG_FP_1 100000
#define PNG_GAMMA_THRESHOLD_FIXED\
((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1))
#endif
#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
#if PNG_LIBPNG_VER < 10700
/* Copied from libpng 1.7.0 png.h */
@ -114,6 +72,8 @@ typedef png_byte *png_const_bytep;
#define png_PLTE PNG_U32( 80, 76, 84, 69)
#define png_bKGD PNG_U32( 98, 75, 71, 68)
#define png_cHRM PNG_U32( 99, 72, 82, 77)
#define png_cICP PNG_U32( 99, 73, 67, 80) /* PNGv3 */
#define png_cLLI PNG_U32( 99, 76, 76, 73) /* PNGv3 */
#define png_eXIf PNG_U32(101, 88, 73, 102) /* registered July 2017 */
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
#define png_gAMA PNG_U32(103, 65, 77, 65)
@ -123,6 +83,7 @@ typedef png_byte *png_const_bytep;
#define png_hIST PNG_U32(104, 73, 83, 84)
#define png_iCCP PNG_U32(105, 67, 67, 80)
#define png_iTXt PNG_U32(105, 84, 88, 116)
#define png_mDCV PNG_U32(109, 68, 67, 86) /* PNGv3 */
#define png_oFFs PNG_U32(111, 70, 70, 115)
#define png_pCAL PNG_U32(112, 67, 65, 76)
#define png_pHYs PNG_U32(112, 72, 89, 115)
@ -209,6 +170,20 @@ static struct
0,
# else
1,
# endif
1, START, 0 },
{ "cICP", PNG_INFO_cICP, png_cICP,
# ifdef PNG_READ_cICP_SUPPORTED
0,
# else
1,
# endif
1, START, 0 },
{ "cLLI", PNG_INFO_cLLI, png_cLLI,
# ifdef PNG_READ_cLLI_SUPPORTED
0,
# else
1,
# endif
1, START, 0 },
{ "eXIf", PNG_INFO_eXIf, png_eXIf,
@ -246,6 +221,13 @@ static struct
1,
# endif
1, ABSENT, 0 },
{ "mDCV", PNG_INFO_mDCV, png_mDCV,
# ifdef PNG_READ_mDCV_SUPPORTED
0,
# else
1,
# endif
1, START, 0 },
{ "oFFs", PNG_INFO_oFFs, png_oFFs,
# ifdef PNG_READ_oFFs_SUPPORTED
0,
@ -370,7 +352,9 @@ find_by_flag(png_uint_32 flag)
{
int i = NINFO;
while (--i >= 0) if (chunk_info[i].flag == flag) return i;
while (--i >= 0)
if (chunk_info[i].flag == flag)
return i;
fprintf(stderr, "pngunknown: internal error\n");
exit(4);
@ -547,27 +531,30 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
case PNG_HANDLE_CHUNK_AS_DEFAULT:
case PNG_HANDLE_CHUNK_NEVER:
discard = 1/*handled; discard*/;
discard = 1; /*handled; discard*/
break;
case PNG_HANDLE_CHUNK_IF_SAFE:
case PNG_HANDLE_CHUNK_ALWAYS:
discard = 0/*not handled; keep*/;
discard = 0; /*not handled; keep*/
break;
}
/* Also store information about this chunk in the display, the relevant flag
* is set if the chunk is to be kept ('not handled'.)
*/
if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */
if (chunk >= 0)
{
png_uint_32 flag = chunk_info[chunk].flag;
if (!discard) /* stupidity to stop a GCC warning */
{
png_uint_32 flag = chunk_info[chunk].flag;
if (pc->location & PNG_AFTER_IDAT)
d->after_IDAT |= flag;
if (pc->location & PNG_AFTER_IDAT)
d->after_IDAT |= flag;
else
d->before_IDAT |= flag;
else
d->before_IDAT |= flag;
}
}
/* However if there is no support to store unknown chunks don't ask libpng to
@ -841,8 +828,9 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
{
png_uint_32 y;
for (y=0; y<height; ++y) if (PNG_ROW_IN_INTERLACE_PASS(y, ipass))
png_read_row(d->png_ptr, NULL, NULL);
for (y=0; y<height; ++y)
if (PNG_ROW_IN_INTERLACE_PASS(y, ipass))
png_read_row(d->png_ptr, NULL, NULL);
}
}
} /* interlaced */
@ -1091,15 +1079,15 @@ perform_one_test_safe(FILE *fp, int argc, const char **argv,
static const char *standard_tests[] =
{
"discard", "default=discard", 0,
"save", "default=save", 0,
"if-safe", "default=if-safe", 0,
"vpAg", "vpAg=if-safe", 0,
"sTER", "sTER=if-safe", 0,
"IDAT", "default=discard", "IDAT=save", 0,
"sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save",
"sBIT=save", "sRGB=save", "eXIf=save", 0,
0/*end*/
"discard", "default=discard", NULL,
"save", "default=save", NULL,
"if-safe", "default=if-safe", NULL,
"vpAg", "vpAg=if-safe", NULL,
"sTER", "sTER=if-safe", NULL,
"IDAT", "default=discard", "IDAT=save", NULL,
"sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save",
"sBIT=save", "sRGB=save", "eXIf=save", NULL,
NULL /*end*/
};
static PNG_NORETURN void
@ -1115,7 +1103,7 @@ int
main(int argc, const char **argv)
{
FILE *fp;
png_uint_32 default_flags[4/*valid,unknown{before,after}*/];
png_uint_32 default_flags[4]; /*valid,unknown{before,after}*/
int strict = 0, default_tests = 0;
const char *count_argv = "default=save";
const char *touch_file = NULL;
@ -1153,8 +1141,9 @@ main(int argc, const char **argv)
/* GCC BUG: if (default_tests && argc != 1) triggers some weird GCC argc
* optimization which causes warnings with -Wstrict-overflow!
*/
else if (default_tests) if (argc != 1)
usage(d.program, "extra arguments");
else if (default_tests)
if (argc != 1)
usage(d.program, "extra arguments");
/* The name of the test file is the last argument; remove it. */
d.file = argv[--argc];
@ -1216,7 +1205,11 @@ main(int argc, const char **argv)
const char *result;
int arg_count = 0;
while (*next) ++next, ++arg_count;
while (*next != NULL)
{
++next;
++arg_count;
}
perform_one_test_safe(fp, arg_count, test, default_flags, &d,
this_test);

View file

@ -1,7 +1,6 @@
/* pngvalid.c - validate libpng by constructing then reading png files.
*
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2021-2025 Cosmin Truta
* Copyright (c) 2014-2017 John Cunningham Bowler
*
* This code is released under the libpng license.
@ -22,6 +21,7 @@
#define _ISOC99_SOURCE 1 /* For floating point */
#define _GNU_SOURCE 1 /* For the floating point exception extension */
#define _BSD_SOURCE 1 /* For the floating point exception extension */
#define _DEFAULT_SOURCE 1 /* For the floating point exception extension */
#include <signal.h>
#include <stdio.h>
@ -62,59 +62,21 @@
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
#if defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
/* pngvalid requires write support and one of the fixed or floating point APIs.
* progressive read is also required currently as the progressive read pointer
* is used to record the 'display' structure.
*/
#if defined(PNG_WRITE_SUPPORTED) &&\
(defined(PNG_FIXED_POINT_SUPPORTED) || defined(PNG_FLOATING_POINT_SUPPORTED))
#if defined PNG_WRITE_SUPPORTED &&\
(defined PNG_PROGRESSIVE_READ_SUPPORTED) &&\
(defined PNG_FIXED_POINT_SUPPORTED || defined PNG_FLOATING_POINT_SUPPORTED)
#if PNG_LIBPNG_VER < 10500
/* This deliberately lacks the const. */
typedef png_byte *png_const_bytep;
/* This is copied from 1.5.1 png.h: */
#define PNG_INTERLACE_ADAM7_PASSES 7
#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)
#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)
#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
-1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
-1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
(((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
#define PNG_COL_FROM_PASS_COL(xIn, pass) \
(((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
#define PNG_PASS_MASK(pass,off) ( \
((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \
((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))
#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
/* These are needed too for the default build: */
#define PNG_WRITE_16BIT_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
/* This comes from pnglibconf.h after 1.5: */
#define PNG_FP_1 100000
#define PNG_GAMMA_THRESHOLD_FIXED\
((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1))
#endif
#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
#ifndef RELEASE_BUILD
/* RELEASE_BUILD is true for releases and release candidates: */
@ -300,20 +262,20 @@ make_four_random_bytes(png_uint_32* seed, png_bytep bytes)
#if defined PNG_READ_SUPPORTED || defined PNG_WRITE_tRNS_SUPPORTED ||\
defined PNG_WRITE_FILTER_SUPPORTED
static void
randomize(void *pv, size_t size)
randomize_bytes(void *pv, size_t size)
{
static png_uint_32 random_seed[2] = {0x56789abc, 0xd};
make_random_bytes(random_seed, pv, size);
}
#define R8(this) randomize(&(this), sizeof (this))
#define R8(this) randomize_bytes(&(this), sizeof (this))
#ifdef PNG_READ_SUPPORTED
static png_byte
random_byte(void)
{
unsigned char b1[1];
randomize(b1, sizeof b1);
randomize_bytes(b1, sizeof b1);
return b1[0];
}
#endif /* READ */
@ -322,7 +284,7 @@ static png_uint_16
random_u16(void)
{
unsigned char b2[2];
randomize(b2, sizeof b2);
randomize_bytes(b2, sizeof b2);
return png_get_uint_16(b2);
}
@ -332,7 +294,7 @@ static png_uint_32
random_u32(void)
{
unsigned char b4[4];
randomize(b4, sizeof b4);
randomize_bytes(b4, sizeof b4);
return png_get_uint_32(b4);
}
#endif /* READ_FILLER || READ_RGB_TO_GRAY */
@ -644,34 +606,8 @@ row_copy(png_bytep toBuffer, png_const_bytep fromBuffer, unsigned int bitWidth,
static int
pixel_cmp(png_const_bytep pa, png_const_bytep pb, png_uint_32 bit_width)
{
#if PNG_LIBPNG_VER < 10506
if (memcmp(pa, pb, bit_width>>3) == 0)
{
png_uint_32 p;
if ((bit_width & 7) == 0) return 0;
/* Ok, any differences? */
p = pa[bit_width >> 3];
p ^= pb[bit_width >> 3];
if (p == 0) return 0;
/* There are, but they may not be significant, remove the bits
* after the end (the low order bits in PNG.)
*/
bit_width &= 7;
p >>= 8-bit_width;
if (p == 0) return 0;
}
#else
/* From libpng-1.5.6 the overwrite should be fixed, so compare the trailing
* bits too:
*/
if (memcmp(pa, pb, (bit_width+7)>>3) == 0)
return 0;
#endif
/* Return the index of the changed byte. */
{
@ -2570,7 +2506,7 @@ modifier_init(png_modifier *pm)
* in the rgb_to_gray check, replacing it with an exact copy of the libpng 1.5
* algorithm.
*/
#define DIGITIZE PNG_LIBPNG_VER < 10700
#define DIGITIZE PNG_LIBPNG_VER != 10700
/* If pm->calculations_use_input_precision is set then operations will happen
* with the precision of the input, not the precision of the output depth.
@ -3982,7 +3918,7 @@ transform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX],
# define check_interlace_type(type) ((void)(type))
# define set_write_interlace_handling(pp,type) png_set_interlace_handling(pp)
# define do_own_interlace 0
#elif PNG_LIBPNG_VER < 10700
#elif PNG_LIBPNG_VER != 10700
# define set_write_interlace_handling(pp,type) (1)
static void
check_interlace_type(int const interlace_type)
@ -4010,7 +3946,7 @@ check_interlace_type(int const interlace_type)
# define do_own_interlace 1
#endif /* WRITE_INTERLACING tests */
#if PNG_LIBPNG_VER >= 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
#if PNG_LIBPNG_VER == 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
# define CAN_WRITE_INTERLACE 1
#else
# define CAN_WRITE_INTERLACE 0
@ -4629,10 +4565,10 @@ static const struct
{
/* no warnings makes these errors undetectable prior to 1.7.0 */
{ sBIT0_error_fn, "sBIT(0): failed to detect error",
PNG_LIBPNG_VER < 10700 },
PNG_LIBPNG_VER != 10700 },
{ sBIT_error_fn, "sBIT(too big): failed to detect error",
PNG_LIBPNG_VER < 10700 },
PNG_LIBPNG_VER != 10700 },
};
static void
@ -4848,9 +4784,7 @@ perform_formatting_test(png_store *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
char timestring[29];
png_structp pp;
png_time pt;
@ -5822,8 +5756,9 @@ test_standard(png_modifier* const pm, png_byte const colour_type,
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < INTERLACE_LAST; ++interlace_type)
{
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
interlace_type, 0, 0, 0), do_read_interlace, pm->use_update_info);
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, interlace_type, 0, 0, 0), do_read_interlace,
pm->use_update_info);
if (fail(pm))
return 0;
@ -5876,47 +5811,50 @@ test_size(png_modifier* const pm, png_byte const colour_type,
{
png_uint_32 h, w;
for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo])
for (h=1; h<=16; h+=hinc[bdlo])
{
/* First test all the 'size' images against the sequential
* reader using libpng to deinterlace (where required.) This
* validates the write side of libpng. There are four possibilities
* to validate.
*/
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/,
pm->use_update_info);
for (w=1; w<=16; w+=winc[bdlo])
{
/* First test all the 'size' images against the sequential
* reader using libpng to deinterlace (where required.) This
* validates the write side of libpng. There are four possibilities
* to validate.
*/
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
if (fail(pm))
return 0;
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/,
pm->use_update_info);
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
if (fail(pm))
return 0;
/* Now validate the interlaced read side - do_interlace true,
* in the progressive case this does actually make a difference
* to the code used in the non-interlaced case too.
*/
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/,
pm->use_update_info);
/* Now validate the interlaced read side - do_interlace true,
* in the progressive case this does actually make a difference
* to the code used in the non-interlaced case too.
*/
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
if (fail(pm))
return 0;
# if CAN_WRITE_INTERLACE
/* Validate the pngvalid code itself: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 1), 1/*do_interlace*/,
pm->use_update_info);
# if CAN_WRITE_INTERLACE
/* Validate the pngvalid code itself: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 1), 1/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
# endif
if (fail(pm))
return 0;
# endif
}
}
}
@ -5927,45 +5865,48 @@ test_size(png_modifier* const pm, png_byte const colour_type,
{
png_uint_32 h, w;
for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo])
for (h=1; h<=16; h+=hinc[bdlo])
{
# ifdef PNG_READ_INTERLACING_SUPPORTED
/* Test with pngvalid generated interlaced images first; we have
* already verify these are ok (unless pngvalid has self-consistent
* read/write errors, which is unlikely), so this detects errors in the
* read side first:
*/
# if CAN_WRITE_INTERLACE
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/,
pm->use_update_info);
for (w=1; w<=16; w+=winc[bdlo])
{
# ifdef PNG_READ_INTERLACING_SUPPORTED
/* Test with pngvalid generated interlaced images first; we have
* already verify these are ok (unless pngvalid has self-consistent
* read/write errors, which is unlikely), so this detects errors in
* the read side first:
*/
# if CAN_WRITE_INTERLACE
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
# endif
# endif /* READ_INTERLACING */
if (fail(pm))
return 0;
# endif
# endif /* READ_INTERLACING */
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Test the libpng write side against the pngvalid read side: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/,
pm->use_update_info);
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Test the libpng write side against the pngvalid read side: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
# endif
if (fail(pm))
return 0;
# endif
# ifdef PNG_READ_INTERLACING_SUPPORTED
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Test both together: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/,
pm->use_update_info);
# ifdef PNG_READ_INTERLACING_SUPPORTED
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Test both together: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
# endif
# endif /* READ_INTERLACING */
if (fail(pm))
return 0;
# endif
# endif /* READ_INTERLACING */
}
}
}
@ -6225,7 +6166,7 @@ image_pixel_add_alpha(image_pixel *this, const standard_display *display,
{
if (this->colour_type == PNG_COLOR_TYPE_GRAY)
{
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (!for_background && this->bit_depth < 8)
this->bit_depth = this->sample_depth = 8;
# endif
@ -6235,7 +6176,7 @@ image_pixel_add_alpha(image_pixel *this, const standard_display *display,
/* After 1.7 the expansion of bit depth only happens if there is a
* tRNS chunk to expand at this point.
*/
# if PNG_LIBPNG_VER >= 10700
# if PNG_LIBPNG_VER == 10700
if (!for_background && this->bit_depth < 8)
this->bit_depth = this->sample_depth = 8;
# endif
@ -6711,7 +6652,7 @@ transform_range_check(png_const_structp pp, unsigned int r, unsigned int g,
unsigned int out, png_byte sample_depth, double err, double limit,
const char *name, double digitization_error)
{
/* Compare the scaled, digitzed, values of our local calculation (in+-err)
/* Compare the scaled, digitized, values of our local calculation (in+-err)
* with the digitized values libpng produced; 'sample_depth' is the actual
* digitization depth of the libpng output colors (the bit depth except for
* palette images where it is always 8.) The check on 'err' is to detect
@ -7116,7 +7057,7 @@ image_transform_png_set_tRNS_to_alpha_mod(const image_transform *this,
image_pixel *that, png_const_structp pp,
const transform_display *display)
{
#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
/* LIBPNG BUG: this always forces palette images to RGB. */
if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
image_pixel_convert_PLTE(that);
@ -7126,13 +7067,13 @@ image_transform_png_set_tRNS_to_alpha_mod(const image_transform *this,
* convert to an alpha channel.
*/
if (that->have_tRNS)
# if PNG_LIBPNG_VER >= 10700
# if PNG_LIBPNG_VER == 10700
if (that->colour_type != PNG_COLOR_TYPE_PALETTE &&
(that->colour_type & PNG_COLOR_MASK_ALPHA) == 0)
# endif
image_pixel_add_alpha(that, &display->this, 0/*!for background*/);
#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
/* LIBPNG BUG: otherwise libpng still expands to 8 bits! */
else
{
@ -7161,7 +7102,7 @@ image_transform_png_set_tRNS_to_alpha_add(image_transform *this,
* any action on a palette image.
*/
return
# if PNG_LIBPNG_VER >= 10700
# if PNG_LIBPNG_VER == 10700
colour_type != PNG_COLOR_TYPE_PALETTE &&
# endif
(colour_type & PNG_COLOR_MASK_ALPHA) == 0;
@ -7302,7 +7243,7 @@ image_transform_png_set_expand_gray_1_2_4_to_8_mod(
const image_transform *this, image_pixel *that, png_const_structp pp,
const transform_display *display)
{
#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
image_transform_png_set_expand_mod(this, that, pp, display);
#else
/* Only expand grayscale of bit depth less than 8: */
@ -7318,7 +7259,7 @@ static int
image_transform_png_set_expand_gray_1_2_4_to_8_add(image_transform *this,
const image_transform **that, png_byte colour_type, png_byte bit_depth)
{
#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
return image_transform_png_set_expand_add(this, that, colour_type,
bit_depth);
#else
@ -7348,7 +7289,7 @@ image_transform_png_set_expand_16_set(const image_transform *this,
png_set_expand_16(pp);
/* NOTE: prior to 1.7 libpng does SET_EXPAND as well, so tRNS is expanded. */
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (that->this.has_tRNS)
that->this.is_transparent = 1;
# endif
@ -7401,7 +7342,7 @@ image_transform_png_set_scale_16_set(const image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_scale_16(pp);
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
/* libpng will limit the gamma table size: */
that->max_gamma_8 = PNG_MAX_GAMMA_8;
# endif
@ -7449,7 +7390,7 @@ image_transform_png_set_strip_16_set(const image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_strip_16(pp);
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
/* libpng will limit the gamma table size: */
that->max_gamma_8 = PNG_MAX_GAMMA_8;
# endif
@ -7474,22 +7415,7 @@ image_transform_png_set_strip_16_mod(const image_transform *this,
* 'scale' API (above) must be used.
*/
# ifdef PNG_READ_ACCURATE_SCALE_SUPPORTED
# if PNG_LIBPNG_VER >= 10504
# error PNG_READ_ACCURATE_SCALE should not be set
# endif
/* The strip 16 algorithm drops the low 8 bits rather than calculating
* 1/257, so we need to adjust the permitted errors appropriately:
* Notice that this is only relevant prior to the addition of the
* png_set_scale_16 API in 1.5.4 (but 1.5.4+ always defines the above!)
*/
{
const double d = (255-128.5)/65535;
that->rede += d;
that->greene += d;
that->bluee += d;
that->alphae += d;
}
# error PNG_READ_ACCURATE_SCALE should not be set
# endif
}
@ -7635,8 +7561,8 @@ image_transform_png_set_rgb_to_gray_ini(const image_transform *this,
else
{
/* The default (built in) coeffcients, as above: */
# if PNG_LIBPNG_VER < 10700
/* The default (built in) coefficients, as above: */
# if PNG_LIBPNG_VER != 10700
data.red_coefficient = 6968 / 32768.;
data.green_coefficient = 23434 / 32768.;
data.blue_coefficient = 2366 / 32768.;
@ -7719,7 +7645,7 @@ image_transform_png_set_rgb_to_gray_ini(const image_transform *this,
* conversion adds another +/-2 in the 16-bit case and
* +/-(1<<(15-PNG_MAX_GAMMA_8)) in the 8-bit case.
*/
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (that->this.bit_depth < 16)
that->max_gamma_8 = PNG_MAX_GAMMA_8;
# endif
@ -7896,7 +7822,7 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
{
double gray, err;
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
image_pixel_convert_PLTE(that);
# endif
@ -8083,7 +8009,7 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
double b = that->bluef;
double be = that->bluee;
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
/* The true gray case involves no math in earlier versions (not
* true, there was some if gamma correction was happening too.)
*/
@ -9057,7 +8983,7 @@ image_transform_reset_count(void)
static int
image_transform_test_counter(png_uint_32 counter, unsigned int max)
{
/* Test the list to see if there is any point contining, given a current
/* Test the list to see if there is any point continuing, given a current
* counter and a 'max' value.
*/
image_transform *next = image_transform_first;
@ -9862,7 +9788,7 @@ gamma_component_validate(const char *name, const validate_info *vi,
* lost. This can result in up to a +/-1 error in the presence of
* an sbit less than the bit depth.
*/
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
# define SBIT_ERROR .5
# else
# define SBIT_ERROR 1.
@ -9922,47 +9848,6 @@ gamma_component_validate(const char *name, const validate_info *vi,
* (chop) method of scaling was used.
*/
# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
# if PNG_LIBPNG_VER < 10504
/* This may be required for other components in the future,
* but at present the presence of gamma correction effectively
* prevents the errors in the component scaling (I don't quite
* understand why, but since it's better this way I care not
* to ask, JB 20110419.)
*/
if (pass == 0 && alpha < 0 && vi->scale16 && vi->sbit > 8 &&
vi->sbit + vi->isbit_shift == 16)
{
tmp = ((id >> 8) - .5)/255;
if (tmp > 0)
{
is_lo = ceil(outmax * tmp - vi->maxout_total);
if (is_lo < 0) is_lo = 0;
}
else
is_lo = 0;
tmp = ((id >> 8) + .5)/255;
if (tmp < 1)
{
is_hi = floor(outmax * tmp + vi->maxout_total);
if (is_hi > outmax) is_hi = outmax;
}
else
is_hi = outmax;
if (!(od < is_lo || od > is_hi))
{
if (encoded_error < vi->outlog)
return i;
pass = "within 8 bit limits:\n";
}
}
# endif
# endif
}
else /* !use_input_precision */
@ -10001,9 +9886,12 @@ gamma_component_validate(const char *name, const validate_info *vi,
case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:
case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:
# endif /* ALPHA_MODE_SUPPORTED */
# if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
(defined PNG_READ_ALPHA_MODE_SUPPORTED)
do_compose = (alpha > 0 && alpha < 1);
use_input = (alpha != 0);
break;
# endif
default:
break;
@ -10649,16 +10537,21 @@ static void perform_gamma_transform_tests(png_modifier *pm)
{
unsigned int i, j;
for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
if (i != j)
for (i=0; i<pm->ngamma_tests; ++i)
{
for (j=0; j<pm->ngamma_tests; ++j)
{
gamma_transform_test(pm, colour_type, bit_depth, palette_number,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 0/*sBIT*/,
pm->use_input_precision, 0 /*do not scale16*/);
if (i != j)
{
gamma_transform_test(pm, colour_type, bit_depth, palette_number,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
0/*sBIT*/, pm->use_input_precision, 0/*do not scale16*/);
if (fail(pm))
return;
if (fail(pm))
return;
}
}
}
}
}
@ -10687,14 +10580,17 @@ static void perform_gamma_sbit_tests(png_modifier *pm)
{
unsigned int j;
for (j=0; j<pm->ngamma_tests; ++j) if (i != j)
for (j=0; j<pm->ngamma_tests; ++j)
{
gamma_transform_test(pm, colour_type, bit_depth, npalette,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
sbit, pm->use_input_precision_sbit, 0 /*scale16*/);
if (i != j)
{
gamma_transform_test(pm, colour_type, bit_depth, npalette,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
sbit, pm->use_input_precision_sbit, 0 /*scale16*/);
if (fail(pm))
return;
if (fail(pm))
return;
}
}
}
}
@ -10711,7 +10607,7 @@ static void perform_gamma_scale16_tests(png_modifier *pm)
# ifndef PNG_MAX_GAMMA_8
# define PNG_MAX_GAMMA_8 11
# endif
# if defined PNG_MAX_GAMMA_8 || PNG_LIBPNG_VER < 10700
# if defined PNG_MAX_GAMMA_8 || PNG_LIBPNG_VER != 10700
# define SBIT_16_TO_8 PNG_MAX_GAMMA_8
# else
# define SBIT_16_TO_8 16
@ -10946,14 +10842,17 @@ perform_gamma_composition_tests(png_modifier *pm, int do_background,
unsigned int i, j;
/* Don't skip the i==j case here - it's relevant. */
for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
for (i=0; i<pm->ngamma_tests; ++i)
{
gamma_composition_test(pm, colour_type, bit_depth, palette_number,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
pm->use_input_precision, do_background, expand_16);
for (j=0; j<pm->ngamma_tests; ++j)
{
gamma_composition_test(pm, colour_type, bit_depth, palette_number,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
pm->use_input_precision, do_background, expand_16);
if (fail(pm))
return;
if (fail(pm))
return;
}
}
}
}
@ -11056,7 +10955,7 @@ perform_gamma_test(png_modifier *pm, int summary)
pm->calculations_use_input_precision = 0;
if (summary)
summarize_gamma_errors(pm, 0/*who*/, 1/*low bit depth*/, 1/*indexed*/);
summarize_gamma_errors(pm, NULL/*who*/, 1/*low bit depth*/, 1/*indexed*/);
if (fail(pm))
return;
@ -11182,8 +11081,10 @@ png_pass_start_row(int pass)
{
int x, y;
++pass;
for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
return y;
for (y=0; y<8; ++y)
for (x=0; x<8; ++x)
if (adam7[y][x] == pass)
return y;
return 0xf;
}
@ -11192,8 +11093,10 @@ png_pass_start_col(int pass)
{
int x, y;
++pass;
for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
return x;
for (x=0; x<8; ++x)
for (y=0; y<8; ++y)
if (adam7[y][x] == pass)
return x;
return 0xf;
}
@ -11202,18 +11105,24 @@ png_pass_row_shift(int pass)
{
int x, y, base=(-1), inc=8;
++pass;
for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
for (y=0; y<8; ++y)
{
if (base == (-1))
base = y;
else if (base == y)
{}
else if (inc == y-base)
base=y;
else if (inc == 8)
inc = y-base, base=y;
else if (inc != y-base)
return 0xff; /* error - more than one 'inc' value! */
for (x=0; x<8; ++x)
{
if (adam7[y][x] == pass)
{
if (base == (-1))
base = y;
else if (base == y)
{}
else if (inc == y-base)
base=y;
else if (inc == 8)
inc = y-base, base=y;
else if (inc != y-base)
return 0xff; /* error - more than one 'inc' value! */
}
}
}
if (base == (-1)) return 0xfe; /* error - no row in pass! */
@ -11236,18 +11145,24 @@ png_pass_col_shift(int pass)
{
int x, y, base=(-1), inc=8;
++pass;
for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
for (x=0; x<8; ++x)
{
if (base == (-1))
base = x;
else if (base == x)
{}
else if (inc == x-base)
base=x;
else if (inc == 8)
inc = x-base, base=x;
else if (inc != x-base)
return 0xff; /* error - more than one 'inc' value! */
for (y=0; y<8; ++y)
{
if (adam7[y][x] == pass)
{
if (base == (-1))
base = x;
else if (base == x)
{}
else if (inc == x-base)
base=x;
else if (inc == 8)
inc = x-base, base=x;
else if (inc != x-base)
return 0xff; /* error - more than one 'inc' value! */
}
}
}
if (base == (-1)) return 0xfe; /* error - no row in pass! */
@ -11311,8 +11226,9 @@ png_row_in_interlace_pass(png_uint_32 y, int pass)
int x;
y &= 7;
++pass;
for (x=0; x<8; ++x) if (adam7[y][x] == pass)
return 1;
for (x=0; x<8; ++x)
if (adam7[y][x] == pass)
return 1;
return 0;
}
@ -11324,8 +11240,9 @@ png_col_in_interlace_pass(png_uint_32 x, int pass)
int y;
x &= 7;
++pass;
for (y=0; y<8; ++y) if (adam7[y][x] == pass)
return 1;
for (y=0; y<8; ++y)
if (adam7[y][x] == pass)
return 1;
return 0;
}
@ -11339,11 +11256,17 @@ png_pass_rows(png_uint_32 height, int pass)
height &= 7;
++pass;
for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
for (y=0; y<8; ++y)
{
rows += tiles;
if (y < height) ++rows;
break; /* i.e. break the 'x', column, loop. */
for (x=0; x<8; ++x)
{
if (adam7[y][x] == pass)
{
rows += tiles;
if (y < height) ++rows;
break; /* i.e. break the 'x', column, loop. */
}
}
}
return rows;
@ -11358,11 +11281,17 @@ png_pass_cols(png_uint_32 width, int pass)
width &= 7;
++pass;
for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
for (x=0; x<8; ++x)
{
cols += tiles;
if (x < width) ++cols;
break; /* i.e. break the 'y', row, loop. */
for (y=0; y<8; ++y)
{
if (adam7[y][x] == pass)
{
cols += tiles;
if (x < width) ++cols;
break; /* i.e. break the 'y', row, loop. */
}
}
}
return cols;
@ -11681,7 +11610,7 @@ int main(int argc, char **argv)
* code that 16-bit arithmetic is used for 8-bit samples when it would make a
* difference.
*/
pm.assume_16_bit_calculations = PNG_LIBPNG_VER >= 10700;
pm.assume_16_bit_calculations = PNG_LIBPNG_VER == 10700;
/* Currently 16 bit expansion happens at the end of the pipeline, so the
* calculations are done in the input bit depth not the output.
@ -11701,17 +11630,17 @@ int main(int argc, char **argv)
# ifdef PNG_WRITE_tRNS_SUPPORTED
pm.test_tRNS = 1;
# endif
pm.test_lbg = PNG_LIBPNG_VER >= 10600;
pm.test_lbg = 1; /* PNG_LIBPNG_VER >= 10600 */
pm.test_lbg_gamma_threshold = 1;
pm.test_lbg_gamma_transform = PNG_LIBPNG_VER >= 10600;
pm.test_lbg_gamma_transform = 1; /* PNG_LIBPNG_VER >= 10600 */
pm.test_lbg_gamma_sbit = 1;
pm.test_lbg_gamma_composition = PNG_LIBPNG_VER >= 10700;
pm.test_lbg_gamma_composition = PNG_LIBPNG_VER == 10700;
/* And the test encodings */
pm.encodings = test_encodings;
pm.nencodings = ARRAY_SIZE(test_encodings);
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */
# else
pm.sbitlow = 1U;
@ -11719,7 +11648,7 @@ int main(int argc, char **argv)
/* The following allows results to pass if they correspond to anything in the
* transformed range [input-.5,input+.5]; this is is required because of the
* way libpng treates the 16_TO_8 flag when building the gamma tables in
* way libpng treats the 16_TO_8 flag when building the gamma tables in
* releases up to 1.6.0.
*
* TODO: review this
@ -11741,7 +11670,7 @@ int main(int argc, char **argv)
pm.maxout16 = .499; /* Error in *encoded* value */
pm.maxabs16 = .00005;/* 1/20000 */
pm.maxcalc16 =1./65535;/* +/-1 in 16 bits for compose errors */
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
pm.maxcalcG = 1./((1<<PNG_MAX_GAMMA_8)-1);
# else
pm.maxcalcG = 1./((1<<16)-1);
@ -11810,21 +11739,21 @@ int main(int argc, char **argv)
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
else if (strncmp(*argv, "--transform-disable=",
sizeof "--transform-disable") == 0)
{
{
pm.test_transform = 1;
transform_disable(*argv + sizeof "--transform-disable");
}
}
else if (strncmp(*argv, "--transform-enable=",
sizeof "--transform-enable") == 0)
{
{
pm.test_transform = 1;
transform_enable(*argv + sizeof "--transform-enable");
}
}
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
else if (strcmp(*argv, "--gamma") == 0)
{
{
/* Just do two gamma tests here (2.2 and linear) for speed: */
pm.ngamma_tests = 2U;
pm.test_gamma_threshold = 1;
@ -11833,7 +11762,7 @@ int main(int argc, char **argv)
pm.test_gamma_scale16 = 1;
pm.test_gamma_background = 1; /* composition */
pm.test_gamma_alpha_mode = 1;
}
}
else if (strcmp(*argv, "--nogamma") == 0)
pm.ngamma_tests = 0;
@ -11875,7 +11804,14 @@ int main(int argc, char **argv)
pm.test_gamma_alpha_mode = 0;
else if (strcmp(*argv, "--expand16") == 0)
pm.test_gamma_expand16 = 1;
{
# ifdef PNG_READ_EXPAND_16_SUPPORTED
pm.test_gamma_expand16 = 1;
# else
fprintf(stderr, "pngvalid: --expand16: no read support\n");
return SKIP;
# endif
}
else if (strcmp(*argv, "--noexpand16") == 0)
pm.test_gamma_expand16 = 0;
@ -11890,10 +11826,15 @@ int main(int argc, char **argv)
pm.test_lbg_gamma_transform = pm.test_lbg_gamma_sbit =
pm.test_lbg_gamma_composition = 0;
# ifdef PNG_WRITE_tRNS_SUPPORTED
else if (strcmp(*argv, "--tRNS") == 0)
else if (strcmp(*argv, "--tRNS") == 0)
{
# ifdef PNG_WRITE_tRNS_SUPPORTED
pm.test_tRNS = 1;
# endif
# else
fprintf(stderr, "pngvalid: --tRNS: no write support\n");
return SKIP;
# endif
}
else if (strcmp(*argv, "--notRNS") == 0)
pm.test_tRNS = 0;
@ -12147,7 +12088,7 @@ int main(int argc, char **argv)
(pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
pm.this.nwarnings)) ? "FAIL" : "PASS",
command,
#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || PNG_LIBPNG_VER < 10500
#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
"floating"
#else
"fixed"

View file

@ -2,8 +2,6 @@
*
* Copyright (c) 2013 John Cunningham Bowler
*
* Last changed in libpng 1.6.1 [March 28, 2013]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h

View file

@ -1,10 +1,8 @@
/* tarith.c
*
* Copyright (c) 2021 Cosmin Truta
* Copyright (c) 2011-2013 John Cunningham Bowler
*
* Last changed in libpng 1.6.0 [February 14, 2013]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -88,6 +86,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
int minorarith = 0;
while (--argc > 0)
{
if (strcmp(*++argv, "-a") == 0)
showall = 1;
else if (strcmp(*argv, "-e") == 0 && argc > 0)
@ -105,6 +104,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
fprintf(stderr, "unknown argument %s\n", *argv);
return 1;
}
}
do
{
@ -130,8 +130,8 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
*/
if (buffer[precision+7] != 71)
{
fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n", test,
precision, buffer, (unsigned long)strlen(buffer));
fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n",
test, precision, buffer, (unsigned long)strlen(buffer));
failed = 1;
}
@ -146,16 +146,16 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
if (test >= 0 && strcmp(buffer, "inf") ||
test < 0 && strcmp(buffer, "-inf"))
{
fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n", test,
precision, buffer);
fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n",
test, precision, buffer);
failed = 1;
}
}
else if (!png_check_fp_number(buffer, precision+10, &state, &index) ||
buffer[index] != 0)
{
fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n", test,
precision, buffer, buffer[index]);
fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n",
test, precision, buffer, buffer[index]);
failed = 1;
}
else if (PNG_FP_IS_NEGATIVE(state) && !(test < 0))
@ -187,7 +187,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
/* Check the result against the original. */
double out = atof(buffer);
double change = fabs((out - test)/test);
double allow = .5/pow(10,
double allow = .5 / pow(10,
(precision >= DBL_DIG) ? DBL_DIG-1 : precision-1);
/* NOTE: if you hit this error case are you compiling with gcc
@ -257,8 +257,9 @@ skip:
}
while (--count);
printf("Tested %d finite values, %d non-finite, %d OK (%d failed) %d minor "
"arithmetic errors\n", finite, nonfinite, ok, failcount, minorarith);
printf("Tested %d finite values, %d non-finite, %d OK (%d failed) "
"%d minor arithmetic errors\n",
finite, nonfinite, ok, failcount, minorarith);
printf(" Error with >=%d digit precision %.2f%%\n", DBL_DIG, max_abs);
printf(" Error with < %d digit precision %.2f%%\n", DBL_DIG, max);
@ -371,8 +372,8 @@ static int check_one_character(checkfp_command *co, checkfp_control c, int ch)
/* This should never fail (it's a serious bug if it does): */
if (index != 0 && index != 1)
{
fprintf(stderr, "%s: read beyond end of string (%lu)\n", co->number,
(unsigned long)index);
fprintf(stderr, "%s: read beyond end of string (%lu)\n",
co->number, (unsigned long)index);
return 0;
}
@ -503,8 +504,8 @@ static int check_one_character(checkfp_command *co, checkfp_control c, int ch)
if (number_is_valid != c.number_was_valid)
{
fprintf(stderr,
"%s: character '%c' [0x%.2x] changed number validity\n", co->number,
ch, ch);
"%s: character '%c' [0x%.2x] changed number validity\n",
co->number, ch, ch);
return 0;
}
@ -521,10 +522,13 @@ static int check_all_characters(checkfp_command *co, checkfp_control c)
{
int ch;
if (c.cnumber+4 < sizeof co->number) for (ch=0; ch<256; ++ch)
if (c.cnumber+4 < sizeof co->number)
{
if (!check_one_character(co, c, ch))
return 0;
for (ch=0; ch<256; ++ch)
{
if (!check_one_character(co, c, ch))
return 0;
}
}
return 1;
@ -539,10 +543,13 @@ static int check_some_characters(checkfp_command *co, checkfp_control c,
if (c.cnumber+4 < sizeof co->number && c.limit >= 0)
{
if (c.limit > 0) for (i=0; tests[i]; ++i)
if (c.limit > 0)
{
if (!check_one_character(co, c, tests[i]))
return 0;
for (i=0; tests[i]; ++i)
{
if (!check_one_character(co, c, tests[i]))
return 0;
}
}
/* At the end check all the characters. */
@ -616,10 +623,10 @@ int validation_muldiv(int count, int argc, char **argv)
png_int_32 times, div;
while (--argc > 0)
{
fprintf(stderr, "unknown argument %s\n", *++argv);
return 1;
}
{
fprintf(stderr, "unknown argument %s\n", *++argv);
return 1;
}
/* Find out about the random number generator. */
randbuffer = RAND_MAX;
@ -687,25 +694,25 @@ int validation_muldiv(int count, int argc, char **argv)
ok = 0, ++overflow, fpround = fp/*misleading*/;
if (verbose)
fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n", a, times, div,
fp, ok ? "ok" : "overflow");
fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n",
a, times, div, fp, ok ? "ok" : "overflow");
++tested;
if (png_muldiv(&result, a, times, div) != ok)
{
++error;
if (ok)
fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n", a,
times, div, fp);
fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n",
a, times, div, fp);
else
fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n", a,
times, div, result, fp);
fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n",
a, times, div, result, fp);
}
else if (ok && result != fpround)
{
++error;
fprintf(stderr, "%d * %d / %d -> %d not %lld\n", a, times, div, result,
fp);
fprintf(stderr, "%d * %d / %d -> %d not %lld\n",
a, times, div, result, fp);
}
else
++passed;
@ -721,8 +728,8 @@ int validation_muldiv(int count, int argc, char **argv)
}
while (--count > 0);
printf("%d tests including %d overflows, %d passed, %d failed (%d 64-bit "
"errors)\n", tested, overflow, passed, error, error64);
printf("%d tests including %d overflows, %d passed, %d failed "
"(%d 64-bit errors)\n", tested, overflow, passed, error, error64);
return 0;
}
@ -821,8 +828,9 @@ int validation_gamma(int argc, char **argv)
{
if (error > .68) /* By experiment error is less than .68 */
{
fprintf(stderr, "16-bit log error: %d: got %u, expected %f"
" error: %f\n", i, png_log16bit(i), correct, error);
fprintf(stderr,
"16-bit log error: %d: got %u, expected %f error: %f\n",
i, png_log16bit(i), correct, error);
}
}
}
@ -841,8 +849,9 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > 1883) /* By experiment. */
{
fprintf(stderr, "32-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp(i), correct, error);
fprintf(stderr,
"32-bit exp error: %d: got %u, expected %f error: %f\n",
i, png_exp(i), correct, error);
}
}
@ -859,8 +868,9 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > .50002) /* By experiment */
{
fprintf(stderr, "8-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp8bit(i), correct, error);
fprintf(stderr,
"8-bit exp error: %d: got %u, expected %f error: %f\n",
i, png_exp8bit(i), correct, error);
}
}
@ -877,8 +887,9 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > .524) /* By experiment */
{
fprintf(stderr, "16-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp16bit(i), correct, error);
fprintf(stderr,
"16-bit exp error: %d: got %u, expected %f error: %f\n",
i, png_exp16bit(i), correct, error);
}
}
@ -940,7 +951,7 @@ int validation_gamma(int argc, char **argv)
/**************************** VALIDATION TESTS ********************************/
/* Various validation routines are included herein, they require some
* definition for png_warning and png_error, seetings of VALIDATION:
* definition for png_warning and png_error, settings of VALIDATION:
*
* 1: validates the ASCII to floating point conversions
* 2: validates png_muldiv

View file

@ -2,8 +2,6 @@
*
* Copyright (c) 2013,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -528,7 +526,7 @@ int main(int argc, char **argv)
}
}
else if (nfiles == 0) /* Read from stdin withoout --dissemble */
else if (nfiles == 0) /* Read from stdin without --dissemble */
{
char filename[FILENAME_MAX+1];