blob: 14e66a46dceb72c2bf90b97ff109c55a408d1eba [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-Pehrsonf8b008c1999-09-18 10:54:36 -05004 * libpng 1.0.4 - September 18, 1999
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
7 * Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06008 * Copyright (c) 1998, 1999 Glenn Randers-Pehrson
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 */
Andreas Dilger47a0c421997-05-16 02:46:07 -050010
11#define PNG_INTERNAL
12#include "png.h"
13
14png_uint_32
15png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
16{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060017 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050018 return(info_ptr->valid & flag);
19 else
20 return(0);
21}
22
23png_uint_32
24png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
25{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060026 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050027 return(info_ptr->rowbytes);
28 else
29 return(0);
30}
31
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060032#ifdef PNG_EASY_ACCESS_SUPPORTED
33/* easy access to info, added in libpng-0.99 */
34png_uint_32
35png_get_image_width(png_structp png_ptr, png_infop info_ptr)
36{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060037 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060038 {
39 return info_ptr->width;
40 }
41 return (0);
42}
43
44png_uint_32
45png_get_image_height(png_structp png_ptr, png_infop info_ptr)
46{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060047 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060048 {
49 return info_ptr->height;
50 }
51 return (0);
52}
53
54png_byte
55png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
56{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060057 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060058 {
59 return info_ptr->bit_depth;
60 }
61 return (0);
62}
63
64png_byte
65png_get_color_type(png_structp png_ptr, png_infop info_ptr)
66{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060067 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060068 {
69 return info_ptr->color_type;
70 }
71 return (0);
72}
73
74png_byte
75png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
76{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060077 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060078 {
79 return info_ptr->filter_type;
80 }
81 return (0);
82}
83
84png_byte
85png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
86{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060087 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060088 {
89 return info_ptr->interlace_type;
90 }
91 return (0);
92}
93
94png_byte
95png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
96{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060097 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060098 {
99 return info_ptr->compression_type;
100 }
101 return (0);
102}
103
104png_uint_32
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600105png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
106{
107#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
108 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
109 {
110 png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
111 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
112 return (0);
113 else return (info_ptr->x_pixels_per_unit);
114 }
115 else
116#endif
117 return (0);
118}
119
120png_uint_32
121png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
122{
123#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
124 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
125 {
126 png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
127 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
128 return (0);
129 else return (info_ptr->y_pixels_per_unit);
130 }
131 else
132#endif
133 return (0);
134}
135
136png_uint_32
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600137png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
138{
139#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600140 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600141 {
142 png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600143 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
144 info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600145 return (0);
146 else return (info_ptr->x_pixels_per_unit);
147 }
148 else
149#endif
150 return (0);
151}
152
153float
154png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
155 {
156#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600157 if (png_ptr != NULL && info_ptr != NULL && (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_aspect_ratio");
160 if (info_ptr->x_pixels_per_unit == 0)
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600161 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600162 else
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600163 return ((float)info_ptr->y_pixels_per_unit
164 /(float)info_ptr->x_pixels_per_unit);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600165 }
166 else
167#endif
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600168 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600169}
170
171png_uint_32
172png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
173{
174#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600175 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600176 {
177 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
178 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
179 return (0);
180 else return (info_ptr->x_offset);
181 }
182 else
183#endif
184 return (0);
185}
186
187png_uint_32
188png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
189{
190#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600191 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600192 {
193 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
194 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
195 return (0);
196 else return (info_ptr->y_offset);
197 }
198 else
199#endif
200 return (0);
201}
202
203png_uint_32
204png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
205{
206#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600207 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600208 {
209 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
210 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
211 return (0);
212 else return (info_ptr->x_offset);
213 }
214 else
215#endif
216 return (0);
217}
218
219png_uint_32
220png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
221{
222#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600223 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600224 {
225 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
226 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
227 return (0);
228 else return (info_ptr->y_offset);
229 }
230 else
231#endif
232 return (0);
233}
234
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600235#ifdef PNG_INCH_CONVERSIONS
236png_uint_32
237png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
238{
239 return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
240 *.03937 +.5)
241}
242
243png_uint_32
244png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
245{
246 return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
247 *.03937 +.5)
248}
249
250png_uint_32
251png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
252{
253 return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
254 *.03937 +.5)
255}
256
257float
258png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
259{
260 return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrson397100e1998-03-07 19:45:37 -0600261 *.03937/1000000. +.5)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600262}
263
264float
265png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
266{
267 return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrson397100e1998-03-07 19:45:37 -0600268 *.03937/1000000. +.5)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600269}
270
271#if defined(PNG_READ_pHYs_SUPPORTED)
272png_uint_32
273png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
274 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
275{
276 png_uint_32 retval = 0;
277
278 if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
279 {
280 png_debug1(1, "in %s retrieval function\n", "pHYs");
281 if (res_x != NULL)
282 {
283 *res_x = info_ptr->x_pixels_per_unit;
284 retval |= PNG_INFO_pHYs;
285 }
286 if (res_y != NULL)
287 {
288 *res_y = info_ptr->y_pixels_per_unit;
289 retval |= PNG_INFO_pHYs;
290 }
291 if (unit_type != NULL)
292 {
293 *unit_type = (int)info_ptr->phys_unit_type;
294 retval |= PNG_INFO_pHYs;
295 if(unit_type == 1)
296 {
297 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50);
298 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50);
299 }
300 }
301 }
302 return (retval);
303}
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500304#endif /* PNG_READ_pHYs_SUPPORTED */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600305#endif /* PNG_INCH_CONVERSIONS */
306
307/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500308
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600309#endif /* PNG_EASY_ACCESS_SUPPORTED */
310
Andreas Dilger47a0c421997-05-16 02:46:07 -0500311png_byte
312png_get_channels(png_structp png_ptr, png_infop info_ptr)
313{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600314 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500315 return(info_ptr->channels);
316 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600317 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500318}
319
320png_bytep
321png_get_signature(png_structp png_ptr, png_infop info_ptr)
322{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600323 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500324 return(info_ptr->signature);
325 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600326 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500327}
328
329#if defined(PNG_READ_bKGD_SUPPORTED)
330png_uint_32
331png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
332 png_color_16p *background)
333{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600334 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
335 && background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500336 {
337 png_debug1(1, "in %s retrieval function\n", "bKGD");
338 *background = &(info_ptr->background);
339 return (PNG_INFO_bKGD);
340 }
341 return (0);
342}
343#endif
344
345#if defined(PNG_READ_cHRM_SUPPORTED)
346png_uint_32
347png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
348 double *white_x, double *white_y, double *red_x, double *red_y,
349 double *green_x, double *green_y, double *blue_x, double *blue_y)
350{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600351 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500352 {
353 png_debug1(1, "in %s retrieval function\n", "cHRM");
354 if (white_x != NULL)
355 *white_x = (double)info_ptr->x_white;
356 if (white_y != NULL)
357 *white_y = (double)info_ptr->y_white;
358 if (red_x != NULL)
359 *red_x = (double)info_ptr->x_red;
360 if (red_y != NULL)
361 *red_y = (double)info_ptr->y_red;
362 if (green_x != NULL)
363 *green_x = (double)info_ptr->x_green;
364 if (green_y != NULL)
365 *green_y = (double)info_ptr->y_green;
366 if (blue_x != NULL)
367 *blue_x = (double)info_ptr->x_blue;
368 if (blue_y != NULL)
369 *blue_y = (double)info_ptr->y_blue;
370 return (PNG_INFO_cHRM);
371 }
372 return (0);
373}
374#endif
375
376#if defined(PNG_READ_gAMA_SUPPORTED)
377png_uint_32
378png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
379{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600380 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
381 && file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500382 {
383 png_debug1(1, "in %s retrieval function\n", "gAMA");
384 *file_gamma = (double)info_ptr->gamma;
385 return (PNG_INFO_gAMA);
386 }
387 return (0);
388}
389#endif
390
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600391#if defined(PNG_READ_sRGB_SUPPORTED)
392png_uint_32
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600393png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600394{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600395 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
396 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600397 {
398 png_debug1(1, "in %s retrieval function\n", "sRGB");
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600399 *file_srgb_intent = (int)info_ptr->srgb_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600400 return (PNG_INFO_sRGB);
401 }
402 return (0);
403}
404#endif
405
Andreas Dilger47a0c421997-05-16 02:46:07 -0500406#if defined(PNG_READ_hIST_SUPPORTED)
407png_uint_32
408png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
409{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600410 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
411 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500412 {
413 png_debug1(1, "in %s retrieval function\n", "hIST");
414 *hist = info_ptr->hist;
415 return (PNG_INFO_hIST);
416 }
417 return (0);
418}
419#endif
420
421png_uint_32
422png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
423 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
424 int *color_type, int *interlace_type, int *compression_type,
425 int *filter_type)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600426
Andreas Dilger47a0c421997-05-16 02:46:07 -0500427{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600428 if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500429 bit_depth != NULL && color_type != NULL)
430 {
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600431 int pixel_depth, channels;
432 png_uint_32 rowbytes_per_pixel;
433
Andreas Dilger47a0c421997-05-16 02:46:07 -0500434 png_debug1(1, "in %s retrieval function\n", "IHDR");
435 *width = info_ptr->width;
436 *height = info_ptr->height;
437 *bit_depth = info_ptr->bit_depth;
438 *color_type = info_ptr->color_type;
439 if (compression_type != NULL)
440 *compression_type = info_ptr->compression_type;
441 if (filter_type != NULL)
442 *filter_type = info_ptr->filter_type;
443 if (interlace_type != NULL)
444 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600445
446 /* check for potential overflow of rowbytes */
447 if (*color_type == PNG_COLOR_TYPE_PALETTE)
448 channels = 1;
449 else if (*color_type & PNG_COLOR_MASK_COLOR)
450 channels = 3;
451 else
452 channels = 1;
453 if (*color_type & PNG_COLOR_MASK_ALPHA)
454 channels++;
455 pixel_depth = *bit_depth * channels;
456 rowbytes_per_pixel = (pixel_depth + 7) >> 3;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500457 if ((*width > PNG_MAX_UINT/rowbytes_per_pixel))
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600458 {
459 png_warning(png_ptr,
460 "Width too large for libpng to process image data.");
461 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500462 return (1);
463 }
464 return (0);
465}
466
467#if defined(PNG_READ_oFFs_SUPPORTED)
468png_uint_32
469png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
470 png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type)
471{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600472 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
473 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500474 {
475 png_debug1(1, "in %s retrieval function\n", "oFFs");
476 *offset_x = info_ptr->x_offset;
477 *offset_y = info_ptr->y_offset;
478 *unit_type = (int)info_ptr->offset_unit_type;
479 return (PNG_INFO_oFFs);
480 }
481 return (0);
482}
483#endif
484
485#if defined(PNG_READ_pCAL_SUPPORTED)
486png_uint_32
487png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
488 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
489 png_charp *units, png_charpp *params)
490{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600491 if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500492 purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
493 nparams != NULL && units != NULL && params != NULL)
494 {
495 png_debug1(1, "in %s retrieval function\n", "pCAL");
496 *purpose = info_ptr->pcal_purpose;
497 *X0 = info_ptr->pcal_X0;
498 *X1 = info_ptr->pcal_X1;
499 *type = (int)info_ptr->pcal_type;
500 *nparams = (int)info_ptr->pcal_nparams;
501 *units = info_ptr->pcal_units;
502 *params = info_ptr->pcal_params;
503 return (PNG_INFO_pCAL);
504 }
505 return (0);
506}
507#endif
508
509#if defined(PNG_READ_pHYs_SUPPORTED)
510png_uint_32
511png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
512 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
513{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600514 png_uint_32 retval = 0;
515
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600516 if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500517 {
518 png_debug1(1, "in %s retrieval function\n", "pHYs");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600519 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600520 {
521 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600522 retval |= PNG_INFO_pHYs;
523 }
524 if (res_y != NULL)
525 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600526 *res_y = info_ptr->y_pixels_per_unit;
527 retval |= PNG_INFO_pHYs;
528 }
529 if (unit_type != NULL)
530 {
531 *unit_type = (int)info_ptr->phys_unit_type;
532 retval |= PNG_INFO_pHYs;
533 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500534 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600535 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500536}
537#endif
538
539png_uint_32
540png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
541 int *num_palette)
542{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600543 if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE &&
544 palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500545 {
546 png_debug1(1, "in %s retrieval function\n", "PLTE");
547 *palette = info_ptr->palette;
548 *num_palette = info_ptr->num_palette;
549 png_debug1(3, "num_palette = %d\n", *num_palette);
550 return (PNG_INFO_PLTE);
551 }
552 return (0);
553}
554
555#if defined(PNG_READ_sBIT_SUPPORTED)
556png_uint_32
557png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
558{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600559 if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT &&
560 sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500561 {
562 png_debug1(1, "in %s retrieval function\n", "sBIT");
563 *sig_bit = &(info_ptr->sig_bit);
564 return (PNG_INFO_sBIT);
565 }
566 return (0);
567}
568#endif
569
570#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
571png_uint_32
572png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
573 int *num_text)
574{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600575 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500576 {
577 png_debug1(1, "in %s retrieval function\n",
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600578 (png_ptr->chunk_name[0] == '\0' ? "text"
579 : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500580 if (text_ptr != NULL)
581 *text_ptr = info_ptr->text;
582 if (num_text != NULL)
583 *num_text = info_ptr->num_text;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600584 return ((png_uint_32)info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500585 }
586 return(0);
587}
588#endif
589
590#if defined(PNG_READ_tIME_SUPPORTED)
591png_uint_32
592png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
593{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600594 if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME &&
595 mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500596 {
597 png_debug1(1, "in %s retrieval function\n", "tIME");
598 *mod_time = &(info_ptr->mod_time);
599 return (PNG_INFO_tIME);
600 }
601 return (0);
602}
603#endif
604
605#if defined(PNG_READ_tRNS_SUPPORTED)
606png_uint_32
607png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
608 png_bytep *trans, int *num_trans, png_color_16p *trans_values)
609{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600610 png_uint_32 retval = 0;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600611 if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500612 {
613 png_debug1(1, "in %s retrieval function\n", "tRNS");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600614 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500615 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600616 if (trans != NULL)
617 {
618 *trans = info_ptr->trans;
619 retval |= PNG_INFO_tRNS;
620 }
621 if (trans_values != NULL)
622 *trans_values = &(info_ptr->trans_values);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500623 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600624 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500625 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600626 if (trans_values != NULL)
627 {
628 *trans_values = &(info_ptr->trans_values);
629 retval |= PNG_INFO_tRNS;
630 }
631 if(trans != NULL)
632 *trans = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500633 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600634 if(num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500635 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600636 *num_trans = info_ptr->num_trans;
637 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500638 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500639 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600640 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500641}
642#endif
643
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600644#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
645png_byte
646png_get_rgb_to_gray_status (png_structp png_ptr)
647{
648 return png_ptr->rgb_to_gray_status;
649}
650#endif