[libpng16] Corrected simplified API default gamma for color-mapped output, added

a flag to change default. In 1.6.0 when the simplified API was used
to produce color-mapped output from an input image with no gamma
information the gamma assumed for the input could be different from
that assumed for non-color-mapped output.  In particular 16-bit depth
input files were assumed to be sRGB encoded, whereas in the 'direct'
case they were assumed to have linear data.  This was an error.  The
fix makes the simplified API treat all input files the same way and
adds a new flag to the png_image::flags member to allow the
application/user to specify that 16-bit files contain sRGB data
rather than the default linear.
Fixed bugs in the pngpixel and makepng test programs.
This commit is contained in:
John Bowler
2013-03-06 22:15:25 -06:00
committed by Glenn Randers-Pehrson
parent 1f24cb74f2
commit 59ae38984f
7 changed files with 90 additions and 14 deletions

View File

@@ -37,7 +37,7 @@ component(png_const_bytep row, png_uint_32 x, unsigned int c,
* bytes wide. Since the row fitted into memory, however, the following must
* work:
*/
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels + c);
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels);
png_uint_32 bit_offset_lo = bit_depth * ((x & 0x3f) * channels + c);
row = (png_const_bytep)(((PNG_CONST png_byte (*)[8])row) + bit_offset_hi);

View File

@@ -440,7 +440,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
/* Palette with fixed color: the image rows are all 0 and the image width
* is 16.
*/
memset(row, rowbytes, 0);
memset(row, 0, rowbytes);
}
else if (colors[0] == channels_of_type(color_type))
@@ -624,8 +624,8 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
gamma_table[0] = 0;
for (i=0; i<255; ++i)
gamma_table[i] = (png_byte)floor(pow(i/255.,conv) * 255 + 127.5);
for (i=1; i<255; ++i)
gamma_table[i] = (png_byte)floor(pow(i/255.,conv) * 255 + .5);
gamma_table[255] = 255;
}

View File

@@ -315,6 +315,7 @@ compare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)
#define KEEP_GOING 32
#define ACCUMULATE 64
#define FAST_WRITE 128
#define sRGB_16BIT 256
static void
print_opts(png_uint_32 opts)
@@ -335,6 +336,8 @@ print_opts(png_uint_32 opts)
printf(" --accumulate");
if (!(opts & FAST_WRITE)) /* --fast is currently the default */
printf(" --slow");
if (opts & sRGB_16BIT)
printf(" --sRGB-16bit");
}
#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */
@@ -3026,6 +3029,10 @@ read_file(Image *image, png_uint_32 format, png_const_colorp background)
return logerror(image, "file init: ", image->file_name, "");
}
/* This must be set after the begin_read call: */
if (image->opts & sRGB_16BIT)
image->image.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;
/* Have an initialized image with all the data we need plus, maybe, an
* allocated file (myfile) or buffer (mybuffer) that need to be freed.
*/
@@ -3488,6 +3495,10 @@ main(int argc, char **argv)
opts &= ~KEEP_GOING;
else if (strcmp(arg, "--strict") == 0)
opts |= STRICT;
else if (strcmp(arg, "--sRGB-16bit") == 0)
opts |= sRGB_16BIT;
else if (strcmp(arg, "--linear-16bit") == 0)
opts &= ~sRGB_16BIT;
else if (strcmp(arg, "--tmpfile") == 0)
{
if (c+1 < argc)