mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Test backport
Tests backported from the multi-version compatible ones in libpng 1.7 Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
177
pngtest.c
177
pngtest.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* Last changed in libpng 1.6.19 [November 12, 2015]
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2015 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.)
|
||||
@@ -60,12 +60,12 @@
|
||||
defined PNG_READ_pHYs_SUPPORTED &&\
|
||||
defined PNG_READ_sBIT_SUPPORTED &&\
|
||||
defined PNG_READ_sCAL_SUPPORTED &&\
|
||||
defined PNG_READ_sPLT_SUPPORTED &&\
|
||||
defined PNG_READ_sRGB_SUPPORTED &&\
|
||||
defined PNG_READ_sPLT_SUPPORTED &&\
|
||||
defined PNG_READ_tEXt_SUPPORTED &&\
|
||||
defined PNG_READ_tIME_SUPPORTED &&\
|
||||
defined PNG_READ_zTXt_SUPPORTED &&\
|
||||
defined PNG_WRITE_INTERLACING_SUPPORTED
|
||||
(defined PNG_WRITE_INTERLACING_SUPPORTED || PNG_LIBPNG_VER >= 10700)
|
||||
|
||||
#ifdef PNG_ZLIB_HEADER
|
||||
# include PNG_ZLIB_HEADER /* defined by pnglibconf.h from 1.7 */
|
||||
@@ -102,6 +102,10 @@ typedef FILE * png_FILE_p;
|
||||
# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
|
||||
#endif
|
||||
|
||||
#ifndef PNG_UNUSED
|
||||
# define PNG_UNUSED(param) (void)param;
|
||||
#endif
|
||||
|
||||
/* Turn on CPU timing
|
||||
#define PNGTEST_TIMING
|
||||
*/
|
||||
@@ -119,6 +123,22 @@ static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
#define PNG_tIME_STRING_LENGTH 29
|
||||
static int tIME_chunk_present = 0;
|
||||
static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
|
||||
|
||||
#if PNG_LIBPNG_VER < 10619
|
||||
#define png_convert_to_rfc1123_buffer(ts, t) tIME_to_str(read_ptr, ts, t)
|
||||
|
||||
static int
|
||||
tIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t)
|
||||
{
|
||||
png_const_charp str = png_convert_to_rfc1123(png_ptr, t);
|
||||
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
strcpy(ts, str);
|
||||
return 1;
|
||||
}
|
||||
#endif /* older libpng */
|
||||
#endif
|
||||
|
||||
static int verbose = 0;
|
||||
@@ -186,16 +206,14 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
||||
|
||||
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
/* Example of using user transform callback (we don't transform anything,
|
||||
* but merely examine the row filters. We set this to 256 rather than
|
||||
* 5 in case illegal filter values are present.)
|
||||
/* Example of using a user transform callback (doesn't do anything at present).
|
||||
*/
|
||||
static png_uint_32 filters_used[256];
|
||||
static void PNGCBAPI
|
||||
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
read_user_callback(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
{
|
||||
if (png_ptr != NULL && row_info != NULL)
|
||||
++filters_used[*(data - 1)];
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(row_info)
|
||||
PNG_UNUSED(data)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -793,7 +811,7 @@ write_chunks(png_structp write_ptr, int location)
|
||||
*/
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
static void
|
||||
pngtest_check_text_support(png_const_structp png_ptr, png_textp text_ptr,
|
||||
pngtest_check_text_support(png_structp png_ptr, png_textp text_ptr,
|
||||
int num_text)
|
||||
{
|
||||
while (num_text > 0)
|
||||
@@ -806,6 +824,8 @@ pngtest_check_text_support(png_const_structp png_ptr, png_textp text_ptr,
|
||||
case PNG_TEXT_COMPRESSION_zTXt:
|
||||
# ifndef PNG_WRITE_zTXt_SUPPORTED
|
||||
++unsupported_chunks;
|
||||
/* In libpng 1.7 this now does an app-error, so stop it: */
|
||||
text_ptr[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
# endif
|
||||
break;
|
||||
|
||||
@@ -813,6 +833,7 @@ pngtest_check_text_support(png_const_structp png_ptr, png_textp text_ptr,
|
||||
case PNG_ITXT_COMPRESSION_zTXt:
|
||||
# ifndef PNG_WRITE_iTXt_SUPPORTED
|
||||
++unsupported_chunks;
|
||||
text_ptr[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
# endif
|
||||
break;
|
||||
|
||||
@@ -839,16 +860,19 @@ 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;
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
int interlace_preserved = 1;
|
||||
#else
|
||||
#endif /* WRITE_FILTER */
|
||||
#else /* !WRITE */
|
||||
png_structp write_ptr = NULL;
|
||||
png_infop write_info_ptr = NULL;
|
||||
png_infop write_end_info_ptr = NULL;
|
||||
#endif
|
||||
#endif /* !WRITE */
|
||||
png_bytep row_buf;
|
||||
png_uint_32 y;
|
||||
png_uint_32 width, height;
|
||||
int num_pass = 1, pass;
|
||||
volatile int num_passes;
|
||||
int pass;
|
||||
int bit_depth, color_type;
|
||||
|
||||
row_buf = NULL;
|
||||
@@ -1001,14 +1025,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i<256; i++)
|
||||
filters_used[i] = 0;
|
||||
|
||||
png_set_read_user_transform_fn(read_ptr, count_filters);
|
||||
}
|
||||
png_set_read_user_transform_fn(read_ptr, read_user_callback);
|
||||
#endif
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
zero_samples = 0;
|
||||
@@ -1055,29 +1072,28 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
|
||||
color_type, interlace_type, 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 and the partial interlaced rows are written directly.
|
||||
/* num_passes may not be available below if interlace support is not
|
||||
* provided by libpng for both read and write.
|
||||
*/
|
||||
switch (interlace_type)
|
||||
{
|
||||
case PNG_INTERLACE_NONE:
|
||||
num_pass = 1;
|
||||
num_passes = 1;
|
||||
break;
|
||||
|
||||
case PNG_INTERLACE_ADAM7:
|
||||
num_pass = 7;
|
||||
break;
|
||||
num_passes = 7;
|
||||
break;
|
||||
|
||||
default:
|
||||
png_error(read_ptr, "invalid interlace type");
|
||||
/*NOT REACHED*/
|
||||
png_error(read_ptr, "invalid interlace type");
|
||||
/*NOT REACHED*/
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
png_error(read_ptr, "png_get_IHDR failed");
|
||||
}
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
{
|
||||
@@ -1092,7 +1108,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_gAMA_SUPPORTED
|
||||
{
|
||||
png_fixed_point gamma;
|
||||
@@ -1126,7 +1141,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif
|
||||
#endif /* Floating point */
|
||||
#endif /* Fixed point */
|
||||
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
{
|
||||
png_charp name;
|
||||
@@ -1142,7 +1156,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sRGB_SUPPORTED
|
||||
{
|
||||
int intent;
|
||||
@@ -1151,7 +1164,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_sRGB(write_ptr, write_info_ptr, intent);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
png_colorp palette;
|
||||
int num_palette;
|
||||
@@ -1159,7 +1171,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette) != 0)
|
||||
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
|
||||
}
|
||||
|
||||
#ifdef PNG_bKGD_SUPPORTED
|
||||
{
|
||||
png_color_16p background;
|
||||
@@ -1170,7 +1181,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
{
|
||||
png_uint_16p hist;
|
||||
@@ -1179,7 +1189,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_hIST(write_ptr, write_info_ptr, hist);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
{
|
||||
png_int_32 offset_x, offset_y;
|
||||
@@ -1192,7 +1201,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_pCAL_SUPPORTED
|
||||
{
|
||||
png_charp purpose, units;
|
||||
@@ -1208,7 +1216,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
{
|
||||
png_uint_32 res_x, res_y;
|
||||
@@ -1219,7 +1226,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sBIT_SUPPORTED
|
||||
{
|
||||
png_color_8p sig_bit;
|
||||
@@ -1228,7 +1234,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
|
||||
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
|
||||
@@ -1255,9 +1260,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
scal_height);
|
||||
}
|
||||
}
|
||||
#endif /* FIXED_POINT */
|
||||
#endif /* FLOATING_POINT */
|
||||
#endif /* sCAL */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
{
|
||||
@@ -1269,7 +1274,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_sPLT(write_ptr, write_info_ptr, entries, num_entries);
|
||||
}
|
||||
}
|
||||
#endif /* sPLT */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
{
|
||||
@@ -1297,8 +1302,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
|
||||
}
|
||||
}
|
||||
#endif /* TEXT */
|
||||
|
||||
#endif
|
||||
#ifdef PNG_tIME_SUPPORTED
|
||||
{
|
||||
png_timep mod_time;
|
||||
@@ -1320,8 +1324,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif /* TIME_RFC1123 */
|
||||
}
|
||||
}
|
||||
#endif /* tIME */
|
||||
|
||||
#endif
|
||||
#ifdef PNG_tRNS_SUPPORTED
|
||||
{
|
||||
png_bytep trans_alpha;
|
||||
@@ -1343,8 +1346,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
trans_color);
|
||||
}
|
||||
}
|
||||
#endif /* tRNS */
|
||||
|
||||
#endif
|
||||
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
{
|
||||
png_unknown_chunkp unknowns;
|
||||
@@ -1395,21 +1397,49 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif /* SINGLE_ROWBUF_ALLOC */
|
||||
pngtest_debug("Writing row data");
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
num_pass = png_set_interlace_handling(read_ptr);
|
||||
if (png_set_interlace_handling(write_ptr) != num_pass)
|
||||
png_error(write_ptr, "png_set_interlace_handling: inconsistent num_pass");
|
||||
#endif
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED) &&\
|
||||
defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
/* Both must be defined for libpng to be able to handle the interlace,
|
||||
* otherwise it gets handled below by simply reading and writing the passes
|
||||
* directly.
|
||||
*/
|
||||
if (png_set_interlace_handling(read_ptr) != num_passes)
|
||||
png_error(write_ptr,
|
||||
"png_set_interlace_handling(read): wrong pass count ");
|
||||
if (png_set_interlace_handling(write_ptr) != num_passes)
|
||||
png_error(write_ptr,
|
||||
"png_set_interlace_handling(write): wrong pass count ");
|
||||
#else /* png_set_interlace_handling not called on either read or write */
|
||||
# define calc_pass_height
|
||||
#endif /* not using libpng interlace handling */
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
t_stop = (float)clock();
|
||||
t_misc += (t_stop - t_start);
|
||||
t_start = t_stop;
|
||||
#endif
|
||||
for (pass = 0; pass < num_pass; pass++)
|
||||
for (pass = 0; pass < num_passes; pass++)
|
||||
{
|
||||
# ifdef calc_pass_height
|
||||
png_uint_32 pass_height;
|
||||
|
||||
if (num_passes == 7) /* interlaced */
|
||||
{
|
||||
if (PNG_PASS_COLS(width, pass) > 0)
|
||||
pass_height = PNG_PASS_ROWS(height, pass);
|
||||
|
||||
else
|
||||
pass_height = 0;
|
||||
}
|
||||
|
||||
else /* not interlaced */
|
||||
pass_height = height;
|
||||
# else
|
||||
# define pass_height height
|
||||
# endif
|
||||
|
||||
pngtest_debug1("Writing row data for pass %d", pass);
|
||||
for (y = 0; y < height; y++)
|
||||
for (y = 0; y < pass_height; y++)
|
||||
{
|
||||
#ifndef SINGLE_ROWBUF_ALLOC
|
||||
pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
|
||||
@@ -1599,7 +1629,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
/* If there we no write support nothing was written! */
|
||||
/* If there is no write support nothing was written! */
|
||||
else if (unsupported_chunks > 0)
|
||||
{
|
||||
fprintf(STDERR, "\n %s: unsupported chunks (%d)%s",
|
||||
@@ -1630,7 +1660,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */
|
||||
#if defined (PNG_WRITE_SUPPORTED) /* else nothing was written */ &&\
|
||||
defined (PNG_WRITE_FILTER_SUPPORTED)
|
||||
if (interlace_preserved != 0) /* else the files will be changed */
|
||||
{
|
||||
for (;;)
|
||||
@@ -1707,7 +1738,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* WRITE */
|
||||
#endif /* WRITE && WRITE_FILTER */
|
||||
|
||||
FCLOSE(fpin);
|
||||
FCLOSE(fpout);
|
||||
@@ -1846,21 +1877,12 @@ main(int argc, char *argv[])
|
||||
kerror = test_one_file(argv[i], outname);
|
||||
if (kerror == 0)
|
||||
{
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
int k;
|
||||
#endif
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",
|
||||
(unsigned long)zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
for (k = 0; k<256; k++)
|
||||
if (filters_used[k] != 0)
|
||||
fprintf(STDERR, " Filter %d was used %lu times\n",
|
||||
k, (unsigned long)filters_used[k]);
|
||||
#endif
|
||||
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
||||
if (tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n", tIME_string);
|
||||
@@ -1937,21 +1959,12 @@ main(int argc, char *argv[])
|
||||
{
|
||||
if (verbose == 1 || i == 2)
|
||||
{
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
int k;
|
||||
#endif
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",
|
||||
(unsigned long)zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
for (k = 0; k<256; k++)
|
||||
if (filters_used[k] != 0)
|
||||
fprintf(STDERR, " Filter %d was used %lu times\n",
|
||||
k, (unsigned long)filters_used[k]);
|
||||
#endif
|
||||
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
||||
if (tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n", tIME_string);
|
||||
|
||||
Reference in New Issue
Block a user