[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

@@ -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