windows.storage.applicationdata: Implement IApplicationDataStatics::get_Current().
[wine.git] / libs / png / pngget.c
blob1490a032e1ade6593f45ad6a293cd60fe70c5705
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
15 #include "pngpriv.h"
17 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
19 png_uint_32 PNGAPI
20 png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
21 png_uint_32 flag)
23 if (png_ptr != NULL && info_ptr != NULL)
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)
31 return(0);
32 #endif
34 return(info_ptr->valid & flag);
37 return(0);
40 size_t PNGAPI
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);
46 return(0);
49 #ifdef PNG_INFO_IMAGE_SUPPORTED
50 png_bytepp PNGAPI
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);
56 return(0);
58 #endif
60 #ifdef PNG_EASY_ACCESS_SUPPORTED
61 /* Easy access to info, added in libpng-0.99 */
62 png_uint_32 PNGAPI
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;
68 return (0);
71 png_uint_32 PNGAPI
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;
77 return (0);
80 png_byte PNGAPI
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;
86 return (0);
89 png_byte PNGAPI
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;
95 return (0);
98 png_byte PNGAPI
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;
104 return (0);
107 png_byte PNGAPI
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;
113 return (0);
116 png_byte PNGAPI
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;
122 return (0);
125 png_uint_32 PNGAPI
126 png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
127 info_ptr)
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);
139 #else
140 PNG_UNUSED(png_ptr)
141 PNG_UNUSED(info_ptr)
142 #endif
144 return (0);
147 png_uint_32 PNGAPI
148 png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
149 info_ptr)
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);
161 #else
162 PNG_UNUSED(png_ptr)
163 PNG_UNUSED(info_ptr)
164 #endif
166 return (0);
169 png_uint_32 PNGAPI
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);
182 #else
183 PNG_UNUSED(png_ptr)
184 PNG_UNUSED(info_ptr)
185 #endif
187 return (0);
190 #ifdef PNG_FLOATING_POINT_SUPPORTED
191 float PNGAPI
192 png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
193 info_ptr)
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));
205 #else
206 PNG_UNUSED(png_ptr)
207 PNG_UNUSED(info_ptr)
208 #endif
210 return ((float)0.0);
212 #endif
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)
226 png_fixed_point res;
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)
235 return res;
237 #else
238 PNG_UNUSED(png_ptr)
239 PNG_UNUSED(info_ptr)
240 #endif
242 return 0;
244 #endif
246 png_int_32 PNGAPI
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);
258 #else
259 PNG_UNUSED(png_ptr)
260 PNG_UNUSED(info_ptr)
261 #endif
263 return (0);
266 png_int_32 PNGAPI
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);
278 #else
279 PNG_UNUSED(png_ptr)
280 PNG_UNUSED(info_ptr)
281 #endif
283 return (0);
286 png_int_32 PNGAPI
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);
298 #else
299 PNG_UNUSED(png_ptr)
300 PNG_UNUSED(info_ptr)
301 #endif
303 return (0);
306 png_int_32 PNGAPI
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);
318 #else
319 PNG_UNUSED(png_ptr)
320 PNG_UNUSED(info_ptr)
321 #endif
323 return (0);
326 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
327 static png_uint_32
328 ppi_from_ppm(png_uint_32 ppm)
330 #if 0
331 /* The conversion is *(2.54/100), in binary (32 digits):
332 * .00000110100000001001110101001001
334 png_uint_32 t1001, t1101;
335 ppm >>= 1; /* .1 */
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 */
345 #else
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,
351 5000) != 0)
352 return (png_uint_32)result;
354 /* Overflow. */
355 return 0;
356 #endif
359 png_uint_32 PNGAPI
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));
365 png_uint_32 PNGAPI
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));
371 png_uint_32 PNGAPI
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
384 * returned.
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));
396 #endif
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));
406 #endif
408 #ifdef PNG_FLOATING_POINT_SUPPORTED
409 float PNGAPI
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
413 * point.
415 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
417 #endif
419 #ifdef PNG_FLOATING_POINT_SUPPORTED
420 float PNGAPI
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
424 * point.
426 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
428 #endif
430 #ifdef PNG_pHYs_SUPPORTED
431 png_uint_32 PNGAPI
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");
442 if (res_x != NULL)
444 *res_x = info_ptr->x_pixels_per_unit;
445 retval |= PNG_INFO_pHYs;
448 if (res_y != NULL)
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;
459 if (*unit_type == 1)
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);
467 return (retval);
469 #endif /* pHYs */
470 #endif /* INCH_CONVERSIONS */
472 /* png_get_channels really belongs in here, too, but it's been around longer */
474 #endif /* EASY_ACCESS */
477 png_byte PNGAPI
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);
483 return (0);
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);
493 return (NULL);
495 #endif
497 #ifdef PNG_bKGD_SUPPORTED
498 png_uint_32 PNGAPI
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 &&
504 background != NULL)
506 png_debug1(1, "in %s retrieval function", "bKGD");
508 *background = &(info_ptr->background);
509 return (PNG_INFO_bKGD);
512 return (0);
514 #endif
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
522 png_uint_32 PNGAPI
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
531 * consistent.
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");
538 if (white_x != NULL)
539 *white_x = png_float(png_ptr,
540 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
541 if (white_y != NULL)
542 *white_y = png_float(png_ptr,
543 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
544 if (red_x != NULL)
545 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
546 "cHRM red X");
547 if (red_y != NULL)
548 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
549 "cHRM red Y");
550 if (green_x != NULL)
551 *green_x = png_float(png_ptr,
552 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
553 if (green_y != NULL)
554 *green_y = png_float(png_ptr,
555 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
556 if (blue_x != NULL)
557 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
558 "cHRM blue X");
559 if (blue_y != NULL)
560 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
561 "cHRM blue Y");
562 return (PNG_INFO_cHRM);
565 return (0);
568 png_uint_32 PNGAPI
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,
572 double *blue_Z)
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)");
579 if (red_X != NULL)
580 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
581 "cHRM red X");
582 if (red_Y != NULL)
583 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
584 "cHRM red Y");
585 if (red_Z != NULL)
586 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
587 "cHRM red Z");
588 if (green_X != NULL)
589 *green_X = png_float(png_ptr,
590 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
591 if (green_Y != NULL)
592 *green_Y = png_float(png_ptr,
593 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
594 if (green_Z != NULL)
595 *green_Z = png_float(png_ptr,
596 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
597 if (blue_X != NULL)
598 *blue_X = png_float(png_ptr,
599 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
600 if (blue_Y != NULL)
601 *blue_Y = png_float(png_ptr,
602 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
603 if (blue_Z != NULL)
604 *blue_Z = png_float(png_ptr,
605 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
606 return (PNG_INFO_cHRM);
609 return (0);
611 # endif
613 # ifdef PNG_FIXED_POINT_SUPPORTED
614 png_uint_32 PNGAPI
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);
648 return (0);
651 png_uint_32 PNGAPI
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)
662 if (white_x != NULL)
663 *white_x = info_ptr->colorspace.end_points_xy.whitex;
664 if (white_y != NULL)
665 *white_y = info_ptr->colorspace.end_points_xy.whitey;
666 if (red_x != NULL)
667 *red_x = info_ptr->colorspace.end_points_xy.redx;
668 if (red_y != NULL)
669 *red_y = info_ptr->colorspace.end_points_xy.redy;
670 if (green_x != NULL)
671 *green_x = info_ptr->colorspace.end_points_xy.greenx;
672 if (green_y != NULL)
673 *green_y = info_ptr->colorspace.end_points_xy.greeny;
674 if (blue_x != NULL)
675 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
676 if (blue_y != NULL)
677 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
678 return (PNG_INFO_cHRM);
681 return (0);
683 # endif
684 #endif
686 #ifdef PNG_gAMA_SUPPORTED
687 # ifdef PNG_FIXED_POINT_SUPPORTED
688 png_uint_32 PNGAPI
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 &&
696 file_gamma != NULL)
698 *file_gamma = info_ptr->colorspace.gamma;
699 return (PNG_INFO_gAMA);
702 return (0);
704 # endif
706 # ifdef PNG_FLOATING_POINT_SUPPORTED
707 png_uint_32 PNGAPI
708 png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
709 double *file_gamma)
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 &&
715 file_gamma != NULL)
717 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
718 "png_get_gAMA");
719 return (PNG_INFO_gAMA);
722 return (0);
724 # endif
725 #endif
727 #ifdef PNG_sRGB_SUPPORTED
728 png_uint_32 PNGAPI
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);
741 return (0);
743 #endif
745 #ifdef PNG_iCCP_SUPPORTED
746 png_uint_32 PNGAPI
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);
768 return (0);
771 #endif
773 #ifdef PNG_sPLT_SUPPORTED
774 int PNGAPI
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;
784 return (0);
786 #endif
788 #ifdef PNG_eXIf_SUPPORTED
789 png_uint_32 PNGAPI
790 png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
791 png_bytep *exif)
793 png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
794 PNG_UNUSED(info_ptr)
795 PNG_UNUSED(exif)
796 return 0;
799 png_uint_32 PNGAPI
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);
813 return (0);
815 #endif
817 #ifdef PNG_hIST_SUPPORTED
818 png_uint_32 PNGAPI
819 png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
820 png_uint_16p *hist)
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);
831 return (0);
833 #endif
835 png_uint_32 PNGAPI
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,
839 int *filter_type)
841 png_debug1(1, "in %s retrieval function", "IHDR");
843 if (png_ptr == NULL || info_ptr == NULL)
844 return (0);
846 if (width != NULL)
847 *width = info_ptr->width;
849 if (height != NULL)
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);
876 return (1);
879 #ifdef PNG_oFFs_SUPPORTED
880 png_uint_32 PNGAPI
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);
896 return (0);
898 #endif
900 #ifdef PNG_pCAL_SUPPORTED
901 png_uint_32 PNGAPI
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);
923 return (0);
925 #endif
927 #ifdef PNG_sCAL_SUPPORTED
928 # ifdef PNG_FIXED_POINT_SUPPORTED
929 # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
930 defined(PNG_FLOATING_POINT_SUPPORTED)
931 png_uint_32 PNGAPI
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
941 * are enabled.
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),
945 "sCAL height");
946 return (PNG_INFO_sCAL);
949 return(0);
951 # endif /* FLOATING_ARITHMETIC */
952 # endif /* FIXED_POINT */
953 # ifdef PNG_FLOATING_POINT_SUPPORTED
954 png_uint_32 PNGAPI
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);
967 return(0);
969 # endif /* FLOATING POINT */
970 png_uint_32 PNGAPI
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);
983 return(0);
985 #endif /* sCAL */
987 #ifdef PNG_pHYs_SUPPORTED
988 png_uint_32 PNGAPI
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)
999 if (res_x != NULL)
1001 *res_x = info_ptr->x_pixels_per_unit;
1002 retval |= PNG_INFO_pHYs;
1005 if (res_y != NULL)
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;
1018 return (retval);
1020 #endif /* pHYs */
1022 png_uint_32 PNGAPI
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);
1037 return (0);
1040 #ifdef PNG_sBIT_SUPPORTED
1041 png_uint_32 PNGAPI
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);
1054 return (0);
1056 #endif
1058 #ifdef PNG_TEXT_SUPPORTED
1059 int PNGAPI
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)
1078 *num_text = 0;
1080 return(0);
1082 #endif
1084 #ifdef PNG_tIME_SUPPORTED
1085 png_uint_32 PNGAPI
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);
1098 return (0);
1100 #endif
1102 #ifdef PNG_tRNS_SUPPORTED
1103 png_uint_32 PNGAPI
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;
1144 return (retval);
1146 #endif
1148 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1149 int PNGAPI
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;
1159 return (0);
1161 #endif
1163 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1164 png_byte PNGAPI
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);
1169 #endif
1171 #ifdef PNG_USER_CHUNKS_SUPPORTED
1172 png_voidp PNGAPI
1173 png_get_user_chunk_ptr(png_const_structrp png_ptr)
1175 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1177 #endif
1179 size_t PNGAPI
1180 png_get_compression_buffer_size(png_const_structrp png_ptr)
1182 if (png_ptr == NULL)
1183 return 0;
1185 #ifdef PNG_WRITE_SUPPORTED
1186 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1187 #endif
1189 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1190 return png_ptr->IDAT_read_size;
1191 #else
1192 return PNG_IDAT_READ_SIZE;
1193 #endif
1196 #ifdef PNG_WRITE_SUPPORTED
1197 else
1198 return png_ptr->zbuffer_size;
1199 #endif
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 */
1205 png_uint_32 PNGAPI
1206 png_get_user_width_max(png_const_structrp png_ptr)
1208 return (png_ptr ? png_ptr->user_width_max : 0);
1211 png_uint_32 PNGAPI
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 */
1218 png_uint_32 PNGAPI
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
1234 png_uint_32 PNGAPI
1235 png_get_io_state(png_const_structrp png_ptr)
1237 return png_ptr->io_state;
1240 png_uint_32 PNGAPI
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
1249 int PNGAPI
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;
1255 return (-1);
1257 # endif
1258 #endif
1260 #endif /* READ || WRITE */