mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng17] Fixed test programs for interlace options. Made pngvalid.c and
pngtest.c work correctly when READ_INTERLACING and/or WRITE_INTERLACING are switched off.
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
eb2af04bd3
commit
114fa16ab3
55
pngtest.c
55
pngtest.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.9 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
@@ -45,6 +45,11 @@
|
||||
|
||||
/* 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 &&\
|
||||
@@ -58,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 PNG_ZLIB_HEADER /* defined by pnglibconf.h */
|
||||
/* Copied from pngpriv.h but only used in error messages below. */
|
||||
#ifndef PNG_ZBUF_SIZE
|
||||
# define PNG_ZBUF_SIZE 8192
|
||||
@@ -826,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;
|
||||
@@ -834,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;
|
||||
@@ -1040,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
|
||||
}
|
||||
}
|
||||
@@ -1336,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
|
||||
@@ -1575,6 +1599,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 (;;)
|
||||
{
|
||||
@@ -1961,7 +1986,7 @@ main(void)
|
||||
fprintf(STDERR,
|
||||
" test ignored because libpng was not built with read support\n");
|
||||
/* And skip this test */
|
||||
return 77;
|
||||
return PNG_LIBPNG_VER < 10600 ? 0 : 77;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user