[HEADERS]
[reactos.git] / rosapps / lib / libpng / pngget.c
1
2 /* pngget.c - retrieval of values from info struct
3 *
4 * Last changed in libpng 1.2.15 January 5, 2007
5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2007 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 {
516 *spalettes = info_ptr->splt_palettes;
517 return ((png_uint_32)info_ptr->splt_palettes_num);
518 }
519 return (0);
520 }
521 #endif
522
523 #if defined(PNG_hIST_SUPPORTED)
524 png_uint_32 PNGAPI
525 png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
526 {
527 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
528 && hist != NULL)
529 {
530 png_debug1(1, "in %s retrieval function\n", "hIST");
531 *hist = info_ptr->hist;
532 return (PNG_INFO_hIST);
533 }
534 return (0);
535 }
536 #endif
537
538 png_uint_32 PNGAPI
539 png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
540 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
541 int *color_type, int *interlace_type, int *compression_type,
542 int *filter_type)
543
544 {
545 if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
546 bit_depth != NULL && color_type != NULL)
547 {
548 png_debug1(1, "in %s retrieval function\n", "IHDR");
549 *width = info_ptr->width;
550 *height = info_ptr->height;
551 *bit_depth = info_ptr->bit_depth;
552 if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
553 png_error(png_ptr, "Invalid bit depth");
554 *color_type = info_ptr->color_type;
555 if (info_ptr->color_type > 6)
556 png_error(png_ptr, "Invalid color type");
557 if (compression_type != NULL)
558 *compression_type = info_ptr->compression_type;
559 if (filter_type != NULL)
560 *filter_type = info_ptr->filter_type;
561 if (interlace_type != NULL)
562 *interlace_type = info_ptr->interlace_type;
563
564 /* check for potential overflow of rowbytes */
565 if (*width == 0 || *width > PNG_UINT_31_MAX)
566 png_error(png_ptr, "Invalid image width");
567 if (*height == 0 || *height > PNG_UINT_31_MAX)
568 png_error(png_ptr, "Invalid image height");
569 if (info_ptr->width > (PNG_UINT_32_MAX
570 >> 3) /* 8-byte RGBA pixels */
571 - 64 /* bigrowbuf hack */
572 - 1 /* filter byte */
573 - 7*8 /* rounding of width to multiple of 8 pixels */
574 - 8) /* extra max_pixel_depth pad */
575 {
576 png_warning(png_ptr,
577 "Width too large for libpng to process image data.");
578 }
579 return (1);
580 }
581 return (0);
582 }
583
584 #if defined(PNG_oFFs_SUPPORTED)
585 png_uint_32 PNGAPI
586 png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
587 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
588 {
589 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
590 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
591 {
592 png_debug1(1, "in %s retrieval function\n", "oFFs");
593 *offset_x = info_ptr->x_offset;
594 *offset_y = info_ptr->y_offset;
595 *unit_type = (int)info_ptr->offset_unit_type;
596 return (PNG_INFO_oFFs);
597 }
598 return (0);
599 }
600 #endif
601
602 #if defined(PNG_pCAL_SUPPORTED)
603 png_uint_32 PNGAPI
604 png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
605 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
606 png_charp *units, png_charpp *params)
607 {
608 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
609 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
610 nparams != NULL && units != NULL && params != NULL)
611 {
612 png_debug1(1, "in %s retrieval function\n", "pCAL");
613 *purpose = info_ptr->pcal_purpose;
614 *X0 = info_ptr->pcal_X0;
615 *X1 = info_ptr->pcal_X1;
616 *type = (int)info_ptr->pcal_type;
617 *nparams = (int)info_ptr->pcal_nparams;
618 *units = info_ptr->pcal_units;
619 *params = info_ptr->pcal_params;
620 return (PNG_INFO_pCAL);
621 }
622 return (0);
623 }
624 #endif
625
626 #if defined(PNG_sCAL_SUPPORTED)
627 #ifdef PNG_FLOATING_POINT_SUPPORTED
628 png_uint_32 PNGAPI
629 png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
630 int *unit, double *width, double *height)
631 {
632 if (png_ptr != NULL && info_ptr != NULL &&
633 (info_ptr->valid & PNG_INFO_sCAL))
634 {
635 *unit = info_ptr->scal_unit;
636 *width = info_ptr->scal_pixel_width;
637 *height = info_ptr->scal_pixel_height;
638 return (PNG_INFO_sCAL);
639 }
640 return(0);
641 }
642 #else
643 #ifdef PNG_FIXED_POINT_SUPPORTED
644 png_uint_32 PNGAPI
645 png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
646 int *unit, png_charpp width, png_charpp height)
647 {
648 if (png_ptr != NULL && info_ptr != NULL &&
649 (info_ptr->valid & PNG_INFO_sCAL))
650 {
651 *unit = info_ptr->scal_unit;
652 *width = info_ptr->scal_s_width;
653 *height = info_ptr->scal_s_height;
654 return (PNG_INFO_sCAL);
655 }
656 return(0);
657 }
658 #endif
659 #endif
660 #endif
661
662 #if defined(PNG_pHYs_SUPPORTED)
663 png_uint_32 PNGAPI
664 png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
665 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
666 {
667 png_uint_32 retval = 0;
668
669 if (png_ptr != NULL && info_ptr != NULL &&
670 (info_ptr->valid & PNG_INFO_pHYs))
671 {
672 png_debug1(1, "in %s retrieval function\n", "pHYs");
673 if (res_x != NULL)
674 {
675 *res_x = info_ptr->x_pixels_per_unit;
676 retval |= PNG_INFO_pHYs;
677 }
678 if (res_y != NULL)
679 {
680 *res_y = info_ptr->y_pixels_per_unit;
681 retval |= PNG_INFO_pHYs;
682 }
683 if (unit_type != NULL)
684 {
685 *unit_type = (int)info_ptr->phys_unit_type;
686 retval |= PNG_INFO_pHYs;
687 }
688 }
689 return (retval);
690 }
691 #endif
692
693 png_uint_32 PNGAPI
694 png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
695 int *num_palette)
696 {
697 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
698 && palette != NULL)
699 {
700 png_debug1(1, "in %s retrieval function\n", "PLTE");
701 *palette = info_ptr->palette;
702 *num_palette = info_ptr->num_palette;
703 png_debug1(3, "num_palette = %d\n", *num_palette);
704 return (PNG_INFO_PLTE);
705 }
706 return (0);
707 }
708
709 #if defined(PNG_sBIT_SUPPORTED)
710 png_uint_32 PNGAPI
711 png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
712 {
713 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
714 && sig_bit != NULL)
715 {
716 png_debug1(1, "in %s retrieval function\n", "sBIT");
717 *sig_bit = &(info_ptr->sig_bit);
718 return (PNG_INFO_sBIT);
719 }
720 return (0);
721 }
722 #endif
723
724 #if defined(PNG_TEXT_SUPPORTED)
725 png_uint_32 PNGAPI
726 png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
727 int *num_text)
728 {
729 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
730 {
731 png_debug1(1, "in %s retrieval function\n",
732 (png_ptr->chunk_name[0] == '\0' ? "text"
733 : (png_const_charp)png_ptr->chunk_name));
734 if (text_ptr != NULL)
735 *text_ptr = info_ptr->text;
736 if (num_text != NULL)
737 *num_text = info_ptr->num_text;
738 return ((png_uint_32)info_ptr->num_text);
739 }
740 if (num_text != NULL)
741 *num_text = 0;
742 return(0);
743 }
744 #endif
745
746 #if defined(PNG_tIME_SUPPORTED)
747 png_uint_32 PNGAPI
748 png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
749 {
750 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
751 && mod_time != NULL)
752 {
753 png_debug1(1, "in %s retrieval function\n", "tIME");
754 *mod_time = &(info_ptr->mod_time);
755 return (PNG_INFO_tIME);
756 }
757 return (0);
758 }
759 #endif
760
761 #if defined(PNG_tRNS_SUPPORTED)
762 png_uint_32 PNGAPI
763 png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
764 png_bytep *trans, int *num_trans, png_color_16p *trans_values)
765 {
766 png_uint_32 retval = 0;
767 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
768 {
769 png_debug1(1, "in %s retrieval function\n", "tRNS");
770 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
771 {
772 if (trans != NULL)
773 {
774 *trans = info_ptr->trans;
775 retval |= PNG_INFO_tRNS;
776 }
777 if (trans_values != NULL)
778 *trans_values = &(info_ptr->trans_values);
779 }
780 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
781 {
782 if (trans_values != NULL)
783 {
784 *trans_values = &(info_ptr->trans_values);
785 retval |= PNG_INFO_tRNS;
786 }
787 if(trans != NULL)
788 *trans = NULL;
789 }
790 if(num_trans != NULL)
791 {
792 *num_trans = info_ptr->num_trans;
793 retval |= PNG_INFO_tRNS;
794 }
795 }
796 return (retval);
797 }
798 #endif
799
800 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
801 png_uint_32 PNGAPI
802 png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
803 png_unknown_chunkpp unknowns)
804 {
805 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
806 {
807 *unknowns = info_ptr->unknown_chunks;
808 return ((png_uint_32)info_ptr->unknown_chunks_num);
809 }
810 return (0);
811 }
812 #endif
813
814 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
815 png_byte PNGAPI
816 png_get_rgb_to_gray_status (png_structp png_ptr)
817 {
818 return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
819 }
820 #endif
821
822 #if defined(PNG_USER_CHUNKS_SUPPORTED)
823 png_voidp PNGAPI
824 png_get_user_chunk_ptr(png_structp png_ptr)
825 {
826 return (png_ptr? png_ptr->user_chunk_ptr : NULL);
827 }
828 #endif
829
830 #ifdef PNG_WRITE_SUPPORTED
831 png_uint_32 PNGAPI
832 png_get_compression_buffer_size(png_structp png_ptr)
833 {
834 return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
835 }
836 #endif
837
838 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
839 #ifndef PNG_1_0_X
840 /* this function was added to libpng 1.2.0 and should exist by default */
841 png_uint_32 PNGAPI
842 png_get_asm_flags (png_structp png_ptr)
843 {
844 /* obsolete, to be removed from libpng-1.4.0 */
845 return (png_ptr? 0L: 0L);
846 }
847
848 /* this function was added to libpng 1.2.0 and should exist by default */
849 png_uint_32 PNGAPI
850 png_get_asm_flagmask (int flag_select)
851 {
852 /* obsolete, to be removed from libpng-1.4.0 */
853 flag_select=flag_select;
854 return 0L;
855 }
856
857 /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
858 /* this function was added to libpng 1.2.0 */
859 png_uint_32 PNGAPI
860 png_get_mmx_flagmask (int flag_select, int *compilerID)
861 {
862 /* obsolete, to be removed from libpng-1.4.0 */
863 flag_select=flag_select;
864 *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
865 return 0L;
866 }
867
868 /* this function was added to libpng 1.2.0 */
869 png_byte PNGAPI
870 png_get_mmx_bitdepth_threshold (png_structp png_ptr)
871 {
872 /* obsolete, to be removed from libpng-1.4.0 */
873 return (png_ptr? 0: 0);
874 }
875
876 /* this function was added to libpng 1.2.0 */
877 png_uint_32 PNGAPI
878 png_get_mmx_rowbytes_threshold (png_structp png_ptr)
879 {
880 /* obsolete, to be removed from libpng-1.4.0 */
881 return (png_ptr? 0L: 0L);
882 }
883 #endif /* ?PNG_1_0_X */
884 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
885
886 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
887 /* these functions were added to libpng 1.2.6 */
888 png_uint_32 PNGAPI
889 png_get_user_width_max (png_structp png_ptr)
890 {
891 return (png_ptr? png_ptr->user_width_max : 0);
892 }
893 png_uint_32 PNGAPI
894 png_get_user_height_max (png_structp png_ptr)
895 {
896 return (png_ptr? png_ptr->user_height_max : 0);
897 }
898 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
899
900
901 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */