mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[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:
201
pngread.c
201
pngread.c
@@ -1125,12 +1125,11 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
|
||||
/* Arguments to png_image_finish_read: */
|
||||
|
||||
/* Encoding of PNG data (used by the color-map code) */
|
||||
/* TODO: change these, dang, ANSI-C reserves the 'E' namespace. */
|
||||
# define E_NOTSET 0 /* File encoding not yet known */
|
||||
# define E_sRGB 1 /* 8-bit encoded to sRGB gamma */
|
||||
# define E_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
|
||||
# define E_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
|
||||
# define E_LINEAR8 4 /* 8-bit linear: only from a file value */
|
||||
# define P_NOTSET 0 /* File encoding not yet known */
|
||||
# define P_sRGB 1 /* 8-bit encoded to sRGB gamma */
|
||||
# define P_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
|
||||
# define P_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
|
||||
# define P_LINEAR8 4 /* 8-bit linear: only from a file value */
|
||||
|
||||
/* Color-map processing: after libpng has run on the PNG image further
|
||||
* processing may be needed to conver the data to color-map indicies.
|
||||
@@ -1161,7 +1160,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 E_FILE, reciprocal of gamma */
|
||||
png_fixed_point gamma_to_linear; /* For P_FILE, reciprocal of gamma */
|
||||
int colormap_processing; /* PNG_CMAP_ values above */
|
||||
} png_image_read_control;
|
||||
|
||||
@@ -1293,7 +1292,7 @@ png_image_read_header(png_voidp argument)
|
||||
#ifdef PNG_COLORSPACE_SUPPORTED
|
||||
/* Does the colorspace match sRGB? If there is no color endpoint
|
||||
* (colorant) information assume yes, otherwise require the
|
||||
* 'ENDPOINTS_MATCHE_sRGB' colorspace flag to have been set. If the
|
||||
* 'ENDPOINTS_MATCHP_sRGB' colorspace flag to have been set. If the
|
||||
* colorspace has been determined to be invalid ignore it.
|
||||
*/
|
||||
if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags
|
||||
@@ -1482,17 +1481,24 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
|
||||
*
|
||||
* Or image data handling:
|
||||
*
|
||||
* tRNS, bKGD, gAMA, cHRM, sRGB, iCCP and sBIT.
|
||||
* tRNS, bKGD, gAMA, cHRM, sRGB, [iCCP] and sBIT.
|
||||
*
|
||||
* This provides a small performance improvement and eliminates any
|
||||
* potential vulnerability to security problems in the unused chunks.
|
||||
*
|
||||
* At present the iCCP chunk data isn't used, so iCCP chunk can be ignored
|
||||
* too. This allows the simplified API to be compiled without iCCP support,
|
||||
* however if the support is there the chunk is still checked to detect
|
||||
* errors (which are unfortunately quite common.)
|
||||
*/
|
||||
{
|
||||
static PNG_CONST png_byte chunks_to_process[] = {
|
||||
98, 75, 71, 68, '\0', /* bKGD */
|
||||
99, 72, 82, 77, '\0', /* cHRM */
|
||||
103, 65, 77, 65, '\0', /* gAMA */
|
||||
# ifdef PNG_READ_iCCP_SUPPORTED
|
||||
105, 67, 67, 80, '\0', /* iCCP */
|
||||
# endif
|
||||
115, 66, 73, 84, '\0', /* sBIT */
|
||||
115, 82, 71, 66, '\0', /* sRGB */
|
||||
};
|
||||
@@ -1529,25 +1535,25 @@ set_file_encoding(png_image_read_control *display)
|
||||
{
|
||||
if (png_gamma_not_sRGB(g))
|
||||
{
|
||||
display->file_encoding = E_FILE;
|
||||
display->file_encoding = P_FILE;
|
||||
display->gamma_to_linear = png_reciprocal(g);
|
||||
}
|
||||
|
||||
else
|
||||
display->file_encoding = E_sRGB;
|
||||
display->file_encoding = P_sRGB;
|
||||
}
|
||||
|
||||
else
|
||||
display->file_encoding = E_LINEAR8;
|
||||
display->file_encoding = P_LINEAR8;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
|
||||
{
|
||||
if (encoding == E_FILE) /* double check */
|
||||
if (encoding == P_FILE) /* double check */
|
||||
encoding = display->file_encoding;
|
||||
|
||||
if (encoding == E_NOTSET) /* must be the file encoding */
|
||||
if (encoding == P_NOTSET) /* must be the file encoding */
|
||||
{
|
||||
set_file_encoding(display);
|
||||
encoding = display->file_encoding;
|
||||
@@ -1555,18 +1561,18 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
|
||||
|
||||
switch (encoding)
|
||||
{
|
||||
case E_FILE:
|
||||
case P_FILE:
|
||||
value = png_gamma_16bit_correct(value*257, display->gamma_to_linear);
|
||||
break;
|
||||
|
||||
case E_sRGB:
|
||||
case P_sRGB:
|
||||
value = png_sRGB_table[value];
|
||||
break;
|
||||
|
||||
case E_LINEAR:
|
||||
case P_LINEAR:
|
||||
break;
|
||||
|
||||
case E_LINEAR8:
|
||||
case P_LINEAR8:
|
||||
value *= 257;
|
||||
break;
|
||||
|
||||
@@ -1585,9 +1591,9 @@ png_colormap_compose(png_image_read_control *display,
|
||||
png_uint_32 background, int encoding)
|
||||
{
|
||||
/* The file value is composed on the background, the background has the given
|
||||
* encoding and so does the result, the file is encoded with E_FILE and the
|
||||
* encoding and so does the result, the file is encoded with P_FILE and the
|
||||
* file and alpha are 8-bit values. The (output) encoding will always be
|
||||
* E_LINEAR or E_sRGB.
|
||||
* P_LINEAR or P_sRGB.
|
||||
*/
|
||||
png_uint_32 f = decode_gamma(display, foreground, foreground_encoding);
|
||||
png_uint_32 b = decode_gamma(display, background, encoding);
|
||||
@@ -1597,7 +1603,7 @@ png_colormap_compose(png_image_read_control *display,
|
||||
*/
|
||||
f = f * alpha + b * (255-alpha);
|
||||
|
||||
if (encoding == E_LINEAR)
|
||||
if (encoding == P_LINEAR)
|
||||
{
|
||||
/* Scale to 65535; divide by 255, approximately (in fact this is extremely
|
||||
* accurate, it divides by 255.00000005937181414556, with no overflow.)
|
||||
@@ -1607,13 +1613,13 @@ png_colormap_compose(png_image_read_control *display,
|
||||
f = (f+32768) >> 16;
|
||||
}
|
||||
|
||||
else /* E_sRGB */
|
||||
else /* P_sRGB */
|
||||
f = PNG_sRGB_FROM_LINEAR(f);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* NOTE: E_LINEAR values to this routine must be 16-bit, but E_FILE values must
|
||||
/* NOTE: P_LINEAR values to this routine must be 16-bit, but P_FILE values must
|
||||
* be 8-bit.
|
||||
*/
|
||||
static void
|
||||
@@ -1623,7 +1629,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
{
|
||||
png_imagep image = display->image;
|
||||
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) ?
|
||||
E_LINEAR : E_sRGB;
|
||||
P_LINEAR : P_sRGB;
|
||||
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
|
||||
(red != green || green != blue);
|
||||
|
||||
@@ -1633,18 +1639,18 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
/* Update the cache with whether the file gamma is significantly different
|
||||
* from sRGB.
|
||||
*/
|
||||
if (encoding == E_FILE)
|
||||
if (encoding == P_FILE)
|
||||
{
|
||||
if (display->file_encoding == E_NOTSET)
|
||||
if (display->file_encoding == P_NOTSET)
|
||||
set_file_encoding(display);
|
||||
|
||||
/* Note that the cached value may be E_FILE too, but if it is then the
|
||||
/* Note that the cached value may be P_FILE too, but if it is then the
|
||||
* gamma_to_linear member has been set.
|
||||
*/
|
||||
encoding = display->file_encoding;
|
||||
}
|
||||
|
||||
if (encoding == E_FILE)
|
||||
if (encoding == P_FILE)
|
||||
{
|
||||
png_fixed_point g = display->gamma_to_linear;
|
||||
|
||||
@@ -1652,10 +1658,10 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
green = png_gamma_16bit_correct(green*257, g);
|
||||
blue = png_gamma_16bit_correct(blue*257, g);
|
||||
|
||||
if (convert_to_Y || output_encoding == E_LINEAR)
|
||||
if (convert_to_Y || output_encoding == P_LINEAR)
|
||||
{
|
||||
alpha *= 257;
|
||||
encoding = E_LINEAR;
|
||||
encoding = P_LINEAR;
|
||||
}
|
||||
|
||||
else
|
||||
@@ -1663,11 +1669,11 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
red = PNG_sRGB_FROM_LINEAR(red * 255);
|
||||
green = PNG_sRGB_FROM_LINEAR(green * 255);
|
||||
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
|
||||
encoding = E_sRGB;
|
||||
encoding = P_sRGB;
|
||||
}
|
||||
}
|
||||
|
||||
else if (encoding == E_LINEAR8)
|
||||
else if (encoding == P_LINEAR8)
|
||||
{
|
||||
/* This encoding occurs quite frequently in test cases because PngSuite
|
||||
* includes a gAMA 1.0 chunk with most images.
|
||||
@@ -1676,10 +1682,10 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
green *= 257;
|
||||
blue *= 257;
|
||||
alpha *= 257;
|
||||
encoding = E_LINEAR;
|
||||
encoding = P_LINEAR;
|
||||
}
|
||||
|
||||
else if (encoding == E_sRGB && (convert_to_Y || output_encoding == E_LINEAR))
|
||||
else if (encoding == P_sRGB && (convert_to_Y || output_encoding == P_LINEAR))
|
||||
{
|
||||
/* The values are 8-bit sRGB values, but must be converted to 16-bit
|
||||
* linear.
|
||||
@@ -1688,11 +1694,11 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
green = png_sRGB_table[green];
|
||||
blue = png_sRGB_table[blue];
|
||||
alpha *= 257;
|
||||
encoding = E_LINEAR;
|
||||
encoding = P_LINEAR;
|
||||
}
|
||||
|
||||
/* This is set if the color isn't gray but the output is. */
|
||||
if (encoding == E_LINEAR)
|
||||
if (encoding == P_LINEAR)
|
||||
{
|
||||
if (convert_to_Y)
|
||||
{
|
||||
@@ -1700,7 +1706,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
png_uint_32 y = (png_uint_32)6968 * red + (png_uint_32)23434 * green +
|
||||
(png_uint_32)2366 * blue;
|
||||
|
||||
if (output_encoding == E_LINEAR)
|
||||
if (output_encoding == P_LINEAR)
|
||||
y = (y + 16384) >> 15;
|
||||
|
||||
else
|
||||
@@ -1709,19 +1715,19 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
y = (y + 128) >> 8;
|
||||
y *= 255;
|
||||
y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7);
|
||||
encoding = E_sRGB;
|
||||
encoding = P_sRGB;
|
||||
}
|
||||
|
||||
blue = red = green = y;
|
||||
}
|
||||
|
||||
else if (output_encoding == E_sRGB)
|
||||
else if (output_encoding == P_sRGB)
|
||||
{
|
||||
red = PNG_sRGB_FROM_LINEAR(red * 255);
|
||||
green = PNG_sRGB_FROM_LINEAR(green * 255);
|
||||
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
|
||||
alpha = PNG_DIV257(alpha);
|
||||
encoding = E_sRGB;
|
||||
encoding = P_sRGB;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1730,7 +1736,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
|
||||
/* Store the value. */
|
||||
{
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
|
||||
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
|
||||
# else
|
||||
@@ -1742,7 +1748,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
# define bgr 0
|
||||
# endif
|
||||
|
||||
if (output_encoding == E_LINEAR)
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
png_uint_16p entry = png_voidcast(png_uint_16p, display->colormap);
|
||||
|
||||
@@ -1797,7 +1803,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
}
|
||||
}
|
||||
|
||||
else /* output encoding is E_sRGB */
|
||||
else /* output encoding is P_sRGB */
|
||||
{
|
||||
png_bytep entry = png_voidcast(png_bytep, display->colormap);
|
||||
|
||||
@@ -1839,7 +1845,7 @@ make_gray_file_colormap(png_image_read_control *display)
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i<256; ++i)
|
||||
png_create_colormap_entry(display, i, i, i, i, 255, E_FILE);
|
||||
png_create_colormap_entry(display, i, i, i, i, 255, P_FILE);
|
||||
|
||||
return i;
|
||||
}
|
||||
@@ -1850,7 +1856,7 @@ make_gray_colormap(png_image_read_control *display)
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i<256; ++i)
|
||||
png_create_colormap_entry(display, i, i, i, i, 255, E_sRGB);
|
||||
png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB);
|
||||
|
||||
return i;
|
||||
}
|
||||
@@ -1889,13 +1895,13 @@ make_ga_colormap(png_image_read_control *display)
|
||||
while (i < 231)
|
||||
{
|
||||
unsigned int gray = (i * 256 + 115) / 231;
|
||||
png_create_colormap_entry(display, i++, gray, gray, gray, 255, E_sRGB);
|
||||
png_create_colormap_entry(display, i++, gray, gray, gray, 255, P_sRGB);
|
||||
}
|
||||
|
||||
/* 255 is used here for the component values for consistency with the code
|
||||
* that undoes premultiplication in pngwrite.c.
|
||||
*/
|
||||
png_create_colormap_entry(display, i++, 255, 255, 255, 0, E_sRGB);
|
||||
png_create_colormap_entry(display, i++, 255, 255, 255, 0, P_sRGB);
|
||||
|
||||
for (a=1; a<5; ++a)
|
||||
{
|
||||
@@ -1903,7 +1909,7 @@ make_ga_colormap(png_image_read_control *display)
|
||||
|
||||
for (g=0; g<6; ++g)
|
||||
png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,
|
||||
E_sRGB);
|
||||
P_sRGB);
|
||||
}
|
||||
|
||||
return i;
|
||||
@@ -1927,7 +1933,7 @@ make_rgb_colormap(png_image_read_control *display)
|
||||
|
||||
for (b=0; b<6; ++b)
|
||||
png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,
|
||||
E_sRGB);
|
||||
P_sRGB);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1950,11 +1956,11 @@ png_image_read_colormap(png_voidp argument)
|
||||
const png_structrp png_ptr = image->opaque->png_ptr;
|
||||
const png_uint_32 output_format = image->format;
|
||||
const int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) ?
|
||||
E_LINEAR : E_sRGB;
|
||||
P_LINEAR : P_sRGB;
|
||||
|
||||
unsigned int cmap_entries;
|
||||
unsigned int output_processing; /* Output processing option */
|
||||
unsigned int data_encoding = E_NOTSET; /* Encoding libpng must produce */
|
||||
unsigned int data_encoding = P_NOTSET; /* Encoding libpng must produce */
|
||||
|
||||
/* Background information; the background color and the index of this color
|
||||
* in the color-map if it exists (else 256).
|
||||
@@ -1974,7 +1980,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_ptr->num_trans > 0) /* alpha in input */ &&
|
||||
((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) /* no alpha in output */)
|
||||
{
|
||||
if (output_encoding == E_LINEAR) /* compose on black */
|
||||
if (output_encoding == P_LINEAR) /* compose on black */
|
||||
back_b = back_g = back_r = 0;
|
||||
|
||||
else if (display->background == NULL /* no way to remove it */)
|
||||
@@ -1998,7 +2004,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
}
|
||||
}
|
||||
|
||||
else if (output_encoding == E_LINEAR)
|
||||
else if (output_encoding == P_LINEAR)
|
||||
back_b = back_r = back_g = 65535;
|
||||
|
||||
else
|
||||
@@ -2056,7 +2062,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
trans = png_ptr->trans_color.gray;
|
||||
|
||||
if ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0)
|
||||
back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
|
||||
back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
|
||||
}
|
||||
|
||||
/* png_create_colormap_entry just takes an RGBA and writes the
|
||||
@@ -2074,7 +2080,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
if (i != trans)
|
||||
png_create_colormap_entry(display, i, val, val, val, 255,
|
||||
E_FILE/*8-bit with file gamma*/);
|
||||
P_FILE/*8-bit with file gamma*/);
|
||||
|
||||
/* Else this entry is transparent. The colors don't matter if
|
||||
* there is an alpha channel (back_alpha == 0), but it does no
|
||||
@@ -2090,7 +2096,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
}
|
||||
|
||||
/* We need libpng to preserve the original encoding. */
|
||||
data_encoding = E_FILE;
|
||||
data_encoding = P_FILE;
|
||||
|
||||
/* The rows from libpng, while technically gray values, are now also
|
||||
* color-map indicies; however, they may need to be expanded to 1
|
||||
@@ -2119,7 +2125,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* ensuring that the corresponding gray level matches the background
|
||||
* color exactly.
|
||||
*/
|
||||
data_encoding = E_sRGB;
|
||||
data_encoding = P_sRGB;
|
||||
|
||||
if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)
|
||||
png_error(png_ptr, "gray[16] color-map: too few entries");
|
||||
@@ -2143,7 +2149,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_color_16 c;
|
||||
png_uint_32 gray = back_g;
|
||||
|
||||
if (output_encoding == E_LINEAR)
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
|
||||
|
||||
@@ -2151,7 +2157,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* matches.
|
||||
*/
|
||||
png_create_colormap_entry(display, gray, back_g, back_g,
|
||||
back_g, 65535, E_LINEAR);
|
||||
back_g, 65535, P_LINEAR);
|
||||
}
|
||||
|
||||
/* The background passed to libpng, however, must be the
|
||||
@@ -2172,7 +2178,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
break;
|
||||
}
|
||||
|
||||
back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
|
||||
back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
|
||||
}
|
||||
|
||||
/* output_processing means that the libpng-processed row will be
|
||||
@@ -2209,7 +2215,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* worry about tRNS matching - tRNS is ignored if there is an alpha
|
||||
* channel.
|
||||
*/
|
||||
data_encoding = E_sRGB;
|
||||
data_encoding = P_sRGB;
|
||||
|
||||
if (output_format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
@@ -2252,13 +2258,13 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
cmap_entries = make_gray_colormap(display);
|
||||
|
||||
if (output_encoding == E_LINEAR)
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
|
||||
|
||||
/* And make sure the corresponding palette entry matches. */
|
||||
png_create_colormap_entry(display, gray, back_g, back_g,
|
||||
back_g, 65535, E_LINEAR);
|
||||
back_g, 65535, P_LINEAR);
|
||||
}
|
||||
|
||||
/* The background passed to libpng, however, must be the sRGB
|
||||
@@ -2289,7 +2295,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
{
|
||||
png_uint_32 gray = (i * 256 + 115) / 231;
|
||||
png_create_colormap_entry(display, i++, gray, gray, gray,
|
||||
255, E_sRGB);
|
||||
255, P_sRGB);
|
||||
}
|
||||
|
||||
/* NOTE: this preserves the full precision of the application
|
||||
@@ -2297,7 +2303,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
background_index = i;
|
||||
png_create_colormap_entry(display, i++, back_r, back_g, back_b,
|
||||
output_encoding == E_LINEAR ? 65535U : 255U, output_encoding);
|
||||
output_encoding == P_LINEAR ? 65535U : 255U, output_encoding);
|
||||
|
||||
/* For non-opaque input composite on the sRGB background - this
|
||||
* requires inverting the encoding for each component. The input
|
||||
@@ -2307,7 +2313,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* represents. Consequently 'G' is always sRGB encoded, while
|
||||
* 'A' is linear. We need the linear background colors.
|
||||
*/
|
||||
if (output_encoding == E_sRGB) /* else already linear */
|
||||
if (output_encoding == P_sRGB) /* else already linear */
|
||||
{
|
||||
/* This may produce a value not exactly matching the
|
||||
* background, but that's ok because these numbers are only
|
||||
@@ -2337,7 +2343,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_create_colormap_entry(display, i++,
|
||||
PNG_sRGB_FROM_LINEAR(gray + back_rx),
|
||||
PNG_sRGB_FROM_LINEAR(gray + back_gx),
|
||||
PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, E_sRGB);
|
||||
PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2364,7 +2370,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
|
||||
-1);
|
||||
data_encoding = E_sRGB;
|
||||
data_encoding = P_sRGB;
|
||||
|
||||
/* The output will now be one or two 8-bit gray or gray+alpha
|
||||
* channels. The more complex case arises when the input has alpha.
|
||||
@@ -2409,7 +2415,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_gamma_not_sRGB(png_ptr->colorspace.gamma))
|
||||
{
|
||||
cmap_entries = make_gray_file_colormap(display);
|
||||
data_encoding = E_FILE;
|
||||
data_encoding = P_FILE;
|
||||
}
|
||||
|
||||
else
|
||||
@@ -2428,18 +2434,18 @@ png_image_read_colormap(png_voidp argument)
|
||||
* it. Achieve this simply by ensuring that the entry
|
||||
* selected for the background really is the background color.
|
||||
*/
|
||||
if (data_encoding == E_FILE) /* from the fixup above */
|
||||
if (data_encoding == P_FILE) /* from the fixup above */
|
||||
{
|
||||
/* The app supplied a gray which is in output_encoding, we
|
||||
* need to convert it to a value of the input (E_FILE)
|
||||
* need to convert it to a value of the input (P_FILE)
|
||||
* encoding then set this palette entry to the required
|
||||
* output encoding.
|
||||
*/
|
||||
if (output_encoding == E_sRGB)
|
||||
gray = png_sRGB_table[gray]; /* now E_LINEAR */
|
||||
if (output_encoding == P_sRGB)
|
||||
gray = png_sRGB_table[gray]; /* now P_LINEAR */
|
||||
|
||||
gray = PNG_DIV257(png_gamma_16bit_correct(gray,
|
||||
png_ptr->colorspace.gamma)); /* now E_FILE */
|
||||
png_ptr->colorspace.gamma)); /* now P_FILE */
|
||||
|
||||
/* And make sure the corresponding palette entry contains
|
||||
* exactly the required sRGB value.
|
||||
@@ -2448,14 +2454,14 @@ png_image_read_colormap(png_voidp argument)
|
||||
back_g, 0/*unused*/, output_encoding);
|
||||
}
|
||||
|
||||
else if (output_encoding == E_LINEAR)
|
||||
else if (output_encoding == P_LINEAR)
|
||||
{
|
||||
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
|
||||
|
||||
/* And make sure the corresponding palette entry matches.
|
||||
*/
|
||||
png_create_colormap_entry(display, gray, back_g, back_g,
|
||||
back_g, 0/*unused*/, E_LINEAR);
|
||||
back_g, 0/*unused*/, P_LINEAR);
|
||||
}
|
||||
|
||||
/* The background passed to libpng, however, must be the
|
||||
@@ -2485,7 +2491,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* to do it once and using PNG_DIV51 on the 6x6x6 reduced RGB cube.
|
||||
* Consequently we always want libpng to produce sRGB data.
|
||||
*/
|
||||
data_encoding = E_sRGB;
|
||||
data_encoding = P_sRGB;
|
||||
|
||||
/* Is there any transparency or alpha? */
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
@@ -2505,7 +2511,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
/* Add a transparent entry. */
|
||||
png_create_colormap_entry(display, cmap_entries, 255, 255,
|
||||
255, 0, E_sRGB);
|
||||
255, 0, P_sRGB);
|
||||
|
||||
/* This is stored as the background index for the processing
|
||||
* algorithm.
|
||||
@@ -2526,7 +2532,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
for (b=0; b<256; b = (b << 1) | 0x7f)
|
||||
png_create_colormap_entry(display, cmap_entries++,
|
||||
r, g, b, 128, E_sRGB);
|
||||
r, g, b, 128, P_sRGB);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2555,7 +2561,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_create_colormap_entry(display, cmap_entries, back_r,
|
||||
back_g, back_b, 0/*unused*/, output_encoding);
|
||||
|
||||
if (output_encoding == E_LINEAR)
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
r = PNG_sRGB_FROM_LINEAR(back_r * 255);
|
||||
g = PNG_sRGB_FROM_LINEAR(back_g * 255);
|
||||
@@ -2595,11 +2601,11 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
for (b=0; b<256; b = (b << 1) | 0x7f)
|
||||
png_create_colormap_entry(display, cmap_entries++,
|
||||
png_colormap_compose(display, r, E_sRGB, 128,
|
||||
png_colormap_compose(display, r, P_sRGB, 128,
|
||||
back_r, output_encoding),
|
||||
png_colormap_compose(display, g, E_sRGB, 128,
|
||||
png_colormap_compose(display, g, P_sRGB, 128,
|
||||
back_g, output_encoding),
|
||||
png_colormap_compose(display, b, E_sRGB, 128,
|
||||
png_colormap_compose(display, b, P_sRGB, 128,
|
||||
back_b, output_encoding),
|
||||
0/*unused*/, output_encoding);
|
||||
}
|
||||
@@ -2658,7 +2664,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
num_trans = 0;
|
||||
|
||||
output_processing = PNG_CMAP_NONE;
|
||||
data_encoding = E_FILE; /* Don't change from color-map indicies */
|
||||
data_encoding = P_FILE; /* Don't change from color-map indicies */
|
||||
cmap_entries = png_ptr->num_palette;
|
||||
if (cmap_entries > 256)
|
||||
cmap_entries = 256;
|
||||
@@ -2680,13 +2686,13 @@ png_image_read_colormap(png_voidp argument)
|
||||
* on the sRGB color in 'back'.
|
||||
*/
|
||||
png_create_colormap_entry(display, i,
|
||||
png_colormap_compose(display, colormap[i].red, E_FILE,
|
||||
png_colormap_compose(display, colormap[i].red, P_FILE,
|
||||
trans[i], back_r, output_encoding),
|
||||
png_colormap_compose(display, colormap[i].green, E_FILE,
|
||||
png_colormap_compose(display, colormap[i].green, P_FILE,
|
||||
trans[i], back_g, output_encoding),
|
||||
png_colormap_compose(display, colormap[i].blue, E_FILE,
|
||||
png_colormap_compose(display, colormap[i].blue, P_FILE,
|
||||
trans[i], back_b, output_encoding),
|
||||
output_encoding == E_LINEAR ? trans[i] * 257U :
|
||||
output_encoding == P_LINEAR ? trans[i] * 257U :
|
||||
trans[i],
|
||||
output_encoding);
|
||||
}
|
||||
@@ -2695,7 +2701,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
else
|
||||
png_create_colormap_entry(display, i, colormap[i].red,
|
||||
colormap[i].green, colormap[i].blue,
|
||||
i < num_trans ? trans[i] : 255U, E_FILE/*8-bit*/);
|
||||
i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/);
|
||||
}
|
||||
|
||||
/* The PNG data may have indicies packed in fewer than 8 bits, it
|
||||
@@ -2723,12 +2729,12 @@ png_image_read_colormap(png_voidp argument)
|
||||
png_error(png_ptr, "bad data option (internal error)");
|
||||
break;
|
||||
|
||||
case E_sRGB:
|
||||
case P_sRGB:
|
||||
/* Change to 8-bit sRGB */
|
||||
png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);
|
||||
/* FALL THROUGH */
|
||||
|
||||
case E_FILE:
|
||||
case P_FILE:
|
||||
if (png_ptr->bit_depth > 8)
|
||||
png_set_scale_16(png_ptr);
|
||||
break;
|
||||
@@ -3277,7 +3283,12 @@ png_image_read_background(png_voidp argument)
|
||||
png_error(png_ptr, "unknown interlace type");
|
||||
}
|
||||
|
||||
switch (png_get_bit_depth(png_ptr, info_ptr))
|
||||
/* Use direct access to info_ptr here because otherwise the simplified API
|
||||
* would require PNG_EASY_ACCESS_SUPPORTED (just for this.) Note this is
|
||||
* checking the value after libpng expansions, not the original value in the
|
||||
* PNG.
|
||||
*/
|
||||
switch (info_ptr->bit_depth)
|
||||
{
|
||||
default:
|
||||
png_error(png_ptr, "unexpected bit depth");
|
||||
@@ -3425,8 +3436,10 @@ png_image_read_background(png_voidp argument)
|
||||
unsigned int outchannels = 1+preserve_alpha;
|
||||
int swap_alpha = 0;
|
||||
|
||||
if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
|
||||
swap_alpha = 1;
|
||||
# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
|
||||
if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
|
||||
swap_alpha = 1;
|
||||
# endif
|
||||
|
||||
for (pass = 0; pass < passes; ++pass)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user