2 /* pngget.c - retrieval of values from info struct
4 * Copyright (c) 2018-2023 Cosmin Truta
5 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
6 * Copyright (c) 1996-1997 Andreas Dilger
7 * 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
17 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
20 png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
23 if (png_ptr != NULL && info_ptr != NULL)
25 #ifdef PNG_READ_tRNS_SUPPORTED
26 /* png_handle_PLTE() may have canceled a valid tRNS chunk but left the
27 * 'valid' flag for the detection of duplicate chunks. Do not report a
28 * valid tRNS chunk in this case.
30 if (flag == PNG_INFO_tRNS && png_ptr->num_trans == 0)
34 return(info_ptr->valid & flag);
41 png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
43 if (png_ptr != NULL && info_ptr != NULL)
44 return(info_ptr->rowbytes);
49 #ifdef PNG_INFO_IMAGE_SUPPORTED
51 png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
53 if (png_ptr != NULL && info_ptr != NULL)
54 return(info_ptr->row_pointers);
60 #ifdef PNG_EASY_ACCESS_SUPPORTED
61 /* Easy access to info, added in libpng-0.99 */
63 png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
65 if (png_ptr != NULL && info_ptr != NULL)
66 return info_ptr->width;
72 png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
74 if (png_ptr != NULL && info_ptr != NULL)
75 return info_ptr->height;
81 png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
83 if (png_ptr != NULL && info_ptr != NULL)
84 return info_ptr->bit_depth;
90 png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
92 if (png_ptr != NULL && info_ptr != NULL)
93 return info_ptr->color_type;
99 png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
101 if (png_ptr != NULL && info_ptr != NULL)
102 return info_ptr->filter_type;
108 png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
110 if (png_ptr != NULL && info_ptr != NULL)
111 return info_ptr->interlace_type;
117 png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
119 if (png_ptr != NULL && info_ptr != NULL)
120 return info_ptr->compression_type;
126 png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
129 #ifdef PNG_pHYs_SUPPORTED
130 if (png_ptr != NULL && info_ptr != NULL &&
131 (info_ptr->valid & PNG_INFO_pHYs) != 0)
133 png_debug1(1, "in %s retrieval function",
134 "png_get_x_pixels_per_meter");
136 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
137 return (info_ptr->x_pixels_per_unit);
148 png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
151 #ifdef PNG_pHYs_SUPPORTED
152 if (png_ptr != NULL && info_ptr != NULL &&
153 (info_ptr->valid & PNG_INFO_pHYs) != 0)
155 png_debug1(1, "in %s retrieval function",
156 "png_get_y_pixels_per_meter");
158 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
159 return (info_ptr->y_pixels_per_unit);
170 png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
172 #ifdef PNG_pHYs_SUPPORTED
173 if (png_ptr != NULL && info_ptr != NULL &&
174 (info_ptr->valid & PNG_INFO_pHYs) != 0)
176 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
178 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
179 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
180 return (info_ptr->x_pixels_per_unit);
190 #ifdef PNG_FLOATING_POINT_SUPPORTED
192 png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
195 #ifdef PNG_READ_pHYs_SUPPORTED
196 if (png_ptr != NULL && info_ptr != NULL &&
197 (info_ptr->valid & PNG_INFO_pHYs) != 0)
199 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
201 if (info_ptr->x_pixels_per_unit != 0)
202 return ((float)((float)info_ptr->y_pixels_per_unit
203 /(float)info_ptr->x_pixels_per_unit));
214 #ifdef PNG_FIXED_POINT_SUPPORTED
215 png_fixed_point PNGAPI
216 png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
217 png_const_inforp info_ptr)
219 #ifdef PNG_READ_pHYs_SUPPORTED
220 if (png_ptr != NULL && info_ptr != NULL &&
221 (info_ptr->valid & PNG_INFO_pHYs) != 0 &&
222 info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
223 info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
224 info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
228 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
230 /* The following casts work because a PNG 4 byte integer only has a valid
231 * range of 0..2^31-1; otherwise the cast might overflow.
233 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
234 (png_int_32)info_ptr->x_pixels_per_unit) != 0)
247 png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
249 #ifdef PNG_oFFs_SUPPORTED
250 if (png_ptr != NULL && info_ptr != NULL &&
251 (info_ptr->valid & PNG_INFO_oFFs) != 0)
253 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
255 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
256 return (info_ptr->x_offset);
267 png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
269 #ifdef PNG_oFFs_SUPPORTED
270 if (png_ptr != NULL && info_ptr != NULL &&
271 (info_ptr->valid & PNG_INFO_oFFs) != 0)
273 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
275 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
276 return (info_ptr->y_offset);
287 png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
289 #ifdef PNG_oFFs_SUPPORTED
290 if (png_ptr != NULL && info_ptr != NULL &&
291 (info_ptr->valid & PNG_INFO_oFFs) != 0)
293 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
295 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
296 return (info_ptr->x_offset);
307 png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
309 #ifdef PNG_oFFs_SUPPORTED
310 if (png_ptr != NULL && info_ptr != NULL &&
311 (info_ptr->valid & PNG_INFO_oFFs) != 0)
313 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
315 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
316 return (info_ptr->y_offset);
326 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
328 ppi_from_ppm(png_uint_32 ppm)
331 /* The conversion is *(2.54/100), in binary (32 digits):
332 * .00000110100000001001110101001001
334 png_uint_32 t1001, t1101;
336 t1001 = ppm + (ppm >> 3); /* .1001 */
337 t1101 = t1001 + (ppm >> 1); /* .1101 */
338 ppm >>= 20; /* .000000000000000000001 */
339 t1101 += t1101 >> 15; /* .1101000000000001101 */
340 t1001 >>= 11; /* .000000000001001 */
341 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
342 ppm += t1001; /* .000000000001001000001001001 */
343 ppm += t1101; /* .110100000001001110101001001 */
344 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
346 /* The argument is a PNG unsigned integer, so it is not permitted
347 * to be bigger than 2^31.
349 png_fixed_point result;
350 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
352 return (png_uint_32)result;
360 png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
362 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
366 png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
368 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
372 png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
374 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
377 #ifdef PNG_FIXED_POINT_SUPPORTED
378 static png_fixed_point
379 png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
381 /* Convert from meters * 1,000,000 to inches * 100,000, meters to
382 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
383 * Notice that this can overflow - a warning is output and 0 is
386 return png_muldiv_warn(png_ptr, microns, 500, 127);
389 png_fixed_point PNGAPI
390 png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
391 png_const_inforp info_ptr)
393 return png_fixed_inches_from_microns(png_ptr,
394 png_get_x_offset_microns(png_ptr, info_ptr));
398 #ifdef PNG_FIXED_POINT_SUPPORTED
399 png_fixed_point PNGAPI
400 png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
401 png_const_inforp info_ptr)
403 return png_fixed_inches_from_microns(png_ptr,
404 png_get_y_offset_microns(png_ptr, info_ptr));
408 #ifdef PNG_FLOATING_POINT_SUPPORTED
410 png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
412 /* To avoid the overflow do the conversion directly in floating
415 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
419 #ifdef PNG_FLOATING_POINT_SUPPORTED
421 png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
423 /* To avoid the overflow do the conversion directly in floating
426 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
430 #ifdef PNG_pHYs_SUPPORTED
432 png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
433 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
435 png_uint_32 retval = 0;
437 if (png_ptr != NULL && info_ptr != NULL &&
438 (info_ptr->valid & PNG_INFO_pHYs) != 0)
440 png_debug1(1, "in %s retrieval function", "pHYs");
444 *res_x = info_ptr->x_pixels_per_unit;
445 retval |= PNG_INFO_pHYs;
450 *res_y = info_ptr->y_pixels_per_unit;
451 retval |= PNG_INFO_pHYs;
454 if (unit_type != NULL)
456 *unit_type = (int)info_ptr->phys_unit_type;
457 retval |= PNG_INFO_pHYs;
461 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
462 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
470 #endif /* INCH_CONVERSIONS */
472 /* png_get_channels really belongs in here, too, but it's been around longer */
474 #endif /* EASY_ACCESS */
478 png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
480 if (png_ptr != NULL && info_ptr != NULL)
481 return(info_ptr->channels);
486 #ifdef PNG_READ_SUPPORTED
487 png_const_bytep PNGAPI
488 png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
490 if (png_ptr != NULL && info_ptr != NULL)
491 return(info_ptr->signature);
497 #ifdef PNG_bKGD_SUPPORTED
499 png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
500 png_color_16p *background)
502 if (png_ptr != NULL && info_ptr != NULL &&
503 (info_ptr->valid & PNG_INFO_bKGD) != 0 &&
506 png_debug1(1, "in %s retrieval function", "bKGD");
508 *background = &(info_ptr->background);
509 return (PNG_INFO_bKGD);
516 #ifdef PNG_cHRM_SUPPORTED
517 /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
518 * same time to correct the rgb grayscale coefficient defaults obtained from the
519 * cHRM chunk in 1.5.4
521 # ifdef PNG_FLOATING_POINT_SUPPORTED
523 png_get_cHRM(png_const_structrp png_ptr, png_const_inforp 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)
527 /* Quiet API change: this code used to only return the end points if a cHRM
528 * chunk was present, but the end points can also come from iCCP or sRGB
529 * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
530 * the png_set_ APIs merely check that set end points are mutually
533 if (png_ptr != NULL && info_ptr != NULL &&
534 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
536 png_debug1(1, "in %s retrieval function", "cHRM");
539 *white_x = png_float(png_ptr,
540 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
542 *white_y = png_float(png_ptr,
543 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
545 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
548 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
551 *green_x = png_float(png_ptr,
552 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
554 *green_y = png_float(png_ptr,
555 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
557 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
560 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
562 return (PNG_INFO_cHRM);
569 png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
570 double *red_X, double *red_Y, double *red_Z, double *green_X,
571 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
574 if (png_ptr != NULL && info_ptr != NULL &&
575 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
577 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
580 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
583 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
586 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
589 *green_X = png_float(png_ptr,
590 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
592 *green_Y = png_float(png_ptr,
593 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
595 *green_Z = png_float(png_ptr,
596 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
598 *blue_X = png_float(png_ptr,
599 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
601 *blue_Y = png_float(png_ptr,
602 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
604 *blue_Z = png_float(png_ptr,
605 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
606 return (PNG_INFO_cHRM);
613 # ifdef PNG_FIXED_POINT_SUPPORTED
615 png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
616 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
617 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
618 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
619 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
620 png_fixed_point *int_blue_Z)
622 if (png_ptr != NULL && info_ptr != NULL &&
623 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
625 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
627 if (int_red_X != NULL)
628 *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
629 if (int_red_Y != NULL)
630 *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
631 if (int_red_Z != NULL)
632 *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
633 if (int_green_X != NULL)
634 *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
635 if (int_green_Y != NULL)
636 *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
637 if (int_green_Z != NULL)
638 *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
639 if (int_blue_X != NULL)
640 *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
641 if (int_blue_Y != NULL)
642 *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
643 if (int_blue_Z != NULL)
644 *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
645 return (PNG_INFO_cHRM);
652 png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
653 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
654 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
655 png_fixed_point *blue_x, png_fixed_point *blue_y)
657 png_debug1(1, "in %s retrieval function", "cHRM");
659 if (png_ptr != NULL && info_ptr != NULL &&
660 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
663 *white_x = info_ptr->colorspace.end_points_xy.whitex;
665 *white_y = info_ptr->colorspace.end_points_xy.whitey;
667 *red_x = info_ptr->colorspace.end_points_xy.redx;
669 *red_y = info_ptr->colorspace.end_points_xy.redy;
671 *green_x = info_ptr->colorspace.end_points_xy.greenx;
673 *green_y = info_ptr->colorspace.end_points_xy.greeny;
675 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
677 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
678 return (PNG_INFO_cHRM);
686 #ifdef PNG_gAMA_SUPPORTED
687 # ifdef PNG_FIXED_POINT_SUPPORTED
689 png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
690 png_fixed_point *file_gamma)
692 png_debug1(1, "in %s retrieval function", "gAMA");
694 if (png_ptr != NULL && info_ptr != NULL &&
695 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
698 *file_gamma = info_ptr->colorspace.gamma;
699 return (PNG_INFO_gAMA);
706 # ifdef PNG_FLOATING_POINT_SUPPORTED
708 png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
711 png_debug1(1, "in %s retrieval function", "gAMA(float)");
713 if (png_ptr != NULL && info_ptr != NULL &&
714 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
717 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
719 return (PNG_INFO_gAMA);
727 #ifdef PNG_sRGB_SUPPORTED
729 png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
730 int *file_srgb_intent)
732 png_debug1(1, "in %s retrieval function", "sRGB");
734 if (png_ptr != NULL && info_ptr != NULL &&
735 (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
737 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
738 return (PNG_INFO_sRGB);
745 #ifdef PNG_iCCP_SUPPORTED
747 png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
748 png_charpp name, int *compression_type,
749 png_bytepp profile, png_uint_32 *proflen)
751 png_debug1(1, "in %s retrieval function", "iCCP");
753 if (png_ptr != NULL && info_ptr != NULL &&
754 (info_ptr->valid & PNG_INFO_iCCP) != 0 &&
755 name != NULL && profile != NULL && proflen != NULL)
757 *name = info_ptr->iccp_name;
758 *profile = info_ptr->iccp_profile;
759 *proflen = png_get_uint_32(info_ptr->iccp_profile);
760 /* This is somewhat irrelevant since the profile data returned has
761 * actually been uncompressed.
763 if (compression_type != NULL)
764 *compression_type = PNG_COMPRESSION_TYPE_BASE;
765 return (PNG_INFO_iCCP);
773 #ifdef PNG_sPLT_SUPPORTED
775 png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
776 png_sPLT_tpp spalettes)
778 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
780 *spalettes = info_ptr->splt_palettes;
781 return info_ptr->splt_palettes_num;
788 #ifdef PNG_eXIf_SUPPORTED
790 png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
793 png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
800 png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
801 png_uint_32 *num_exif, png_bytep *exif)
803 png_debug1(1, "in %s retrieval function", "eXIf");
805 if (png_ptr != NULL && info_ptr != NULL &&
806 (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
808 *num_exif = info_ptr->num_exif;
809 *exif = info_ptr->exif;
810 return (PNG_INFO_eXIf);
817 #ifdef PNG_hIST_SUPPORTED
819 png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
822 png_debug1(1, "in %s retrieval function", "hIST");
824 if (png_ptr != NULL && info_ptr != NULL &&
825 (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
827 *hist = info_ptr->hist;
828 return (PNG_INFO_hIST);
836 png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
837 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
838 int *color_type, int *interlace_type, int *compression_type,
841 png_debug1(1, "in %s retrieval function", "IHDR");
843 if (png_ptr == NULL || info_ptr == NULL)
847 *width = info_ptr->width;
850 *height = info_ptr->height;
852 if (bit_depth != NULL)
853 *bit_depth = info_ptr->bit_depth;
855 if (color_type != NULL)
856 *color_type = info_ptr->color_type;
858 if (compression_type != NULL)
859 *compression_type = info_ptr->compression_type;
861 if (filter_type != NULL)
862 *filter_type = info_ptr->filter_type;
864 if (interlace_type != NULL)
865 *interlace_type = info_ptr->interlace_type;
867 /* This is redundant if we can be sure that the info_ptr values were all
868 * assigned in png_set_IHDR(). We do the check anyhow in case an
869 * application has ignored our advice not to mess with the members
870 * of info_ptr directly.
872 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
873 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
874 info_ptr->compression_type, info_ptr->filter_type);
879 #ifdef PNG_oFFs_SUPPORTED
881 png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
882 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
884 png_debug1(1, "in %s retrieval function", "oFFs");
886 if (png_ptr != NULL && info_ptr != NULL &&
887 (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
888 offset_x != NULL && offset_y != NULL && unit_type != NULL)
890 *offset_x = info_ptr->x_offset;
891 *offset_y = info_ptr->y_offset;
892 *unit_type = (int)info_ptr->offset_unit_type;
893 return (PNG_INFO_oFFs);
900 #ifdef PNG_pCAL_SUPPORTED
902 png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
903 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
904 png_charp *units, png_charpp *params)
906 png_debug1(1, "in %s retrieval function", "pCAL");
908 if (png_ptr != NULL && info_ptr != NULL &&
909 (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
910 purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
911 nparams != NULL && units != NULL && params != NULL)
913 *purpose = info_ptr->pcal_purpose;
914 *X0 = info_ptr->pcal_X0;
915 *X1 = info_ptr->pcal_X1;
916 *type = (int)info_ptr->pcal_type;
917 *nparams = (int)info_ptr->pcal_nparams;
918 *units = info_ptr->pcal_units;
919 *params = info_ptr->pcal_params;
920 return (PNG_INFO_pCAL);
927 #ifdef PNG_sCAL_SUPPORTED
928 # ifdef PNG_FIXED_POINT_SUPPORTED
929 # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
930 defined(PNG_FLOATING_POINT_SUPPORTED)
932 png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
933 int *unit, png_fixed_point *width, png_fixed_point *height)
935 if (png_ptr != NULL && info_ptr != NULL &&
936 (info_ptr->valid & PNG_INFO_sCAL) != 0)
938 *unit = info_ptr->scal_unit;
939 /*TODO: make this work without FP support; the API is currently eliminated
940 * if neither floating point APIs nor internal floating point arithmetic
943 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
944 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
946 return (PNG_INFO_sCAL);
951 # endif /* FLOATING_ARITHMETIC */
952 # endif /* FIXED_POINT */
953 # ifdef PNG_FLOATING_POINT_SUPPORTED
955 png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
956 int *unit, double *width, double *height)
958 if (png_ptr != NULL && info_ptr != NULL &&
959 (info_ptr->valid & PNG_INFO_sCAL) != 0)
961 *unit = info_ptr->scal_unit;
962 *width = atof(info_ptr->scal_s_width);
963 *height = atof(info_ptr->scal_s_height);
964 return (PNG_INFO_sCAL);
969 # endif /* FLOATING POINT */
971 png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
972 int *unit, png_charpp width, png_charpp height)
974 if (png_ptr != NULL && info_ptr != NULL &&
975 (info_ptr->valid & PNG_INFO_sCAL) != 0)
977 *unit = info_ptr->scal_unit;
978 *width = info_ptr->scal_s_width;
979 *height = info_ptr->scal_s_height;
980 return (PNG_INFO_sCAL);
987 #ifdef PNG_pHYs_SUPPORTED
989 png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
990 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
992 png_uint_32 retval = 0;
994 png_debug1(1, "in %s retrieval function", "pHYs");
996 if (png_ptr != NULL && info_ptr != NULL &&
997 (info_ptr->valid & PNG_INFO_pHYs) != 0)
1001 *res_x = info_ptr->x_pixels_per_unit;
1002 retval |= PNG_INFO_pHYs;
1007 *res_y = info_ptr->y_pixels_per_unit;
1008 retval |= PNG_INFO_pHYs;
1011 if (unit_type != NULL)
1013 *unit_type = (int)info_ptr->phys_unit_type;
1014 retval |= PNG_INFO_pHYs;
1023 png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
1024 png_colorp *palette, int *num_palette)
1026 png_debug1(1, "in %s retrieval function", "PLTE");
1028 if (png_ptr != NULL && info_ptr != NULL &&
1029 (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
1031 *palette = info_ptr->palette;
1032 *num_palette = info_ptr->num_palette;
1033 png_debug1(3, "num_palette = %d", *num_palette);
1034 return (PNG_INFO_PLTE);
1040 #ifdef PNG_sBIT_SUPPORTED
1042 png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
1043 png_color_8p *sig_bit)
1045 png_debug1(1, "in %s retrieval function", "sBIT");
1047 if (png_ptr != NULL && info_ptr != NULL &&
1048 (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
1050 *sig_bit = &(info_ptr->sig_bit);
1051 return (PNG_INFO_sBIT);
1058 #ifdef PNG_TEXT_SUPPORTED
1060 png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
1061 png_textp *text_ptr, int *num_text)
1063 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
1065 png_debug1(1, "in 0x%lx retrieval function",
1066 (unsigned long)png_ptr->chunk_name);
1068 if (text_ptr != NULL)
1069 *text_ptr = info_ptr->text;
1071 if (num_text != NULL)
1072 *num_text = info_ptr->num_text;
1074 return info_ptr->num_text;
1077 if (num_text != NULL)
1084 #ifdef PNG_tIME_SUPPORTED
1086 png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1087 png_timep *mod_time)
1089 png_debug1(1, "in %s retrieval function", "tIME");
1091 if (png_ptr != NULL && info_ptr != NULL &&
1092 (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
1094 *mod_time = &(info_ptr->mod_time);
1095 return (PNG_INFO_tIME);
1102 #ifdef PNG_tRNS_SUPPORTED
1104 png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
1105 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
1107 png_uint_32 retval = 0;
1108 if (png_ptr != NULL && info_ptr != NULL &&
1109 (info_ptr->valid & PNG_INFO_tRNS) != 0)
1111 png_debug1(1, "in %s retrieval function", "tRNS");
1113 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1115 if (trans_alpha != NULL)
1117 *trans_alpha = info_ptr->trans_alpha;
1118 retval |= PNG_INFO_tRNS;
1121 if (trans_color != NULL)
1122 *trans_color = &(info_ptr->trans_color);
1125 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1127 if (trans_color != NULL)
1129 *trans_color = &(info_ptr->trans_color);
1130 retval |= PNG_INFO_tRNS;
1133 if (trans_alpha != NULL)
1134 *trans_alpha = NULL;
1137 if (num_trans != NULL)
1139 *num_trans = info_ptr->num_trans;
1140 retval |= PNG_INFO_tRNS;
1148 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1150 png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
1151 png_unknown_chunkpp unknowns)
1153 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1155 *unknowns = info_ptr->unknown_chunks;
1156 return info_ptr->unknown_chunks_num;
1163 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1165 png_get_rgb_to_gray_status(png_const_structrp png_ptr)
1167 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
1171 #ifdef PNG_USER_CHUNKS_SUPPORTED
1173 png_get_user_chunk_ptr(png_const_structrp png_ptr)
1175 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1180 png_get_compression_buffer_size(png_const_structrp png_ptr)
1182 if (png_ptr == NULL)
1185 #ifdef PNG_WRITE_SUPPORTED
1186 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1189 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1190 return png_ptr->IDAT_read_size;
1192 return PNG_IDAT_READ_SIZE;
1196 #ifdef PNG_WRITE_SUPPORTED
1198 return png_ptr->zbuffer_size;
1202 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
1203 /* These functions were added to libpng 1.2.6 and were enabled
1204 * by default in libpng-1.4.0 */
1206 png_get_user_width_max(png_const_structrp png_ptr)
1208 return (png_ptr ? png_ptr->user_width_max : 0);
1212 png_get_user_height_max(png_const_structrp png_ptr)
1214 return (png_ptr ? png_ptr->user_height_max : 0);
1217 /* This function was added to libpng 1.4.0 */
1219 png_get_chunk_cache_max(png_const_structrp png_ptr)
1221 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1224 /* This function was added to libpng 1.4.1 */
1225 png_alloc_size_t PNGAPI
1226 png_get_chunk_malloc_max(png_const_structrp png_ptr)
1228 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1230 #endif /* SET_USER_LIMITS */
1232 /* These functions were added to libpng 1.4.0 */
1233 #ifdef PNG_IO_STATE_SUPPORTED
1235 png_get_io_state(png_const_structrp png_ptr)
1237 return png_ptr->io_state;
1241 png_get_io_chunk_type(png_const_structrp png_ptr)
1243 return png_ptr->chunk_name;
1245 #endif /* IO_STATE */
1247 #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1248 # ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1250 png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1252 if (png_ptr != NULL && info_ptr != NULL)
1253 return png_ptr->num_palette_max;
1260 #ifdef PNG_APNG_SUPPORTED
1262 png_get_acTL(png_structp png_ptr, png_infop info_ptr,
1263 png_uint_32 *num_frames, png_uint_32 *num_plays)
1265 png_debug1(1, "in %s retrieval function", "acTL");
1267 if (png_ptr != NULL && info_ptr != NULL &&
1268 (info_ptr->valid & PNG_INFO_acTL) &&
1269 num_frames != NULL && num_plays != NULL)
1271 *num_frames = info_ptr->num_frames;
1272 *num_plays = info_ptr->num_plays;
1280 png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
1282 png_debug(1, "in png_get_num_frames()");
1284 if (png_ptr != NULL && info_ptr != NULL)
1285 return (info_ptr->num_frames);
1290 png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
1292 png_debug(1, "in png_get_num_plays()");
1294 if (png_ptr != NULL && info_ptr != NULL)
1295 return (info_ptr->num_plays);
1300 png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
1301 png_uint_32 *width, png_uint_32 *height,
1302 png_uint_32 *x_offset, png_uint_32 *y_offset,
1303 png_uint_16 *delay_num, png_uint_16 *delay_den,
1304 png_byte *dispose_op, png_byte *blend_op)
1306 png_debug1(1, "in %s retrieval function", "fcTL");
1308 if (png_ptr != NULL && info_ptr != NULL &&
1309 (info_ptr->valid & PNG_INFO_fcTL) &&
1310 width != NULL && height != NULL &&
1311 x_offset != NULL && y_offset != NULL &&
1312 delay_num != NULL && delay_den != NULL &&
1313 dispose_op != NULL && blend_op != NULL)
1315 *width = info_ptr->next_frame_width;
1316 *height = info_ptr->next_frame_height;
1317 *x_offset = info_ptr->next_frame_x_offset;
1318 *y_offset = info_ptr->next_frame_y_offset;
1319 *delay_num = info_ptr->next_frame_delay_num;
1320 *delay_den = info_ptr->next_frame_delay_den;
1321 *dispose_op = info_ptr->next_frame_dispose_op;
1322 *blend_op = info_ptr->next_frame_blend_op;
1330 png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
1332 png_debug(1, "in png_get_next_frame_width()");
1334 if (png_ptr != NULL && info_ptr != NULL)
1335 return (info_ptr->next_frame_width);
1340 png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
1342 png_debug(1, "in png_get_next_frame_height()");
1344 if (png_ptr != NULL && info_ptr != NULL)
1345 return (info_ptr->next_frame_height);
1350 png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
1352 png_debug(1, "in png_get_next_frame_x_offset()");
1354 if (png_ptr != NULL && info_ptr != NULL)
1355 return (info_ptr->next_frame_x_offset);
1360 png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
1362 png_debug(1, "in png_get_next_frame_y_offset()");
1364 if (png_ptr != NULL && info_ptr != NULL)
1365 return (info_ptr->next_frame_y_offset);
1370 png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
1372 png_debug(1, "in png_get_next_frame_delay_num()");
1374 if (png_ptr != NULL && info_ptr != NULL)
1375 return (info_ptr->next_frame_delay_num);
1380 png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
1382 png_debug(1, "in png_get_next_frame_delay_den()");
1384 if (png_ptr != NULL && info_ptr != NULL)
1385 return (info_ptr->next_frame_delay_den);
1390 png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
1392 png_debug(1, "in png_get_next_frame_dispose_op()");
1394 if (png_ptr != NULL && info_ptr != NULL)
1395 return (info_ptr->next_frame_dispose_op);
1400 png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
1402 png_debug(1, "in png_get_next_frame_blend_op()");
1404 if (png_ptr != NULL && info_ptr != NULL)
1405 return (info_ptr->next_frame_blend_op);
1410 png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
1412 png_debug(1, "in png_first_frame_is_hidden()");
1414 if (png_ptr != NULL)
1415 return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
1417 PNG_UNUSED(info_ptr)
1421 #endif /* PNG_APNG_SUPPORTED */
1422 #endif /* READ || WRITE */