diff --git a/ANNOUNCE b/ANNOUNCE index 58f92846c..e49bb717a 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.7.0beta66 - September 20, 2015 +Libpng 1.7.0beta66 - September 22, 2015 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. @@ -871,7 +871,7 @@ Version 1.7.0beta65 [September 16, 2015] (but not yet by the writer) (John Bowler). Implemented shared transform handling that is used throughout (John Bowler). -Version 1.7.0beta66 [September 20, 2015] +Version 1.7.0beta66 [September 22, 2015] Enabled the low-bit-depth gray tests that were disabled in prior versions of libpng because of problems that should have been fixed by the recent changes to libpng17. Enabling the tests revealed bugs in those changes @@ -901,6 +901,34 @@ Version 1.7.0beta66 [September 20, 2015] did further corrections, only shown by using files with gAMA 1/1.52 in pngstest (John Bowler). Suppressed bogus Coverity issues in pngrutil.c and pngwutil.c. + Corrected sRGB gamma handling in the Simplified API (John Bowler). + If a gamma encoded file that has a gamma not matching that of sRGB is + passed to the simplified API the previous code simply interpreted it as + a power law encoding. However old Mac files had a power law correction + of 1.45 built in to the encoding, even though the display devices were + consistent with sRGB. Assuming a power law encoding results in + substantial differences in the interpretation of low 8-bit values; + below 10. For example an Apple '5' which is equivalent to an sRGB '17' + ends up as the value '8'. This patch provides some measure of correction + for this by making the gamma correction done within the simplified API + assume that any encoded data is encoded relative to an sRGB-like transfer + function; the data is corrected back to the PNG-nominal 2.2 value then + decoded to linear (if required) using the sRGB transfer function. + This reduces the errors reported by pngstest for such files (colormapped + ones) but still leaves the issue with files where the standard libpng + code does the gamma decoding. To cope with the latter cases there is a + new pngstest-errors which allows the result; however, this is still a + work-in-progress; a better solution is possible. + Added a '--small' option to 'makepng' to allow the generation of smaller + images that also give better test case coverage. Also added copyright + and licence to the generated images, reflecting the fact that they are + original works of the author of the code. The licence used is the + Creative Commons Public Domain (CC0-1.0) one, which is appropriate + for non-source-code works. The resultant images were used to generate + the recently-updated pngstest-errors.h file. + Added test files generated by "contrib/testpngs/makepngs.sh --small" + with MAKEPNG set to the makepng compiled from the current + contrib/libtests/makepngs.sh, to the "contrib/testpngs" directory. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index 8f5123e7f..6c54176d8 100644 --- a/CHANGES +++ b/CHANGES @@ -5170,7 +5170,7 @@ Version 1.7.0beta65 [September 16, 2015] (but not yet by the writer) (John Bowler). Implemented shared transform handling that is used throughout (John Bowler). -Version 1.7.0beta66 [September 20, 2015] +Version 1.7.0beta66 [September 22, 2015] Enabled the low-bit-depth gray tests that were disabled in prior versions of libpng because of problems that should have been fixed by the recent changes to libpng17. Enabling the tests revealed bugs in those changes @@ -5200,6 +5200,34 @@ Version 1.7.0beta66 [September 20, 2015] did further corrections, only shown by using files with gAMA 1/1.52 in pngstest (John Bowler). Suppressed bogus Coverity issues in pngrutil.c and pngwutil.c. + Corrected sRGB gamma handling in the Simplified API (John Bowler). + If a gamma encoded file that has a gamma not matching that of sRGB is + passed to the simplified API the previous code simply interpreted it as + a power law encoding. However old Mac files had a power law correction + of 1.45 built in to the encoding, even though the display devices were + consistent with sRGB. Assuming a power law encoding results in + substantial differences in the interpretation of low 8-bit values; + below 10. For example an Apple '5' which is equivalent to an sRGB '17' + ends up as the value '8'. This patch provides some measure of correction + for this by making the gamma correction done within the simplified API + assume that any encoded data is encoded relative to an sRGB-like transfer + function; the data is corrected back to the PNG-nominal 2.2 value then + decoded to linear (if required) using the sRGB transfer function. + This reduces the errors reported by pngstest for such files (colormapped + ones) but still leaves the issue with files where the standard libpng + code does the gamma decoding. To cope with the latter cases there is a + new pngstest-errors which allows the result; however, this is still a + work-in-progress; a better solution is possible. + Added a '--small' option to 'makepng' to allow the generation of smaller + images that also give better test case coverage. Also added copyright + and licence to the generated images, reflecting the fact that they are + original works of the author of the code. The licence used is the + Creative Commons Public Domain (CC0-1.0) one, which is appropriate + for non-source-code works. The resultant images were used to generate + the recently-updated pngstest-errors.h file. + Added test files generated by "contrib/testpngs/makepngs.sh --small" + with MAKEPNG set to the makepng compiled from the current + contrib/libtests/makepngs.sh, to the "contrib/testpngs" directory. 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 73fa44755..7f54e24a2 100644 --- a/contrib/libtests/makepng.c +++ b/contrib/libtests/makepng.c @@ -1,8 +1,9 @@ -/* makepng.c - * - * Copyright (c) 2013 John Cunningham Bowler - * - * Last changed in libpng 1.6.1 [March 28, 2013] +/* makepng.c */ +#define _ISOC99_SOURCE +/* Copyright: */ +#define COPYRIGHT "\251 2013,2015 John Cunningham Bowler" +/* + * Last changed in libpng 1.7.0 [September 20, 2015] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer @@ -10,8 +11,8 @@ * * Make a test PNG image. The arguments are as follows: * - * makepng [--sRGB|--linear|--1.8] [--color=] color-type bit-depth \ - * [file-name] + * makepng [--sRGB|--linear|--1.8] [--tRNS] [--nofilters] \ + * 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 @@ -39,8 +40,8 @@ * 4 channels: linear combinations of, from the top-left corner clockwise, * transparent, red, green, blue. * - * For color-mapped images a four channel color-map is used and the PNG file has - * a tRNS chunk, as follows: + * For color-mapped images a four channel color-map is used and if --tRNS is + * given the PNG file has a tRNS chunk, as follows: * * 1-bit: entry 0 is transparent-red, entry 1 is opaque-white * 2-bit: entry 0: transparent-green @@ -53,6 +54,9 @@ * The palette always has 2^bit-depth entries and the tRNS chunk one fewer. The * image is the 1-channel diamond, but using palette index, not luminosity. * + * For formats other than color-mapped ones if --tRNS is specified a tRNS chunk + * is generated with all channels equal to the low bits of 0x0101. + * * Image size is determined by the final pixel depth in bits, i.e. channels x * bit-depth, as follows: * @@ -60,20 +64,64 @@ * 16 bits: 256x256 * More than 16 bits: 1024x1024 * - * Row filtering is turned off (the 'none' filter is used on every row) and the - * images are not interlaced. + * Row filtering is the libpng default but may be turned off (the 'none' filter + * is used on every row) with the --nofilters option. + * + * The images are not interlaced. + * + * 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 + * text mode of stdout! + * + * makepng --color= ... * * 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 - * text mode of stdout! + * makepng --small ... + * + * If --small is given the images are no larger than required to include every + * possible pixel value for the format. + * + * For formats with pixels 8 bits or fewer in size the images consist of a + * single row with 2^pixel-depth pixels, one of every possible value. + * + * For formats with 16-bit pixels a 256x256 image is generated containing every + * possible pixel value. + * + * For larger pixel sizes a 256x256 image is generated where the first row + * consists of each pixel that has identical byte values throughout the pixel + * followed by rows where the byte values differ within the pixel. + * + * In all cases the pixel values are arranged in such a way that the SUB and UP + * filters give byte sequences for maximal zlib compression. By default (if + * --nofilters is not given) the SUB filter is used on the first row and the UP + * filter on all following rows. + * + * The --small option is meant to provide good test-case coverage, however the + * images are not easy to examine visually. Without the --small option the + * images contain identical color values; the pixel values are adjusted + * according to the gamma encoding with no gamma encoding being interpreted as + * sRGB. + * + * LICENSING + * ========= + * + * This code is copyright of the authors, see the COPYRIGHT define above. The + * code is licensed as above, using the libpng license. The code generates + * images which are solely the product of the code; the options choose which of + * the many possibilities to generate. The images that result (but not the code + * which generates them) are licensed as defined here: + * + * IMPORTANT: the COPYRIGHT #define must contain ISO-Latin-1 characters, the + * IMAGE_LICENSING #define must contain UTF-8 characters. The 'copyright' + * symbol 0xA9U (\251) in ISO-Latin-1 encoding and 0xC20xA9 (\302\251) in UTF-8. */ -#define _ISOC99_SOURCE /* for strtoull */ +#define IMAGE_LICENSING "Dedicated to the public domain per Creative Commons "\ + "license \"CC0 1.0\"; https://creativecommons.org/publicdomain/zero/1.0/" #include /* for offsetof */ #include @@ -82,6 +130,7 @@ #include #include #include +#include #include #if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H) @@ -97,6 +146,8 @@ # include "../../png.h" #endif +#include + /* Work round for GCC complaints about casting a (double) function result to * an unsigned: */ @@ -153,7 +204,8 @@ pixel_depth_of_type(int color_type, int bit_depth) } static unsigned int -image_size_of_type(int color_type, int bit_depth, unsigned int *colors) +image_size_of_type(int color_type, int bit_depth, unsigned int *colors, + int small) { if (*colors) return 16; @@ -162,7 +214,16 @@ 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) + if (small) + { + if (pixel_depth <= 8) /* there will be one row */ + return 1 << pixel_depth; + + else + return 256; + } + + else if (pixel_depth < 8) return 64; else if (pixel_depth > 16) @@ -325,15 +386,148 @@ set_value(png_bytep row, size_t rowbytes, png_uint_32 x, unsigned int bit_depth, } } -static void +static int /* filter mask for row */ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type, int bit_depth, png_const_bytep gamma_table, double conv, - unsigned int *colors) + unsigned int *colors, int small) { - png_uint_32 size_max = image_size_of_type(color_type, bit_depth, colors)-1; + int filters = 0; /* file *MASK*, 0 means the default, not NONE */ + png_uint_32 size_max = + image_size_of_type(color_type, bit_depth, colors, small)-1; png_uint_32 depth_max = (1U << bit_depth)-1; /* up to 65536 */ - if (colors[0] == 0) switch (channels_of_type(color_type)) + if (colors[0] == 0) if (small) + { + unsigned int pixel_depth = pixel_depth_of_type(color_type, bit_depth); + + /* For pixel depths less than 16 generate a single row containing all the + * possible pixel values. For 16 generate all 65536 byte pair + * combinations in a 256x256 pixel array. + */ + switch (pixel_depth) + { + case 1: + assert(y == 0 && rowbytes == 1 && size_max == 1); + row[0] = 0x6CU; /* binary: 01101100, only top 2 bits used */ + filters = PNG_FILTER_NONE; + break; + + case 2: + assert(y == 0 && rowbytes == 1 && size_max == 3); + row[0] = 0x1BU; /* binary 00011011, all bits used */ + filters = PNG_FILTER_NONE; + break; + + case 4: + assert(y == 0 && rowbytes == 8 && size_max == 15); + row[0] = 0x01U; + row[1] = 0x23U; /* SUB gives 0x22U for all following bytes */ + row[2] = 0x45U; + row[3] = 0x67U; + row[4] = 0x89U; + row[5] = 0xABU; + row[6] = 0xCDU; + row[7] = 0xEFU; + filters = PNG_FILTER_SUB; + break; + + case 8: + /* The row will have all the pixel values in order starting with + * '1', the SUB filter will change every byte into '1' (including + * the last, which generates pixel value '0'). Since the SUB filter + * has value 1 this should result in maximum compression. + */ + assert(y == 0 && rowbytes == 256 && size_max == 255); + for (;;) + { + row[size_max] = 0xFFU & (size_max+1); + if (size_max == 0) + break; + --size_max; + } + filters = PNG_FILTER_SUB; + break; + + case 16: + /* Rows are generated such that each row has a constant difference + * between the first and second byte of each pixel and so that the + * difference increases by 1 at each row. The rows start with the + * first byte value of 0 and the value increases to 255 across the + * row. + * + * The difference starts at 1, so the first row is: + * + * 0 1 1 2 2 3 3 4 ... 254 255 255 0 + * + * This means that running the SUB filter on the first row produces: + * + * [SUB==1] 0 1 0 1 0 1... + * + * Then the difference is 2 on the next row, giving: + * + * 0 2 1 3 2 4 3 5 ... 254 0 255 1 + * + * When the UP filter is run on this libpng produces: + * + * [UP ==2] 0 1 0 1 0 1... + * + * And so on for all the remain rows to the final two * rows: + * + * row 254: 0 255 1 0 2 1 3 2 4 3 ... 254 253 255 254 + * row 255: 0 0 1 1 2 2 3 3 4 4 ... 254 254 255 255 + */ + assert(rowbytes == 512 && size_max == 255); + for (;;) + { + row[2*size_max ] = 0xFFU & size_max; + row[2*size_max+1] = 0xFFU & (size_max+y+1); + if (size_max == 0) + break; + --size_max; + } + /* The first row must include PNG_FILTER_UP so that libpng knows we + * need to keep it for the following row: + */ + filters = (y == 0 ? PNG_FILTER_SUB+PNG_FILTER_UP : PNG_FILTER_UP); + break; + + case 24: + case 32: + case 48: + case 64: + /* The rows are filled by an alogorithm similar to the above, in the + * first row pixel bytes are all equal, increasing from 0 by 1 for + * each pixel. In the second row the bytes within a pixel are + * incremented 1,3,5,7,... from the previous row byte. Using an odd + * number ensures all the possible byte values are used. + */ + assert(size_max == 255 && rowbytes == 256*(pixel_depth>>3)); + pixel_depth >>= 3; /* now in bytes */ + while (rowbytes > 0) + { + const size_t pixel_index = --rowbytes/pixel_depth; + + if (y == 0) + row[rowbytes] = 0xFFU & pixel_index; + + else + { + const size_t byte_offset = + rowbytes - pixel_index * pixel_depth; + + row[rowbytes] = + 0xFFU & (pixel_index + (byte_offset * 2*y) + 1); + } + } + filters = (y == 0 ? PNG_FILTER_SUB+PNG_FILTER_UP : PNG_FILTER_UP); + break; + + default: + assert(0/*NOT REACHED*/); + } + } + + else switch (channels_of_type(color_type)) { /* 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. @@ -545,6 +739,8 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type, colors[0], channels_of_type(color_type)); exit(1); } + + return filters; } @@ -573,7 +769,7 @@ makepng_error(png_structp png_ptr, png_const_charp message) static int /* 0 on success, else an error code */ write_png(const char **name, FILE *fp, int color_type, int bit_depth, volatile png_fixed_point gamma, chunk_insert * volatile insert, - unsigned int filters, unsigned int *colors) + unsigned int filters, unsigned int *colors, int small, int tRNS) { png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, name, makepng_error, makepng_warning); @@ -600,6 +796,15 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth, /* Allow benign errors so that we can write PNGs with errors */ png_set_benign_errors(png_ptr, 1/*allowed*/); + + /* Max out the text compression level in an attempt to make the license + * small. If --small then do the same for the IDAT. + */ + if (small) + png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); + + png_set_text_compression_level(png_ptr, Z_BEST_COMPRESSION); + png_init_io(png_ptr, fp); info_ptr = png_create_info_struct(png_ptr); @@ -607,11 +812,37 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth, png_error(png_ptr, "OOM allocating info structure"); { - unsigned int size = image_size_of_type(color_type, bit_depth, colors); + const unsigned int size = + image_size_of_type(color_type, bit_depth, colors, small); + unsigned int ysize; png_fixed_point real_gamma = 45455; /* For sRGB */ png_byte gamma_table[256]; double conv; + /* Normally images are square, but with 'small' we want to simply generate + * all the pixel values, or all that we reasonably can: + */ + if (small) + { + const unsigned int pixel_depth = + pixel_depth_of_type(color_type, bit_depth); + + if (pixel_depth <= 8U) + { + assert(size == (1U<next; + } + + new_insert = add_iTXt("Licensing", "en", NULL, licensing); + if (new_insert != NULL) + { + *insert_ptr = new_insert; + insert_ptr = &new_insert->next; + } + } + { int ret = write_png(&file_name, fp, color_type, bit_depth, gamma, - head_insert, filters, colors); + head_insert, filters, colors, small, tRNS); if (ret != 0 && file_name != NULL) remove(file_name); diff --git a/contrib/libtests/pngstest-errors.h b/contrib/libtests/pngstest-errors.h index b818fd497..241ec6206 100644 --- a/contrib/libtests/pngstest-errors.h +++ b/contrib/libtests/pngstest-errors.h @@ -32,7 +32,7 @@ static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] = { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, { /* input: sRGB-rgb+alpha */ - { 0, 4, 13, 0 }, { 0, 15, 13, 0 }, { 0, 19, 1, 0 }, { 0, 0, 0, 0 }, + { 0, 14, 13, 0 }, { 0, 15, 13, 0 }, { 0, 19, 1, 0 }, { 0, 0, 0, 0 }, { 0, 832, 764, 0 }, { 0, 832, 764, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } @@ -52,7 +52,7 @@ static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] = { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, { /* input: linear-rgb+alpha */ - { 0, 126, 143, 0 }, { 0, 9, 7, 0 }, { 0, 74, 9, 0 }, { 0, 17, 9, 0 }, + { 0, 126, 143, 0 }, { 0, 11, 7, 0 }, { 0, 74, 9, 0 }, { 0, 17, 9, 0 }, { 0, 4, 4, 0 }, { 0, 5, 4, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } @@ -73,7 +73,7 @@ static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] = { 0, 0, 460, 0 }, { 0, 0, 460, 0 }, { 0, 0, 263, 0 }, { 0, 0, 263, 0 } }, { /* input: color-mapped-sRGB-rgb+alpha */ { 0, 6, 8, 0 }, { 0, 7, 8, 0 }, { 0, 75, 8, 0 }, { 0, 9, 8, 0 }, - { 0, 585, 427, 0 }, { 0, 585, 427, 0 }, { 0, 717, 462, 0 }, { 0, 717, 462, 0 }, + { 0, 585, 427, 0 }, { 0, 585, 427, 0 }, { 0, 717, 584, 0 }, { 0, 717, 584, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 13323, 460, 0 }, { 0, 427, 460, 0 }, { 0, 16480, 263, 0 }, { 0, 243, 263, 0 } }, { /* input: color-mapped-linear-gray */ @@ -115,7 +115,7 @@ static png_uint_16 gpc_error_via_linear[16][4/*out*/][4] = }, { /* input: linear-rgb */ { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 } }, { /* input: linear-rgb+alpha */ - { 0, 1, 1, 0 }, { 0, 8, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 } + { 0, 1, 1, 0 }, { 0, 9, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 } }, { /* input: color-mapped-sRGB-gray */ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, { /* input: color-mapped-sRGB-gray+alpha */ @@ -123,7 +123,7 @@ static png_uint_16 gpc_error_via_linear[16][4/*out*/][4] = }, { /* input: color-mapped-sRGB-rgb */ { 0, 0, 13, 0 }, { 0, 0, 13, 0 }, { 0, 0, 14, 0 }, { 0, 0, 14, 0 } }, { /* input: color-mapped-sRGB-rgb+alpha */ - { 0, 4, 8, 0 }, { 0, 9, 8, 0 }, { 0, 9, 3, 0 }, { 0, 32, 3, 0 } + { 0, 4, 8, 0 }, { 0, 9, 8, 0 }, { 0, 9, 9, 0 }, { 0, 32, 9, 0 } }, { /* input: color-mapped-linear-gray */ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, { /* input: color-mapped-linear-gray+alpha */ @@ -138,28 +138,28 @@ static png_uint_16 gpc_error_to_colormap[8/*i*/][8/*o*/][4] = { { /* input: sRGB-gray */ { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, - { 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 } + { 0, 0, 742, 0 }, { 0, 0, 742, 0 }, { 0, 0, 742, 0 }, { 0, 0, 742, 0 } }, { /* input: sRGB-gray+alpha */ - { 0, 19, 2, 0 }, { 0, 255, 2, 25 }, { 0, 88, 2, 0 }, { 0, 255, 2, 25 }, - { 0, 1012, 745, 0 }, { 0, 16026, 745, 6425 }, { 0, 1012, 745, 0 }, { 0, 16026, 745, 6425 } + { 0, 19, 6, 0 }, { 0, 255, 6, 25 }, { 0, 88, 6, 0 }, { 0, 255, 6, 25 }, + { 0, 1012, 911, 0 }, { 0, 16026, 911, 6425 }, { 0, 1012, 911, 0 }, { 0, 16026, 911, 6425 } }, { /* input: sRGB-rgb */ { 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 25, 0 }, { 0, 0, 25, 0 }, { 0, 0, 962, 0 }, { 0, 0, 962, 0 }, { 0, 0, 13677, 0 }, { 0, 0, 13677, 0 } }, { /* input: sRGB-rgb+alpha */ - { 0, 63, 77, 0 }, { 0, 255, 19, 25 }, { 0, 220, 25, 0 }, { 0, 255, 25, 67 }, - { 0, 17534, 18491, 0 }, { 0, 15614, 2824, 6425 }, { 0, 14019, 13677, 0 }, { 0, 48573, 13677, 17219 } + { 0, 63, 77, 0 }, { 0, 255, 19, 25 }, { 0, 225, 25, 0 }, { 0, 255, 25, 67 }, + { 0, 17534, 18491, 0 }, { 0, 15998, 2824, 6425 }, { 0, 14103, 13677, 0 }, { 0, 50115, 13677, 17219 } }, { /* input: linear-gray */ { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 } }, { /* input: linear-gray+alpha */ - { 0, 74, 74, 0 }, { 0, 255, 74, 25 }, { 0, 97, 74, 0 }, { 0, 255, 74, 25 }, - { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6552 }, { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6552 } + { 0, 74, 74, 0 }, { 0, 255, 74, 25 }, { 0, 99, 74, 0 }, { 0, 255, 74, 25 }, + { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6553 }, { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6553 } }, { /* input: linear-rgb */ { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 98, 0 }, { 0, 0, 98, 0 }, { 0, 0, 18664, 0 }, { 0, 0, 18664, 0 }, { 0, 0, 24998, 0 }, { 0, 0, 24998, 0 } }, { /* input: linear-rgb+alpha */ { 0, 181, 196, 0 }, { 0, 255, 61, 25 }, { 206, 187, 98, 0 }, { 0, 255, 98, 67 }, - { 0, 18141, 18137, 0 }, { 0, 17494, 17504, 6553 }, { 0, 24979, 24992, 0 }, { 0, 46509, 24992, 17347 } + { 0, 18141, 18137, 0 }, { 0, 17494, 17504, 6553 }, { 0, 24979, 24992, 0 }, { 0, 49172, 24992, 17347 } } }; /* END MACHINE GENERATED */ diff --git a/contrib/testpngs/gray-1-1.8-tRNS.png b/contrib/testpngs/gray-1-1.8-tRNS.png new file mode 100644 index 000000000..0fc6cb7db Binary files /dev/null and b/contrib/testpngs/gray-1-1.8-tRNS.png differ diff --git a/contrib/testpngs/gray-1-1.8.png b/contrib/testpngs/gray-1-1.8.png new file mode 100644 index 000000000..5db4d7915 Binary files /dev/null and b/contrib/testpngs/gray-1-1.8.png differ diff --git a/contrib/testpngs/gray-1-linear-tRNS.png b/contrib/testpngs/gray-1-linear-tRNS.png new file mode 100644 index 000000000..5beb9d1df Binary files /dev/null and b/contrib/testpngs/gray-1-linear-tRNS.png differ diff --git a/contrib/testpngs/gray-1-linear.png b/contrib/testpngs/gray-1-linear.png new file mode 100644 index 000000000..36a89a5ab Binary files /dev/null and b/contrib/testpngs/gray-1-linear.png differ diff --git a/contrib/testpngs/gray-1-sRGB-tRNS.png b/contrib/testpngs/gray-1-sRGB-tRNS.png new file mode 100644 index 000000000..80cec4b5e Binary files /dev/null and b/contrib/testpngs/gray-1-sRGB-tRNS.png differ diff --git a/contrib/testpngs/gray-1-sRGB.png b/contrib/testpngs/gray-1-sRGB.png new file mode 100644 index 000000000..484fd18c4 Binary files /dev/null and b/contrib/testpngs/gray-1-sRGB.png differ diff --git a/contrib/testpngs/gray-1-tRNS.png b/contrib/testpngs/gray-1-tRNS.png new file mode 100644 index 000000000..a988db968 Binary files /dev/null and b/contrib/testpngs/gray-1-tRNS.png differ diff --git a/contrib/testpngs/gray-1.png b/contrib/testpngs/gray-1.png new file mode 100644 index 000000000..71e37a336 Binary files /dev/null and b/contrib/testpngs/gray-1.png differ diff --git a/contrib/testpngs/gray-16-1.8-tRNS.png b/contrib/testpngs/gray-16-1.8-tRNS.png new file mode 100644 index 000000000..06cc0c138 Binary files /dev/null and b/contrib/testpngs/gray-16-1.8-tRNS.png differ diff --git a/contrib/testpngs/gray-16-1.8.png b/contrib/testpngs/gray-16-1.8.png new file mode 100644 index 000000000..06cc0c138 Binary files /dev/null and b/contrib/testpngs/gray-16-1.8.png differ diff --git a/contrib/testpngs/gray-16-linear-tRNS.png b/contrib/testpngs/gray-16-linear-tRNS.png new file mode 100644 index 000000000..beb4e96e2 Binary files /dev/null and b/contrib/testpngs/gray-16-linear-tRNS.png differ diff --git a/contrib/testpngs/gray-16-linear.png b/contrib/testpngs/gray-16-linear.png new file mode 100644 index 000000000..beb4e96e2 Binary files /dev/null and b/contrib/testpngs/gray-16-linear.png differ diff --git a/contrib/testpngs/gray-16-sRGB-tRNS.png b/contrib/testpngs/gray-16-sRGB-tRNS.png new file mode 100644 index 000000000..315db86a6 Binary files /dev/null and b/contrib/testpngs/gray-16-sRGB-tRNS.png differ diff --git a/contrib/testpngs/gray-16-sRGB.png b/contrib/testpngs/gray-16-sRGB.png new file mode 100644 index 000000000..315db86a6 Binary files /dev/null and b/contrib/testpngs/gray-16-sRGB.png differ diff --git a/contrib/testpngs/gray-16-tRNS.png b/contrib/testpngs/gray-16-tRNS.png new file mode 100644 index 000000000..4826d61eb Binary files /dev/null and b/contrib/testpngs/gray-16-tRNS.png differ diff --git a/contrib/testpngs/gray-16.png b/contrib/testpngs/gray-16.png new file mode 100644 index 000000000..4826d61eb Binary files /dev/null and b/contrib/testpngs/gray-16.png differ diff --git a/contrib/testpngs/gray-2-1.8-tRNS.png b/contrib/testpngs/gray-2-1.8-tRNS.png new file mode 100644 index 000000000..a1c6854c9 Binary files /dev/null and b/contrib/testpngs/gray-2-1.8-tRNS.png differ diff --git a/contrib/testpngs/gray-2-1.8.png b/contrib/testpngs/gray-2-1.8.png new file mode 100644 index 000000000..4cc811cdf Binary files /dev/null and b/contrib/testpngs/gray-2-1.8.png differ diff --git a/contrib/testpngs/gray-2-linear-tRNS.png b/contrib/testpngs/gray-2-linear-tRNS.png new file mode 100644 index 000000000..3c29ec6d9 Binary files /dev/null and b/contrib/testpngs/gray-2-linear-tRNS.png differ diff --git a/contrib/testpngs/gray-2-linear.png b/contrib/testpngs/gray-2-linear.png new file mode 100644 index 000000000..6ca6fb74d Binary files /dev/null and b/contrib/testpngs/gray-2-linear.png differ diff --git a/contrib/testpngs/gray-2-sRGB-tRNS.png b/contrib/testpngs/gray-2-sRGB-tRNS.png new file mode 100644 index 000000000..b418c8fbb Binary files /dev/null and b/contrib/testpngs/gray-2-sRGB-tRNS.png differ diff --git a/contrib/testpngs/gray-2-sRGB.png b/contrib/testpngs/gray-2-sRGB.png new file mode 100644 index 000000000..a6bde60af Binary files /dev/null and b/contrib/testpngs/gray-2-sRGB.png differ diff --git a/contrib/testpngs/gray-2-tRNS.png b/contrib/testpngs/gray-2-tRNS.png new file mode 100644 index 000000000..8e04cb502 Binary files /dev/null and b/contrib/testpngs/gray-2-tRNS.png differ diff --git a/contrib/testpngs/gray-2.png b/contrib/testpngs/gray-2.png new file mode 100644 index 000000000..9d85a2ace Binary files /dev/null and b/contrib/testpngs/gray-2.png differ diff --git a/contrib/testpngs/gray-4-1.8-tRNS.png b/contrib/testpngs/gray-4-1.8-tRNS.png new file mode 100644 index 000000000..402d699fb Binary files /dev/null and b/contrib/testpngs/gray-4-1.8-tRNS.png differ diff --git a/contrib/testpngs/gray-4-1.8.png b/contrib/testpngs/gray-4-1.8.png new file mode 100644 index 000000000..bc8da9876 Binary files /dev/null and b/contrib/testpngs/gray-4-1.8.png differ diff --git a/contrib/testpngs/gray-4-linear-tRNS.png b/contrib/testpngs/gray-4-linear-tRNS.png new file mode 100644 index 000000000..45c063d85 Binary files /dev/null and b/contrib/testpngs/gray-4-linear-tRNS.png differ diff --git a/contrib/testpngs/gray-4-linear.png b/contrib/testpngs/gray-4-linear.png new file mode 100644 index 000000000..0bd068d73 Binary files /dev/null and b/contrib/testpngs/gray-4-linear.png differ diff --git a/contrib/testpngs/gray-4-sRGB-tRNS.png b/contrib/testpngs/gray-4-sRGB-tRNS.png new file mode 100644 index 000000000..be8521049 Binary files /dev/null and b/contrib/testpngs/gray-4-sRGB-tRNS.png differ diff --git a/contrib/testpngs/gray-4-sRGB.png b/contrib/testpngs/gray-4-sRGB.png new file mode 100644 index 000000000..38a79228d Binary files /dev/null and b/contrib/testpngs/gray-4-sRGB.png differ diff --git a/contrib/testpngs/gray-4-tRNS.png b/contrib/testpngs/gray-4-tRNS.png new file mode 100644 index 000000000..14c4f1fb3 Binary files /dev/null and b/contrib/testpngs/gray-4-tRNS.png differ diff --git a/contrib/testpngs/gray-4.png b/contrib/testpngs/gray-4.png new file mode 100644 index 000000000..16bcada82 Binary files /dev/null and b/contrib/testpngs/gray-4.png differ diff --git a/contrib/testpngs/gray-8-1.8-tRNS.png b/contrib/testpngs/gray-8-1.8-tRNS.png new file mode 100644 index 000000000..2b3892458 Binary files /dev/null and b/contrib/testpngs/gray-8-1.8-tRNS.png differ diff --git a/contrib/testpngs/gray-8-1.8.png b/contrib/testpngs/gray-8-1.8.png new file mode 100644 index 000000000..4bba74cfa Binary files /dev/null and b/contrib/testpngs/gray-8-1.8.png differ diff --git a/contrib/testpngs/gray-8-linear-tRNS.png b/contrib/testpngs/gray-8-linear-tRNS.png new file mode 100644 index 000000000..a801abdaa Binary files /dev/null and b/contrib/testpngs/gray-8-linear-tRNS.png differ diff --git a/contrib/testpngs/gray-8-linear.png b/contrib/testpngs/gray-8-linear.png new file mode 100644 index 000000000..91be367ee Binary files /dev/null and b/contrib/testpngs/gray-8-linear.png differ diff --git a/contrib/testpngs/gray-8-sRGB-tRNS.png b/contrib/testpngs/gray-8-sRGB-tRNS.png new file mode 100644 index 000000000..f54f23d6b Binary files /dev/null and b/contrib/testpngs/gray-8-sRGB-tRNS.png differ diff --git a/contrib/testpngs/gray-8-sRGB.png b/contrib/testpngs/gray-8-sRGB.png new file mode 100644 index 000000000..2ae6377ff Binary files /dev/null and b/contrib/testpngs/gray-8-sRGB.png differ diff --git a/contrib/testpngs/gray-8-tRNS.png b/contrib/testpngs/gray-8-tRNS.png new file mode 100644 index 000000000..842245f1d Binary files /dev/null and b/contrib/testpngs/gray-8-tRNS.png differ diff --git a/contrib/testpngs/gray-8.png b/contrib/testpngs/gray-8.png new file mode 100644 index 000000000..23af27e14 Binary files /dev/null and b/contrib/testpngs/gray-8.png differ diff --git a/contrib/testpngs/gray-alpha-16-1.8.png b/contrib/testpngs/gray-alpha-16-1.8.png new file mode 100644 index 000000000..e0d36b7f0 Binary files /dev/null and b/contrib/testpngs/gray-alpha-16-1.8.png differ diff --git a/contrib/testpngs/gray-alpha-16-linear.png b/contrib/testpngs/gray-alpha-16-linear.png new file mode 100644 index 000000000..26aa32cee Binary files /dev/null and b/contrib/testpngs/gray-alpha-16-linear.png differ diff --git a/contrib/testpngs/gray-alpha-16-sRGB.png b/contrib/testpngs/gray-alpha-16-sRGB.png new file mode 100644 index 000000000..f1e811ba3 Binary files /dev/null and b/contrib/testpngs/gray-alpha-16-sRGB.png differ diff --git a/contrib/testpngs/gray-alpha-16.png b/contrib/testpngs/gray-alpha-16.png new file mode 100644 index 000000000..689879737 Binary files /dev/null and b/contrib/testpngs/gray-alpha-16.png differ diff --git a/contrib/testpngs/gray-alpha-8-1.8.png b/contrib/testpngs/gray-alpha-8-1.8.png new file mode 100644 index 000000000..68883a52d Binary files /dev/null and b/contrib/testpngs/gray-alpha-8-1.8.png differ diff --git a/contrib/testpngs/gray-alpha-8-linear.png b/contrib/testpngs/gray-alpha-8-linear.png new file mode 100644 index 000000000..cdc07031d Binary files /dev/null and b/contrib/testpngs/gray-alpha-8-linear.png differ diff --git a/contrib/testpngs/gray-alpha-8-sRGB.png b/contrib/testpngs/gray-alpha-8-sRGB.png new file mode 100644 index 000000000..7c37c8883 Binary files /dev/null and b/contrib/testpngs/gray-alpha-8-sRGB.png differ diff --git a/contrib/testpngs/gray-alpha-8.png b/contrib/testpngs/gray-alpha-8.png new file mode 100644 index 000000000..eb0a92499 Binary files /dev/null and b/contrib/testpngs/gray-alpha-8.png differ diff --git a/contrib/testpngs/makepngs.sh b/contrib/testpngs/makepngs.sh index 707a0e500..51ff5af1c 100755 --- a/contrib/testpngs/makepngs.sh +++ b/contrib/testpngs/makepngs.sh @@ -7,22 +7,35 @@ # ones that extend the code-coverage of libpng from the existing test files in # contrib/pngsuite. test -n "$MAKEPNG" || MAKEPNG=./makepng +opts= mp(){ - ${MAKEPNG} $1 "$3" "$4" "$2$3-$4.png" + ${MAKEPNG} $opts $1 "$3" "$4" "$3-$4$2.png" } mpg(){ - if test "$g" = "none" + if test "$1" = "none" then mp "" "" "$2" "$3" else - mp "--$1" "$1-" "$2" "$3" + mp "--$1" "-$1" "$2" "$3" + fi +} + +mptrans(){ + if test "$1" = "none" + then + mp "--tRNS" "-tRNS" "$2" "$3" + else + mp "--tRNS --$1" "-$1-tRNS" "$2" "$3" fi } case "$1" in - --all) + --small) + opts="--small";;& + + --all|--small) for g in none sRGB linear 1.8 do for c in gray palette @@ -30,17 +43,23 @@ case "$1" in for b in 1 2 4 do mpg "$g" "$c" "$b" + mptrans "$g" "$c" "$b" done done mpg "$g" palette 8 + mptrans "$g" palette 8 - for c in gray gray-alpha rgb rgb-alpha + for b in 8 16 do - for b in 8 16 + for c in gray gray-alpha rgb rgb-alpha do mpg "$g" "$c" "$b" done + for c in gray rgb + do + mptrans "$g" "$c" "$b" + done done done;; @@ -62,6 +81,6 @@ case "$1" in *) echo "$0 $1: unknown argument, usage:" >&2 - echo " $0 [--all|--coverage" >&2 + echo " $0 [--all|--coverage|--small]" >&2 exit 1 esac diff --git a/contrib/testpngs/palette-1-1.8-tRNS.png b/contrib/testpngs/palette-1-1.8-tRNS.png new file mode 100644 index 000000000..7bf60410d Binary files /dev/null and b/contrib/testpngs/palette-1-1.8-tRNS.png differ diff --git a/contrib/testpngs/palette-1-1.8.png b/contrib/testpngs/palette-1-1.8.png new file mode 100644 index 000000000..73965b724 Binary files /dev/null and b/contrib/testpngs/palette-1-1.8.png differ diff --git a/contrib/testpngs/palette-1-linear-tRNS.png b/contrib/testpngs/palette-1-linear-tRNS.png new file mode 100644 index 000000000..9b0133dc9 Binary files /dev/null and b/contrib/testpngs/palette-1-linear-tRNS.png differ diff --git a/contrib/testpngs/palette-1-linear.png b/contrib/testpngs/palette-1-linear.png new file mode 100644 index 000000000..bf232fd33 Binary files /dev/null and b/contrib/testpngs/palette-1-linear.png differ diff --git a/contrib/testpngs/palette-1-sRGB-tRNS.png b/contrib/testpngs/palette-1-sRGB-tRNS.png new file mode 100644 index 000000000..1c6f262b3 Binary files /dev/null and b/contrib/testpngs/palette-1-sRGB-tRNS.png differ diff --git a/contrib/testpngs/palette-1-sRGB.png b/contrib/testpngs/palette-1-sRGB.png new file mode 100644 index 000000000..fbadc097f Binary files /dev/null and b/contrib/testpngs/palette-1-sRGB.png differ diff --git a/contrib/testpngs/palette-1-tRNS.png b/contrib/testpngs/palette-1-tRNS.png new file mode 100644 index 000000000..8f1642b7b Binary files /dev/null and b/contrib/testpngs/palette-1-tRNS.png differ diff --git a/contrib/testpngs/palette-1.png b/contrib/testpngs/palette-1.png new file mode 100644 index 000000000..a27d1362a Binary files /dev/null and b/contrib/testpngs/palette-1.png differ diff --git a/contrib/testpngs/palette-2-1.8-tRNS.png b/contrib/testpngs/palette-2-1.8-tRNS.png new file mode 100644 index 000000000..9d2ab1656 Binary files /dev/null and b/contrib/testpngs/palette-2-1.8-tRNS.png differ diff --git a/contrib/testpngs/palette-2-1.8.png b/contrib/testpngs/palette-2-1.8.png new file mode 100644 index 000000000..cdcf28329 Binary files /dev/null and b/contrib/testpngs/palette-2-1.8.png differ diff --git a/contrib/testpngs/palette-2-linear-tRNS.png b/contrib/testpngs/palette-2-linear-tRNS.png new file mode 100644 index 000000000..d346d4007 Binary files /dev/null and b/contrib/testpngs/palette-2-linear-tRNS.png differ diff --git a/contrib/testpngs/palette-2-linear.png b/contrib/testpngs/palette-2-linear.png new file mode 100644 index 000000000..5c2f6d335 Binary files /dev/null and b/contrib/testpngs/palette-2-linear.png differ diff --git a/contrib/testpngs/palette-2-sRGB-tRNS.png b/contrib/testpngs/palette-2-sRGB-tRNS.png new file mode 100644 index 000000000..e5a491a71 Binary files /dev/null and b/contrib/testpngs/palette-2-sRGB-tRNS.png differ diff --git a/contrib/testpngs/palette-2-sRGB.png b/contrib/testpngs/palette-2-sRGB.png new file mode 100644 index 000000000..a3bf9a2f3 Binary files /dev/null and b/contrib/testpngs/palette-2-sRGB.png differ diff --git a/contrib/testpngs/palette-2-tRNS.png b/contrib/testpngs/palette-2-tRNS.png new file mode 100644 index 000000000..c34a6986d Binary files /dev/null and b/contrib/testpngs/palette-2-tRNS.png differ diff --git a/contrib/testpngs/palette-2.png b/contrib/testpngs/palette-2.png new file mode 100644 index 000000000..eaf4536e0 Binary files /dev/null and b/contrib/testpngs/palette-2.png differ diff --git a/contrib/testpngs/palette-4-1.8-tRNS.png b/contrib/testpngs/palette-4-1.8-tRNS.png new file mode 100644 index 000000000..20cb465ce Binary files /dev/null and b/contrib/testpngs/palette-4-1.8-tRNS.png differ diff --git a/contrib/testpngs/palette-4-1.8.png b/contrib/testpngs/palette-4-1.8.png new file mode 100644 index 000000000..c2318ff82 Binary files /dev/null and b/contrib/testpngs/palette-4-1.8.png differ diff --git a/contrib/testpngs/palette-4-linear-tRNS.png b/contrib/testpngs/palette-4-linear-tRNS.png new file mode 100644 index 000000000..4d96a4724 Binary files /dev/null and b/contrib/testpngs/palette-4-linear-tRNS.png differ diff --git a/contrib/testpngs/palette-4-linear.png b/contrib/testpngs/palette-4-linear.png new file mode 100644 index 000000000..dfc5a868e Binary files /dev/null and b/contrib/testpngs/palette-4-linear.png differ diff --git a/contrib/testpngs/palette-4-sRGB-tRNS.png b/contrib/testpngs/palette-4-sRGB-tRNS.png new file mode 100644 index 000000000..92d23e7dd Binary files /dev/null and b/contrib/testpngs/palette-4-sRGB-tRNS.png differ diff --git a/contrib/testpngs/palette-4-sRGB.png b/contrib/testpngs/palette-4-sRGB.png new file mode 100644 index 000000000..26ea9e5ab Binary files /dev/null and b/contrib/testpngs/palette-4-sRGB.png differ diff --git a/contrib/testpngs/palette-4-tRNS.png b/contrib/testpngs/palette-4-tRNS.png new file mode 100644 index 000000000..429f6b953 Binary files /dev/null and b/contrib/testpngs/palette-4-tRNS.png differ diff --git a/contrib/testpngs/palette-4.png b/contrib/testpngs/palette-4.png new file mode 100644 index 000000000..82f348994 Binary files /dev/null and b/contrib/testpngs/palette-4.png differ diff --git a/contrib/testpngs/palette-8-1.8-tRNS.png b/contrib/testpngs/palette-8-1.8-tRNS.png new file mode 100644 index 000000000..c10bb5697 Binary files /dev/null and b/contrib/testpngs/palette-8-1.8-tRNS.png differ diff --git a/contrib/testpngs/palette-8-1.8.png b/contrib/testpngs/palette-8-1.8.png new file mode 100644 index 000000000..cc09ee60f Binary files /dev/null and b/contrib/testpngs/palette-8-1.8.png differ diff --git a/contrib/testpngs/palette-8-linear-tRNS.png b/contrib/testpngs/palette-8-linear-tRNS.png new file mode 100644 index 000000000..27f5a3336 Binary files /dev/null and b/contrib/testpngs/palette-8-linear-tRNS.png differ diff --git a/contrib/testpngs/palette-8-linear.png b/contrib/testpngs/palette-8-linear.png new file mode 100644 index 000000000..40d413cd6 Binary files /dev/null and b/contrib/testpngs/palette-8-linear.png differ diff --git a/contrib/testpngs/palette-8-sRGB-tRNS.png b/contrib/testpngs/palette-8-sRGB-tRNS.png new file mode 100644 index 000000000..b8863ec2b Binary files /dev/null and b/contrib/testpngs/palette-8-sRGB-tRNS.png differ diff --git a/contrib/testpngs/palette-8-sRGB.png b/contrib/testpngs/palette-8-sRGB.png new file mode 100644 index 000000000..90f891204 Binary files /dev/null and b/contrib/testpngs/palette-8-sRGB.png differ diff --git a/contrib/testpngs/palette-8-tRNS.png b/contrib/testpngs/palette-8-tRNS.png new file mode 100644 index 000000000..9660e6776 Binary files /dev/null and b/contrib/testpngs/palette-8-tRNS.png differ diff --git a/contrib/testpngs/palette-8.png b/contrib/testpngs/palette-8.png new file mode 100644 index 000000000..2502d305b Binary files /dev/null and b/contrib/testpngs/palette-8.png differ diff --git a/contrib/testpngs/rgb-16-1.8-tRNS.png b/contrib/testpngs/rgb-16-1.8-tRNS.png new file mode 100644 index 000000000..03251b12e Binary files /dev/null and b/contrib/testpngs/rgb-16-1.8-tRNS.png differ diff --git a/contrib/testpngs/rgb-16-1.8.png b/contrib/testpngs/rgb-16-1.8.png new file mode 100644 index 000000000..03251b12e Binary files /dev/null and b/contrib/testpngs/rgb-16-1.8.png differ diff --git a/contrib/testpngs/rgb-16-linear-tRNS.png b/contrib/testpngs/rgb-16-linear-tRNS.png new file mode 100644 index 000000000..3dfa6a6ad Binary files /dev/null and b/contrib/testpngs/rgb-16-linear-tRNS.png differ diff --git a/contrib/testpngs/rgb-16-linear.png b/contrib/testpngs/rgb-16-linear.png new file mode 100644 index 000000000..3dfa6a6ad Binary files /dev/null and b/contrib/testpngs/rgb-16-linear.png differ diff --git a/contrib/testpngs/rgb-16-sRGB-tRNS.png b/contrib/testpngs/rgb-16-sRGB-tRNS.png new file mode 100644 index 000000000..2cf2209e0 Binary files /dev/null and b/contrib/testpngs/rgb-16-sRGB-tRNS.png differ diff --git a/contrib/testpngs/rgb-16-sRGB.png b/contrib/testpngs/rgb-16-sRGB.png new file mode 100644 index 000000000..2cf2209e0 Binary files /dev/null and b/contrib/testpngs/rgb-16-sRGB.png differ diff --git a/contrib/testpngs/rgb-16-tRNS.png b/contrib/testpngs/rgb-16-tRNS.png new file mode 100644 index 000000000..28643528d Binary files /dev/null and b/contrib/testpngs/rgb-16-tRNS.png differ diff --git a/contrib/testpngs/rgb-16.png b/contrib/testpngs/rgb-16.png new file mode 100644 index 000000000..28643528d Binary files /dev/null and b/contrib/testpngs/rgb-16.png differ diff --git a/contrib/testpngs/rgb-8-1.8-tRNS.png b/contrib/testpngs/rgb-8-1.8-tRNS.png new file mode 100644 index 000000000..afff9df22 Binary files /dev/null and b/contrib/testpngs/rgb-8-1.8-tRNS.png differ diff --git a/contrib/testpngs/rgb-8-1.8.png b/contrib/testpngs/rgb-8-1.8.png new file mode 100644 index 000000000..d4bb12afa Binary files /dev/null and b/contrib/testpngs/rgb-8-1.8.png differ diff --git a/contrib/testpngs/rgb-8-linear-tRNS.png b/contrib/testpngs/rgb-8-linear-tRNS.png new file mode 100644 index 000000000..5a2ed9f00 Binary files /dev/null and b/contrib/testpngs/rgb-8-linear-tRNS.png differ diff --git a/contrib/testpngs/rgb-8-linear.png b/contrib/testpngs/rgb-8-linear.png new file mode 100644 index 000000000..7c42b0840 Binary files /dev/null and b/contrib/testpngs/rgb-8-linear.png differ diff --git a/contrib/testpngs/rgb-8-sRGB-tRNS.png b/contrib/testpngs/rgb-8-sRGB-tRNS.png new file mode 100644 index 000000000..f8b4ecbdc Binary files /dev/null and b/contrib/testpngs/rgb-8-sRGB-tRNS.png differ diff --git a/contrib/testpngs/rgb-8-sRGB.png b/contrib/testpngs/rgb-8-sRGB.png new file mode 100644 index 000000000..4acae649d Binary files /dev/null and b/contrib/testpngs/rgb-8-sRGB.png differ diff --git a/contrib/testpngs/rgb-8-tRNS.png b/contrib/testpngs/rgb-8-tRNS.png new file mode 100644 index 000000000..cdb1642eb Binary files /dev/null and b/contrib/testpngs/rgb-8-tRNS.png differ diff --git a/contrib/testpngs/rgb-8.png b/contrib/testpngs/rgb-8.png new file mode 100644 index 000000000..e69c71bfd Binary files /dev/null and b/contrib/testpngs/rgb-8.png differ diff --git a/contrib/testpngs/rgb-alpha-16-1.8.png b/contrib/testpngs/rgb-alpha-16-1.8.png new file mode 100644 index 000000000..ad65d150e Binary files /dev/null and b/contrib/testpngs/rgb-alpha-16-1.8.png differ diff --git a/contrib/testpngs/rgb-alpha-16-linear.png b/contrib/testpngs/rgb-alpha-16-linear.png new file mode 100644 index 000000000..1f3990031 Binary files /dev/null and b/contrib/testpngs/rgb-alpha-16-linear.png differ diff --git a/contrib/testpngs/rgb-alpha-16-sRGB.png b/contrib/testpngs/rgb-alpha-16-sRGB.png new file mode 100644 index 000000000..d9cea633a Binary files /dev/null and b/contrib/testpngs/rgb-alpha-16-sRGB.png differ diff --git a/contrib/testpngs/rgb-alpha-16.png b/contrib/testpngs/rgb-alpha-16.png new file mode 100644 index 000000000..59262397e Binary files /dev/null and b/contrib/testpngs/rgb-alpha-16.png differ diff --git a/contrib/testpngs/rgb-alpha-8-1.8.png b/contrib/testpngs/rgb-alpha-8-1.8.png new file mode 100644 index 000000000..f4d08ec04 Binary files /dev/null and b/contrib/testpngs/rgb-alpha-8-1.8.png differ diff --git a/contrib/testpngs/rgb-alpha-8-linear.png b/contrib/testpngs/rgb-alpha-8-linear.png new file mode 100644 index 000000000..b4f8bc829 Binary files /dev/null and b/contrib/testpngs/rgb-alpha-8-linear.png differ diff --git a/contrib/testpngs/rgb-alpha-8-sRGB.png b/contrib/testpngs/rgb-alpha-8-sRGB.png new file mode 100644 index 000000000..f06e7f837 Binary files /dev/null and b/contrib/testpngs/rgb-alpha-8-sRGB.png differ diff --git a/contrib/testpngs/rgb-alpha-8.png b/contrib/testpngs/rgb-alpha-8.png new file mode 100644 index 000000000..e15d4913f Binary files /dev/null and b/contrib/testpngs/rgb-alpha-8.png differ diff --git a/pngread.c b/pngread.c index 5295bbcaa..5e9ca7066 100644 --- a/pngread.c +++ b/pngread.c @@ -756,7 +756,7 @@ png_read_destroy(png_structrp png_ptr) if (png_ptr->zstream.state != NULL) { int ret = inflateEnd(&png_ptr->zstream); - + if (ret != Z_OK) { png_zstream_error(png_ptr, ret); @@ -1081,7 +1081,7 @@ typedef struct png_voidp first_row; ptrdiff_t row_bytes; /* step between rows */ int file_encoding; /* E_ values above */ - png_fixed_point gamma_to_linear; /* For P_FILE, reciprocal of gamma */ + png_fixed_point file_to_sRGB; /* Cached correction factor */ int colormap_processing; /* PNG_CMAP_ values above */ } png_image_read_control; @@ -1445,20 +1445,15 @@ png_image_skip_unused_chunks(png_structrp png_ptr) static void set_file_encoding(png_image_read_control *display) { + /* First test for an encoding close to linear: */ if (png_need_gamma_correction(display->image->opaque->png_ptr, 0/*PNG gamma*/, 0/*not sRGB*/)) { png_fixed_point g = display->image->opaque->png_ptr->colorspace.gamma; + /* Now look for one close to sRGB: */ if (png_gamma_not_sRGB(g)) - { display->file_encoding = P_FILE; - /* Record the reciprocal of 'g', the colorspace gamma. If this - * overflows just store FP_1. - */ - if (!png_muldiv(&display->gamma_to_linear, PNG_FP_1, PNG_FP_1, g)) - display->gamma_to_linear = PNG_FP_1; - } else display->file_encoding = P_sRGB; @@ -1468,6 +1463,96 @@ set_file_encoding(png_image_read_control *display) display->file_encoding = P_LINEAR8; } +/* For colormap entries we end up doing the gamma correction here and the + * following routines are provided to separate out the code. In all cases the + * input value is in the range 0..255 and is encoded P_FILE with the gamma value + * stored in the png_struct colorspace. + */ +static void +init_correct(png_const_structrp png_ptr, png_fixed_point *correct) +{ + /* Record the convertion necessary to get from the encoding values to + * sRGB. If this overflows just store FP_1. + * + * NOTE: this code used to store, and use, a convertion factor to + * linear then use the sRGB encoding tables to get back to sRGB, but + * this smashes the low values; the ones which fall in the linear part + * of the sRGB transfer function. + * + * The new version of this code assumes an encoding which is neither + * linear nor sRGB is a power law transform of the sRGB curve, not + * linear values. This is somewhat at odds with a precise reading of + * the PNG spec, but given that we are trying to produce sRGB values + * here it is most likely to be correct. + */ + affirm(png_ptr->colorspace.gamma > 0); + + if (!png_muldiv(correct, PNG_GAMMA_sRGB_INVERSE, PNG_FP_1, + png_ptr->colorspace.gamma)) + *correct = PNG_FP_1; +} + +static png_uint_32 +convert_to_sRGB(png_image_read_control *display, png_uint_32 value) +{ + /* Converts an 8-bit value from P_FILE to P_sRGB */ + png_const_structrp png_ptr = display->image->opaque->png_ptr; + + affirm(value <= 255U); + + if (display->file_to_sRGB == 0) + init_correct(png_ptr, &display->file_to_sRGB); + + /* Now simply apply this correction factor and scale back to 8 bits. */ + if (display->file_to_sRGB != PNG_FP_1) + value = PNG_DIV257( + png_gamma_16bit_correct(png_ptr, value*257U, display->file_to_sRGB)); + + return value; +} + +static png_uint_32 +convert_to_linear(png_image_read_control *display, png_uint_32 value) +{ + /* Converts an 8-bit value from P_FILE to 16-bit P_LINEAR */ + png_const_structrp png_ptr = display->image->opaque->png_ptr; + + affirm(value <= 255U); + + if (display->file_to_sRGB == 0) + init_correct(png_ptr, &display->file_to_sRGB); + + /* Use this correct to get a 16-bit sRGB value: */ + value *= 257U; + + if (display->file_to_sRGB != PNG_FP_1) + value = png_gamma_16bit_correct(png_ptr, value, display->file_to_sRGB); + + /* Now convert this back to linear, using the correct transfer function. */ + if (value <= 2650U /* 65535 * 0.04045 */) + { + /* We want to divide a 12-bit number by 12.92, do this by scaling to 32 + * bits then dividing by 2^24, with rounding: + */ + value = (value * 1298546U + 649273U) >> 24; + } + + else + { + /* Calculate for v in the range 0.04045..1.0 calculate: + * + * ((v + 0.055)/1.055)^2.4 + * + * the gamma correction function needs a 16-bit value: + */ + value *= 62119U; + value += 223904831U+32768U; /* cannot overflow; test with 65535 */ + value = png_gamma_16bit_correct(png_ptr, value >> 16, 240000); + } + + return value; +} + static unsigned int decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding) { @@ -1483,8 +1568,7 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding) switch (encoding) { case P_FILE: - value = png_gamma_16bit_correct(display->image->opaque->png_ptr, - value*257, display->gamma_to_linear); + value = convert_to_linear(display, value); break; case P_sRGB: @@ -1567,31 +1651,26 @@ png_create_colormap_entry(png_image_read_control *display, if (display->file_encoding == P_NOTSET) set_file_encoding(display); - /* Note that the cached value may be P_FILE too, but if it is then the - * gamma_to_linear member has been set. - */ + /* Note that the cached value may be P_FILE too. */ encoding = display->file_encoding; } if (encoding == P_FILE) { - png_fixed_point g = display->gamma_to_linear; - - red = png_gamma_16bit_correct(png_ptr, red*257, g); - green = png_gamma_16bit_correct(png_ptr, green*257, g); - blue = png_gamma_16bit_correct(png_ptr, blue*257, g); - if (convert_to_Y != 0 || output_encoding == P_LINEAR) { + red = convert_to_linear(display, red); + green = convert_to_linear(display, green); + blue = convert_to_linear(display, blue); alpha *= 257; encoding = P_LINEAR; } else { - red = PNG_sRGB_FROM_LINEAR(png_ptr, red * 255); - green = PNG_sRGB_FROM_LINEAR(png_ptr, green * 255); - blue = PNG_sRGB_FROM_LINEAR(png_ptr, blue * 255); + red = convert_to_sRGB(display, red); + green = convert_to_sRGB(display, green); + blue = convert_to_sRGB(display, blue); encoding = P_sRGB; } } @@ -1960,7 +2039,12 @@ png_image_read_colormap(png_voidp argument) else png_ptr->colorspace.gamma = PNG_GAMMA_sRGB_INVERSE; - png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; + /* Make sure libpng doesn't ignore the setting: */ + if (png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) + png_ptr->colorspace.flags = PNG_COLORSPACE_HAVE_GAMMA; + + else + png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA; } /* Decide what to do based on the PNG color type of the input data. The diff --git a/pngrtran.c b/pngrtran.c index 98ef61569..df317d2fc 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -4926,10 +4926,7 @@ png_do_background_alpha_GA(png_transformp *transform, png_transform_controlp tc) case 65535U: /* opaque */ if (copy) - { memcpy(dp, sp, 4U); - UNTESTED - } break; }