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
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
)
24 return(info_ptr
->valid
& flag
);
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
);
38 #ifdef PNG_INFO_IMAGE_SUPPORTED
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
);
49 #ifdef PNG_EASY_ACCESS_SUPPORTED
50 /* Easy access to info, added in libpng-0.99 */
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
;
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
;
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
;
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
;
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
;
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
;
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
;
115 png_get_x_pixels_per_meter(png_const_structrp png_ptr
, png_const_inforp
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
);
136 png_get_y_pixels_per_meter(png_const_structrp png_ptr
, png_const_inforp
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
);
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
);
176 #ifdef PNG_FLOATING_POINT_SUPPORTED
178 png_get_pixel_aspect_ratio(png_const_structrp png_ptr
, png_const_inforp
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
));
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
)
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
))
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
);
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
);
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
);
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
);
306 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
308 ppi_from_ppm(png_uint_32 ppm
)
311 /* The conversion is *(2.54/100), in binary (32 digits):
312 * .00000110100000001001110101001001
314 png_uint_32 t1001
, t1101
;
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 */
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,
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
));
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
));
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
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
));
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
));
388 #ifdef PNG_FLOATING_POINT_SUPPORTED
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
395 return (float)(png_get_x_offset_microns(png_ptr
, info_ptr
) * .00003937);
399 #ifdef PNG_FLOATING_POINT_SUPPORTED
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
406 return (float)(png_get_y_offset_microns(png_ptr
, info_ptr
) * .00003937);
410 #ifdef PNG_pHYs_SUPPORTED
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");
423 *res_x
= info_ptr
->x_pixels_per_unit
;
424 retval
|= PNG_INFO_pHYs
;
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
;
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);
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 */
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
);
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
);
476 #ifdef PNG_bKGD_SUPPORTED
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
);
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
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
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");
517 *white_x
= png_float(png_ptr
,
518 info_ptr
->colorspace
.end_points_xy
.whitex
, "cHRM white X");
520 *white_y
= png_float(png_ptr
,
521 info_ptr
->colorspace
.end_points_xy
.whitey
, "cHRM white Y");
523 *red_x
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.redx
,
526 *red_y
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.redy
,
529 *green_x
= png_float(png_ptr
,
530 info_ptr
->colorspace
.end_points_xy
.greenx
, "cHRM green X");
532 *green_y
= png_float(png_ptr
,
533 info_ptr
->colorspace
.end_points_xy
.greeny
, "cHRM green Y");
535 *blue_x
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.bluex
,
538 *blue_y
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_xy
.bluey
,
540 return (PNG_INFO_cHRM
);
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
,
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)");
558 *red_X
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_XYZ
.red_X
,
561 *red_Y
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_XYZ
.red_Y
,
564 *red_Z
= png_float(png_ptr
, info_ptr
->colorspace
.end_points_XYZ
.red_Z
,
567 *green_X
= png_float(png_ptr
,
568 info_ptr
->colorspace
.end_points_XYZ
.green_X
, "cHRM green X");
570 *green_Y
= png_float(png_ptr
,
571 info_ptr
->colorspace
.end_points_XYZ
.green_Y
, "cHRM green Y");
573 *green_Z
= png_float(png_ptr
,
574 info_ptr
->colorspace
.end_points_XYZ
.green_Z
, "cHRM green Z");
576 *blue_X
= png_float(png_ptr
,
577 info_ptr
->colorspace
.end_points_XYZ
.blue_X
, "cHRM blue X");
579 *blue_Y
= png_float(png_ptr
,
580 info_ptr
->colorspace
.end_points_XYZ
.blue_Y
, "cHRM blue Y");
582 *blue_Z
= png_float(png_ptr
,
583 info_ptr
->colorspace
.end_points_XYZ
.blue_Z
, "cHRM blue Z");
584 return (PNG_INFO_cHRM
);
591 # ifdef PNG_FIXED_POINT_SUPPORTED
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
);
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
))
641 *white_x
= info_ptr
->colorspace
.end_points_xy
.whitex
;
643 *white_y
= info_ptr
->colorspace
.end_points_xy
.whitey
;
645 *red_x
= info_ptr
->colorspace
.end_points_xy
.redx
;
647 *red_y
= info_ptr
->colorspace
.end_points_xy
.redy
;
649 *green_x
= info_ptr
->colorspace
.end_points_xy
.greenx
;
651 *green_y
= info_ptr
->colorspace
.end_points_xy
.greeny
;
653 *blue_x
= info_ptr
->colorspace
.end_points_xy
.bluex
;
655 *blue_y
= info_ptr
->colorspace
.end_points_xy
.bluey
;
656 return (PNG_INFO_cHRM
);
664 #ifdef PNG_gAMA_SUPPORTED
665 # ifdef PNG_FIXED_POINT_SUPPORTED
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
) &&
676 *file_gamma
= info_ptr
->colorspace
.gamma
;
677 return (PNG_INFO_gAMA
);
684 # ifdef PNG_FLOATING_POINT_SUPPORTED
686 png_get_gAMA(png_const_structrp png_ptr
, png_const_inforp info_ptr
,
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
) &&
695 *file_gamma
= png_float(png_ptr
, info_ptr
->colorspace
.gamma
,
697 return (PNG_INFO_gAMA
);
705 #ifdef PNG_sRGB_SUPPORTED
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
);
723 #ifdef PNG_iCCP_SUPPORTED
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
&&
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
);
749 #ifdef PNG_sPLT_SUPPORTED
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
;
764 #ifdef PNG_hIST_SUPPORTED
766 png_get_hIST(png_const_structrp png_ptr
, png_inforp info_ptr
,
769 png_debug1(1, "in %s retrieval function", "hIST");
771 if (png_ptr
!= NULL
&& info_ptr
!= NULL
&& (info_ptr
->valid
& PNG_INFO_hIST
)
774 *hist
= info_ptr
->hist
;
775 return (PNG_INFO_hIST
);
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
,
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
)
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
);
820 #ifdef PNG_oFFs_SUPPORTED
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
);
840 #ifdef PNG_pCAL_SUPPORTED
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
);
866 #ifdef PNG_sCAL_SUPPORTED
867 # ifdef PNG_FIXED_POINT_SUPPORTED
868 # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
869 defined(PNG_FLOATING_POINT_SUPPORTED)
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
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
),
885 return (PNG_INFO_sCAL
);
890 # endif /* FLOATING_ARITHMETIC */
891 # endif /* FIXED_POINT */
892 # ifdef PNG_FLOATING_POINT_SUPPORTED
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
);
908 # endif /* FLOATING POINT */
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
);
926 #ifdef PNG_pHYs_SUPPORTED
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
))
940 *res_x
= info_ptr
->x_pixels_per_unit
;
941 retval
|= PNG_INFO_pHYs
;
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
;
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
)
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
);
979 #ifdef PNG_sBIT_SUPPORTED
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
)
989 *sig_bit
= &(info_ptr
->sig_bit
);
990 return (PNG_INFO_sBIT
);
997 #ifdef PNG_TEXT_SUPPORTED
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
)
1023 #ifdef PNG_tIME_SUPPORTED
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
);
1041 #ifdef PNG_tRNS_SUPPORTED
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
;
1086 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
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
;
1101 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
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);
1109 #ifdef PNG_USER_CHUNKS_SUPPORTED
1111 png_get_user_chunk_ptr(png_const_structrp png_ptr
)
1113 return (png_ptr
? png_ptr
->user_chunk_ptr
: NULL
);
1118 png_get_compression_buffer_size(png_const_structrp png_ptr
)
1120 if (png_ptr
== NULL
)
1123 # ifdef PNG_WRITE_SUPPORTED
1124 if (png_ptr
->mode
& PNG_IS_READ_STRUCT
)
1127 # ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1128 return png_ptr
->IDAT_read_size
;
1130 return PNG_IDAT_READ_SIZE
;
1134 # ifdef PNG_WRITE_SUPPORTED
1136 return png_ptr
->zbuffer_size
;
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 */
1144 png_get_user_width_max (png_const_structrp png_ptr
)
1146 return (png_ptr
? png_ptr
->user_width_max
: 0);
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 */
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
1173 png_get_io_state (png_const_structrp png_ptr
)
1175 return png_ptr
->io_state
;
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
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
;
1198 #ifdef PNG_APNG_SUPPORTED
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
;
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
);
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
);
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
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
)
1359 #endif /* PNG_APNG_SUPPORTED */
1360 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */