blob: 2c2732d19731f2a47da102d61feaee2ff8107ba2 [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-Pehrson145f5c82008-07-10 09:13:13 -05004 * Last changed in libpng 1.40. [July 10, 2008]
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05006 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05007 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 */
Andreas Dilger47a0c421997-05-16 02:46:07 -050010
Andreas Dilger47a0c421997-05-16 02:46:07 -050011#include "png.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060012#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050013#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060014
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050015png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050016png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
17{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060018 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050019 return(info_ptr->valid & flag);
20 else
21 return(0);
22}
23
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050024png_size_t PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050025png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
26{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060027 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050028 return(info_ptr->rowbytes);
29 else
30 return(0);
31}
32
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060033#if defined(PNG_INFO_IMAGE_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050034png_bytepp PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060035png_get_rows(png_structp png_ptr, png_infop info_ptr)
36{
37 if (png_ptr != NULL && info_ptr != NULL)
38 return(info_ptr->row_pointers);
39 else
40 return(0);
41}
42#endif
43
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060044#ifdef PNG_EASY_ACCESS_SUPPORTED
45/* easy access to info, added in libpng-0.99 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050046png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060047png_get_image_width(png_structp png_ptr, png_infop info_ptr)
48{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060049 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060050 {
51 return info_ptr->width;
52 }
53 return (0);
54}
55
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050056png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060057png_get_image_height(png_structp png_ptr, png_infop info_ptr)
58{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060059 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060060 {
61 return info_ptr->height;
62 }
63 return (0);
64}
65
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050066png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060067png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
68{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060069 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060070 {
71 return info_ptr->bit_depth;
72 }
73 return (0);
74}
75
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050076png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060077png_get_color_type(png_structp png_ptr, png_infop info_ptr)
78{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060079 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060080 {
81 return info_ptr->color_type;
82 }
83 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 {
91 return info_ptr->filter_type;
92 }
93 return (0);
94}
95
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050096png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060097png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
98{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060099 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600100 {
101 return info_ptr->interlace_type;
102 }
103 return (0);
104}
105
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500106png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600107png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
108{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600109 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600110 {
111 return info_ptr->compression_type;
112 }
113 return (0);
114}
115
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500116png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600117png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
118{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500119 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600120#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500121 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600122 {
123 png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500124 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600125 return (0);
126 else return (info_ptr->x_pixels_per_unit);
127 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500128#else
129 return (0);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600130#endif
131 return (0);
132}
133
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500134png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600135png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
136{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500137 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600138#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500139 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600140 {
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500141 png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500142 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600143 return (0);
144 else return (info_ptr->y_pixels_per_unit);
145 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500146#else
147 return (0);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600148#endif
149 return (0);
150}
151
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500152png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600153png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
154{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500155 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600156#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500157 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600158 {
159 png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500160 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600161 info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600162 return (0);
163 else return (info_ptr->x_pixels_per_unit);
164 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500165#else
166 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600167#endif
168 return (0);
169}
170
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600171#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500172float PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600173png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
174 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500175 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600176#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500177 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600178 {
179 png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
180 if (info_ptr->x_pixels_per_unit == 0)
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600181 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600182 else
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500183 return ((float)((float)info_ptr->y_pixels_per_unit
184 /(float)info_ptr->x_pixels_per_unit));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600185 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500186#else
187 return (0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600188#endif
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500189 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600190}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600191#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600192
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500193png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600194png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
195{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500196 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600197#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500198 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600199 {
200 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500201 if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600202 return (0);
203 else return (info_ptr->x_offset);
204 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500205#else
206 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600207#endif
208 return (0);
209}
210
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500211png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600212png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
213{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500214 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600215#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500216 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600217 {
218 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500219 if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600220 return (0);
221 else return (info_ptr->y_offset);
222 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500223#else
224 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600225#endif
226 return (0);
227}
228
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500229png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600230png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
231{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500232 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600233#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500234 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600235 {
236 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500237 if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600238 return (0);
239 else return (info_ptr->x_offset);
240 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500241#else
242 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600243#endif
244 return (0);
245}
246
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500247png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600248png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
249{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500250 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600251#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500252 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600253 {
254 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500255 if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600256 return (0);
257 else return (info_ptr->y_offset);
258 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500259#else
260 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600261#endif
262 return (0);
263}
264
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600265#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500266png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600267png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
268{
269 return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500270 *.0254 +.5));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600271}
272
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500273png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600274png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
275{
276 return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500277 *.0254 +.5));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600278}
279
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500280png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600281png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
282{
283 return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500284 *.0254 +.5));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600285}
286
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500287float PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600288png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
289{
290 return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600291 *.00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600292}
293
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500294float PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600295png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
296{
297 return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500298 *.00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600299}
300
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500301#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500302png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600303png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
304 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
305{
306 png_uint_32 retval = 0;
307
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600308 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600309 {
310 png_debug1(1, "in %s retrieval function\n", "pHYs");
311 if (res_x != NULL)
312 {
313 *res_x = info_ptr->x_pixels_per_unit;
314 retval |= PNG_INFO_pHYs;
315 }
316 if (res_y != NULL)
317 {
318 *res_y = info_ptr->y_pixels_per_unit;
319 retval |= PNG_INFO_pHYs;
320 }
321 if (unit_type != NULL)
322 {
323 *unit_type = (int)info_ptr->phys_unit_type;
324 retval |= PNG_INFO_pHYs;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500325 if (*unit_type == 1)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600326 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600327 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
328 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600329 }
330 }
331 }
332 return (retval);
333}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500334#endif /* PNG_pHYs_SUPPORTED */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600335#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600336
337/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500338
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600339#endif /* PNG_EASY_ACCESS_SUPPORTED */
340
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500341png_byte PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500342png_get_channels(png_structp png_ptr, png_infop info_ptr)
343{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600344 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500345 return(info_ptr->channels);
346 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600347 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500348}
349
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500350png_bytep PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500351png_get_signature(png_structp png_ptr, png_infop info_ptr)
352{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600353 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500354 return(info_ptr->signature);
355 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600356 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500357}
358
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500359#if defined(PNG_bKGD_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500360png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500361png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
362 png_color_16p *background)
363{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600364 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
365 && background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500366 {
367 png_debug1(1, "in %s retrieval function\n", "bKGD");
368 *background = &(info_ptr->background);
369 return (PNG_INFO_bKGD);
370 }
371 return (0);
372}
373#endif
374
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500375#if defined(PNG_cHRM_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600376#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500377png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500378png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
379 double *white_x, double *white_y, double *red_x, double *red_y,
380 double *green_x, double *green_y, double *blue_x, double *blue_y)
381{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600382 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500383 {
384 png_debug1(1, "in %s retrieval function\n", "cHRM");
385 if (white_x != NULL)
386 *white_x = (double)info_ptr->x_white;
387 if (white_y != NULL)
388 *white_y = (double)info_ptr->y_white;
389 if (red_x != NULL)
390 *red_x = (double)info_ptr->x_red;
391 if (red_y != NULL)
392 *red_y = (double)info_ptr->y_red;
393 if (green_x != NULL)
394 *green_x = (double)info_ptr->x_green;
395 if (green_y != NULL)
396 *green_y = (double)info_ptr->y_green;
397 if (blue_x != NULL)
398 *blue_x = (double)info_ptr->x_blue;
399 if (blue_y != NULL)
400 *blue_y = (double)info_ptr->y_blue;
401 return (PNG_INFO_cHRM);
402 }
403 return (0);
404}
405#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600406#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500407png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600408png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600409 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
410 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
411 png_fixed_point *blue_x, png_fixed_point *blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600412{
413 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
414 {
415 png_debug1(1, "in %s retrieval function\n", "cHRM");
416 if (white_x != NULL)
417 *white_x = info_ptr->int_x_white;
418 if (white_y != NULL)
419 *white_y = info_ptr->int_y_white;
420 if (red_x != NULL)
421 *red_x = info_ptr->int_x_red;
422 if (red_y != NULL)
423 *red_y = info_ptr->int_y_red;
424 if (green_x != NULL)
425 *green_x = info_ptr->int_x_green;
426 if (green_y != NULL)
427 *green_y = info_ptr->int_y_green;
428 if (blue_x != NULL)
429 *blue_x = info_ptr->int_x_blue;
430 if (blue_y != NULL)
431 *blue_y = info_ptr->int_y_blue;
432 return (PNG_INFO_cHRM);
433 }
434 return (0);
435}
436#endif
437#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500438
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500439#if defined(PNG_gAMA_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600440#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500441png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500442png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
443{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600444 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
445 && file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500446 {
447 png_debug1(1, "in %s retrieval function\n", "gAMA");
448 *file_gamma = (double)info_ptr->gamma;
449 return (PNG_INFO_gAMA);
450 }
451 return (0);
452}
453#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500454#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500455png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600456png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600457 png_fixed_point *int_file_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600458{
459 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
460 && int_file_gamma != NULL)
461 {
462 png_debug1(1, "in %s retrieval function\n", "gAMA");
463 *int_file_gamma = info_ptr->int_gamma;
464 return (PNG_INFO_gAMA);
465 }
466 return (0);
467}
468#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500469#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500470
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500471#if defined(PNG_sRGB_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500472png_uint_32 PNGAPI
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600473png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600474{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600475 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
476 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600477 {
478 png_debug1(1, "in %s retrieval function\n", "sRGB");
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600479 *file_srgb_intent = (int)info_ptr->srgb_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600480 return (PNG_INFO_sRGB);
481 }
482 return (0);
483}
484#endif
485
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500486#if defined(PNG_iCCP_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500487png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600488png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
489 png_charpp name, int *compression_type,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600490 png_charpp profile, png_uint_32 *proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600491{
492 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
493 && name != NULL && profile != NULL && proflen != NULL)
494 {
495 png_debug1(1, "in %s retrieval function\n", "iCCP");
496 *name = info_ptr->iccp_name;
497 *profile = info_ptr->iccp_profile;
498 /* compression_type is a dummy so the API won't have to change
499 if we introduce multiple compression types later. */
500 *proflen = (int)info_ptr->iccp_proflen;
501 *compression_type = (int)info_ptr->iccp_compression;
502 return (PNG_INFO_iCCP);
503 }
504 return (0);
505}
506#endif
507
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500508#if defined(PNG_sPLT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500509png_uint_32 PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600510png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600511 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600512{
513 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500514 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600515 *spalettes = info_ptr->splt_palettes;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500516 return ((png_uint_32)info_ptr->splt_palettes_num);
517 }
518 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600519}
520#endif
521
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500522#if defined(PNG_hIST_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500523png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500524png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
525{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600526 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
527 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500528 {
529 png_debug1(1, "in %s retrieval function\n", "hIST");
530 *hist = info_ptr->hist;
531 return (PNG_INFO_hIST);
532 }
533 return (0);
534}
535#endif
536
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500537png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500538png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
539 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
540 int *color_type, int *interlace_type, int *compression_type,
541 int *filter_type)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600542
Andreas Dilger47a0c421997-05-16 02:46:07 -0500543{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600544 if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500545 bit_depth != NULL && color_type != NULL)
546 {
547 png_debug1(1, "in %s retrieval function\n", "IHDR");
548 *width = info_ptr->width;
549 *height = info_ptr->height;
550 *bit_depth = info_ptr->bit_depth;
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600551 if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
552 png_error(png_ptr, "Invalid bit depth");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500553 *color_type = info_ptr->color_type;
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600554 if (info_ptr->color_type > 6)
555 png_error(png_ptr, "Invalid color type");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500556 if (compression_type != NULL)
557 *compression_type = info_ptr->compression_type;
558 if (filter_type != NULL)
559 *filter_type = info_ptr->filter_type;
560 if (interlace_type != NULL)
561 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600562
563 /* check for potential overflow of rowbytes */
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -0600564 if (*width == 0 || *width > PNG_UINT_31_MAX)
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -0600565 png_error(png_ptr, "Invalid image width");
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -0600566 if (*height == 0 || *height > PNG_UINT_31_MAX)
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -0600567 png_error(png_ptr, "Invalid image height");
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500568 if (info_ptr->width > (PNG_UINT_32_MAX
569 >> 3) /* 8-byte RGBA pixels */
570 - 64 /* bigrowbuf hack */
571 - 1 /* filter byte */
572 - 7*8 /* rounding of width to multiple of 8 pixels */
573 - 8) /* extra max_pixel_depth pad */
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600574 {
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500575 png_warning(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500576 "Width too large for libpng to process image data");
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600577 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500578 return (1);
579 }
580 return (0);
581}
582
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500583#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500584png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500585png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600586 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500587{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600588 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
589 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500590 {
591 png_debug1(1, "in %s retrieval function\n", "oFFs");
592 *offset_x = info_ptr->x_offset;
593 *offset_y = info_ptr->y_offset;
594 *unit_type = (int)info_ptr->offset_unit_type;
595 return (PNG_INFO_oFFs);
596 }
597 return (0);
598}
599#endif
600
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500601#if defined(PNG_pCAL_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500602png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500603png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
604 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
605 png_charp *units, png_charpp *params)
606{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600607 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
608 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500609 nparams != NULL && units != NULL && params != NULL)
610 {
611 png_debug1(1, "in %s retrieval function\n", "pCAL");
612 *purpose = info_ptr->pcal_purpose;
613 *X0 = info_ptr->pcal_X0;
614 *X1 = info_ptr->pcal_X1;
615 *type = (int)info_ptr->pcal_type;
616 *nparams = (int)info_ptr->pcal_nparams;
617 *units = info_ptr->pcal_units;
618 *params = info_ptr->pcal_params;
619 return (PNG_INFO_pCAL);
620 }
621 return (0);
622}
623#endif
624
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500625#if defined(PNG_sCAL_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600626#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500627png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600628png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600629 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600630{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600631 if (png_ptr != NULL && info_ptr != NULL &&
632 (info_ptr->valid & PNG_INFO_sCAL))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600633 {
634 *unit = info_ptr->scal_unit;
635 *width = info_ptr->scal_pixel_width;
636 *height = info_ptr->scal_pixel_height;
637 return (PNG_INFO_sCAL);
638 }
639 return(0);
640}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600641#else
642#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500643png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600644png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600645 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600646{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600647 if (png_ptr != NULL && info_ptr != NULL &&
648 (info_ptr->valid & PNG_INFO_sCAL))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600649 {
650 *unit = info_ptr->scal_unit;
651 *width = info_ptr->scal_s_width;
652 *height = info_ptr->scal_s_height;
653 return (PNG_INFO_sCAL);
654 }
655 return(0);
656}
657#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600658#endif
659#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600660
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500661#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500662png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500663png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
664 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
665{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600666 png_uint_32 retval = 0;
667
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600668 if (png_ptr != NULL && info_ptr != NULL &&
669 (info_ptr->valid & PNG_INFO_pHYs))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500670 {
671 png_debug1(1, "in %s retrieval function\n", "pHYs");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600672 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600673 {
674 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600675 retval |= PNG_INFO_pHYs;
676 }
677 if (res_y != NULL)
678 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600679 *res_y = info_ptr->y_pixels_per_unit;
680 retval |= PNG_INFO_pHYs;
681 }
682 if (unit_type != NULL)
683 {
684 *unit_type = (int)info_ptr->phys_unit_type;
685 retval |= PNG_INFO_pHYs;
686 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500687 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600688 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500689}
690#endif
691
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500692png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500693png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
694 int *num_palette)
695{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600696 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
697 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500698 {
699 png_debug1(1, "in %s retrieval function\n", "PLTE");
700 *palette = info_ptr->palette;
701 *num_palette = info_ptr->num_palette;
702 png_debug1(3, "num_palette = %d\n", *num_palette);
703 return (PNG_INFO_PLTE);
704 }
705 return (0);
706}
707
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500708#if defined(PNG_sBIT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500709png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500710png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
711{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600712 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
713 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500714 {
715 png_debug1(1, "in %s retrieval function\n", "sBIT");
716 *sig_bit = &(info_ptr->sig_bit);
717 return (PNG_INFO_sBIT);
718 }
719 return (0);
720}
721#endif
722
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500723#if defined(PNG_TEXT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500724png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500725png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
726 int *num_text)
727{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600728 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500729 {
730 png_debug1(1, "in %s retrieval function\n",
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600731 (png_ptr->chunk_name[0] == '\0' ? "text"
732 : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500733 if (text_ptr != NULL)
734 *text_ptr = info_ptr->text;
735 if (num_text != NULL)
736 *num_text = info_ptr->num_text;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600737 return ((png_uint_32)info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500738 }
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600739 if (num_text != NULL)
740 *num_text = 0;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500741 return(0);
742}
743#endif
744
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500745#if defined(PNG_tIME_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500746png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500747png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
748{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600749 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
750 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500751 {
752 png_debug1(1, "in %s retrieval function\n", "tIME");
753 *mod_time = &(info_ptr->mod_time);
754 return (PNG_INFO_tIME);
755 }
756 return (0);
757}
758#endif
759
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500760#if defined(PNG_tRNS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500761png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500762png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
763 png_bytep *trans, int *num_trans, png_color_16p *trans_values)
764{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600765 png_uint_32 retval = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600766 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500767 {
768 png_debug1(1, "in %s retrieval function\n", "tRNS");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600769 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500770 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600771 if (trans != NULL)
772 {
773 *trans = info_ptr->trans;
774 retval |= PNG_INFO_tRNS;
775 }
776 if (trans_values != NULL)
777 *trans_values = &(info_ptr->trans_values);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500778 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600779 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500780 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600781 if (trans_values != NULL)
782 {
783 *trans_values = &(info_ptr->trans_values);
784 retval |= PNG_INFO_tRNS;
785 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500786 if (trans != NULL)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600787 *trans = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500788 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500789 if (num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500790 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600791 *num_trans = info_ptr->num_trans;
792 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500793 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500794 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600795 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500796}
797#endif
798
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500799#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500800png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600801png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
802 png_unknown_chunkpp unknowns)
803{
804 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500805 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600806 *unknowns = info_ptr->unknown_chunks;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500807 return ((png_uint_32)info_ptr->unknown_chunks_num);
808 }
809 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600810}
811#endif
812
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600813#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500814png_byte PNGAPI
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600815png_get_rgb_to_gray_status (png_structp png_ptr)
816{
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600817 return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600818}
819#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600820
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500821#if defined(PNG_USER_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500822png_voidp PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600823png_get_user_chunk_ptr(png_structp png_ptr)
824{
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600825 return (png_ptr? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600826}
827#endif
828
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500829#ifdef PNG_WRITE_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500830png_size_t PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500831png_get_compression_buffer_size(png_structp png_ptr)
832{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500833 return (png_ptr ? png_ptr->zbuf_size : 0L);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500834}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500835#endif
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500836
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500837
838#ifdef PNG_SET_USER_LIMITS_SUPPORTED
839/* these functions were added to libpng 1.2.6 */
840png_uint_32 PNGAPI
841png_get_user_width_max (png_structp png_ptr)
842{
843 return (png_ptr? png_ptr->user_width_max : 0);
844}
845png_uint_32 PNGAPI
846png_get_user_height_max (png_structp png_ptr)
847{
848 return (png_ptr? png_ptr->user_height_max : 0);
849}
850#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500851
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500852#ifdef PNG_IO_STATE_SUPPORTED
853png_uint_32 PNGAPI
854png_get_io_state (png_structp png_ptr)
855{
856 return png_ptr->io_state;
857}
858
859png_bytep PNGAPI
860png_get_io_chunk_name (png_structp png_ptr)
861{
862 return png_ptr->chunk_name;
863}
864#endif /* ?PNG_IO_STATE_SUPPORTED */
865
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600866#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */