VirtualBox

source: vbox/trunk/src/libs/libpng-1.6.43/pngget.c@ 106877

Last change on this file since 106877 was 103316, checked in by vboxsync, 10 months ago

libpng-1.6.42: Applied and adjusted our libpng changes to 1.6.42. bugref:8515

  • Property svn:eol-style set to native
File size: 33.4 KB
Line 
1
2/* pngget.c - retrieval of values from info struct
3 *
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.
8 *
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
12 *
13 */
14
15#include "pngpriv.h"
16
17#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
18
19png_uint_32 PNGAPI
20png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
21 png_uint_32 flag)
22{
23 if (png_ptr != NULL && info_ptr != NULL)
24 {
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.
29 */
30 if (flag == PNG_INFO_tRNS && png_ptr->num_trans == 0)
31 return 0;
32#endif
33
34 return info_ptr->valid & flag;
35 }
36
37 return 0;
38}
39
40size_t PNGAPI
41png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
42{
43 if (png_ptr != NULL && info_ptr != NULL)
44 return info_ptr->rowbytes;
45
46 return 0;
47}
48
49#ifdef PNG_INFO_IMAGE_SUPPORTED
50png_bytepp PNGAPI
51png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
52{
53 if (png_ptr != NULL && info_ptr != NULL)
54 return info_ptr->row_pointers;
55
56 return 0;
57}
58#endif
59
60#ifdef PNG_EASY_ACCESS_SUPPORTED
61/* Easy access to info, added in libpng-0.99 */
62png_uint_32 PNGAPI
63png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
64{
65 if (png_ptr != NULL && info_ptr != NULL)
66 return info_ptr->width;
67
68 return 0;
69}
70
71png_uint_32 PNGAPI
72png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
73{
74 if (png_ptr != NULL && info_ptr != NULL)
75 return info_ptr->height;
76
77 return 0;
78}
79
80png_byte PNGAPI
81png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
82{
83 if (png_ptr != NULL && info_ptr != NULL)
84 return info_ptr->bit_depth;
85
86 return 0;
87}
88
89png_byte PNGAPI
90png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
91{
92 if (png_ptr != NULL && info_ptr != NULL)
93 return info_ptr->color_type;
94
95 return 0;
96}
97
98png_byte PNGAPI
99png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
100{
101 if (png_ptr != NULL && info_ptr != NULL)
102 return info_ptr->filter_type;
103
104 return 0;
105}
106
107png_byte PNGAPI
108png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
109{
110 if (png_ptr != NULL && info_ptr != NULL)
111 return info_ptr->interlace_type;
112
113 return 0;
114}
115
116png_byte PNGAPI
117png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
118{
119 if (png_ptr != NULL && info_ptr != NULL)
120 return info_ptr->compression_type;
121
122 return 0;
123}
124
125png_uint_32 PNGAPI
126png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
127 info_ptr)
128{
129#ifdef PNG_pHYs_SUPPORTED
130 png_debug(1, "in png_get_x_pixels_per_meter");
131
132 if (png_ptr != NULL && info_ptr != NULL &&
133 (info_ptr->valid & PNG_INFO_pHYs) != 0)
134 {
135 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
136 return info_ptr->x_pixels_per_unit;
137 }
138#else
139 PNG_UNUSED(png_ptr)
140 PNG_UNUSED(info_ptr)
141#endif
142
143 return 0;
144}
145
146png_uint_32 PNGAPI
147png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
148 info_ptr)
149{
150#ifdef PNG_pHYs_SUPPORTED
151 png_debug(1, "in png_get_y_pixels_per_meter");
152
153 if (png_ptr != NULL && info_ptr != NULL &&
154 (info_ptr->valid & PNG_INFO_pHYs) != 0)
155 {
156 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
157 return info_ptr->y_pixels_per_unit;
158 }
159#else
160 PNG_UNUSED(png_ptr)
161 PNG_UNUSED(info_ptr)
162#endif
163
164 return 0;
165}
166
167png_uint_32 PNGAPI
168png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
169{
170#ifdef PNG_pHYs_SUPPORTED
171 png_debug(1, "in png_get_pixels_per_meter");
172
173 if (png_ptr != NULL && info_ptr != NULL &&
174 (info_ptr->valid & PNG_INFO_pHYs) != 0)
175 {
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;
179 }
180#else
181 PNG_UNUSED(png_ptr)
182 PNG_UNUSED(info_ptr)
183#endif
184
185 return 0;
186}
187
188#ifdef PNG_FLOATING_POINT_SUPPORTED
189float PNGAPI
190png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
191 info_ptr)
192{
193#ifdef PNG_READ_pHYs_SUPPORTED
194 png_debug(1, "in png_get_pixel_aspect_ratio");
195
196 if (png_ptr != NULL && info_ptr != NULL &&
197 (info_ptr->valid & PNG_INFO_pHYs) != 0)
198 {
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;
202 }
203#else
204 PNG_UNUSED(png_ptr)
205 PNG_UNUSED(info_ptr)
206#endif
207
208 return (float)0.0;
209}
210#endif
211
212#ifdef PNG_FIXED_POINT_SUPPORTED
213png_fixed_point PNGAPI
214png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
215 png_const_inforp info_ptr)
216{
217#ifdef PNG_READ_pHYs_SUPPORTED
218 png_debug(1, "in png_get_pixel_aspect_ratio_fixed");
219
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)
225 {
226 png_fixed_point res;
227
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.
230 */
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)
233 return res;
234 }
235#else
236 PNG_UNUSED(png_ptr)
237 PNG_UNUSED(info_ptr)
238#endif
239
240 return 0;
241}
242#endif
243
244png_int_32 PNGAPI
245png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
246{
247#ifdef PNG_oFFs_SUPPORTED
248 png_debug(1, "in png_get_x_offset_microns");
249
250 if (png_ptr != NULL && info_ptr != NULL &&
251 (info_ptr->valid & PNG_INFO_oFFs) != 0)
252 {
253 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
254 return info_ptr->x_offset;
255 }
256#else
257 PNG_UNUSED(png_ptr)
258 PNG_UNUSED(info_ptr)
259#endif
260
261 return 0;
262}
263
264png_int_32 PNGAPI
265png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
266{
267#ifdef PNG_oFFs_SUPPORTED
268 png_debug(1, "in png_get_y_offset_microns");
269
270 if (png_ptr != NULL && info_ptr != NULL &&
271 (info_ptr->valid & PNG_INFO_oFFs) != 0)
272 {
273 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
274 return info_ptr->y_offset;
275 }
276#else
277 PNG_UNUSED(png_ptr)
278 PNG_UNUSED(info_ptr)
279#endif
280
281 return 0;
282}
283
284png_int_32 PNGAPI
285png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
286{
287#ifdef PNG_oFFs_SUPPORTED
288 png_debug(1, "in png_get_x_offset_pixels");
289
290 if (png_ptr != NULL && info_ptr != NULL &&
291 (info_ptr->valid & PNG_INFO_oFFs) != 0)
292 {
293 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
294 return info_ptr->x_offset;
295 }
296#else
297 PNG_UNUSED(png_ptr)
298 PNG_UNUSED(info_ptr)
299#endif
300
301 return 0;
302}
303
304png_int_32 PNGAPI
305png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
306{
307#ifdef PNG_oFFs_SUPPORTED
308 png_debug(1, "in png_get_y_offset_pixels");
309
310 if (png_ptr != NULL && info_ptr != NULL &&
311 (info_ptr->valid & PNG_INFO_oFFs) != 0)
312 {
313 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
314 return info_ptr->y_offset;
315 }
316#else
317 PNG_UNUSED(png_ptr)
318 PNG_UNUSED(info_ptr)
319#endif
320
321 return 0;
322}
323
324#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
325static png_uint_32
326ppi_from_ppm(png_uint_32 ppm)
327{
328#if 0
329 /* The conversion is *(2.54/100), in binary (32 digits):
330 * .00000110100000001001110101001001
331 */
332 png_uint_32 t1001, t1101;
333 ppm >>= 1; /* .1 */
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 */
343#else
344 /* The argument is a PNG unsigned integer, so it is not permitted
345 * to be bigger than 2^31.
346 */
347 png_fixed_point result;
348 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
349 5000) != 0)
350 return (png_uint_32)result;
351
352 /* Overflow. */
353 return 0;
354#endif
355}
356
357png_uint_32 PNGAPI
358png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
359{
360 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
361}
362
363png_uint_32 PNGAPI
364png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
365{
366 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
367}
368
369png_uint_32 PNGAPI
370png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
371{
372 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
373}
374
375#ifdef PNG_FIXED_POINT_SUPPORTED
376static png_fixed_point
377png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
378{
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
382 * returned.
383 */
384 return png_muldiv_warn(png_ptr, microns, 500, 127);
385}
386
387png_fixed_point PNGAPI
388png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
389 png_const_inforp info_ptr)
390{
391 return png_fixed_inches_from_microns(png_ptr,
392 png_get_x_offset_microns(png_ptr, info_ptr));
393}
394#endif
395
396#ifdef PNG_FIXED_POINT_SUPPORTED
397png_fixed_point PNGAPI
398png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
399 png_const_inforp info_ptr)
400{
401 return png_fixed_inches_from_microns(png_ptr,
402 png_get_y_offset_microns(png_ptr, info_ptr));
403}
404#endif
405
406#ifdef PNG_FLOATING_POINT_SUPPORTED
407float PNGAPI
408png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
409{
410 /* To avoid the overflow do the conversion directly in floating
411 * point.
412 */
413 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
414}
415#endif
416
417#ifdef PNG_FLOATING_POINT_SUPPORTED
418float PNGAPI
419png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
420{
421 /* To avoid the overflow do the conversion directly in floating
422 * point.
423 */
424 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
425}
426#endif
427
428#ifdef PNG_pHYs_SUPPORTED
429png_uint_32 PNGAPI
430png_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)
432{
433 png_uint_32 retval = 0;
434
435 png_debug1(1, "in %s retrieval function", "pHYs");
436
437 if (png_ptr != NULL && info_ptr != NULL &&
438 (info_ptr->valid & PNG_INFO_pHYs) != 0)
439 {
440 if (res_x != NULL)
441 {
442 *res_x = info_ptr->x_pixels_per_unit;
443 retval |= PNG_INFO_pHYs;
444 }
445
446 if (res_y != NULL)
447 {
448 *res_y = info_ptr->y_pixels_per_unit;
449 retval |= PNG_INFO_pHYs;
450 }
451
452 if (unit_type != NULL)
453 {
454 *unit_type = (int)info_ptr->phys_unit_type;
455 retval |= PNG_INFO_pHYs;
456
457 if (*unit_type == 1)
458 {
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);
461 }
462 }
463 }
464
465 return retval;
466}
467#endif /* pHYs */
468#endif /* INCH_CONVERSIONS */
469
470/* png_get_channels really belongs in here, too, but it's been around longer */
471
472#endif /* EASY_ACCESS */
473
474
475png_byte PNGAPI
476png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
477{
478 if (png_ptr != NULL && info_ptr != NULL)
479 return info_ptr->channels;
480
481 return 0;
482}
483
484#ifdef PNG_READ_SUPPORTED
485png_const_bytep PNGAPI
486png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
487{
488 if (png_ptr != NULL && info_ptr != NULL)
489 return info_ptr->signature;
490
491 return NULL;
492}
493#endif
494
495#ifdef PNG_bKGD_SUPPORTED
496png_uint_32 PNGAPI
497png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
498 png_color_16p *background)
499{
500 png_debug1(1, "in %s retrieval function", "bKGD");
501
502 if (png_ptr != NULL && info_ptr != NULL &&
503 (info_ptr->valid & PNG_INFO_bKGD) != 0 &&
504 background != NULL)
505 {
506 *background = &(info_ptr->background);
507 return PNG_INFO_bKGD;
508 }
509
510 return 0;
511}
512#endif
513
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
518 */
519# ifdef PNG_FLOATING_POINT_SUPPORTED
520png_uint_32 PNGAPI
521png_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)
524{
525 png_debug1(1, "in %s retrieval function", "cHRM");
526
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.
532 */
533 if (png_ptr != NULL && info_ptr != NULL &&
534 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
535 {
536 if (white_x != NULL)
537 *white_x = png_float(png_ptr,
538 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
539 if (white_y != NULL)
540 *white_y = png_float(png_ptr,
541 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
542 if (red_x != NULL)
543 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
544 "cHRM red X");
545 if (red_y != NULL)
546 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
547 "cHRM red Y");
548 if (green_x != NULL)
549 *green_x = png_float(png_ptr,
550 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
551 if (green_y != NULL)
552 *green_y = png_float(png_ptr,
553 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
554 if (blue_x != NULL)
555 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
556 "cHRM blue X");
557 if (blue_y != NULL)
558 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
559 "cHRM blue Y");
560 return PNG_INFO_cHRM;
561 }
562
563 return 0;
564}
565
566png_uint_32 PNGAPI
567png_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,
570 double *blue_Z)
571{
572 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
573
574 if (png_ptr != NULL && info_ptr != NULL &&
575 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
576 {
577 if (red_X != NULL)
578 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
579 "cHRM red X");
580 if (red_Y != NULL)
581 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
582 "cHRM red Y");
583 if (red_Z != NULL)
584 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
585 "cHRM red Z");
586 if (green_X != NULL)
587 *green_X = png_float(png_ptr,
588 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
589 if (green_Y != NULL)
590 *green_Y = png_float(png_ptr,
591 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
592 if (green_Z != NULL)
593 *green_Z = png_float(png_ptr,
594 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
595 if (blue_X != NULL)
596 *blue_X = png_float(png_ptr,
597 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
598 if (blue_Y != NULL)
599 *blue_Y = png_float(png_ptr,
600 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
601 if (blue_Z != NULL)
602 *blue_Z = png_float(png_ptr,
603 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
604 return PNG_INFO_cHRM;
605 }
606
607 return 0;
608}
609# endif
610
611# ifdef PNG_FIXED_POINT_SUPPORTED
612png_uint_32 PNGAPI
613png_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)
619{
620 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
621
622 if (png_ptr != NULL && info_ptr != NULL &&
623 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
624 {
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;
644 }
645
646 return 0;
647}
648
649png_uint_32 PNGAPI
650png_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)
654{
655 png_debug1(1, "in %s retrieval function", "cHRM");
656
657 if (png_ptr != NULL && info_ptr != NULL &&
658 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
659 {
660 if (white_x != NULL)
661 *white_x = info_ptr->colorspace.end_points_xy.whitex;
662 if (white_y != NULL)
663 *white_y = info_ptr->colorspace.end_points_xy.whitey;
664 if (red_x != NULL)
665 *red_x = info_ptr->colorspace.end_points_xy.redx;
666 if (red_y != NULL)
667 *red_y = info_ptr->colorspace.end_points_xy.redy;
668 if (green_x != NULL)
669 *green_x = info_ptr->colorspace.end_points_xy.greenx;
670 if (green_y != NULL)
671 *green_y = info_ptr->colorspace.end_points_xy.greeny;
672 if (blue_x != NULL)
673 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
674 if (blue_y != NULL)
675 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
676 return PNG_INFO_cHRM;
677 }
678
679 return 0;
680}
681# endif
682#endif
683
684#ifdef PNG_gAMA_SUPPORTED
685# ifdef PNG_FIXED_POINT_SUPPORTED
686png_uint_32 PNGAPI
687png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
688 png_fixed_point *file_gamma)
689{
690 png_debug1(1, "in %s retrieval function", "gAMA");
691
692 if (png_ptr != NULL && info_ptr != NULL &&
693 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
694 file_gamma != NULL)
695 {
696 *file_gamma = info_ptr->colorspace.gamma;
697 return PNG_INFO_gAMA;
698 }
699
700 return 0;
701}
702# endif
703
704# ifdef PNG_FLOATING_POINT_SUPPORTED
705png_uint_32 PNGAPI
706png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
707 double *file_gamma)
708{
709 png_debug1(1, "in %s retrieval function", "gAMA(float)");
710
711 if (png_ptr != NULL && info_ptr != NULL &&
712 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
713 file_gamma != NULL)
714 {
715 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
716 "png_get_gAMA");
717 return PNG_INFO_gAMA;
718 }
719
720 return 0;
721}
722# endif
723#endif
724
725#ifdef PNG_sRGB_SUPPORTED
726png_uint_32 PNGAPI
727png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
728 int *file_srgb_intent)
729{
730 png_debug1(1, "in %s retrieval function", "sRGB");
731
732 if (png_ptr != NULL && info_ptr != NULL &&
733 (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
734 {
735 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
736 return PNG_INFO_sRGB;
737 }
738
739 return 0;
740}
741#endif
742
743#ifdef PNG_iCCP_SUPPORTED
744png_uint_32 PNGAPI
745png_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)
748{
749 png_debug1(1, "in %s retrieval function", "iCCP");
750
751 if (png_ptr != NULL && info_ptr != NULL &&
752 (info_ptr->valid & PNG_INFO_iCCP) != 0 &&
753 name != NULL && profile != NULL && proflen != NULL)
754 {
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.
760 */
761 if (compression_type != NULL)
762 *compression_type = PNG_COMPRESSION_TYPE_BASE;
763 return PNG_INFO_iCCP;
764 }
765
766 return 0;
767
768}
769#endif
770
771#ifdef PNG_sPLT_SUPPORTED
772int PNGAPI
773png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
774 png_sPLT_tpp spalettes)
775{
776 png_debug1(1, "in %s retrieval function", "sPLT");
777
778 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
779 {
780 *spalettes = info_ptr->splt_palettes;
781 return info_ptr->splt_palettes_num;
782 }
783
784 return 0;
785}
786#endif
787
788#ifdef PNG_eXIf_SUPPORTED
789png_uint_32 PNGAPI
790png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
791 png_bytep *exif)
792{
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;
797}
798
799png_uint_32 PNGAPI
800png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
801 png_uint_32 *num_exif, png_bytep *exif)
802{
803 png_debug1(1, "in %s retrieval function", "eXIf");
804
805 if (png_ptr != NULL && info_ptr != NULL &&
806 (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
807 {
808 *num_exif = info_ptr->num_exif;
809 *exif = info_ptr->exif;
810 return PNG_INFO_eXIf;
811 }
812
813 return 0;
814}
815#endif
816
817#ifdef PNG_hIST_SUPPORTED
818png_uint_32 PNGAPI
819png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
820 png_uint_16p *hist)
821{
822 png_debug1(1, "in %s retrieval function", "hIST");
823
824 if (png_ptr != NULL && info_ptr != NULL &&
825 (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
826 {
827 *hist = info_ptr->hist;
828 return PNG_INFO_hIST;
829 }
830
831 return 0;
832}
833#endif
834
835png_uint_32 PNGAPI
836png_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)
840{
841 png_debug1(1, "in %s retrieval function", "IHDR");
842
843 if (png_ptr == NULL || info_ptr == NULL)
844 return 0;
845
846 if (width != NULL)
847 *width = info_ptr->width;
848
849 if (height != NULL)
850 *height = info_ptr->height;
851
852 if (bit_depth != NULL)
853 *bit_depth = info_ptr->bit_depth;
854
855 if (color_type != NULL)
856 *color_type = info_ptr->color_type;
857
858 if (compression_type != NULL)
859 *compression_type = info_ptr->compression_type;
860
861 if (filter_type != NULL)
862 *filter_type = info_ptr->filter_type;
863
864 if (interlace_type != NULL)
865 *interlace_type = info_ptr->interlace_type;
866
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.
871 */
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);
875
876 return 1;
877}
878
879#ifdef PNG_oFFs_SUPPORTED
880png_uint_32 PNGAPI
881png_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)
883{
884 png_debug1(1, "in %s retrieval function", "oFFs");
885
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)
889 {
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;
894 }
895
896 return 0;
897}
898#endif
899
900#ifdef PNG_pCAL_SUPPORTED
901png_uint_32 PNGAPI
902png_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)
905{
906 png_debug1(1, "in %s retrieval function", "pCAL");
907
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)
912 {
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;
921 }
922
923 return 0;
924}
925#endif
926
927#ifdef PNG_sCAL_SUPPORTED
928# ifdef PNG_FIXED_POINT_SUPPORTED
929# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
930 defined(PNG_FLOATING_POINT_SUPPORTED)
931png_uint_32 PNGAPI
932png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
933 int *unit, png_fixed_point *width, png_fixed_point *height)
934{
935 png_debug1(1, "in %s retrieval function", "sCAL");
936
937 if (png_ptr != NULL && info_ptr != NULL &&
938 (info_ptr->valid & PNG_INFO_sCAL) != 0)
939 {
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
943 * are enabled.
944 */
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),
947 "sCAL height");
948 return PNG_INFO_sCAL;
949 }
950
951 return 0;
952}
953# endif /* FLOATING_ARITHMETIC */
954# endif /* FIXED_POINT */
955# ifdef PNG_FLOATING_POINT_SUPPORTED
956png_uint_32 PNGAPI
957png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
958 int *unit, double *width, double *height)
959{
960 png_debug1(1, "in %s retrieval function", "sCAL(float)");
961
962 if (png_ptr != NULL && info_ptr != NULL &&
963 (info_ptr->valid & PNG_INFO_sCAL) != 0)
964 {
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;
969 }
970
971 return 0;
972}
973# endif /* FLOATING POINT */
974png_uint_32 PNGAPI
975png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
976 int *unit, png_charpp width, png_charpp height)
977{
978 png_debug1(1, "in %s retrieval function", "sCAL(str)");
979
980 if (png_ptr != NULL && info_ptr != NULL &&
981 (info_ptr->valid & PNG_INFO_sCAL) != 0)
982 {
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;
987 }
988
989 return 0;
990}
991#endif /* sCAL */
992
993#ifdef PNG_pHYs_SUPPORTED
994png_uint_32 PNGAPI
995png_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)
997{
998 png_uint_32 retval = 0;
999
1000 png_debug1(1, "in %s retrieval function", "pHYs");
1001
1002 if (png_ptr != NULL && info_ptr != NULL &&
1003 (info_ptr->valid & PNG_INFO_pHYs) != 0)
1004 {
1005 if (res_x != NULL)
1006 {
1007 *res_x = info_ptr->x_pixels_per_unit;
1008 retval |= PNG_INFO_pHYs;
1009 }
1010
1011 if (res_y != NULL)
1012 {
1013 *res_y = info_ptr->y_pixels_per_unit;
1014 retval |= PNG_INFO_pHYs;
1015 }
1016
1017 if (unit_type != NULL)
1018 {
1019 *unit_type = (int)info_ptr->phys_unit_type;
1020 retval |= PNG_INFO_pHYs;
1021 }
1022 }
1023
1024 return retval;
1025}
1026#endif /* pHYs */
1027
1028png_uint_32 PNGAPI
1029png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
1030 png_colorp *palette, int *num_palette)
1031{
1032 png_debug1(1, "in %s retrieval function", "PLTE");
1033
1034 if (png_ptr != NULL && info_ptr != NULL &&
1035 (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
1036 {
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;
1041 }
1042
1043 return 0;
1044}
1045
1046#ifdef PNG_sBIT_SUPPORTED
1047png_uint_32 PNGAPI
1048png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
1049 png_color_8p *sig_bit)
1050{
1051 png_debug1(1, "in %s retrieval function", "sBIT");
1052
1053 if (png_ptr != NULL && info_ptr != NULL &&
1054 (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
1055 {
1056 *sig_bit = &(info_ptr->sig_bit);
1057 return PNG_INFO_sBIT;
1058 }
1059
1060 return 0;
1061}
1062#endif
1063
1064#ifdef PNG_TEXT_SUPPORTED
1065int PNGAPI
1066png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
1067 png_textp *text_ptr, int *num_text)
1068{
1069 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
1070 {
1071 png_debug1(1, "in text retrieval function, chunk typeid = 0x%lx",
1072 (unsigned long)png_ptr->chunk_name);
1073
1074 if (text_ptr != NULL)
1075 *text_ptr = info_ptr->text;
1076
1077 if (num_text != NULL)
1078 *num_text = info_ptr->num_text;
1079
1080 return info_ptr->num_text;
1081 }
1082
1083 if (num_text != NULL)
1084 *num_text = 0;
1085
1086 return 0;
1087}
1088#endif
1089
1090#ifdef PNG_tIME_SUPPORTED
1091png_uint_32 PNGAPI
1092png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1093 png_timep *mod_time)
1094{
1095 png_debug1(1, "in %s retrieval function", "tIME");
1096
1097 if (png_ptr != NULL && info_ptr != NULL &&
1098 (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
1099 {
1100 *mod_time = &(info_ptr->mod_time);
1101 return PNG_INFO_tIME;
1102 }
1103
1104 return 0;
1105}
1106#endif
1107
1108#ifdef PNG_tRNS_SUPPORTED
1109png_uint_32 PNGAPI
1110png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
1111 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
1112{
1113 png_uint_32 retval = 0;
1114
1115 png_debug1(1, "in %s retrieval function", "tRNS");
1116
1117 if (png_ptr != NULL && info_ptr != NULL &&
1118 (info_ptr->valid & PNG_INFO_tRNS) != 0)
1119 {
1120 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1121 {
1122 if (trans_alpha != NULL)
1123 {
1124 *trans_alpha = info_ptr->trans_alpha;
1125 retval |= PNG_INFO_tRNS;
1126 }
1127
1128 if (trans_color != NULL)
1129 *trans_color = &(info_ptr->trans_color);
1130 }
1131
1132 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1133 {
1134 if (trans_color != NULL)
1135 {
1136 *trans_color = &(info_ptr->trans_color);
1137 retval |= PNG_INFO_tRNS;
1138 }
1139
1140 if (trans_alpha != NULL)
1141 *trans_alpha = NULL;
1142 }
1143
1144 if (num_trans != NULL)
1145 {
1146 *num_trans = info_ptr->num_trans;
1147 retval |= PNG_INFO_tRNS;
1148 }
1149 }
1150
1151 return retval;
1152}
1153#endif
1154
1155#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1156int PNGAPI
1157png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
1158 png_unknown_chunkpp unknowns)
1159{
1160 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1161 {
1162 *unknowns = info_ptr->unknown_chunks;
1163 return info_ptr->unknown_chunks_num;
1164 }
1165
1166 return 0;
1167}
1168#endif
1169
1170#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1171png_byte PNGAPI
1172png_get_rgb_to_gray_status(png_const_structrp png_ptr)
1173{
1174 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
1175}
1176#endif
1177
1178#ifdef PNG_USER_CHUNKS_SUPPORTED
1179png_voidp PNGAPI
1180png_get_user_chunk_ptr(png_const_structrp png_ptr)
1181{
1182 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1183}
1184#endif
1185
1186size_t PNGAPI
1187png_get_compression_buffer_size(png_const_structrp png_ptr)
1188{
1189 if (png_ptr == NULL)
1190 return 0;
1191
1192#ifdef PNG_WRITE_SUPPORTED
1193 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1194#endif
1195 {
1196#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1197 return png_ptr->IDAT_read_size;
1198#else
1199 return PNG_IDAT_READ_SIZE;
1200#endif
1201 }
1202
1203#ifdef PNG_WRITE_SUPPORTED
1204 else
1205 return png_ptr->zbuffer_size;
1206#endif
1207}
1208
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 */
1212png_uint_32 PNGAPI
1213png_get_user_width_max(png_const_structrp png_ptr)
1214{
1215 return (png_ptr ? png_ptr->user_width_max : 0);
1216}
1217
1218png_uint_32 PNGAPI
1219png_get_user_height_max(png_const_structrp png_ptr)
1220{
1221 return (png_ptr ? png_ptr->user_height_max : 0);
1222}
1223
1224/* This function was added to libpng 1.4.0 */
1225png_uint_32 PNGAPI
1226png_get_chunk_cache_max(png_const_structrp png_ptr)
1227{
1228 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1229}
1230
1231/* This function was added to libpng 1.4.1 */
1232png_alloc_size_t PNGAPI
1233png_get_chunk_malloc_max(png_const_structrp png_ptr)
1234{
1235 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1236}
1237#endif /* SET_USER_LIMITS */
1238
1239/* These functions were added to libpng 1.4.0 */
1240#ifdef PNG_IO_STATE_SUPPORTED
1241png_uint_32 PNGAPI
1242png_get_io_state(png_const_structrp png_ptr)
1243{
1244 return png_ptr->io_state;
1245}
1246
1247png_uint_32 PNGAPI
1248png_get_io_chunk_type(png_const_structrp png_ptr)
1249{
1250 return png_ptr->chunk_name;
1251}
1252#endif /* IO_STATE */
1253
1254#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1255# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1256int PNGAPI
1257png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1258{
1259 if (png_ptr != NULL && info_ptr != NULL)
1260 return png_ptr->num_palette_max;
1261
1262 return -1;
1263}
1264# endif
1265#endif
1266
1267#endif /* READ || WRITE */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette