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