summaryrefslogtreecommitdiff
path: root/pngget.c
diff options
context:
space:
mode:
Diffstat (limited to 'pngget.c')
-rw-r--r--pngget.c129
1 files changed, 84 insertions, 45 deletions
diff --git a/pngget.c b/pngget.c
index 3b2b64600..0022d95f1 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,9 +1,9 @@
/* pngget.c - retrieval of values from info struct
*
- * Last changed in libpng 1.2.30 [August 15, 2008]
+ * Last changed in libpng 1.2.37 [June 4, 2009]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2008 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2009 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@@ -17,6 +17,7 @@ png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->valid & flag);
+
else
return(0);
}
@@ -26,6 +27,7 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->rowbytes);
+
else
return(0);
}
@@ -36,20 +38,20 @@ 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
#ifdef PNG_EASY_ACCESS_SUPPORTED
-/* easy access to info, added in libpng-0.99 */
+/* Easy access to info, added in libpng-0.99 */
png_uint_32 PNGAPI
png_get_image_width(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
- {
return info_ptr->width;
- }
+
return (0);
}
@@ -57,9 +59,8 @@ png_uint_32 PNGAPI
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
- {
return info_ptr->height;
- }
+
return (0);
}
@@ -67,9 +68,8 @@ png_byte PNGAPI
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
- {
return info_ptr->bit_depth;
- }
+
return (0);
}
@@ -77,9 +77,8 @@ png_byte PNGAPI
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
- {
return info_ptr->color_type;
- }
+
return (0);
}
@@ -87,9 +86,8 @@ png_byte PNGAPI
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
- {
return info_ptr->filter_type;
- }
+
return (0);
}
@@ -97,9 +95,8 @@ png_byte PNGAPI
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
- {
return info_ptr->interlace_type;
- }
+
return (0);
}
@@ -107,9 +104,8 @@ png_byte PNGAPI
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
- {
return info_ptr->compression_type;
- }
+
return (0);
}
@@ -121,9 +117,12 @@ png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter");
+
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
- else return (info_ptr->x_pixels_per_unit);
+
+ else
+ return (info_ptr->x_pixels_per_unit);
}
#else
return (0);
@@ -139,9 +138,12 @@ png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter");
+
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
- else return (info_ptr->y_pixels_per_unit);
+
+ else
+ return (info_ptr->y_pixels_per_unit);
}
#else
return (0);
@@ -157,10 +159,13 @@ png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
+
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
return (0);
- else return (info_ptr->x_pixels_per_unit);
+
+ else
+ return (info_ptr->x_pixels_per_unit);
}
#else
return (0);
@@ -174,6 +179,7 @@ png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED)
+
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
@@ -184,7 +190,7 @@ png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
/(float)info_ptr->x_pixels_per_unit));
}
#else
- return (0.0);
+ return (0.0);
#endif
return ((float)0.0);
}
@@ -195,15 +201,19 @@ png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED)
+
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
+
if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
- else return (info_ptr->x_offset);
+
+ else
+ return (info_ptr->x_offset);
}
#else
- return (0);
+ return (0);
#endif
return (0);
}
@@ -212,13 +222,17 @@ png_int_32 PNGAPI
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
+
#if defined(PNG_oFFs_SUPPORTED)
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
+
if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
- else return (info_ptr->y_offset);
+
+ else
+ return (info_ptr->y_offset);
}
#else
return (0);
@@ -230,13 +244,17 @@ png_int_32 PNGAPI
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
+
#if defined(PNG_oFFs_SUPPORTED)
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
+
if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
- else return (info_ptr->x_offset);
+
+ else
+ return (info_ptr->x_offset);
}
#else
return (0);
@@ -248,13 +266,17 @@ png_int_32 PNGAPI
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
+
#if defined(PNG_oFFs_SUPPORTED)
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
+
if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
- else return (info_ptr->y_offset);
+
+ else
+ return (info_ptr->y_offset);
}
#else
return (0);
@@ -495,8 +517,9 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
png_debug1(1, "in %s retrieval function", "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. */
+ /* 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);
@@ -549,22 +572,29 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
*height = info_ptr->height;
*bit_depth = info_ptr->bit_depth;
if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
- png_error(png_ptr, "Invalid bit depth");
+ png_error(png_ptr, "Invalid bit depth");
+
*color_type = info_ptr->color_type;
+
if (info_ptr->color_type > 6)
- png_error(png_ptr, "Invalid color type");
+ png_error(png_ptr, "Invalid color type");
+
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;
- /* check for potential overflow of rowbytes */
+ /* Check for potential overflow of rowbytes */
if (*width == 0 || *width > PNG_UINT_31_MAX)
png_error(png_ptr, "Invalid image width");
+
if (*height == 0 || *height > PNG_UINT_31_MAX)
png_error(png_ptr, "Invalid image height");
+
if (info_ptr->width > (PNG_UINT_32_MAX
>> 3) /* 8-byte RGBA pixels */
- 64 /* bigrowbuf hack */
@@ -575,6 +605,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
png_warning(png_ptr,
"Width too large for libpng to process image data.");
}
+
return (1);
}
return (0);
@@ -605,8 +636,8 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *units, png_charpp *params)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
- && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
- nparams != NULL && units != NULL && params != NULL)
+ && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
+ nparams != NULL && units != NULL && params != NULL)
{
png_debug1(1, "in %s retrieval function", "pCAL");
*purpose = info_ptr->pcal_purpose;
@@ -629,7 +660,7 @@ png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
int *unit, double *width, double *height)
{
if (png_ptr != NULL && info_ptr != NULL &&
- (info_ptr->valid & PNG_INFO_sCAL))
+ (info_ptr->valid & PNG_INFO_sCAL))
{
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_pixel_width;
@@ -645,7 +676,7 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
int *unit, png_charpp width, png_charpp height)
{
if (png_ptr != NULL && info_ptr != NULL &&
- (info_ptr->valid & PNG_INFO_sCAL))
+ (info_ptr->valid & PNG_INFO_sCAL))
{
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_s_width;
@@ -669,16 +700,19 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
(info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function", "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;
@@ -730,10 +764,13 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
png_debug1(1, "in %s retrieval function",
(png_ptr->chunk_name[0] == '\0' ? "text"
: (png_const_charp)png_ptr->chunk_name));
+
if (text_ptr != NULL)
*text_ptr = info_ptr->text;
+
if (num_text != NULL)
*num_text = info_ptr->num_text;
+
return ((png_uint_32)info_ptr->num_text);
}
if (num_text != NULL)
@@ -773,6 +810,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
*trans = info_ptr->trans;
retval |= PNG_INFO_tRNS;
}
+
if (trans_values != NULL)
*trans_values = &(info_ptr->trans_values);
}
@@ -783,6 +821,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
*trans_values = &(info_ptr->trans_values);
retval |= PNG_INFO_tRNS;
}
+
if (trans != NULL)
*trans = NULL;
}
@@ -836,47 +875,47 @@ png_get_compression_buffer_size(png_structp png_ptr)
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
#ifndef PNG_1_0_X
-/* this function was added to libpng 1.2.0 and should exist by default */
+/* This function was added to libpng 1.2.0 and should exist by default */
png_uint_32 PNGAPI
png_get_asm_flags (png_structp png_ptr)
{
- /* obsolete, to be removed from libpng-1.4.0 */
+ /* Obsolete, to be removed from libpng-1.4.0 */
return (png_ptr? 0L: 0L);
}
-/* this function was added to libpng 1.2.0 and should exist by default */
+/* This function was added to libpng 1.2.0 and should exist by default */
png_uint_32 PNGAPI
png_get_asm_flagmask (int flag_select)
{
- /* obsolete, to be removed from libpng-1.4.0 */
+ /* Obsolete, to be removed from libpng-1.4.0 */
flag_select=flag_select;
return 0L;
}
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
-/* this function was added to libpng 1.2.0 */
+/* This function was added to libpng 1.2.0 */
png_uint_32 PNGAPI
png_get_mmx_flagmask (int flag_select, int *compilerID)
{
- /* obsolete, to be removed from libpng-1.4.0 */
+ /* Obsolete, to be removed from libpng-1.4.0 */
flag_select=flag_select;
*compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
return 0L;
}
-/* this function was added to libpng 1.2.0 */
+/* This function was added to libpng 1.2.0 */
png_byte PNGAPI
png_get_mmx_bitdepth_threshold (png_structp png_ptr)
{
- /* obsolete, to be removed from libpng-1.4.0 */
+ /* Obsolete, to be removed from libpng-1.4.0 */
return (png_ptr? 0: 0);
}
-/* this function was added to libpng 1.2.0 */
+/* This function was added to libpng 1.2.0 */
png_uint_32 PNGAPI
png_get_mmx_rowbytes_threshold (png_structp png_ptr)
{
- /* obsolete, to be removed from libpng-1.4.0 */
+ /* Obsolete, to be removed from libpng-1.4.0 */
return (png_ptr? 0L: 0L);
}
#endif /* ?PNG_1_0_X */