Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibPNG/pngread.c view on Meta::CPAN
* sets the png_struct fields; that's all we are interested in here. The
* precise interaction with an app call to png_set_tRNS and PNG file reading
* is unclear.
*/
else if (png_ptr->num_trans > 0)
format |= PNG_FORMAT_FLAG_ALPHA;
if (png_ptr->bit_depth == 16)
format |= PNG_FORMAT_FLAG_LINEAR;
if ((png_ptr->color_type & PNG_COLOR_MASK_PALETTE) != 0)
format |= PNG_FORMAT_FLAG_COLORMAP;
return format;
}
/* Is the given gamma significantly different from sRGB? The test is the same
* one used in pngrtran.c when deciding whether to do gamma correction. The
* arithmetic optimizes the division by using the fact that the inverse of the
* file sRGB gamma is 2.2
*/
static int
png_gamma_not_sRGB(png_fixed_point g)
{
if (g < PNG_FP_1)
{
/* An uninitialized gamma is assumed to be sRGB for the simplified API. */
if (g == 0)
return 0;
return png_gamma_significant((g * 11 + 2)/5 /* i.e. *2.2, rounded */);
}
return 1;
}
/* Do the main body of a 'png_image_begin_read' function; read the PNG file
* header and fill in all the information. This is executed in a safe context,
* unlike the init routine above.
*/
static int
png_image_read_header(png_voidp argument)
{
png_imagep image = png_voidcast(png_imagep, argument);
png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr;
png_set_benign_errors(png_ptr, 1/*warn*/);
png_read_info(png_ptr, info_ptr);
/* Do this the fast way; just read directly out of png_struct. */
image->width = png_ptr->width;
image->height = png_ptr->height;
{
png_uint_32 format = png_image_format(png_ptr);
image->format = format;
#ifdef PNG_COLORSPACE_SUPPORTED
/* Does the colorspace match sRGB? If there is no color endpoint
* (colorant) information assume yes, otherwise require 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
& (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB|
PNG_COLORSPACE_INVALID)) == PNG_COLORSPACE_HAVE_ENDPOINTS))
image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB;
#endif
}
/* We need the maximum number of entries regardless of the format the
* application sets here.
*/
{
png_uint_32 cmap_entries;
switch (png_ptr->color_type)
{
case PNG_COLOR_TYPE_GRAY:
cmap_entries = 1U << png_ptr->bit_depth;
break;
case PNG_COLOR_TYPE_PALETTE:
cmap_entries = png_ptr->num_palette;
break;
default:
cmap_entries = 256;
break;
}
if (cmap_entries > 256)
cmap_entries = 256;
image->colormap_entries = cmap_entries;
}
return 1;
}
#ifdef PNG_STDIO_SUPPORTED
int PNGAPI
png_image_begin_read_from_stdio(png_imagep image, FILE* file)
{
if (image != NULL && image->version == PNG_IMAGE_VERSION)
{
if (file != NULL)
{
if (png_image_read_init(image) != 0)
{
/* This is slightly evil, but png_init_io doesn't do anything other
* than this and we haven't changed the standard IO functions so
* this saves a 'safe' function.
*/
image->opaque->png_ptr->io_ptr = file;
return png_safe_execute(image, png_image_read_header, image);
}
}
( run in 0.353 second using v1.01-cache-2.11-cpan-d0baa829c65 )