[libpng16] Fixed 'minimal' builds. Various obviously useful minimal

configurations don't build because of missing contrib/libtests test programs
and overly complex dependencies in scripts/pnglibconf.dfa. This change adds
contrib/conftest/*.dfa files that can be used in automatic build
scripts to ensure that these configurations continue to build.
This commit is contained in:
Glenn Randers-Pehrson
2013-11-22 14:58:04 -06:00
parent 113213416c
commit c912050a7b
19 changed files with 698 additions and 238 deletions

View File

@@ -517,14 +517,23 @@ static void format_default(format_list *pf, int redundant)
for (f=0; f<FORMAT_COUNT; ++f)
{
/* Eliminate redundant settings. */
/* BGR is meaningless if no color: */
if ((f & PNG_FORMAT_FLAG_COLOR) == 0 && (f & PNG_FORMAT_FLAG_BGR) != 0)
/* Eliminate redundant and unsupported settings. */
# ifdef PNG_FORMAT_BGR_SUPPORTED
/* BGR is meaningless if no color: */
if ((f & PNG_FORMAT_FLAG_COLOR) == 0 &&
(f & PNG_FORMAT_FLAG_BGR) != 0)
# else
if ((f & 0x10U/*HACK: fixed value*/) != 0)
# endif
continue;
/* AFIRST is meaningless if no alpha: */
if ((f & PNG_FORMAT_FLAG_ALPHA) == 0 &&
(f & PNG_FORMAT_FLAG_AFIRST) != 0)
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if ((f & PNG_FORMAT_FLAG_ALPHA) == 0 &&
(f & PNG_FORMAT_FLAG_AFIRST) != 0)
# else
if ((f & 0x20U/*HACK: fixed value*/) != 0)
# endif
continue;
format_set(pf, f);
@@ -786,6 +795,7 @@ gp_ga8(Pixel *p, png_const_voidp pb)
p->a = pp[1];
}
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
static void
gp_ag8(Pixel *p, png_const_voidp pb)
{
@@ -794,6 +804,7 @@ gp_ag8(Pixel *p, png_const_voidp pb)
p->r = p->g = p->b = pp[1];
p->a = pp[0];
}
#endif
static void
gp_rgb8(Pixel *p, png_const_voidp pb)
@@ -806,6 +817,7 @@ gp_rgb8(Pixel *p, png_const_voidp pb)
p->a = 255;
}
#ifdef PNG_FORMAT_BGR_SUPPORTED
static void
gp_bgr8(Pixel *p, png_const_voidp pb)
{
@@ -816,6 +828,7 @@ gp_bgr8(Pixel *p, png_const_voidp pb)
p->b = pp[0];
p->a = 255;
}
#endif
static void
gp_rgba8(Pixel *p, png_const_voidp pb)
@@ -828,6 +841,7 @@ gp_rgba8(Pixel *p, png_const_voidp pb)
p->a = pp[3];
}
#ifdef PNG_FORMAT_BGR_SUPPORTED
static void
gp_bgra8(Pixel *p, png_const_voidp pb)
{
@@ -838,7 +852,9 @@ gp_bgra8(Pixel *p, png_const_voidp pb)
p->b = pp[0];
p->a = pp[3];
}
#endif
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
static void
gp_argb8(Pixel *p, png_const_voidp pb)
{
@@ -849,7 +865,9 @@ gp_argb8(Pixel *p, png_const_voidp pb)
p->b = pp[3];
p->a = pp[0];
}
#endif
#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)
static void
gp_abgr8(Pixel *p, png_const_voidp pb)
{
@@ -860,6 +878,7 @@ gp_abgr8(Pixel *p, png_const_voidp pb)
p->b = pp[1];
p->a = pp[0];
}
#endif
static void
gp_g16(Pixel *p, png_const_voidp pb)
@@ -879,6 +898,7 @@ gp_ga16(Pixel *p, png_const_voidp pb)
p->a = pp[1];
}
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
static void
gp_ag16(Pixel *p, png_const_voidp pb)
{
@@ -887,6 +907,7 @@ gp_ag16(Pixel *p, png_const_voidp pb)
p->r = p->g = p->b = pp[1];
p->a = pp[0];
}
#endif
static void
gp_rgb16(Pixel *p, png_const_voidp pb)
@@ -899,6 +920,7 @@ gp_rgb16(Pixel *p, png_const_voidp pb)
p->a = 65535;
}
#ifdef PNG_FORMAT_BGR_SUPPORTED
static void
gp_bgr16(Pixel *p, png_const_voidp pb)
{
@@ -909,6 +931,7 @@ gp_bgr16(Pixel *p, png_const_voidp pb)
p->b = pp[0];
p->a = 65535;
}
#endif
static void
gp_rgba16(Pixel *p, png_const_voidp pb)
@@ -921,6 +944,7 @@ gp_rgba16(Pixel *p, png_const_voidp pb)
p->a = pp[3];
}
#ifdef PNG_FORMAT_BGR_SUPPORTED
static void
gp_bgra16(Pixel *p, png_const_voidp pb)
{
@@ -931,7 +955,9 @@ gp_bgra16(Pixel *p, png_const_voidp pb)
p->b = pp[0];
p->a = pp[3];
}
#endif
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
static void
gp_argb16(Pixel *p, png_const_voidp pb)
{
@@ -942,7 +968,9 @@ gp_argb16(Pixel *p, png_const_voidp pb)
p->b = pp[3];
p->a = pp[0];
}
#endif
#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)
static void
gp_abgr16(Pixel *p, png_const_voidp pb)
{
@@ -953,6 +981,7 @@ gp_abgr16(Pixel *p, png_const_voidp pb)
p->b = pp[1];
p->a = pp[0];
}
#endif
/* Given a format, return the correct one of the above functions. */
static void (*
@@ -966,29 +995,35 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
{
if (format & PNG_FORMAT_FLAG_COLOR)
{
if (format & PNG_FORMAT_FLAG_BGR)
{
if (format & PNG_FORMAT_FLAG_ALPHA)
# ifdef PNG_FORMAT_BGR_SUPPORTED
if (format & PNG_FORMAT_FLAG_BGR)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_abgr16;
if (format & PNG_FORMAT_FLAG_ALPHA)
{
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_abgr16;
else
# endif
return gp_bgra16;
}
else
return gp_bgra16;
return gp_bgr16;
}
else
return gp_bgr16;
}
else
# endif
{
if (format & PNG_FORMAT_FLAG_ALPHA)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_argb16;
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_argb16;
else
else
# endif
return gp_rgba16;
}
@@ -1001,10 +1036,12 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
{
if (format & PNG_FORMAT_FLAG_ALPHA)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_ag16;
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_ag16;
else
else
# endif
return gp_ga16;
}
@@ -1017,29 +1054,35 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
{
if (format & PNG_FORMAT_FLAG_COLOR)
{
if (format & PNG_FORMAT_FLAG_BGR)
{
if (format & PNG_FORMAT_FLAG_ALPHA)
# ifdef PNG_FORMAT_BGR_SUPPORTED
if (format & PNG_FORMAT_FLAG_BGR)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_abgr8;
if (format & PNG_FORMAT_FLAG_ALPHA)
{
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_abgr8;
else
# endif
return gp_bgra8;
}
else
return gp_bgra8;
return gp_bgr8;
}
else
return gp_bgr8;
}
else
# endif
{
if (format & PNG_FORMAT_FLAG_ALPHA)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_argb8;
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_argb8;
else
else
# endif
return gp_rgba8;
}
@@ -1052,10 +1095,12 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
{
if (format & PNG_FORMAT_FLAG_ALPHA)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_ag8;
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
return gp_ag8;
else
else
# endif
return gp_ga8;
}
@@ -2618,13 +2663,15 @@ component_loc(png_byte loc[4], png_uint_32 format)
loc[2] = 1;
if (format & PNG_FORMAT_FLAG_BGR)
{
loc[1] = 2;
loc[3] = 0;
}
# ifdef PNG_FORMAT_BGR_SUPPORTED
if (format & PNG_FORMAT_FLAG_BGR)
{
loc[1] = 2;
loc[3] = 0;
}
else
else
# endif
{
loc[1] = 0;
loc[3] = 2;
@@ -2639,15 +2686,17 @@ component_loc(png_byte loc[4], png_uint_32 format)
if (format & PNG_FORMAT_FLAG_ALPHA)
{
if (format & PNG_FORMAT_FLAG_AFIRST)
{
loc[0] = 0;
++loc[1];
++loc[2];
++loc[3];
}
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
if (format & PNG_FORMAT_FLAG_AFIRST)
{
loc[0] = 0;
++loc[1];
++loc[2];
++loc[3];
}
else
else
# endif
loc[0] = channels;
++channels;
@@ -3017,17 +3066,25 @@ read_file(Image *image, png_uint_32 format, png_const_colorp background)
return logerror(image, "memory init: ", image->file_name, "");
}
else if (image->input_file != NULL)
{
if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
return logerror(image, "stdio init: ", image->file_name, "");
}
# ifdef PNG_STDIO_SUPPORTED
else if (image->input_file != NULL)
{
if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
return logerror(image, "stdio init: ", image->file_name, "");
}
else
{
if (!png_image_begin_read_from_file(&image->image, image->file_name))
return logerror(image, "file init: ", image->file_name, "");
}
else
{
if (!png_image_begin_read_from_file(&image->image, image->file_name))
return logerror(image, "file init: ", image->file_name, "");
}
# else
else
{
return logerror(image, "unsupported file/stdio init: ",
image->file_name, "");
}
# endif
/* This must be set after the begin_read call: */
if (image->opts & sRGB_16BIT)
@@ -3466,11 +3523,19 @@ main(int argc, char **argv)
memset(gpc_error_via_linear, 0, sizeof gpc_error_via_linear);
}
else if (strcmp(arg, "--file") == 0)
opts |= READ_FILE;
# ifdef PNG_STDIO_SUPPORTED
opts |= READ_FILE;
# else
return 77; /* skipped: no support */
# endif
else if (strcmp(arg, "--memory") == 0)
opts &= ~READ_FILE;
else if (strcmp(arg, "--stdio") == 0)
opts |= USE_STDIO;
# ifdef PNG_STDIO_SUPPORTED
opts |= USE_STDIO;
# else
return 77; /* skipped: no support */
# endif
else if (strcmp(arg, "--name") == 0)
opts &= ~USE_STDIO;
else if (strcmp(arg, "--verbose") == 0)

View File

@@ -43,7 +43,10 @@
# include "../../png.h"
#endif
#ifdef PNG_WRITE_SUPPORTED /* else pngvalid can do nothing */
/* pngvalid requires write support and one of the fixed or floating point APIs.
*/
#if defined(PNG_WRITE_SUPPORTED) &&\
(defined(PNG_FIXED_POINT_SUPPORTED) || defined(PNG_FLOATING_POINT_SUPPORTED))
#if PNG_LIBPNG_VER < 10500
/* This deliberately lacks the PNG_CONST. */
@@ -106,6 +109,11 @@ typedef png_byte *png_const_bytep;
# endif
#endif
/* Fixups for various minimal builds */
#ifndef PNG_ERROR_TEXT_SUPPORTED
# define png_error(a,b) png_err(a)
#endif
/***************************** EXCEPTION HANDLING *****************************/
#ifdef PNG_FREESTANDING_TESTS
# include <cexcept.h>
@@ -1263,6 +1271,7 @@ store_current_palette(png_store *ps, int *npalette)
#endif /* PNG_READ_SUPPORTED */
/***************************** MEMORY MANAGEMENT*** ***************************/
#ifdef PNG_USER_MEM_SUPPORTED
/* A store_memory is simply the header for an allocated block of memory. The
* pointer returned to libpng is just after the end of the header block, the
* allocated memory is followed by a second copy of the 'mark'.
@@ -1463,6 +1472,7 @@ store_free(png_structp ppIn, png_voidp memory)
this->next = NULL;
store_memory_free(pp, pool, this);
}
#endif /* PNG_USER_MEM_SUPPORTED */
/* Setup functions. */
/* Cleanup when aborting a write or after storing the new file. */
@@ -1488,7 +1498,9 @@ store_write_reset(png_store *ps)
/* And make sure that all the memory has been freed - this will output
* spurious errors in the case of memory corruption above, but this is safe.
*/
store_pool_delete(ps, &ps->write_memory_pool);
# ifdef PNG_USER_MEM_SUPPORTED
store_pool_delete(ps, &ps->write_memory_pool);
# endif
store_freenew(ps);
}
@@ -1512,16 +1524,20 @@ set_store_for_write(png_store *ps, png_infopp ppi,
store_write_reset(ps);
safecat(ps->wname, sizeof ps->wname, 0, name);
/* Don't do the slow memory checks if doing a speed test. */
if (ps->speed)
/* Don't do the slow memory checks if doing a speed test, also if user
* memory is not supported we can't do it anyway.
*/
# ifdef PNG_USER_MEM_SUPPORTED
if (!ps->speed)
ps->pwrite = png_create_write_struct_2(PNG_LIBPNG_VER_STRING,
ps, store_error, store_warning, &ps->write_memory_pool,
store_malloc, store_free);
else
# endif
ps->pwrite = png_create_write_struct(PNG_LIBPNG_VER_STRING,
ps, store_error, store_warning);
else
ps->pwrite = png_create_write_struct_2(PNG_LIBPNG_VER_STRING,
ps, store_error, store_warning, &ps->write_memory_pool,
store_malloc, store_free);
png_set_write_fn(ps->pwrite, ps, store_write, store_flush);
# ifdef PNG_SET_OPTION_SUPPORTED
@@ -1569,8 +1585,10 @@ store_read_reset(png_store *ps)
}
# endif
/* Always do this to be safe. */
store_pool_delete(ps, &ps->read_memory_pool);
# ifdef PNG_USER_MEM_SUPPORTED
/* Always do this to be safe. */
store_pool_delete(ps, &ps->read_memory_pool);
# endif
ps->current = NULL;
ps->next = NULL;
@@ -1630,14 +1648,16 @@ set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id,
* However, given that store_error works correctly in these circumstances
* we don't ever expect NULL in this program.
*/
if (ps->speed)
ps->pread = png_create_read_struct(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning);
# ifdef PNG_USER_MEM_SUPPORTED
if (!ps->speed)
ps->pread = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning, &ps->read_memory_pool, store_malloc,
store_free);
else
ps->pread = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning, &ps->read_memory_pool, store_malloc,
store_free);
else
# endif
ps->pread = png_create_read_struct(PNG_LIBPNG_VER_STRING, ps, store_error,
store_warning);
if (ps->pread == NULL)
{
@@ -1933,9 +1953,11 @@ typedef struct png_modifier
} png_modifier;
/* This returns true if the test should be stopped now because it has already
* failed and it is running silently.
* failed and it is running silently. It is not static simply to avoid having
* to special case it on all the #ifdefs on which it depends.
*/
static int fail(png_modifier *pm)
extern int fail(png_modifier *pm);
/*static*/ int fail(png_modifier *pm)
{
return !pm->log && !pm->this.verbose && (pm->this.nerrors > 0 ||
(pm->this.treat_warnings_as_errors && pm->this.nwarnings > 0));
@@ -3109,8 +3131,10 @@ init_standard_palette(png_store *ps, png_structp pp, png_infop pi, int npalette,
for (; i<256; ++i)
tRNS[i] = 24;
if (j > 0)
png_set_tRNS(pp, pi, tRNS, j, 0/*color*/);
# ifdef PNG_WRITE_tRNS_SUPPORTED
if (j > 0)
png_set_tRNS(pp, pi, tRNS, j, 0/*color*/);
# endif
}
}
@@ -3356,6 +3380,13 @@ 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.
*/
#ifndef PNG_WRITE_INTERLACING_SUPPORTED
# define png_set_interlace_handling(a) (1)
#endif
/* Make a standardized image given a an image colour type, bit depth and
* interlace type. The standard images have a very restricted range of
* rows and heights and are used for testing transforms rather than image
@@ -3509,8 +3540,12 @@ make_transform_images(png_store *ps)
{
int interlace_type;
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < PNG_INTERLACE_LAST; ++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
{
char name[FILE_NAME_SIZE];
@@ -3666,7 +3701,9 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
int npasses = npasses_from_interlace_type(pp, interlace_type);
png_uint_32 y;
int pass;
int nfilter = PNG_FILTER_VALUE_LAST;
# ifdef PNG_WRITE_FILTER_SUPPORTED
int nfilter = PNG_FILTER_VALUE_LAST;
# endif
png_byte image[16][SIZE_ROWMAX];
/* To help consistent error detection make the parts of this buffer
@@ -3720,6 +3757,7 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
continue;
}
# ifdef PNG_WRITE_FILTER_SUPPORTED
/* Only get to here if the row has some pixels in it, set the
* filters to 'all' for the very first row and thereafter to a
* single filter. It isn't well documented, but png_set_filter
@@ -3735,6 +3773,7 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
if (nfilter-- == 0)
nfilter = PNG_FILTER_VALUE_LAST-1;
# endif
png_write_row(pp, row);
}
@@ -3802,8 +3841,10 @@ make_size(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, int bdlo,
width, height, 0);
make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_NONE,
width, height, 1);
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,
width, height, 0);
# endif
make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,
width, height, 1);
}
@@ -3998,8 +4039,12 @@ make_errors(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)
# 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
{
unsigned int test;
char name[FILE_NAME_SIZE];
@@ -4020,7 +4065,7 @@ make_errors(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
return 1; /* keep going */
}
#endif
#endif /* PNG_WARNINGS_SUPPORTED */
static void
perform_error_test(png_modifier *pm)
@@ -10224,10 +10269,11 @@ int main(int argc, char **argv)
return 0;
}
#else /* write not supported */
#else /* write or low level APIs not supported */
int main(void)
{
fprintf(stderr, "pngvalid: no write support in libpng, all tests skipped\n");
fprintf(stderr,
"pngvalid: no low level write support in libpng, all tests skipped\n");
/* So the test is skipped: */
return 77;
}