[libpng15] Merged pngvalid and pngtest from libpng-1.5; made compressed chunks

after IDAT work with the progressive read code (this is a minor and
somewhat ugly fix-up; the proper fix is in 1.6).
This commit is contained in:
John Bowler 2013-12-29 10:44:25 -06:00 committed by Glenn Randers-Pehrson
parent c5568595ff
commit 71fcb39efc
7 changed files with 175 additions and 71 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.5.18beta03 - December 27, 2013
Libpng 1.5.18beta03 - December 29, 2013
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
@ -39,8 +39,8 @@ Version 1.5.18beta02 [December 26, 2013]
Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69
in the tar distributions.
Version 1.5.18beta03 [December 27, 2013]
Fixed 'unused' warnings and mergeed with libpng16 pngvalid.
Version 1.5.18beta03 [December 29, 2013]
Fixed 'unused' warnings and merged with libpng16 pngvalid.
Various warnings revealed by configurations added to the tested
configurations in libpng 1.6 need corresponding fixes in libpng 1.5.
This takes the libpng 1.6 pngvalid.c and adds it back to libpng 1.5,
@ -48,6 +48,9 @@ Version 1.5.18beta03 [December 27, 2013]
work; possibly because of failures to reset or initialize the deflate
stream correctly in write-only cases.
Merged libpng-1.7 changes and created a single pngvalid.c
Merged pngvalid and pngtest from libpng-1.5; made compressed chunks
after IDAT work with the progressive read code (this is a minor and
somewhat ugly fix-up; the proper fix is in 1.6).
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -4163,8 +4163,8 @@ Version 1.5.18beta02 [December 26, 2013]
Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69
in the tar distributions.
Version 1.5.18beta03 [December 27, 2013]
Fixed 'unused' warnings and mergeed with libpng16 pngvalid.
Version 1.5.18beta03 [December 29, 2013]
Fixed 'unused' warnings and merged with libpng16 pngvalid.
Various warnings revealed by configurations added to the tested
configurations in libpng 1.6 need corresponding fixes in libpng 1.5.
This takes the libpng 1.6 pngvalid.c and adds it back to libpng 1.5,
@ -4172,6 +4172,9 @@ Version 1.5.18beta03 [December 27, 2013]
work; possibly because of failures to reset or initialize the deflate
stream correctly in write-only cases.
Merged libpng-1.7 changes and created a single pngvalid.c
Merged pngvalid and pngtest from libpng-1.5; made compressed chunks
after IDAT work with the progressive read code (this is a minor and
somewhat ugly fix-up; the proper fix is in 1.6).
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -1,8 +1,8 @@
/* pngvalid.c - validate libpng by constructing then reading png files.
*
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
* Copyright (c) 2012 Glenn Randers-Pehrson
* Last changed in libpng 1.5.18 [%RDATE%]
* Copyright (c) 2013 Glenn Randers-Pehrson
* Written by John Cunningham Bowler
*
* This code is released under the libpng license.
@ -49,6 +49,15 @@
# include <zlib.h> /* For crc32 */
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER < 10601
# define SKIP 0
#else
# define SKIP 77
#endif
/* pngvalid requires write support and one of the fixed or floating point APIs.
*/
#if defined(PNG_WRITE_SUPPORTED) &&\
@ -3401,10 +3410,28 @@ transform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX],
#define DEPTH(bd) ((png_byte)(1U << (bd)))
/* This is just a helper for compiling on minimal systems with no write
* interlacing support.
* interlacing support. If there is no write interlacing we can't generate test
* cases with interlace:
*/
#ifndef PNG_WRITE_INTERLACING_SUPPORTED
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
# define INTERLACE_LAST PNG_INTERLACE_LAST
# define check_interlace_type(type) ((void)(type))
#else
# define INTERLACE_LAST (PNG_INTERLACE_NONE+1)
# define png_set_interlace_handling(a) (1)
static void
check_interlace_type(int PNG_CONST interlace_type)
{
if (interlace_type != PNG_INTERLACE_NONE)
{
/* This is an internal error - --interlace tests should be skipped, not
* attempted.
*/
fprintf(stderr, "pngvalid: no interlace support\n");
exit(99);
}
}
#endif
/* Make a standardized image given a an image colour type, bit depth and
@ -3420,6 +3447,8 @@ make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
{
context(ps, fault);
check_interlace_type(interlace_type);
Try
{
png_infop pi;
@ -3560,12 +3589,8 @@ make_transform_images(png_store *ps)
{
int interlace_type;
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < PNG_INTERLACE_LAST; ++interlace_type)
# else
interlace_type = PNG_INTERLACE_NONE;
# endif
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < INTERLACE_LAST; ++interlace_type)
{
char name[FILE_NAME_SIZE];
@ -3655,6 +3680,12 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
{
context(ps, fault);
/* At present libpng does not support the write of an interlaced image unless
* PNG_WRITE_INTERLACING_SUPPORTED, even with do_interlace so the code here
* does the pixel interlace itself, so:
*/
check_interlace_type(interlace_type);
Try
{
png_infop pi;
@ -3864,13 +3895,6 @@ make_size(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, int bdlo,
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,
width, height, 0);
# endif
# if defined(PNG_WRITE_INTERLACING_SUPPORTED) || PNG_LIBPNG_VER > 10518
/* This fails in 1.5.8 with a zlib stream error writing the rows of
* the internally generated interlaced images, but only when the
* read code is disabled: to be investigated. Probably an erroneous
* #define out of the zlib deflate reset.
*/
make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,
width, height, 1);
# endif
@ -3964,6 +3988,8 @@ make_error(png_store* volatile psIn, png_byte PNG_CONST colour_type,
context(ps, fault);
check_interlace_type(interlace_type);
Try
{
png_structp pp;
@ -4066,12 +4092,8 @@ make_errors(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
{
int interlace_type;
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < PNG_INTERLACE_LAST; ++interlace_type)
# else
interlace_type = PNG_INTERLACE_NONE;
# endif
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < INTERLACE_LAST; ++interlace_type)
{
unsigned int test;
char name[FILE_NAME_SIZE];
@ -4269,6 +4291,7 @@ standard_display_init(standard_display *dp, png_store* ps, png_uint_32 id,
dp->red_sBIT = dp->blue_sBIT = dp->green_sBIT = dp->alpha_sBIT =
dp->bit_depth;
dp->interlace_type = INTERLACE_FROM_ID(id);
check_interlace_type(dp->interlace_type);
dp->id = id;
/* All the rest are filled in after the read_info: */
dp->w = 0;
@ -4887,7 +4910,7 @@ standard_text_validate(standard_display *dp, png_const_structp pp,
{
standard_check_text(pp, tp, "image name", dp->ps->current->name);
/* This exists because prior to 1.6 the progressive reader left the
/* This exists because prior to 1.5.18 the progressive reader left the
* png_struct z_stream unreset at the end of the image, so subsequent
* attempts to use it simply returns Z_STREAM_END.
*/
@ -4996,7 +5019,7 @@ standard_end(png_structp ppIn, png_infop pi)
* interlaced images.
*/
standard_text_validate(dp, pp, pi,
PNG_LIBPNG_VER >= 10600/*check_end: see comments above*/);
PNG_LIBPNG_VER >= 10518/*check_end: see comments above*/);
standard_image_validate(dp, pp, 0, -1);
}
@ -5098,7 +5121,7 @@ test_standard(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
int interlace_type;
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < PNG_INTERLACE_LAST; ++interlace_type)
interlace_type < INTERLACE_LAST; ++interlace_type)
{
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
interlace_type, 0, 0, 0), 0/*do_interlace*/, pm->use_update_info);
@ -5173,6 +5196,7 @@ test_size(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
if (fail(pm))
return 0;
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/,
pm->use_update_info);
@ -5186,6 +5210,7 @@ test_size(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
if (fail(pm))
return 0;
# endif
/* Now validate the interlaced read side - do_interlace true,
* in the progressive case this does actually make a difference
@ -5198,12 +5223,14 @@ test_size(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
if (fail(pm))
return 0;
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
# endif
}
}
@ -9251,6 +9278,28 @@ static void gamma_composition_test(png_modifier *pm,
r = random_32();
background.blue = (png_uint_16)r;
background.gray = (png_uint_16)(r >> 16);
/* In earlier libpng versions, those where DIGITIZE is set, any background
* gamma correction in the expand16 case was done using 8-bit gamma
* correction tables, resulting in larger errors. To cope with those
* cases use a 16-bit background value which will handle this gamma
* correction.
*/
# if DIGITIZE
if (expand_16 && (do_background == PNG_BACKGROUND_GAMMA_UNIQUE ||
do_background == PNG_BACKGROUND_GAMMA_FILE) &&
fabs(bg*screen_gamma-1) > PNG_GAMMA_THRESHOLD)
{
/* The background values will be looked up in an 8-bit table to do
* the gamma correction, so only select values which are an exact
* match for the 8-bit table entries:
*/
background.red = (png_uint_16)((background.red >> 8) * 257);
background.green = (png_uint_16)((background.green >> 8) * 257);
background.blue = (png_uint_16)((background.blue >> 8) * 257);
background.gray = (png_uint_16)((background.gray >> 8) * 257);
}
# endif
}
else /* 8 bit colors */
@ -10222,7 +10271,14 @@ int main(int argc, char **argv)
++pm.use_update_info; /* Can call multiple times */
else if (strcmp(*argv, "--interlace") == 0)
pm.interlace_type = PNG_INTERLACE_ADAM7;
{
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
pm.interlace_type = PNG_INTERLACE_ADAM7;
# else
fprintf(stderr, "pngvalid: no write interlace support\n");
return SKIP;
# endif
}
else if (strcmp(*argv, "--use-input-precision") == 0)
pm.use_input_precision = 1U;
@ -10521,11 +10577,6 @@ int main(void)
fprintf(stderr,
"pngvalid: no low level write support in libpng, all tests skipped\n");
/* So the test is skipped: */
#if PNG_LIBPNG_VER < 10601
/* Test harness support was only added in libpng 1.6.1: */
return 0;
#else
return 77;
#endif
return SKIP;
}
#endif

View File

@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode
*
* Last changed in libpng 1.5.11 [June 14, 2012]
* Last changed in libpng 1.5.18 [(PENDING RELEASE)]
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -897,6 +897,12 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
*/
ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH);
/* Hack, added in 1.5.18: the progressive reader does not reset
* png_ptr->zstream, so any attempt to use it after the last IDAT fails
* (silently). This allows the read code to do the reset when required.
*/
png_ptr->flags |= PNG_FLAG_ZSTREAM_PROGRESSIVE;
/* Check for any failure before proceeding. */
if (ret != Z_OK && ret != Z_STREAM_END)
{

View File

@ -6,7 +6,7 @@
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* Last changed in libpng 1.5.17 [(PENDING RELEASE)]
* Last changed in libpng 1.5.18 [(PENDING RELEASE)]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -572,7 +572,7 @@
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000
#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000
#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000
/* 0x200000 unused */
#define PNG_FLAG_ZSTREAM_PROGRESSIVE 0x200000
/* 0x400000 unused */
#define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000 /* Added to libpng-1.4.0 */
#define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000 /* 5 lines added */

View File

@ -282,6 +282,17 @@ png_inflate(png_structp png_ptr, png_bytep data, png_size_t size,
{
png_size_t count = 0;
/* HACK: added in libpng 1.5.18: the progressive reader always leaves
* png_ptr->zstream in a non-reset state. This causes a reset if it needs to
* be used again. This only copes with that one specific error; see libpng
* 1.6 for a better solution.
*/
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_PROGRESSIVE) != 0)
{
(void)inflateReset(&png_ptr->zstream);
png_ptr->flags &= ~PNG_FLAG_ZSTREAM_PROGRESSIVE;
}
/* zlib can't necessarily handle more than 65535 bytes at once (i.e. it can't
* even necessarily handle 65536 bytes) because the type uInt is "16 bits or
* more". Consequently it is necessary to chunk the input to zlib. This

View File

@ -43,6 +43,14 @@
#include "png.h"
/* Known chunks that exist in pngtest.png must be supported or pngtest will fail
* simply as a result of re-ordering them. This may be fixed in 1.7
*
* pngtest allocates a single row buffer for each row and overwrites it,
* therefore if the write side doesn't support the writing of interlaced images
* nothing can be done for an interlaced image (and the code below will fail
* horribly trying to write extra data after writing garbage).
*/
#if defined PNG_READ_SUPPORTED && /* else nothing can be done */\
defined PNG_READ_bKGD_SUPPORTED &&\
defined PNG_READ_cHRM_SUPPORTED &&\
@ -55,9 +63,15 @@
defined PNG_READ_sRGB_SUPPORTED &&\
defined PNG_READ_tEXt_SUPPORTED &&\
defined PNG_READ_tIME_SUPPORTED &&\
defined PNG_READ_zTXt_SUPPORTED
defined PNG_READ_zTXt_SUPPORTED &&\
defined PNG_WRITE_INTERLACING_SUPPORTED
#ifdef PNG_ZLIB_HEADER
# include PNG_ZLIB_HEADER /* defined by pnglibconf.h from 1.7 */
#else
# include "zlib.h"
#endif
#include "zlib.h"
/* Copied from pngpriv.h but only used in error messages below. */
#ifndef PNG_ZBUF_SIZE
# define PNG_ZBUF_SIZE 8192
@ -113,10 +127,6 @@ static int unsupported_chunks = 0; /* chunk unsupported by libpng in input */
static int error_count = 0; /* count calls to png_error */
static int warning_count = 0; /* count calls to png_warning */
#ifdef __TURBOC__
#include <mem.h>
#endif
/* 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
@ -570,7 +580,8 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
/* We must free the list element too, but first kill
the memory that is to be freed. */
memset(ptr, 0x55, pinfo->size);
png_free_default(png_ptr, pinfo);
if (pinfo)
free(pinfo);
pinfo = NULL;
break;
}
@ -589,7 +600,8 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
if (verbose)
printf("Freeing %p\n", ptr);
png_free_default(png_ptr, ptr);
if (ptr)
free(ptr);
ptr = NULL;
}
#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
@ -720,18 +732,18 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
static void
write_sTER_chunk(png_structp write_ptr)
{
png_byte png_sTER[5] = {115, 84, 69, 82, '\0'};
png_byte sTER[5] = {115, 84, 69, 82, '\0'};
if (verbose)
fprintf(STDERR, "\n stereo mode = %d\n", user_chunk_data.sTER_mode);
png_write_chunk(write_ptr, png_sTER, &user_chunk_data.sTER_mode, 1);
png_write_chunk(write_ptr, sTER, &user_chunk_data.sTER_mode, 1);
}
static void
write_vpAg_chunk(png_structp write_ptr)
{
png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'};
png_byte vpAg[5] = {118, 112, 65, 103, '\0'};
png_byte vpag_chunk_data[9];
@ -744,7 +756,7 @@ write_vpAg_chunk(png_structp write_ptr)
png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width);
png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height);
vpag_chunk_data[8] = user_chunk_data.vpAg_units;
png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
png_write_chunk(write_ptr, vpAg, vpag_chunk_data, 9);
}
static void
@ -825,6 +837,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_structp write_ptr;
png_infop write_info_ptr;
png_infop write_end_info_ptr;
int interlace_preserved = 1;
#else
png_structp write_ptr = NULL;
png_infop write_info_ptr = NULL;
@ -833,7 +846,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_bytep row_buf;
png_uint_32 y;
png_uint_32 width, height;
int num_pass, pass;
int num_pass = 1, pass;
int bit_depth, color_type;
row_buf = NULL;
@ -1039,10 +1052,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
&color_type, &interlace_type, &compression_type, &filter_type))
{
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
color_type, interlace_type, compression_type, filter_type);
#else
color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
#ifndef PNG_READ_INTERLACING_SUPPORTED
/* num_pass will not be set below, set it here if the image is
* interlaced: what happens is that write interlacing is *not* turned
* on an the partial interlaced rows are written directly.
*/
switch (interlace_type)
{
case PNG_INTERLACE_NONE:
num_pass = 1;
break;
case PNG_INTERLACE_ADAM7:
num_pass = 7;
break;
default:
png_error(read_ptr, "invalid interlace type");
/*NOT REACHED*/
}
#endif
}
}
@ -1186,7 +1215,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
#endif
#ifdef PNG_sCAL_SUPPORTED
#ifdef PNG_FLOATING_POINT_SUPPORTED
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
{
int unit;
double scal_width, scal_height;
@ -1334,14 +1364,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif /* SINGLE_ROWBUF_ALLOC */
pngtest_debug("Writing row data");
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
#ifdef PNG_READ_INTERLACING_SUPPORTED
num_pass = png_set_interlace_handling(read_ptr);
# ifdef PNG_WRITE_SUPPORTED
png_set_interlace_handling(write_ptr);
# endif
#else
num_pass = 1;
if (png_set_interlace_handling(write_ptr) != num_pass)
png_error(write_ptr, "png_set_interlace_handling: inconsistent num_pass");
#endif
#ifdef PNGTEST_TIMING
@ -1387,11 +1413,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
}
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
#endif
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
# ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
# endif
# ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
# endif
#endif
pngtest_debug("Reading and writing end_info data");
@ -1570,6 +1598,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */
if (interlace_preserved) /* else the files will be changed */
{
for (;;)
{
@ -1955,7 +1984,8 @@ main(void)
{
fprintf(STDERR,
" test ignored because libpng was not built with read support\n");
return 0;
/* And skip this test */
return PNG_LIBPNG_VER < 10600 ? 0 : 77;
}
#endif