Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibPNG/pngrtran.c view on Meta::CPAN
trans_gray *= 0x11;
break;
default:
case 8:
/* FALL THROUGH (Already 8 bits) */
case 16:
/* Already a full 16 bits */
break;
}
png_ptr->background.red = png_ptr->background.green =
png_ptr->background.blue = (png_uint_16)gray;
if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
{
png_ptr->trans_color.red = png_ptr->trans_color.green =
png_ptr->trans_color.blue = (png_uint_16)trans_gray;
}
}
} /* background expand and (therefore) no alpha association. */
#endif /* READ_EXPAND && READ_BACKGROUND */
}
void /* PRIVATE */
png_init_read_transformations(png_structrp png_ptr)
{
png_debug(1, "in png_init_read_transformations");
/* This internal function is called from png_read_start_row in pngrutil.c
* and it is called before the 'rowbytes' calculation is done, so the code
* in here can change or update the transformations flags.
*
* First do updates that do not depend on the details of the PNG image data
* being processed.
*/
#ifdef PNG_READ_GAMMA_SUPPORTED
/* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds
* png_set_alpha_mode and this is another source for a default file gamma so
* the test needs to be performed later - here. In addition prior to 1.5.4
* the tests were repeated for the PALETTE color type here - this is no
* longer necessary (and doesn't seem to have been necessary before.)
*/
{
/* The following temporary indicates if overall gamma correction is
* required.
*/
int gamma_correction = 0;
if (png_ptr->colorspace.gamma != 0) /* has been set */
{
if (png_ptr->screen_gamma != 0) /* screen set too */
gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
png_ptr->screen_gamma);
else
/* Assume the output matches the input; a long time default behavior
* of libpng, although the standard has nothing to say about this.
*/
png_ptr->screen_gamma = png_reciprocal(png_ptr->colorspace.gamma);
}
else if (png_ptr->screen_gamma != 0)
/* The converse - assume the file matches the screen, note that this
* perhaps undesireable default can (from 1.5.4) be changed by calling
* png_set_alpha_mode (even if the alpha handling mode isn't required
* or isn't changed from the default.)
*/
png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma);
else /* neither are set */
/* Just in case the following prevents any processing - file and screen
* are both assumed to be linear and there is no way to introduce a
* third gamma value other than png_set_background with 'UNIQUE', and,
* prior to 1.5.4
*/
png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1;
/* We have a gamma value now. */
png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
/* Now turn the gamma transformation on or off as appropriate. Notice
* that PNG_GAMMA just refers to the file->screen correction. Alpha
* composition may independently cause gamma correction because it needs
* linear data (e.g. if the file has a gAMA chunk but the screen gamma
* hasn't been specified.) In any case this flag may get turned off in
* the code immediately below if the transform can be handled outside the
* row loop.
*/
if (gamma_correction != 0)
png_ptr->transformations |= PNG_GAMMA;
else
png_ptr->transformations &= ~PNG_GAMMA;
}
#endif
/* Certain transformations have the effect of preventing other
* transformations that happen afterward in png_do_read_transformations;
* resolve the interdependencies here. From the code of
* png_do_read_transformations the order is:
*
* 1) PNG_EXPAND (including PNG_EXPAND_tRNS)
* 2) PNG_STRIP_ALPHA (if no compose)
* 3) PNG_RGB_TO_GRAY
* 4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY
* 5) PNG_COMPOSE
* 6) PNG_GAMMA
* 7) PNG_STRIP_ALPHA (if compose)
* 8) PNG_ENCODE_ALPHA
* 9) PNG_SCALE_16_TO_8
* 10) PNG_16_TO_8
* 11) PNG_QUANTIZE (converts to palette)
* 12) PNG_EXPAND_16
* 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
* 14) PNG_INVERT_MONO
* 15) PNG_INVERT_ALPHA
* 16) PNG_SHIFT
( run in 0.452 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )