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
@ -11,8 +9,8 @@
* Generate crc32 and adler32 checksums of the given input files, used to
* generate check-codes for use when matching ICC profiles within libpng.
*/
#include <stdio.h>
#include <stdio.h>
#include <zlib.h>
static int

View file

@ -1,144 +0,0 @@
#!/bin/sh
# chkfmt
#
# COPYRIGHT: Written by John Cunningham Bowler, 2010.
# To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from:
# United States.
#
# Check the format of the source files in the current directory - checks for a
# line length of 80 characters max and no tab characters.
#
# Optionally arguments are files or directories to check.
#
# -v: output the long lines (makes fixing them easier)
# -e: spawn an editor for each file that needs a change ($EDITOR must be
# defined). When using -e the script MUST be run from an interactive
# command line.
verbose=
edit=
vers=
test "$1" = "-v" && {
shift
verbose=yes
}
test "$1" = "-e" && {
shift
if test -n "$EDITOR"
then
edit=yes
# Copy the standard streams for the editor
exec 3>&0 4>&1 5>&2
else
echo "chkfmt -e: EDITOR must be defined" >&2
exit 1
fi
}
# Function to edit a single file - if the file isn't changed ask the user
# whether or not to continue. This stuff only works if the script is run from
# the command line (otherwise, don't specify -e or you will be sorry).
doed(){
cp "$file" "$file".orig
"$EDITOR" "$file" 0>&3 1>&4 2>&5 3>&- 4>&- 5>&- || exit 1
if cmp -s "$file".orig "$file"
then
rm "$file".orig
echo -n "$file: file not changed, type anything to continue: " >&5
read ans 0>&3
test -n "$ans" || return 1
fi
return 0
}
# In beta versions the version string which appears in files can be a little
# long and cause spuriously overlong lines. To avoid this substitute the version
# string with a 'standard' version a.b.cc before checking for long lines.
if test -r png.h
then
vers="`sed -n -e \
's/^#define PNG_LIBPNG_VER_STRING .\([0-9]\.[0-9]\.[0-9][0-9a-z]*\).$/\1/p' \
png.h`"
echo "chkfmt: checking version $vers"
fi
if test -z "$vers"
then
echo "chkfmt: png.h not found, ignoring version number" >&2
fi
test -n "$1" || set -- .
find "$@" \( -type d \( -name '.git' -o -name '.libs' -o -name 'projects' \) \
-prune \) -o \( -type f \
! -name '*.[oa]' ! -name '*.l[oa]' ! -name '*.png' ! -name '*.out' \
! -name '*.jpg' ! -name '*.patch' ! -name '*.obj' ! -name '*.exe' \
! -name '*.com' ! -name '*.tar.*' ! -name '*.zip' ! -name '*.ico' \
! -name '*.res' ! -name '*.rc' ! -name '*.mms' ! -name '*.rej' \
! -name '*.dsp' ! -name '*.orig' ! -name '*.dfn' ! -name '*.swp' \
! -name '~*' ! -name '*.3' \
! -name 'missing' ! -name 'mkinstalldirs' ! -name 'depcomp' \
! -name 'aclocal.m4' ! -name 'install-sh' ! -name 'Makefile.in' \
! -name 'ltmain.sh' ! -name 'config*' -print \) | {
st=0
while read file
do
case "$file" in
*.mak|*[Mm]akefile.*|*[Mm]akefile)
# Makefiles require tabs, dependency lines can be this long.
check_tabs=
line_length=100;;
*.awk)
# Includes literal tabs
check_tabs=
# The following is arbitrary
line_length=132;;
*contrib/*/*.[ch])
check_tabs=yes
line_length=96;;
*)
check_tabs=yes
line_length=80;;
esac
# Note that vers can only contain 0-9, . and a-z
if test -n "$vers"
then
sed -e "s/$vers/a.b.cc/g" "$file" >"$file".$$
else
cp "$file" "$file".$$
fi
splt="`fold -$line_length "$file".$$ | diff -c "$file".$$ -`"
rm "$file".$$
if test -n "$splt"
then
echo "$file: lines too long"
st=1
if test -n "$EDITOR" -a -n "$edit"
then
doed "$file" || exit 1
elif test -n "$verbose"
then
echo "$splt"
fi
fi
if test -n "$check_tabs"
then
tab="`tr -c -d '\t' <"$file"`"
if test -n "$tab"
then
echo "$file: file contains tab characters"
st=1
if test -n "$EDITOR" -a -n "$edit"
then
doed "$file" || exit 1
elif test -n "$verbose"
then
echo "$splt"
fi
fi
fi
done
exit $st
}

View file

@ -1,7 +1,4 @@
/*-
* convert.c
*
* Last changed in libpng 1.6.0 [February 14, 2013]
/* convert.c
*
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
* To the extent possible under law, the author has waived all copyright and
@ -10,6 +7,7 @@
*
* Convert 8-bit sRGB or 16-bit linear values to another format.
*/
#define _ISOC99_SOURCE 1
#include <stdlib.h>

View file

@ -1,4 +1,4 @@
/*- genpng
/* genpng
*
* COPYRIGHT: Written by John Cunningham Bowler, 2015.
* Revised by Glenn Randers-Pehrson, 2017, to add buffer-size check.
@ -69,6 +69,7 @@
* joins are mitres; the outside of the lines are continued to the point of
* intersection.
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@ -453,7 +454,7 @@ check_square(const struct arg *arg, double x, double y)
* { inside_circle_filled, check_circle_filled },
* { inside_circle, check_circle }
*
* The functions here are analoguous to the square ones; however, they check
* The functions here are analogous to the square ones; however, they check
* the corresponding ellipse as opposed to the rectangle.
*/
static int

View file

@ -1,13 +1,11 @@
#!/bin/sh
#
# intgamma.sh
#
# Last changed in libpng 1.6.0 [February 14, 2013]
#
# COPYRIGHT: Written by John Cunningham Bowler, 2013.
# To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from:
# United States.
# related or neighboring rights to this work. The author published this work
# from the United States.
#
# Shell script to generate png.c 8-bit and 16-bit log tables (see the code in
# png.c for details).
@ -17,11 +15,11 @@
# (0..255) value and a similar table for the exponent calculation.
#
# "bc" must be on the path when the script is executed, and the math library
# (-lm) must be available
#
# function to print out a list of numbers as integers; the function truncates
# the integers which must be one-per-line
function print(){
# (-lm) must be available.
# Function to print out a list of numbers as integers; the function truncates
# the integers which must be one-per-line.
print(){
awk 'BEGIN{
str = ""
}

View file

@ -1,6 +1,4 @@
/* makesRGB.c -- build sRGB-to-linear and linear-to-sRGB conversion tables
*
* Last changed in libpng 1.6.0 [February 14, 2013]
*
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
* To the extent possible under law, the author has waived all copyright and
@ -14,6 +12,7 @@
* approximation to the 8-bit sRGB encoded value. Calculate the error in these
* tables and display it.
*/
#define _C99_SOURCE 1
#include <stdio.h>
#include <math.h>

View file

@ -1,8 +1,6 @@
/* png-fix-itxt version 1.0.0
/* png-fix-itxt
*
* Copyright 2015 Glenn Randers-Pehrson
* Last changed in libpng 1.6.18 [July 23, 2015]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -10,7 +8,7 @@
*
* Usage:
*
* png-fix-itxt.exe < bad.png > good.png
* png-fix-itxt < bad.png > good.png
*
* Fixes a PNG file written with libpng-1.6.0 or 1.6.1 that has one or more
* uncompressed iTXt chunks. Assumes that the actual length is greater

View file

@ -1,8 +1,6 @@
/* pngcp.c
*
* Copyright (c) 2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.24 [August 4, 2016]
* Copyright (c) 2016,2022,2024 John Cunningham Bowler
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -14,7 +12,12 @@
*
* For a more extensive example that uses the transforms see
* contrib/libtests/pngimage.c in the libpng distribution.
*
* This code is not intended for installation in a release system; the command
* line options are not documented and most of the behavior is intended for
* testing libpng performance, both speed and compression.
*/
#include "pnglibconf.h" /* To find how libpng was configured. */
#ifdef PNG_PNGCP_TIMING_SUPPORTED
@ -85,16 +88,6 @@
# define voidcast(type, value) (value)
#endif /* __cplusplus */
#ifdef __GNUC__
/* Many versions of GCC erroneously report that local variables unmodified
* within the scope of a setjmp may be clobbered. This hacks round the
* problem (sometimes) without harming other compilers.
*/
# define gv volatile
#else
# define gv
#endif
/* 'CLOCK_PROCESS_CPUTIME_ID' is one of the clock timers for clock_gettime. It
* need not be supported even when clock_gettime is available. It returns the
* 'CPU' time the process has consumed. 'CPU' time is assumed to include time
@ -336,7 +329,7 @@ static const option options[] =
# define VLC(name) VLCIDAT(name) VLCiCCP(name) VLCzTXt(name)
# ifdef PNG_SW_COMPRESS_png_level
/* The libpng compression level isn't searched because it justs sets the
/* The libpng compression level isn't searched because it just sets the
* other things that are searched!
*/
VLO("compression", compression, 0)
@ -392,6 +385,7 @@ struct display
{
jmp_buf error_return; /* Where to go to on error */
unsigned int errset; /* error_return is set */
int errlevel; /* error level from longjmp */
const char *operation; /* What is happening */
const char *filename; /* The name of the original file */
@ -503,10 +497,10 @@ display_init(struct display *dp)
}
static void
display_clean_read(struct display *dp)
display_clean_read(struct display *dp, int freeinfo)
{
if (dp->read_pp != NULL)
png_destroy_read_struct(&dp->read_pp, NULL, NULL);
png_destroy_read_struct(&dp->read_pp, freeinfo ? &dp->ip : NULL, NULL);
if (dp->fp != NULL)
{
@ -517,7 +511,7 @@ display_clean_read(struct display *dp)
}
static void
display_clean_write(struct display *dp)
display_clean_write(struct display *dp, int freeinfo)
{
if (dp->fp != NULL)
{
@ -527,14 +521,14 @@ display_clean_write(struct display *dp)
}
if (dp->write_pp != NULL)
png_destroy_write_struct(&dp->write_pp, dp->tsp > 0 ? NULL : &dp->ip);
png_destroy_write_struct(&dp->write_pp, freeinfo ? &dp->ip : NULL);
}
static void
display_clean(struct display *dp)
{
display_clean_read(dp);
display_clean_write(dp);
display_clean_read(dp, 1/*freeinfo*/);
display_clean_write(dp, 1/*freeinfo*/);
dp->output_file = NULL;
# if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED
@ -631,7 +625,10 @@ display_log(struct display *dp, error_level level, const char *fmt, ...)
if (level > APP_FAIL || (level > ERRORS && !(dp->options & CONTINUE)))
{
if (dp->errset)
{
dp->errlevel = level;
longjmp(dp->error_return, level);
}
else
exit(99);
@ -778,7 +775,7 @@ static void
set_opt_string(struct display *dp, unsigned int sp)
/* Add the appropriate option string to dp->curr. */
{
dp->stack[sp].opt_string_end = set_opt_string_(dp, sp, dp->stack[sp].opt,
dp->stack[sp].opt_string_end = set_opt_string_(dp, sp, dp->stack[sp].opt,
options[dp->stack[sp].opt].values[dp->stack[sp].entry].name);
}
@ -1745,7 +1742,17 @@ read_function(png_structp pp, png_bytep data, size_t size)
static void
read_png(struct display *dp, const char *filename)
{
display_clean_read(dp); /* safety */
/* This is an assumption of the code; it may happen if a previous write fails
* and there is a bug in the cleanup handling below (look for setjmp).
* Passing freeinfo==1 to display_clean_read below avoids a second error
* on dp->ip != NULL below.
*/
if (dp->read_pp != NULL)
{
display_log(dp, APP_FAIL, "unexpected png_read_struct");
display_clean_read(dp, 1/*freeinfo*/); /* recovery */
}
display_start_read(dp, filename);
dp->read_pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, dp,
@ -1769,6 +1776,13 @@ read_png(struct display *dp, const char *filename)
png_set_check_for_invalid_index(dp->read_pp, -1/*off completely*/);
# endif /* IGNORE_INDEX */
if (dp->ip != NULL)
{
/* UNEXPECTED: some problem in the display_clean function calls! */
display_log(dp, APP_FAIL, "read_png: freeing old info struct");
png_destroy_info_struct(dp->read_pp, &dp->ip);
}
/* The png_read_png API requires us to make the info struct, but it does the
* call to png_read_info.
*/
@ -1848,7 +1862,14 @@ read_png(struct display *dp, const char *filename)
}
#endif /* FIX_INDEX */
display_clean_read(dp);
/* NOTE: dp->ip is where all the information about the PNG that was just read
* is stored. It can be used to write and write again a single PNG file,
* however be aware that prior to libpng 1.7 text chunks could only be
* written once; this is a bug which would require a significant code rewrite
* to fix, it has been there in several versions of libpng (it was introduced
* to fix another bug involving duplicate writes of the text chunks.)
*/
display_clean_read(dp, 0/*freeiinfo*/);
dp->operation = "none";
}
@ -1975,7 +1996,21 @@ set_text_compression(struct display *dp)
static void
write_png(struct display *dp, const char *destname)
{
display_clean_write(dp); /* safety */
/* If this test fails png_write_png would fail *silently* below; this
* is not helpful, so catch the problem now and give up:
*/
if (dp->ip == NULL)
display_log(dp, INTERNAL_ERROR, "missing png_info");
/* This is an assumption of the code; it may happen if a previous
* write fails and there is a bug in the cleanup handling below.
*/
if (dp->write_pp != NULL)
{
display_log(dp, APP_FAIL, "unexpected png_write_struct");
display_clean_write(dp, 0/*!freeinfo*/);
}
display_start_write(dp, destname);
dp->write_pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, dp,
@ -2073,10 +2108,6 @@ write_png(struct display *dp, const char *destname)
destname == NULL ? "stdout" : destname, strerror(errno));
}
/* Clean it on the way out - if control returns to the caller then the
* written_file contains the required data.
*/
display_clean_write(dp);
dp->operation = "none";
}
@ -2243,6 +2274,10 @@ cp_one_file(struct display *dp, const char *filename, const char *destname)
/* Loop to find the best option. */
do
{
/* Clean before each write_png; this just removes *dp->write_pp which
* cannot be reused.
*/
display_clean_write(dp, 0/*!freeinfo*/);
write_png(dp, tmpname);
/* And compare the sizes (the write function makes sure write_size
@ -2272,17 +2307,14 @@ cp_one_file(struct display *dp, const char *filename, const char *destname)
/* Do this for the 'sizes' option so that it reports the correct size. */
dp->write_size = dp->best_size;
}
display_clean_write(dp, 1/*freeinfo*/);
}
static int
cppng(struct display *dp, const char *file, const char *gv dest)
/* Exists solely to isolate the setjmp clobbers which some versions of GCC
* erroneously generate.
*/
cppng(struct display *dp, const char *file, const char *dest)
{
int ret = setjmp(dp->error_return);
if (ret == 0)
if (setjmp(dp->error_return) == 0)
{
dp->errset = 1;
cp_one_file(dp, file, dest);
@ -2294,10 +2326,11 @@ cppng(struct display *dp, const char *file, const char *gv dest)
{
dp->errset = 0;
if (ret < ERRORS) /* shouldn't longjmp on warnings */
display_log(dp, INTERNAL_ERROR, "unexpected return code %d", ret);
if (dp->errlevel < ERRORS) /* shouldn't longjmp on warnings */
display_log(dp, INTERNAL_ERROR, "unexpected return code %d",
dp->errlevel);
return ret;
return dp->errlevel;
}
}

View file

@ -1,7 +1,6 @@
/* pngfix.c
*
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2014-2017 John Cunningham Bowler
* Copyright (c) 2014-2017,2024 John Cunningham Bowler
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -10,6 +9,7 @@
* Tool to check and fix the zlib inflate 'too far back' problem.
* See the usage message for more information.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -20,19 +20,6 @@
#define implies(x,y) assert(!(x) || (y))
#ifdef __GNUC__
/* This is used to fix the error:
*
* pngfix.c:
* In function 'zlib_advance':
* pngfix.c:181:13: error: assuming signed overflow does not
* occur when simplifying conditional to constant [-Werror=strict-overflow]
*/
# define FIX_GCC volatile
#else
# define FIX_GCC
#endif
#define PROGRAM_NAME "pngfix"
/* Define the following to use this program against your installed libpng,
@ -45,7 +32,7 @@
#endif
#if PNG_LIBPNG_VER < 10603 /* 1.6.3 */
# error "pngfix will not work with libpng prior to 1.6.3"
# error pngfix requires libpng version 1.6.3 or newer
#endif
#ifdef PNG_SETJMP_SUPPORTED
@ -81,7 +68,7 @@
#endif
#ifndef PNG_MAXIMUM_INFLATE_WINDOW
# error "pngfix not supported in this libpng version"
# error pngfix requires libpng with PNG_MAXIMUM_INFLATE_WINDOW supported
#endif
#if ZLIB_VERNUM >= 0x1240
@ -146,11 +133,6 @@
/* Is it safe to copy? */
#define SAFE_TO_COPY(chunk) (((chunk) & PNG_U32(0,0,0,32)) != 0)
/* Fix ups for builds with limited read support */
#ifndef PNG_ERROR_TEXT_SUPPORTED
# define png_error(a,b) png_err(a)
#endif
/********************************* UTILITIES **********************************/
/* UNREACHED is a value to cause an assert to fail. Because of the way the
* assert macro is written the string "UNREACHED" is produced in the error
@ -218,7 +200,7 @@ uarb_inc(uarb num, int in_digits, png_int_32 add)
* in_digits+1 if add is known to be in the range -65535..65535.
*/
{
FIX_GCC int out_digits = 0;
int out_digits = 0;
while (out_digits < in_digits)
{
@ -263,7 +245,7 @@ uarb_add32(uarb num, int in_digits, png_uint_32 add)
}
static int
uarb_mult_digit(uarb acc, int a_digits, uarb num, FIX_GCC int n_digits,
uarb_mult_digit(uarb acc, int a_digits, uarb num, int n_digits,
png_uint_16 val)
/* Primitive one-digit multiply - 'val' must be 0..65535. Note that this
* primitive is a multiply and accumulate - the result of *num * val is added
@ -336,7 +318,7 @@ uarb_shift(uarb inout, int ndigits, unsigned int right_shift)
* 1..15
*/
{
FIX_GCC int i = ndigits;
int i = ndigits;
png_uint_16 carry = 0;
assert(right_shift >= 1 && right_shift <= 15);
@ -351,7 +333,7 @@ uarb_shift(uarb inout, int ndigits, unsigned int right_shift)
inout[i] = temp;
/* The shift may reduce ndigits */
if (i == ndigits-1 && temp == 0)
if (i+1 == ndigits && temp == 0)
ndigits = i;
}
@ -867,7 +849,7 @@ struct file
* signature (in length,type).
*
* When a chunk control structure is instantiated these values are copied
* into the structure and can then be overritten with the data for the next
* into the structure and can then be overwritten with the data for the next
* chunk.
*/
fpos_t data_pos; /* Position of first byte of chunk data */
@ -1005,10 +987,18 @@ file_end(struct file *file)
if (file->out != NULL)
{
/* NOTE: this is bitwise |, all the following functions must execute and
* must succeed.
/* On some systems 'fclose' deletes the FILE struct (making it
* inaccessbile). There is no guarantee that fclose returns an error
* code from fflush or, indeed, from the FILE error indicator. There is
* also no explicit (or clear) guarantee in the standard that anything
* other than a read or write operation sets the error indicator; fflush
* is not a read or write operation, so both conditions must be checked
* to ensure the close succeeded and in ANSI-C conformant code they must
* be checked before the fclose call.
*/
if (ferror(file->out) | fflush(file->out) | fclose(file->out))
const int err = fflush(file->out) || ferror(file->out);
if (fclose(file->out) || err)
{
perror(file->out_name);
emit_error(file, READ_ERROR_CODE, "output write error");
@ -1598,7 +1588,7 @@ chunk_init(struct chunk * const chunk, struct file * const file)
chunk->chunk_length = file->length;
chunk->chunk_type = file->type;
/* Compresssed/uncompressed size information (from the zlib control structure
/* Compressed/uncompressed size information (from the zlib control structure
* that is used to check the compressed data in a chunk.)
*/
chunk->uncompressed_digits = 0;
@ -2929,7 +2919,7 @@ process_chunk(struct file *file, png_uint_32 file_crc, png_uint_32 next_length,
}
/* Control reaches this point if the chunk must be skipped. For chunks other
* than IDAT this means that the zlib compressed data is fatally damanged and
* than IDAT this means that the zlib compressed data is fatally damaged and
* the chunk will not be passed to libpng. For IDAT it means that the end of
* the IDAT stream has not yet been reached and we must handle the next
* (IDAT) chunk. If the LZ data in an IDAT stream cannot be read 'stop' must
@ -3961,6 +3951,14 @@ main(int argc, const char **argv)
{
size_t outlen = strlen(*argv);
if (outlen > FILENAME_MAX)
{
fprintf(stderr, "%s: output file name too long: %s%s%s\n",
prog, prefix, *argv, suffix ? suffix : "");
global.status_code |= WRITE_ERROR;
continue;
}
if (outfile == NULL) /* else this takes precedence */
{
/* Consider the prefix/suffix options */
@ -4046,4 +4044,4 @@ main(void)
return 77;
}
#endif /* PNG_SETJMP_SUPPORTED */
/* vi: set textwidth=80 shiftwidth=3 softtabstop=-1 expandtab: */

View file

@ -1,25 +0,0 @@
#!/bin/sh
# reindent a libpng C source
# COPYRIGHT: Written by Glenn Randers-Pehrson, 2016.
# To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from:
# United States.
# Usage:
# reindent inputtabsize outputtabsize inputcontinuestring outputcontinuestring
#
# Assumes that continued lines begin with indentation plus one space, and
# that continued comments begin with indentation plus " *".
#
# eg, to change libpng coding style from 3-space indentation with 4-space
# continuations to 4-space indentation with 2-space continuations:
#
# reindent 3 4 "\t " " " < example.c > example.c_4_2
# and to restore the file back to libpng coding style
# reindent 4 3 " " " " < example.c_4_2 > example.c_3_4
unexpand --first-only --t $1 | \
sed -e "/^ *$3[^\*]/{s/$3/$4/}" | \
expand -t $2

View file

@ -1,7 +1,4 @@
/*-
* sRGB.h
*
* Last changed in libpng 1.6.0 [February 14, 2013]
/* sRGB.h
*
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
* To the extent possible under law, the author has waived all copyright and
@ -16,6 +13,7 @@
* (in fact the source of the numbers is the wikipedia article at
* https://en.wikipedia.org/wiki/SRGB).
*/
static double
sRGB_from_linear(double l)
{