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