summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Deutschmann <whissi@gentoo.org>2020-03-19 13:53:45 +0100
committerThomas Deutschmann <whissi@gentoo.org>2020-08-13 11:28:25 +0200
commitdc2ba49207af71193f1390d84bba4e15aeea0ce0 (patch)
tree79c2a51cb5fa2b87800b1113e0015a7108cd2eb3 /libpng/contrib
parentImport Ghostscript 9.50 (diff)
downloadghostscript-gpl-patches-dc2ba49207af71193f1390d84bba4e15aeea0ce0.tar.gz
ghostscript-gpl-patches-dc2ba49207af71193f1390d84bba4e15aeea0ce0.tar.bz2
ghostscript-gpl-patches-dc2ba49207af71193f1390d84bba4e15aeea0ce0.zip
Import Ghostscript 9.52ghostscript-9.52
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'libpng/contrib')
-rw-r--r--libpng/contrib/conftest/pngcp.dfa4
-rw-r--r--libpng/contrib/examples/iccfrompng.c2
-rw-r--r--libpng/contrib/examples/pngpixel.c6
-rw-r--r--libpng/contrib/gregbook/readpng2.c2
-rw-r--r--libpng/contrib/libtests/makepng.c42
-rw-r--r--libpng/contrib/libtests/pngimage.c18
-rw-r--r--libpng/contrib/libtests/pngstest.c39
-rw-r--r--libpng/contrib/libtests/pngunknown.c4
-rw-r--r--libpng/contrib/libtests/pngvalid.c240
-rw-r--r--libpng/contrib/libtests/readpng.c2
-rw-r--r--libpng/contrib/libtests/tarith.c10
-rw-r--r--libpng/contrib/libtests/timepng.c4
-rw-r--r--libpng/contrib/oss-fuzz/Dockerfile7
-rw-r--r--libpng/contrib/oss-fuzz/README.txt4
-rwxr-xr-xlibpng/contrib/oss-fuzz/build.sh11
-rw-r--r--libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc24
-rw-r--r--libpng/contrib/oss-fuzz/newcc190
-rw-r--r--libpng/contrib/pngminus/CHANGES.txt13
-rw-r--r--libpng/contrib/pngminus/CMakeLists.txt24
-rw-r--r--libpng/contrib/pngminus/LICENSE.txt22
-rw-r--r--libpng/contrib/pngminus/Makefile62
-rw-r--r--libpng/contrib/pngminus/README.txt (renamed from libpng/contrib/pngminus/README)85
-rw-r--r--libpng/contrib/pngminus/makefile.std66
-rw-r--r--libpng/contrib/pngminus/makefile.tc338
-rwxr-xr-xlibpng/contrib/pngminus/png2pnm.bat4
-rw-r--r--libpng/contrib/pngminus/png2pnm.c165
-rwxr-xr-xlibpng/contrib/pngminus/png2pnm.sh4
-rwxr-xr-xlibpng/contrib/pngminus/pngminus.bat2
-rwxr-xr-xlibpng/contrib/pngminus/pngminus.sh2
-rwxr-xr-xlibpng/contrib/pngminus/pnm2png.bat4
-rw-r--r--libpng/contrib/pngminus/pnm2png.c258
-rwxr-xr-xlibpng/contrib/pngminus/pnm2png.sh4
-rw-r--r--libpng/contrib/pngsuite/README2
-rw-r--r--libpng/contrib/pngsuite/bad_interlace_conversions.txt9
-rw-r--r--libpng/contrib/pngsuite/ibasn0g08.pngbin0 -> 237 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn0g16.pngbin0 -> 274 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn2c08.pngbin0 -> 299 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn2c16.pngbin0 -> 558 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn3p08.pngbin0 -> 1492 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn4a08.pngbin0 -> 198 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn4a16.pngbin0 -> 2839 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn6a08.pngbin0 -> 339 bytes
-rw-r--r--libpng/contrib/pngsuite/ibasn6a16.pngbin0 -> 4164 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbbn2c16.pngbin0 -> 2624 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbbn3p08.pngbin0 -> 1507 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbgn2c16.pngbin0 -> 2624 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbgn3p08.pngbin0 -> 1507 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbrn2c08.pngbin0 -> 1624 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbwn0g16.pngbin0 -> 1448 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbwn3p08.pngbin0 -> 1507 bytes
-rw-r--r--libpng/contrib/pngsuite/iftbyn3p08.pngbin0 -> 1507 bytes
-rw-r--r--libpng/contrib/pngsuite/iftp0n0g08.pngbin0 -> 847 bytes
-rw-r--r--libpng/contrib/pngsuite/iftp0n2c08.pngbin0 -> 2020 bytes
-rw-r--r--libpng/contrib/pngsuite/iftp0n3p08.pngbin0 -> 1495 bytes
-rw-r--r--libpng/contrib/pngsuite/iftp1n3p08.pngbin0 -> 1507 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/README2
-rw-r--r--libpng/contrib/pngsuite/interlaced/ibasn0g01.pngbin0 -> 201 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/ibasn0g02.pngbin0 -> 138 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/ibasn0g04.pngbin0 -> 231 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/ibasn3p01.pngbin0 -> 116 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/ibasn3p02.pngbin0 -> 163 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/ibasn3p04.pngbin0 -> 288 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/iftbbn0g01.pngbin0 -> 214 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/iftbbn0g02.pngbin0 -> 211 bytes
-rw-r--r--libpng/contrib/pngsuite/interlaced/iftbbn0g04.pngbin0 -> 489 bytes
-rw-r--r--libpng/contrib/powerpc-vsx/README2
-rw-r--r--libpng/contrib/powerpc-vsx/linux_aux.c6
-rwxr-xr-xlibpng/contrib/testpngs/makepngs.sh2
-rwxr-xr-xlibpng/contrib/tools/chkfmt2
-rw-r--r--libpng/contrib/tools/makesRGB.c6
-rw-r--r--libpng/contrib/tools/pngcp.c26
-rw-r--r--libpng/contrib/tools/pngfix.c16
-rw-r--r--libpng/contrib/visupng/PngFile.c11
-rw-r--r--libpng/contrib/visupng/PngFile.h4
-rw-r--r--libpng/contrib/visupng/VisualPng.c2
75 files changed, 608 insertions, 844 deletions
diff --git a/libpng/contrib/conftest/pngcp.dfa b/libpng/contrib/conftest/pngcp.dfa
index 15a856e2..31c411d5 100644
--- a/libpng/contrib/conftest/pngcp.dfa
+++ b/libpng/contrib/conftest/pngcp.dfa
@@ -33,7 +33,7 @@ option WRITE_16BIT on
option WRITE_FILTER on
# pngcp needs this to preserve unknown chunks, switching all these on means that
-# pngcp can work without explicit known chunk reading suppport
+# pngcp can work without explicit known chunk reading support
option UNKNOWN_CHUNKS on
option SET_UNKNOWN_CHUNKS on
option HANDLE_AS_UNKNOWN on
@@ -52,6 +52,6 @@ option TEXT on
option USER_LIMITS on
option SET_USER_LIMITS on
-# these are are just required for specific customizations
+# these are just required for specific customizations
option WRITE_CUSTOMIZE_ZTXT_COMPRESSION on
option WRITE_CUSTOMIZE_COMPRESSION on
diff --git a/libpng/contrib/examples/iccfrompng.c b/libpng/contrib/examples/iccfrompng.c
index 603037e7..00056abf 100644
--- a/libpng/contrib/examples/iccfrompng.c
+++ b/libpng/contrib/examples/iccfrompng.c
@@ -10,7 +10,7 @@
* without processing the image. Notice that some header information may occur
* after the image data. Textual data and comments are an example; the approach
* in this file won't work reliably for such data because it only looks for the
- * information in the section of the file that preceeds the image data.
+ * information in the section of the file that precedes the image data.
*
* Compile and link against libpng and zlib, plus anything else required on the
* system you use.
diff --git a/libpng/contrib/examples/pngpixel.c b/libpng/contrib/examples/pngpixel.c
index f762379e..9185d518 100644
--- a/libpng/contrib/examples/pngpixel.c
+++ b/libpng/contrib/examples/pngpixel.c
@@ -42,7 +42,7 @@ component(png_const_bytep row, png_uint_32 x, unsigned int c,
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels);
png_uint_32 bit_offset_lo = bit_depth * ((x & 0x3f) * channels + c);
- row = (png_const_bytep)(((PNG_CONST png_byte (*)[8])row) + bit_offset_hi);
+ row = (png_const_bytep)(((const png_byte (*)[8])row) + bit_offset_hi);
row += bit_offset_lo >> 3;
bit_offset_lo &= 0x07;
@@ -73,7 +73,7 @@ static void
print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
png_uint_32 x)
{
- PNG_CONST unsigned int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
+ unsigned int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
switch (png_get_color_type(png_ptr, info_ptr))
{
@@ -87,7 +87,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
*/
case PNG_COLOR_TYPE_PALETTE:
{
- PNG_CONST int index = component(row, x, 0, bit_depth, 1);
+ int index = component(row, x, 0, bit_depth, 1);
png_colorp palette = NULL;
int num_palette = 0;
diff --git a/libpng/contrib/gregbook/readpng2.c b/libpng/contrib/gregbook/readpng2.c
index 5d13e153..610b3cd8 100644
--- a/libpng/contrib/gregbook/readpng2.c
+++ b/libpng/contrib/gregbook/readpng2.c
@@ -146,7 +146,7 @@ int readpng2_init(mainprog_info *mainprog_ptr)
/* These byte strings were copied from png.h. If a future version
* of readpng2.c recognizes more chunks, add them to this list.
*/
- static PNG_CONST png_byte chunks_to_process[] = {
+ static const png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
103, 65, 77, 65, '\0', /* gAMA */
115, 82, 71, 66, '\0', /* sRGB */
diff --git a/libpng/contrib/libtests/makepng.c b/libpng/contrib/libtests/makepng.c
index 9dff0484..312062bd 100644
--- a/libpng/contrib/libtests/makepng.c
+++ b/libpng/contrib/libtests/makepng.c
@@ -661,7 +661,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
{
case 1:
{
- const png_uint_32 luma = colors[1];
+ png_uint_32 luma = colors[1];
png_uint_32 x;
for (x=0; x<=size_max; ++x)
@@ -672,8 +672,8 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
case 2:
{
- const png_uint_32 luma = colors[1];
- const png_uint_32 alpha = colors[2];
+ png_uint_32 luma = colors[1];
+ png_uint_32 alpha = colors[2];
png_uint_32 x;
for (x=0; x<size_max; ++x)
@@ -688,9 +688,9 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
case 3:
{
- const png_uint_32 red = colors[1];
- const png_uint_32 green = colors[2];
- const png_uint_32 blue = colors[3];
+ png_uint_32 red = colors[1];
+ png_uint_32 green = colors[2];
+ png_uint_32 blue = colors[3];
png_uint_32 x;
for (x=0; x<=size_max; ++x)
@@ -707,10 +707,10 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
case 4:
{
- const png_uint_32 red = colors[1];
- const png_uint_32 green = colors[2];
- const png_uint_32 blue = colors[3];
- const png_uint_32 alpha = colors[4];
+ png_uint_32 red = colors[1];
+ png_uint_32 green = colors[2];
+ png_uint_32 blue = colors[3];
+ png_uint_32 alpha = colors[4];
png_uint_32 x;
for (x=0; x<=size_max; ++x)
@@ -812,7 +812,7 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
png_error(png_ptr, "OOM allocating info structure");
{
- const unsigned int size =
+ unsigned int size =
image_size_of_type(color_type, bit_depth, colors, small);
unsigned int ysize;
png_fixed_point real_gamma = 45455; /* For sRGB */
@@ -824,7 +824,7 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
*/
if (small)
{
- const unsigned int pixel_depth =
+ unsigned int pixel_depth =
pixel_depth_of_type(color_type, bit_depth);
if (pixel_depth <= 8U)
@@ -950,7 +950,7 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
int passes = 1;
# endif /* !WRITE_INTERLACING */
int pass;
- png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
row = malloc(rowbytes);
@@ -1094,7 +1094,7 @@ load_file(png_const_charp name, png_bytepp result)
return 0;
}
-static png_size_t
+static size_t
load_fake(png_charp param, png_bytepp profile)
{
char *endptr = NULL;
@@ -1164,7 +1164,7 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
{
case '<':
{
- png_size_t filelen = load_file(params[1]+1, &profile);
+ size_t filelen = load_file(params[1]+1, &profile);
if (filelen > 0xfffffffc) /* Maximum profile length */
{
fprintf(stderr, "%s: file too long (%lu) for an ICC profile\n",
@@ -1179,7 +1179,7 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{
- png_size_t fake_len = load_fake(params[1], &profile);
+ size_t fake_len = load_fake(params[1], &profile);
if (fake_len > 0) /* else a simple parameter */
{
@@ -1274,7 +1274,7 @@ set_text(png_structp png_ptr, png_infop info_ptr, png_textp text,
case '5': case '6': case '7': case '8': case '9':
{
png_bytep data = NULL;
- png_size_t fake_len = load_fake(param, &data);
+ size_t fake_len = load_fake(param, &data);
if (fake_len > 0) /* else a simple parameter */
{
@@ -1378,10 +1378,10 @@ static void
insert_sBIT(png_structp png_ptr, png_infop info_ptr, int nparams,
png_charpp params)
{
- const int ct = png_get_color_type(png_ptr, info_ptr);
- const int c = (ct & PNG_COLOR_MASK_COLOR ? 3 : 1) +
+ int ct = png_get_color_type(png_ptr, info_ptr);
+ int c = (ct & PNG_COLOR_MASK_COLOR ? 3 : 1) +
(ct & PNG_COLOR_MASK_ALPHA ? 1 : 0);
- const unsigned int maxval =
+ unsigned int maxval =
ct & PNG_COLOR_MASK_PALETTE ? 8U : png_get_bit_depth(png_ptr, info_ptr);
png_color_8 sBIT;
@@ -1856,7 +1856,7 @@ main(int argc, char **argv)
/* Check the colors */
{
- const unsigned int lim = (color_type == PNG_COLOR_TYPE_PALETTE ? 255U :
+ unsigned int lim = (color_type == PNG_COLOR_TYPE_PALETTE ? 255U :
(1U<<bit_depth)-1);
unsigned int i;
diff --git a/libpng/contrib/libtests/pngimage.c b/libpng/contrib/libtests/pngimage.c
index 9ae402cc..f130c043 100644
--- a/libpng/contrib/libtests/pngimage.c
+++ b/libpng/contrib/libtests/pngimage.c
@@ -551,7 +551,7 @@ struct display
png_structp original_pp; /* used on the original read */
png_infop original_ip; /* set by the original read */
- png_size_t original_rowbytes; /* of the original rows: */
+ size_t original_rowbytes; /* of the original rows: */
png_bytepp original_rows; /* from the original read */
/* Original chunks valid */
@@ -807,7 +807,7 @@ display_cache_file(struct display *dp, const char *filename)
static void
buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
- png_size_t size)
+ size_t size)
{
struct buffer_list *last = bp->current;
size_t read_count = bp->read_count;
@@ -855,7 +855,7 @@ buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
}
static void PNGCBAPI
-read_function(png_structp pp, png_bytep data, png_size_t size)
+read_function(png_structp pp, png_bytep data, size_t size)
{
buffer_read(get_dp(pp), get_buffer(pp), data, size);
}
@@ -927,7 +927,7 @@ update_display(struct display *dp)
png_structp pp;
png_infop ip;
- /* Now perform the initial read with a 0 tranform. */
+ /* Now perform the initial read with a 0 transform. */
read_png(dp, &dp->original_file, "original read", 0/*no transform*/);
/* Move the result to the 'original' fields */
@@ -1267,7 +1267,7 @@ compare_read(struct display *dp, int applied_transforms)
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
- png_size_t size)
+ size_t size)
/* Generic write function used both from the write callback provided to
* libpng and from the generic read code.
*/
@@ -1311,7 +1311,7 @@ buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
}
static void PNGCBAPI
-write_function(png_structp pp, png_bytep data, png_size_t size)
+write_function(png_structp pp, png_bytep data, size_t size)
{
buffer_write(get_dp(pp), get_buffer(pp), data, size);
}
@@ -1446,7 +1446,7 @@ test_one_file(struct display *dp, const char *filename)
* unsigned, because some transforms are negative on a 16-bit system.
*/
unsigned int active = dp->active_transforms;
- const int exhaustive = (dp->options & EXHAUSTIVE) != 0;
+ int exhaustive = (dp->options & EXHAUSTIVE) != 0;
unsigned int current = first_transform(active);
unsigned int bad_transforms = 0;
unsigned int bad_combo = ~0U; /* bitwise AND of failing transforms */
@@ -1572,7 +1572,7 @@ do_test(struct display *dp, const char *file)
}
int
-main(const int argc, const char * const * const argv)
+main(int argc, char **argv)
{
/* For each file on the command line test it with a range of transforms */
int option_end, ilog = 0;
@@ -1674,7 +1674,7 @@ main(const int argc, const char * const * const argv)
/* Here on any return, including failures, except user/internal issues
*/
{
- const int pass = (d.options & STRICT) ?
+ int pass = (d.options & STRICT) ?
RESULT_STRICT(d.results) : RESULT_RELAXED(d.results);
if (!pass)
diff --git a/libpng/contrib/libtests/pngstest.c b/libpng/contrib/libtests/pngstest.c
index ab450893..a368bf0f 100644
--- a/libpng/contrib/libtests/pngstest.c
+++ b/libpng/contrib/libtests/pngstest.c
@@ -372,7 +372,7 @@ print_opts(png_uint_32 opts)
*/
#define FORMAT_COUNT 64
#define FORMAT_MASK 0x3f
-static PNG_CONST char * PNG_CONST format_names[FORMAT_COUNT] =
+static const char * const format_names[FORMAT_COUNT] =
{
"sRGB-gray",
"sRGB-gray+alpha",
@@ -578,11 +578,11 @@ typedef struct
int stride_extra;
FILE *input_file;
png_voidp input_memory;
- png_size_t input_memory_size;
+ size_t input_memory_size;
png_bytep buffer;
ptrdiff_t stride;
- png_size_t bufsize;
- png_size_t allocsize;
+ size_t bufsize;
+ size_t allocsize;
char tmpfile_name[32];
png_uint_16 colormap[256*4];
}
@@ -665,7 +665,7 @@ static void initimage(Image *image, png_uint_32 opts, const char *file_name,
static void
allocbuffer(Image *image)
{
- png_size_t size = PNG_IMAGE_BUFFER_SIZE(image->image, image->stride);
+ size_t size = PNG_IMAGE_BUFFER_SIZE(image->image, image->stride);
if (size+32 > image->bufsize)
{
@@ -1142,7 +1142,7 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
}
}
-/* Convertion between pixel formats. The code above effectively eliminates the
+/* Conversion between pixel formats. The code above effectively eliminates the
* component ordering changes leaving three basic changes:
*
* 1) Remove an alpha channel by pre-multiplication or compositing on a
@@ -2036,7 +2036,7 @@ typedef struct
/* Precalculated values: */
int in_opaque; /* Value of input alpha that is opaque */
int is_palette; /* Sample values come from the palette */
- int accumulate; /* Accumlate component errors (don't log) */
+ int accumulate; /* Accumulate component errors (don't log) */
int output_8bit; /* Output is 8-bit (else 16-bit) */
void (*in_gp)(Pixel*, png_const_voidp);
@@ -2346,8 +2346,8 @@ static int
logpixel(const Transform *transform, png_uint_32 x, png_uint_32 y,
const Pixel *in, const Pixel *calc, const Pixel *out, const char *reason)
{
- const png_uint_32 in_format = transform->in_image->image.format;
- const png_uint_32 out_format = transform->out_image->image.format;
+ png_uint_32 in_format = transform->in_image->image.format;
+ png_uint_32 out_format = transform->out_image->image.format;
png_uint_32 back_format = out_format & ~PNG_FORMAT_FLAG_ALPHA;
const char *via_linear = "";
@@ -2602,12 +2602,12 @@ compare_two_images(Image *a, Image *b, int via_linear,
ptrdiff_t strideb = b->stride;
png_const_bytep rowa = a->buffer+16;
png_const_bytep rowb = b->buffer+16;
- const png_uint_32 width = a->image.width;
- const png_uint_32 height = a->image.height;
- const png_uint_32 formata = a->image.format;
- const png_uint_32 formatb = b->image.format;
- const unsigned int a_sample = PNG_IMAGE_SAMPLE_SIZE(formata);
- const unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);
+ png_uint_32 width = a->image.width;
+ png_uint_32 height = a->image.height;
+ png_uint_32 formata = a->image.format;
+ png_uint_32 formatb = b->image.format;
+ unsigned int a_sample = PNG_IMAGE_SAMPLE_SIZE(formata);
+ unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);
int alpha_added, alpha_removed;
int bchannels;
png_uint_32 y;
@@ -2726,7 +2726,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
result = 0;
}
- /* If reqested copy the error values back from the Transform. */
+ /* If requested, copy the error values back from the Transform. */
if (a->opts & ACCUMULATE)
{
tr.error_ptr[0] = tr.error[0];
@@ -2790,8 +2790,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
(formata & (formatb ^ PNG_FORMAT_FLAG_COLOR) & PNG_FORMAT_FLAG_COLOR)))
{
/* Was an alpha channel changed? */
- const png_uint_32 alpha_changed = (formata ^ formatb) &
- PNG_FORMAT_FLAG_ALPHA;
+ png_uint_32 alpha_changed = (formata ^ formatb) & PNG_FORMAT_FLAG_ALPHA;
/* Was an alpha channel removed? (The third test.) If so the direct
* comparison is only possible if the input alpha is opaque.
@@ -2932,7 +2931,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
}
}
- /* If reqested copy the error values back from the Transform. */
+ /* If requested, copy the error values back from the Transform. */
if (a->opts & ACCUMULATE)
{
tr.error_ptr[0] = tr.error[0];
@@ -3627,7 +3626,7 @@ main(int argc, char **argv)
if (arg[0] == '-')
{
- const int term = (arg[1] == '0' ? 0 : '\n');
+ int term = (arg[1] == '0' ? 0 : '\n');
unsigned int ich = 0;
/* Loop reading files, use a static buffer to simplify this and just
diff --git a/libpng/contrib/libtests/pngunknown.c b/libpng/contrib/libtests/pngunknown.c
index 12eab725..05bdd833 100644
--- a/libpng/contrib/libtests/pngunknown.c
+++ b/libpng/contrib/libtests/pngunknown.c
@@ -56,7 +56,7 @@
defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
#if PNG_LIBPNG_VER < 10500
-/* This deliberately lacks the PNG_CONST. */
+/* This deliberately lacks the const. */
typedef png_byte *png_const_bytep;
/* This is copied from 1.5.1 png.h: */
@@ -85,7 +85,7 @@ typedef png_byte *png_const_bytep;
#define PNG_WRITE_16BIT_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
-/* This comes from pnglibconf.h afer 1.5: */
+/* 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))
diff --git a/libpng/contrib/libtests/pngvalid.c b/libpng/contrib/libtests/pngvalid.c
index 4dc4f844..d800110c 100644
--- a/libpng/contrib/libtests/pngvalid.c
+++ b/libpng/contrib/libtests/pngvalid.c
@@ -21,6 +21,7 @@
#define _POSIX_SOURCE 1
#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 */
#include <signal.h>
#include <stdio.h>
@@ -102,7 +103,7 @@ typedef png_byte *png_const_bytep;
#define PNG_WRITE_16BIT_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
-/* This comes from pnglibconf.h afer 1.5: */
+/* 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))
@@ -711,7 +712,7 @@ typedef struct png_store_file
unsigned int IDAT_bits; /* Number of bits in IDAT size */
png_uint_32 IDAT_size; /* Total size of IDAT data */
png_uint_32 id; /* must be correct (see FILEID) */
- png_size_t datacount; /* In this (the last) buffer */
+ size_t datacount; /* In this (the last) buffer */
png_store_buffer data; /* Last buffer in file */
int npalette; /* Number of entries in palette */
store_palette_entry* palette; /* May be NULL */
@@ -777,10 +778,10 @@ typedef struct png_store
png_infop piread;
png_store_file* current; /* Set when reading */
png_store_buffer* next; /* Set when reading */
- png_size_t readpos; /* Position in *next */
+ size_t readpos; /* Position in *next */
png_byte* image; /* Buffer for reading interlaced images */
- png_size_t cb_image; /* Size of this buffer */
- png_size_t cb_row; /* Row size of the image(s) */
+ size_t cb_image; /* Size of this buffer */
+ size_t cb_row; /* Row size of the image(s) */
uLong IDAT_crc;
png_uint_32 IDAT_len; /* Used when re-chunking IDAT chunks */
png_uint_32 IDAT_pos; /* Used when re-chunking IDAT chunks */
@@ -791,7 +792,7 @@ typedef struct png_store
png_store_file* saved;
png_structp pwrite; /* Used when writing a new file */
png_infop piwrite;
- png_size_t writepos; /* Position in .new */
+ size_t writepos; /* Position in .new */
char wname[FILE_NAME_SIZE];
png_store_buffer new; /* The end of the new PNG file being written. */
store_pool write_memory_pool;
@@ -961,7 +962,7 @@ bits_of(png_uint_32 num)
return b; /* 0..32 */
}
-/* Main interface to file storeage, after writing a new PNG file (see the API
+/* Main interface to file storage, after writing a new PNG file (see the API
* below) call store_storefile to store the result with the given name and id.
*/
static void
@@ -1125,7 +1126,7 @@ static png_bytep
store_image_row(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;
+ size_t coffset = (nImage * ps->image_h + y) * (ps->cb_row + 5) + 2;
if (ps->image == NULL)
png_error(pp, "no allocated image");
@@ -1160,9 +1161,9 @@ store_image_free(png_store *ps, png_const_structp pp)
static void
store_ensure_image(png_store *ps, png_const_structp pp, int nImages,
- png_size_t cbRow, png_uint_32 cRows)
+ size_t cbRow, png_uint_32 cRows)
{
- png_size_t cb = nImages * cRows * (cbRow + 5);
+ size_t cb = nImages * cRows * (cbRow + 5);
if (ps->cb_image < cb)
{
@@ -1234,7 +1235,7 @@ store_image_check(const png_store* ps, png_const_structp pp, int iImage)
png_error(pp, "image overwrite");
else
{
- png_size_t cbRow = ps->cb_row;
+ size_t cbRow = ps->cb_row;
png_uint_32 rows = ps->image_h;
image += iImage * (cbRow+5) * ps->image_h;
@@ -1278,7 +1279,7 @@ valid_chunktype(png_uint_32 chunktype)
}
static void PNGCBAPI
-store_write(png_structp ppIn, png_bytep pb, png_size_t st)
+store_write(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));
@@ -1346,13 +1347,13 @@ store_write(png_structp ppIn, png_bytep pb, png_size_t st)
else /* chunkpos >= 8 */
{
- png_size_t cb = st;
+ size_t cb = st;
if (cb > STORE_BUFFER_SIZE - writepos)
cb = STORE_BUFFER_SIZE - writepos;
if (cb > chunklen - chunkpos/* bytes left in chunk*/)
- cb = (png_size_t)/*SAFE*/(chunklen - chunkpos);
+ cb = (size_t)/*SAFE*/(chunklen - chunkpos);
memcpy(ps->new.buffer + writepos, pb, cb);
chunkpos += (png_uint_32)/*SAFE*/cb;
@@ -1440,7 +1441,7 @@ store_read_buffer_next(png_store *ps)
* during progressive read, where the io_ptr is set internally by libpng.
*/
static void
-store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
+store_read_imp(png_store *ps, png_bytep pb, size_t st)
{
if (ps->current == NULL || ps->next == NULL)
png_error(ps->pread, "store state damaged");
@@ -1463,14 +1464,13 @@ store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
}
}
-static png_size_t
-store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
- const png_size_t min)
+static size_t
+store_read_chunk(png_store *ps, png_bytep pb, size_t max, size_t min)
{
png_uint_32 chunklen = ps->chunklen;
png_uint_32 chunktype = ps->chunktype;
png_uint_32 chunkpos = ps->chunkpos;
- png_size_t st = max;
+ size_t st = max;
if (st > 0) do
{
@@ -1601,8 +1601,8 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
store_read_imp(ps, pb, avail);
ps->IDAT_crc = crc32(ps->IDAT_crc, pb, avail);
- pb += (png_size_t)/*SAFE*/avail;
- st -= (png_size_t)/*SAFE*/avail;
+ pb += (size_t)/*SAFE*/avail;
+ st -= (size_t)/*SAFE*/avail;
chunkpos += (png_uint_32)/*SAFE*/avail;
IDAT_size -= (png_uint_32)/*SAFE*/avail;
IDAT_pos += (png_uint_32)/*SAFE*/avail;
@@ -1669,10 +1669,10 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
else /* Return chunk bytes, including the CRC */
{
- png_size_t avail = st;
+ size_t avail = st;
if (avail > chunklen - chunkpos)
- avail = (png_size_t)/*SAFE*/(chunklen - chunkpos);
+ avail = (size_t)/*SAFE*/(chunklen - chunkpos);
store_read_imp(ps, pb, avail);
pb += avail;
@@ -1698,7 +1698,7 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
}
static void PNGCBAPI
-store_read(png_structp ppIn, png_bytep pb, png_size_t st)
+store_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));
@@ -1724,7 +1724,7 @@ store_progressive_read(png_store *ps, png_structp pp, png_infop pi)
while (store_read_buffer_avail(ps) > 0)
{
static png_uint_32 noise = 2;
- png_size_t cb;
+ size_t cb;
png_byte buffer[512];
/* Generate 15 more bits of stuff: */
@@ -2590,7 +2590,7 @@ static double digitize(double value, int depth, int do_round)
* rounding and 'do_round' should be 1, if it is 0 the digitized value will
* be truncated.
*/
- const unsigned int digitization_factor = (1U << depth) -1;
+ unsigned int digitization_factor = (1U << depth) - 1;
/* Limiting the range is done as a convenience to the caller - it's easier to
* do it once here than every time at the call site.
@@ -2991,7 +2991,7 @@ modifier_setbuffer(png_modifier *pm)
* png_struct.
*/
static void
-modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
+modifier_read_imp(png_modifier *pm, png_bytep pb, size_t st)
{
while (st > 0)
{
@@ -3137,7 +3137,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
*/
if (len+12 <= sizeof pm->buffer)
{
- png_size_t s = len+12-pm->buffer_count;
+ size_t s = len+12-pm->buffer_count;
store_read_chunk(&pm->this, pm->buffer+pm->buffer_count, s, s);
pm->buffer_count = len+12;
@@ -3196,7 +3196,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
/* The callback: */
static void PNGCBAPI
-modifier_read(png_structp ppIn, png_bytep pb, png_size_t st)
+modifier_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
png_modifier *pm = voidcast(png_modifier*, png_get_io_ptr(pp));
@@ -3226,7 +3226,7 @@ modifier_progressive_read(png_modifier *pm, png_structp pp, png_infop pi)
for (;;)
{
static png_uint_32 noise = 1;
- png_size_t cb, cbAvail;
+ size_t cb, cbAvail;
png_byte buffer[512];
/* Generate 15 more bits of stuff: */
@@ -3688,8 +3688,8 @@ init_standard_palette(png_store *ps, png_structp pp, png_infop pi, int npalette,
#ifdef PNG_WRITE_tRNS_SUPPORTED
static void
-set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
- const int bit_depth)
+set_random_tRNS(png_structp pp, png_infop pi, png_byte colour_type,
+ int bit_depth)
{
/* To make this useful the tRNS color needs to match at least one pixel.
* Random values are fine for gray, including the 16-bit case where we know
@@ -3697,7 +3697,7 @@ set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
* method as only 65536 different RGB values are generated.
*/
png_color_16 tRNS;
- const png_uint_16 mask = (png_uint_16)((1U << bit_depth)-1);
+ png_uint_16 mask = (png_uint_16)((1U << bit_depth)-1);
R8(tRNS); /* makes unset fields random */
@@ -4338,7 +4338,7 @@ make_size_image(png_store* const ps, png_byte const colour_type,
/* Make a name and get an appropriate id for the store: */
char name[FILE_NAME_SIZE];
- const png_uint_32 id = FILEID(colour_type, bit_depth, 0/*palette*/,
+ png_uint_32 id = FILEID(colour_type, bit_depth, 0/*palette*/,
interlace_type, w, h, do_interlace);
standard_name_from_id(name, sizeof name, 0, id);
@@ -4414,7 +4414,7 @@ make_size_image(png_store* const ps, png_byte const colour_type,
for (pass=0; pass<npasses; ++pass)
{
/* The following two are for checking the macros: */
- const png_uint_32 wPass = PNG_PASS_COLS(w, pass);
+ png_uint_32 wPass = PNG_PASS_COLS(w, pass);
/* If do_interlace is set we don't call png_write_row for every
* row because some of them are empty. In fact, for a 1x1 image,
@@ -4646,7 +4646,7 @@ make_error(png_store* const ps, png_byte const colour_type,
Try
{
png_infop pi;
- const png_structp pp = set_store_for_write(ps, &pi, name);
+ png_structp pp = set_store_for_write(ps, &pi, name);
png_uint_32 w, h;
gnu_volatile(pp)
@@ -4706,7 +4706,7 @@ make_error(png_store* const ps, png_byte const colour_type,
else
{
/* Now write the whole image, just to make sure that the detected, or
- * undetected, errro has not created problems inside libpng. This
+ * undetected, error has not created problems inside libpng. This
* doesn't work if there was a png_error in png_write_info because that
* can abort before PLTE was written.
*/
@@ -5001,7 +5001,7 @@ standard_display_init(standard_display *dp, png_store* ps, png_uint_32 id,
dp->npalette = 0;
/* Preset the transparent color to black: */
memset(&dp->transparent, 0, sizeof dp->transparent);
- /* Preset the palette to full intensity/opaque througout: */
+ /* Preset the palette to full intensity/opaque throughout: */
memset(dp->palette, 0xff, sizeof dp->palette);
}
@@ -5270,7 +5270,7 @@ standard_info_part1(standard_display *dp, png_structp pp, png_infop pi)
*/
standard_palette_validate(dp, pp, pi);
- /* In any case always check for a tranparent color (notice that the
+ /* In any case always check for a transparent color (notice that the
* colour type 3 case must not give a successful return on the get_tRNS call
* with these arguments!)
*/
@@ -5469,14 +5469,14 @@ progressive_row(png_structp ppIn, png_bytep new_row, png_uint_32 y, int pass)
static void
sequential_row(standard_display *dp, png_structp pp, png_infop pi,
- const int iImage, const int iDisplay)
+ int iImage, int iDisplay)
{
- const int npasses = dp->npasses;
- const int do_interlace = dp->do_interlace &&
+ int npasses = dp->npasses;
+ int do_interlace = dp->do_interlace &&
dp->interlace_type == PNG_INTERLACE_ADAM7;
- const png_uint_32 height = standard_height(pp, dp->id);
- const png_uint_32 width = standard_width(pp, dp->id);
- const png_store* ps = dp->ps;
+ png_uint_32 height = standard_height(pp, dp->id);
+ png_uint_32 width = standard_width(pp, dp->id);
+ const png_store* ps = dp->ps;
int pass;
for (pass=0; pass<npasses; ++pass)
@@ -5870,7 +5870,7 @@ test_size(png_modifier* const pm, png_byte const colour_type,
*/
static const png_byte hinc[] = {1, 3, 11, 1, 5};
static const png_byte winc[] = {1, 9, 5, 7, 1};
- const int save_bdlo = bdlo;
+ int save_bdlo = bdlo;
for (; bdlo <= bdhi; ++bdlo)
{
@@ -6078,12 +6078,12 @@ image_pixel_init(image_pixel *this, png_const_bytep row, png_byte colour_type,
png_byte bit_depth, png_uint_32 x, store_palette palette,
const image_pixel *format /*from pngvalid transform of input*/)
{
- const png_byte sample_depth = (png_byte)(colour_type ==
- PNG_COLOR_TYPE_PALETTE ? 8 : bit_depth);
- const unsigned int max = (1U<<sample_depth)-1;
- const int swap16 = (format != 0 && format->swap16);
- const int littleendian = (format != 0 && format->littleendian);
- const int sig_bits = (format != 0 && format->sig_bits);
+ png_byte sample_depth =
+ (png_byte)(colour_type == PNG_COLOR_TYPE_PALETTE ? 8 : bit_depth);
+ unsigned int max = (1U<<sample_depth)-1;
+ int swap16 = (format != 0 && format->swap16);
+ int littleendian = (format != 0 && format->littleendian);
+ int sig_bits = (format != 0 && format->sig_bits);
/* Initially just set everything to the same number and the alpha to opaque.
* Note that this currently assumes a simple palette where entry x has colour
@@ -6101,7 +6101,7 @@ image_pixel_init(image_pixel *this, png_const_bytep row, png_byte colour_type,
/* This permits the caller to default to the sample value. */
if (palette != 0)
{
- const unsigned int i = this->palette_index;
+ unsigned int i = this->palette_index;
this->red = palette[i].red;
this->green = palette[i].green;
@@ -6432,8 +6432,8 @@ static void
image_transform_mod_end(const image_transform *this, image_pixel *that,
png_const_structp pp, const transform_display *display)
{
- const unsigned int scale = (1U<<that->sample_depth)-1;
- const int sig_bits = that->sig_bits;
+ unsigned int scale = (1U<<that->sample_depth)-1;
+ int sig_bits = that->sig_bits;
UNUSED(this)
UNUSED(pp)
@@ -6756,19 +6756,19 @@ transform_image_validate(transform_display *dp, png_const_structp pp,
{
/* Constants for the loop below: */
const png_store* const ps = dp->this.ps;
- const png_byte in_ct = dp->this.colour_type;
- const png_byte in_bd = dp->this.bit_depth;
- const png_uint_32 w = dp->this.w;
- const png_uint_32 h = dp->this.h;
- const png_byte out_ct = dp->output_colour_type;
- const png_byte out_bd = dp->output_bit_depth;
- const png_byte sample_depth = (png_byte)(out_ct ==
- PNG_COLOR_TYPE_PALETTE ? 8 : out_bd);
- const png_byte red_sBIT = dp->this.red_sBIT;
- const png_byte green_sBIT = dp->this.green_sBIT;
- const png_byte blue_sBIT = dp->this.blue_sBIT;
- const png_byte alpha_sBIT = dp->this.alpha_sBIT;
- const int have_tRNS = dp->this.is_transparent;
+ png_byte in_ct = dp->this.colour_type;
+ png_byte in_bd = dp->this.bit_depth;
+ png_uint_32 w = dp->this.w;
+ png_uint_32 h = dp->this.h;
+ png_byte out_ct = dp->output_colour_type;
+ png_byte out_bd = dp->output_bit_depth;
+ png_byte sample_depth =
+ (png_byte)(out_ct == PNG_COLOR_TYPE_PALETTE ? 8 : out_bd);
+ png_byte red_sBIT = dp->this.red_sBIT;
+ png_byte green_sBIT = dp->this.green_sBIT;
+ png_byte blue_sBIT = dp->this.blue_sBIT;
+ png_byte alpha_sBIT = dp->this.alpha_sBIT;
+ int have_tRNS = dp->this.is_transparent;
double digitization_error;
store_palette out_palette;
@@ -6780,7 +6780,7 @@ transform_image_validate(transform_display *dp, png_const_structp pp,
store_image_check(dp->this.ps, pp, 0);
/* Read the palette corresponding to the output if the output colour type
- * indicates a palette, othewise set out_palette to garbage.
+ * indicates a palette, otherwise set out_palette to garbage.
*/
if (out_ct == PNG_COLOR_TYPE_PALETTE)
{
@@ -6929,7 +6929,7 @@ transform_end(png_structp ppIn, png_infop pi)
/* A single test run. */
static void
-transform_test(png_modifier *pmIn, const png_uint_32 idIn,
+transform_test(png_modifier *pmIn, png_uint_32 idIn,
const image_transform* transform_listIn, const char * const name)
{
transform_display d;
@@ -7764,7 +7764,7 @@ static void
image_transform_png_set_rgb_to_gray_set(const image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
- const int error_action = 1; /* no error, no defines in png.h */
+ int error_action = 1; /* no error, no defines in png.h */
# ifdef PNG_FLOATING_POINT_SUPPORTED
png_set_rgb_to_gray(pp, error_action, data.red_to_set, data.green_to_set);
@@ -7905,10 +7905,10 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
# if DIGITIZE
{
png_modifier *pm = display->pm;
- const unsigned int sample_depth = that->sample_depth;
- const unsigned int calc_depth = (pm->assume_16_bit_calculations ? 16 :
+ unsigned int sample_depth = that->sample_depth;
+ unsigned int calc_depth = (pm->assume_16_bit_calculations ? 16 :
sample_depth);
- const unsigned int gamma_depth =
+ unsigned int gamma_depth =
(sample_depth == 16 ?
display->max_gamma_8 :
(pm->assume_16_bit_calculations ?
@@ -7991,7 +7991,7 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
/* Now calculate the actual gray values. Although the error in the
* coefficients depends on whether they were specified on the command
* line (in which case truncation to 15 bits happened) or not (rounding
- * was used) the maxium error in an individual coefficient is always
+ * was used) the maximum error in an individual coefficient is always
* 2/32768, because even in the rounding case the requirement that
* coefficients add up to 32768 can cause a larger rounding error.
*
@@ -8002,7 +8002,7 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
b * data.blue_coefficient;
{
- const int do_round = data.gamma != 1 || calc_depth == 16;
+ int do_round = data.gamma != 1 || calc_depth == 16;
const double ce = 2. / 32768;
graylo = DD(rlo * (data.red_coefficient-ce) +
@@ -8207,7 +8207,7 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
that->bluef = that->greenf = that->redf = gray;
that->bluee = that->greene = that->rede = err;
- /* The sBIT is the minium of the three colour channel sBITs. */
+ /* The sBIT is the minimum of the three colour channel sBITs. */
if (that->red_sBIT > that->green_sBIT)
that->red_sBIT = that->green_sBIT;
if (that->red_sBIT > that->blue_sBIT)
@@ -8626,7 +8626,7 @@ image_transform_png_set_filler_mod(const image_transform *this,
(that->colour_type == PNG_COLOR_TYPE_RGB ||
that->colour_type == PNG_COLOR_TYPE_GRAY))
{
- const unsigned int max = (1U << that->bit_depth)-1;
+ unsigned int max = (1U << that->bit_depth)-1;
that->alpha = data.filler & max;
that->alphaf = ((double)that->alpha) / max;
that->alphae = 0;
@@ -8693,7 +8693,7 @@ image_transform_png_set_add_alpha_mod(const image_transform *this,
(that->colour_type == PNG_COLOR_TYPE_RGB ||
that->colour_type == PNG_COLOR_TYPE_GRAY))
{
- const unsigned int max = (1U << that->bit_depth)-1;
+ unsigned int max = (1U << that->bit_depth)-1;
that->alpha = data.filler & max;
that->alphaf = ((double)that->alpha) / max;
that->alphae = 0;
@@ -8884,7 +8884,7 @@ image_transform_png_set_shift_set(const image_transform *this,
* field is randomized independently. This acts as a check that
* libpng does use the correct field.
*/
- const unsigned int depth = that->this.bit_depth;
+ unsigned int depth = that->this.bit_depth;
data.red = (png_byte)/*SAFE*/(random_mod(depth)+1);
data.green = (png_byte)/*SAFE*/(random_mod(depth)+1);
@@ -9299,12 +9299,12 @@ gamma_info_imp(gamma_display *dp, png_structp pp, png_infop pi)
int mode = dp->do_background - ALPHA_MODE_OFFSET;
/* The gamma value is the output gamma, and is in the standard,
- * non-inverted, represenation. It provides a default for the PNG file
+ * non-inverted, representation. It provides a default for the PNG file
* gamma, but since the file has a gAMA chunk this does not matter.
*/
const double sg = dp->screen_gamma;
# ifndef PNG_FLOATING_POINT_SUPPORTED
- const png_fixed_point g = fix(sg);
+ png_fixed_point g = fix(sg);
# endif
# ifdef PNG_FLOATING_POINT_SUPPORTED
@@ -9352,7 +9352,7 @@ gamma_info_imp(gamma_display *dp, png_structp pp, png_infop pi)
*/
const double bg = dp->background_gamma;
# ifndef PNG_FLOATING_POINT_SUPPORTED
- const png_fixed_point g = fix(bg);
+ png_fixed_point g = fix(bg);
# endif
# ifdef PNG_FLOATING_POINT_SUPPORTED
@@ -9426,7 +9426,7 @@ static void
init_validate_info(validate_info *vi, gamma_display *dp, png_const_structp pp,
int in_depth, int out_depth)
{
- const unsigned int outmax = (1U<<out_depth)-1;
+ unsigned int outmax = (1U<<out_depth)-1;
vi->pp = pp;
vi->dp = dp;
@@ -9588,14 +9588,14 @@ gamma_component_compose(int do_background, double input_sample, double alpha,
/* This API returns the encoded *input* component, in the range 0..1 */
static double
gamma_component_validate(const char *name, const validate_info *vi,
- const unsigned int id, const unsigned int od,
+ unsigned int id, unsigned int od,
const double alpha /* <0 for the alpha channel itself */,
const double background /* component background value */)
{
- const unsigned int isbit = id >> vi->isbit_shift;
- const unsigned int sbit_max = vi->sbit_max;
- const unsigned int outmax = vi->outmax;
- const int do_background = vi->do_background;
+ unsigned int isbit = id >> vi->isbit_shift;
+ unsigned int sbit_max = vi->sbit_max;
+ unsigned int outmax = vi->outmax;
+ int do_background = vi->do_background;
double i;
@@ -9746,7 +9746,7 @@ gamma_component_validate(const char *name, const validate_info *vi,
*
* pngvalid calculations:
* input_sample: linear result; i linearized and composed, range 0..1
- * encoded_sample: encoded result; input_sample scaled to ouput bit depth
+ * encoded_sample: encoded result; input_sample scaled to output bit depth
*
* libpng calculations:
* output: linear result; od scaled to 0..1 and linearized
@@ -10161,13 +10161,13 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
{
/* Get some constants derived from the input and output file formats: */
const png_store* const ps = dp->this.ps;
- const png_byte in_ct = dp->this.colour_type;
- const png_byte in_bd = dp->this.bit_depth;
- const png_uint_32 w = dp->this.w;
- const png_uint_32 h = dp->this.h;
+ png_byte in_ct = dp->this.colour_type;
+ png_byte in_bd = dp->this.bit_depth;
+ png_uint_32 w = dp->this.w;
+ png_uint_32 h = dp->this.h;
const size_t cbRow = dp->this.cbRow;
- const png_byte out_ct = png_get_color_type(pp, pi);
- const png_byte out_bd = png_get_bit_depth(pp, pi);
+ png_byte out_ct = png_get_color_type(pp, pi);
+ png_byte out_bd = png_get_bit_depth(pp, pi);
/* There are three sources of error, firstly the quantization in the
* file encoding, determined by sbit and/or the file depth, secondly
@@ -10183,10 +10183,10 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
* Since the library must quantize the output to 8 or 16 bits there is
* a fundamental limit on the accuracy of the output of +/-.5 - this
* quantization limit is included in addition to the other limits
- * specified by the paramaters to the API. (Effectively, add .5
+ * specified by the parameters to the API. (Effectively, add .5
* everywhere.)
*
- * The behavior of the 'sbit' paramter is defined by section 12.5
+ * The behavior of the 'sbit' parameter is defined by section 12.5
* (sample depth scaling) of the PNG spec. That section forces the
* decoder to assume that the PNG values have been scaled if sBIT is
* present:
@@ -10208,11 +10208,11 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
* The basic tests below do not do this, however if 'use_input_precision'
* is set a subsequent test is performed above.
*/
- const unsigned int samples_per_pixel = (out_ct & 2U) ? 3U : 1U;
+ unsigned int samples_per_pixel = (out_ct & 2U) ? 3U : 1U;
int processing;
png_uint_32 y;
const store_palette_entry *in_palette = dp->this.palette;
- const int in_is_transparent = dp->this.is_transparent;
+ int in_is_transparent = dp->this.is_transparent;
int process_tRNS;
int out_npalette = -1;
int out_is_transparent = 0; /* Just refers to the palette case */
@@ -10260,9 +10260,9 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
double alpha = 1; /* serves as a flag value */
/* Record the palette index for index images. */
- const unsigned int in_index =
+ unsigned int in_index =
in_ct == 3 ? sample(std, 3, in_bd, x, 0, 0, 0) : 256;
- const unsigned int out_index =
+ unsigned int out_index =
out_ct == 3 ? sample(std, 3, out_bd, x, 0, 0, 0) : 256;
/* Handle input alpha - png_set_background will cause the output
@@ -10271,7 +10271,7 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
if ((in_ct & PNG_COLOR_MASK_ALPHA) != 0 ||
(in_ct == 3 && in_is_transparent))
{
- const unsigned int input_alpha = in_ct == 3 ?
+ unsigned int input_alpha = in_ct == 3 ?
dp->this.palette[in_index].alpha :
sample(std, in_ct, in_bd, x, samples_per_pixel, 0, 0);
@@ -10396,14 +10396,14 @@ gamma_end(png_structp ppIn, png_infop pi)
* maxpc: maximum percentage error (as a percentage)
*/
static void
-gamma_test(png_modifier *pmIn, const png_byte colour_typeIn,
- const png_byte bit_depthIn, const int palette_numberIn,
- const int interlace_typeIn,
+gamma_test(png_modifier *pmIn, png_byte colour_typeIn,
+ png_byte bit_depthIn, int palette_numberIn,
+ int interlace_typeIn,
const double file_gammaIn, const double screen_gammaIn,
- const png_byte sbitIn, const int threshold_testIn,
+ png_byte sbitIn, int threshold_testIn,
const char *name,
- const int use_input_precisionIn, const int scale16In,
- const int expand16In, const int do_backgroundIn,
+ int use_input_precisionIn, int scale16In,
+ int expand16In, int do_backgroundIn,
const png_color_16 *bkgd_colorIn, double bkgd_gammaIn)
{
gamma_display d;
@@ -10607,11 +10607,11 @@ perform_gamma_threshold_tests(png_modifier *pm)
}
static void gamma_transform_test(png_modifier *pm,
- const png_byte colour_type, const png_byte bit_depth,
- const int palette_number,
- const int interlace_type, const double file_gamma,
- const double screen_gamma, const png_byte sbit,
- const int use_input_precision, const int scale16)
+ png_byte colour_type, png_byte bit_depth,
+ int palette_number,
+ int interlace_type, const double file_gamma,
+ const double screen_gamma, png_byte sbit,
+ int use_input_precision, int scale16)
{
size_t pos = 0;
char name[64];
@@ -10768,12 +10768,12 @@ static void perform_gamma_scale16_tests(png_modifier *pm)
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
static void gamma_composition_test(png_modifier *pm,
- const png_byte colour_type, const png_byte bit_depth,
- const int palette_number,
- const int interlace_type, const double file_gamma,
+ png_byte colour_type, png_byte bit_depth,
+ int palette_number,
+ int interlace_type, const double file_gamma,
const double screen_gamma,
- const int use_input_precision, const int do_background,
- const int expand_16)
+ int use_input_precision, int do_background,
+ int expand_16)
{
size_t pos = 0;
png_const_charp base;
@@ -11729,7 +11729,7 @@ int main(int argc, char **argv)
/* Some default values (set the behavior for 'make check' here).
* These values simply control the maximum error permitted in the gamma
- * transformations. The practial limits for human perception are described
+ * transformations. The practical limits for human perception are described
* below (the setting for maxpc16), however for 8 bit encodings it isn't
* possible to meet the accepted capabilities of human vision - i.e. 8 bit
* images can never be good enough, regardless of encoding.
diff --git a/libpng/contrib/libtests/readpng.c b/libpng/contrib/libtests/readpng.c
index 3336d4e2..60a2d46c 100644
--- a/libpng/contrib/libtests/readpng.c
+++ b/libpng/contrib/libtests/readpng.c
@@ -60,7 +60,7 @@ read_png(FILE *fp)
png_read_info(png_ptr, info_ptr);
{
- png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
/* Failure to initialize these is harmless */
row = malloc(rowbytes);
diff --git a/libpng/contrib/libtests/tarith.c b/libpng/contrib/libtests/tarith.c
index cb17ffa7..c03f05a8 100644
--- a/libpng/contrib/libtests/tarith.c
+++ b/libpng/contrib/libtests/tarith.c
@@ -108,7 +108,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
do
{
- png_size_t index;
+ size_t index;
int state, failed = 0;
char buffer[64];
@@ -176,7 +176,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
}
else if (PNG_FP_IS_POSITIVE(state) && !(test > 0))
{
- fprintf(stderr, "%g[%d] -> '%s' but postive value not so reported\n",
+ fprintf(stderr, "%g[%d] -> '%s' but positive value not so reported\n",
test, precision, buffer);
failed = 1;
assert(!PNG_FP_IS_NEGATIVE(state));
@@ -329,10 +329,10 @@ static int check_one_character(checkfp_command *co, checkfp_control c, int ch)
{
/* Test this character (ch) to ensure the parser does the correct thing.
*/
- png_size_t index = 0;
+ size_t index = 0;
const char test = (char)ch;
- const int number_is_valid = png_check_fp_number(&test, 1, &c.state, &index);
- const int character_accepted = (index == 1);
+ int number_is_valid = png_check_fp_number(&test, 1, &c.state, &index);
+ int character_accepted = (index == 1);
if (c.check_state != exponent && isdigit(ch) && ch != '0')
c.is_zero = 0;
diff --git a/libpng/contrib/libtests/timepng.c b/libpng/contrib/libtests/timepng.c
index 3bcfde5a..23d8b17b 100644
--- a/libpng/contrib/libtests/timepng.c
+++ b/libpng/contrib/libtests/timepng.c
@@ -65,7 +65,7 @@ typedef struct
} io_data;
static PNG_CALLBACK(void, read_and_copy,
- (png_structp png_ptr, png_bytep buffer, png_size_t cb))
+ (png_structp png_ptr, png_bytep buffer, size_t cb))
{
io_data *io = (io_data*)png_get_io_ptr(png_ptr);
@@ -100,7 +100,7 @@ static void read_by_row(png_structp png_ptr, png_infop info_ptr,
png_read_info(png_ptr, info_ptr);
{
- png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
row = voidcast(png_bytep,malloc(rowbytes));
display = voidcast(png_bytep,malloc(rowbytes));
diff --git a/libpng/contrib/oss-fuzz/Dockerfile b/libpng/contrib/oss-fuzz/Dockerfile
index 7e4d1ebf..f5bc1a98 100644
--- a/libpng/contrib/oss-fuzz/Dockerfile
+++ b/libpng/contrib/oss-fuzz/Dockerfile
@@ -16,9 +16,10 @@
FROM gcr.io/oss-fuzz-base/base-builder
MAINTAINER glennrp@gmail.com
-RUN apt-get update && apt-get install -y make autoconf automake libtool zlib1g-dev
+RUN apt-get update && \
+ apt-get install -y make autoconf automake libtool
+RUN git clone --depth 1 https://github.com/madler/zlib.git
RUN git clone --depth 1 https://github.com/glennrp/libpng.git
-RUN (cd libpng; git log | head -1)
+RUN cp libpng/contrib/oss-fuzz/build.sh $SRC
WORKDIR libpng
-COPY build.sh $SRC/
diff --git a/libpng/contrib/oss-fuzz/README.txt b/libpng/contrib/oss-fuzz/README.txt
index a2b67366..3b3656fb 100644
--- a/libpng/contrib/oss-fuzz/README.txt
+++ b/libpng/contrib/oss-fuzz/README.txt
@@ -24,13 +24,13 @@ The files are
Filename or derived Copyright License
========================= ========== ================ ==========
Dockerfile* derived 2017, Glenn R-P Apache 2.0
- build.sh* derived 2017, Glenn R-P Apache 2.0
+ build.sh derived 2017, Glenn R-P Apache 2.0
libpng_read_fuzzer.cc derived 2017, Glenn R-P Chromium
libpng_read_fuzzer.options original 2015, Chrome Devs Chromium
png.dict original 2015, Chrome Devs Chromium
README.txt (this file) original 2017, Glenn R-P libpng
- * Dockerfile and build.sh are copies of the files used by oss-fuzz.
+ * Dockerfile is a copy of the file used by oss-fuzz. build.sh,
png.dict and libpng_read_fuzzer.* are the actual files used by oss-fuzz,
which retrieves them from the libpng repository at Github.
diff --git a/libpng/contrib/oss-fuzz/build.sh b/libpng/contrib/oss-fuzz/build.sh
index d2137b13..f9e1b077 100755
--- a/libpng/contrib/oss-fuzz/build.sh
+++ b/libpng/contrib/oss-fuzz/build.sh
@@ -1,5 +1,5 @@
#!/bin/bash -eu
-# Copyright 2017 Glenn Randers-Pehrson
+# Copyright 2017-2018 Glenn Randers-Pehrson
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,12 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# Last changed in libpng 1.6.33 [September 28, 2017]
+# Last changed in libpng 1.6.35 [July 15, 2018]
#
-# Revisions by Glenn Randers-Pehson, 2017:
+# Revisions by Glenn Randers-Pehrson, 2017:
# 1. Build only the library, not the tools (changed "make -j$(nproc) all" to
# "make -j$(nproc) libpng16.la").
# 2. Disabled WARNING and WRITE options in pnglibconf.dfa.
+# 3. Build zlib alongside libpng
################################################################################
# Disable logging via library build configuration control.
@@ -30,9 +31,9 @@ cat scripts/pnglibconf.dfa | \
> scripts/pnglibconf.dfa.temp
mv scripts/pnglibconf.dfa.temp scripts/pnglibconf.dfa
-# build the library.
+# build the libpng library.
autoreconf -f -i
-./configure
+./configure --with-libpng-prefix=OSS_FUZZ_
make -j$(nproc) clean
make -j$(nproc) libpng16.la
diff --git a/libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc b/libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc
index 78c7c9ff..7b305509 100644
--- a/libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc
+++ b/libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc
@@ -1,11 +1,11 @@
// libpng_read_fuzzer.cc
-// Copyright 2017 Glenn Randers-Pehrson
+// Copyright 2017-2018 Glenn Randers-Pehrson
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that may
// be found in the LICENSE file https://cs.chromium.org/chromium/src/LICENSE
-// Last changed in libpng 1.6.32 [August 24, 2017]
+// Last changed in libpng 1.6.35 [July 15, 2018]
// The modifications in 2017 by Glenn Randers-Pehrson include
// 1. addition of a PNG_CLEANUP macro,
@@ -13,6 +13,7 @@
// 3. adding "#include <string.h>" which is needed on some platforms
// to provide memcpy().
// 4. adding read_end_info() and creating an end_info structure.
+// 5. adding calls to png_set_*() transforms commonly used by browsers.
#include <stddef.h>
#include <stdint.h>
@@ -67,7 +68,7 @@ struct PngObjectHandler {
}
};
-void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
+void user_read_data(png_structp png_ptr, png_bytep data, size_t length) {
BufState* buf_state = static_cast<BufState*>(png_get_io_ptr(png_ptr));
if (length > buf_state->bytes_left) {
png_error(png_ptr, "read error");
@@ -136,9 +137,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Reading.
png_read_info(png_handler.png_ptr, png_handler.info_ptr);
- png_handler.row_ptr = png_malloc(
- png_handler.png_ptr, png_get_rowbytes(png_handler.png_ptr,
- png_handler.info_ptr));
// reset error handler to put png_deleter into scope.
if (setjmp(png_jmpbuf(png_handler.png_ptr))) {
@@ -163,8 +161,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return 0;
}
+ // Set several transforms that browsers typically use:
+ png_set_gray_to_rgb(png_handler.png_ptr);
+ png_set_expand(png_handler.png_ptr);
+ png_set_packing(png_handler.png_ptr);
+ png_set_scale_16(png_handler.png_ptr);
+ png_set_tRNS_to_alpha(png_handler.png_ptr);
+
int passes = png_set_interlace_handling(png_handler.png_ptr);
- png_start_read_image(png_handler.png_ptr);
+
+ png_read_update_info(png_handler.png_ptr, png_handler.info_ptr);
+
+ png_handler.row_ptr = png_malloc(
+ png_handler.png_ptr, png_get_rowbytes(png_handler.png_ptr,
+ png_handler.info_ptr));
for (int pass = 0; pass < passes; ++pass) {
for (png_uint_32 y = 0; y < height; ++y) {
diff --git a/libpng/contrib/oss-fuzz/newcc b/libpng/contrib/oss-fuzz/newcc
deleted file mode 100644
index 0fc9e206..00000000
--- a/libpng/contrib/oss-fuzz/newcc
+++ /dev/null
@@ -1,190 +0,0 @@
-
-// libpng_read_fuzzer.cc
-// Copyright 2017 Glenn Randers-Pehrson
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that may
-// be found in the LICENSE file https://cs.chromium.org/chromium/src/LICENSE
-
-// Last changed in libpng 1.6.33beta03 [September 27, 2017]
-
-// The modifications in 2017 by Glenn Randers-Pehrson include
-// 1. addition of a PNG_CLEANUP macro,
-// 2. setting the option to ignore ADLER32 checksums,
-// 3. adding "#include <string.h>" which is needed on some platforms
-// to provide memcpy().
-// 4. adding read_end_info() and creating an end_info structure.
-
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <vector>
-
-#define PNG_INTERNAL
-#include "png.h"
-
-struct BufState {
- const uint8_t* data;
- size_t bytes_left;
-};
-
-struct PngObjectHandler {
- png_infop info_ptr = nullptr;
- png_structp png_ptr = nullptr;
- png_infop end_info_ptr = nullptr;
- png_voidp row_ptr = nullptr;
- BufState* buf_state = nullptr;
-
- ~PngObjectHandler() {
- if (row_ptr)
- png_free(png_ptr, row_ptr);
- if (end_info_ptr)
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info_ptr);
- else if (info_ptr)
- png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
- else
- png_destroy_read_struct(&png_ptr, nullptr, nullptr);
- delete buf_state;
- }
-};
-
-void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
- BufState* buf_state = static_cast<BufState*>(png_get_io_ptr(png_ptr));
- if (length > buf_state->bytes_left) {
- png_error(png_ptr, "read error");
- }
- memcpy(data, buf_state->data, length);
- buf_state->bytes_left -= length;
- buf_state->data += length;
-}
-
-static const int kPngHeaderSize = 8;
-
-// Entry point for LibFuzzer.
-// Roughly follows the libpng book example:
-// http://www.libpng.org/pub/png/book/chapter13.html
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- if (size < kPngHeaderSize) {
- return 0;
- }
-
- std::vector<unsigned char> v(data, data + size);
- if (png_sig_cmp(v.data(), 0, kPngHeaderSize)) {
- // not a PNG.
- return 0;
- }
-
- PngObjectHandler png_handler;
- png_handler.png_ptr = nullptr;
- png_handler.row_ptr = nullptr;
- png_handler.info_ptr = nullptr;
- png_handler.end_info_ptr = nullptr;
-
- png_handler.png_ptr = png_create_read_struct
- (PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
- if (!png_handler.png_ptr) {
- return 0;
- }
-
-#define PNG_CLEANUP \
- if(png_handler.png_ptr) \
- { \
- if (png_handler.row_ptr) \
- png_free(png_handler.png_ptr, png_handler.row_ptr); \
- if (png_handler.end_info_ptr) \
- png_destroy_read_struct(&png_handler.png_ptr, &png_handler.info_ptr,\
- &png_handler.end_info_ptr); \
- else if (png_handler.info_ptr) \
- png_destroy_read_struct(&png_handler.png_ptr, &png_handler.info_ptr,\
- nullptr); \
- else \
- png_destroy_read_struct(&png_handler.png_ptr, nullptr, nullptr); \
- png_handler.png_ptr = nullptr; \
- png_handler.row_ptr = nullptr; \
- png_handler.info_ptr = nullptr; \
- png_handler.end_info_ptr = nullptr; \
- }
-
- png_handler.info_ptr = png_create_info_struct(png_handler.png_ptr);
- if (!png_handler.info_ptr) {
- PNG_CLEANUP
- return 0;
- }
-
- png_handler.end_info_ptr = png_create_info_struct(png_handler.png_ptr);
- if (!png_handler.end_info_ptr) {
- PNG_CLEANUP
- return 0;
- }
-
- /* Treat benign errors as warnings */
- png_set_benign_errors(png_handler.png_ptr, 1);
-
- png_set_crc_action(png_handler.png_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
-
-#ifdef PNG_IGNORE_ADLER32
- png_set_option(png_handler.png_ptr, PNG_IGNORE_ADLER32, PNG_OPTION_ON);
-#endif
-
- // Setting up reading from buffer.
- png_handler.buf_state = new BufState();
- png_handler.buf_state->data = data + kPngHeaderSize;
- png_handler.buf_state->bytes_left = size - kPngHeaderSize;
- png_set_read_fn(png_handler.png_ptr, png_handler.buf_state, user_read_data);
- png_set_sig_bytes(png_handler.png_ptr, kPngHeaderSize);
-
- if (setjmp(png_jmpbuf(png_handler.png_ptr))) {
- PNG_CLEANUP
- return 0;
- }
-
- // Reading.
- png_read_info(png_handler.png_ptr, png_handler.info_ptr);
- png_read_update_info(png_handler.png_ptr, png_handler.info_ptr);
- png_handler.row_ptr = png_malloc(
- png_handler.png_ptr, png_get_rowbytes(png_handler.png_ptr,
- png_handler.info_ptr));
-
- // reset error handler to put png_deleter into scope.
- if (setjmp(png_jmpbuf(png_handler.png_ptr))) {
- PNG_CLEANUP
- return 0;
- }
-
- png_uint_32 width, height;
- int bit_depth, color_type, interlace_type, compression_type;
- int filter_type;
-
- if (!png_get_IHDR(png_handler.png_ptr, png_handler.info_ptr, &width,
- &height, &bit_depth, &color_type, &interlace_type,
- &compression_type, &filter_type)) {
- PNG_CLEANUP
- return 0;
- }
-
- // This is going to be too slow.
- if (width && height > 100000000 / width) {
- PNG_CLEANUP
- return 0;
- }
-
- int passes = png_set_interlace_handling(png_handler.png_ptr);
- png_start_read_image(png_handler.png_ptr);
-
- /* To do: prevent the optimizer from removing this code entirely */
- for (int pass = 0; pass < passes; ++pass) {
- for (png_uint_32 y = 0; y < height; ++y) {
- png_read_row(png_handler.png_ptr,
- static_cast<png_bytep>(png_handler.row_ptr), nullptr);
- }
- }
-
- png_read_end(png_handler.png_ptr, png_handler.end_info_ptr);
-
- PNG_CLEANUP
-
- /* TO do: exercise the progressive reader here */
-
- return 0;
-}
diff --git a/libpng/contrib/pngminus/CHANGES.txt b/libpng/contrib/pngminus/CHANGES.txt
new file mode 100644
index 00000000..4e64e5ee
--- /dev/null
+++ b/libpng/contrib/pngminus/CHANGES.txt
@@ -0,0 +1,13 @@
+
+pnm2png / png2pnm --- conversion from PBM/PGM/PPM-file to PNG-file
+copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
+
+version 1.0 - 1999.10.15 - First version.
+ 1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)
+ 1.2 - 2017.04.22 - Add buffer-size check
+ 1.3 - 2017.08.24 - Fix potential overflow in buffer-size check
+ (Glenn Randers-Pehrson)
+ 1.4 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
+ 1.5 - 2018.08.05 - Fix buffer overflow in tokenizer (Cosmin Truta)
+ 1.6 - 2018.08.05 - Improve portability and fix style (Cosmin Truta)
+ 1.7 - 2019.01.22 - Change license to MIT (Willem van Schaik)
diff --git a/libpng/contrib/pngminus/CMakeLists.txt b/libpng/contrib/pngminus/CMakeLists.txt
new file mode 100644
index 00000000..1f815a58
--- /dev/null
+++ b/libpng/contrib/pngminus/CMakeLists.txt
@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 3.1)
+cmake_policy(VERSION 3.1)
+
+project(PNGMINUS C)
+
+option(PNGMINUS_USE_STATIC_LIBRARIES "Use the static library builds" ON)
+
+# libpng
+add_subdirectory(../.. libpng)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/libpng)
+if(PNGMINUS_USE_STATIC_LIBRARIES)
+ set(PNGMINUS_PNG_LIBRARY png_static)
+else()
+ set(PNGMINUS_PNG_LIBRARY png)
+endif()
+
+# png2pnm
+add_executable(png2pnm png2pnm.c)
+target_link_libraries(png2pnm ${PNGMINUS_PNG_LIBRARY})
+
+# pnm2png
+add_executable(pnm2png pnm2png.c)
+target_link_libraries(pnm2png ${PNGMINUS_PNG_LIBRARY})
diff --git a/libpng/contrib/pngminus/LICENSE.txt b/libpng/contrib/pngminus/LICENSE.txt
new file mode 100644
index 00000000..00878a9a
--- /dev/null
+++ b/libpng/contrib/pngminus/LICENSE.txt
@@ -0,0 +1,22 @@
+
+pnm2png / png2pnm --- conversion from PBM/PGM/PPM-file to PNG-file
+
+copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The software is provided "as is", without warranty of any kind, express or
+implied, including but not limited to the warranties of merchantability,
+fitness for a particular purpose and noninfringement. In no event shall the
+authors or copyight holders be liable for any claim, damages or other
+liability, whether in an action of contract, tort or otherwise, arising from,
+out of or in connection with the software or the use or other dealings in the
+software.
diff --git a/libpng/contrib/pngminus/Makefile b/libpng/contrib/pngminus/Makefile
new file mode 100644
index 00000000..4bba0796
--- /dev/null
+++ b/libpng/contrib/pngminus/Makefile
@@ -0,0 +1,62 @@
+# Makefile for PngMinus (png2pnm and pnm2png)
+# Linux / Unix
+
+#CC = cc
+CC = gcc
+LD = $(CC)
+
+RM = rm -f
+
+PNGINC = -I../..
+PNGLIB_SHARED = -L../.. -lpng
+PNGLIB_STATIC = ../../libpng.a
+
+# Uncomment the following if you have a custom zlib build at ../../../zlib
+#ZINC = -I../../../zlib
+#ZLIB_SHARED = -L../../../zlib -lz
+#ZLIB_STATIC = ../../../zlib/libz.a
+
+# Use the system zlib otherwise
+ZLIB_SHARED = -lz
+ZLIB_STATIC = -lz
+
+CPPFLAGS = $(PNGINC) $(ZINC)
+CFLAGS =
+LDFLAGS =
+LIBS_SHARED = $(PNGLIB_SHARED) $(ZLIB_SHARED)
+LIBS_STATIC = $(PNGLIB_STATIC) $(ZLIB_STATIC)
+
+EXEEXT =
+#EXEEXT = .exe
+
+# dependencies
+
+all: png2pnm$(EXEEXT) pnm2png$(EXEEXT) png2pnm-static$(EXEEXT) pnm2png-static$(EXEEXT)
+
+png2pnm.o: png2pnm.c
+ $(CC) -c $(CPPFLAGS) $(CFLAGS) png2pnm.c
+
+pnm2png.o: pnm2png.c
+ $(CC) -c $(CPPFLAGS) $(CFLAGS) pnm2png.c
+
+png2pnm$(EXEEXT): png2pnm.o
+ $(LD) $(LDFLAGS) -o png2pnm$(EXEEXT) png2pnm.o $(LIBS_SHARED) -lm
+
+pnm2png$(EXEEXT): pnm2png.o
+ $(LD) $(LDFLAGS) -o pnm2png$(EXEEXT) pnm2png.o $(LIBS_SHARED) -lm
+
+png2pnm-static$(EXEEXT): png2pnm.o
+ $(LD) $(LDFLAGS) -o png2pnm-static$(EXEEXT) png2pnm.o $(LIBS_STATIC) -lm
+
+pnm2png-static$(EXEEXT): pnm2png.o
+ $(LD) $(LDFLAGS) -o pnm2png-static$(EXEEXT) pnm2png.o $(LIBS_STATIC) -lm
+
+clean:
+ $(RM) png2pnm.o
+ $(RM) pnm2png.o
+ $(RM) png2pnm$(EXEEXT)
+ $(RM) pnm2png$(EXEEXT)
+ $(RM) png2pnm-static$(EXEEXT)
+ $(RM) pnm2png-static$(EXEEXT)
+
+# End of makefile for png2pnm / pnm2png
diff --git a/libpng/contrib/pngminus/README b/libpng/contrib/pngminus/README.txt
index fbcfc986..f7f6ecb3 100644
--- a/libpng/contrib/pngminus/README
+++ b/libpng/contrib/pngminus/README.txt
@@ -1,26 +1,16 @@
PngMinus
--------
-(copyright Willem van Schaik, 1999)
+(copyright Willem van Schaik, 1999-2019)
-License
--------
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear in
-supporting documentation. This software is provided "as is" without
-express or implied warranty.
-
Some history
------------
Soon after the creation of PNG in 1995, the need was felt for a set of
-pnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I
+pnmtopng / pngtopnm utilities. Independently Alexander Lehmann and I
(Willem van Schaik) started such a project. Luckily we discovered this
-and merged the two together into pnmtopng.tar.gz, which is available
-from a/o ftp://ftp.simplesystems.org/pub/libpng/png/.
+and merged the two, which later became part of NetPBM, available from
+SourceForge.
These two utilities have many, many options and make use of most of the
features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes
@@ -35,8 +25,8 @@ makes the whole setup a bit bulky. But that's unavoidable given the many
features of pnmtopng.
-What now
---------
+What now (1999)
+---------------
At this moment libpng is in a very stable state and can do much of the
work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new
interface of libpng. Hence, it is time for a rewrite from the ground up
@@ -49,8 +39,8 @@ a small prototype that contains only the basic functionality. It doesn't
have any of the options to read or write special chunks and it will do
no gamma correction. But this makes it also a simple program that is
quite easy to understand and can serve well as a template for other
-software developments. (By now there are of course a couple of programs,
-like Greg Roelofs' rpng/wpng, that can be used just as good.)
+software developments. By now there are of course a couple of programs,
+like Greg Roelofs' rpng/wpng, that can be used just as good.
Can and can not
@@ -60,7 +50,8 @@ PngMinus. Because I started this development in good-old Turbo-C, I
avoided the use the netpbm library, which requires DOS extenders. Again,
another reason to call it PngMinus (minus netpbm :-). So, part of the
program are some elementary routines to read / write pgm- and ppm-files.
-It does not read b&w pbm-files.
+It does not handle B&W pbm-files, but instead you could do pgm with bit-
+depth 1.
The downside of this approach is that you can not use them on images
that require blocks of memory bigger than 64k (the DOS version). For
@@ -96,58 +87,34 @@ To list the options type "png2pnm -h" or "pnm2png -h".
Just like Scandinavian furniture
--------------------------------
-You have to put it together yourself. I did test the software under
-MS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both
-cases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK,
-however some older libpng versions have a bug in pngmem.c when using
-Turbo-C 3.0 (see below).
-
-You can build it using one of the two makefiles (make -f makefile.###)
-or use the batch/script files pngminus.bat / pngminus.sh. This assumes
-that you have built the libraries in ../libpng and ../zlib. Using Linux,
-make sure that you have built libpng with makefile.std and not
-makefile.linux (also called .lnx in earlier versions of libpng). The
-latter creates a .so shared-library, while the PngMinus makefile assumes
-a normal .a static library.
+You have to put it together yourself. I developed the software on MS-DOS
+with Turbo-C 3.0 and RedHat Linux 4.2 with gcc. In both cases I used
+libpng-1.0.4 and zlib-1.1.3. By now (2019) it is twenty years later and
+more current versions are OK.
+
+The makefile assumes that the libpng libraries can be found in ../.. and
+libz in ../../../zlib. But you can change this to for example ../libpng
+and ../zlib. The makefile creates two versions of each program, one with
+static library support and the other using shared libraries.
If you create a ../pngsuite directory and then store the basn####.png
files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can
-test in one go the proper functioning of PngMinus, see png2pnm.bat and
-pnm2png.bat (or the .sh versions).
+test the proper functioning of PngMinus by running pngminus.sh.
Warranty
-------
Please, remember that this was just a small experiment to learn a few
-things. It will have many unforeseen features <vbg>. Who said bugs? Use
-it when you are in need for something simple or when you want to start
-developing your own stuff.
-
-
-The Turbo bug
--------------
-** pngmem.old
- hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
- hptr += 16L;
-** pngmem.c
- hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
- hptr = hptr + 16L;
-**
-
-** pngmem.old
- png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
- hptr += (png_uint_32)65536L;
-** pngmem.c
- png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
- hptr = hptr + 65536L;
-**
+things. It will have many unforeseen features <vbg> ... who said bugs? Use
+it when you are in need for something simple or when you want a starting
+point for developing your own stuff.
The end
-------
Willem van Schaik
-mailto:willem at schaik.com
+mailto:willem at schaik dot com
http://www.schaik.com/png/
--------
-Oct 1999
+
+Oct 1999, Jan 2019
diff --git a/libpng/contrib/pngminus/makefile.std b/libpng/contrib/pngminus/makefile.std
deleted file mode 100644
index 14e25cd6..00000000
--- a/libpng/contrib/pngminus/makefile.std
+++ /dev/null
@@ -1,66 +0,0 @@
-# Makefile for PngMinus (png2pnm and pnm2png)
-# Linux / Unix
-
-#CC=cc
-CC=gcc
-LD=$(CC)
-
-RM=rm -f
-
-#PNGPATH = /usr/local
-#PNGINC = -I$(PNGPATH)/include/libpng16
-#PNGLIB = -L$(PNGPATH)/lib -lpng16
-#PNGLIBS = $(PNGPATH)/lib/libpng16.a
-PNGINC = -I../..
-PNGLIB = -L../.. -lpng
-PNGLIBS = ../../libpng.a
-
-#ZPATH = /usr/local
-#ZINC = -I$(ZPATH)/include
-#ZLIB = -L$(ZPATH)/lib -lz
-#ZLIBS = $(ZPATH)/lib/libz.a
-ZINC = -I../../../zlib
-ZLIB = -L../../../zlib -lz
-ZLIBS = ../../../zlib/libz.a
-
-CPPFLAGS=$(PNGINC) $(ZINC)
-CFLAGS=
-LDLIBS=$(PNGLIB) $(ZLIB)
-LDLIBSS=$(PNGLIBS) $(ZLIBS)
-C=.c
-O=.o
-L=.a
-E=
-
-# dependencies
-
-#all: png2pnm$(E) pnm2png$(E)
-all: png2pnm$(E) pnm2png$(E) png2pnm-static$(E) pnm2png-static$(E)
-
-png2pnm$(O): png2pnm$(C)
- $(CC) -c $(CPPFLAGS) $(CFLAGS) png2pnm$(C)
-
-png2pnm$(E): png2pnm$(O)
- $(LD) $(LDFLAGS) -o png2pnm$(E) png2pnm$(O) $(LDLIBS) -lm
-
-png2pnm-static$(E): png2pnm$(O)
- $(LD) $(LDFLAGS) -o png2pnm-static$(E) png2pnm$(O) $(LDLIBSS) -lm
-
-pnm2png$(O): pnm2png$(C)
- $(CC) -c $(CPPFLAGS) $(CFLAGS) pnm2png$(C)
-
-pnm2png$(E): pnm2png$(O)
- $(LD) $(LDFLAGS) -o pnm2png$(E) pnm2png$(O) $(LDLIBS) -lm
-
-pnm2png-static$(E): pnm2png$(O)
- $(LD) $(LDFLAGS) -o pnm2png-static$(E) pnm2png$(O) $(LDLIBSS) -lm
-
-clean:
- $(RM) png2pnm$(O)
- $(RM) pnm2png$(O)
- $(RM) png2pnm$(E)
- $(RM) pnm2png$(E)
- $(RM) png2pnm-static$(E)
- $(RM) pnm2png-static$(E)
-
-# End of makefile for png2pnm / pnm2png
diff --git a/libpng/contrib/pngminus/makefile.tc3 b/libpng/contrib/pngminus/makefile.tc3
deleted file mode 100644
index 6a2f4b98..00000000
--- a/libpng/contrib/pngminus/makefile.tc3
+++ /dev/null
@@ -1,38 +0,0 @@
-# Makefile for PngMinus (png2pnm and pnm2png)
-# TurboC++ 3.0
-
-CC=tcc -Ic:\tc3\inc
-LD=tcc -Lc:\tc3\lib
-LB=tlib
-RM=del
-CP=copy
-MODEL=l
-CPPFLAGS=-I..\libpng -I..\zlib
-CFLAGS=-O -m$(MODEL)
-LDFLAGS=-m$(MODEL) -L..\libpng -L..\zlib
-C=.c
-O=.obj
-L=.lib
-E=.exe
-
-# dependencies
-
-all: png2pnm$(E) pnm2png$(E)
-
-png2pnm$(O): png2pnm$(C)
- $(CC) -c $(CPPFLAGS) $(CFLAGS) png2pnm$(C)
-
-png2pnm$(E): png2pnm$(O)
- $(LD) $(LDFLAGS) png2pnm$(O) libpng$(L) zlib$(L)
-
-pnm2png$(O): pnm2png$(C)
- $(CC) -c $(CPPFLAGS) $(CFLAGS) pnm2png$(C)
-
-pnm2png$(E): pnm2png$(O)
- $(LD) $(LDFLAGS) pnm2png$(O) libpng$(L) zlib$(L)
-
-clean:
- $(RM) *$(O)
- $(RM) *$(E)
-
-# End of makefile for png2pnm / pnm2png
diff --git a/libpng/contrib/pngminus/png2pnm.bat b/libpng/contrib/pngminus/png2pnm.bat
index 449cf367..a2798c34 100755
--- a/libpng/contrib/pngminus/png2pnm.bat
+++ b/libpng/contrib/pngminus/png2pnm.bat
@@ -7,7 +7,7 @@ png2pnm.exe -noraw ..\pngsuite\basn0g16.png basn0g16.pgm
REM -- full-color
png2pnm.exe -noraw ..\pngsuite\basn2c08.png basn2c08.ppm
png2pnm.exe -noraw ..\pngsuite\basn2c16.png basn2c16.ppm
-REM -- palletted
+REM -- paletted
png2pnm.exe -noraw ..\pngsuite\basn3p01.png basn3p01.ppm
png2pnm.exe -noraw ..\pngsuite\basn3p02.png basn3p02.ppm
png2pnm.exe -noraw ..\pngsuite\basn3p04.png basn3p04.ppm
@@ -27,7 +27,7 @@ png2pnm.exe -raw ..\pngsuite\basn0g16.png rawn0g16.pgm
REM -- full-color
png2pnm.exe -raw ..\pngsuite\basn2c08.png rawn2c08.ppm
png2pnm.exe -raw ..\pngsuite\basn2c16.png rawn2c16.ppm
-REM -- palletted
+REM -- paletted
png2pnm.exe -raw ..\pngsuite\basn3p01.png rawn3p01.ppm
png2pnm.exe -raw ..\pngsuite\basn3p02.png rawn3p02.ppm
png2pnm.exe -raw ..\pngsuite\basn3p04.png rawn3p04.ppm
diff --git a/libpng/contrib/pngminus/png2pnm.c b/libpng/contrib/pngminus/png2pnm.c
index 1420a783..5fef7ed1 100644
--- a/libpng/contrib/pngminus/png2pnm.c
+++ b/libpng/contrib/pngminus/png2pnm.c
@@ -1,28 +1,14 @@
/*
* png2pnm.c --- conversion from PNG-file to PGM/PPM-file
- * copyright (C) 1999,2017 by Willem van Schaik <willem at schaik.com>
+ * copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
*
- * version 1.0 - 1999.10.15 - First version.
- * 1.1 - 2017.04.22 - Add buffer-size check (Glenn Randers-Pehrson)
- * 1.2 - 2017.08.24 - Fix potential overflow in buffer-size check
- * (Glenn Randers-Pehrson)
- * 1.3 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear in
- * supporting documentation. This software is provided "as is" without
- * express or implied warranty.
+ * This software is released under the MIT license. For conditions of
+ * distribution and use, see the LICENSE file part of this package.
*/
#include <stdio.h>
#include <stdlib.h>
-#ifdef __TURBOC__
-#include <mem.h>
#include <fcntl.h>
-#endif
-#include <zlib.h>
#ifndef BOOL
#define BOOL unsigned char
@@ -34,45 +20,25 @@
#define FALSE (BOOL) 0
#endif
-#ifdef __TURBOC__
-#define STDIN 0
-#define STDOUT 1
-#define STDERR 2
-#endif
-
-/* to make png2pnm verbose so we can find problems (needs to be before png.h) */
+/* make png2pnm verbose so we can find problems (needs to be before png.h) */
#ifndef PNG_DEBUG
#define PNG_DEBUG 0
#endif
-
#include "png.h"
-/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
-#ifndef png_jmpbuf
-# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
-#endif
-
-#ifndef PNGMINUS_UNUSED
-/* Unused formal parameter warnings are silenced using the following macro
- * which is expected to have no bad effects on performance (optimizing
- * compilers will probably remove it entirely).
- */
-# define PNGMINUS_UNUSED(param) (void)param
-#endif
-
/* function prototypes */
-int main (int argc, char *argv[]);
+int main (int argc, char *argv[]);
void usage ();
-BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw,
- BOOL alpha);
+BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
+ BOOL raw, BOOL alpha);
/*
* main
*/
-int main(int argc, char *argv[])
+int main (int argc, char *argv[])
{
FILE *fp_rd = stdin;
FILE *fp_wr = stdout;
@@ -99,21 +65,21 @@ int main(int argc, char *argv[])
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
{
fprintf (stderr, "PNM2PNG\n");
- fprintf (stderr, "Error: can not create alpha-channel file %s\n",
- argv[argi]);
+ fprintf (stderr, "Error: cannot create alpha-channel file %s\n",
+ argv[argi]);
exit (1);
}
break;
case 'h':
case '?':
- usage();
- exit(0);
+ usage ();
+ exit (0);
break;
default:
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
- usage();
- exit(1);
+ usage ();
+ exit (1);
break;
} /* end switch */
}
@@ -121,9 +87,9 @@ int main(int argc, char *argv[])
{
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
{
- fprintf (stderr, "PNG2PNM\n");
- fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
- exit (1);
+ fprintf (stderr, "PNG2PNM\n");
+ fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
+ exit (1);
}
}
else if (fp_wr == stdout)
@@ -131,7 +97,7 @@ int main(int argc, char *argv[])
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
{
fprintf (stderr, "PNG2PNM\n");
- fprintf (stderr, "Error: can not create file %s\n", argv[argi]);
+ fprintf (stderr, "Error: cannot create file %s\n", argv[argi]);
exit (1);
}
}
@@ -139,21 +105,17 @@ int main(int argc, char *argv[])
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: too many parameters\n");
- usage();
- exit(1);
+ usage ();
+ exit (1);
}
} /* end for */
-#ifdef __TURBOC__
+#if defined(O_BINARY) && (O_BINARY != 0)
/* set stdin/stdout if required to binary */
if (fp_rd == stdin)
- {
- setmode (STDIN, O_BINARY);
- }
+ setmode (fileno (stdin), O_BINARY);
if ((raw) && (fp_wr == stdout))
- {
- setmode (STDOUT, O_BINARY);
- }
+ setmode (fileno (stdout), O_BINARY);
#endif
/* call the conversion program itself */
@@ -161,7 +123,7 @@ int main(int argc, char *argv[])
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n");
- exit(1);
+ exit (1);
}
/* close input file */
@@ -179,23 +141,18 @@ int main(int argc, char *argv[])
* usage
*/
-void usage()
+void usage ()
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, " by Willem van Schaik, 1999\n");
-#ifdef __TURBOC__
- fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
-#else
- fprintf (stderr, " for Linux (and Unix) compilers\n");
-#endif
fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
fprintf (stderr, " or: ... | png2pnm [options]\n");
fprintf (stderr, "Options:\n");
fprintf (stderr,
- " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
+ " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
fprintf (stderr,
- " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
+ " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
fprintf (stderr, " -h | -? print this help-information\n");
}
@@ -204,10 +161,10 @@ void usage()
*/
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
- volatile BOOL raw, BOOL alpha)
+ BOOL raw, BOOL alpha)
{
png_struct *png_ptr = NULL;
- png_info *info_ptr = NULL;
+ png_info *info_ptr = NULL;
png_byte buf[8];
png_byte *png_pixels = NULL;
png_byte **row_pointers = NULL;
@@ -231,24 +188,24 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
return FALSE;
ret = png_sig_cmp (buf, 0, 8);
- if (ret)
+ if (ret != 0)
return FALSE;
/* create png and info structures */
png_ptr = png_create_read_struct (png_get_libpng_ver(NULL),
- NULL, NULL, NULL);
+ NULL, NULL, NULL);
if (!png_ptr)
- return FALSE; /* out of memory */
+ return FALSE; /* out of memory */
info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
png_destroy_read_struct (&png_ptr, NULL, NULL);
- return FALSE; /* out of memory */
+ return FALSE; /* out of memory */
}
- if (setjmp (png_jmpbuf(png_ptr)))
+ if (setjmp (png_jmpbuf (png_ptr)))
{
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
@@ -256,15 +213,14 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
/* set up the input control for C streams */
png_init_io (png_ptr, png_file);
- png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
+ png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
/* read the file information */
png_read_info (png_ptr, info_ptr);
/* get size and bit-depth of the PNG-image */
- png_get_IHDR (png_ptr, info_ptr,
- &width, &height, &bit_depth, &color_type,
- NULL, NULL, NULL);
+ png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
+ NULL, NULL, NULL);
/* set-up the transformations */
@@ -284,7 +240,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
png_set_strip_16 (png_ptr);
/* transform grayscale images into full-color */
if (color_type == PNG_COLOR_TYPE_GRAY ||
- color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png_ptr);
/* only if file has a file gamma, we do a correction */
if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
@@ -298,14 +254,14 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
/* get the new color-type and bit-depth (after expansion/stripping) */
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
- NULL, NULL, NULL);
+ NULL, NULL, NULL);
/* check for 16-bit files */
if (bit_depth == 16)
{
raw = FALSE;
-#ifdef __TURBOC__
- pnm_file->flags &= ~((unsigned) _F_BIN);
+#if defined(O_BINARY) && (O_BINARY != 0)
+ setmode (fileno (pnm_file), O_BINARY);
#endif
}
@@ -333,25 +289,25 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
/* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
- if ((row_bytes == 0 || (size_t)height > ((size_t)(-1))/(size_t)row_bytes))
+ if ((row_bytes == 0) ||
+ ((size_t) height > (size_t) (-1) / (size_t) row_bytes))
{
- /* too big */
+ /* too big */
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
}
if ((png_pixels = (png_byte *)
- malloc ((size_t)row_bytes * (size_t)height * sizeof (png_byte))) == NULL)
+ malloc ((size_t) row_bytes * (size_t) height)) == NULL)
{
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
}
if ((row_pointers = (png_byte **)
- malloc ((size_t)height * sizeof (png_bytep))) == NULL)
+ malloc ((size_t) height * sizeof (png_byte *))) == NULL)
{
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
free (png_pixels);
- png_pixels = NULL;
return FALSE;
}
@@ -366,7 +322,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
png_read_end (png_ptr, info_ptr);
/* clean up after the read, and free any memory allocated - REQUIRED */
- png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
+ png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
/* write header of PNM file */
@@ -406,14 +362,21 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
for (i = 0; i < (channels - alpha_present); i++)
{
if (raw)
- fputc ((int) *pix_ptr++ , pnm_file);
+ {
+ fputc ((int) *pix_ptr++, pnm_file);
+ }
else
- if (bit_depth == 16){
+ {
+ if (bit_depth == 16)
+ {
dep_16 = (long) *pix_ptr++;
fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++));
}
else
+ {
fprintf (pnm_file, "%ld ", (long) *pix_ptr++);
+ }
+ }
}
if (alpha_present)
{
@@ -426,17 +389,23 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
else /* output alpha-channel as pgm file */
{
if (raw)
- fputc ((int) *pix_ptr++ , alpha_file);
+ {
+ fputc ((int) *pix_ptr++, alpha_file);
+ }
else
+ {
if (bit_depth == 16)
{
dep_16 = (long) *pix_ptr++;
fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
}
else
+ {
fprintf (alpha_file, "%ld ", (long) *pix_ptr++);
+ }
+ }
}
- } /* if alpha_present */
+ } /* end if alpha_present */
if (!raw)
if (col % 4 == 3)
@@ -448,13 +417,11 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
fprintf (pnm_file, "\n");
} /* end for row */
- if (row_pointers != (unsigned char**) NULL)
+ if (row_pointers != NULL)
free (row_pointers);
- if (png_pixels != (unsigned char*) NULL)
+ if (png_pixels != NULL)
free (png_pixels);
- PNGMINUS_UNUSED(raw); /* to quiet a Coverity defect */
return TRUE;
} /* end of source */
-
diff --git a/libpng/contrib/pngminus/png2pnm.sh b/libpng/contrib/pngminus/png2pnm.sh
index b1c05370..756126a5 100755
--- a/libpng/contrib/pngminus/png2pnm.sh
+++ b/libpng/contrib/pngminus/png2pnm.sh
@@ -8,7 +8,7 @@
# -- full-color
./png2pnm -noraw ../pngsuite/basn2c08.png basn2c08.ppm
./png2pnm -noraw ../pngsuite/basn2c16.png basn2c16.ppm
-# -- palletted
+# -- paletted
./png2pnm -noraw ../pngsuite/basn3p01.png basn3p01.ppm
./png2pnm -noraw ../pngsuite/basn3p02.png basn3p02.ppm
./png2pnm -noraw ../pngsuite/basn3p04.png basn3p04.ppm
@@ -28,7 +28,7 @@
# -- full-color
./png2pnm -raw ../pngsuite/basn2c08.png rawn2c08.ppm
./png2pnm -raw ../pngsuite/basn2c16.png rawn2c16.ppm
-# -- palletted
+# -- paletted
./png2pnm -raw ../pngsuite/basn3p01.png rawn3p01.ppm
./png2pnm -raw ../pngsuite/basn3p02.png rawn3p02.ppm
./png2pnm -raw ../pngsuite/basn3p04.png rawn3p04.ppm
diff --git a/libpng/contrib/pngminus/pngminus.bat b/libpng/contrib/pngminus/pngminus.bat
index 911bb8df..fa60e7de 100755
--- a/libpng/contrib/pngminus/pngminus.bat
+++ b/libpng/contrib/pngminus/pngminus.bat
@@ -1,4 +1,4 @@
-make -f makefile.tc3
+make
call png2pnm.bat
call pnm2png.bat
diff --git a/libpng/contrib/pngminus/pngminus.sh b/libpng/contrib/pngminus/pngminus.sh
index 2a0a9d8f..cc9b4a56 100755
--- a/libpng/contrib/pngminus/pngminus.sh
+++ b/libpng/contrib/pngminus/pngminus.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-make -f makefile.std
+make
sh png2pnm.sh
sh pnm2png.sh
diff --git a/libpng/contrib/pngminus/pnm2png.bat b/libpng/contrib/pngminus/pnm2png.bat
index f756cb84..c02b80be 100755
--- a/libpng/contrib/pngminus/pnm2png.bat
+++ b/libpng/contrib/pngminus/pnm2png.bat
@@ -7,7 +7,7 @@ pnm2png.exe basn0g16.pgm basn0g16.png
REM -- full-color
pnm2png.exe basn2c08.ppm basn2c08.png
pnm2png.exe basn2c16.ppm basn2c16.png
-REM -- palletted
+REM -- paletted
pnm2png.exe basn3p01.ppm basn3p01.png
pnm2png.exe basn3p02.ppm basn3p02.png
pnm2png.exe basn3p04.ppm basn3p04.png
@@ -27,7 +27,7 @@ pnm2png.exe rawn0g16.pgm rawn0g16.png
REM -- full-color
pnm2png.exe rawn2c08.ppm rawn2c08.png
pnm2png.exe rawn2c16.ppm rawn2c16.png
-REM -- palletted
+REM -- paletted
pnm2png.exe rawn3p01.ppm rawn3p01.png
pnm2png.exe rawn3p02.ppm rawn3p02.png
pnm2png.exe rawn3p04.ppm rawn3p04.png
diff --git a/libpng/contrib/pngminus/pnm2png.c b/libpng/contrib/pngminus/pnm2png.c
index 0d2caef9..a2c2551d 100644
--- a/libpng/contrib/pngminus/pnm2png.c
+++ b/libpng/contrib/pngminus/pnm2png.c
@@ -1,29 +1,14 @@
/*
* pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file
- * copyright (C) 1999,2015,2017 by Willem van Schaik <willem at schaik.com>
+ * copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
*
- * version 1.0 - 1999.10.15 - First version.
- * version 1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)
- * version 1.2 - 2017.04.22 - Add buffer-size check
- * 1.3 - 2017.08.24 - Fix potential overflow in buffer-size check
- * (Glenn Randers-Pehrson)
- * 1.4 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear in
- * supporting documentation. This software is provided "as is" without
- * express or implied warranty.
+ * This software is released under the MIT license. For conditions of
+ * distribution and use, see the LICENSE file part of this package.
*/
#include <stdio.h>
#include <stdlib.h>
-#ifdef __TURBOC__
-#include <mem.h>
#include <fcntl.h>
-#endif
-#include <zlib.h>
#ifndef BOOL
#define BOOL unsigned char
@@ -35,38 +20,20 @@
#define FALSE (BOOL) 0
#endif
-#define STDIN 0
-#define STDOUT 1
-#define STDERR 2
-
-/* to make pnm2png verbose so we can find problems (needs to be before png.h) */
+/* make pnm2png verbose so we can find problems (needs to be before png.h) */
#ifndef PNG_DEBUG
#define PNG_DEBUG 0
#endif
#include "png.h"
-/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
-#ifndef png_jmpbuf
-# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
-#endif
-
-#ifndef PNGMINUS_UNUSED
-/* Unused formal parameter warnings are silenced using the following macro
- * which is expected to have no bad effects on performance (optimizing
- * compilers will probably remove it entirely).
- */
-# define PNGMINUS_UNUSED(param) (void)param
-#endif
-
-
/* function prototypes */
-int main (int argc, char *argv[]);
+int main (int argc, char *argv[]);
void usage ();
-BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
- BOOL alpha);
-void get_token(FILE *pnm_file, char *token);
+BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file,
+ BOOL interlace, BOOL alpha);
+void get_token (FILE *pnm_file, char *token_buf, size_t token_buf_size);
png_uint_32 get_data (FILE *pnm_file, int depth);
png_uint_32 get_value (FILE *pnm_file, int depth);
@@ -74,7 +41,7 @@ png_uint_32 get_value (FILE *pnm_file, int depth);
* main
*/
-int main(int argc, char *argv[])
+int main (int argc, char *argv[])
{
FILE *fp_rd = stdin;
FILE *fp_al = NULL;
@@ -99,20 +66,20 @@ int main(int argc, char *argv[])
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: alpha-channel file %s does not exist\n",
- argv[argi]);
+ argv[argi]);
exit (1);
}
break;
case 'h':
case '?':
- usage();
- exit(0);
+ usage ();
+ exit (0);
break;
default:
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
- usage();
- exit(1);
+ usage ();
+ exit (1);
break;
} /* end switch */
}
@@ -130,7 +97,7 @@ int main(int argc, char *argv[])
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
{
fprintf (stderr, "PNM2PNG\n");
- fprintf (stderr, "Error: can not create PNG-file %s\n", argv[argi]);
+ fprintf (stderr, "Error: cannot create PNG-file %s\n", argv[argi]);
exit (1);
}
}
@@ -138,21 +105,19 @@ int main(int argc, char *argv[])
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: too many parameters\n");
- usage();
+ usage ();
exit (1);
}
} /* end for */
-#ifdef __TURBOC__
- /* set stdin/stdout to binary, we're reading the PNM always! in binary format */
+#if defined(O_BINARY) && (O_BINARY != 0)
+ /* set stdin/stdout to binary,
+ * we're reading the PNM always! in binary format
+ */
if (fp_rd == stdin)
- {
- setmode (STDIN, O_BINARY);
- }
+ setmode (fileno (stdin), O_BINARY);
if (fp_wr == stdout)
- {
- setmode (STDOUT, O_BINARY);
- }
+ setmode (fileno (stdout), O_BINARY);
#endif
/* call the conversion program itself */
@@ -178,15 +143,10 @@ int main(int argc, char *argv[])
* usage
*/
-void usage()
+void usage ()
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, " by Willem van Schaik, 1999\n");
-#ifdef __TURBOC__
- fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
-#else
- fprintf (stderr, " for Linux (and Unix) compilers\n");
-#endif
fprintf (stderr, "Usage: pnm2png [options] <file>.<pnm> [<file>.png]\n");
fprintf (stderr, " or: ... | pnm2png [options]\n");
fprintf (stderr, "Options:\n");
@@ -200,31 +160,31 @@ void usage()
* pnm2png
*/
-BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
- BOOL alpha)
+BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file,
+ BOOL interlace, BOOL alpha)
{
png_struct *png_ptr = NULL;
png_info *info_ptr = NULL;
png_byte *png_pixels = NULL;
png_byte **row_pointers = NULL;
png_byte *pix_ptr = NULL;
- volatile png_uint_32 row_bytes;
+ volatile png_uint_32 row_bytes;
char type_token[16];
char width_token[16];
char height_token[16];
char maxval_token[16];
- volatile int color_type=1;
- unsigned long ul_width=0, ul_alpha_width=0;
- unsigned long ul_height=0, ul_alpha_height=0;
- unsigned long ul_maxval=0;
- volatile png_uint_32 width=0, height=0;
- volatile png_uint_32 alpha_width=0, alpha_height=0;
+ volatile int color_type = 1;
+ unsigned long ul_width = 0, ul_alpha_width = 0;
+ unsigned long ul_height = 0, ul_alpha_height = 0;
+ unsigned long ul_maxval = 0;
+ volatile png_uint_32 width = 0, height = 0;
+ volatile png_uint_32 alpha_width = 0, alpha_height = 0;
png_uint_32 maxval;
- volatile int bit_depth = 0;
- int channels=0;
+ volatile int bit_depth = 0;
+ int channels = 0;
int alpha_depth = 0;
- int alpha_present=0;
+ int alpha_present = 0;
int row, col;
BOOL raw, alpha_raw = FALSE;
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
@@ -235,7 +195,7 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
/* read header of PNM file */
- get_token(pnm_file, type_token);
+ get_token (pnm_file, type_token, sizeof (type_token));
if (type_token[0] != 'P')
{
return FALSE;
@@ -245,30 +205,31 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
raw = (type_token[1] == '4');
color_type = PNG_COLOR_TYPE_GRAY;
- get_token(pnm_file, width_token);
+ get_token (pnm_file, width_token, sizeof (width_token));
sscanf (width_token, "%lu", &ul_width);
width = (png_uint_32) ul_width;
- get_token(pnm_file, height_token);
+ get_token (pnm_file, height_token, sizeof (height_token));
sscanf (height_token, "%lu", &ul_height);
height = (png_uint_32) ul_height;
bit_depth = 1;
packed_bitmap = TRUE;
#else
- fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and \n");
+ fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and\n");
fprintf (stderr, "PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\n");
+ return FALSE;
#endif
}
else if ((type_token[1] == '2') || (type_token[1] == '5'))
{
raw = (type_token[1] == '5');
color_type = PNG_COLOR_TYPE_GRAY;
- get_token(pnm_file, width_token);
+ get_token (pnm_file, width_token, sizeof (width_token));
sscanf (width_token, "%lu", &ul_width);
width = (png_uint_32) ul_width;
- get_token(pnm_file, height_token);
+ get_token (pnm_file, height_token, sizeof (height_token));
sscanf (height_token, "%lu", &ul_height);
height = (png_uint_32) ul_height;
- get_token(pnm_file, maxval_token);
+ get_token (pnm_file, maxval_token, sizeof (maxval_token));
sscanf (maxval_token, "%lu", &ul_maxval);
maxval = (png_uint_32) ul_maxval;
@@ -280,20 +241,22 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
bit_depth = 4;
else if (maxval <= 255)
bit_depth = 8;
- else /* if (maxval <= 65535) */
+ else if (maxval <= 65535U)
bit_depth = 16;
+ else /* maxval > 65535U */
+ return FALSE;
}
else if ((type_token[1] == '3') || (type_token[1] == '6'))
{
raw = (type_token[1] == '6');
color_type = PNG_COLOR_TYPE_RGB;
- get_token(pnm_file, width_token);
+ get_token (pnm_file, width_token, sizeof (width_token));
sscanf (width_token, "%lu", &ul_width);
width = (png_uint_32) ul_width;
- get_token(pnm_file, height_token);
+ get_token (pnm_file, height_token, sizeof (height_token));
sscanf (height_token, "%lu", &ul_height);
height = (png_uint_32) ul_height;
- get_token(pnm_file, maxval_token);
+ get_token (pnm_file, maxval_token, sizeof (maxval_token));
sscanf (maxval_token, "%lu", &ul_maxval);
maxval = (png_uint_32) ul_maxval;
if (maxval <= 1)
@@ -304,8 +267,10 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
bit_depth = 4;
else if (maxval <= 255)
bit_depth = 8;
- else /* if (maxval <= 65535) */
+ else if (maxval <= 65535U)
bit_depth = 16;
+ else /* maxval > 65535U */
+ return FALSE;
}
else
{
@@ -321,7 +286,7 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
if (color_type == PNG_COLOR_TYPE_RGB)
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
- get_token(alpha_file, type_token);
+ get_token (alpha_file, type_token, sizeof (type_token));
if (type_token[0] != 'P')
{
return FALSE;
@@ -329,17 +294,17 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
else if ((type_token[1] == '2') || (type_token[1] == '5'))
{
alpha_raw = (type_token[1] == '5');
- get_token(alpha_file, width_token);
+ get_token (alpha_file, width_token, sizeof (width_token));
sscanf (width_token, "%lu", &ul_alpha_width);
- alpha_width=(png_uint_32) ul_alpha_width;
+ alpha_width = (png_uint_32) ul_alpha_width;
if (alpha_width != width)
return FALSE;
- get_token(alpha_file, height_token);
+ get_token (alpha_file, height_token, sizeof (height_token));
sscanf (height_token, "%lu", &ul_alpha_height);
alpha_height = (png_uint_32) ul_alpha_height;
if (alpha_height != height)
return FALSE;
- get_token(alpha_file, maxval_token);
+ get_token (alpha_file, maxval_token, sizeof (maxval_token));
sscanf (maxval_token, "%lu", &ul_maxval);
maxval = (png_uint_32) ul_maxval;
if (maxval <= 1)
@@ -350,8 +315,10 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
alpha_depth = 4;
else if (maxval <= 255)
alpha_depth = 8;
- else /* if (maxval <= 65535) */
+ else if (maxval <= 65535U)
alpha_depth = 16;
+ else /* maxval > 65535U */
+ return FALSE;
if (alpha_depth != bit_depth)
return FALSE;
}
@@ -379,21 +346,29 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
if (packed_bitmap)
+ {
/* row data is as many bytes as can fit width x channels x bit_depth */
row_bytes = (width * channels * bit_depth + 7) / 8;
+ }
else
#endif
- /* row_bytes is the width x number of channels x (bit-depth / 8) */
+ {
+ /* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
+ }
- if ((row_bytes == 0 || (size_t)height > ((size_t)(-1))/(size_t)row_bytes))
+ if ((row_bytes == 0) ||
+ ((size_t) height > (size_t) (-1) / (size_t) row_bytes))
{
- /* too big */
+ /* too big */
return FALSE;
}
if ((png_pixels = (png_byte *)
- malloc ((size_t)row_bytes * (size_t)height * sizeof (png_byte))) == NULL)
+ malloc ((size_t) row_bytes * (size_t) height)) == NULL)
+ {
+ /* out of memory */
return FALSE;
+ }
/* read data from PNM file */
pix_ptr = png_pixels;
@@ -404,9 +379,12 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
if (packed_bitmap)
{
for (i = 0; i < (int) row_bytes; i++)
+ {
/* png supports this format natively so no conversion is needed */
*pix_ptr++ = get_data (pnm_file, 8);
- } else
+ }
+ }
+ else
#endif
{
for (col = 0; col < (int) width; col++)
@@ -414,10 +392,15 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
for (i = 0; i < (channels - alpha_present); i++)
{
if (raw)
+ {
*pix_ptr++ = get_data (pnm_file, bit_depth);
+ }
else
+ {
if (bit_depth <= 8)
+ {
*pix_ptr++ = get_value (pnm_file, bit_depth);
+ }
else
{
tmp16 = get_value (pnm_file, bit_depth);
@@ -426,41 +409,46 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
*pix_ptr = (png_byte) (tmp16 & 0xFF);
pix_ptr++;
}
+ }
}
if (alpha) /* read alpha-channel from pgm file */
{
if (alpha_raw)
+ {
*pix_ptr++ = get_data (alpha_file, alpha_depth);
+ }
else
+ {
if (alpha_depth <= 8)
+ {
*pix_ptr++ = get_value (alpha_file, bit_depth);
+ }
else
{
tmp16 = get_value (alpha_file, bit_depth);
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
}
- } /* if alpha */
- } /* if packed_bitmap */
+ }
+ } /* end if alpha */
+ } /* end if packed_bitmap */
} /* end for col */
} /* end for row */
/* prepare the standard PNG structures */
- png_ptr = png_create_write_struct (png_get_libpng_ver(NULL), NULL, NULL,
- NULL);
+ png_ptr = png_create_write_struct (png_get_libpng_ver(NULL),
+ NULL, NULL, NULL);
if (!png_ptr)
{
free (png_pixels);
- png_pixels = NULL;
return FALSE;
}
info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
- png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
+ png_destroy_write_struct (&png_ptr, NULL);
free (png_pixels);
- png_pixels = NULL;
return FALSE;
}
@@ -472,12 +460,10 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
}
#endif
- /* setjmp() must be called in every function that calls a PNG-reading libpng function */
- if (setjmp (png_jmpbuf(png_ptr)))
+ if (setjmp (png_jmpbuf (png_ptr)))
{
png_destroy_write_struct (&png_ptr, &info_ptr);
free (png_pixels);
- png_pixels = NULL;
return FALSE;
}
@@ -486,21 +472,20 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
/* we're going to write more or less the same PNG as the input file */
png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type,
- (!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
- PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+ (!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* write the file header information */
png_write_info (png_ptr, info_ptr);
/* if needed we will allocate memory for an new array of row-pointers */
- if (row_pointers == (unsigned char**) NULL)
+ if (row_pointers == NULL)
{
if ((row_pointers = (png_byte **)
- malloc (height * sizeof (png_bytep))) == NULL)
+ malloc (height * sizeof (png_byte *))) == NULL)
{
png_destroy_write_struct (&png_ptr, &info_ptr);
free (png_pixels);
- png_pixels = NULL;
return FALSE;
}
}
@@ -518,62 +503,60 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
/* clean up after the write, and free any memory allocated */
png_destroy_write_struct (&png_ptr, &info_ptr);
- if (row_pointers != (unsigned char**) NULL)
+ if (row_pointers != NULL)
free (row_pointers);
- if (png_pixels != (unsigned char*) NULL)
+ if (png_pixels != NULL)
free (png_pixels);
- PNGMINUS_UNUSED(raw); /* Quiet a Coverity defect */
-
return TRUE;
} /* end of pnm2png */
/*
- * get_token() - gets the first string after whitespace
+ * get_token - gets the first string after whitespace
*/
-void get_token(FILE *pnm_file, char *token)
+void get_token (FILE *pnm_file, char *token_buf, size_t token_buf_size)
{
- int i = 0;
+ size_t i = 0;
int ret;
/* remove white-space and comment lines */
do
{
- ret = fgetc(pnm_file);
+ ret = fgetc (pnm_file);
if (ret == '#')
{
/* the rest of this line is a comment */
do
{
- ret = fgetc(pnm_file);
+ ret = fgetc (pnm_file);
}
while ((ret != '\n') && (ret != '\r') && (ret != EOF));
}
if (ret == EOF) break;
- token[i] = (unsigned char) ret;
+ token_buf[i] = (char) ret;
}
- while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
+ while ((ret == '\n') || (ret == '\r') || (ret == ' '));
/* read string */
do
{
- ret = fgetc(pnm_file);
+ ret = fgetc (pnm_file);
if (ret == EOF) break;
- i++;
- token[i] = (unsigned char) ret;
+ if (++i == token_buf_size - 1) break;
+ token_buf[i] = (char) ret;
}
- while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));
+ while ((ret != '\n') && (ret != '\r') && (ret != ' '));
- token[i] = '\0';
+ token_buf[i] = '\0';
return;
}
/*
- * get_data() - takes first byte and converts into next pixel value,
- * taking as much bits as defined by bit-depth and
- * using the bit-depth to fill up a byte (0Ah -> AAh)
+ * get_data - takes first byte and converts into next pixel value,
+ * taking as much bits as defined by bit-depth and
+ * using the bit-depth to fill up a byte (0Ah -> AAh)
*/
png_uint_32 get_data (FILE *pnm_file, int depth)
@@ -605,14 +588,14 @@ png_uint_32 get_data (FILE *pnm_file, int depth)
}
/*
- * get_value() - takes first (numeric) string and converts into number,
- * using the bit-depth to fill up a byte (0Ah -> AAh)
+ * get_value - takes first (numeric) string and converts into number,
+ * using the bit-depth to fill up a byte (0Ah -> AAh)
*/
png_uint_32 get_value (FILE *pnm_file, int depth)
{
static png_uint_32 mask = 0;
- png_byte token[16];
+ char token[16];
unsigned long ul_ret_value;
png_uint_32 ret_value;
int i = 0;
@@ -621,8 +604,8 @@ png_uint_32 get_value (FILE *pnm_file, int depth)
for (i = 0; i < depth; i++)
mask = (mask << 1) | 0x01;
- get_token (pnm_file, (char *) token);
- sscanf ((const char *) token, "%lu", &ul_ret_value);
+ get_token (pnm_file, token, sizeof (token));
+ sscanf (token, "%lu", &ul_ret_value);
ret_value = (png_uint_32) ul_ret_value;
ret_value &= mask;
@@ -635,4 +618,3 @@ png_uint_32 get_value (FILE *pnm_file, int depth)
}
/* end of source */
-
diff --git a/libpng/contrib/pngminus/pnm2png.sh b/libpng/contrib/pngminus/pnm2png.sh
index d79df2fa..2ad17a60 100755
--- a/libpng/contrib/pngminus/pnm2png.sh
+++ b/libpng/contrib/pngminus/pnm2png.sh
@@ -8,7 +8,7 @@
# -- full-color
./pnm2png basn2c08.ppm basn2c08.png
./pnm2png basn2c16.ppm basn2c16.png
-# -- palletted
+# -- paletted
./pnm2png basn3p01.ppm basn3p01.png
./pnm2png basn3p02.ppm basn3p02.png
./pnm2png basn3p04.ppm basn3p04.png
@@ -28,7 +28,7 @@
# -- full-color
./pnm2png rawn2c08.ppm rawn2c08.png
./pnm2png rawn2c16.ppm rawn2c16.png
-# -- palletted
+# -- paletted
./pnm2png rawn3p01.ppm rawn3p01.png
./pnm2png rawn3p02.ppm rawn3p02.png
./pnm2png rawn3p04.ppm rawn3p04.png
diff --git a/libpng/contrib/pngsuite/README b/libpng/contrib/pngsuite/README
index 53ba5c8f..d236b02e 100644
--- a/libpng/contrib/pngsuite/README
+++ b/libpng/contrib/pngsuite/README
@@ -16,6 +16,8 @@ chunks, etc.
The "ft*.png" images are "free/libre" replacements for the transparent
corresponding t*.png images in the PngSuite.
+The "i*.png" images are the same images, but interlaced.
+
The images in this directory represent the basic PNG color-types:
grayscale (1-16 bit deep), full color (8 or 16 bit), paletted
(1-8 bit) and grayscale or color images with alpha channel. You
diff --git a/libpng/contrib/pngsuite/bad_interlace_conversions.txt b/libpng/contrib/pngsuite/bad_interlace_conversions.txt
new file mode 100644
index 00000000..8afbde79
--- /dev/null
+++ b/libpng/contrib/pngsuite/bad_interlace_conversions.txt
@@ -0,0 +1,9 @@
+basn0g01.png
+basn0g02.png
+basn0g04.png
+basn3p01.png
+basn3p02.png
+basn3p04.png
+ftbbn0g01.png
+ftbbn0g02.png
+ftbbn0g04.png
diff --git a/libpng/contrib/pngsuite/ibasn0g08.png b/libpng/contrib/pngsuite/ibasn0g08.png
new file mode 100644
index 00000000..90b5305e
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn0g08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn0g16.png b/libpng/contrib/pngsuite/ibasn0g16.png
new file mode 100644
index 00000000..c82f230e
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn0g16.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn2c08.png b/libpng/contrib/pngsuite/ibasn2c08.png
new file mode 100644
index 00000000..05d46888
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn2c08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn2c16.png b/libpng/contrib/pngsuite/ibasn2c16.png
new file mode 100644
index 00000000..399f1be5
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn2c16.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn3p08.png b/libpng/contrib/pngsuite/ibasn3p08.png
new file mode 100644
index 00000000..6df8370a
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn3p08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn4a08.png b/libpng/contrib/pngsuite/ibasn4a08.png
new file mode 100644
index 00000000..bda8e3c6
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn4a08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn4a16.png b/libpng/contrib/pngsuite/ibasn4a16.png
new file mode 100644
index 00000000..500f9128
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn4a16.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn6a08.png b/libpng/contrib/pngsuite/ibasn6a08.png
new file mode 100644
index 00000000..258f9405
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn6a08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/ibasn6a16.png b/libpng/contrib/pngsuite/ibasn6a16.png
new file mode 100644
index 00000000..e4de69fe
--- /dev/null
+++ b/libpng/contrib/pngsuite/ibasn6a16.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbbn2c16.png b/libpng/contrib/pngsuite/iftbbn2c16.png
new file mode 100644
index 00000000..64a9cdf2
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbbn2c16.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbbn3p08.png b/libpng/contrib/pngsuite/iftbbn3p08.png
new file mode 100644
index 00000000..47d6eeb3
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbbn3p08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbgn2c16.png b/libpng/contrib/pngsuite/iftbgn2c16.png
new file mode 100644
index 00000000..64a9cdf2
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbgn2c16.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbgn3p08.png b/libpng/contrib/pngsuite/iftbgn3p08.png
new file mode 100644
index 00000000..47d6eeb3
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbgn3p08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbrn2c08.png b/libpng/contrib/pngsuite/iftbrn2c08.png
new file mode 100644
index 00000000..08ebbae2
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbrn2c08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbwn0g16.png b/libpng/contrib/pngsuite/iftbwn0g16.png
new file mode 100644
index 00000000..4b7537e3
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbwn0g16.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbwn3p08.png b/libpng/contrib/pngsuite/iftbwn3p08.png
new file mode 100644
index 00000000..47d6eeb3
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbwn3p08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftbyn3p08.png b/libpng/contrib/pngsuite/iftbyn3p08.png
new file mode 100644
index 00000000..47d6eeb3
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftbyn3p08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftp0n0g08.png b/libpng/contrib/pngsuite/iftp0n0g08.png
new file mode 100644
index 00000000..aa826b86
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftp0n0g08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftp0n2c08.png b/libpng/contrib/pngsuite/iftp0n2c08.png
new file mode 100644
index 00000000..b12bd0a7
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftp0n2c08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftp0n3p08.png b/libpng/contrib/pngsuite/iftp0n3p08.png
new file mode 100644
index 00000000..37aa0cb0
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftp0n3p08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/iftp1n3p08.png b/libpng/contrib/pngsuite/iftp1n3p08.png
new file mode 100644
index 00000000..47d6eeb3
--- /dev/null
+++ b/libpng/contrib/pngsuite/iftp1n3p08.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/README b/libpng/contrib/pngsuite/interlaced/README
new file mode 100644
index 00000000..f171eee0
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/README
@@ -0,0 +1,2 @@
+
+These images fail the "pngimage-quick" and "pngimage-full" tests.
diff --git a/libpng/contrib/pngsuite/interlaced/ibasn0g01.png b/libpng/contrib/pngsuite/interlaced/ibasn0g01.png
new file mode 100644
index 00000000..828fa760
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/ibasn0g01.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/ibasn0g02.png b/libpng/contrib/pngsuite/interlaced/ibasn0g02.png
new file mode 100644
index 00000000..7fc17e3a
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/ibasn0g02.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/ibasn0g04.png b/libpng/contrib/pngsuite/interlaced/ibasn0g04.png
new file mode 100644
index 00000000..1beade28
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/ibasn0g04.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/ibasn3p01.png b/libpng/contrib/pngsuite/interlaced/ibasn3p01.png
new file mode 100644
index 00000000..f91e7233
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/ibasn3p01.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/ibasn3p02.png b/libpng/contrib/pngsuite/interlaced/ibasn3p02.png
new file mode 100644
index 00000000..0f9ce76e
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/ibasn3p02.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/ibasn3p04.png b/libpng/contrib/pngsuite/interlaced/ibasn3p04.png
new file mode 100644
index 00000000..b2ca7207
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/ibasn3p04.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/iftbbn0g01.png b/libpng/contrib/pngsuite/interlaced/iftbbn0g01.png
new file mode 100644
index 00000000..6eb27d10
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/iftbbn0g01.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/iftbbn0g02.png b/libpng/contrib/pngsuite/interlaced/iftbbn0g02.png
new file mode 100644
index 00000000..46ba4977
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/iftbbn0g02.png
Binary files differ
diff --git a/libpng/contrib/pngsuite/interlaced/iftbbn0g04.png b/libpng/contrib/pngsuite/interlaced/iftbbn0g04.png
new file mode 100644
index 00000000..e9db0ad5
--- /dev/null
+++ b/libpng/contrib/pngsuite/interlaced/iftbbn0g04.png
Binary files differ
diff --git a/libpng/contrib/powerpc-vsx/README b/libpng/contrib/powerpc-vsx/README
index e566147e..4970a52c 100644
--- a/libpng/contrib/powerpc-vsx/README
+++ b/libpng/contrib/powerpc-vsx/README
@@ -46,7 +46,7 @@ everything should be static. It must define the function:
static int png_have_vsx(png_structp png_ptr);
-That function must return 1 if ARM NEON instructions are supported, 0 if not.
+That function must return 1 if POWERPC_VSX instructions are supported, 0 if not.
It must not execute png_error unless it detects a bug. A png_error will prevent
the reading of the PNG and in the future, writing too.
diff --git a/libpng/contrib/powerpc-vsx/linux_aux.c b/libpng/contrib/powerpc-vsx/linux_aux.c
index 796922d7..7828acaf 100644
--- a/libpng/contrib/powerpc-vsx/linux_aux.c
+++ b/libpng/contrib/powerpc-vsx/linux_aux.c
@@ -23,14 +23,12 @@
static int
png_have_vsx(png_structp png_ptr)
{
-
- const unsigned long auxv = getauxval( AT_HWCAP );
+ unsigned long auxv = getauxval(AT_HWCAP);
PNG_UNUSED(png_ptr)
- if(auxv & (PPC_FEATURE_HAS_ALTIVEC|PPC_FEATURE_HAS_VSX ))
+ if(auxv & (PPC_FEATURE_HAS_ALTIVEC|PPC_FEATURE_HAS_VSX))
return 1;
else
return 0;
}
-
diff --git a/libpng/contrib/testpngs/makepngs.sh b/libpng/contrib/testpngs/makepngs.sh
index 059503e2..eb1c15fc 100755
--- a/libpng/contrib/testpngs/makepngs.sh
+++ b/libpng/contrib/testpngs/makepngs.sh
@@ -74,7 +74,7 @@ case "$1" in
--coverage)
# Comments below indicate cases known to be required and not duplicated
# in other (required) cases; the aim is to get a minimal set that gives
- # the maxium code coverage.
+ # the maximum code coverage.
mpg none gray-alpha 8 # required: code coverage, sRGB opaque component
mpg none palette 8 # required: basic palette read
mpg 1.8 gray 2 # required: tests gamma threshold code
diff --git a/libpng/contrib/tools/chkfmt b/libpng/contrib/tools/chkfmt
index a1b88ccb..95181fde 100755
--- a/libpng/contrib/tools/chkfmt
+++ b/libpng/contrib/tools/chkfmt
@@ -54,7 +54,7 @@ doed(){
}
# In beta versions the version string which appears in files can be a little
-# long and cause spuriously overlong lines. To avoid this subtitute the version
+# 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
diff --git a/libpng/contrib/tools/makesRGB.c b/libpng/contrib/tools/makesRGB.c
index e66c9f15..d0c0ca93 100644
--- a/libpng/contrib/tools/makesRGB.c
+++ b/libpng/contrib/tools/makesRGB.c
@@ -388,7 +388,7 @@ main(int argc, char **argv)
if (!test_only)
{
- printf("PNG_CONST png_uint_16 png_sRGB_table[256] =\n{\n ");
+ printf("const png_uint_16 png_sRGB_table[256] =\n{\n ");
for (i=0; i<255; )
{
do
@@ -401,7 +401,7 @@ main(int argc, char **argv)
printf("%d\n};\n\n", png_sRGB_table[i]);
- printf("PNG_CONST png_uint_16 png_sRGB_base[512] =\n{\n ");
+ printf("const png_uint_16 png_sRGB_base[512] =\n{\n ");
for (i=0; i<511; )
{
do
@@ -413,7 +413,7 @@ main(int argc, char **argv)
}
printf("%d\n};\n\n", png_sRGB_base[i]);
- printf("PNG_CONST png_byte png_sRGB_delta[512] =\n{\n ");
+ printf("const png_byte png_sRGB_delta[512] =\n{\n ");
for (i=0; i<511; )
{
do
diff --git a/libpng/contrib/tools/pngcp.c b/libpng/contrib/tools/pngcp.c
index e82dddcc..16d4e7f4 100644
--- a/libpng/contrib/tools/pngcp.c
+++ b/libpng/contrib/tools/pngcp.c
@@ -191,7 +191,7 @@ vl_strategy[] =
/* This controls the order of search. */
{ "huffman", Z_HUFFMAN_ONLY },
{ "RLE", Z_RLE },
- { "fixed", Z_FIXED }, /* the remainder do window searchs */
+ { "fixed", Z_FIXED }, /* the remainder do window searches */
{ "filtered", Z_FILTERED },
{ "default", Z_DEFAULT_STRATEGY },
{ all, 0 }
@@ -336,7 +336,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 beause it justs sets the
+ /* The libpng compression level isn't searched because it justs sets the
* other things that are searched!
*/
VLO("compression", compression, 0)
@@ -735,7 +735,7 @@ option_index(struct display *dp, const char *opt, size_t len)
static int
get_option(struct display *dp, const char *opt, int *value)
{
- const png_byte i = option_index(dp, opt, strlen(opt));
+ png_byte i = option_index(dp, opt, strlen(opt));
if (dp->entry[i]) /* option was set on command line */
{
@@ -789,7 +789,7 @@ record_opt(struct display *dp, png_byte opt, const char *entry_name)
* numerical value.
*/
{
- const unsigned int sp = dp->csp; /* stack entry of next searched option */
+ unsigned int sp = dp->csp; /* stack entry of next searched option */
if (sp >= dp->tsp)
{
@@ -797,7 +797,7 @@ record_opt(struct display *dp, png_byte opt, const char *entry_name)
* searched entry or the start of the dp->curr buffer if there is nothing
* on the stack yet (sp == 0).
*/
- const int offset = set_opt_string_(dp, sp, opt, entry_name);
+ int offset = set_opt_string_(dp, sp, opt, entry_name);
if (sp > 0)
dp->stack[sp-1].opt_string_end = offset;
@@ -1222,7 +1222,7 @@ advance_opt(struct display *dp, png_byte opt, int search)
}
static int
-getallopts_(struct display *dp, const png_byte opt, int *value, int record)
+getallopts_(struct display *dp, png_byte opt, int *value, int record)
/* Like getop but iterate over all the values if the option was set to "all".
*/
{
@@ -1259,7 +1259,7 @@ getsearchopts(struct display *dp, const char *opt_str, int *value)
/* As above except that if the option was not set try a search */
{
png_byte istrat;
- const png_byte opt = option_index(dp, opt_str, strlen(opt_str));
+ png_byte opt = option_index(dp, opt_str, strlen(opt_str));
int record = options[opt].search;
const char *entry_name;
@@ -1725,7 +1725,7 @@ display_start_read(struct display *dp, const char *filename)
}
static void PNGCBAPI
-read_function(png_structp pp, png_bytep data, png_size_t size)
+read_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);
@@ -1881,7 +1881,7 @@ display_start_write(struct display *dp, const char *filename)
}
static void PNGCBAPI
-write_function(png_structp pp, png_bytep data, png_size_t size)
+write_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);
@@ -2117,7 +2117,7 @@ better_options(const struct display *dp)
*
* This function looks through the stack from the bottom up looking for an
* option that does not match the current best value. When it finds one it
- * checks to see if it is more or less desireable and returns true or false
+ * checks to see if it is more or less desirable and returns true or false
* as appropriate.
*
* Notice that this means that the order options are pushed onto the stack
@@ -2220,7 +2220,7 @@ cp_one_file(struct display *dp, const char *filename, const char *destname)
strcpy(dp->best, dp->curr);
dp->best_size = dp->write_size;
- if (dp->nsp > 0) /* interating over lists */
+ if (dp->nsp > 0) /* iterating over lists */
{
char *tmpname, tmpbuf[(sizeof dp->namebuf) + 4];
assert(dp->curr[0] == ' ' && dp->tsp > 0);
@@ -2302,7 +2302,7 @@ cppng(struct display *dp, const char *file, const char *gv dest)
}
int
-main(const int argc, const char * const * const argv)
+main(int argc, char **argv)
{
/* For each file on the command line test it with a range of transforms */
int option_end;
@@ -2379,7 +2379,7 @@ main(const int argc, const char * const * const argv)
/* Here on any return, including failures, except user/internal issues
*/
{
- const int pass = (d.options & STRICT) ?
+ int pass = (d.options & STRICT) ?
RESULT_STRICT(d.results) : RESULT_RELAXED(d.results);
if (!pass)
diff --git a/libpng/contrib/tools/pngfix.c b/libpng/contrib/tools/pngfix.c
index 69ffc170..2fa5d13e 100644
--- a/libpng/contrib/tools/pngfix.c
+++ b/libpng/contrib/tools/pngfix.c
@@ -772,7 +772,7 @@ skip_chunk_type(const struct global *global, png_uint_32 type)
return 0;
/* Chunks that specify gamma encoding which should therefore only be
- * removed the the user insists:
+ * removed if the user insists:
*/
case png_gAMA: case png_sRGB:
if (global->skip >= SKIP_ALL)
@@ -2363,7 +2363,7 @@ zlib_advance(struct zlib *zlib, png_uint_32 nbytes)
flush = Z_NO_FLUSH;
out_bytes = 0;
- /* NOTE: expression 3 is only evaluted on 'continue', because of the
+ /* NOTE: expression 3 is only evaluated on 'continue', because of the
* 'break' at the end of this loop below.
*/
for (;endrc == ZLIB_OK;
@@ -2514,7 +2514,7 @@ zlib_run(struct zlib *zlib)
*/
for (;;)
{
- const unsigned int count = list->count;
+ unsigned int count = list->count;
unsigned int i;
for (i = 0; i<count; ++i)
@@ -2664,7 +2664,7 @@ zlib_check(struct file *file, png_uint_32 offset)
* this case, so do the optimization anyway.
*/
if (zlib.cksum)
- chunk_message(zlib.chunk, "zlib checkum");
+ chunk_message(zlib.chunk, "zlib checksum");
break;
@@ -2791,7 +2791,7 @@ process_chunk(struct file *file, png_uint_32 file_crc, png_uint_32 next_length,
* to read_chunk.
*/
{
- const png_uint_32 type = file->type;
+ png_uint_32 type = file->type;
if (file->global->verbose > 1)
{
@@ -3152,7 +3152,7 @@ read_chunk(struct file *file)
}
}
- /* Control gets to here if the the stream seems invalid or damaged in some
+ /* Control gets to here if the stream seems invalid or damaged in some
* way. Either there was a problem reading all the expected data (this
* chunk's data, its CRC and the length and type of the next chunk) or the
* next chunk length/type are invalid. Notice that the cases that end up
@@ -3678,7 +3678,7 @@ usage(const char *prog)
size_t i;
static const char *usage_string[] = {
" Tests, optimizes and optionally fixes the zlib header in PNG files.",
-" Optionally, when fixing, strips ancilliary chunks from the file.",
+" Optionally, when fixing, strips ancillary chunks from the file.",
0,
"OPTIONS",
" OPERATION",
@@ -3710,7 +3710,7 @@ usage(const char *prog)
" practice most programs will ignore it.",
" bKGD [transform]: This is used by libpng transforms."
" --max=<number>:",
-" Use IDAT chunks sized <number>. If no number is given the the IDAT",
+" Use IDAT chunks sized <number>. If no number is given the IDAT",
" chunks will be the maximum size permitted; 2^31-1 bytes. If the option",
" is omitted the original chunk sizes will not be changed. When the",
" option is given --strip=unsafe is set automatically. This may be",
diff --git a/libpng/contrib/visupng/PngFile.c b/libpng/contrib/visupng/PngFile.c
index d46318f4..cf943f32 100644
--- a/libpng/contrib/visupng/PngFile.c
+++ b/libpng/contrib/visupng/PngFile.c
@@ -410,15 +410,14 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
#ifndef PNG_STDIO_SUPPORTED
static void
-png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
+png_read_data(png_structp png_ptr, png_bytep data, size_t length)
{
- png_size_t check;
+ size_t check;
- /* fread() returns 0 on error, so it is OK to store this in a png_size_t
+ /* fread() returns 0 on error, so it is OK to store this in a size_t
* instead of an int, which is what fread() actually returns.
*/
- check = (png_size_t)fread(data, (png_size_t)1, length,
- (FILE *)png_ptr->io_ptr);
+ check = fread(data, 1, length, (FILE *)png_ptr->io_ptr);
if (check != length)
{
@@ -427,7 +426,7 @@ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
static void
-png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
+png_write_data(png_structp png_ptr, png_bytep data, size_t length)
{
png_uint_32 check;
diff --git a/libpng/contrib/visupng/PngFile.h b/libpng/contrib/visupng/PngFile.h
index 474426c2..1b7b9be3 100644
--- a/libpng/contrib/visupng/PngFile.h
+++ b/libpng/contrib/visupng/PngFile.h
@@ -23,8 +23,8 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
int iWidth, int iHeight, png_color BkgColor);
#ifndef PNG_STDIO_SUPPORTED
-static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
-static void png_write_data(png_structp png_ptr, png_bytep data, png_size_t length);
+static void png_read_data(png_structp png_ptr, png_bytep data, size_t length);
+static void png_write_data(png_structp png_ptr, png_bytep data, size_t length);
static void png_flush(png_structp png_ptr);
#endif
diff --git a/libpng/contrib/visupng/VisualPng.c b/libpng/contrib/visupng/VisualPng.c
index 20e1625f..6baa3b66 100644
--- a/libpng/contrib/visupng/VisualPng.c
+++ b/libpng/contrib/visupng/VisualPng.c
@@ -716,7 +716,7 @@ BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
png_color bkgGray = {127, 127, 127};
png_color bkgWhite = {255, 255, 255};
- /* allocate memory for the Device Independant bitmap */
+ /* allocate memory for the Device Independent bitmap */
wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2;