Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibPNG/pngread.c view on Meta::CPAN
PNG_sRGB_FROM_LINEAR(gray + back_gx),
PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);
}
}
cmap_entries = i;
output_processing = PNG_CMAP_GA;
}
}
break;
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_RGB_ALPHA:
/* Exclude the case where the output is gray; we can always handle this
* with the cases above.
*/
if ((output_format & PNG_FORMAT_FLAG_COLOR) == 0)
{
/* The color-map will be grayscale, so we may as well convert the
* input RGB values to a simple grayscale and use the grayscale
* code above.
*
* NOTE: calling this apparently damages the recognition of the
* transparent color in background color handling; call
* png_set_tRNS_to_alpha before png_set_background_fixed.
*/
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
-1);
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.
*/
if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
png_ptr->num_trans > 0) &&
(output_format & PNG_FORMAT_FLAG_ALPHA) != 0)
{
/* Both input and output have an alpha channel, so no background
* processing is required; just map the GA bytes to the right
* color-map entry.
*/
expand_tRNS = 1;
if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "rgb[ga] color-map: too few entries");
cmap_entries = make_ga_colormap(display);
background_index = PNG_CMAP_GA_BACKGROUND;
output_processing = PNG_CMAP_GA;
}
else
{
/* Either the input or the output has no alpha channel, so there
* will be no non-opaque pixels in the color-map; it will just be
* grayscale.
*/
if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "rgb[gray] color-map: too few entries");
/* Ideally this code would use libpng to do the gamma correction,
* but if an input alpha channel is to be removed we will hit the
* libpng bug in gamma+compose+rgb-to-gray (the double gamma
* correction bug). Fix this by dropping the gamma correction in
* this case and doing it in the palette; this will result in
* duplicate palette entries, but that's better than the
* alternative of double gamma correction.
*/
if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
png_ptr->num_trans > 0) &&
png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0)
{
cmap_entries = make_gray_file_colormap(display);
data_encoding = P_FILE;
}
else
cmap_entries = make_gray_colormap(display);
/* But if the input has alpha or transparency it must be removed
*/
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
png_ptr->num_trans > 0)
{
png_color_16 c;
png_uint_32 gray = back_g;
/* We need to ensure that the application background exists in
* the colormap and that completely transparent pixels map to
* it. Achieve this simply by ensuring that the entry
* selected for the background really is the background color.
*/
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 (P_FILE)
* encoding then set this palette entry to the required
* output encoding.
*/
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 P_FILE */
/* And make sure the corresponding palette entry contains
* exactly the required sRGB value.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 0/*unused*/, output_encoding);
}
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*/, P_LINEAR);
}
( run in 0.986 second using v1.01-cache-2.11-cpan-e93a5daba3e )