blob: bcc0dce96533943711002ba96926f9522bd1c6fd [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-Pehrsond60b8fa2006-04-20 21:31:14 -05004 * Last changed in libpng 1.4.0 April 20, 2006
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06006 * Copyright (c) 1998-2006 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-Pehrsonbeb572e2006-08-19 13:59:24 -050012#include "pngpriv.h"
Andreas Dilger47a0c421997-05-16 02:46:07 -050013
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060014#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
15
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050016png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050017png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
18{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060019 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050020 return(info_ptr->valid & flag);
21 else
22 return(0);
23}
24
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050025png_size_t PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -050026png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
27{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060028 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050029 return(info_ptr->rowbytes);
30 else
31 return(0);
32}
33
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060034#if defined(PNG_INFO_IMAGE_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050035png_bytepp PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060036png_get_rows(png_structp png_ptr, png_infop info_ptr)
37{
38 if (png_ptr != NULL && info_ptr != NULL)
39 return(info_ptr->row_pointers);
40 else
41 return(0);
42}
43#endif
44
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060045#ifdef PNG_EASY_ACCESS_SUPPORTED
46/* easy access to info, added in libpng-0.99 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050047png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060048png_get_image_width(png_structp png_ptr, png_infop info_ptr)
49{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060050 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060051 {
52 return info_ptr->width;
53 }
54 return (0);
55}
56
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050057png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060058png_get_image_height(png_structp png_ptr, png_infop info_ptr)
59{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060060 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060061 {
62 return info_ptr->height;
63 }
64 return (0);
65}
66
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050067png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060068png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
69{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060070 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060071 {
72 return info_ptr->bit_depth;
73 }
74 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 {
82 return info_ptr->color_type;
83 }
84 return (0);
85}
86
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050087png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060088png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
89{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060090 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060091 {
92 return info_ptr->filter_type;
93 }
94 return (0);
95}
96
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050097png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060098png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
99{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600100 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600101 {
102 return info_ptr->interlace_type;
103 }
104 return (0);
105}
106
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500107png_byte PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600108png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
109{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600110 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600111 {
112 return info_ptr->compression_type;
113 }
114 return (0);
115}
116
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500117png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600118png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
119{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500120 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600121#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500122 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600123 {
124 png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
125 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
126 return (0);
127 else return (info_ptr->x_pixels_per_unit);
128 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500129#else
130 return (0);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600131#endif
132 return (0);
133}
134
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500135png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600136png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
137{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500138 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600139#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500140 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600141 {
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500142 png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600143 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
144 return (0);
145 else return (info_ptr->y_pixels_per_unit);
146 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500147#else
148 return (0);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600149#endif
150 return (0);
151}
152
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500153png_uint_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600154png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
155{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500156 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600157#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500158 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600159 {
160 png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600161 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
162 info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600163 return (0);
164 else return (info_ptr->x_pixels_per_unit);
165 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500166#else
167 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600168#endif
169 return (0);
170}
171
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600172#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500173float PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600174png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
175 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500176 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600177#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500178 if (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600179 {
180 png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
181 if (info_ptr->x_pixels_per_unit == 0)
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600182 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600183 else
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500184 return ((float)((float)info_ptr->y_pixels_per_unit
185 /(float)info_ptr->x_pixels_per_unit));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600186 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500187#else
188 return (0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600189#endif
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500190 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600191}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600192#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600193
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500194png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600195png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
196{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500197 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600198#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500199 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600200 {
201 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
202 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
203 return (0);
204 else return (info_ptr->x_offset);
205 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500206#else
207 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600208#endif
209 return (0);
210}
211
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500212png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600213png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
214{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500215 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600216#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500217 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600218 {
219 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
220 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
221 return (0);
222 else return (info_ptr->y_offset);
223 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500224#else
225 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600226#endif
227 return (0);
228}
229
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500230png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600231png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
232{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500233 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600234#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500235 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600236 {
237 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
238 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
239 return (0);
240 else return (info_ptr->x_offset);
241 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500242#else
243 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600244#endif
245 return (0);
246}
247
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500248png_int_32 PNGAPI
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600249png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
250{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500251 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600252#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500253 if (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600254 {
255 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
256 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
257 return (0);
258 else return (info_ptr->y_offset);
259 }
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500260#else
261 return (0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600262#endif
263 return (0);
264}
265
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600266#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500267png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600268png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
269{
270 return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500271 *.0254 +.5));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600272}
273
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500274png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600275png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
276{
277 return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500278 *.0254 +.5));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600279}
280
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500281png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600282png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
283{
284 return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500285 *.0254 +.5));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600286}
287
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500288float PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600289png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
290{
291 return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600292 *.00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600293}
294
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500295float PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600296png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
297{
298 return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500299 *.00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600300}
301
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500302#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500303png_uint_32 PNGAPI
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600304png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
305 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
306{
307 png_uint_32 retval = 0;
308
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600309 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600310 {
311 png_debug1(1, "in %s retrieval function\n", "pHYs");
312 if (res_x != NULL)
313 {
314 *res_x = info_ptr->x_pixels_per_unit;
315 retval |= PNG_INFO_pHYs;
316 }
317 if (res_y != NULL)
318 {
319 *res_y = info_ptr->y_pixels_per_unit;
320 retval |= PNG_INFO_pHYs;
321 }
322 if (unit_type != NULL)
323 {
324 *unit_type = (int)info_ptr->phys_unit_type;
325 retval |= PNG_INFO_pHYs;
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500326 if(*unit_type == 1)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600327 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600328 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
329 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600330 }
331 }
332 }
333 return (retval);
334}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500335#endif /* PNG_pHYs_SUPPORTED */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600336#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600337
338/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500339
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600340#endif /* PNG_EASY_ACCESS_SUPPORTED */
341
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500342png_byte PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500343png_get_channels(png_structp png_ptr, png_infop info_ptr)
344{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600345 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500346 return(info_ptr->channels);
347 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600348 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500349}
350
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500351png_bytep PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500352png_get_signature(png_structp png_ptr, png_infop info_ptr)
353{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600354 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500355 return(info_ptr->signature);
356 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600357 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500358}
359
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500360#if defined(PNG_bKGD_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500361png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500362png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
363 png_color_16p *background)
364{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600365 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
366 && background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500367 {
368 png_debug1(1, "in %s retrieval function\n", "bKGD");
369 *background = &(info_ptr->background);
370 return (PNG_INFO_bKGD);
371 }
372 return (0);
373}
374#endif
375
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500376#if defined(PNG_cHRM_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600377#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500378png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500379png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
380 double *white_x, double *white_y, double *red_x, double *red_y,
381 double *green_x, double *green_y, double *blue_x, double *blue_y)
382{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600383 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500384 {
385 png_debug1(1, "in %s retrieval function\n", "cHRM");
386 if (white_x != NULL)
387 *white_x = (double)info_ptr->x_white;
388 if (white_y != NULL)
389 *white_y = (double)info_ptr->y_white;
390 if (red_x != NULL)
391 *red_x = (double)info_ptr->x_red;
392 if (red_y != NULL)
393 *red_y = (double)info_ptr->y_red;
394 if (green_x != NULL)
395 *green_x = (double)info_ptr->x_green;
396 if (green_y != NULL)
397 *green_y = (double)info_ptr->y_green;
398 if (blue_x != NULL)
399 *blue_x = (double)info_ptr->x_blue;
400 if (blue_y != NULL)
401 *blue_y = (double)info_ptr->y_blue;
402 return (PNG_INFO_cHRM);
403 }
404 return (0);
405}
406#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600407#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500408png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600409png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600410 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
411 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
412 png_fixed_point *blue_x, png_fixed_point *blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600413{
414 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
415 {
416 png_debug1(1, "in %s retrieval function\n", "cHRM");
417 if (white_x != NULL)
418 *white_x = info_ptr->int_x_white;
419 if (white_y != NULL)
420 *white_y = info_ptr->int_y_white;
421 if (red_x != NULL)
422 *red_x = info_ptr->int_x_red;
423 if (red_y != NULL)
424 *red_y = info_ptr->int_y_red;
425 if (green_x != NULL)
426 *green_x = info_ptr->int_x_green;
427 if (green_y != NULL)
428 *green_y = info_ptr->int_y_green;
429 if (blue_x != NULL)
430 *blue_x = info_ptr->int_x_blue;
431 if (blue_y != NULL)
432 *blue_y = info_ptr->int_y_blue;
433 return (PNG_INFO_cHRM);
434 }
435 return (0);
436}
437#endif
438#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500439
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500440#if defined(PNG_gAMA_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600441#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500442png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500443png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
444{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600445 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
446 && file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500447 {
448 png_debug1(1, "in %s retrieval function\n", "gAMA");
449 *file_gamma = (double)info_ptr->gamma;
450 return (PNG_INFO_gAMA);
451 }
452 return (0);
453}
454#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500455#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500456png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600457png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600458 png_fixed_point *int_file_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600459{
460 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
461 && int_file_gamma != NULL)
462 {
463 png_debug1(1, "in %s retrieval function\n", "gAMA");
464 *int_file_gamma = info_ptr->int_gamma;
465 return (PNG_INFO_gAMA);
466 }
467 return (0);
468}
469#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500470#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500471
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500472#if defined(PNG_sRGB_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500473png_uint_32 PNGAPI
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600474png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600475{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600476 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
477 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600478 {
479 png_debug1(1, "in %s retrieval function\n", "sRGB");
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600480 *file_srgb_intent = (int)info_ptr->srgb_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600481 return (PNG_INFO_sRGB);
482 }
483 return (0);
484}
485#endif
486
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500487#if defined(PNG_iCCP_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500488png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600489png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
490 png_charpp name, int *compression_type,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600491 png_charpp profile, png_uint_32 *proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600492{
493 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
494 && name != NULL && profile != NULL && proflen != NULL)
495 {
496 png_debug1(1, "in %s retrieval function\n", "iCCP");
497 *name = info_ptr->iccp_name;
498 *profile = info_ptr->iccp_profile;
499 /* compression_type is a dummy so the API won't have to change
500 if we introduce multiple compression types later. */
501 *proflen = (int)info_ptr->iccp_proflen;
502 *compression_type = (int)info_ptr->iccp_compression;
503 return (PNG_INFO_iCCP);
504 }
505 return (0);
506}
507#endif
508
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500509#if defined(PNG_sPLT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500510png_uint_32 PNGAPI
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600511png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600512 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600513{
514 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
515 *spalettes = info_ptr->splt_palettes;
516 return ((png_uint_32)info_ptr->splt_palettes_num);
517}
518#endif
519
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500520#if defined(PNG_hIST_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500521png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500522png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
523{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600524 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
525 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500526 {
527 png_debug1(1, "in %s retrieval function\n", "hIST");
528 *hist = info_ptr->hist;
529 return (PNG_INFO_hIST);
530 }
531 return (0);
532}
533#endif
534
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500535png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500536png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
537 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
538 int *color_type, int *interlace_type, int *compression_type,
539 int *filter_type)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600540
Andreas Dilger47a0c421997-05-16 02:46:07 -0500541{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600542 if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500543 bit_depth != NULL && color_type != NULL)
544 {
545 png_debug1(1, "in %s retrieval function\n", "IHDR");
546 *width = info_ptr->width;
547 *height = info_ptr->height;
548 *bit_depth = info_ptr->bit_depth;
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600549 if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
550 png_error(png_ptr, "Invalid bit depth");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500551 *color_type = info_ptr->color_type;
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600552 if (info_ptr->color_type > 6)
553 png_error(png_ptr, "Invalid color type");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500554 if (compression_type != NULL)
555 *compression_type = info_ptr->compression_type;
556 if (filter_type != NULL)
557 *filter_type = info_ptr->filter_type;
558 if (interlace_type != NULL)
559 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600560
561 /* check for potential overflow of rowbytes */
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -0600562 if (*width == 0 || *width > PNG_UINT_31_MAX)
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -0600563 png_error(png_ptr, "Invalid image width");
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -0600564 if (*height == 0 || *height > PNG_UINT_31_MAX)
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -0600565 png_error(png_ptr, "Invalid image height");
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500566 if (info_ptr->width > (PNG_UINT_32_MAX
567 >> 3) /* 8-byte RGBA pixels */
568 - 64 /* bigrowbuf hack */
569 - 1 /* filter byte */
570 - 7*8 /* rounding of width to multiple of 8 pixels */
571 - 8) /* extra max_pixel_depth pad */
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600572 {
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500573 png_warning(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500574 "Width too large for libpng to process image data");
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600575 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500576 return (1);
577 }
578 return (0);
579}
580
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500581#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500582png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500583png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600584 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500585{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600586 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
587 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500588 {
589 png_debug1(1, "in %s retrieval function\n", "oFFs");
590 *offset_x = info_ptr->x_offset;
591 *offset_y = info_ptr->y_offset;
592 *unit_type = (int)info_ptr->offset_unit_type;
593 return (PNG_INFO_oFFs);
594 }
595 return (0);
596}
597#endif
598
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500599#if defined(PNG_pCAL_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500600png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500601png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
602 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
603 png_charp *units, png_charpp *params)
604{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600605 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
606 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500607 nparams != NULL && units != NULL && params != NULL)
608 {
609 png_debug1(1, "in %s retrieval function\n", "pCAL");
610 *purpose = info_ptr->pcal_purpose;
611 *X0 = info_ptr->pcal_X0;
612 *X1 = info_ptr->pcal_X1;
613 *type = (int)info_ptr->pcal_type;
614 *nparams = (int)info_ptr->pcal_nparams;
615 *units = info_ptr->pcal_units;
616 *params = info_ptr->pcal_params;
617 return (PNG_INFO_pCAL);
618 }
619 return (0);
620}
621#endif
622
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500623#if defined(PNG_sCAL_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600624#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500625png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600626png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600627 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600628{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600629 if (png_ptr != NULL && info_ptr != NULL &&
630 (info_ptr->valid & PNG_INFO_sCAL))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600631 {
632 *unit = info_ptr->scal_unit;
633 *width = info_ptr->scal_pixel_width;
634 *height = info_ptr->scal_pixel_height;
635 return (PNG_INFO_sCAL);
636 }
637 return(0);
638}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600639#else
640#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500641png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600642png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600643 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600644{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600645 if (png_ptr != NULL && info_ptr != NULL &&
646 (info_ptr->valid & PNG_INFO_sCAL))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600647 {
648 *unit = info_ptr->scal_unit;
649 *width = info_ptr->scal_s_width;
650 *height = info_ptr->scal_s_height;
651 return (PNG_INFO_sCAL);
652 }
653 return(0);
654}
655#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600656#endif
657#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600658
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500659#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500660png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500661png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
662 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
663{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600664 png_uint_32 retval = 0;
665
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600666 if (png_ptr != NULL && info_ptr != NULL &&
667 (info_ptr->valid & PNG_INFO_pHYs))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500668 {
669 png_debug1(1, "in %s retrieval function\n", "pHYs");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600670 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600671 {
672 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600673 retval |= PNG_INFO_pHYs;
674 }
675 if (res_y != NULL)
676 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600677 *res_y = info_ptr->y_pixels_per_unit;
678 retval |= PNG_INFO_pHYs;
679 }
680 if (unit_type != NULL)
681 {
682 *unit_type = (int)info_ptr->phys_unit_type;
683 retval |= PNG_INFO_pHYs;
684 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500685 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600686 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500687}
688#endif
689
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500690png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500691png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
692 int *num_palette)
693{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600694 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
695 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500696 {
697 png_debug1(1, "in %s retrieval function\n", "PLTE");
698 *palette = info_ptr->palette;
699 *num_palette = info_ptr->num_palette;
700 png_debug1(3, "num_palette = %d\n", *num_palette);
701 return (PNG_INFO_PLTE);
702 }
703 return (0);
704}
705
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500706#if defined(PNG_sBIT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500707png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500708png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
709{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600710 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
711 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500712 {
713 png_debug1(1, "in %s retrieval function\n", "sBIT");
714 *sig_bit = &(info_ptr->sig_bit);
715 return (PNG_INFO_sBIT);
716 }
717 return (0);
718}
719#endif
720
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500721#if defined(PNG_TEXT_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500722png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500723png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
724 int *num_text)
725{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600726 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500727 {
728 png_debug1(1, "in %s retrieval function\n",
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600729 (png_ptr->chunk_name[0] == '\0' ? "text"
730 : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500731 if (text_ptr != NULL)
732 *text_ptr = info_ptr->text;
733 if (num_text != NULL)
734 *num_text = info_ptr->num_text;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600735 return ((png_uint_32)info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500736 }
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600737 if (num_text != NULL)
738 *num_text = 0;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500739 return(0);
740}
741#endif
742
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500743#if defined(PNG_tIME_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500744png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500745png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
746{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600747 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
748 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500749 {
750 png_debug1(1, "in %s retrieval function\n", "tIME");
751 *mod_time = &(info_ptr->mod_time);
752 return (PNG_INFO_tIME);
753 }
754 return (0);
755}
756#endif
757
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500758#if defined(PNG_tRNS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500759png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500760png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
761 png_bytep *trans, int *num_trans, png_color_16p *trans_values)
762{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600763 png_uint_32 retval = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600764 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500765 {
766 png_debug1(1, "in %s retrieval function\n", "tRNS");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600767 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500768 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600769 if (trans != NULL)
770 {
771 *trans = info_ptr->trans;
772 retval |= PNG_INFO_tRNS;
773 }
774 if (trans_values != NULL)
775 *trans_values = &(info_ptr->trans_values);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500776 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600777 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500778 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600779 if (trans_values != NULL)
780 {
781 *trans_values = &(info_ptr->trans_values);
782 retval |= PNG_INFO_tRNS;
783 }
784 if(trans != NULL)
785 *trans = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500786 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600787 if(num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500788 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600789 *num_trans = info_ptr->num_trans;
790 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500791 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500792 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600793 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500794}
795#endif
796
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500797#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500798png_uint_32 PNGAPI
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600799png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
800 png_unknown_chunkpp unknowns)
801{
802 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
803 *unknowns = info_ptr->unknown_chunks;
804 return ((png_uint_32)info_ptr->unknown_chunks_num);
805}
806#endif
807
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600808#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500809png_byte PNGAPI
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600810png_get_rgb_to_gray_status (png_structp png_ptr)
811{
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600812 return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600813}
814#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600815
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500816#if defined(PNG_USER_CHUNKS_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500817png_voidp PNGAPI
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600818png_get_user_chunk_ptr(png_structp png_ptr)
819{
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600820 return (png_ptr? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600821}
822#endif
823
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500824#ifdef PNG_WRITE_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500825png_size_t PNGAPI
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500826png_get_compression_buffer_size(png_structp png_ptr)
827{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500828 return (png_ptr ? png_ptr->zbuf_size : 0);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500829}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500830#endif
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500831
832#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500833/* this function was added to libpng 1.2.0 and should exist by default */
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500834png_uint_32 PNGAPI
835png_get_asm_flags (png_structp png_ptr)
836{
837 return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
838}
839
840/* this function was added to libpng 1.2.0 and should exist by default */
841png_uint_32 PNGAPI
842png_get_asm_flagmask (int flag_select)
843{
844 png_uint_32 settable_asm_flags = 0;
845
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -0500846#ifdef PNG_MMX_CODE_SUPPORTED
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500847 if (flag_select & PNG_SELECT_READ)
848 settable_asm_flags |=
849 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
850 PNG_ASM_FLAG_MMX_READ_INTERLACE |
851 PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
852 PNG_ASM_FLAG_MMX_READ_FILTER_UP |
853 PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
854 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
855 /* no non-MMX flags yet */
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -0500856#endif
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500857
858#if 0
859 /* GRR: no write-flags yet, either, but someday... */
860 if (flag_select & PNG_SELECT_WRITE)
861 settable_asm_flags |=
862 PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
863#endif /* 0 */
864
865 return settable_asm_flags; /* _theoretically_ settable capabilities only */
866}
867#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
868
869
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -0500870#if defined(PNG_MMX_CODE_SUPPORTED)
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500871/* this function was added to libpng 1.2.0 */
872png_uint_32 PNGAPI
873png_get_mmx_flagmask (int flag_select, int *compilerID)
874{
875 png_uint_32 settable_mmx_flags = 0;
876
877 if (flag_select & PNG_SELECT_READ)
878 settable_mmx_flags |=
879 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
880 PNG_ASM_FLAG_MMX_READ_INTERLACE |
881 PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
882 PNG_ASM_FLAG_MMX_READ_FILTER_UP |
883 PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
884 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
885#if 0
886 /* GRR: no MMX write support yet, but someday... */
887 if (flag_select & PNG_SELECT_WRITE)
888 settable_mmx_flags |=
889 PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
890#endif /* 0 */
891
892 if (compilerID != NULL) {
893#ifdef PNG_USE_PNGVCRD
894 *compilerID = 1; /* MSVC */
895#else
896#ifdef PNG_USE_PNGGCCRD
897 *compilerID = 2; /* gcc/gas */
898#else
899 *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
900#endif
901#endif
902 }
903
904 return settable_mmx_flags; /* _theoretically_ settable capabilities only */
905}
906
907/* this function was added to libpng 1.2.0 */
908png_byte PNGAPI
909png_get_mmx_bitdepth_threshold (png_structp png_ptr)
910{
911 return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
912}
913
914/* this function was added to libpng 1.2.0 */
915png_uint_32 PNGAPI
916png_get_mmx_rowbytes_threshold (png_structp png_ptr)
917{
918 return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
919}
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -0500920#endif /* ?PNG_MMX_CODE_SUPPORTED */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500921
922#ifdef PNG_SET_USER_LIMITS_SUPPORTED
923/* these functions were added to libpng 1.2.6 */
924png_uint_32 PNGAPI
925png_get_user_width_max (png_structp png_ptr)
926{
927 return (png_ptr? png_ptr->user_width_max : 0);
928}
929png_uint_32 PNGAPI
930png_get_user_height_max (png_structp png_ptr)
931{
932 return (png_ptr? png_ptr->user_height_max : 0);
933}
934#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
935
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500936#ifdef PNG_IO_STATE_SUPPORTED
937png_uint_32 PNGAPI
938png_get_io_state (png_structp png_ptr)
939{
940 return png_ptr->io_state;
941}
942
943png_bytep PNGAPI
944png_get_io_chunk_name (png_structp png_ptr)
945{
946 return png_ptr->chunk_name;
947}
948#endif /* ?PNG_IO_STATE_SUPPORTED */
949
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600950#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */