This repository has been archived on 2023-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
libpng/pngget.c

901 lines
24 KiB
C
Raw Normal View History

1997-05-16 02:46:07 -05:00
/* pngget.c - retrieval of values from info struct
1998-01-01 07:13:13 -06:00
*
2008-08-15 09:15:00 -05:00
* Last changed in libpng 1.2.30 [August 15, 2008]
1998-01-01 07:13:13 -06:00
* For conditions of distribution and use, see copyright notice in png.h
2008-07-06 06:05:04 -05:00
* Copyright (c) 1998-2008 Glenn Randers-Pehrson
2000-06-04 14:29:29 -05:00
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
1998-01-01 07:13:13 -06:00
*/
1997-05-16 02:46:07 -05:00
#define PNG_INTERNAL
#include "png.h"
2006-02-20 22:09:05 -06:00
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1997-05-16 02:46:07 -05:00
return(info_ptr->valid & flag);
else
return(0);
}
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1997-05-16 02:46:07 -05:00
return(info_ptr->rowbytes);
else
return(0);
}
2000-02-18 13:48:52 -06:00
#if defined(PNG_INFO_IMAGE_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_bytepp PNGAPI
2000-02-18 13:48:52 -06:00
png_get_rows(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->row_pointers);
else
return(0);
}
#endif
1998-01-30 21:45:12 -06:00
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* easy access to info, added in libpng-0.99 */
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-01-30 21:45:12 -06:00
png_get_image_width(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1998-01-30 21:45:12 -06:00
{
return info_ptr->width;
}
return (0);
}
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-01-30 21:45:12 -06:00
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1998-01-30 21:45:12 -06:00
{
return info_ptr->height;
}
return (0);
}
2000-05-06 14:09:57 -05:00
png_byte PNGAPI
1998-01-30 21:45:12 -06:00
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1998-01-30 21:45:12 -06:00
{
return info_ptr->bit_depth;
}
return (0);
}
2000-05-06 14:09:57 -05:00
png_byte PNGAPI
1998-01-30 21:45:12 -06:00
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1998-01-30 21:45:12 -06:00
{
return info_ptr->color_type;
}
return (0);
}
2000-05-06 14:09:57 -05:00
png_byte PNGAPI
1998-01-30 21:45:12 -06:00
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1998-01-30 21:45:12 -06:00
{
return info_ptr->filter_type;
}
return (0);
}
2000-05-06 14:09:57 -05:00
png_byte PNGAPI
1998-01-30 21:45:12 -06:00
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1998-01-30 21:45:12 -06:00
{
return info_ptr->interlace_type;
}
return (0);
}
2000-05-06 14:09:57 -05:00
png_byte PNGAPI
1998-01-30 21:45:12 -06:00
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1998-01-30 21:45:12 -06:00
{
return info_ptr->compression_type;
}
return (0);
}
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-02-28 07:00:24 -06:00
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_pHYs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_pHYs)
1998-02-28 07:00:24 -06:00
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
2008-07-10 09:10:58 -05:00
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
1998-02-28 07:00:24 -06:00
return (0);
else return (info_ptr->x_pixels_per_unit);
}
2000-05-29 08:58:03 -05:00
#else
return (0);
1998-02-28 07:00:24 -06:00
#endif
return (0);
}
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-02-28 07:00:24 -06:00
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_pHYs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_pHYs)
1998-02-28 07:00:24 -06:00
{
2001-05-07 14:52:45 -05:00
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
2008-07-10 09:10:58 -05:00
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
1998-02-28 07:00:24 -06:00
return (0);
else return (info_ptr->y_pixels_per_unit);
}
2000-05-29 08:58:03 -05:00
#else
return (0);
1998-02-28 07:00:24 -06:00
#endif
return (0);
}
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-01-30 21:45:12 -06:00
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_pHYs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_pHYs)
1998-01-30 21:45:12 -06:00
{
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
2008-07-10 09:10:58 -05:00
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
1998-02-28 07:00:24 -06:00
info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
1998-01-30 21:45:12 -06:00
return (0);
else return (info_ptr->x_pixels_per_unit);
}
2000-05-29 08:58:03 -05:00
#else
return (0);
1998-01-30 21:45:12 -06:00
#endif
return (0);
}
1999-12-10 09:43:02 -06:00
#ifdef PNG_FLOATING_POINT_SUPPORTED
2000-05-06 14:09:57 -05:00
float PNGAPI
1998-01-30 21:45:12 -06:00
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_pHYs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_pHYs)
1998-01-30 21:45:12 -06:00
{
png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
if (info_ptr->x_pixels_per_unit == 0)
1998-02-07 10:20:57 -06:00
return ((float)0.0);
1998-01-30 21:45:12 -06:00
else
2000-05-29 08:58:03 -05:00
return ((float)((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit));
1998-01-30 21:45:12 -06:00
}
2000-05-29 08:58:03 -05:00
#else
return (0.0);
1998-01-30 21:45:12 -06:00
#endif
2000-05-29 08:58:03 -05:00
return ((float)0.0);
1998-01-30 21:45:12 -06:00
}
1999-12-10 09:43:02 -06:00
#endif
1998-01-30 21:45:12 -06:00
2000-05-29 08:58:03 -05:00
png_int_32 PNGAPI
1998-01-30 21:45:12 -06:00
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_oFFs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_oFFs)
1998-01-30 21:45:12 -06:00
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
2008-07-10 09:10:58 -05:00
if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
1998-01-30 21:45:12 -06:00
return (0);
else return (info_ptr->x_offset);
}
2000-05-29 08:58:03 -05:00
#else
return (0);
1998-01-30 21:45:12 -06:00
#endif
return (0);
}
2000-05-29 08:58:03 -05:00
png_int_32 PNGAPI
1998-01-30 21:45:12 -06:00
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_oFFs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_oFFs)
1998-01-30 21:45:12 -06:00
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
2008-07-10 09:10:58 -05:00
if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
1998-01-30 21:45:12 -06:00
return (0);
else return (info_ptr->y_offset);
}
2000-05-29 08:58:03 -05:00
#else
return (0);
1998-01-30 21:45:12 -06:00
#endif
return (0);
}
2000-05-29 08:58:03 -05:00
png_int_32 PNGAPI
1998-01-30 21:45:12 -06:00
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_oFFs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_oFFs)
1998-01-30 21:45:12 -06:00
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
2008-07-10 09:10:58 -05:00
if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
1998-01-30 21:45:12 -06:00
return (0);
else return (info_ptr->x_offset);
}
2000-05-29 08:58:03 -05:00
#else
return (0);
1998-01-30 21:45:12 -06:00
#endif
return (0);
}
2000-05-29 08:58:03 -05:00
png_int_32 PNGAPI
1998-01-30 21:45:12 -06:00
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
2000-05-29 08:58:03 -05:00
if (png_ptr != NULL && info_ptr != NULL)
1999-12-10 09:43:02 -06:00
#if defined(PNG_oFFs_SUPPORTED)
2000-05-29 08:58:03 -05:00
if (info_ptr->valid & PNG_INFO_oFFs)
1998-01-30 21:45:12 -06:00
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
2008-07-10 09:10:58 -05:00
if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
1998-01-30 21:45:12 -06:00
return (0);
else return (info_ptr->y_offset);
}
2000-05-29 08:58:03 -05:00
#else
return (0);
1998-01-30 21:45:12 -06:00
#endif
return (0);
}
1999-12-10 09:43:02 -06:00
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-02-28 07:00:24 -06:00
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
2000-05-29 08:58:03 -05:00
*.0254 +.5));
1998-02-28 07:00:24 -06:00
}
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-02-28 07:00:24 -06:00
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
2000-05-29 08:58:03 -05:00
*.0254 +.5));
1998-02-28 07:00:24 -06:00
}
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-02-28 07:00:24 -06:00
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
2000-05-29 08:58:03 -05:00
*.0254 +.5));
1998-02-28 07:00:24 -06:00
}
2000-05-06 14:09:57 -05:00
float PNGAPI
1998-02-28 07:00:24 -06:00
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
2000-02-18 13:48:52 -06:00
*.00003937);
1998-02-28 07:00:24 -06:00
}
2000-05-06 14:09:57 -05:00
float PNGAPI
1998-02-28 07:00:24 -06:00
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
2000-05-29 08:58:03 -05:00
*.00003937);
1998-02-28 07:00:24 -06:00
}
2001-05-07 14:52:45 -05:00
#if defined(PNG_pHYs_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-02-28 07:00:24 -06:00
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
png_uint_32 retval = 0;
2000-02-04 23:40:16 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
1998-02-28 07:00:24 -06:00
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
if (res_x != NULL)
{
*res_x = info_ptr->x_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (res_y != NULL)
{
*res_y = info_ptr->y_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (unit_type != NULL)
{
*unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs;
2008-07-10 09:10:58 -05:00
if (*unit_type == 1)
1998-02-28 07:00:24 -06:00
{
2000-02-18 13:48:52 -06:00
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
1998-02-28 07:00:24 -06:00
}
}
}
return (retval);
}
2001-05-07 14:52:45 -05:00
#endif /* PNG_pHYs_SUPPORTED */
2000-02-04 23:40:16 -06:00
#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
1998-02-28 07:00:24 -06:00
/* png_get_channels really belongs in here, too, but it's been around longer */
1998-06-06 15:31:35 -05:00
1998-02-28 07:00:24 -06:00
#endif /* PNG_EASY_ACCESS_SUPPORTED */
2000-05-06 14:09:57 -05:00
png_byte PNGAPI
1997-05-16 02:46:07 -05:00
png_get_channels(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1997-05-16 02:46:07 -05:00
return(info_ptr->channels);
else
1998-02-07 10:20:57 -06:00
return (0);
1997-05-16 02:46:07 -05:00
}
2000-05-06 14:09:57 -05:00
png_bytep PNGAPI
1997-05-16 02:46:07 -05:00
png_get_signature(png_structp png_ptr, png_infop info_ptr)
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL)
1997-05-16 02:46:07 -05:00
return(info_ptr->signature);
else
1998-02-07 10:20:57 -06:00
return (NULL);
1997-05-16 02:46:07 -05:00
}
2001-05-07 14:52:45 -05:00
#if defined(PNG_bKGD_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
png_color_16p *background)
{
1998-02-28 07:00:24 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
&& background != NULL)
1997-05-16 02:46:07 -05:00
{
png_debug1(1, "in %s retrieval function\n", "bKGD");
*background = &(info_ptr->background);
return (PNG_INFO_bKGD);
}
return (0);
}
#endif
2001-05-07 14:52:45 -05:00
#if defined(PNG_cHRM_SUPPORTED)
1999-12-10 09:43:02 -06:00
#ifdef PNG_FLOATING_POINT_SUPPORTED
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
double *white_x, double *white_y, double *red_x, double *red_y,
double *green_x, double *green_y, double *blue_x, double *blue_y)
{
1998-02-28 07:00:24 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
1997-05-16 02:46:07 -05:00
{
png_debug1(1, "in %s retrieval function\n", "cHRM");
if (white_x != NULL)
*white_x = (double)info_ptr->x_white;
if (white_y != NULL)
*white_y = (double)info_ptr->y_white;
if (red_x != NULL)
*red_x = (double)info_ptr->x_red;
if (red_y != NULL)
*red_y = (double)info_ptr->y_red;
if (green_x != NULL)
*green_x = (double)info_ptr->x_green;
if (green_y != NULL)
*green_y = (double)info_ptr->y_green;
if (blue_x != NULL)
*blue_x = (double)info_ptr->x_blue;
if (blue_y != NULL)
*blue_y = (double)info_ptr->y_blue;
return (PNG_INFO_cHRM);
}
return (0);
}
#endif
1999-12-10 09:43:02 -06:00
#ifdef PNG_FIXED_POINT_SUPPORTED
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1999-12-10 09:43:02 -06:00
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
2000-02-04 23:40:16 -06:00
png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
png_fixed_point *blue_x, png_fixed_point *blue_y)
1999-12-10 09:43:02 -06:00
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
{
png_debug1(1, "in %s retrieval function\n", "cHRM");
if (white_x != NULL)
*white_x = info_ptr->int_x_white;
if (white_y != NULL)
*white_y = info_ptr->int_y_white;
if (red_x != NULL)
*red_x = info_ptr->int_x_red;
if (red_y != NULL)
*red_y = info_ptr->int_y_red;
if (green_x != NULL)
*green_x = info_ptr->int_x_green;
if (green_y != NULL)
*green_y = info_ptr->int_y_green;
if (blue_x != NULL)
*blue_x = info_ptr->int_x_blue;
if (blue_y != NULL)
*blue_y = info_ptr->int_y_blue;
return (PNG_INFO_cHRM);
}
return (0);
}
#endif
#endif
1997-05-16 02:46:07 -05:00
2001-05-07 14:52:45 -05:00
#if defined(PNG_gAMA_SUPPORTED)
1999-12-10 09:43:02 -06:00
#ifdef PNG_FLOATING_POINT_SUPPORTED
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{
1998-02-28 07:00:24 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& file_gamma != NULL)
1997-05-16 02:46:07 -05:00
{
png_debug1(1, "in %s retrieval function\n", "gAMA");
*file_gamma = (double)info_ptr->gamma;
return (PNG_INFO_gAMA);
}
return (0);
}
#endif
2000-05-01 09:31:54 -05:00
#ifdef PNG_FIXED_POINT_SUPPORTED
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1999-12-10 09:43:02 -06:00
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
2000-02-04 23:40:16 -06:00
png_fixed_point *int_file_gamma)
1999-12-10 09:43:02 -06:00
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& int_file_gamma != NULL)
{
png_debug1(1, "in %s retrieval function\n", "gAMA");
*int_file_gamma = info_ptr->int_gamma;
return (PNG_INFO_gAMA);
}
return (0);
}
#endif
2000-05-01 09:31:54 -05:00
#endif
1997-05-16 02:46:07 -05:00
2001-05-07 14:52:45 -05:00
#if defined(PNG_sRGB_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1998-01-16 22:06:18 -06:00
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
1998-01-01 07:13:13 -06:00
{
1998-02-28 07:00:24 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
&& file_srgb_intent != NULL)
1998-01-01 07:13:13 -06:00
{
png_debug1(1, "in %s retrieval function\n", "sRGB");
1998-01-16 22:06:18 -06:00
*file_srgb_intent = (int)info_ptr->srgb_intent;
1998-01-01 07:13:13 -06:00
return (PNG_INFO_sRGB);
}
return (0);
}
#endif
2001-05-07 14:52:45 -05:00
#if defined(PNG_iCCP_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1999-12-10 09:43:02 -06:00
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charpp name, int *compression_type,
2000-02-04 23:40:16 -06:00
png_charpp profile, png_uint_32 *proflen)
1999-12-10 09:43:02 -06:00
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
&& name != NULL && profile != NULL && proflen != NULL)
{
png_debug1(1, "in %s retrieval function\n", "iCCP");
*name = info_ptr->iccp_name;
*profile = info_ptr->iccp_profile;
/* compression_type is a dummy so the API won't have to change
if we introduce multiple compression types later. */
*proflen = (int)info_ptr->iccp_proflen;
*compression_type = (int)info_ptr->iccp_compression;
return (PNG_INFO_iCCP);
}
return (0);
}
#endif
2001-05-07 14:52:45 -05:00
#if defined(PNG_sPLT_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
2000-02-18 13:48:52 -06:00
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
2000-03-21 05:13:06 -06:00
png_sPLT_tpp spalettes)
1999-12-10 09:43:02 -06:00
{
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
2007-05-28 08:45:13 -05:00
{
1999-12-10 09:43:02 -06:00
*spalettes = info_ptr->splt_palettes;
2007-05-28 08:45:13 -05:00
return ((png_uint_32)info_ptr->splt_palettes_num);
}
return (0);
1999-12-10 09:43:02 -06:00
}
#endif
2001-05-07 14:52:45 -05:00
#if defined(PNG_hIST_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
1998-02-28 07:00:24 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
&& hist != NULL)
1997-05-16 02:46:07 -05:00
{
png_debug1(1, "in %s retrieval function\n", "hIST");
*hist = info_ptr->hist;
return (PNG_INFO_hIST);
}
return (0);
}
#endif
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *width, png_uint_32 *height, int *bit_depth,
int *color_type, int *interlace_type, int *compression_type,
int *filter_type)
1998-12-29 11:47:59 -06:00
1997-05-16 02:46:07 -05:00
{
1998-02-08 20:56:40 -06:00
if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
1997-05-16 02:46:07 -05:00
bit_depth != NULL && color_type != NULL)
{
png_debug1(1, "in %s retrieval function\n", "IHDR");
*width = info_ptr->width;
*height = info_ptr->height;
*bit_depth = info_ptr->bit_depth;
2002-03-25 18:49:08 -06:00
if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
png_error(png_ptr, "Invalid bit depth");
1997-05-16 02:46:07 -05:00
*color_type = info_ptr->color_type;
2002-03-25 18:49:08 -06:00
if (info_ptr->color_type > 6)
png_error(png_ptr, "Invalid color type");
1997-05-16 02:46:07 -05:00
if (compression_type != NULL)
*compression_type = info_ptr->compression_type;
if (filter_type != NULL)
*filter_type = info_ptr->filter_type;
if (interlace_type != NULL)
*interlace_type = info_ptr->interlace_type;
1998-02-07 10:20:57 -06:00
/* check for potential overflow of rowbytes */
2004-11-01 14:13:40 -06:00
if (*width == 0 || *width > PNG_UINT_31_MAX)
2002-02-23 18:55:25 -06:00
png_error(png_ptr, "Invalid image width");
2004-11-01 14:13:40 -06:00
if (*height == 0 || *height > PNG_UINT_31_MAX)
2002-02-23 18:55:25 -06:00
png_error(png_ptr, "Invalid image height");
2004-08-04 06:34:52 -05:00
if (info_ptr->width > (PNG_UINT_32_MAX
>> 3) /* 8-byte RGBA pixels */
- 64 /* bigrowbuf hack */
- 1 /* filter byte */
- 7*8 /* rounding of width to multiple of 8 pixels */
- 8) /* extra max_pixel_depth pad */
1998-02-07 10:20:57 -06:00
{
2004-08-04 06:34:52 -05:00
png_warning(png_ptr,
1998-02-07 10:20:57 -06:00
"Width too large for libpng to process image data.");
}
1997-05-16 02:46:07 -05:00
return (1);
}
return (0);
}
2001-05-07 14:52:45 -05:00
#if defined(PNG_oFFs_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
1999-12-10 09:43:02 -06:00
png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
1997-05-16 02:46:07 -05:00
{
1998-02-28 07:00:24 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
1997-05-16 02:46:07 -05:00
{
png_debug1(1, "in %s retrieval function\n", "oFFs");
*offset_x = info_ptr->x_offset;
*offset_y = info_ptr->y_offset;
*unit_type = (int)info_ptr->offset_unit_type;
return (PNG_INFO_oFFs);
}
return (0);
}
#endif
2001-05-07 14:52:45 -05:00
#if defined(PNG_pCAL_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
png_charp *units, png_charpp *params)
{
2000-02-04 23:40:16 -06:00
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
1997-05-16 02:46:07 -05:00
nparams != NULL && units != NULL && params != NULL)
{
png_debug1(1, "in %s retrieval function\n", "pCAL");
*purpose = info_ptr->pcal_purpose;
*X0 = info_ptr->pcal_X0;
*X1 = info_ptr->pcal_X1;
*type = (int)info_ptr->pcal_type;
*nparams = (int)info_ptr->pcal_nparams;
*units = info_ptr->pcal_units;
*params = info_ptr->pcal_params;
return (PNG_INFO_pCAL);
}
return (0);
}
#endif
2001-05-07 14:52:45 -05:00
#if defined(PNG_sCAL_SUPPORTED)
1999-12-10 09:43:02 -06:00
#ifdef PNG_FLOATING_POINT_SUPPORTED
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1999-12-10 09:43:02 -06:00
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
2000-02-04 23:40:16 -06:00
int *unit, double *width, double *height)
1999-12-10 09:43:02 -06:00
{
2000-02-04 23:40:16 -06:00
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL))
1999-12-10 09:43:02 -06:00
{
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_pixel_width;
*height = info_ptr->scal_pixel_height;
return (PNG_INFO_sCAL);
}
return(0);
}
2000-02-04 23:40:16 -06:00
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1999-12-10 09:43:02 -06:00
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
2000-02-04 23:40:16 -06:00
int *unit, png_charpp width, png_charpp height)
1999-12-10 09:43:02 -06:00
{
2000-02-04 23:40:16 -06:00
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL))
1999-12-10 09:43:02 -06:00
{
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_s_width;
*height = info_ptr->scal_s_height;
return (PNG_INFO_sCAL);
}
return(0);
}
#endif
2000-02-04 23:40:16 -06:00
#endif
#endif
1999-12-10 09:43:02 -06:00
2001-05-07 14:52:45 -05:00
#if defined(PNG_pHYs_SUPPORTED)
2000-05-06 14:09:57 -05:00
png_uint_32 PNGAPI
1997-05-16 02:46:07 -05:00
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
1998-01-01 07:13:13 -06:00
png_uint_32 retval = 0;
2000-02-04 23:40:16 -06:00
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs))
1997-05-16 02:46:07 -05:00
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
1998-02-28 07:00:24 -06:00
if (res_x != NULL)
1998-01-01 07:13:13 -06:00
{
*res_x = info_ptr->x_pixels_per_unit;
1998-02-28 07:00:24 -06:00
retval |= PNG_INFO_pHYs;
}
if (res_y != NULL)
{
1998-01-01 07:13:13 -06:00
*res_y = info_ptr->y_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (unit_type != NULL)
{
*unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs;
}
1997-05-16 02:46:07 -05:00
}
1998-02-28 07:00:24 -06:00
return (retval);
1997-05-16 02:46:07 -05:00
}
#endif