]> git.saurik.com Git - wxWidgets.git/blame - src/png/pngget.c
Use mask when drawing bitmaps in generic wxDataViewCtrl.
[wxWidgets.git] / src / png / pngget.c
CommitLineData
0272a10d
VZ
1
2/* pngget.c - retrieval of values from info struct
3 *
fff5f7d5
VZ
4 * Last changed in libpng 1.6.1 [March 28, 2013]
5 * Copyright (c) 1998-2013 Glenn Randers-Pehrson
0272a10d
VZ
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
b61cc19c
PC
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
0272a10d
VZ
13 */
14
b61cc19c 15#include "pngpriv.h"
0272a10d 16
9c0d9ce3
DS
17#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
18
0272a10d 19png_uint_32 PNGAPI
fff5f7d5 20png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 21 png_uint_32 flag)
0272a10d
VZ
22{
23 if (png_ptr != NULL && info_ptr != NULL)
24 return(info_ptr->valid & flag);
b61cc19c 25
9c0d9ce3 26 return(0);
0272a10d
VZ
27}
28
b61cc19c 29png_size_t PNGAPI
fff5f7d5 30png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
31{
32 if (png_ptr != NULL && info_ptr != NULL)
33 return(info_ptr->rowbytes);
b61cc19c 34
9c0d9ce3 35 return(0);
0272a10d
VZ
36}
37
b61cc19c 38#ifdef PNG_INFO_IMAGE_SUPPORTED
0272a10d 39png_bytepp PNGAPI
fff5f7d5 40png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
41{
42 if (png_ptr != NULL && info_ptr != NULL)
43 return(info_ptr->row_pointers);
b61cc19c 44
9c0d9ce3 45 return(0);
0272a10d
VZ
46}
47#endif
48
49#ifdef PNG_EASY_ACCESS_SUPPORTED
b61cc19c 50/* Easy access to info, added in libpng-0.99 */
0272a10d 51png_uint_32 PNGAPI
fff5f7d5 52png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
53{
54 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 55 return info_ptr->width;
b61cc19c 56
0272a10d
VZ
57 return (0);
58}
59
60png_uint_32 PNGAPI
fff5f7d5 61png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
62{
63 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 64 return info_ptr->height;
b61cc19c 65
0272a10d
VZ
66 return (0);
67}
68
69png_byte PNGAPI
fff5f7d5 70png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
71{
72 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 73 return info_ptr->bit_depth;
b61cc19c 74
0272a10d
VZ
75 return (0);
76}
77
78png_byte PNGAPI
fff5f7d5 79png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
80{
81 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 82 return info_ptr->color_type;
b61cc19c 83
0272a10d
VZ
84 return (0);
85}
86
87png_byte PNGAPI
fff5f7d5 88png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
89{
90 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 91 return info_ptr->filter_type;
b61cc19c 92
0272a10d
VZ
93 return (0);
94}
95
96png_byte PNGAPI
fff5f7d5 97png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
98{
99 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 100 return info_ptr->interlace_type;
b61cc19c 101
0272a10d
VZ
102 return (0);
103}
104
105png_byte PNGAPI
fff5f7d5 106png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
107{
108 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 109 return info_ptr->compression_type;
b61cc19c 110
0272a10d
VZ
111 return (0);
112}
113
114png_uint_32 PNGAPI
fff5f7d5
VZ
115png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
116 info_ptr)
0272a10d 117{
b61cc19c 118#ifdef PNG_pHYs_SUPPORTED
9c0d9ce3
DS
119 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
120 {
121 png_debug1(1, "in %s retrieval function",
122 "png_get_x_pixels_per_meter");
b61cc19c 123
9c0d9ce3
DS
124 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
125 return (info_ptr->x_pixels_per_unit);
126 }
0272a10d 127#endif
9c0d9ce3 128
0272a10d
VZ
129 return (0);
130}
131
132png_uint_32 PNGAPI
fff5f7d5
VZ
133png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
134 info_ptr)
0272a10d 135{
b61cc19c 136#ifdef PNG_pHYs_SUPPORTED
9c0d9ce3 137 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
0272a10d 138 {
9c0d9ce3
DS
139 png_debug1(1, "in %s retrieval function",
140 "png_get_y_pixels_per_meter");
b61cc19c 141
9c0d9ce3
DS
142 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
143 return (info_ptr->y_pixels_per_unit);
0272a10d 144 }
0272a10d 145#endif
9c0d9ce3 146
0272a10d
VZ
147 return (0);
148}
149
150png_uint_32 PNGAPI
fff5f7d5 151png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 152{
b61cc19c 153#ifdef PNG_pHYs_SUPPORTED
9c0d9ce3 154 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
0272a10d 155 {
970f6abe 156 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
b61cc19c 157
9c0d9ce3
DS
158 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
159 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
160 return (info_ptr->x_pixels_per_unit);
0272a10d 161 }
0272a10d 162#endif
9c0d9ce3 163
0272a10d
VZ
164 return (0);
165}
166
167#ifdef PNG_FLOATING_POINT_SUPPORTED
168float PNGAPI
fff5f7d5
VZ
169png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
170 info_ptr)
9c0d9ce3
DS
171{
172#ifdef PNG_READ_pHYs_SUPPORTED
173 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
0272a10d 174 {
970f6abe 175 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
b61cc19c 176
9c0d9ce3 177 if (info_ptr->x_pixels_per_unit != 0)
0272a10d 178 return ((float)((float)info_ptr->y_pixels_per_unit
9c0d9ce3 179 /(float)info_ptr->x_pixels_per_unit));
0272a10d 180 }
fff5f7d5
VZ
181#else
182 PNG_UNUSED(png_ptr)
183 PNG_UNUSED(info_ptr)
0272a10d 184#endif
9c0d9ce3 185
0272a10d
VZ
186 return ((float)0.0);
187}
188#endif
189
9c0d9ce3
DS
190#ifdef PNG_FIXED_POINT_SUPPORTED
191png_fixed_point PNGAPI
fff5f7d5
VZ
192png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
193 png_const_inforp info_ptr)
9c0d9ce3
DS
194{
195#ifdef PNG_READ_pHYs_SUPPORTED
196 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
197 && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
198 && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
199 && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
200 {
201 png_fixed_point res;
202
203 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
204
205 /* The following casts work because a PNG 4 byte integer only has a valid
206 * range of 0..2^31-1; otherwise the cast might overflow.
207 */
208 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
209 (png_int_32)info_ptr->x_pixels_per_unit))
210 return res;
211 }
fff5f7d5
VZ
212#else
213 PNG_UNUSED(png_ptr)
214 PNG_UNUSED(info_ptr)
9c0d9ce3
DS
215#endif
216
217 return 0;
218}
219#endif
220
0272a10d 221png_int_32 PNGAPI
fff5f7d5 222png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 223{
b61cc19c 224#ifdef PNG_oFFs_SUPPORTED
9c0d9ce3 225 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
0272a10d 226 {
970f6abe 227 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
b61cc19c 228
9c0d9ce3
DS
229 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
230 return (info_ptr->x_offset);
0272a10d 231 }
0272a10d 232#endif
9c0d9ce3 233
0272a10d
VZ
234 return (0);
235}
236
237png_int_32 PNGAPI
fff5f7d5 238png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 239{
b61cc19c 240#ifdef PNG_oFFs_SUPPORTED
9c0d9ce3 241 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
0272a10d 242 {
970f6abe 243 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
b61cc19c 244
9c0d9ce3
DS
245 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
246 return (info_ptr->y_offset);
0272a10d 247 }
0272a10d 248#endif
9c0d9ce3 249
0272a10d
VZ
250 return (0);
251}
252
253png_int_32 PNGAPI
fff5f7d5 254png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 255{
b61cc19c 256#ifdef PNG_oFFs_SUPPORTED
9c0d9ce3 257 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
0272a10d 258 {
9c0d9ce3 259 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
b61cc19c 260
9c0d9ce3
DS
261 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
262 return (info_ptr->x_offset);
0272a10d 263 }
0272a10d 264#endif
9c0d9ce3 265
0272a10d
VZ
266 return (0);
267}
268
269png_int_32 PNGAPI
fff5f7d5 270png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 271{
b61cc19c 272#ifdef PNG_oFFs_SUPPORTED
9c0d9ce3 273 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
0272a10d 274 {
9c0d9ce3 275 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
b61cc19c 276
9c0d9ce3
DS
277 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
278 return (info_ptr->y_offset);
0272a10d 279 }
0272a10d 280#endif
9c0d9ce3 281
0272a10d
VZ
282 return (0);
283}
284
9c0d9ce3
DS
285#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
286static png_uint_32
287ppi_from_ppm(png_uint_32 ppm)
288{
289#if 0
290 /* The conversion is *(2.54/100), in binary (32 digits):
291 * .00000110100000001001110101001001
292 */
293 png_uint_32 t1001, t1101;
294 ppm >>= 1; /* .1 */
295 t1001 = ppm + (ppm >> 3); /* .1001 */
296 t1101 = t1001 + (ppm >> 1); /* .1101 */
297 ppm >>= 20; /* .000000000000000000001 */
298 t1101 += t1101 >> 15; /* .1101000000000001101 */
299 t1001 >>= 11; /* .000000000001001 */
300 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
301 ppm += t1001; /* .000000000001001000001001001 */
302 ppm += t1101; /* .110100000001001110101001001 */
303 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
304#else
305 /* The argument is a PNG unsigned integer, so it is not permitted
306 * to be bigger than 2^31.
307 */
308 png_fixed_point result;
309 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
310 5000))
311 return result;
312
313 /* Overflow. */
314 return 0;
315#endif
316}
317
0272a10d 318png_uint_32 PNGAPI
fff5f7d5 319png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 320{
9c0d9ce3 321 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
0272a10d
VZ
322}
323
324png_uint_32 PNGAPI
fff5f7d5 325png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 326{
9c0d9ce3 327 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
0272a10d
VZ
328}
329
330png_uint_32 PNGAPI
fff5f7d5 331png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
9c0d9ce3
DS
332{
333 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
334}
335
336#ifdef PNG_FIXED_POINT_SUPPORTED
337static png_fixed_point
fff5f7d5 338png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
0272a10d 339{
9c0d9ce3
DS
340 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
341 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
342 * Notice that this can overflow - a warning is output and 0 is
343 * returned.
344 */
345 return png_muldiv_warn(png_ptr, microns, 500, 127);
0272a10d
VZ
346}
347
9c0d9ce3 348png_fixed_point PNGAPI
fff5f7d5
VZ
349png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
350 png_const_inforp info_ptr)
9c0d9ce3
DS
351{
352 return png_fixed_inches_from_microns(png_ptr,
353 png_get_x_offset_microns(png_ptr, info_ptr));
354}
355#endif
356
357#ifdef PNG_FIXED_POINT_SUPPORTED
358png_fixed_point PNGAPI
fff5f7d5
VZ
359png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
360 png_const_inforp info_ptr)
9c0d9ce3
DS
361{
362 return png_fixed_inches_from_microns(png_ptr,
363 png_get_y_offset_microns(png_ptr, info_ptr));
364}
365#endif
366
367#ifdef PNG_FLOATING_POINT_SUPPORTED
0272a10d 368float PNGAPI
fff5f7d5 369png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 370{
9c0d9ce3
DS
371 /* To avoid the overflow do the conversion directly in floating
372 * point.
373 */
374 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
0272a10d 375}
9c0d9ce3 376#endif
0272a10d 377
9c0d9ce3 378#ifdef PNG_FLOATING_POINT_SUPPORTED
0272a10d 379float PNGAPI
fff5f7d5 380png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d 381{
9c0d9ce3
DS
382 /* To avoid the overflow do the conversion directly in floating
383 * point.
384 */
385 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
0272a10d 386}
9c0d9ce3 387#endif
0272a10d 388
b61cc19c 389#ifdef PNG_pHYs_SUPPORTED
0272a10d 390png_uint_32 PNGAPI
fff5f7d5 391png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 392 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
0272a10d
VZ
393{
394 png_uint_32 retval = 0;
395
396 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
397 {
970f6abe 398 png_debug1(1, "in %s retrieval function", "pHYs");
b61cc19c 399
0272a10d
VZ
400 if (res_x != NULL)
401 {
402 *res_x = info_ptr->x_pixels_per_unit;
403 retval |= PNG_INFO_pHYs;
404 }
9c0d9ce3 405
0272a10d
VZ
406 if (res_y != NULL)
407 {
408 *res_y = info_ptr->y_pixels_per_unit;
409 retval |= PNG_INFO_pHYs;
410 }
9c0d9ce3 411
0272a10d
VZ
412 if (unit_type != NULL)
413 {
414 *unit_type = (int)info_ptr->phys_unit_type;
415 retval |= PNG_INFO_pHYs;
9c0d9ce3 416
970f6abe 417 if (*unit_type == 1)
0272a10d
VZ
418 {
419 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
420 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
421 }
422 }
423 }
9c0d9ce3 424
0272a10d
VZ
425 return (retval);
426}
427#endif /* PNG_pHYs_SUPPORTED */
9c0d9ce3 428#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
0272a10d
VZ
429
430/* png_get_channels really belongs in here, too, but it's been around longer */
431
432#endif /* PNG_EASY_ACCESS_SUPPORTED */
433
fff5f7d5 434
0272a10d 435png_byte PNGAPI
fff5f7d5 436png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
437{
438 if (png_ptr != NULL && info_ptr != NULL)
439 return(info_ptr->channels);
9c0d9ce3
DS
440
441 return (0);
0272a10d
VZ
442}
443
fff5f7d5 444#ifdef PNG_READ_SUPPORTED
9c0d9ce3 445png_const_bytep PNGAPI
fff5f7d5 446png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
0272a10d
VZ
447{
448 if (png_ptr != NULL && info_ptr != NULL)
449 return(info_ptr->signature);
9c0d9ce3
DS
450
451 return (NULL);
0272a10d 452}
fff5f7d5 453#endif
0272a10d 454
b61cc19c 455#ifdef PNG_bKGD_SUPPORTED
0272a10d 456png_uint_32 PNGAPI
fff5f7d5 457png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
0272a10d
VZ
458 png_color_16p *background)
459{
460 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
9c0d9ce3 461 && background != NULL)
0272a10d 462 {
970f6abe 463 png_debug1(1, "in %s retrieval function", "bKGD");
b61cc19c 464
0272a10d
VZ
465 *background = &(info_ptr->background);
466 return (PNG_INFO_bKGD);
467 }
9c0d9ce3 468
0272a10d
VZ
469 return (0);
470}
471#endif
472
b61cc19c 473#ifdef PNG_cHRM_SUPPORTED
9c0d9ce3
DS
474/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
475 * same time to correct the rgb grayscale coefficient defaults obtained from the
476 * cHRM chunk in 1.5.4
477 */
9c0d9ce3 478# ifdef PNG_FLOATING_POINT_SUPPORTED
0272a10d 479png_uint_32 PNGAPI
fff5f7d5 480png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3
DS
481 double *white_x, double *white_y, double *red_x, double *red_y,
482 double *green_x, double *green_y, double *blue_x, double *blue_y)
0272a10d 483{
fff5f7d5
VZ
484 /* Quiet API change: this code used to only return the end points if a cHRM
485 * chunk was present, but the end points can also come from iCCP or sRGB
486 * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
487 * the png_set_ APIs merely check that set end points are mutually
488 * consistent.
489 */
490 if (png_ptr != NULL && info_ptr != NULL &&
491 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
0272a10d 492 {
970f6abe 493 png_debug1(1, "in %s retrieval function", "cHRM");
b61cc19c 494
0272a10d 495 if (white_x != NULL)
fff5f7d5
VZ
496 *white_x = png_float(png_ptr,
497 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
0272a10d 498 if (white_y != NULL)
fff5f7d5
VZ
499 *white_y = png_float(png_ptr,
500 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
0272a10d 501 if (red_x != NULL)
fff5f7d5
VZ
502 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
503 "cHRM red X");
0272a10d 504 if (red_y != NULL)
fff5f7d5
VZ
505 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
506 "cHRM red Y");
0272a10d 507 if (green_x != NULL)
fff5f7d5
VZ
508 *green_x = png_float(png_ptr,
509 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
0272a10d 510 if (green_y != NULL)
fff5f7d5
VZ
511 *green_y = png_float(png_ptr,
512 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
0272a10d 513 if (blue_x != NULL)
fff5f7d5
VZ
514 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
515 "cHRM blue X");
0272a10d 516 if (blue_y != NULL)
fff5f7d5
VZ
517 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
518 "cHRM blue Y");
0272a10d
VZ
519 return (PNG_INFO_cHRM);
520 }
9c0d9ce3 521
0272a10d
VZ
522 return (0);
523}
9c0d9ce3
DS
524
525png_uint_32 PNGAPI
fff5f7d5 526png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3
DS
527 double *red_X, double *red_Y, double *red_Z, double *green_X,
528 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
529 double *blue_Z)
530{
fff5f7d5
VZ
531 if (png_ptr != NULL && info_ptr != NULL &&
532 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
9c0d9ce3 533 {
fff5f7d5
VZ
534 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
535
9c0d9ce3 536 if (red_X != NULL)
fff5f7d5
VZ
537 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
538 "cHRM red X");
9c0d9ce3 539 if (red_Y != NULL)
fff5f7d5
VZ
540 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
541 "cHRM red Y");
9c0d9ce3 542 if (red_Z != NULL)
fff5f7d5
VZ
543 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
544 "cHRM red Z");
9c0d9ce3 545 if (green_X != NULL)
fff5f7d5
VZ
546 *green_X = png_float(png_ptr,
547 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
9c0d9ce3 548 if (green_Y != NULL)
fff5f7d5
VZ
549 *green_Y = png_float(png_ptr,
550 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
9c0d9ce3 551 if (green_Z != NULL)
fff5f7d5
VZ
552 *green_Z = png_float(png_ptr,
553 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
9c0d9ce3 554 if (blue_X != NULL)
fff5f7d5
VZ
555 *blue_X = png_float(png_ptr,
556 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
9c0d9ce3 557 if (blue_Y != NULL)
fff5f7d5
VZ
558 *blue_Y = png_float(png_ptr,
559 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
9c0d9ce3 560 if (blue_Z != NULL)
fff5f7d5
VZ
561 *blue_Z = png_float(png_ptr,
562 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
9c0d9ce3
DS
563 return (PNG_INFO_cHRM);
564 }
565
566 return (0);
567}
568# endif
569
570# ifdef PNG_FIXED_POINT_SUPPORTED
0272a10d 571png_uint_32 PNGAPI
fff5f7d5
VZ
572png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
573 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
574 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
575 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
576 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
577 png_fixed_point *int_blue_Z)
578{
579 if (png_ptr != NULL && info_ptr != NULL &&
580 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
581 {
582 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
583
584 if (int_red_X != NULL)
585 *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
586 if (int_red_Y != NULL)
587 *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
588 if (int_red_Z != NULL)
589 *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
590 if (int_green_X != NULL)
591 *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
592 if (int_green_Y != NULL)
593 *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
594 if (int_green_Z != NULL)
595 *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
596 if (int_blue_X != NULL)
597 *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
598 if (int_blue_Y != NULL)
599 *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
600 if (int_blue_Z != NULL)
601 *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
602 return (PNG_INFO_cHRM);
603 }
604
605 return (0);
606}
607
608png_uint_32 PNGAPI
609png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3
DS
610 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
611 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
612 png_fixed_point *blue_x, png_fixed_point *blue_y)
0272a10d 613{
b61cc19c
PC
614 png_debug1(1, "in %s retrieval function", "cHRM");
615
fff5f7d5
VZ
616 if (png_ptr != NULL && info_ptr != NULL &&
617 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
0272a10d 618 {
0272a10d 619 if (white_x != NULL)
fff5f7d5 620 *white_x = info_ptr->colorspace.end_points_xy.whitex;
0272a10d 621 if (white_y != NULL)
fff5f7d5 622 *white_y = info_ptr->colorspace.end_points_xy.whitey;
0272a10d 623 if (red_x != NULL)
fff5f7d5 624 *red_x = info_ptr->colorspace.end_points_xy.redx;
0272a10d 625 if (red_y != NULL)
fff5f7d5 626 *red_y = info_ptr->colorspace.end_points_xy.redy;
0272a10d 627 if (green_x != NULL)
fff5f7d5 628 *green_x = info_ptr->colorspace.end_points_xy.greenx;
0272a10d 629 if (green_y != NULL)
fff5f7d5 630 *green_y = info_ptr->colorspace.end_points_xy.greeny;
0272a10d 631 if (blue_x != NULL)
fff5f7d5 632 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
0272a10d 633 if (blue_y != NULL)
fff5f7d5 634 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
0272a10d
VZ
635 return (PNG_INFO_cHRM);
636 }
9c0d9ce3 637
0272a10d
VZ
638 return (0);
639}
9c0d9ce3 640# endif
0272a10d
VZ
641#endif
642
b61cc19c 643#ifdef PNG_gAMA_SUPPORTED
fff5f7d5
VZ
644# ifdef PNG_FIXED_POINT_SUPPORTED
645png_uint_32 PNGAPI
646png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 647 png_fixed_point *file_gamma)
0272a10d 648{
b61cc19c
PC
649 png_debug1(1, "in %s retrieval function", "gAMA");
650
fff5f7d5
VZ
651 if (png_ptr != NULL && info_ptr != NULL &&
652 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
653 file_gamma != NULL)
0272a10d 654 {
fff5f7d5 655 *file_gamma = info_ptr->colorspace.gamma;
0272a10d
VZ
656 return (PNG_INFO_gAMA);
657 }
9c0d9ce3 658
0272a10d
VZ
659 return (0);
660}
fff5f7d5
VZ
661# endif
662
9c0d9ce3 663# ifdef PNG_FLOATING_POINT_SUPPORTED
0272a10d 664png_uint_32 PNGAPI
fff5f7d5 665png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 666 double *file_gamma)
0272a10d 667{
fff5f7d5 668 png_debug1(1, "in %s retrieval function", "gAMA(float)");
b61cc19c 669
fff5f7d5
VZ
670 if (png_ptr != NULL && info_ptr != NULL &&
671 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
672 file_gamma != NULL)
673 {
674 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
675 "png_get_gAMA");
676 return (PNG_INFO_gAMA);
677 }
9c0d9ce3 678
fff5f7d5 679 return (0);
0272a10d 680}
9c0d9ce3 681# endif
0272a10d
VZ
682#endif
683
b61cc19c 684#ifdef PNG_sRGB_SUPPORTED
0272a10d 685png_uint_32 PNGAPI
fff5f7d5 686png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 687 int *file_srgb_intent)
0272a10d 688{
b61cc19c
PC
689 png_debug1(1, "in %s retrieval function", "sRGB");
690
0272a10d 691 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
9c0d9ce3 692 && file_srgb_intent != NULL)
0272a10d 693 {
fff5f7d5 694 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
0272a10d
VZ
695 return (PNG_INFO_sRGB);
696 }
9c0d9ce3 697
0272a10d
VZ
698 return (0);
699}
700#endif
701
b61cc19c 702#ifdef PNG_iCCP_SUPPORTED
0272a10d 703png_uint_32 PNGAPI
fff5f7d5 704png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3
DS
705 png_charpp name, int *compression_type,
706 png_bytepp profile, png_uint_32 *proflen)
0272a10d 707{
b61cc19c
PC
708 png_debug1(1, "in %s retrieval function", "iCCP");
709
0272a10d 710 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
72281370
DS
711 && name != NULL && compression_type != NULL && profile != NULL &&
712 proflen != NULL)
0272a10d 713 {
0272a10d
VZ
714 *name = info_ptr->iccp_name;
715 *profile = info_ptr->iccp_profile;
fff5f7d5
VZ
716 *proflen = png_get_uint_32(info_ptr->iccp_profile);
717 /* This is somewhat irrelevant since the profile data returned has
718 * actually been uncompressed.
b61cc19c 719 */
fff5f7d5 720 *compression_type = PNG_COMPRESSION_TYPE_BASE;
0272a10d
VZ
721 return (PNG_INFO_iCCP);
722 }
9c0d9ce3 723
0272a10d
VZ
724 return (0);
725}
726#endif
727
b61cc19c 728#ifdef PNG_sPLT_SUPPORTED
fff5f7d5
VZ
729int PNGAPI
730png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3 731 png_sPLT_tpp spalettes)
0272a10d
VZ
732{
733 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
734 {
9c0d9ce3 735 *spalettes = info_ptr->splt_palettes;
fff5f7d5 736 return info_ptr->splt_palettes_num;
0272a10d 737 }
9c0d9ce3 738
0272a10d
VZ
739 return (0);
740}
741#endif
742
b61cc19c 743#ifdef PNG_hIST_SUPPORTED
0272a10d 744png_uint_32 PNGAPI
fff5f7d5 745png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3 746 png_uint_16p *hist)
0272a10d 747{
b61cc19c
PC
748 png_debug1(1, "in %s retrieval function", "hIST");
749
0272a10d 750 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
9c0d9ce3 751 && hist != NULL)
0272a10d 752 {
0272a10d
VZ
753 *hist = info_ptr->hist;
754 return (PNG_INFO_hIST);
755 }
9c0d9ce3 756
0272a10d
VZ
757 return (0);
758}
759#endif
760
761png_uint_32 PNGAPI
fff5f7d5 762png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3
DS
763 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
764 int *color_type, int *interlace_type, int *compression_type,
765 int *filter_type)
0272a10d 766{
b61cc19c
PC
767 png_debug1(1, "in %s retrieval function", "IHDR");
768
769 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
770 height == NULL || bit_depth == NULL || color_type == NULL)
771 return (0);
772
773 *width = info_ptr->width;
774 *height = info_ptr->height;
775 *bit_depth = info_ptr->bit_depth;
776 *color_type = info_ptr->color_type;
777
778 if (compression_type != NULL)
779 *compression_type = info_ptr->compression_type;
780
781 if (filter_type != NULL)
782 *filter_type = info_ptr->filter_type;
783
784 if (interlace_type != NULL)
785 *interlace_type = info_ptr->interlace_type;
786
787 /* This is redundant if we can be sure that the info_ptr values were all
788 * assigned in png_set_IHDR(). We do the check anyhow in case an
789 * application has ignored our advice not to mess with the members
790 * of info_ptr directly.
791 */
fff5f7d5 792 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
b61cc19c
PC
793 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
794 info_ptr->compression_type, info_ptr->filter_type);
795
796 return (1);
0272a10d
VZ
797}
798
b61cc19c 799#ifdef PNG_oFFs_SUPPORTED
0272a10d 800png_uint_32 PNGAPI
fff5f7d5 801png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 802 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
0272a10d 803{
b61cc19c
PC
804 png_debug1(1, "in %s retrieval function", "oFFs");
805
0272a10d 806 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
9c0d9ce3 807 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
0272a10d 808 {
0272a10d
VZ
809 *offset_x = info_ptr->x_offset;
810 *offset_y = info_ptr->y_offset;
811 *unit_type = (int)info_ptr->offset_unit_type;
812 return (PNG_INFO_oFFs);
813 }
9c0d9ce3 814
0272a10d
VZ
815 return (0);
816}
817#endif
818
b61cc19c 819#ifdef PNG_pCAL_SUPPORTED
0272a10d 820png_uint_32 PNGAPI
fff5f7d5 821png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3
DS
822 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
823 png_charp *units, png_charpp *params)
0272a10d 824{
b61cc19c
PC
825 png_debug1(1, "in %s retrieval function", "pCAL");
826
0272a10d 827 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
b61cc19c
PC
828 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
829 nparams != NULL && units != NULL && params != NULL)
0272a10d 830 {
0272a10d
VZ
831 *purpose = info_ptr->pcal_purpose;
832 *X0 = info_ptr->pcal_X0;
833 *X1 = info_ptr->pcal_X1;
834 *type = (int)info_ptr->pcal_type;
835 *nparams = (int)info_ptr->pcal_nparams;
836 *units = info_ptr->pcal_units;
837 *params = info_ptr->pcal_params;
838 return (PNG_INFO_pCAL);
839 }
9c0d9ce3 840
0272a10d
VZ
841 return (0);
842}
843#endif
844
b61cc19c 845#ifdef PNG_sCAL_SUPPORTED
9c0d9ce3 846# ifdef PNG_FIXED_POINT_SUPPORTED
fff5f7d5
VZ
847# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
848 defined(PNG_FLOATING_POINT_SUPPORTED)
0272a10d 849png_uint_32 PNGAPI
fff5f7d5 850png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 851 int *unit, png_fixed_point *width, png_fixed_point *height)
0272a10d 852{
9c0d9ce3
DS
853 if (png_ptr != NULL && info_ptr != NULL &&
854 (info_ptr->valid & PNG_INFO_sCAL))
855 {
856 *unit = info_ptr->scal_unit;
fff5f7d5
VZ
857 /*TODO: make this work without FP support; the API is currently eliminated
858 * if neither floating point APIs nor internal floating point arithmetic
859 * are enabled.
860 */
9c0d9ce3
DS
861 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
862 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
863 "sCAL height");
864 return (PNG_INFO_sCAL);
865 }
866
867 return(0);
0272a10d 868}
9c0d9ce3
DS
869# endif /* FLOATING_ARITHMETIC */
870# endif /* FIXED_POINT */
871# ifdef PNG_FLOATING_POINT_SUPPORTED
0272a10d 872png_uint_32 PNGAPI
fff5f7d5 873png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 874 int *unit, double *width, double *height)
0272a10d 875{
9c0d9ce3
DS
876 if (png_ptr != NULL && info_ptr != NULL &&
877 (info_ptr->valid & PNG_INFO_sCAL))
878 {
879 *unit = info_ptr->scal_unit;
880 *width = atof(info_ptr->scal_s_width);
881 *height = atof(info_ptr->scal_s_height);
882 return (PNG_INFO_sCAL);
883 }
884
885 return(0);
0272a10d 886}
9c0d9ce3
DS
887# endif /* FLOATING POINT */
888png_uint_32 PNGAPI
fff5f7d5 889png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3
DS
890 int *unit, png_charpp width, png_charpp height)
891{
892 if (png_ptr != NULL && info_ptr != NULL &&
893 (info_ptr->valid & PNG_INFO_sCAL))
894 {
895 *unit = info_ptr->scal_unit;
896 *width = info_ptr->scal_s_width;
897 *height = info_ptr->scal_s_height;
898 return (PNG_INFO_sCAL);
899 }
900
901 return(0);
902}
903#endif /* sCAL */
0272a10d 904
b61cc19c 905#ifdef PNG_pHYs_SUPPORTED
0272a10d 906png_uint_32 PNGAPI
fff5f7d5 907png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
9c0d9ce3 908 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
0272a10d
VZ
909{
910 png_uint_32 retval = 0;
911
b61cc19c
PC
912 png_debug1(1, "in %s retrieval function", "pHYs");
913
0272a10d 914 if (png_ptr != NULL && info_ptr != NULL &&
9c0d9ce3 915 (info_ptr->valid & PNG_INFO_pHYs))
0272a10d 916 {
0272a10d
VZ
917 if (res_x != NULL)
918 {
919 *res_x = info_ptr->x_pixels_per_unit;
920 retval |= PNG_INFO_pHYs;
921 }
b61cc19c 922
0272a10d
VZ
923 if (res_y != NULL)
924 {
925 *res_y = info_ptr->y_pixels_per_unit;
926 retval |= PNG_INFO_pHYs;
927 }
b61cc19c 928
0272a10d
VZ
929 if (unit_type != NULL)
930 {
931 *unit_type = (int)info_ptr->phys_unit_type;
932 retval |= PNG_INFO_pHYs;
933 }
934 }
9c0d9ce3 935
0272a10d
VZ
936 return (retval);
937}
9c0d9ce3 938#endif /* pHYs */
0272a10d
VZ
939
940png_uint_32 PNGAPI
fff5f7d5 941png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3 942 png_colorp *palette, int *num_palette)
0272a10d 943{
b61cc19c
PC
944 png_debug1(1, "in %s retrieval function", "PLTE");
945
0272a10d
VZ
946 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
947 && palette != NULL)
948 {
0272a10d
VZ
949 *palette = info_ptr->palette;
950 *num_palette = info_ptr->num_palette;
970f6abe 951 png_debug1(3, "num_palette = %d", *num_palette);
0272a10d
VZ
952 return (PNG_INFO_PLTE);
953 }
9c0d9ce3 954
0272a10d
VZ
955 return (0);
956}
957
b61cc19c 958#ifdef PNG_sBIT_SUPPORTED
0272a10d 959png_uint_32 PNGAPI
fff5f7d5 960png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3 961 png_color_8p *sig_bit)
0272a10d 962{
b61cc19c
PC
963 png_debug1(1, "in %s retrieval function", "sBIT");
964
0272a10d 965 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
9c0d9ce3 966 && sig_bit != NULL)
0272a10d 967 {
0272a10d
VZ
968 *sig_bit = &(info_ptr->sig_bit);
969 return (PNG_INFO_sBIT);
970 }
9c0d9ce3 971
0272a10d
VZ
972 return (0);
973}
974#endif
975
b61cc19c 976#ifdef PNG_TEXT_SUPPORTED
fff5f7d5
VZ
977int PNGAPI
978png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3 979 png_textp *text_ptr, int *num_text)
0272a10d
VZ
980{
981 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
982 {
9c0d9ce3
DS
983 png_debug1(1, "in 0x%lx retrieval function",
984 (unsigned long)png_ptr->chunk_name);
b61cc19c 985
0272a10d
VZ
986 if (text_ptr != NULL)
987 *text_ptr = info_ptr->text;
b61cc19c 988
0272a10d
VZ
989 if (num_text != NULL)
990 *num_text = info_ptr->num_text;
b61cc19c 991
fff5f7d5 992 return info_ptr->num_text;
0272a10d 993 }
9c0d9ce3 994
0272a10d 995 if (num_text != NULL)
9c0d9ce3
DS
996 *num_text = 0;
997
0272a10d
VZ
998 return(0);
999}
1000#endif
1001
b61cc19c 1002#ifdef PNG_tIME_SUPPORTED
0272a10d 1003png_uint_32 PNGAPI
fff5f7d5
VZ
1004png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1005 png_timep *mod_time)
0272a10d 1006{
b61cc19c
PC
1007 png_debug1(1, "in %s retrieval function", "tIME");
1008
0272a10d
VZ
1009 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
1010 && mod_time != NULL)
1011 {
0272a10d
VZ
1012 *mod_time = &(info_ptr->mod_time);
1013 return (PNG_INFO_tIME);
1014 }
9c0d9ce3 1015
0272a10d
VZ
1016 return (0);
1017}
1018#endif
1019
b61cc19c 1020#ifdef PNG_tRNS_SUPPORTED
0272a10d 1021png_uint_32 PNGAPI
fff5f7d5 1022png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3 1023 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
0272a10d
VZ
1024{
1025 png_uint_32 retval = 0;
1026 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
1027 {
970f6abe 1028 png_debug1(1, "in %s retrieval function", "tRNS");
b61cc19c 1029
0272a10d
VZ
1030 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1031 {
9c0d9ce3
DS
1032 if (trans_alpha != NULL)
1033 {
1034 *trans_alpha = info_ptr->trans_alpha;
1035 retval |= PNG_INFO_tRNS;
1036 }
1037
1038 if (trans_color != NULL)
1039 *trans_color = &(info_ptr->trans_color);
0272a10d 1040 }
9c0d9ce3 1041
0272a10d
VZ
1042 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1043 {
9c0d9ce3
DS
1044 if (trans_color != NULL)
1045 {
1046 *trans_color = &(info_ptr->trans_color);
1047 retval |= PNG_INFO_tRNS;
1048 }
1049
1050 if (trans_alpha != NULL)
1051 *trans_alpha = NULL;
0272a10d 1052 }
9c0d9ce3 1053
970f6abe 1054 if (num_trans != NULL)
0272a10d
VZ
1055 {
1056 *num_trans = info_ptr->num_trans;
1057 retval |= PNG_INFO_tRNS;
1058 }
1059 }
9c0d9ce3 1060
0272a10d
VZ
1061 return (retval);
1062}
1063#endif
1064
fff5f7d5 1065#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
9c0d9ce3 1066int PNGAPI
fff5f7d5 1067png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
9c0d9ce3 1068 png_unknown_chunkpp unknowns)
0272a10d
VZ
1069{
1070 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1071 {
9c0d9ce3
DS
1072 *unknowns = info_ptr->unknown_chunks;
1073 return info_ptr->unknown_chunks_num;
0272a10d 1074 }
9c0d9ce3 1075
0272a10d
VZ
1076 return (0);
1077}
1078#endif
1079
b61cc19c 1080#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
0272a10d 1081png_byte PNGAPI
fff5f7d5 1082png_get_rgb_to_gray_status (png_const_structrp png_ptr)
0272a10d 1083{
9c0d9ce3 1084 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
0272a10d
VZ
1085}
1086#endif
1087
b61cc19c 1088#ifdef PNG_USER_CHUNKS_SUPPORTED
0272a10d 1089png_voidp PNGAPI
fff5f7d5 1090png_get_user_chunk_ptr(png_const_structrp png_ptr)
0272a10d 1091{
9c0d9ce3 1092 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
0272a10d
VZ
1093}
1094#endif
1095
b61cc19c 1096png_size_t PNGAPI
fff5f7d5 1097png_get_compression_buffer_size(png_const_structrp png_ptr)
0272a10d 1098{
fff5f7d5
VZ
1099 if (png_ptr == NULL)
1100 return 0;
1101
1102# ifdef PNG_WRITE_SUPPORTED
1103 if (png_ptr->mode & PNG_IS_READ_STRUCT)
1104# endif
1105 {
1106# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1107 return png_ptr->IDAT_read_size;
1108# else
1109 return PNG_IDAT_READ_SIZE;
1110# endif
1111 }
1112
1113# ifdef PNG_WRITE_SUPPORTED
1114 else
1115 return png_ptr->zbuffer_size;
1116# endif
0272a10d 1117}
0272a10d 1118
b61cc19c
PC
1119#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1120/* These functions were added to libpng 1.2.6 and were enabled
1121 * by default in libpng-1.4.0 */
0272a10d 1122png_uint_32 PNGAPI
fff5f7d5 1123png_get_user_width_max (png_const_structrp png_ptr)
0272a10d 1124{
9c0d9ce3 1125 return (png_ptr ? png_ptr->user_width_max : 0);
0272a10d 1126}
9c0d9ce3 1127
0272a10d 1128png_uint_32 PNGAPI
fff5f7d5 1129png_get_user_height_max (png_const_structrp png_ptr)
0272a10d 1130{
9c0d9ce3 1131 return (png_ptr ? png_ptr->user_height_max : 0);
0272a10d 1132}
9c0d9ce3 1133
b61cc19c 1134/* This function was added to libpng 1.4.0 */
0272a10d 1135png_uint_32 PNGAPI
fff5f7d5 1136png_get_chunk_cache_max (png_const_structrp png_ptr)
0272a10d 1137{
9c0d9ce3 1138 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
0272a10d 1139}
9c0d9ce3 1140
b61cc19c
PC
1141/* This function was added to libpng 1.4.1 */
1142png_alloc_size_t PNGAPI
fff5f7d5 1143png_get_chunk_malloc_max (png_const_structrp png_ptr)
0272a10d 1144{
9c0d9ce3 1145 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
0272a10d 1146}
b61cc19c 1147#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
0272a10d 1148
b61cc19c
PC
1149/* These functions were added to libpng 1.4.0 */
1150#ifdef PNG_IO_STATE_SUPPORTED
0272a10d 1151png_uint_32 PNGAPI
fff5f7d5 1152png_get_io_state (png_const_structrp png_ptr)
0272a10d 1153{
9c0d9ce3 1154 return png_ptr->io_state;
0272a10d 1155}
0272a10d 1156
9c0d9ce3 1157png_uint_32 PNGAPI
fff5f7d5 1158png_get_io_chunk_type (png_const_structrp png_ptr)
0272a10d 1159{
b61cc19c 1160 return png_ptr->chunk_name;
0272a10d 1161}
fff5f7d5 1162#endif /* ?PNG_IO_STATE_SUPPORTED */
9c0d9ce3 1163
fff5f7d5
VZ
1164#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1165# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1166int PNGAPI
1167png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
9c0d9ce3 1168{
fff5f7d5
VZ
1169 if (png_ptr != NULL && info_ptr != NULL)
1170 return png_ptr->num_palette_max;
1171
1172 return (-1);
9c0d9ce3 1173}
fff5f7d5
VZ
1174# endif
1175#endif
0272a10d
VZ
1176
1177#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */