Debian Codegraph @

PNG/libpng/pngget.c

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