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