]> git.saurik.com Git - wxWidgets.git/blame - src/png/pngget.c
Add various selection menu items to the sample.
[wxWidgets.git] / src / png / pngget.c
CommitLineData
0272a10d
VZ
1
2/* pngget.c - retrieval of values from info struct
3 *
b61cc19c
PC
4 * Last changed in libpng 1.4.2 [May 6, 2010]
5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
0272a10d
VZ
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
b61cc19c
PC
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 *
0272a10d
VZ
13 */
14
b61cc19c 15#define PNG_NO_PEDANTIC_WARNINGS
0272a10d 16#include "png.h"
0272a10d 17#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
b61cc19c 18#include "pngpriv.h"
0272a10d
VZ
19
20png_uint_32 PNGAPI
21png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
22{
23 if (png_ptr != NULL && info_ptr != NULL)
24 return(info_ptr->valid & flag);
b61cc19c 25
0272a10d
VZ
26 else
27 return(0);
28}
29
b61cc19c 30png_size_t PNGAPI
0272a10d
VZ
31png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
32{
33 if (png_ptr != NULL && info_ptr != NULL)
34 return(info_ptr->rowbytes);
b61cc19c 35
0272a10d
VZ
36 else
37 return(0);
38}
39
b61cc19c 40#ifdef PNG_INFO_IMAGE_SUPPORTED
0272a10d
VZ
41png_bytepp PNGAPI
42png_get_rows(png_structp png_ptr, png_infop info_ptr)
43{
44 if (png_ptr != NULL && info_ptr != NULL)
45 return(info_ptr->row_pointers);
b61cc19c 46
0272a10d
VZ
47 else
48 return(0);
49}
50#endif
51
52#ifdef PNG_EASY_ACCESS_SUPPORTED
b61cc19c 53/* Easy access to info, added in libpng-0.99 */
0272a10d
VZ
54png_uint_32 PNGAPI
55png_get_image_width(png_structp png_ptr, png_infop info_ptr)
56{
57 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 58 return info_ptr->width;
b61cc19c 59
0272a10d
VZ
60 return (0);
61}
62
63png_uint_32 PNGAPI
64png_get_image_height(png_structp png_ptr, png_infop info_ptr)
65{
66 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 67 return info_ptr->height;
b61cc19c 68
0272a10d
VZ
69 return (0);
70}
71
72png_byte PNGAPI
73png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
74{
75 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 76 return info_ptr->bit_depth;
b61cc19c 77
0272a10d
VZ
78 return (0);
79}
80
81png_byte PNGAPI
82png_get_color_type(png_structp png_ptr, png_infop info_ptr)
83{
84 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 85 return info_ptr->color_type;
b61cc19c 86
0272a10d
VZ
87 return (0);
88}
89
90png_byte PNGAPI
91png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
92{
93 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 94 return info_ptr->filter_type;
b61cc19c 95
0272a10d
VZ
96 return (0);
97}
98
99png_byte PNGAPI
100png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
101{
102 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 103 return info_ptr->interlace_type;
b61cc19c 104
0272a10d
VZ
105 return (0);
106}
107
108png_byte PNGAPI
109png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
110{
111 if (png_ptr != NULL && info_ptr != NULL)
0272a10d 112 return info_ptr->compression_type;
b61cc19c 113
0272a10d
VZ
114 return (0);
115}
116
117png_uint_32 PNGAPI
118png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
119{
120 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c 121#ifdef PNG_pHYs_SUPPORTED
0272a10d
VZ
122 if (info_ptr->valid & PNG_INFO_pHYs)
123 {
970f6abe 124 png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter");
b61cc19c 125
970f6abe 126 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
0272a10d 127 return (0);
b61cc19c
PC
128
129 else
130 return (info_ptr->x_pixels_per_unit);
0272a10d
VZ
131 }
132#else
133 return (0);
134#endif
135 return (0);
136}
137
138png_uint_32 PNGAPI
139png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
140{
141 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c 142#ifdef PNG_pHYs_SUPPORTED
0272a10d
VZ
143 if (info_ptr->valid & PNG_INFO_pHYs)
144 {
970f6abe 145 png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter");
b61cc19c 146
970f6abe 147 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
0272a10d 148 return (0);
b61cc19c
PC
149
150 else
151 return (info_ptr->y_pixels_per_unit);
0272a10d
VZ
152 }
153#else
154 return (0);
155#endif
156 return (0);
157}
158
159png_uint_32 PNGAPI
160png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
161{
162 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c 163#ifdef PNG_pHYs_SUPPORTED
0272a10d
VZ
164 if (info_ptr->valid & PNG_INFO_pHYs)
165 {
970f6abe 166 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
b61cc19c 167
970f6abe 168 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
0272a10d
VZ
169 info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
170 return (0);
b61cc19c
PC
171
172 else
173 return (info_ptr->x_pixels_per_unit);
0272a10d
VZ
174 }
175#else
176 return (0);
177#endif
178 return (0);
179}
180
181#ifdef PNG_FLOATING_POINT_SUPPORTED
182float PNGAPI
183png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
184 {
185 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c
PC
186#ifdef PNG_pHYs_SUPPORTED
187
0272a10d
VZ
188 if (info_ptr->valid & PNG_INFO_pHYs)
189 {
970f6abe 190 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
b61cc19c 191
0272a10d
VZ
192 if (info_ptr->x_pixels_per_unit == 0)
193 return ((float)0.0);
b61cc19c 194
0272a10d
VZ
195 else
196 return ((float)((float)info_ptr->y_pixels_per_unit
197 /(float)info_ptr->x_pixels_per_unit));
198 }
199#else
b61cc19c 200 return (0.0);
0272a10d
VZ
201#endif
202 return ((float)0.0);
203}
204#endif
205
206png_int_32 PNGAPI
207png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
208{
209 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c
PC
210#ifdef PNG_oFFs_SUPPORTED
211
0272a10d
VZ
212 if (info_ptr->valid & PNG_INFO_oFFs)
213 {
970f6abe 214 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
b61cc19c 215
970f6abe 216 if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
0272a10d 217 return (0);
b61cc19c
PC
218
219 else
220 return (info_ptr->x_offset);
0272a10d
VZ
221 }
222#else
b61cc19c 223 return (0);
0272a10d
VZ
224#endif
225 return (0);
226}
227
228png_int_32 PNGAPI
229png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
230{
231 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c
PC
232
233#ifdef PNG_oFFs_SUPPORTED
0272a10d
VZ
234 if (info_ptr->valid & PNG_INFO_oFFs)
235 {
970f6abe 236 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
b61cc19c 237
970f6abe 238 if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
0272a10d 239 return (0);
b61cc19c
PC
240
241 else
242 return (info_ptr->y_offset);
0272a10d
VZ
243 }
244#else
245 return (0);
246#endif
247 return (0);
248}
249
250png_int_32 PNGAPI
251png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
252{
253 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c
PC
254
255#ifdef PNG_oFFs_SUPPORTED
0272a10d
VZ
256 if (info_ptr->valid & PNG_INFO_oFFs)
257 {
970f6abe 258 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
b61cc19c 259
970f6abe 260 if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
0272a10d 261 return (0);
b61cc19c
PC
262
263 else
264 return (info_ptr->x_offset);
0272a10d
VZ
265 }
266#else
267 return (0);
268#endif
269 return (0);
270}
271
272png_int_32 PNGAPI
273png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
274{
275 if (png_ptr != NULL && info_ptr != NULL)
b61cc19c
PC
276
277#ifdef PNG_oFFs_SUPPORTED
0272a10d
VZ
278 if (info_ptr->valid & PNG_INFO_oFFs)
279 {
970f6abe 280 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
b61cc19c 281
970f6abe 282 if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
0272a10d 283 return (0);
b61cc19c
PC
284
285 else
286 return (info_ptr->y_offset);
0272a10d
VZ
287 }
288#else
289 return (0);
290#endif
291 return (0);
292}
293
294#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
295png_uint_32 PNGAPI
296png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
297{
298 return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
299 *.0254 +.5));
300}
301
302png_uint_32 PNGAPI
303png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
304{
305 return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
306 *.0254 +.5));
307}
308
309png_uint_32 PNGAPI
310png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
311{
312 return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
313 *.0254 +.5));
314}
315
316float PNGAPI
317png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
318{
319 return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
320 *.00003937);
321}
322
323float PNGAPI
324png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
325{
326 return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
327 *.00003937);
328}
329
b61cc19c 330#ifdef PNG_pHYs_SUPPORTED
0272a10d
VZ
331png_uint_32 PNGAPI
332png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
333 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
334{
335 png_uint_32 retval = 0;
336
337 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
338 {
970f6abe 339 png_debug1(1, "in %s retrieval function", "pHYs");
b61cc19c 340
0272a10d
VZ
341 if (res_x != NULL)
342 {
343 *res_x = info_ptr->x_pixels_per_unit;
344 retval |= PNG_INFO_pHYs;
345 }
346 if (res_y != NULL)
347 {
348 *res_y = info_ptr->y_pixels_per_unit;
349 retval |= PNG_INFO_pHYs;
350 }
351 if (unit_type != NULL)
352 {
353 *unit_type = (int)info_ptr->phys_unit_type;
354 retval |= PNG_INFO_pHYs;
970f6abe 355 if (*unit_type == 1)
0272a10d
VZ
356 {
357 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
358 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
359 }
360 }
361 }
362 return (retval);
363}
364#endif /* PNG_pHYs_SUPPORTED */
365#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
366
367/* png_get_channels really belongs in here, too, but it's been around longer */
368
369#endif /* PNG_EASY_ACCESS_SUPPORTED */
370
371png_byte PNGAPI
372png_get_channels(png_structp png_ptr, png_infop info_ptr)
373{
374 if (png_ptr != NULL && info_ptr != NULL)
375 return(info_ptr->channels);
376 else
377 return (0);
378}
379
380png_bytep PNGAPI
381png_get_signature(png_structp png_ptr, png_infop info_ptr)
382{
383 if (png_ptr != NULL && info_ptr != NULL)
384 return(info_ptr->signature);
385 else
386 return (NULL);
387}
388
b61cc19c 389#ifdef PNG_bKGD_SUPPORTED
0272a10d
VZ
390png_uint_32 PNGAPI
391png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
392 png_color_16p *background)
393{
394 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
395 && background != NULL)
396 {
970f6abe 397 png_debug1(1, "in %s retrieval function", "bKGD");
b61cc19c 398
0272a10d
VZ
399 *background = &(info_ptr->background);
400 return (PNG_INFO_bKGD);
401 }
402 return (0);
403}
404#endif
405
b61cc19c 406#ifdef PNG_cHRM_SUPPORTED
0272a10d
VZ
407#ifdef PNG_FLOATING_POINT_SUPPORTED
408png_uint_32 PNGAPI
409png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
410 double *white_x, double *white_y, double *red_x, double *red_y,
411 double *green_x, double *green_y, double *blue_x, double *blue_y)
412{
413 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
414 {
970f6abe 415 png_debug1(1, "in %s retrieval function", "cHRM");
b61cc19c 416
0272a10d
VZ
417 if (white_x != NULL)
418 *white_x = (double)info_ptr->x_white;
419 if (white_y != NULL)
420 *white_y = (double)info_ptr->y_white;
421 if (red_x != NULL)
422 *red_x = (double)info_ptr->x_red;
423 if (red_y != NULL)
424 *red_y = (double)info_ptr->y_red;
425 if (green_x != NULL)
426 *green_x = (double)info_ptr->x_green;
427 if (green_y != NULL)
428 *green_y = (double)info_ptr->y_green;
429 if (blue_x != NULL)
430 *blue_x = (double)info_ptr->x_blue;
431 if (blue_y != NULL)
432 *blue_y = (double)info_ptr->y_blue;
433 return (PNG_INFO_cHRM);
434 }
435 return (0);
436}
437#endif
438#ifdef PNG_FIXED_POINT_SUPPORTED
439png_uint_32 PNGAPI
440png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
441 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
442 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
443 png_fixed_point *blue_x, png_fixed_point *blue_y)
444{
b61cc19c
PC
445 png_debug1(1, "in %s retrieval function", "cHRM");
446
0272a10d
VZ
447 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
448 {
0272a10d
VZ
449 if (white_x != NULL)
450 *white_x = info_ptr->int_x_white;
451 if (white_y != NULL)
452 *white_y = info_ptr->int_y_white;
453 if (red_x != NULL)
454 *red_x = info_ptr->int_x_red;
455 if (red_y != NULL)
456 *red_y = info_ptr->int_y_red;
457 if (green_x != NULL)
458 *green_x = info_ptr->int_x_green;
459 if (green_y != NULL)
460 *green_y = info_ptr->int_y_green;
461 if (blue_x != NULL)
462 *blue_x = info_ptr->int_x_blue;
463 if (blue_y != NULL)
464 *blue_y = info_ptr->int_y_blue;
465 return (PNG_INFO_cHRM);
466 }
467 return (0);
468}
469#endif
470#endif
471
b61cc19c 472#ifdef PNG_gAMA_SUPPORTED
0272a10d
VZ
473#ifdef PNG_FLOATING_POINT_SUPPORTED
474png_uint_32 PNGAPI
475png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
476{
b61cc19c
PC
477 png_debug1(1, "in %s retrieval function", "gAMA");
478
0272a10d
VZ
479 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
480 && file_gamma != NULL)
481 {
0272a10d
VZ
482 *file_gamma = (double)info_ptr->gamma;
483 return (PNG_INFO_gAMA);
484 }
485 return (0);
486}
487#endif
488#ifdef PNG_FIXED_POINT_SUPPORTED
489png_uint_32 PNGAPI
490png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
491 png_fixed_point *int_file_gamma)
492{
b61cc19c
PC
493 png_debug1(1, "in %s retrieval function", "gAMA");
494
0272a10d
VZ
495 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
496 && int_file_gamma != NULL)
497 {
0272a10d
VZ
498 *int_file_gamma = info_ptr->int_gamma;
499 return (PNG_INFO_gAMA);
500 }
501 return (0);
502}
503#endif
504#endif
505
b61cc19c 506#ifdef PNG_sRGB_SUPPORTED
0272a10d
VZ
507png_uint_32 PNGAPI
508png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
509{
b61cc19c
PC
510 png_debug1(1, "in %s retrieval function", "sRGB");
511
0272a10d
VZ
512 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
513 && file_srgb_intent != NULL)
514 {
0272a10d
VZ
515 *file_srgb_intent = (int)info_ptr->srgb_intent;
516 return (PNG_INFO_sRGB);
517 }
518 return (0);
519}
520#endif
521
b61cc19c 522#ifdef PNG_iCCP_SUPPORTED
0272a10d
VZ
523png_uint_32 PNGAPI
524png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
525 png_charpp name, int *compression_type,
526 png_charpp profile, png_uint_32 *proflen)
527{
b61cc19c
PC
528 png_debug1(1, "in %s retrieval function", "iCCP");
529
0272a10d
VZ
530 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
531 && name != NULL && profile != NULL && proflen != NULL)
532 {
0272a10d
VZ
533 *name = info_ptr->iccp_name;
534 *profile = info_ptr->iccp_profile;
b61cc19c
PC
535 /* Compression_type is a dummy so the API won't have to change
536 * if we introduce multiple compression types later.
537 */
0272a10d
VZ
538 *proflen = (int)info_ptr->iccp_proflen;
539 *compression_type = (int)info_ptr->iccp_compression;
540 return (PNG_INFO_iCCP);
541 }
542 return (0);
543}
544#endif
545
b61cc19c 546#ifdef PNG_sPLT_SUPPORTED
0272a10d
VZ
547png_uint_32 PNGAPI
548png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
549 png_sPLT_tpp spalettes)
550{
551 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
552 {
553 *spalettes = info_ptr->splt_palettes;
554 return ((png_uint_32)info_ptr->splt_palettes_num);
555 }
556 return (0);
557}
558#endif
559
b61cc19c 560#ifdef PNG_hIST_SUPPORTED
0272a10d
VZ
561png_uint_32 PNGAPI
562png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
563{
b61cc19c
PC
564 png_debug1(1, "in %s retrieval function", "hIST");
565
0272a10d
VZ
566 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
567 && hist != NULL)
568 {
0272a10d
VZ
569 *hist = info_ptr->hist;
570 return (PNG_INFO_hIST);
571 }
572 return (0);
573}
574#endif
575
576png_uint_32 PNGAPI
577png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
578 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
579 int *color_type, int *interlace_type, int *compression_type,
580 int *filter_type)
581
582{
b61cc19c
PC
583 png_debug1(1, "in %s retrieval function", "IHDR");
584
585 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
586 height == NULL || bit_depth == NULL || color_type == NULL)
587 return (0);
588
589 *width = info_ptr->width;
590 *height = info_ptr->height;
591 *bit_depth = info_ptr->bit_depth;
592 *color_type = info_ptr->color_type;
593
594 if (compression_type != NULL)
595 *compression_type = info_ptr->compression_type;
596
597 if (filter_type != NULL)
598 *filter_type = info_ptr->filter_type;
599
600 if (interlace_type != NULL)
601 *interlace_type = info_ptr->interlace_type;
602
603 /* This is redundant if we can be sure that the info_ptr values were all
604 * assigned in png_set_IHDR(). We do the check anyhow in case an
605 * application has ignored our advice not to mess with the members
606 * of info_ptr directly.
607 */
608 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
609 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
610 info_ptr->compression_type, info_ptr->filter_type);
611
612 return (1);
0272a10d
VZ
613}
614
b61cc19c 615#ifdef PNG_oFFs_SUPPORTED
0272a10d
VZ
616png_uint_32 PNGAPI
617png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
618 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
619{
b61cc19c
PC
620 png_debug1(1, "in %s retrieval function", "oFFs");
621
0272a10d
VZ
622 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
623 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
624 {
0272a10d
VZ
625 *offset_x = info_ptr->x_offset;
626 *offset_y = info_ptr->y_offset;
627 *unit_type = (int)info_ptr->offset_unit_type;
628 return (PNG_INFO_oFFs);
629 }
630 return (0);
631}
632#endif
633
b61cc19c 634#ifdef PNG_pCAL_SUPPORTED
0272a10d
VZ
635png_uint_32 PNGAPI
636png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
637 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
638 png_charp *units, png_charpp *params)
639{
b61cc19c
PC
640 png_debug1(1, "in %s retrieval function", "pCAL");
641
0272a10d 642 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
b61cc19c
PC
643 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
644 nparams != NULL && units != NULL && params != NULL)
0272a10d 645 {
0272a10d
VZ
646 *purpose = info_ptr->pcal_purpose;
647 *X0 = info_ptr->pcal_X0;
648 *X1 = info_ptr->pcal_X1;
649 *type = (int)info_ptr->pcal_type;
650 *nparams = (int)info_ptr->pcal_nparams;
651 *units = info_ptr->pcal_units;
652 *params = info_ptr->pcal_params;
653 return (PNG_INFO_pCAL);
654 }
655 return (0);
656}
657#endif
658
b61cc19c 659#ifdef PNG_sCAL_SUPPORTED
0272a10d
VZ
660#ifdef PNG_FLOATING_POINT_SUPPORTED
661png_uint_32 PNGAPI
662png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
663 int *unit, double *width, double *height)
664{
665 if (png_ptr != NULL && info_ptr != NULL &&
b61cc19c 666 (info_ptr->valid & PNG_INFO_sCAL))
0272a10d
VZ
667 {
668 *unit = info_ptr->scal_unit;
669 *width = info_ptr->scal_pixel_width;
670 *height = info_ptr->scal_pixel_height;
671 return (PNG_INFO_sCAL);
672 }
673 return(0);
674}
675#else
676#ifdef PNG_FIXED_POINT_SUPPORTED
677png_uint_32 PNGAPI
678png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
679 int *unit, png_charpp width, png_charpp height)
680{
681 if (png_ptr != NULL && info_ptr != NULL &&
b61cc19c 682 (info_ptr->valid & PNG_INFO_sCAL))
0272a10d
VZ
683 {
684 *unit = info_ptr->scal_unit;
685 *width = info_ptr->scal_s_width;
686 *height = info_ptr->scal_s_height;
687 return (PNG_INFO_sCAL);
688 }
689 return(0);
690}
691#endif
692#endif
693#endif
694
b61cc19c 695#ifdef PNG_pHYs_SUPPORTED
0272a10d
VZ
696png_uint_32 PNGAPI
697png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
698 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
699{
700 png_uint_32 retval = 0;
701
b61cc19c
PC
702 png_debug1(1, "in %s retrieval function", "pHYs");
703
0272a10d
VZ
704 if (png_ptr != NULL && info_ptr != NULL &&
705 (info_ptr->valid & PNG_INFO_pHYs))
706 {
0272a10d
VZ
707 if (res_x != NULL)
708 {
709 *res_x = info_ptr->x_pixels_per_unit;
710 retval |= PNG_INFO_pHYs;
711 }
b61cc19c 712
0272a10d
VZ
713 if (res_y != NULL)
714 {
715 *res_y = info_ptr->y_pixels_per_unit;
716 retval |= PNG_INFO_pHYs;
717 }
b61cc19c 718
0272a10d
VZ
719 if (unit_type != NULL)
720 {
721 *unit_type = (int)info_ptr->phys_unit_type;
722 retval |= PNG_INFO_pHYs;
723 }
724 }
725 return (retval);
726}
727#endif
728
729png_uint_32 PNGAPI
730png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
731 int *num_palette)
732{
b61cc19c
PC
733 png_debug1(1, "in %s retrieval function", "PLTE");
734
0272a10d
VZ
735 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
736 && palette != NULL)
737 {
0272a10d
VZ
738 *palette = info_ptr->palette;
739 *num_palette = info_ptr->num_palette;
970f6abe 740 png_debug1(3, "num_palette = %d", *num_palette);
0272a10d
VZ
741 return (PNG_INFO_PLTE);
742 }
743 return (0);
744}
745
b61cc19c 746#ifdef PNG_sBIT_SUPPORTED
0272a10d
VZ
747png_uint_32 PNGAPI
748png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
749{
b61cc19c
PC
750 png_debug1(1, "in %s retrieval function", "sBIT");
751
0272a10d
VZ
752 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
753 && sig_bit != NULL)
754 {
0272a10d
VZ
755 *sig_bit = &(info_ptr->sig_bit);
756 return (PNG_INFO_sBIT);
757 }
758 return (0);
759}
760#endif
761
b61cc19c 762#ifdef PNG_TEXT_SUPPORTED
0272a10d
VZ
763png_uint_32 PNGAPI
764png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
765 int *num_text)
766{
767 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
768 {
970f6abe 769 png_debug1(1, "in %s retrieval function",
0272a10d
VZ
770 (png_ptr->chunk_name[0] == '\0' ? "text"
771 : (png_const_charp)png_ptr->chunk_name));
b61cc19c 772
0272a10d
VZ
773 if (text_ptr != NULL)
774 *text_ptr = info_ptr->text;
b61cc19c 775
0272a10d
VZ
776 if (num_text != NULL)
777 *num_text = info_ptr->num_text;
b61cc19c 778
0272a10d
VZ
779 return ((png_uint_32)info_ptr->num_text);
780 }
781 if (num_text != NULL)
782 *num_text = 0;
783 return(0);
784}
785#endif
786
b61cc19c 787#ifdef PNG_tIME_SUPPORTED
0272a10d
VZ
788png_uint_32 PNGAPI
789png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
790{
b61cc19c
PC
791 png_debug1(1, "in %s retrieval function", "tIME");
792
0272a10d
VZ
793 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
794 && mod_time != NULL)
795 {
0272a10d
VZ
796 *mod_time = &(info_ptr->mod_time);
797 return (PNG_INFO_tIME);
798 }
799 return (0);
800}
801#endif
802
b61cc19c 803#ifdef PNG_tRNS_SUPPORTED
0272a10d
VZ
804png_uint_32 PNGAPI
805png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
b61cc19c 806 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
0272a10d
VZ
807{
808 png_uint_32 retval = 0;
809 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
810 {
970f6abe 811 png_debug1(1, "in %s retrieval function", "tRNS");
b61cc19c 812
0272a10d
VZ
813 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
814 {
b61cc19c 815 if (trans_alpha != NULL)
0272a10d 816 {
b61cc19c 817 *trans_alpha = info_ptr->trans_alpha;
0272a10d
VZ
818 retval |= PNG_INFO_tRNS;
819 }
b61cc19c
PC
820
821 if (trans_color != NULL)
822 *trans_color = &(info_ptr->trans_color);
0272a10d
VZ
823 }
824 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
825 {
b61cc19c 826 if (trans_color != NULL)
0272a10d 827 {
b61cc19c 828 *trans_color = &(info_ptr->trans_color);
0272a10d
VZ
829 retval |= PNG_INFO_tRNS;
830 }
b61cc19c
PC
831
832 if (trans_alpha != NULL)
833 *trans_alpha = NULL;
0272a10d 834 }
970f6abe 835 if (num_trans != NULL)
0272a10d
VZ
836 {
837 *num_trans = info_ptr->num_trans;
838 retval |= PNG_INFO_tRNS;
839 }
840 }
841 return (retval);
842}
843#endif
844
b61cc19c 845#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
0272a10d
VZ
846png_uint_32 PNGAPI
847png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
848 png_unknown_chunkpp unknowns)
849{
850 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
851 {
852 *unknowns = info_ptr->unknown_chunks;
853 return ((png_uint_32)info_ptr->unknown_chunks_num);
854 }
855 return (0);
856}
857#endif
858
b61cc19c 859#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
0272a10d
VZ
860png_byte PNGAPI
861png_get_rgb_to_gray_status (png_structp png_ptr)
862{
863 return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
864}
865#endif
866
b61cc19c 867#ifdef PNG_USER_CHUNKS_SUPPORTED
0272a10d
VZ
868png_voidp PNGAPI
869png_get_user_chunk_ptr(png_structp png_ptr)
870{
871 return (png_ptr? png_ptr->user_chunk_ptr : NULL);
872}
873#endif
874
b61cc19c 875png_size_t PNGAPI
0272a10d
VZ
876png_get_compression_buffer_size(png_structp png_ptr)
877{
b61cc19c 878 return (png_ptr ? png_ptr->zbuf_size : 0L);
0272a10d 879}
0272a10d 880
b61cc19c
PC
881
882#ifdef PNG_SET_USER_LIMITS_SUPPORTED
883/* These functions were added to libpng 1.2.6 and were enabled
884 * by default in libpng-1.4.0 */
0272a10d 885png_uint_32 PNGAPI
b61cc19c 886png_get_user_width_max (png_structp png_ptr)
0272a10d 887{
b61cc19c 888 return (png_ptr? png_ptr->user_width_max : 0);
0272a10d 889}
0272a10d 890png_uint_32 PNGAPI
b61cc19c 891png_get_user_height_max (png_structp png_ptr)
0272a10d 892{
b61cc19c 893 return (png_ptr? png_ptr->user_height_max : 0);
0272a10d 894}
b61cc19c 895/* This function was added to libpng 1.4.0 */
0272a10d 896png_uint_32 PNGAPI
b61cc19c 897png_get_chunk_cache_max (png_structp png_ptr)
0272a10d 898{
b61cc19c 899 return (png_ptr? png_ptr->user_chunk_cache_max : 0);
0272a10d 900}
b61cc19c
PC
901/* This function was added to libpng 1.4.1 */
902png_alloc_size_t PNGAPI
903png_get_chunk_malloc_max (png_structp png_ptr)
0272a10d 904{
b61cc19c
PC
905 return (png_ptr?
906 png_ptr->user_chunk_malloc_max : 0);
0272a10d 907}
b61cc19c 908#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
0272a10d 909
b61cc19c
PC
910/* These functions were added to libpng 1.4.0 */
911#ifdef PNG_IO_STATE_SUPPORTED
0272a10d 912png_uint_32 PNGAPI
b61cc19c 913png_get_io_state (png_structp png_ptr)
0272a10d 914{
b61cc19c 915 return png_ptr->io_state;
0272a10d 916}
0272a10d 917
b61cc19c
PC
918png_bytep PNGAPI
919png_get_io_chunk_name (png_structp png_ptr)
0272a10d 920{
b61cc19c 921 return png_ptr->chunk_name;
0272a10d 922}
b61cc19c 923#endif /* ?PNG_IO_STATE_SUPPORTED */
0272a10d
VZ
924
925#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */