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