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