blob: 045f0003d0f1281c6238551f1cb2ce9c2bb3531b [file] [log] [blame]
Andreas Dilger47a0c421997-05-16 02:46:07 -05001
2/* pngget.c - retrieval of values from info struct
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrsonf197d6d2010-10-15 19:22:01 -05004 * Last changed in libpng 1.5.0 [(PENDING RELEASE)]
Glenn Randers-Pehrsone69b55d2010-01-01 10:29:06 -06005 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -05008 *
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05009 * This code is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -050010 * For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -050011 * and license in png.h
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -050012 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060013 */
Andreas Dilger47a0c421997-05-16 02:46:07 -050014
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050015#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060016
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060017#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
18
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050019png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050020png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
21{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060022 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050023 return(info_ptr->valid & flag);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050024
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -050025 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -050026}
27
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050028png_size_t PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050029png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
30{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060031 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050032 return(info_ptr->rowbytes);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050033
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -050034 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -050035}
36
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050037#ifdef PNG_INFO_IMAGE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050038png_bytepp PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060039png_get_rows(png_structp png_ptr, png_infop info_ptr)
40{
41 if (png_ptr != NULL && info_ptr != NULL)
42 return(info_ptr->row_pointers);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050043
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -050044 return(0);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060045}
46#endif
47
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060048#ifdef PNG_EASY_ACCESS_SUPPORTED
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050049/* Easy access to info, added in libpng-0.99 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050050png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060051png_get_image_width(png_structp png_ptr, png_infop info_ptr)
52{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060053 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060054 return info_ptr->width;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050055
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060056 return (0);
57}
58
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050059png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060060png_get_image_height(png_structp png_ptr, png_infop info_ptr)
61{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060062 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060063 return info_ptr->height;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050064
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060065 return (0);
66}
67
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050068png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060069png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
70{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060071 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060072 return info_ptr->bit_depth;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050073
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060074 return (0);
75}
76
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050077png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060078png_get_color_type(png_structp png_ptr, png_infop info_ptr)
79{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060080 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060081 return info_ptr->color_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050082
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060083 return (0);
84}
85
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050086png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060087png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
88{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060089 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060090 return info_ptr->filter_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050091
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060092 return (0);
93}
94
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050095png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060096png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
97{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060098 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060099 return info_ptr->interlace_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500100
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600101 return (0);
102}
103
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500104png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600105png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
106{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600107 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600108 return info_ptr->compression_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500109
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600110 return (0);
111}
112
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500113png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600114png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
115{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500116#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500117 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
118 {
119 png_debug1(1, "in %s retrieval function",
120 "png_get_x_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500121
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500122 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
123 return (info_ptr->x_pixels_per_unit);
124 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600125#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500126
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600127 return (0);
128}
129
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500130png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600131png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
132{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500133#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500134 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600135 {
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500136 png_debug1(1, "in %s retrieval function",
137 "png_get_y_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500138
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500139 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600140 return (info_ptr->y_pixels_per_unit);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600141 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600142#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500143
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600144 return (0);
145}
146
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500147png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600148png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
149{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500150#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500151 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600152 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500153 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500154
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500155 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
156 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600157 return (info_ptr->x_pixels_per_unit);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600158 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600159#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500160
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600161 return (0);
162}
163
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600164#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500165float PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600166png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600167{
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500168#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500169 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600170 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500171 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500172
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500173 if (info_ptr->x_pixels_per_unit != 0)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500174 return ((float)((float)info_ptr->y_pixels_per_unit
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600175 /(float)info_ptr->x_pixels_per_unit));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600176 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600177#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500178
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500179 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600180}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600181#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600182
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500183#ifdef PNG_FIXED_POINT_SUPPORTED
184png_fixed_point PNGAPI
185png_get_pixel_aspect_ratio_fixed(png_structp png_ptr, png_infop info_ptr)
186{
187#ifdef PNG_READ_pHYs_SUPPORTED
188 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500189 && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
190 && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
191 && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500192 {
193 png_fixed_point res;
194
195 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
196
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500197 /* The following casts work because a PNG 4 byte integer only has a valid
198 * range of 0..2^31-1; otherwise the cast might overflow.
199 */
200 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
201 (png_int_32)info_ptr->x_pixels_per_unit))
Glenn Randers-Pehrson3df324d2010-07-31 13:45:04 -0500202 return res;
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500203 }
204#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500205
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500206 return 0;
207}
208#endif
209
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500210png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600211png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
212{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500213#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500214 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600215 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500216 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500217
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500218 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600219 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600220 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600221#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500222
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600223 return (0);
224}
225
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500226png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600227png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
228{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500229#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500230 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600231 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500232 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500233
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500234 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600235 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600236 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600237#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500238
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600239 return (0);
240}
241
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500242png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600243png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
244{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500245#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500246 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600247 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500248 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500249
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500250 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600251 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600252 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600253#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500254
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600255 return (0);
256}
257
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500258png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600259png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
260{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500261#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500262 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600263 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500264 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500265
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500266 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600267 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600268 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600269#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500270
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600271 return (0);
272}
273
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500274#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
275static png_uint_32
276ppi_from_ppm(png_uint_32 ppm)
277{
278#if 0
Glenn Randers-Pehrson233357e2010-07-29 21:49:38 -0500279 /* The conversion is *(2.54/100), in binary (32 digits):
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500280 * .00000110100000001001110101001001
281 */
282 png_uint_32 t1001, t1101;
283 ppm >>= 1; /* .1 */
284 t1001 = ppm + (ppm >> 3); /* .1001 */
285 t1101 = t1001 + (ppm >> 1); /* .1101 */
286 ppm >>= 20; /* .000000000000000000001 */
287 t1101 += t1101 >> 15; /* .1101000000000001101 */
288 t1001 >>= 11; /* .000000000001001 */
289 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
290 ppm += t1001; /* .000000000001001000001001001 */
291 ppm += t1101; /* .110100000001001110101001001 */
292 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
293#else
294 /* The argument is a PNG unsigned integer, so it is not permitted
295 * to be bigger than 2^31.
296 */
297 png_fixed_point result;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500298 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
299 5000))
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500300 return result;
301
302 /* Overflow. */
303 return 0;
304#endif
305}
306
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500307png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600308png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
309{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500310 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600311}
312
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500313png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600314png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
315{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500316 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600317}
318
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500319png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600320png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
321{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500322 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600323}
324
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500325#ifdef PNG_FIXED_POINT_SUPPORTED
326static png_fixed_point
327png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns)
328{
329 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500330 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500331 * Notice that this can overflow - a warning is output and 0 is
332 * returned.
333 */
334 return png_muldiv_warn(png_ptr, microns, 500, 127);
335}
336
337png_fixed_point PNGAPI
338png_get_x_offset_inches_fixed(png_structp png_ptr, png_infop info_ptr)
339{
340 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500341 png_get_x_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500342}
343#endif
344
345#ifdef PNG_FIXED_POINT_SUPPORTED
346png_fixed_point PNGAPI
347png_get_y_offset_inches_fixed(png_structp png_ptr, png_infop info_ptr)
348{
349 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500350 png_get_y_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500351}
352#endif
353
354#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500355float PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600356png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
357{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500358 /* To avoid the overflow do the conversion directly in floating
359 * point.
360 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500361 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600362}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500363#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600364
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500365#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500366float PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600367png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
368{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500369 /* To avoid the overflow do the conversion directly in floating
370 * point.
371 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500372 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600373}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500374#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600375
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500376#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500377png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600378png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600379 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600380{
381 png_uint_32 retval = 0;
382
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600383 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600384 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500385 png_debug1(1, "in %s retrieval function", "pHYs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500386
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600387 if (res_x != NULL)
388 {
389 *res_x = info_ptr->x_pixels_per_unit;
390 retval |= PNG_INFO_pHYs;
391 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500392
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600393 if (res_y != NULL)
394 {
395 *res_y = info_ptr->y_pixels_per_unit;
396 retval |= PNG_INFO_pHYs;
397 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500398
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600399 if (unit_type != NULL)
400 {
401 *unit_type = (int)info_ptr->phys_unit_type;
402 retval |= PNG_INFO_pHYs;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500403
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500404 if (*unit_type == 1)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600405 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600406 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
407 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600408 }
409 }
410 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500411
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600412 return (retval);
413}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500414#endif /* PNG_pHYs_SUPPORTED */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500415#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600416
417/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500418
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600419#endif /* PNG_EASY_ACCESS_SUPPORTED */
420
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500421png_byte PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500422png_get_channels(png_structp png_ptr, png_infop info_ptr)
423{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600424 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500425 return(info_ptr->channels);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500426
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500427 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500428}
429
Glenn Randers-Pehrsone600c512010-08-18 07:25:46 -0500430png_const_bytep PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500431png_get_signature(png_structp png_ptr, png_infop info_ptr)
432{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600433 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500434 return(info_ptr->signature);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500435
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500436 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500437}
438
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500439#ifdef PNG_bKGD_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500440png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500441png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
442 png_color_16p *background)
443{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600444 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600445 && background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500446 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500447 png_debug1(1, "in %s retrieval function", "bKGD");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500448
Andreas Dilger47a0c421997-05-16 02:46:07 -0500449 *background = &(info_ptr->background);
450 return (PNG_INFO_bKGD);
451 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500452
Andreas Dilger47a0c421997-05-16 02:46:07 -0500453 return (0);
454}
455#endif
456
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500457#ifdef PNG_cHRM_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500458# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500459png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500460png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600461 double *white_x, double *white_y, double *red_x, double *red_y,
462 double *green_x, double *green_y, double *blue_x, double *blue_y)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500463{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600464 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500465 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500466 png_debug1(1, "in %s retrieval function", "cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500467
Andreas Dilger47a0c421997-05-16 02:46:07 -0500468 if (white_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500469 *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500470 if (white_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500471 *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500472 if (red_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500473 *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500474 if (red_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500475 *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500476 if (green_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500477 *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500478 if (green_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500479 *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500480 if (blue_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500481 *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500482 if (blue_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500483 *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500484 return (PNG_INFO_cHRM);
485 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500486
Andreas Dilger47a0c421997-05-16 02:46:07 -0500487 return (0);
488}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500489# endif
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500490
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500491# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500492png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600493png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600494 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
495 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
496 png_fixed_point *blue_x, png_fixed_point *blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600497{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500498 png_debug1(1, "in %s retrieval function", "cHRM");
499
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600500 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
501 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600502 if (white_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500503 *white_x = info_ptr->x_white;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600504 if (white_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500505 *white_y = info_ptr->y_white;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600506 if (red_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500507 *red_x = info_ptr->x_red;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600508 if (red_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500509 *red_y = info_ptr->y_red;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600510 if (green_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500511 *green_x = info_ptr->x_green;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600512 if (green_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500513 *green_y = info_ptr->y_green;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600514 if (blue_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500515 *blue_x = info_ptr->x_blue;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600516 if (blue_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500517 *blue_y = info_ptr->y_blue;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600518 return (PNG_INFO_cHRM);
519 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500520
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600521 return (0);
522}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500523# endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600524#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500525
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500526#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500527png_uint_32 PNGFAPI
528png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
529 png_fixed_point *file_gamma)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500530{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500531 png_debug1(1, "in %s retrieval function", "gAMA");
532
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600533 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600534 && file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500535 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500536 *file_gamma = info_ptr->gamma;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500537 return (PNG_INFO_gAMA);
538 }
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500539
Andreas Dilger47a0c421997-05-16 02:46:07 -0500540 return (0);
541}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500542# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500543png_uint_32 PNGAPI
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500544png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600545{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500546 png_fixed_point igamma;
547 png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma);
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500548
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500549 if (ok)
550 *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA");
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500551
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500552 return ok;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600553}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500554
555# endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500556#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500557
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500558#ifdef PNG_sRGB_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500559png_uint_32 PNGAPI
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600560png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600561{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500562 png_debug1(1, "in %s retrieval function", "sRGB");
563
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600564 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600565 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600566 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600567 *file_srgb_intent = (int)info_ptr->srgb_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600568 return (PNG_INFO_sRGB);
569 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500570
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600571 return (0);
572}
573#endif
574
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500575#ifdef PNG_iCCP_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500576png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600577png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600578 png_charpp name, int *compression_type,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500579 png_bytepp profile, png_uint_32 *proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600580{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500581 png_debug1(1, "in %s retrieval function", "iCCP");
582
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600583 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600584 && name != NULL && profile != NULL && proflen != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600585 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600586 *name = info_ptr->iccp_name;
587 *profile = info_ptr->iccp_profile;
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500588 /* Compression_type is a dummy so the API won't have to change
589 * if we introduce multiple compression types later.
590 */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600591 *proflen = (int)info_ptr->iccp_proflen;
592 *compression_type = (int)info_ptr->iccp_compression;
593 return (PNG_INFO_iCCP);
594 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500595
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600596 return (0);
597}
598#endif
599
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500600#ifdef PNG_sPLT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500601png_uint_32 PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600602png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600603 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600604{
605 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500606 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600607 *spalettes = info_ptr->splt_palettes;
608 return ((png_uint_32)info_ptr->splt_palettes_num);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500609 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500610
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500611 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600612}
613#endif
614
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500615#ifdef PNG_hIST_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500616png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500617png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
618{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500619 png_debug1(1, "in %s retrieval function", "hIST");
620
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600621 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600622 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500623 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500624 *hist = info_ptr->hist;
625 return (PNG_INFO_hIST);
626 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500627
Andreas Dilger47a0c421997-05-16 02:46:07 -0500628 return (0);
629}
630#endif
631
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500632png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500633png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600634 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
635 int *color_type, int *interlace_type, int *compression_type,
636 int *filter_type)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600637
Andreas Dilger47a0c421997-05-16 02:46:07 -0500638{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500639 png_debug1(1, "in %s retrieval function", "IHDR");
640
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500641 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
642 height == NULL || bit_depth == NULL || color_type == NULL)
643 return (0);
644
645 *width = info_ptr->width;
646 *height = info_ptr->height;
647 *bit_depth = info_ptr->bit_depth;
648 *color_type = info_ptr->color_type;
649
650 if (compression_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500651 *compression_type = info_ptr->compression_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500652
653 if (filter_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500654 *filter_type = info_ptr->filter_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500655
656 if (interlace_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500657 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500658
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500659 /* This is redundant if we can be sure that the info_ptr values were all
660 * assigned in png_set_IHDR(). We do the check anyhow in case an
661 * application has ignored our advice not to mess with the members
662 * of info_ptr directly.
663 */
664 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
665 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
666 info_ptr->compression_type, info_ptr->filter_type);
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500667
668 return (1);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500669}
670
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500671#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500672png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500673png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600674 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500675{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500676 png_debug1(1, "in %s retrieval function", "oFFs");
677
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600678 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600679 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500680 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500681 *offset_x = info_ptr->x_offset;
682 *offset_y = info_ptr->y_offset;
683 *unit_type = (int)info_ptr->offset_unit_type;
684 return (PNG_INFO_oFFs);
685 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500686
Andreas Dilger47a0c421997-05-16 02:46:07 -0500687 return (0);
688}
689#endif
690
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500691#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500692png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500693png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600694 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
695 png_charp *units, png_charpp *params)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500696{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500697 png_debug1(1, "in %s retrieval function", "pCAL");
698
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600699 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500700 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
701 nparams != NULL && units != NULL && params != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500702 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500703 *purpose = info_ptr->pcal_purpose;
704 *X0 = info_ptr->pcal_X0;
705 *X1 = info_ptr->pcal_X1;
706 *type = (int)info_ptr->pcal_type;
707 *nparams = (int)info_ptr->pcal_nparams;
708 *units = info_ptr->pcal_units;
709 *params = info_ptr->pcal_params;
710 return (PNG_INFO_pCAL);
711 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500712
Andreas Dilger47a0c421997-05-16 02:46:07 -0500713 return (0);
714}
715#endif
716
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500717#ifdef PNG_sCAL_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500718# ifdef PNG_FIXED_POINT_SUPPORTED
719# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500720png_uint_32 PNGAPI
721png_get_sCAL_fixed(png_structp png_ptr, png_infop info_ptr,
722 int *unit, png_fixed_point *width, png_fixed_point *height)
723{
724 if (png_ptr != NULL && info_ptr != NULL &&
725 (info_ptr->valid & PNG_INFO_sCAL))
726 {
727 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500728 /*TODO: make this work without FP support */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500729 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
730 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
731 "sCAL height");
732 return (PNG_INFO_sCAL);
733 }
734
735 return(0);
736}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500737# endif /* FLOATING_ARITHMETIC */
738# endif /* FIXED_POINT */
739# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500740png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600741png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600742 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600743{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600744 if (png_ptr != NULL && info_ptr != NULL &&
745 (info_ptr->valid & PNG_INFO_sCAL))
746 {
747 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500748 *width = atof(info_ptr->scal_s_width);
749 *height = atof(info_ptr->scal_s_height);
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600750 return (PNG_INFO_sCAL);
751 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500752
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600753 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600754}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500755# endif /* FLOATING POINT */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500756png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600757png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500758 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600759{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600760 if (png_ptr != NULL && info_ptr != NULL &&
761 (info_ptr->valid & PNG_INFO_sCAL))
762 {
763 *unit = info_ptr->scal_unit;
764 *width = info_ptr->scal_s_width;
765 *height = info_ptr->scal_s_height;
766 return (PNG_INFO_sCAL);
767 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500768
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600769 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600770}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500771#endif /* sCAL */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600772
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500773#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500774png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500775png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600776 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500777{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600778 png_uint_32 retval = 0;
779
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500780 png_debug1(1, "in %s retrieval function", "pHYs");
781
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600782 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600783 (info_ptr->valid & PNG_INFO_pHYs))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500784 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600785 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600786 {
787 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600788 retval |= PNG_INFO_pHYs;
789 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500790
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600791 if (res_y != NULL)
792 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600793 *res_y = info_ptr->y_pixels_per_unit;
794 retval |= PNG_INFO_pHYs;
795 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500796
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600797 if (unit_type != NULL)
798 {
799 *unit_type = (int)info_ptr->phys_unit_type;
800 retval |= PNG_INFO_pHYs;
801 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500802 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500803
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600804 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500805}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500806#endif /* pHYs */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500807
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500808png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500809png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600810 int *num_palette)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500811{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500812 png_debug1(1, "in %s retrieval function", "PLTE");
813
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600814 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
815 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500816 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500817 *palette = info_ptr->palette;
818 *num_palette = info_ptr->num_palette;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500819 png_debug1(3, "num_palette = %d", *num_palette);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500820 return (PNG_INFO_PLTE);
821 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500822
Andreas Dilger47a0c421997-05-16 02:46:07 -0500823 return (0);
824}
825
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500826#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500827png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500828png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
829{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500830 png_debug1(1, "in %s retrieval function", "sBIT");
831
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600832 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600833 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500834 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500835 *sig_bit = &(info_ptr->sig_bit);
836 return (PNG_INFO_sBIT);
837 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500838
Andreas Dilger47a0c421997-05-16 02:46:07 -0500839 return (0);
840}
841#endif
842
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500843#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500844png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500845png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600846 int *num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500847{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600848 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500849 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500850 png_debug1(1, "in %s retrieval function",
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600851 (png_ptr->chunk_name[0] == '\0' ? "text" :
852 (png_const_charp)png_ptr->chunk_name));
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500853
Andreas Dilger47a0c421997-05-16 02:46:07 -0500854 if (text_ptr != NULL)
855 *text_ptr = info_ptr->text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500856
Andreas Dilger47a0c421997-05-16 02:46:07 -0500857 if (num_text != NULL)
858 *num_text = info_ptr->num_text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500859
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600860 return ((png_uint_32)info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500861 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500862
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600863 if (num_text != NULL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600864 *num_text = 0;
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500865
Andreas Dilger47a0c421997-05-16 02:46:07 -0500866 return(0);
867}
868#endif
869
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500870#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500871png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500872png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
873{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500874 png_debug1(1, "in %s retrieval function", "tIME");
875
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600876 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
877 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500878 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500879 *mod_time = &(info_ptr->mod_time);
880 return (PNG_INFO_tIME);
881 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500882
Andreas Dilger47a0c421997-05-16 02:46:07 -0500883 return (0);
884}
885#endif
886
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500887#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500888png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500889png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600890 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500891{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600892 png_uint_32 retval = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600893 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500894 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500895 png_debug1(1, "in %s retrieval function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500896
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600897 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500898 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600899 if (trans_alpha != NULL)
900 {
901 *trans_alpha = info_ptr->trans_alpha;
902 retval |= PNG_INFO_tRNS;
903 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500904
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600905 if (trans_color != NULL)
906 *trans_color = &(info_ptr->trans_color);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500907 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500908
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600909 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500910 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600911 if (trans_color != NULL)
912 {
913 *trans_color = &(info_ptr->trans_color);
914 retval |= PNG_INFO_tRNS;
915 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500916
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600917 if (trans_alpha != NULL)
918 *trans_alpha = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500919 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500920
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500921 if (num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500922 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600923 *num_trans = info_ptr->num_trans;
924 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500925 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500926 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500927
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600928 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500929}
930#endif
931
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500932#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500933int PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600934png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600935 png_unknown_chunkpp unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600936{
937 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500938 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600939 *unknowns = info_ptr->unknown_chunks;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500940 return info_ptr->unknown_chunks_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500941 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500942
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500943 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600944}
945#endif
946
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500947#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500948png_byte PNGAPI
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600949png_get_rgb_to_gray_status (png_structp png_ptr)
950{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -0600951 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600952}
953#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600954
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500955#ifdef PNG_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500956png_voidp PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600957png_get_user_chunk_ptr(png_structp png_ptr)
958{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -0600959 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600960}
961#endif
962
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500963png_size_t PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500964png_get_compression_buffer_size(png_structp png_ptr)
965{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500966 return (png_ptr ? png_ptr->zbuf_size : 0L);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500967}
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500968
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500969
970#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600971/* These functions were added to libpng 1.2.6 and were enabled
972 * by default in libpng-1.4.0 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500973png_uint_32 PNGAPI
974png_get_user_width_max (png_structp png_ptr)
975{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -0600976 return (png_ptr ? png_ptr->user_width_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500977}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500978
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500979png_uint_32 PNGAPI
980png_get_user_height_max (png_structp png_ptr)
981{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -0600982 return (png_ptr ? png_ptr->user_height_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500983}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500984
Glenn Randers-Pehrson17ca3402009-11-09 06:51:16 -0600985/* This function was added to libpng 1.4.0 */
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500986png_uint_32 PNGAPI
987png_get_chunk_cache_max (png_structp png_ptr)
988{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -0600989 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600990}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500991
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600992/* This function was added to libpng 1.4.1 */
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -0600993png_alloc_size_t PNGAPI
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600994png_get_chunk_malloc_max (png_structp png_ptr)
995{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -0600996 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500997}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500998#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -0500999
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001000/* These functions were added to libpng 1.4.0 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001001#ifdef PNG_IO_STATE_SUPPORTED
1002png_uint_32 PNGAPI
1003png_get_io_state (png_structp png_ptr)
1004{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001005 return png_ptr->io_state;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001006}
1007
Glenn Randers-Pehrsone600c512010-08-18 07:25:46 -05001008png_const_bytep PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001009png_get_io_chunk_name (png_structp png_ptr)
1010{
1011 return png_ptr->chunk_name;
1012}
1013#endif /* ?PNG_IO_STATE_SUPPORTED */
1014
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001015#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */