Bumping manifests a=b2g-bump
[gecko.git] / media / libpng / pngget.c
blob3177784158331987d4aa9eeb2e9acec30e63b0e4
2 /* pngget.c - retrieval of values from info struct
4 * Last changed in libpng 1.6.11 [June 5, 2014]
5 * Copyright (c) 1998-2014 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
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
15 #include "pngpriv.h"
17 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
19 png_uint_32 PNGAPI
20 png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
21 png_uint_32 flag)
23 if (png_ptr != NULL && info_ptr != NULL)
24 return(info_ptr->valid & flag);
26 return(0);
29 png_size_t PNGAPI
30 png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
32 if (png_ptr != NULL && info_ptr != NULL)
33 return(info_ptr->rowbytes);
35 return(0);
38 #ifdef PNG_INFO_IMAGE_SUPPORTED
39 png_bytepp PNGAPI
40 png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
42 if (png_ptr != NULL && info_ptr != NULL)
43 return(info_ptr->row_pointers);
45 return(0);
47 #endif
49 #ifdef PNG_EASY_ACCESS_SUPPORTED
50 /* Easy access to info, added in libpng-0.99 */
51 png_uint_32 PNGAPI
52 png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
54 if (png_ptr != NULL && info_ptr != NULL)
55 return info_ptr->width;
57 return (0);
60 png_uint_32 PNGAPI
61 png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
63 if (png_ptr != NULL && info_ptr != NULL)
64 return info_ptr->height;
66 return (0);
69 png_byte PNGAPI
70 png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
72 if (png_ptr != NULL && info_ptr != NULL)
73 return info_ptr->bit_depth;
75 return (0);
78 png_byte PNGAPI
79 png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
81 if (png_ptr != NULL && info_ptr != NULL)
82 return info_ptr->color_type;
84 return (0);
87 png_byte PNGAPI
88 png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
90 if (png_ptr != NULL && info_ptr != NULL)
91 return info_ptr->filter_type;
93 return (0);
96 png_byte PNGAPI
97 png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
99 if (png_ptr != NULL && info_ptr != NULL)
100 return info_ptr->interlace_type;
102 return (0);
105 png_byte PNGAPI
106 png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
108 if (png_ptr != NULL && info_ptr != NULL)
109 return info_ptr->compression_type;
111 return (0);
114 png_uint_32 PNGAPI
115 png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
116 info_ptr)
118 #ifdef PNG_pHYs_SUPPORTED
119 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
121 png_debug1(1, "in %s retrieval function",
122 "png_get_x_pixels_per_meter");
124 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
125 return (info_ptr->x_pixels_per_unit);
127 #else
128 PNG_UNUSED(png_ptr)
129 PNG_UNUSED(info_ptr)
130 #endif
132 return (0);
135 png_uint_32 PNGAPI
136 png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
137 info_ptr)
139 #ifdef PNG_pHYs_SUPPORTED
140 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
142 png_debug1(1, "in %s retrieval function",
143 "png_get_y_pixels_per_meter");
145 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
146 return (info_ptr->y_pixels_per_unit);
148 #else
149 PNG_UNUSED(png_ptr)
150 PNG_UNUSED(info_ptr)
151 #endif
153 return (0);
156 png_uint_32 PNGAPI
157 png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
159 #ifdef PNG_pHYs_SUPPORTED
160 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
162 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
164 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
165 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
166 return (info_ptr->x_pixels_per_unit);
168 #else
169 PNG_UNUSED(png_ptr)
170 PNG_UNUSED(info_ptr)
171 #endif
173 return (0);
176 #ifdef PNG_FLOATING_POINT_SUPPORTED
177 float PNGAPI
178 png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
179 info_ptr)
181 #ifdef PNG_READ_pHYs_SUPPORTED
182 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
184 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
186 if (info_ptr->x_pixels_per_unit != 0)
187 return ((float)((float)info_ptr->y_pixels_per_unit
188 /(float)info_ptr->x_pixels_per_unit));
190 #else
191 PNG_UNUSED(png_ptr)
192 PNG_UNUSED(info_ptr)
193 #endif
195 return ((float)0.0);
197 #endif
199 #ifdef PNG_FIXED_POINT_SUPPORTED
200 png_fixed_point PNGAPI
201 png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
202 png_const_inforp info_ptr)
204 #ifdef PNG_READ_pHYs_SUPPORTED
205 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
206 && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
207 && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
208 && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
210 png_fixed_point res;
212 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
214 /* The following casts work because a PNG 4 byte integer only has a valid
215 * range of 0..2^31-1; otherwise the cast might overflow.
217 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
218 (png_int_32)info_ptr->x_pixels_per_unit))
219 return res;
221 #else
222 PNG_UNUSED(png_ptr)
223 PNG_UNUSED(info_ptr)
224 #endif
226 return 0;
228 #endif
230 png_int_32 PNGAPI
231 png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
233 #ifdef PNG_oFFs_SUPPORTED
234 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
236 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
238 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
239 return (info_ptr->x_offset);
241 #else
242 PNG_UNUSED(png_ptr)
243 PNG_UNUSED(info_ptr)
244 #endif
246 return (0);
249 png_int_32 PNGAPI
250 png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
252 #ifdef PNG_oFFs_SUPPORTED
253 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
255 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
257 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
258 return (info_ptr->y_offset);
260 #else
261 PNG_UNUSED(png_ptr)
262 PNG_UNUSED(info_ptr)
263 #endif
265 return (0);
268 png_int_32 PNGAPI
269 png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
271 #ifdef PNG_oFFs_SUPPORTED
272 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
274 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
276 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
277 return (info_ptr->x_offset);
279 #else
280 PNG_UNUSED(png_ptr)
281 PNG_UNUSED(info_ptr)
282 #endif
284 return (0);
287 png_int_32 PNGAPI
288 png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
290 #ifdef PNG_oFFs_SUPPORTED
291 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
293 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
295 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
296 return (info_ptr->y_offset);
298 #else
299 PNG_UNUSED(png_ptr)
300 PNG_UNUSED(info_ptr)
301 #endif
303 return (0);
306 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
307 static png_uint_32
308 ppi_from_ppm(png_uint_32 ppm)
310 #if 0
311 /* The conversion is *(2.54/100), in binary (32 digits):
312 * .00000110100000001001110101001001
314 png_uint_32 t1001, t1101;
315 ppm >>= 1; /* .1 */
316 t1001 = ppm + (ppm >> 3); /* .1001 */
317 t1101 = t1001 + (ppm >> 1); /* .1101 */
318 ppm >>= 20; /* .000000000000000000001 */
319 t1101 += t1101 >> 15; /* .1101000000000001101 */
320 t1001 >>= 11; /* .000000000001001 */
321 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
322 ppm += t1001; /* .000000000001001000001001001 */
323 ppm += t1101; /* .110100000001001110101001001 */
324 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
325 #else
326 /* The argument is a PNG unsigned integer, so it is not permitted
327 * to be bigger than 2^31.
329 png_fixed_point result;
330 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
331 5000))
332 return result;
334 /* Overflow. */
335 return 0;
336 #endif
339 png_uint_32 PNGAPI
340 png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
342 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
345 png_uint_32 PNGAPI
346 png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
348 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
351 png_uint_32 PNGAPI
352 png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
354 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
357 #ifdef PNG_FIXED_POINT_SUPPORTED
358 static png_fixed_point
359 png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
361 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
362 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
363 * Notice that this can overflow - a warning is output and 0 is
364 * returned.
366 return png_muldiv_warn(png_ptr, microns, 500, 127);
369 png_fixed_point PNGAPI
370 png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
371 png_const_inforp info_ptr)
373 return png_fixed_inches_from_microns(png_ptr,
374 png_get_x_offset_microns(png_ptr, info_ptr));
376 #endif
378 #ifdef PNG_FIXED_POINT_SUPPORTED
379 png_fixed_point PNGAPI
380 png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
381 png_const_inforp info_ptr)
383 return png_fixed_inches_from_microns(png_ptr,
384 png_get_y_offset_microns(png_ptr, info_ptr));
386 #endif
388 #ifdef PNG_FLOATING_POINT_SUPPORTED
389 float PNGAPI
390 png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
392 /* To avoid the overflow do the conversion directly in floating
393 * point.
395 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
397 #endif
399 #ifdef PNG_FLOATING_POINT_SUPPORTED
400 float PNGAPI
401 png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
403 /* To avoid the overflow do the conversion directly in floating
404 * point.
406 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
408 #endif
410 #ifdef PNG_pHYs_SUPPORTED
411 png_uint_32 PNGAPI
412 png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
413 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
415 png_uint_32 retval = 0;
417 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
419 png_debug1(1, "in %s retrieval function", "pHYs");
421 if (res_x != NULL)
423 *res_x = info_ptr->x_pixels_per_unit;
424 retval |= PNG_INFO_pHYs;
427 if (res_y != NULL)
429 *res_y = info_ptr->y_pixels_per_unit;
430 retval |= PNG_INFO_pHYs;
433 if (unit_type != NULL)
435 *unit_type = (int)info_ptr->phys_unit_type;
436 retval |= PNG_INFO_pHYs;
438 if (*unit_type == 1)
440 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
441 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
446 return (retval);
448 #endif /* PNG_pHYs_SUPPORTED */
449 #endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
451 /* png_get_channels really belongs in here, too, but it's been around longer */
453 #endif /* PNG_EASY_ACCESS_SUPPORTED */
456 png_byte PNGAPI
457 png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
459 if (png_ptr != NULL && info_ptr != NULL)
460 return(info_ptr->channels);
462 return (0);
465 #ifdef PNG_READ_SUPPORTED
466 png_const_bytep PNGAPI
467 png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
469 if (png_ptr != NULL && info_ptr != NULL)
470 return(info_ptr->signature);
472 return (NULL);
474 #endif
476 #ifdef PNG_bKGD_SUPPORTED
477 png_uint_32 PNGAPI
478 png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
479 png_color_16p *background)
481 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
482 && background != NULL)
484 png_debug1(1, "in %s retrieval function", "bKGD");
486 *background = &(info_ptr->background);
487 return (PNG_INFO_bKGD);
490 return (0);
492 #endif
494 #ifdef PNG_cHRM_SUPPORTED
495 /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
496 * same time to correct the rgb grayscale coefficient defaults obtained from the
497 * cHRM chunk in 1.5.4
499 # ifdef PNG_FLOATING_POINT_SUPPORTED
500 png_uint_32 PNGAPI
501 png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
502 double *white_x, double *white_y, double *red_x, double *red_y,
503 double *green_x, double *green_y, double *blue_x, double *blue_y)
505 /* Quiet API change: this code used to only return the end points if a cHRM
506 * chunk was present, but the end points can also come from iCCP or sRGB
507 * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
508 * the png_set_ APIs merely check that set end points are mutually
509 * consistent.
511 if (png_ptr != NULL && info_ptr != NULL &&
512 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
514 png_debug1(1, "in %s retrieval function", "cHRM");
516 if (white_x != NULL)
517 *white_x = png_float(png_ptr,
518 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
519 if (white_y != NULL)
520 *white_y = png_float(png_ptr,
521 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
522 if (red_x != NULL)
523 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
524 "cHRM red X");
525 if (red_y != NULL)
526 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
527 "cHRM red Y");
528 if (green_x != NULL)
529 *green_x = png_float(png_ptr,
530 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
531 if (green_y != NULL)
532 *green_y = png_float(png_ptr,
533 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
534 if (blue_x != NULL)
535 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
536 "cHRM blue X");
537 if (blue_y != NULL)
538 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
539 "cHRM blue Y");
540 return (PNG_INFO_cHRM);
543 return (0);
546 png_uint_32 PNGAPI
547 png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
548 double *red_X, double *red_Y, double *red_Z, double *green_X,
549 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
550 double *blue_Z)
552 if (png_ptr != NULL && info_ptr != NULL &&
553 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
555 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
557 if (red_X != NULL)
558 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
559 "cHRM red X");
560 if (red_Y != NULL)
561 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
562 "cHRM red Y");
563 if (red_Z != NULL)
564 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
565 "cHRM red Z");
566 if (green_X != NULL)
567 *green_X = png_float(png_ptr,
568 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
569 if (green_Y != NULL)
570 *green_Y = png_float(png_ptr,
571 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
572 if (green_Z != NULL)
573 *green_Z = png_float(png_ptr,
574 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
575 if (blue_X != NULL)
576 *blue_X = png_float(png_ptr,
577 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
578 if (blue_Y != NULL)
579 *blue_Y = png_float(png_ptr,
580 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
581 if (blue_Z != NULL)
582 *blue_Z = png_float(png_ptr,
583 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
584 return (PNG_INFO_cHRM);
587 return (0);
589 # endif
591 # ifdef PNG_FIXED_POINT_SUPPORTED
592 png_uint_32 PNGAPI
593 png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
594 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
595 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
596 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
597 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
598 png_fixed_point *int_blue_Z)
600 if (png_ptr != NULL && info_ptr != NULL &&
601 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
603 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
605 if (int_red_X != NULL)
606 *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
607 if (int_red_Y != NULL)
608 *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
609 if (int_red_Z != NULL)
610 *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
611 if (int_green_X != NULL)
612 *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
613 if (int_green_Y != NULL)
614 *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
615 if (int_green_Z != NULL)
616 *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
617 if (int_blue_X != NULL)
618 *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
619 if (int_blue_Y != NULL)
620 *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
621 if (int_blue_Z != NULL)
622 *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
623 return (PNG_INFO_cHRM);
626 return (0);
629 png_uint_32 PNGAPI
630 png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
631 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
632 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
633 png_fixed_point *blue_x, png_fixed_point *blue_y)
635 png_debug1(1, "in %s retrieval function", "cHRM");
637 if (png_ptr != NULL && info_ptr != NULL &&
638 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
640 if (white_x != NULL)
641 *white_x = info_ptr->colorspace.end_points_xy.whitex;
642 if (white_y != NULL)
643 *white_y = info_ptr->colorspace.end_points_xy.whitey;
644 if (red_x != NULL)
645 *red_x = info_ptr->colorspace.end_points_xy.redx;
646 if (red_y != NULL)
647 *red_y = info_ptr->colorspace.end_points_xy.redy;
648 if (green_x != NULL)
649 *green_x = info_ptr->colorspace.end_points_xy.greenx;
650 if (green_y != NULL)
651 *green_y = info_ptr->colorspace.end_points_xy.greeny;
652 if (blue_x != NULL)
653 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
654 if (blue_y != NULL)
655 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
656 return (PNG_INFO_cHRM);
659 return (0);
661 # endif
662 #endif
664 #ifdef PNG_gAMA_SUPPORTED
665 # ifdef PNG_FIXED_POINT_SUPPORTED
666 png_uint_32 PNGAPI
667 png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
668 png_fixed_point *file_gamma)
670 png_debug1(1, "in %s retrieval function", "gAMA");
672 if (png_ptr != NULL && info_ptr != NULL &&
673 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
674 file_gamma != NULL)
676 *file_gamma = info_ptr->colorspace.gamma;
677 return (PNG_INFO_gAMA);
680 return (0);
682 # endif
684 # ifdef PNG_FLOATING_POINT_SUPPORTED
685 png_uint_32 PNGAPI
686 png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
687 double *file_gamma)
689 png_debug1(1, "in %s retrieval function", "gAMA(float)");
691 if (png_ptr != NULL && info_ptr != NULL &&
692 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
693 file_gamma != NULL)
695 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
696 "png_get_gAMA");
697 return (PNG_INFO_gAMA);
700 return (0);
702 # endif
703 #endif
705 #ifdef PNG_sRGB_SUPPORTED
706 png_uint_32 PNGAPI
707 png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
708 int *file_srgb_intent)
710 png_debug1(1, "in %s retrieval function", "sRGB");
712 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
713 && file_srgb_intent != NULL)
715 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
716 return (PNG_INFO_sRGB);
719 return (0);
721 #endif
723 #ifdef PNG_iCCP_SUPPORTED
724 png_uint_32 PNGAPI
725 png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
726 png_charpp name, int *compression_type,
727 png_bytepp profile, png_uint_32 *proflen)
729 png_debug1(1, "in %s retrieval function", "iCCP");
731 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
732 && name != NULL && compression_type != NULL && profile != NULL &&
733 proflen != NULL)
735 *name = info_ptr->iccp_name;
736 *profile = info_ptr->iccp_profile;
737 *proflen = png_get_uint_32(info_ptr->iccp_profile);
738 /* This is somewhat irrelevant since the profile data returned has
739 * actually been uncompressed.
741 *compression_type = PNG_COMPRESSION_TYPE_BASE;
742 return (PNG_INFO_iCCP);
745 return (0);
747 #endif
749 #ifdef PNG_sPLT_SUPPORTED
750 int PNGAPI
751 png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
752 png_sPLT_tpp spalettes)
754 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
756 *spalettes = info_ptr->splt_palettes;
757 return info_ptr->splt_palettes_num;
760 return (0);
762 #endif
764 #ifdef PNG_hIST_SUPPORTED
765 png_uint_32 PNGAPI
766 png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
767 png_uint_16p *hist)
769 png_debug1(1, "in %s retrieval function", "hIST");
771 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
772 && hist != NULL)
774 *hist = info_ptr->hist;
775 return (PNG_INFO_hIST);
778 return (0);
780 #endif
782 png_uint_32 PNGAPI
783 png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
784 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
785 int *color_type, int *interlace_type, int *compression_type,
786 int *filter_type)
788 png_debug1(1, "in %s retrieval function", "IHDR");
790 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
791 height == NULL || bit_depth == NULL || color_type == NULL)
792 return (0);
794 *width = info_ptr->width;
795 *height = info_ptr->height;
796 *bit_depth = info_ptr->bit_depth;
797 *color_type = info_ptr->color_type;
799 if (compression_type != NULL)
800 *compression_type = info_ptr->compression_type;
802 if (filter_type != NULL)
803 *filter_type = info_ptr->filter_type;
805 if (interlace_type != NULL)
806 *interlace_type = info_ptr->interlace_type;
808 /* This is redundant if we can be sure that the info_ptr values were all
809 * assigned in png_set_IHDR(). We do the check anyhow in case an
810 * application has ignored our advice not to mess with the members
811 * of info_ptr directly.
813 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
814 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
815 info_ptr->compression_type, info_ptr->filter_type);
817 return (1);
820 #ifdef PNG_oFFs_SUPPORTED
821 png_uint_32 PNGAPI
822 png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
823 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
825 png_debug1(1, "in %s retrieval function", "oFFs");
827 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
828 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
830 *offset_x = info_ptr->x_offset;
831 *offset_y = info_ptr->y_offset;
832 *unit_type = (int)info_ptr->offset_unit_type;
833 return (PNG_INFO_oFFs);
836 return (0);
838 #endif
840 #ifdef PNG_pCAL_SUPPORTED
841 png_uint_32 PNGAPI
842 png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
843 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
844 png_charp *units, png_charpp *params)
846 png_debug1(1, "in %s retrieval function", "pCAL");
848 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
849 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
850 nparams != NULL && units != NULL && params != NULL)
852 *purpose = info_ptr->pcal_purpose;
853 *X0 = info_ptr->pcal_X0;
854 *X1 = info_ptr->pcal_X1;
855 *type = (int)info_ptr->pcal_type;
856 *nparams = (int)info_ptr->pcal_nparams;
857 *units = info_ptr->pcal_units;
858 *params = info_ptr->pcal_params;
859 return (PNG_INFO_pCAL);
862 return (0);
864 #endif
866 #ifdef PNG_sCAL_SUPPORTED
867 # ifdef PNG_FIXED_POINT_SUPPORTED
868 # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
869 defined(PNG_FLOATING_POINT_SUPPORTED)
870 png_uint_32 PNGAPI
871 png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
872 int *unit, png_fixed_point *width, png_fixed_point *height)
874 if (png_ptr != NULL && info_ptr != NULL &&
875 (info_ptr->valid & PNG_INFO_sCAL))
877 *unit = info_ptr->scal_unit;
878 /*TODO: make this work without FP support; the API is currently eliminated
879 * if neither floating point APIs nor internal floating point arithmetic
880 * are enabled.
882 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
883 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
884 "sCAL height");
885 return (PNG_INFO_sCAL);
888 return(0);
890 # endif /* FLOATING_ARITHMETIC */
891 # endif /* FIXED_POINT */
892 # ifdef PNG_FLOATING_POINT_SUPPORTED
893 png_uint_32 PNGAPI
894 png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
895 int *unit, double *width, double *height)
897 if (png_ptr != NULL && info_ptr != NULL &&
898 (info_ptr->valid & PNG_INFO_sCAL))
900 *unit = info_ptr->scal_unit;
901 *width = atof(info_ptr->scal_s_width);
902 *height = atof(info_ptr->scal_s_height);
903 return (PNG_INFO_sCAL);
906 return(0);
908 # endif /* FLOATING POINT */
909 png_uint_32 PNGAPI
910 png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
911 int *unit, png_charpp width, png_charpp height)
913 if (png_ptr != NULL && info_ptr != NULL &&
914 (info_ptr->valid & PNG_INFO_sCAL))
916 *unit = info_ptr->scal_unit;
917 *width = info_ptr->scal_s_width;
918 *height = info_ptr->scal_s_height;
919 return (PNG_INFO_sCAL);
922 return(0);
924 #endif /* sCAL */
926 #ifdef PNG_pHYs_SUPPORTED
927 png_uint_32 PNGAPI
928 png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
929 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
931 png_uint_32 retval = 0;
933 png_debug1(1, "in %s retrieval function", "pHYs");
935 if (png_ptr != NULL && info_ptr != NULL &&
936 (info_ptr->valid & PNG_INFO_pHYs))
938 if (res_x != NULL)
940 *res_x = info_ptr->x_pixels_per_unit;
941 retval |= PNG_INFO_pHYs;
944 if (res_y != NULL)
946 *res_y = info_ptr->y_pixels_per_unit;
947 retval |= PNG_INFO_pHYs;
950 if (unit_type != NULL)
952 *unit_type = (int)info_ptr->phys_unit_type;
953 retval |= PNG_INFO_pHYs;
957 return (retval);
959 #endif /* pHYs */
961 png_uint_32 PNGAPI
962 png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
963 png_colorp *palette, int *num_palette)
965 png_debug1(1, "in %s retrieval function", "PLTE");
967 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
968 && palette != NULL)
970 *palette = info_ptr->palette;
971 *num_palette = info_ptr->num_palette;
972 png_debug1(3, "num_palette = %d", *num_palette);
973 return (PNG_INFO_PLTE);
976 return (0);
979 #ifdef PNG_sBIT_SUPPORTED
980 png_uint_32 PNGAPI
981 png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
982 png_color_8p *sig_bit)
984 png_debug1(1, "in %s retrieval function", "sBIT");
986 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
987 && sig_bit != NULL)
989 *sig_bit = &(info_ptr->sig_bit);
990 return (PNG_INFO_sBIT);
993 return (0);
995 #endif
997 #ifdef PNG_TEXT_SUPPORTED
998 int PNGAPI
999 png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
1000 png_textp *text_ptr, int *num_text)
1002 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
1004 png_debug1(1, "in 0x%lx retrieval function",
1005 (unsigned long)png_ptr->chunk_name);
1007 if (text_ptr != NULL)
1008 *text_ptr = info_ptr->text;
1010 if (num_text != NULL)
1011 *num_text = info_ptr->num_text;
1013 return info_ptr->num_text;
1016 if (num_text != NULL)
1017 *num_text = 0;
1019 return(0);
1021 #endif
1023 #ifdef PNG_tIME_SUPPORTED
1024 png_uint_32 PNGAPI
1025 png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1026 png_timep *mod_time)
1028 png_debug1(1, "in %s retrieval function", "tIME");
1030 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
1031 && mod_time != NULL)
1033 *mod_time = &(info_ptr->mod_time);
1034 return (PNG_INFO_tIME);
1037 return (0);
1039 #endif
1041 #ifdef PNG_tRNS_SUPPORTED
1042 png_uint_32 PNGAPI
1043 png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
1044 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
1046 png_uint_32 retval = 0;
1047 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
1049 png_debug1(1, "in %s retrieval function", "tRNS");
1051 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1053 if (trans_alpha != NULL)
1055 *trans_alpha = info_ptr->trans_alpha;
1056 retval |= PNG_INFO_tRNS;
1059 if (trans_color != NULL)
1060 *trans_color = &(info_ptr->trans_color);
1063 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1065 if (trans_color != NULL)
1067 *trans_color = &(info_ptr->trans_color);
1068 retval |= PNG_INFO_tRNS;
1071 if (trans_alpha != NULL)
1072 *trans_alpha = NULL;
1075 if (num_trans != NULL)
1077 *num_trans = info_ptr->num_trans;
1078 retval |= PNG_INFO_tRNS;
1082 return (retval);
1084 #endif
1086 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1087 int PNGAPI
1088 png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
1089 png_unknown_chunkpp unknowns)
1091 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1093 *unknowns = info_ptr->unknown_chunks;
1094 return info_ptr->unknown_chunks_num;
1097 return (0);
1099 #endif
1101 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1102 png_byte PNGAPI
1103 png_get_rgb_to_gray_status (png_const_structrp png_ptr)
1105 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
1107 #endif
1109 #ifdef PNG_USER_CHUNKS_SUPPORTED
1110 png_voidp PNGAPI
1111 png_get_user_chunk_ptr(png_const_structrp png_ptr)
1113 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1115 #endif
1117 png_size_t PNGAPI
1118 png_get_compression_buffer_size(png_const_structrp png_ptr)
1120 if (png_ptr == NULL)
1121 return 0;
1123 # ifdef PNG_WRITE_SUPPORTED
1124 if (png_ptr->mode & PNG_IS_READ_STRUCT)
1125 # endif
1127 # ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1128 return png_ptr->IDAT_read_size;
1129 # else
1130 return PNG_IDAT_READ_SIZE;
1131 # endif
1134 # ifdef PNG_WRITE_SUPPORTED
1135 else
1136 return png_ptr->zbuffer_size;
1137 # endif
1140 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
1141 /* These functions were added to libpng 1.2.6 and were enabled
1142 * by default in libpng-1.4.0 */
1143 png_uint_32 PNGAPI
1144 png_get_user_width_max (png_const_structrp png_ptr)
1146 return (png_ptr ? png_ptr->user_width_max : 0);
1149 png_uint_32 PNGAPI
1150 png_get_user_height_max (png_const_structrp png_ptr)
1152 return (png_ptr ? png_ptr->user_height_max : 0);
1155 /* This function was added to libpng 1.4.0 */
1156 png_uint_32 PNGAPI
1157 png_get_chunk_cache_max (png_const_structrp png_ptr)
1159 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1162 /* This function was added to libpng 1.4.1 */
1163 png_alloc_size_t PNGAPI
1164 png_get_chunk_malloc_max (png_const_structrp png_ptr)
1166 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1168 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1170 /* These functions were added to libpng 1.4.0 */
1171 #ifdef PNG_IO_STATE_SUPPORTED
1172 png_uint_32 PNGAPI
1173 png_get_io_state (png_const_structrp png_ptr)
1175 return png_ptr->io_state;
1178 png_uint_32 PNGAPI
1179 png_get_io_chunk_type (png_const_structrp png_ptr)
1181 return png_ptr->chunk_name;
1183 #endif /* ?PNG_IO_STATE_SUPPORTED */
1185 #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1186 # ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1187 int PNGAPI
1188 png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1190 if (png_ptr != NULL && info_ptr != NULL)
1191 return png_ptr->num_palette_max;
1193 return (-1);
1195 # endif
1196 #endif
1198 #ifdef PNG_APNG_SUPPORTED
1199 png_uint_32 PNGAPI
1200 png_get_acTL(png_structp png_ptr, png_infop info_ptr,
1201 png_uint_32 *num_frames, png_uint_32 *num_plays)
1203 png_debug1(1, "in %s retrieval function", "acTL");
1205 if (png_ptr != NULL && info_ptr != NULL &&
1206 (info_ptr->valid & PNG_INFO_acTL) &&
1207 num_frames != NULL && num_plays != NULL)
1209 *num_frames = info_ptr->num_frames;
1210 *num_plays = info_ptr->num_plays;
1211 return (1);
1214 return (0);
1217 png_uint_32 PNGAPI
1218 png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
1220 png_debug(1, "in png_get_num_frames()");
1222 if (png_ptr != NULL && info_ptr != NULL)
1223 return (info_ptr->num_frames);
1224 return (0);
1227 png_uint_32 PNGAPI
1228 png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
1230 png_debug(1, "in png_get_num_plays()");
1232 if (png_ptr != NULL && info_ptr != NULL)
1233 return (info_ptr->num_plays);
1234 return (0);
1237 png_uint_32 PNGAPI
1238 png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
1239 png_uint_32 *width, png_uint_32 *height,
1240 png_uint_32 *x_offset, png_uint_32 *y_offset,
1241 png_uint_16 *delay_num, png_uint_16 *delay_den,
1242 png_byte *dispose_op, png_byte *blend_op)
1244 png_debug1(1, "in %s retrieval function", "fcTL");
1246 if (png_ptr != NULL && info_ptr != NULL &&
1247 (info_ptr->valid & PNG_INFO_fcTL) &&
1248 width != NULL && height != NULL &&
1249 x_offset != NULL && y_offset != NULL &&
1250 delay_num != NULL && delay_den != NULL &&
1251 dispose_op != NULL && blend_op != NULL)
1253 *width = info_ptr->next_frame_width;
1254 *height = info_ptr->next_frame_height;
1255 *x_offset = info_ptr->next_frame_x_offset;
1256 *y_offset = info_ptr->next_frame_y_offset;
1257 *delay_num = info_ptr->next_frame_delay_num;
1258 *delay_den = info_ptr->next_frame_delay_den;
1259 *dispose_op = info_ptr->next_frame_dispose_op;
1260 *blend_op = info_ptr->next_frame_blend_op;
1261 return (1);
1264 return (0);
1267 png_uint_32 PNGAPI
1268 png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
1270 png_debug(1, "in png_get_next_frame_width()");
1272 if (png_ptr != NULL && info_ptr != NULL)
1273 return (info_ptr->next_frame_width);
1274 return (0);
1277 png_uint_32 PNGAPI
1278 png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
1280 png_debug(1, "in png_get_next_frame_height()");
1282 if (png_ptr != NULL && info_ptr != NULL)
1283 return (info_ptr->next_frame_height);
1284 return (0);
1287 png_uint_32 PNGAPI
1288 png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
1290 png_debug(1, "in png_get_next_frame_x_offset()");
1292 if (png_ptr != NULL && info_ptr != NULL)
1293 return (info_ptr->next_frame_x_offset);
1294 return (0);
1297 png_uint_32 PNGAPI
1298 png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
1300 png_debug(1, "in png_get_next_frame_y_offset()");
1302 if (png_ptr != NULL && info_ptr != NULL)
1303 return (info_ptr->next_frame_y_offset);
1304 return (0);
1307 png_uint_16 PNGAPI
1308 png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
1310 png_debug(1, "in png_get_next_frame_delay_num()");
1312 if (png_ptr != NULL && info_ptr != NULL)
1313 return (info_ptr->next_frame_delay_num);
1314 return (0);
1317 png_uint_16 PNGAPI
1318 png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
1320 png_debug(1, "in png_get_next_frame_delay_den()");
1322 if (png_ptr != NULL && info_ptr != NULL)
1323 return (info_ptr->next_frame_delay_den);
1324 return (0);
1327 png_byte PNGAPI
1328 png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
1330 png_debug(1, "in png_get_next_frame_dispose_op()");
1332 if (png_ptr != NULL && info_ptr != NULL)
1333 return (info_ptr->next_frame_dispose_op);
1334 return (0);
1337 png_byte PNGAPI
1338 png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
1340 png_debug(1, "in png_get_next_frame_blend_op()");
1342 if (png_ptr != NULL && info_ptr != NULL)
1343 return (info_ptr->next_frame_blend_op);
1344 return (0);
1347 png_byte PNGAPI
1348 png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
1350 png_debug(1, "in png_first_frame_is_hidden()");
1352 if (png_ptr != NULL)
1353 return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
1355 PNG_UNUSED(info_ptr)
1357 return 0;
1359 #endif /* PNG_APNG_SUPPORTED */
1360 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */