VirtualBox

source: vbox/trunk/src/libs/libpng-1.6.45/pngget.c@ 107935

Last change on this file since 107935 was 107813, checked in by vboxsync, 3 weeks ago

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

  • Property svn:eol-style set to native
File size: 34.2 KB
Line 
1/* pngget.c - retrieval of values from info struct
2 *
3 * Copyright (c) 2018-2024 Cosmin Truta
4 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
5 * Copyright (c) 1996-1997 Andreas Dilger
6 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
7 *
8 * This code is released under the libpng license.
9 * For conditions of distribution and use, see the disclaimer
10 * and license in png.h
11 *
12 */
13
14#include "pngpriv.h"
15
16#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
17
18png_uint_32 PNGAPI
19png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
20 png_uint_32 flag)
21{
22 if (png_ptr != NULL && info_ptr != NULL)
23 {
24#ifdef PNG_READ_tRNS_SUPPORTED
25 /* png_handle_PLTE() may have canceled a valid tRNS chunk but left the
26 * 'valid' flag for the detection of duplicate chunks. Do not report a
27 * valid tRNS chunk in this case.
28 */
29 if (flag == PNG_INFO_tRNS && png_ptr->num_trans == 0)
30 return 0;
31#endif
32
33 return info_ptr->valid & flag;
34 }
35
36 return 0;
37}
38
39size_t PNGAPI
40png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
41{
42 if (png_ptr != NULL && info_ptr != NULL)
43 return info_ptr->rowbytes;
44
45 return 0;
46}
47
48#ifdef PNG_INFO_IMAGE_SUPPORTED
49png_bytepp PNGAPI
50png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
51{
52 if (png_ptr != NULL && info_ptr != NULL)
53 return info_ptr->row_pointers;
54
55 return 0;
56}
57#endif
58
59#ifdef PNG_EASY_ACCESS_SUPPORTED
60/* Easy access to info, added in libpng-0.99 */
61png_uint_32 PNGAPI
62png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
63{
64 if (png_ptr != NULL && info_ptr != NULL)
65 return info_ptr->width;
66
67 return 0;
68}
69
70png_uint_32 PNGAPI
71png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
72{
73 if (png_ptr != NULL && info_ptr != NULL)
74 return info_ptr->height;
75
76 return 0;
77}
78
79png_byte PNGAPI
80png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
81{
82 if (png_ptr != NULL && info_ptr != NULL)
83 return info_ptr->bit_depth;
84
85 return 0;
86}
87
88png_byte PNGAPI
89png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
90{
91 if (png_ptr != NULL && info_ptr != NULL)
92 return info_ptr->color_type;
93
94 return 0;
95}
96
97png_byte PNGAPI
98png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
99{
100 if (png_ptr != NULL && info_ptr != NULL)
101 return info_ptr->filter_type;
102
103 return 0;
104}
105
106png_byte PNGAPI
107png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
108{
109 if (png_ptr != NULL && info_ptr != NULL)
110 return info_ptr->interlace_type;
111
112 return 0;
113}
114
115png_byte PNGAPI
116png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
117{
118 if (png_ptr != NULL && info_ptr != NULL)
119 return info_ptr->compression_type;
120
121 return 0;
122}
123
124png_uint_32 PNGAPI
125png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
126 info_ptr)
127{
128#ifdef PNG_pHYs_SUPPORTED
129 png_debug(1, "in png_get_x_pixels_per_meter");
130
131 if (png_ptr != NULL && info_ptr != NULL &&
132 (info_ptr->valid & PNG_INFO_pHYs) != 0)
133 {
134 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
135 return info_ptr->x_pixels_per_unit;
136 }
137#else
138 PNG_UNUSED(png_ptr)
139 PNG_UNUSED(info_ptr)
140#endif
141
142 return 0;
143}
144
145png_uint_32 PNGAPI
146png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
147 info_ptr)
148{
149#ifdef PNG_pHYs_SUPPORTED
150 png_debug(1, "in png_get_y_pixels_per_meter");
151
152 if (png_ptr != NULL && info_ptr != NULL &&
153 (info_ptr->valid & PNG_INFO_pHYs) != 0)
154 {
155 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
156 return info_ptr->y_pixels_per_unit;
157 }
158#else
159 PNG_UNUSED(png_ptr)
160 PNG_UNUSED(info_ptr)
161#endif
162
163 return 0;
164}
165
166png_uint_32 PNGAPI
167png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
168{
169#ifdef PNG_pHYs_SUPPORTED
170 png_debug(1, "in png_get_pixels_per_meter");
171
172 if (png_ptr != NULL && info_ptr != NULL &&
173 (info_ptr->valid & PNG_INFO_pHYs) != 0)
174 {
175 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
176 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
177 return info_ptr->x_pixels_per_unit;
178 }
179#else
180 PNG_UNUSED(png_ptr)
181 PNG_UNUSED(info_ptr)
182#endif
183
184 return 0;
185}
186
187#ifdef PNG_FLOATING_POINT_SUPPORTED
188float PNGAPI
189png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
190 info_ptr)
191{
192#ifdef PNG_READ_pHYs_SUPPORTED
193 png_debug(1, "in png_get_pixel_aspect_ratio");
194
195 if (png_ptr != NULL && info_ptr != NULL &&
196 (info_ptr->valid & PNG_INFO_pHYs) != 0)
197 {
198 if (info_ptr->x_pixels_per_unit != 0)
199 return (float)info_ptr->y_pixels_per_unit
200 / (float)info_ptr->x_pixels_per_unit;
201 }
202#else
203 PNG_UNUSED(png_ptr)
204 PNG_UNUSED(info_ptr)
205#endif
206
207 return (float)0.0;
208}
209#endif
210
211#ifdef PNG_FIXED_POINT_SUPPORTED
212png_fixed_point PNGAPI
213png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
214 png_const_inforp info_ptr)
215{
216#ifdef PNG_READ_pHYs_SUPPORTED
217 png_debug(1, "in png_get_pixel_aspect_ratio_fixed");
218
219 if (png_ptr != NULL && info_ptr != NULL &&
220 (info_ptr->valid & PNG_INFO_pHYs) != 0 &&
221 info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
222 info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
223 info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
224 {
225 png_fixed_point res;
226
227 /* The following casts work because a PNG 4 byte integer only has a valid
228 * range of 0..2^31-1; otherwise the cast might overflow.
229 */
230 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
231 (png_int_32)info_ptr->x_pixels_per_unit) != 0)
232 return res;
233 }
234#else
235 PNG_UNUSED(png_ptr)
236 PNG_UNUSED(info_ptr)
237#endif
238
239 return 0;
240}
241#endif
242
243png_int_32 PNGAPI
244png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
245{
246#ifdef PNG_oFFs_SUPPORTED
247 png_debug(1, "in png_get_x_offset_microns");
248
249 if (png_ptr != NULL && info_ptr != NULL &&
250 (info_ptr->valid & PNG_INFO_oFFs) != 0)
251 {
252 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
253 return info_ptr->x_offset;
254 }
255#else
256 PNG_UNUSED(png_ptr)
257 PNG_UNUSED(info_ptr)
258#endif
259
260 return 0;
261}
262
263png_int_32 PNGAPI
264png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
265{
266#ifdef PNG_oFFs_SUPPORTED
267 png_debug(1, "in png_get_y_offset_microns");
268
269 if (png_ptr != NULL && info_ptr != NULL &&
270 (info_ptr->valid & PNG_INFO_oFFs) != 0)
271 {
272 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
273 return info_ptr->y_offset;
274 }
275#else
276 PNG_UNUSED(png_ptr)
277 PNG_UNUSED(info_ptr)
278#endif
279
280 return 0;
281}
282
283png_int_32 PNGAPI
284png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
285{
286#ifdef PNG_oFFs_SUPPORTED
287 png_debug(1, "in png_get_x_offset_pixels");
288
289 if (png_ptr != NULL && info_ptr != NULL &&
290 (info_ptr->valid & PNG_INFO_oFFs) != 0)
291 {
292 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
293 return info_ptr->x_offset;
294 }
295#else
296 PNG_UNUSED(png_ptr)
297 PNG_UNUSED(info_ptr)
298#endif
299
300 return 0;
301}
302
303png_int_32 PNGAPI
304png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
305{
306#ifdef PNG_oFFs_SUPPORTED
307 png_debug(1, "in png_get_y_offset_pixels");
308
309 if (png_ptr != NULL && info_ptr != NULL &&
310 (info_ptr->valid & PNG_INFO_oFFs) != 0)
311 {
312 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
313 return info_ptr->y_offset;
314 }
315#else
316 PNG_UNUSED(png_ptr)
317 PNG_UNUSED(info_ptr)
318#endif
319
320 return 0;
321}
322
323#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
324static png_uint_32
325ppi_from_ppm(png_uint_32 ppm)
326{
327#if 0
328 /* The conversion is *(2.54/100), in binary (32 digits):
329 * .00000110100000001001110101001001
330 */
331 png_uint_32 t1001, t1101;
332 ppm >>= 1; /* .1 */
333 t1001 = ppm + (ppm >> 3); /* .1001 */
334 t1101 = t1001 + (ppm >> 1); /* .1101 */
335 ppm >>= 20; /* .000000000000000000001 */
336 t1101 += t1101 >> 15; /* .1101000000000001101 */
337 t1001 >>= 11; /* .000000000001001 */
338 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
339 ppm += t1001; /* .000000000001001000001001001 */
340 ppm += t1101; /* .110100000001001110101001001 */
341 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
342#else
343 /* The argument is a PNG unsigned integer, so it is not permitted
344 * to be bigger than 2^31.
345 */
346 png_fixed_point result;
347 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
348 5000) != 0)
349 return (png_uint_32)result;
350
351 /* Overflow. */
352 return 0;
353#endif
354}
355
356png_uint_32 PNGAPI
357png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
358{
359 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
360}
361
362png_uint_32 PNGAPI
363png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
364{
365 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
366}
367
368png_uint_32 PNGAPI
369png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
370{
371 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
372}
373
374#ifdef PNG_FIXED_POINT_SUPPORTED
375static png_fixed_point
376png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
377{
378 /* Convert from meters * 1,000,000 to inches * 100,000, meters to
379 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
380 * Notice that this can overflow - a warning is output and 0 is
381 * returned.
382 */
383 return png_muldiv_warn(png_ptr, microns, 500, 127);
384}
385
386png_fixed_point PNGAPI
387png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
388 png_const_inforp info_ptr)
389{
390 return png_fixed_inches_from_microns(png_ptr,
391 png_get_x_offset_microns(png_ptr, info_ptr));
392}
393#endif
394
395#ifdef PNG_FIXED_POINT_SUPPORTED
396png_fixed_point PNGAPI
397png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
398 png_const_inforp info_ptr)
399{
400 return png_fixed_inches_from_microns(png_ptr,
401 png_get_y_offset_microns(png_ptr, info_ptr));
402}
403#endif
404
405#ifdef PNG_FLOATING_POINT_SUPPORTED
406float PNGAPI
407png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
408{
409 /* To avoid the overflow do the conversion directly in floating
410 * point.
411 */
412 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
413}
414#endif
415
416#ifdef PNG_FLOATING_POINT_SUPPORTED
417float PNGAPI
418png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
419{
420 /* To avoid the overflow do the conversion directly in floating
421 * point.
422 */
423 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
424}
425#endif
426
427#ifdef PNG_pHYs_SUPPORTED
428png_uint_32 PNGAPI
429png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
430 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
431{
432 png_uint_32 retval = 0;
433
434 png_debug1(1, "in %s retrieval function", "pHYs");
435
436 if (png_ptr != NULL && info_ptr != NULL &&
437 (info_ptr->valid & PNG_INFO_pHYs) != 0)
438 {
439 if (res_x != NULL)
440 {
441 *res_x = info_ptr->x_pixels_per_unit;
442 retval |= PNG_INFO_pHYs;
443 }
444
445 if (res_y != NULL)
446 {
447 *res_y = info_ptr->y_pixels_per_unit;
448 retval |= PNG_INFO_pHYs;
449 }
450
451 if (unit_type != NULL)
452 {
453 *unit_type = (int)info_ptr->phys_unit_type;
454 retval |= PNG_INFO_pHYs;
455
456 if (*unit_type == 1)
457 {
458 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
459 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
460 }
461 }
462 }
463
464 return retval;
465}
466#endif /* pHYs */
467#endif /* INCH_CONVERSIONS */
468
469/* png_get_channels really belongs in here, too, but it's been around longer */
470
471#endif /* EASY_ACCESS */
472
473
474png_byte PNGAPI
475png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
476{
477 if (png_ptr != NULL && info_ptr != NULL)
478 return info_ptr->channels;
479
480 return 0;
481}
482
483#ifdef PNG_READ_SUPPORTED
484png_const_bytep PNGAPI
485png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
486{
487 if (png_ptr != NULL && info_ptr != NULL)
488 return info_ptr->signature;
489
490 return NULL;
491}
492#endif
493
494#ifdef PNG_bKGD_SUPPORTED
495png_uint_32 PNGAPI
496png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
497 png_color_16p *background)
498{
499 png_debug1(1, "in %s retrieval function", "bKGD");
500
501 if (png_ptr != NULL && info_ptr != NULL &&
502 (info_ptr->valid & PNG_INFO_bKGD) != 0 &&
503 background != NULL)
504 {
505 *background = &(info_ptr->background);
506 return PNG_INFO_bKGD;
507 }
508
509 return 0;
510}
511#endif
512
513#ifdef PNG_cHRM_SUPPORTED
514/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
515 * same time to correct the rgb grayscale coefficient defaults obtained from the
516 * cHRM chunk in 1.5.4
517 */
518# ifdef PNG_FLOATING_POINT_SUPPORTED
519png_uint_32 PNGAPI
520png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
521 double *white_x, double *white_y, double *red_x, double *red_y,
522 double *green_x, double *green_y, double *blue_x, double *blue_y)
523{
524 png_debug1(1, "in %s retrieval function", "cHRM");
525
526 /* Quiet API change: this code used to only return the end points if a cHRM
527 * chunk was present, but the end points can also come from iCCP or sRGB
528 * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
529 * the png_set_ APIs merely check that set end points are mutually
530 * consistent.
531 */
532 if (png_ptr != NULL && info_ptr != NULL &&
533 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
534 {
535 if (white_x != NULL)
536 *white_x = png_float(png_ptr,
537 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
538 if (white_y != NULL)
539 *white_y = png_float(png_ptr,
540 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
541 if (red_x != NULL)
542 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
543 "cHRM red X");
544 if (red_y != NULL)
545 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
546 "cHRM red Y");
547 if (green_x != NULL)
548 *green_x = png_float(png_ptr,
549 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
550 if (green_y != NULL)
551 *green_y = png_float(png_ptr,
552 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
553 if (blue_x != NULL)
554 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
555 "cHRM blue X");
556 if (blue_y != NULL)
557 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
558 "cHRM blue Y");
559 return PNG_INFO_cHRM;
560 }
561
562 return 0;
563}
564
565png_uint_32 PNGAPI
566png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
567 double *red_X, double *red_Y, double *red_Z, double *green_X,
568 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
569 double *blue_Z)
570{
571 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
572
573 if (png_ptr != NULL && info_ptr != NULL &&
574 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
575 {
576 if (red_X != NULL)
577 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
578 "cHRM red X");
579 if (red_Y != NULL)
580 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
581 "cHRM red Y");
582 if (red_Z != NULL)
583 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
584 "cHRM red Z");
585 if (green_X != NULL)
586 *green_X = png_float(png_ptr,
587 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
588 if (green_Y != NULL)
589 *green_Y = png_float(png_ptr,
590 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
591 if (green_Z != NULL)
592 *green_Z = png_float(png_ptr,
593 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
594 if (blue_X != NULL)
595 *blue_X = png_float(png_ptr,
596 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
597 if (blue_Y != NULL)
598 *blue_Y = png_float(png_ptr,
599 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
600 if (blue_Z != NULL)
601 *blue_Z = png_float(png_ptr,
602 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
603 return PNG_INFO_cHRM;
604 }
605
606 return 0;
607}
608# endif
609
610# ifdef PNG_FIXED_POINT_SUPPORTED
611png_uint_32 PNGAPI
612png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
613 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
614 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
615 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
616 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
617 png_fixed_point *int_blue_Z)
618{
619 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
620
621 if (png_ptr != NULL && info_ptr != NULL &&
622 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
623 {
624 if (int_red_X != NULL)
625 *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
626 if (int_red_Y != NULL)
627 *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
628 if (int_red_Z != NULL)
629 *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
630 if (int_green_X != NULL)
631 *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
632 if (int_green_Y != NULL)
633 *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
634 if (int_green_Z != NULL)
635 *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
636 if (int_blue_X != NULL)
637 *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
638 if (int_blue_Y != NULL)
639 *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
640 if (int_blue_Z != NULL)
641 *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
642 return PNG_INFO_cHRM;
643 }
644
645 return 0;
646}
647
648png_uint_32 PNGAPI
649png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
650 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
651 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
652 png_fixed_point *blue_x, png_fixed_point *blue_y)
653{
654 png_debug1(1, "in %s retrieval function", "cHRM");
655
656 if (png_ptr != NULL && info_ptr != NULL &&
657 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
658 {
659 if (white_x != NULL)
660 *white_x = info_ptr->colorspace.end_points_xy.whitex;
661 if (white_y != NULL)
662 *white_y = info_ptr->colorspace.end_points_xy.whitey;
663 if (red_x != NULL)
664 *red_x = info_ptr->colorspace.end_points_xy.redx;
665 if (red_y != NULL)
666 *red_y = info_ptr->colorspace.end_points_xy.redy;
667 if (green_x != NULL)
668 *green_x = info_ptr->colorspace.end_points_xy.greenx;
669 if (green_y != NULL)
670 *green_y = info_ptr->colorspace.end_points_xy.greeny;
671 if (blue_x != NULL)
672 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
673 if (blue_y != NULL)
674 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
675 return PNG_INFO_cHRM;
676 }
677
678 return 0;
679}
680# endif
681#endif
682
683#ifdef PNG_gAMA_SUPPORTED
684# ifdef PNG_FIXED_POINT_SUPPORTED
685png_uint_32 PNGAPI
686png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
687 png_fixed_point *file_gamma)
688{
689 png_debug1(1, "in %s retrieval function", "gAMA");
690
691 if (png_ptr != NULL && info_ptr != NULL &&
692 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
693 file_gamma != NULL)
694 {
695 *file_gamma = info_ptr->colorspace.gamma;
696 return PNG_INFO_gAMA;
697 }
698
699 return 0;
700}
701# endif
702
703# ifdef PNG_FLOATING_POINT_SUPPORTED
704png_uint_32 PNGAPI
705png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
706 double *file_gamma)
707{
708 png_debug1(1, "in %s retrieval function", "gAMA(float)");
709
710 if (png_ptr != NULL && info_ptr != NULL &&
711 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
712 file_gamma != NULL)
713 {
714 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
715 "png_get_gAMA");
716 return PNG_INFO_gAMA;
717 }
718
719 return 0;
720}
721# endif
722#endif
723
724#ifdef PNG_sRGB_SUPPORTED
725png_uint_32 PNGAPI
726png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
727 int *file_srgb_intent)
728{
729 png_debug1(1, "in %s retrieval function", "sRGB");
730
731 if (png_ptr != NULL && info_ptr != NULL &&
732 (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
733 {
734 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
735 return PNG_INFO_sRGB;
736 }
737
738 return 0;
739}
740#endif
741
742#ifdef PNG_iCCP_SUPPORTED
743png_uint_32 PNGAPI
744png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
745 png_charpp name, int *compression_type,
746 png_bytepp profile, png_uint_32 *proflen)
747{
748 png_debug1(1, "in %s retrieval function", "iCCP");
749
750 if (png_ptr != NULL && info_ptr != NULL &&
751 (info_ptr->valid & PNG_INFO_iCCP) != 0 &&
752 name != NULL && profile != NULL && proflen != NULL)
753 {
754 *name = info_ptr->iccp_name;
755 *profile = info_ptr->iccp_profile;
756 *proflen = png_get_uint_32(info_ptr->iccp_profile);
757 /* This is somewhat irrelevant since the profile data returned has
758 * actually been uncompressed.
759 */
760 if (compression_type != NULL)
761 *compression_type = PNG_COMPRESSION_TYPE_BASE;
762 return PNG_INFO_iCCP;
763 }
764
765 return 0;
766
767}
768#endif
769
770#ifdef PNG_sPLT_SUPPORTED
771int PNGAPI
772png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
773 png_sPLT_tpp spalettes)
774{
775 png_debug1(1, "in %s retrieval function", "sPLT");
776
777 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
778 {
779 *spalettes = info_ptr->splt_palettes;
780 return info_ptr->splt_palettes_num;
781 }
782
783 return 0;
784}
785#endif
786
787#ifdef PNG_cICP_SUPPORTED
788png_uint_32 PNGAPI
789png_get_cICP(png_const_structrp png_ptr,
790 png_inforp info_ptr, png_bytep colour_primaries,
791 png_bytep transfer_function, png_bytep matrix_coefficients,
792 png_bytep video_full_range_flag)
793{
794 png_debug1(1, "in %s retrieval function", "cICP");
795
796 if (png_ptr != NULL && info_ptr != NULL &&
797 (info_ptr->valid & PNG_INFO_cICP) != 0 &&
798 colour_primaries != NULL && transfer_function != NULL &&
799 matrix_coefficients != NULL && video_full_range_flag != NULL)
800 {
801 *colour_primaries = info_ptr->cicp_colour_primaries;
802 *transfer_function = info_ptr->cicp_transfer_function;
803 *matrix_coefficients = info_ptr->cicp_matrix_coefficients;
804 *video_full_range_flag = info_ptr->cicp_video_full_range_flag;
805 return (PNG_INFO_cICP);
806 }
807
808 return (0);
809}
810#endif
811
812#ifdef PNG_eXIf_SUPPORTED
813png_uint_32 PNGAPI
814png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
815 png_bytep *exif)
816{
817 png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
818 PNG_UNUSED(info_ptr)
819 PNG_UNUSED(exif)
820 return 0;
821}
822
823png_uint_32 PNGAPI
824png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
825 png_uint_32 *num_exif, png_bytep *exif)
826{
827 png_debug1(1, "in %s retrieval function", "eXIf");
828
829 if (png_ptr != NULL && info_ptr != NULL &&
830 (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
831 {
832 *num_exif = info_ptr->num_exif;
833 *exif = info_ptr->exif;
834 return PNG_INFO_eXIf;
835 }
836
837 return 0;
838}
839#endif
840
841#ifdef PNG_hIST_SUPPORTED
842png_uint_32 PNGAPI
843png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
844 png_uint_16p *hist)
845{
846 png_debug1(1, "in %s retrieval function", "hIST");
847
848 if (png_ptr != NULL && info_ptr != NULL &&
849 (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
850 {
851 *hist = info_ptr->hist;
852 return PNG_INFO_hIST;
853 }
854
855 return 0;
856}
857#endif
858
859png_uint_32 PNGAPI
860png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
861 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
862 int *color_type, int *interlace_type, int *compression_type,
863 int *filter_type)
864{
865 png_debug1(1, "in %s retrieval function", "IHDR");
866
867 if (png_ptr == NULL || info_ptr == NULL)
868 return 0;
869
870 if (width != NULL)
871 *width = info_ptr->width;
872
873 if (height != NULL)
874 *height = info_ptr->height;
875
876 if (bit_depth != NULL)
877 *bit_depth = info_ptr->bit_depth;
878
879 if (color_type != NULL)
880 *color_type = info_ptr->color_type;
881
882 if (compression_type != NULL)
883 *compression_type = info_ptr->compression_type;
884
885 if (filter_type != NULL)
886 *filter_type = info_ptr->filter_type;
887
888 if (interlace_type != NULL)
889 *interlace_type = info_ptr->interlace_type;
890
891 /* This is redundant if we can be sure that the info_ptr values were all
892 * assigned in png_set_IHDR(). We do the check anyhow in case an
893 * application has ignored our advice not to mess with the members
894 * of info_ptr directly.
895 */
896 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
897 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
898 info_ptr->compression_type, info_ptr->filter_type);
899
900 return 1;
901}
902
903#ifdef PNG_oFFs_SUPPORTED
904png_uint_32 PNGAPI
905png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
906 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
907{
908 png_debug1(1, "in %s retrieval function", "oFFs");
909
910 if (png_ptr != NULL && info_ptr != NULL &&
911 (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
912 offset_x != NULL && offset_y != NULL && unit_type != NULL)
913 {
914 *offset_x = info_ptr->x_offset;
915 *offset_y = info_ptr->y_offset;
916 *unit_type = (int)info_ptr->offset_unit_type;
917 return PNG_INFO_oFFs;
918 }
919
920 return 0;
921}
922#endif
923
924#ifdef PNG_pCAL_SUPPORTED
925png_uint_32 PNGAPI
926png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
927 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
928 png_charp *units, png_charpp *params)
929{
930 png_debug1(1, "in %s retrieval function", "pCAL");
931
932 if (png_ptr != NULL && info_ptr != NULL &&
933 (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
934 purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
935 nparams != NULL && units != NULL && params != NULL)
936 {
937 *purpose = info_ptr->pcal_purpose;
938 *X0 = info_ptr->pcal_X0;
939 *X1 = info_ptr->pcal_X1;
940 *type = (int)info_ptr->pcal_type;
941 *nparams = (int)info_ptr->pcal_nparams;
942 *units = info_ptr->pcal_units;
943 *params = info_ptr->pcal_params;
944 return PNG_INFO_pCAL;
945 }
946
947 return 0;
948}
949#endif
950
951#ifdef PNG_sCAL_SUPPORTED
952# ifdef PNG_FIXED_POINT_SUPPORTED
953# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
954 defined(PNG_FLOATING_POINT_SUPPORTED)
955png_uint_32 PNGAPI
956png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
957 int *unit, png_fixed_point *width, png_fixed_point *height)
958{
959 png_debug1(1, "in %s retrieval function", "sCAL");
960
961 if (png_ptr != NULL && info_ptr != NULL &&
962 (info_ptr->valid & PNG_INFO_sCAL) != 0)
963 {
964 *unit = info_ptr->scal_unit;
965 /*TODO: make this work without FP support; the API is currently eliminated
966 * if neither floating point APIs nor internal floating point arithmetic
967 * are enabled.
968 */
969 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
970 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
971 "sCAL height");
972 return PNG_INFO_sCAL;
973 }
974
975 return 0;
976}
977# endif /* FLOATING_ARITHMETIC */
978# endif /* FIXED_POINT */
979# ifdef PNG_FLOATING_POINT_SUPPORTED
980png_uint_32 PNGAPI
981png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
982 int *unit, double *width, double *height)
983{
984 png_debug1(1, "in %s retrieval function", "sCAL(float)");
985
986 if (png_ptr != NULL && info_ptr != NULL &&
987 (info_ptr->valid & PNG_INFO_sCAL) != 0)
988 {
989 *unit = info_ptr->scal_unit;
990 *width = atof(info_ptr->scal_s_width);
991 *height = atof(info_ptr->scal_s_height);
992 return PNG_INFO_sCAL;
993 }
994
995 return 0;
996}
997# endif /* FLOATING POINT */
998png_uint_32 PNGAPI
999png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
1000 int *unit, png_charpp width, png_charpp height)
1001{
1002 png_debug1(1, "in %s retrieval function", "sCAL(str)");
1003
1004 if (png_ptr != NULL && info_ptr != NULL &&
1005 (info_ptr->valid & PNG_INFO_sCAL) != 0)
1006 {
1007 *unit = info_ptr->scal_unit;
1008 *width = info_ptr->scal_s_width;
1009 *height = info_ptr->scal_s_height;
1010 return PNG_INFO_sCAL;
1011 }
1012
1013 return 0;
1014}
1015#endif /* sCAL */
1016
1017#ifdef PNG_pHYs_SUPPORTED
1018png_uint_32 PNGAPI
1019png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
1020 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
1021{
1022 png_uint_32 retval = 0;
1023
1024 png_debug1(1, "in %s retrieval function", "pHYs");
1025
1026 if (png_ptr != NULL && info_ptr != NULL &&
1027 (info_ptr->valid & PNG_INFO_pHYs) != 0)
1028 {
1029 if (res_x != NULL)
1030 {
1031 *res_x = info_ptr->x_pixels_per_unit;
1032 retval |= PNG_INFO_pHYs;
1033 }
1034
1035 if (res_y != NULL)
1036 {
1037 *res_y = info_ptr->y_pixels_per_unit;
1038 retval |= PNG_INFO_pHYs;
1039 }
1040
1041 if (unit_type != NULL)
1042 {
1043 *unit_type = (int)info_ptr->phys_unit_type;
1044 retval |= PNG_INFO_pHYs;
1045 }
1046 }
1047
1048 return retval;
1049}
1050#endif /* pHYs */
1051
1052png_uint_32 PNGAPI
1053png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
1054 png_colorp *palette, int *num_palette)
1055{
1056 png_debug1(1, "in %s retrieval function", "PLTE");
1057
1058 if (png_ptr != NULL && info_ptr != NULL &&
1059 (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
1060 {
1061 *palette = info_ptr->palette;
1062 *num_palette = info_ptr->num_palette;
1063 png_debug1(3, "num_palette = %d", *num_palette);
1064 return PNG_INFO_PLTE;
1065 }
1066
1067 return 0;
1068}
1069
1070#ifdef PNG_sBIT_SUPPORTED
1071png_uint_32 PNGAPI
1072png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
1073 png_color_8p *sig_bit)
1074{
1075 png_debug1(1, "in %s retrieval function", "sBIT");
1076
1077 if (png_ptr != NULL && info_ptr != NULL &&
1078 (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
1079 {
1080 *sig_bit = &(info_ptr->sig_bit);
1081 return PNG_INFO_sBIT;
1082 }
1083
1084 return 0;
1085}
1086#endif
1087
1088#ifdef PNG_TEXT_SUPPORTED
1089int PNGAPI
1090png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
1091 png_textp *text_ptr, int *num_text)
1092{
1093 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
1094 {
1095 png_debug1(1, "in text retrieval function, chunk typeid = 0x%lx",
1096 (unsigned long)png_ptr->chunk_name);
1097
1098 if (text_ptr != NULL)
1099 *text_ptr = info_ptr->text;
1100
1101 if (num_text != NULL)
1102 *num_text = info_ptr->num_text;
1103
1104 return info_ptr->num_text;
1105 }
1106
1107 if (num_text != NULL)
1108 *num_text = 0;
1109
1110 return 0;
1111}
1112#endif
1113
1114#ifdef PNG_tIME_SUPPORTED
1115png_uint_32 PNGAPI
1116png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1117 png_timep *mod_time)
1118{
1119 png_debug1(1, "in %s retrieval function", "tIME");
1120
1121 if (png_ptr != NULL && info_ptr != NULL &&
1122 (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
1123 {
1124 *mod_time = &(info_ptr->mod_time);
1125 return PNG_INFO_tIME;
1126 }
1127
1128 return 0;
1129}
1130#endif
1131
1132#ifdef PNG_tRNS_SUPPORTED
1133png_uint_32 PNGAPI
1134png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
1135 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
1136{
1137 png_uint_32 retval = 0;
1138
1139 png_debug1(1, "in %s retrieval function", "tRNS");
1140
1141 if (png_ptr != NULL && info_ptr != NULL &&
1142 (info_ptr->valid & PNG_INFO_tRNS) != 0)
1143 {
1144 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1145 {
1146 if (trans_alpha != NULL)
1147 {
1148 *trans_alpha = info_ptr->trans_alpha;
1149 retval |= PNG_INFO_tRNS;
1150 }
1151
1152 if (trans_color != NULL)
1153 *trans_color = &(info_ptr->trans_color);
1154 }
1155
1156 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1157 {
1158 if (trans_color != NULL)
1159 {
1160 *trans_color = &(info_ptr->trans_color);
1161 retval |= PNG_INFO_tRNS;
1162 }
1163
1164 if (trans_alpha != NULL)
1165 *trans_alpha = NULL;
1166 }
1167
1168 if (num_trans != NULL)
1169 {
1170 *num_trans = info_ptr->num_trans;
1171 retval |= PNG_INFO_tRNS;
1172 }
1173 }
1174
1175 return retval;
1176}
1177#endif
1178
1179#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1180int PNGAPI
1181png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
1182 png_unknown_chunkpp unknowns)
1183{
1184 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1185 {
1186 *unknowns = info_ptr->unknown_chunks;
1187 return info_ptr->unknown_chunks_num;
1188 }
1189
1190 return 0;
1191}
1192#endif
1193
1194#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1195png_byte PNGAPI
1196png_get_rgb_to_gray_status(png_const_structrp png_ptr)
1197{
1198 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
1199}
1200#endif
1201
1202#ifdef PNG_USER_CHUNKS_SUPPORTED
1203png_voidp PNGAPI
1204png_get_user_chunk_ptr(png_const_structrp png_ptr)
1205{
1206 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1207}
1208#endif
1209
1210size_t PNGAPI
1211png_get_compression_buffer_size(png_const_structrp png_ptr)
1212{
1213 if (png_ptr == NULL)
1214 return 0;
1215
1216#ifdef PNG_WRITE_SUPPORTED
1217 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1218#endif
1219 {
1220#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1221 return png_ptr->IDAT_read_size;
1222#else
1223 return PNG_IDAT_READ_SIZE;
1224#endif
1225 }
1226
1227#ifdef PNG_WRITE_SUPPORTED
1228 else
1229 return png_ptr->zbuffer_size;
1230#endif
1231}
1232
1233#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1234/* These functions were added to libpng 1.2.6 and were enabled
1235 * by default in libpng-1.4.0 */
1236png_uint_32 PNGAPI
1237png_get_user_width_max(png_const_structrp png_ptr)
1238{
1239 return (png_ptr ? png_ptr->user_width_max : 0);
1240}
1241
1242png_uint_32 PNGAPI
1243png_get_user_height_max(png_const_structrp png_ptr)
1244{
1245 return (png_ptr ? png_ptr->user_height_max : 0);
1246}
1247
1248/* This function was added to libpng 1.4.0 */
1249png_uint_32 PNGAPI
1250png_get_chunk_cache_max(png_const_structrp png_ptr)
1251{
1252 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1253}
1254
1255/* This function was added to libpng 1.4.1 */
1256png_alloc_size_t PNGAPI
1257png_get_chunk_malloc_max(png_const_structrp png_ptr)
1258{
1259 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1260}
1261#endif /* SET_USER_LIMITS */
1262
1263/* These functions were added to libpng 1.4.0 */
1264#ifdef PNG_IO_STATE_SUPPORTED
1265png_uint_32 PNGAPI
1266png_get_io_state(png_const_structrp png_ptr)
1267{
1268 return png_ptr->io_state;
1269}
1270
1271png_uint_32 PNGAPI
1272png_get_io_chunk_type(png_const_structrp png_ptr)
1273{
1274 return png_ptr->chunk_name;
1275}
1276#endif /* IO_STATE */
1277
1278#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1279# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1280int PNGAPI
1281png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1282{
1283 if (png_ptr != NULL && info_ptr != NULL)
1284 return png_ptr->num_palette_max;
1285
1286 return -1;
1287}
1288# endif
1289#endif
1290
1291#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