2 /* pngget.c - retrieval of values from info struct
4 * Copyright (c) 2018-2024 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 png_debug(1, "in png_get_x_pixels_per_meter");
132 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
133 (info_ptr
->valid
& PNG_INFO_pHYs
) != 0)
135 if (info_ptr
->phys_unit_type
== PNG_RESOLUTION_METER
)
136 return info_ptr
->x_pixels_per_unit
;
147 png_get_y_pixels_per_meter(png_const_structrp png_ptr
, png_const_inforp
150 #ifdef PNG_pHYs_SUPPORTED
151 png_debug(1, "in png_get_y_pixels_per_meter");
153 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
154 (info_ptr
->valid
& PNG_INFO_pHYs
) != 0)
156 if (info_ptr
->phys_unit_type
== PNG_RESOLUTION_METER
)
157 return info_ptr
->y_pixels_per_unit
;
168 png_get_pixels_per_meter(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
170 #ifdef PNG_pHYs_SUPPORTED
171 png_debug(1, "in png_get_pixels_per_meter");
173 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
174 (info_ptr
->valid
& PNG_INFO_pHYs
) != 0)
176 if (info_ptr
->phys_unit_type
== PNG_RESOLUTION_METER
&&
177 info_ptr
->x_pixels_per_unit
== info_ptr
->y_pixels_per_unit
)
178 return info_ptr
->x_pixels_per_unit
;
188 #ifdef PNG_FLOATING_POINT_SUPPORTED
190 png_get_pixel_aspect_ratio(png_const_structrp png_ptr
, png_const_inforp
193 #ifdef PNG_READ_pHYs_SUPPORTED
194 png_debug(1, "in png_get_pixel_aspect_ratio");
196 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
197 (info_ptr
->valid
& PNG_INFO_pHYs
) != 0)
199 if (info_ptr
->x_pixels_per_unit
!= 0)
200 return (float)info_ptr
->y_pixels_per_unit
201 / (float)info_ptr
->x_pixels_per_unit
;
212 #ifdef PNG_FIXED_POINT_SUPPORTED
213 png_fixed_point PNGAPI
214 png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr
,
215 png_const_inforp info_ptr
)
217 #ifdef PNG_READ_pHYs_SUPPORTED
218 png_debug(1, "in png_get_pixel_aspect_ratio_fixed");
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 /* The following casts work because a PNG 4 byte integer only has a valid
229 * range of 0..2^31-1; otherwise the cast might overflow.
231 if (png_muldiv(&res
, (png_int_32
)info_ptr
->y_pixels_per_unit
, PNG_FP_1
,
232 (png_int_32
)info_ptr
->x_pixels_per_unit
) != 0)
245 png_get_x_offset_microns(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
247 #ifdef PNG_oFFs_SUPPORTED
248 png_debug(1, "in png_get_x_offset_microns");
250 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
251 (info_ptr
->valid
& PNG_INFO_oFFs
) != 0)
253 if (info_ptr
->offset_unit_type
== PNG_OFFSET_MICROMETER
)
254 return info_ptr
->x_offset
;
265 png_get_y_offset_microns(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
267 #ifdef PNG_oFFs_SUPPORTED
268 png_debug(1, "in png_get_y_offset_microns");
270 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
271 (info_ptr
->valid
& PNG_INFO_oFFs
) != 0)
273 if (info_ptr
->offset_unit_type
== PNG_OFFSET_MICROMETER
)
274 return info_ptr
->y_offset
;
285 png_get_x_offset_pixels(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
287 #ifdef PNG_oFFs_SUPPORTED
288 png_debug(1, "in png_get_x_offset_pixels");
290 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
291 (info_ptr
->valid
& PNG_INFO_oFFs
) != 0)
293 if (info_ptr
->offset_unit_type
== PNG_OFFSET_PIXEL
)
294 return info_ptr
->x_offset
;
305 png_get_y_offset_pixels(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
307 #ifdef PNG_oFFs_SUPPORTED
308 png_debug(1, "in png_get_y_offset_pixels");
310 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
311 (info_ptr
->valid
& PNG_INFO_oFFs
) != 0)
313 if (info_ptr
->offset_unit_type
== PNG_OFFSET_PIXEL
)
314 return info_ptr
->y_offset
;
324 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
326 ppi_from_ppm(png_uint_32 ppm
)
329 /* The conversion is *(2.54/100), in binary (32 digits):
330 * .00000110100000001001110101001001
332 png_uint_32 t1001
, t1101
;
334 t1001
= ppm
+ (ppm
>> 3); /* .1001 */
335 t1101
= t1001
+ (ppm
>> 1); /* .1101 */
336 ppm
>>= 20; /* .000000000000000000001 */
337 t1101
+= t1101
>> 15; /* .1101000000000001101 */
338 t1001
>>= 11; /* .000000000001001 */
339 t1001
+= t1001
>> 12; /* .000000000001001000000001001 */
340 ppm
+= t1001
; /* .000000000001001000001001001 */
341 ppm
+= t1101
; /* .110100000001001110101001001 */
342 return (ppm
+ 16) >> 5;/* .00000110100000001001110101001001 */
344 /* The argument is a PNG unsigned integer, so it is not permitted
345 * to be bigger than 2^31.
347 png_fixed_point result
;
348 if (ppm
<= PNG_UINT_31_MAX
&& png_muldiv(&result
, (png_int_32
)ppm
, 127,
350 return (png_uint_32
)result
;
358 png_get_pixels_per_inch(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
360 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr
, info_ptr
));
364 png_get_x_pixels_per_inch(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
366 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr
, info_ptr
));
370 png_get_y_pixels_per_inch(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
372 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr
, info_ptr
));
375 #ifdef PNG_FIXED_POINT_SUPPORTED
376 static png_fixed_point
377 png_fixed_inches_from_microns(png_const_structrp png_ptr
, png_int_32 microns
)
379 /* Convert from meters * 1,000,000 to inches * 100,000, meters to
380 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
381 * Notice that this can overflow - a warning is output and 0 is
384 return png_muldiv_warn(png_ptr
, microns
, 500, 127);
387 png_fixed_point PNGAPI
388 png_get_x_offset_inches_fixed(png_const_structrp png_ptr
,
389 png_const_inforp info_ptr
)
391 return png_fixed_inches_from_microns(png_ptr
,
392 png_get_x_offset_microns(png_ptr
, info_ptr
));
396 #ifdef PNG_FIXED_POINT_SUPPORTED
397 png_fixed_point PNGAPI
398 png_get_y_offset_inches_fixed(png_const_structrp png_ptr
,
399 png_const_inforp info_ptr
)
401 return png_fixed_inches_from_microns(png_ptr
,
402 png_get_y_offset_microns(png_ptr
, info_ptr
));
406 #ifdef PNG_FLOATING_POINT_SUPPORTED
408 png_get_x_offset_inches(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
410 /* To avoid the overflow do the conversion directly in floating
413 return (float)(png_get_x_offset_microns(png_ptr
, info_ptr
) * .00003937);
417 #ifdef PNG_FLOATING_POINT_SUPPORTED
419 png_get_y_offset_inches(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
421 /* To avoid the overflow do the conversion directly in floating
424 return (float)(png_get_y_offset_microns(png_ptr
, info_ptr
) * .00003937);
428 #ifdef PNG_pHYs_SUPPORTED
430 png_get_pHYs_dpi(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
431 png_uint_32
*res_x
, png_uint_32
*res_y
, int *unit_type
)
433 png_uint_32 retval
= 0;
435 png_debug1(1, "in %s retrieval function", "pHYs");
437 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
438 (info_ptr
->valid
& PNG_INFO_pHYs
) != 0)
442 *res_x
= info_ptr
->x_pixels_per_unit
;
443 retval
|= PNG_INFO_pHYs
;
448 *res_y
= info_ptr
->y_pixels_per_unit
;
449 retval
|= PNG_INFO_pHYs
;
452 if (unit_type
!= NULL
)
454 *unit_type
= (int)info_ptr
->phys_unit_type
;
455 retval
|= PNG_INFO_pHYs
;
459 if (res_x
!= NULL
) *res_x
= (png_uint_32
)(*res_x
* .0254 + .50);
460 if (res_y
!= NULL
) *res_y
= (png_uint_32
)(*res_y
* .0254 + .50);
468 #endif /* INCH_CONVERSIONS */
470 /* png_get_channels really belongs in here, too, but it's been around longer */
472 #endif /* EASY_ACCESS */
476 png_get_channels(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
478 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
479 return info_ptr
->channels
;
484 #ifdef PNG_READ_SUPPORTED
485 png_const_bytep PNGAPI
486 png_get_signature(png_const_structrp png_ptr
, png_const_inforp info_ptr
)
488 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
489 return info_ptr
->signature
;
495 #ifdef PNG_bKGD_SUPPORTED
497 png_get_bKGD(png_const_structrp png_ptr
, png_inforp info_ptr
,
498 png_color_16p
*background
)
500 png_debug1(1, "in %s retrieval function", "bKGD");
502 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
503 (info_ptr
->valid
& PNG_INFO_bKGD
) != 0 &&
506 *background
= &(info_ptr
->background
);
507 return PNG_INFO_bKGD
;
514 #ifdef PNG_cHRM_SUPPORTED
515 /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
516 * same time to correct the rgb grayscale coefficient defaults obtained from the
517 * cHRM chunk in 1.5.4
519 # ifdef PNG_FLOATING_POINT_SUPPORTED
521 png_get_cHRM(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
522 double *white_x
, double *white_y
, double *red_x
, double *red_y
,
523 double *green_x
, double *green_y
, double *blue_x
, double *blue_y
)
525 png_debug1(1, "in %s retrieval function", "cHRM");
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)
537 *white_x
= png_float(png_ptr
,
538 info_ptr
->colorspace
.end_points_xy
.whitex
, "cHRM white X");
540 *white_y
= png_float(png_ptr
,
541 info_ptr
->colorspace
.end_points_xy
.whitey
, "cHRM white Y");
543 *red_x
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.redx
,
546 *red_y
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.redy
,
549 *green_x
= png_float(png_ptr
,
550 info_ptr
->colorspace
.end_points_xy
.greenx
, "cHRM green X");
552 *green_y
= png_float(png_ptr
,
553 info_ptr
->colorspace
.end_points_xy
.greeny
, "cHRM green Y");
555 *blue_x
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.bluex
,
558 *blue_y
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.bluey
,
560 return PNG_INFO_cHRM
;
567 png_get_cHRM_XYZ(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
568 double *red_X
, double *red_Y
, double *red_Z
, double *green_X
,
569 double *green_Y
, double *green_Z
, double *blue_X
, double *blue_Y
,
572 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
574 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
575 (info_ptr
->colorspace
.flags
& PNG_COLORSPACE_HAVE_ENDPOINTS
) != 0)
578 *red_X
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_XYZ
.red_X
,
581 *red_Y
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_XYZ
.red_Y
,
584 *red_Z
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_XYZ
.red_Z
,
587 *green_X
= png_float(png_ptr
,
588 info_ptr
->colorspace
.end_points_XYZ
.green_X
, "cHRM green X");
590 *green_Y
= png_float(png_ptr
,
591 info_ptr
->colorspace
.end_points_XYZ
.green_Y
, "cHRM green Y");
593 *green_Z
= png_float(png_ptr
,
594 info_ptr
->colorspace
.end_points_XYZ
.green_Z
, "cHRM green Z");
596 *blue_X
= png_float(png_ptr
,
597 info_ptr
->colorspace
.end_points_XYZ
.blue_X
, "cHRM blue X");
599 *blue_Y
= png_float(png_ptr
,
600 info_ptr
->colorspace
.end_points_XYZ
.blue_Y
, "cHRM blue Y");
602 *blue_Z
= png_float(png_ptr
,
603 info_ptr
->colorspace
.end_points_XYZ
.blue_Z
, "cHRM blue Z");
604 return PNG_INFO_cHRM
;
611 # ifdef PNG_FIXED_POINT_SUPPORTED
613 png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
614 png_fixed_point
*int_red_X
, png_fixed_point
*int_red_Y
,
615 png_fixed_point
*int_red_Z
, png_fixed_point
*int_green_X
,
616 png_fixed_point
*int_green_Y
, png_fixed_point
*int_green_Z
,
617 png_fixed_point
*int_blue_X
, png_fixed_point
*int_blue_Y
,
618 png_fixed_point
*int_blue_Z
)
620 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
622 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
623 (info_ptr
->colorspace
.flags
& PNG_COLORSPACE_HAVE_ENDPOINTS
) != 0)
625 if (int_red_X
!= NULL
)
626 *int_red_X
= info_ptr
->colorspace
.end_points_XYZ
.red_X
;
627 if (int_red_Y
!= NULL
)
628 *int_red_Y
= info_ptr
->colorspace
.end_points_XYZ
.red_Y
;
629 if (int_red_Z
!= NULL
)
630 *int_red_Z
= info_ptr
->colorspace
.end_points_XYZ
.red_Z
;
631 if (int_green_X
!= NULL
)
632 *int_green_X
= info_ptr
->colorspace
.end_points_XYZ
.green_X
;
633 if (int_green_Y
!= NULL
)
634 *int_green_Y
= info_ptr
->colorspace
.end_points_XYZ
.green_Y
;
635 if (int_green_Z
!= NULL
)
636 *int_green_Z
= info_ptr
->colorspace
.end_points_XYZ
.green_Z
;
637 if (int_blue_X
!= NULL
)
638 *int_blue_X
= info_ptr
->colorspace
.end_points_XYZ
.blue_X
;
639 if (int_blue_Y
!= NULL
)
640 *int_blue_Y
= info_ptr
->colorspace
.end_points_XYZ
.blue_Y
;
641 if (int_blue_Z
!= NULL
)
642 *int_blue_Z
= info_ptr
->colorspace
.end_points_XYZ
.blue_Z
;
643 return PNG_INFO_cHRM
;
650 png_get_cHRM_fixed(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
651 png_fixed_point
*white_x
, png_fixed_point
*white_y
, png_fixed_point
*red_x
,
652 png_fixed_point
*red_y
, png_fixed_point
*green_x
, png_fixed_point
*green_y
,
653 png_fixed_point
*blue_x
, png_fixed_point
*blue_y
)
655 png_debug1(1, "in %s retrieval function", "cHRM");
657 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
658 (info_ptr
->colorspace
.flags
& PNG_COLORSPACE_HAVE_ENDPOINTS
) != 0)
661 *white_x
= info_ptr
->colorspace
.end_points_xy
.whitex
;
663 *white_y
= info_ptr
->colorspace
.end_points_xy
.whitey
;
665 *red_x
= info_ptr
->colorspace
.end_points_xy
.redx
;
667 *red_y
= info_ptr
->colorspace
.end_points_xy
.redy
;
669 *green_x
= info_ptr
->colorspace
.end_points_xy
.greenx
;
671 *green_y
= info_ptr
->colorspace
.end_points_xy
.greeny
;
673 *blue_x
= info_ptr
->colorspace
.end_points_xy
.bluex
;
675 *blue_y
= info_ptr
->colorspace
.end_points_xy
.bluey
;
676 return PNG_INFO_cHRM
;
684 #ifdef PNG_gAMA_SUPPORTED
685 # ifdef PNG_FIXED_POINT_SUPPORTED
687 png_get_gAMA_fixed(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
688 png_fixed_point
*file_gamma
)
690 png_debug1(1, "in %s retrieval function", "gAMA");
692 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
693 (info_ptr
->colorspace
.flags
& PNG_COLORSPACE_HAVE_GAMMA
) != 0 &&
696 *file_gamma
= info_ptr
->colorspace
.gamma
;
697 return PNG_INFO_gAMA
;
704 # ifdef PNG_FLOATING_POINT_SUPPORTED
706 png_get_gAMA(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
709 png_debug1(1, "in %s retrieval function", "gAMA(float)");
711 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
712 (info_ptr
->colorspace
.flags
& PNG_COLORSPACE_HAVE_GAMMA
) != 0 &&
715 *file_gamma
= png_float(png_ptr
, info_ptr
->colorspace
.gamma
,
717 return PNG_INFO_gAMA
;
725 #ifdef PNG_sRGB_SUPPORTED
727 png_get_sRGB(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
728 int *file_srgb_intent
)
730 png_debug1(1, "in %s retrieval function", "sRGB");
732 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
733 (info_ptr
->valid
& PNG_INFO_sRGB
) != 0 && file_srgb_intent
!= NULL
)
735 *file_srgb_intent
= info_ptr
->colorspace
.rendering_intent
;
736 return PNG_INFO_sRGB
;
743 #ifdef PNG_iCCP_SUPPORTED
745 png_get_iCCP(png_const_structrp png_ptr
, png_inforp info_ptr
,
746 png_charpp name
, int *compression_type
,
747 png_bytepp profile
, png_uint_32
*proflen
)
749 png_debug1(1, "in %s retrieval function", "iCCP");
751 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
752 (info_ptr
->valid
& PNG_INFO_iCCP
) != 0 &&
753 name
!= NULL
&& profile
!= NULL
&& proflen
!= NULL
)
755 *name
= info_ptr
->iccp_name
;
756 *profile
= info_ptr
->iccp_profile
;
757 *proflen
= png_get_uint_32(info_ptr
->iccp_profile
);
758 /* This is somewhat irrelevant since the profile data returned has
759 * actually been uncompressed.
761 if (compression_type
!= NULL
)
762 *compression_type
= PNG_COMPRESSION_TYPE_BASE
;
763 return PNG_INFO_iCCP
;
771 #ifdef PNG_sPLT_SUPPORTED
773 png_get_sPLT(png_const_structrp png_ptr
, png_inforp info_ptr
,
774 png_sPLT_tpp spalettes
)
776 png_debug1(1, "in %s retrieval function", "sPLT");
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 png_debug1(1, "in %s retrieval function", "sCAL");
937 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
938 (info_ptr
->valid
& PNG_INFO_sCAL
) != 0)
940 *unit
= info_ptr
->scal_unit
;
941 /*TODO: make this work without FP support; the API is currently eliminated
942 * if neither floating point APIs nor internal floating point arithmetic
945 *width
= png_fixed(png_ptr
, atof(info_ptr
->scal_s_width
), "sCAL width");
946 *height
= png_fixed(png_ptr
, atof(info_ptr
->scal_s_height
),
948 return PNG_INFO_sCAL
;
953 # endif /* FLOATING_ARITHMETIC */
954 # endif /* FIXED_POINT */
955 # ifdef PNG_FLOATING_POINT_SUPPORTED
957 png_get_sCAL(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
958 int *unit
, double *width
, double *height
)
960 png_debug1(1, "in %s retrieval function", "sCAL(float)");
962 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
963 (info_ptr
->valid
& PNG_INFO_sCAL
) != 0)
965 *unit
= info_ptr
->scal_unit
;
966 *width
= atof(info_ptr
->scal_s_width
);
967 *height
= atof(info_ptr
->scal_s_height
);
968 return PNG_INFO_sCAL
;
973 # endif /* FLOATING POINT */
975 png_get_sCAL_s(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
976 int *unit
, png_charpp width
, png_charpp height
)
978 png_debug1(1, "in %s retrieval function", "sCAL(str)");
980 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
981 (info_ptr
->valid
& PNG_INFO_sCAL
) != 0)
983 *unit
= info_ptr
->scal_unit
;
984 *width
= info_ptr
->scal_s_width
;
985 *height
= info_ptr
->scal_s_height
;
986 return PNG_INFO_sCAL
;
993 #ifdef PNG_pHYs_SUPPORTED
995 png_get_pHYs(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
996 png_uint_32
*res_x
, png_uint_32
*res_y
, int *unit_type
)
998 png_uint_32 retval
= 0;
1000 png_debug1(1, "in %s retrieval function", "pHYs");
1002 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
1003 (info_ptr
->valid
& PNG_INFO_pHYs
) != 0)
1007 *res_x
= info_ptr
->x_pixels_per_unit
;
1008 retval
|= PNG_INFO_pHYs
;
1013 *res_y
= info_ptr
->y_pixels_per_unit
;
1014 retval
|= PNG_INFO_pHYs
;
1017 if (unit_type
!= NULL
)
1019 *unit_type
= (int)info_ptr
->phys_unit_type
;
1020 retval
|= PNG_INFO_pHYs
;
1029 png_get_PLTE(png_const_structrp png_ptr
, png_inforp info_ptr
,
1030 png_colorp
*palette
, int *num_palette
)
1032 png_debug1(1, "in %s retrieval function", "PLTE");
1034 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
1035 (info_ptr
->valid
& PNG_INFO_PLTE
) != 0 && palette
!= NULL
)
1037 *palette
= info_ptr
->palette
;
1038 *num_palette
= info_ptr
->num_palette
;
1039 png_debug1(3, "num_palette = %d", *num_palette
);
1040 return PNG_INFO_PLTE
;
1046 #ifdef PNG_sBIT_SUPPORTED
1048 png_get_sBIT(png_const_structrp png_ptr
, png_inforp info_ptr
,
1049 png_color_8p
*sig_bit
)
1051 png_debug1(1, "in %s retrieval function", "sBIT");
1053 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
1054 (info_ptr
->valid
& PNG_INFO_sBIT
) != 0 && sig_bit
!= NULL
)
1056 *sig_bit
= &(info_ptr
->sig_bit
);
1057 return PNG_INFO_sBIT
;
1064 #ifdef PNG_TEXT_SUPPORTED
1066 png_get_text(png_const_structrp png_ptr
, png_inforp info_ptr
,
1067 png_textp
*text_ptr
, int *num_text
)
1069 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&& info_ptr
->num_text
> 0)
1071 png_debug1(1, "in text retrieval function, chunk typeid = 0x%lx",
1072 (unsigned long)png_ptr
->chunk_name
);
1074 if (text_ptr
!= NULL
)
1075 *text_ptr
= info_ptr
->text
;
1077 if (num_text
!= NULL
)
1078 *num_text
= info_ptr
->num_text
;
1080 return info_ptr
->num_text
;
1083 if (num_text
!= NULL
)
1090 #ifdef PNG_tIME_SUPPORTED
1092 png_get_tIME(png_const_structrp png_ptr
, png_inforp info_ptr
,
1093 png_timep
*mod_time
)
1095 png_debug1(1, "in %s retrieval function", "tIME");
1097 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
1098 (info_ptr
->valid
& PNG_INFO_tIME
) != 0 && mod_time
!= NULL
)
1100 *mod_time
= &(info_ptr
->mod_time
);
1101 return PNG_INFO_tIME
;
1108 #ifdef PNG_tRNS_SUPPORTED
1110 png_get_tRNS(png_const_structrp png_ptr
, png_inforp info_ptr
,
1111 png_bytep
*trans_alpha
, int *num_trans
, png_color_16p
*trans_color
)
1113 png_uint_32 retval
= 0;
1115 png_debug1(1, "in %s retrieval function", "tRNS");
1117 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
1118 (info_ptr
->valid
& PNG_INFO_tRNS
) != 0)
1120 if (info_ptr
->color_type
== PNG_COLOR_TYPE_PALETTE
)
1122 if (trans_alpha
!= NULL
)
1124 *trans_alpha
= info_ptr
->trans_alpha
;
1125 retval
|= PNG_INFO_tRNS
;
1128 if (trans_color
!= NULL
)
1129 *trans_color
= &(info_ptr
->trans_color
);
1132 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1134 if (trans_color
!= NULL
)
1136 *trans_color
= &(info_ptr
->trans_color
);
1137 retval
|= PNG_INFO_tRNS
;
1140 if (trans_alpha
!= NULL
)
1141 *trans_alpha
= NULL
;
1144 if (num_trans
!= NULL
)
1146 *num_trans
= info_ptr
->num_trans
;
1147 retval
|= PNG_INFO_tRNS
;
1155 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1157 png_get_unknown_chunks(png_const_structrp png_ptr
, png_inforp info_ptr
,
1158 png_unknown_chunkpp unknowns
)
1160 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&& unknowns
!= NULL
)
1162 *unknowns
= info_ptr
->unknown_chunks
;
1163 return info_ptr
->unknown_chunks_num
;
1170 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1172 png_get_rgb_to_gray_status(png_const_structrp png_ptr
)
1174 return (png_byte
)(png_ptr
? png_ptr
->rgb_to_gray_status
: 0);
1178 #ifdef PNG_USER_CHUNKS_SUPPORTED
1180 png_get_user_chunk_ptr(png_const_structrp png_ptr
)
1182 return (png_ptr
? png_ptr
->user_chunk_ptr
: NULL
);
1187 png_get_compression_buffer_size(png_const_structrp png_ptr
)
1189 if (png_ptr
== NULL
)
1192 #ifdef PNG_WRITE_SUPPORTED
1193 if ((png_ptr
->mode
& PNG_IS_READ_STRUCT
) != 0)
1196 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1197 return png_ptr
->IDAT_read_size
;
1199 return PNG_IDAT_READ_SIZE
;
1203 #ifdef PNG_WRITE_SUPPORTED
1205 return png_ptr
->zbuffer_size
;
1209 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
1210 /* These functions were added to libpng 1.2.6 and were enabled
1211 * by default in libpng-1.4.0 */
1213 png_get_user_width_max(png_const_structrp png_ptr
)
1215 return (png_ptr
? png_ptr
->user_width_max
: 0);
1219 png_get_user_height_max(png_const_structrp png_ptr
)
1221 return (png_ptr
? png_ptr
->user_height_max
: 0);
1224 /* This function was added to libpng 1.4.0 */
1226 png_get_chunk_cache_max(png_const_structrp png_ptr
)
1228 return (png_ptr
? png_ptr
->user_chunk_cache_max
: 0);
1231 /* This function was added to libpng 1.4.1 */
1232 png_alloc_size_t PNGAPI
1233 png_get_chunk_malloc_max(png_const_structrp png_ptr
)
1235 return (png_ptr
? png_ptr
->user_chunk_malloc_max
: 0);
1237 #endif /* SET_USER_LIMITS */
1239 /* These functions were added to libpng 1.4.0 */
1240 #ifdef PNG_IO_STATE_SUPPORTED
1242 png_get_io_state(png_const_structrp png_ptr
)
1244 return png_ptr
->io_state
;
1248 png_get_io_chunk_type(png_const_structrp png_ptr
)
1250 return png_ptr
->chunk_name
;
1252 #endif /* IO_STATE */
1254 #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1255 # ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1257 png_get_palette_max(png_const_structp png_ptr
, png_const_infop info_ptr
)
1259 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1260 return png_ptr
->num_palette_max
;
1267 #ifdef PNG_APNG_SUPPORTED
1269 png_get_acTL(png_structp png_ptr
, png_infop info_ptr
,
1270 png_uint_32
*num_frames
, png_uint_32
*num_plays
)
1272 png_debug1(1, "in %s retrieval function", "acTL");
1274 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
1275 (info_ptr
->valid
& PNG_INFO_acTL
) != 0 &&
1276 num_frames
!= NULL
&& num_plays
!= NULL
)
1278 *num_frames
= info_ptr
->num_frames
;
1279 *num_plays
= info_ptr
->num_plays
;
1287 png_get_num_frames(png_structp png_ptr
, png_infop info_ptr
)
1289 png_debug(1, "in png_get_num_frames()");
1291 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1292 return (info_ptr
->num_frames
);
1297 png_get_num_plays(png_structp png_ptr
, png_infop info_ptr
)
1299 png_debug(1, "in png_get_num_plays()");
1301 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1302 return (info_ptr
->num_plays
);
1307 png_get_next_frame_fcTL(png_structp png_ptr
, png_infop info_ptr
,
1308 png_uint_32
*width
, png_uint_32
*height
,
1309 png_uint_32
*x_offset
, png_uint_32
*y_offset
,
1310 png_uint_16
*delay_num
, png_uint_16
*delay_den
,
1311 png_byte
*dispose_op
, png_byte
*blend_op
)
1313 png_debug1(1, "in %s retrieval function", "fcTL");
1315 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&&
1316 (info_ptr
->valid
& PNG_INFO_fcTL
) != 0 &&
1317 width
!= NULL
&& height
!= NULL
&&
1318 x_offset
!= NULL
&& y_offset
!= NULL
&&
1319 delay_num
!= NULL
&& delay_den
!= NULL
&&
1320 dispose_op
!= NULL
&& blend_op
!= NULL
)
1322 *width
= info_ptr
->next_frame_width
;
1323 *height
= info_ptr
->next_frame_height
;
1324 *x_offset
= info_ptr
->next_frame_x_offset
;
1325 *y_offset
= info_ptr
->next_frame_y_offset
;
1326 *delay_num
= info_ptr
->next_frame_delay_num
;
1327 *delay_den
= info_ptr
->next_frame_delay_den
;
1328 *dispose_op
= info_ptr
->next_frame_dispose_op
;
1329 *blend_op
= info_ptr
->next_frame_blend_op
;
1337 png_get_next_frame_width(png_structp png_ptr
, png_infop info_ptr
)
1339 png_debug(1, "in png_get_next_frame_width()");
1341 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1342 return (info_ptr
->next_frame_width
);
1347 png_get_next_frame_height(png_structp png_ptr
, png_infop info_ptr
)
1349 png_debug(1, "in png_get_next_frame_height()");
1351 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1352 return (info_ptr
->next_frame_height
);
1357 png_get_next_frame_x_offset(png_structp png_ptr
, png_infop info_ptr
)
1359 png_debug(1, "in png_get_next_frame_x_offset()");
1361 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1362 return (info_ptr
->next_frame_x_offset
);
1367 png_get_next_frame_y_offset(png_structp png_ptr
, png_infop info_ptr
)
1369 png_debug(1, "in png_get_next_frame_y_offset()");
1371 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1372 return (info_ptr
->next_frame_y_offset
);
1377 png_get_next_frame_delay_num(png_structp png_ptr
, png_infop info_ptr
)
1379 png_debug(1, "in png_get_next_frame_delay_num()");
1381 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1382 return (info_ptr
->next_frame_delay_num
);
1387 png_get_next_frame_delay_den(png_structp png_ptr
, png_infop info_ptr
)
1389 png_debug(1, "in png_get_next_frame_delay_den()");
1391 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1392 return (info_ptr
->next_frame_delay_den
);
1397 png_get_next_frame_dispose_op(png_structp png_ptr
, png_infop info_ptr
)
1399 png_debug(1, "in png_get_next_frame_dispose_op()");
1401 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1402 return (info_ptr
->next_frame_dispose_op
);
1407 png_get_next_frame_blend_op(png_structp png_ptr
, png_infop info_ptr
)
1409 png_debug(1, "in png_get_next_frame_blend_op()");
1411 if (png_ptr
!= NULL
&& info_ptr
!= NULL
)
1412 return (info_ptr
->next_frame_blend_op
);
1417 png_get_first_frame_is_hidden(png_structp png_ptr
, png_infop info_ptr
)
1419 png_debug(1, "in png_first_frame_is_hidden()");
1421 if (png_ptr
!= NULL
)
1422 return (png_byte
)(png_ptr
->apng_flags
& PNG_FIRST_FRAME_HIDDEN
);
1424 PNG_UNUSED(info_ptr
)
1429 #endif /* READ || WRITE */