From f2aacefb3f22872bd7eefa73137e396a2e517f36 Mon Sep 17 00:00:00 2001 From: John Bowler Date: Tue, 13 Nov 2012 19:18:53 -0600 Subject: [PATCH] [libpng16] Added the ability for contrib/libtests/makepng.c to make a PNG with just one color. This is useful for debugging pngstest color inaccuracy reports. --- ANNOUNCE | 8 +- CHANGES | 6 +- contrib/libtests/makepng.c | 305 ++++++++++++++++++++++++++++++------- 3 files changed, 263 insertions(+), 56 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 941f3a017..69ecf2193 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.6.0beta32 - November 2, 2012 +Libpng 1.6.0beta32 - November 14, 2012 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. @@ -545,8 +545,10 @@ Version 1.6.0beta31 [November 1, 2012] gain; implementing full ICC color correction may be desireable but is left up to applications. -Version 1.6.0beta32 [November 2, 2012] - Fixed an intermittent SEGV in pngstest. +Version 1.6.0beta32 [November 14, 2012] + Fixed an intermittent SEGV in pngstest due to an uninitialized array element. + Added the ability for contrib/libtests/makepng.c to make a PNG with just one + color. This is useful for debugging pngstest color inaccuracy reports. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index 9283ec667..b34132166 100644 --- a/CHANGES +++ b/CHANGES @@ -4297,8 +4297,10 @@ Version 1.6.0beta31 [November 1, 2012] gain; implementing full ICC color correction may be desireable but is left up to applications. -Version 1.6.0beta32 [November 2, 2012] - Fixed an intermittent SEGV in pngstest. +Version 1.6.0beta32 [November 14, 2012] + Fixed an intermittent SEGV in pngstest due to an uninitialized array element. + Added the ability for contrib/libtests/makepng.c to make a PNG with just one + color. This is useful for debugging pngstest color inaccuracy reports. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/contrib/libtests/makepng.c b/contrib/libtests/makepng.c index 969cbcf95..8df01dfff 100644 --- a/contrib/libtests/makepng.c +++ b/contrib/libtests/makepng.c @@ -10,7 +10,8 @@ * * Make a test PNG image. The arguments are as follows: * - * makepng [--sRGB|--linear|--1.8] color-type bit-depth [file-name] + * makepng [--sRGB|--linear|--1.8] [--color=] color-type bit-depth \ + * [file-name] * * The color-type may be numeric (and must match the numbers used by the PNG * specification) or one of the format names listed below. The bit-depth is the @@ -23,7 +24,8 @@ * approximately value^(1/1.45) to the color values and so a gAMA chunk of 65909 * is written (1.45/2.2). * - * The image data is generated internally. The images used are as follows: + * The image data is generated internally. Unless --color is given the images + * used are as follows: * * 1 channel: a square image with a diamond, the least luminous colors are on * the edge of the image, the most luminous in the center. @@ -61,6 +63,11 @@ * Row filtering is turned off (the 'none' filter is used on every row) and the * images are not interlaced. * + * If --color is given then the whole image has that color, color-mapped images + * will have exactly one palette entry and all image files with be 16x16 in + * size. The color value is 1 to 4 decimal numbers as appropriate for the color + * type. + * * If file-name is given then the PNG is written to that file, else it is * written to stdout. Notice that stdout is not supported on systems where, by * default, it assumes text output; this program makes no attempt to change the @@ -128,18 +135,24 @@ pixel_depth_of_type(int color_type, int bit_depth) } static unsigned int -image_size_of_type(int color_type, int bit_depth) +image_size_of_type(int color_type, int bit_depth, unsigned int *colors) { - int pixel_depth = pixel_depth_of_type(color_type, bit_depth); - - if (pixel_depth < 8) - return 64; - - else if (pixel_depth > 16) - return 1024; + if (*colors) + return 16; else - return 256; + { + int pixel_depth = pixel_depth_of_type(color_type, bit_depth); + + if (pixel_depth < 8) + return 64; + + else if (pixel_depth > 16) + return 1024; + + else + return 256; + } } static void @@ -155,7 +168,7 @@ set_color(png_colorp color, png_bytep trans, unsigned int red, static int generate_palette(png_colorp palette, png_bytep trans, int bit_depth, - png_const_bytep gamma_table) + png_const_bytep gamma_table, unsigned int *colors) { /* * 1-bit: entry 0 is transparent-red, entry 1 is opaque-white @@ -166,39 +179,69 @@ generate_palette(png_colorp palette, png_bytep trans, int bit_depth, * 4-bit: the 16 combinations of the 2-bit case * 8-bit: the 256 combinations of the 4-bit case */ - if (bit_depth == 1) + switch (colors[0]) { - set_color(palette+0, trans+0, 255, 0, 0, 0, gamma_table); - set_color(palette+1, trans+1, 255, 255, 255, 255, gamma_table); - return 2; - } + default: + fprintf(stderr, "makepng: --colors=...: invalid count %u\n", + colors[0]); + exit(1); - else - { - unsigned int size = 1U << (bit_depth/2); /* 2, 4 or 16 */ - unsigned int x, y, ip; - - for (x=0; x 65535) + { + fprintf(stderr, "makepng --color=...'%s': too big\n", arg); + exit(1); + } + + if (ep == arg) + { + fprintf(stderr, "makepng --color=...'%s': not a valid color\n", arg); + exit(1); + } + + if (*ep) ++ep; /* skip a separator */ + arg = ep; + + colors[++ncolors] = (unsigned int)ul; /* checked above */ + } + + if (*arg) + { + fprintf(stderr, "makepng --color=...'%s': too many values\n", arg); + exit(1); + } + + *colors = ncolors; +} + int main(int argc, char **argv) { @@ -1101,14 +1280,17 @@ main(int argc, char **argv) const char *file_name = NULL; int color_type = 8; /* invalid */ int bit_depth = 32; /* invalid */ + unsigned int colors[5]; unsigned int filters = PNG_ALL_FILTERS; png_fixed_point gamma = 0; /* not set */ chunk_insert *head_insert = NULL; chunk_insert **insert_ptr = &head_insert; + memset(colors, 0, sizeof colors); + while (--argc > 0) { - const char *arg = *++argv; + char *arg = *++argv; if (strcmp(arg, "--sRGB") == 0) { @@ -1134,6 +1316,12 @@ main(int argc, char **argv) continue; } + if (strncmp(arg, "--color=", 8) == 0) + { + parse_color(arg+8, colors); + continue; + } + if (argc >= 3 && strcmp(arg, "--insert") == 0) { png_const_charp what = *++argv; @@ -1245,11 +1433,26 @@ main(int argc, char **argv) if (color_type == 8 || bit_depth == 32) { fprintf(stderr, "usage: makepng [--sRGB|--linear|--1.8] " - "color-type bit-depth [file-name]\n" + "[--color=...] color-type bit-depth [file-name]\n" " Make a test PNG file, by default writes to stdout.\n"); exit(1); } + /* Check the colors */ + { + const unsigned int lim = (color_type == PNG_COLOR_TYPE_PALETTE ? 255U : + (1U< lim) + { + fprintf(stderr, "makepng: --color=...: %u out of range [0..%u]\n", + colors[i], lim); + exit(1); + } + } + /* Restrict the filters for more speed to those we know are used for the * generated images. */ @@ -1273,7 +1476,7 @@ main(int argc, char **argv) { int ret = write_png(&file_name, fp, color_type, bit_depth, gamma, - head_insert, filters); + head_insert, filters, colors); if (ret != 0 && file_name != NULL) remove(file_name);