source: liacs/MIR2010/SourceCode/cximage/png/pngget.c@ 230

Last change on this file since 230 was 95, checked in by Rick van der Zwet, 15 years ago

Bad boy, improper move of directory

File size: 26.8 KB
Line 
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
16png_uint_32 PNGAPI
17png_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
25png_uint_32 PNGAPI
26png_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)
35png_bytepp PNGAPI
36png_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 */
47png_uint_32 PNGAPI
48png_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
57png_uint_32 PNGAPI
58png_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
67png_byte PNGAPI
68png_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
77png_byte PNGAPI
78png_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
87png_byte PNGAPI
88png_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
97png_byte PNGAPI
98png_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
107png_byte PNGAPI
108png_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
117png_uint_32 PNGAPI
118png_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
135png_uint_32 PNGAPI
136png_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
153png_uint_32 PNGAPI
154png_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
173float PNGAPI
174png_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
194png_int_32 PNGAPI
195png_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
212png_int_32 PNGAPI
213png_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
230png_int_32 PNGAPI
231png_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
248png_int_32 PNGAPI
249png_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)
267png_uint_32 PNGAPI
268png_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
274png_uint_32 PNGAPI
275png_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
281png_uint_32 PNGAPI
282png_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
288float PNGAPI
289png_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
295float PNGAPI
296png_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)
303png_uint_32 PNGAPI
304png_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
342png_byte PNGAPI
343png_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
351png_bytep PNGAPI
352png_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)
361png_uint_32 PNGAPI
362png_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
378png_uint_32 PNGAPI
379png_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
408png_uint_32 PNGAPI
409png_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
442png_uint_32 PNGAPI
443png_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
456png_uint_32 PNGAPI
457png_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)
473png_uint_32 PNGAPI
474png_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)
488png_uint_32 PNGAPI
489png_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)
510png_uint_32 PNGAPI
511png_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)
521png_uint_32 PNGAPI
522png_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
535png_uint_32 PNGAPI
536png_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)
582png_uint_32 PNGAPI
583png_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)
600png_uint_32 PNGAPI
601png_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
625png_uint_32 PNGAPI
626png_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
641png_uint_32 PNGAPI
642png_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)
660png_uint_32 PNGAPI
661png_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
690png_uint_32 PNGAPI
691png_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)
707png_uint_32 PNGAPI
708png_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)
722png_uint_32 PNGAPI
723png_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)
744png_uint_32 PNGAPI
745png_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)
759png_uint_32 PNGAPI
760png_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)
798png_uint_32 PNGAPI
799png_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)
809png_byte PNGAPI
810png_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)
817png_voidp PNGAPI
818png_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
825png_uint_32 PNGAPI
826png_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#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
833#ifndef PNG_1_0_X
834/* this function was added to libpng 1.2.0 and should exist by default */
835png_uint_32 PNGAPI
836png_get_asm_flags (png_structp png_ptr)
837{
838#ifdef PNG_MMX_CODE_SUPPORTED
839 return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
840#else
841 return (png_ptr? 0L: 0L);
842#endif
843}
844
845/* this function was added to libpng 1.2.0 and should exist by default */
846png_uint_32 PNGAPI
847png_get_asm_flagmask (int flag_select)
848{
849#ifdef PNG_MMX_CODE_SUPPORTED
850 png_uint_32 settable_asm_flags = 0;
851
852 if (flag_select & PNG_SELECT_READ)
853 settable_asm_flags |=
854 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
855 PNG_ASM_FLAG_MMX_READ_INTERLACE |
856 PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
857 PNG_ASM_FLAG_MMX_READ_FILTER_UP |
858 PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
859 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
860 /* no non-MMX flags yet */
861
862#if 0
863 /* GRR: no write-flags yet, either, but someday... */
864 if (flag_select & PNG_SELECT_WRITE)
865 settable_asm_flags |=
866 PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
867#endif /* 0 */
868
869 return settable_asm_flags; /* _theoretically_ settable capabilities only */
870#else
871 return (0L);
872#endif /* PNG_MMX_CODE_SUPPORTED */
873}
874
875
876 /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
877/* this function was added to libpng 1.2.0 */
878png_uint_32 PNGAPI
879png_get_mmx_flagmask (int flag_select, int *compilerID)
880{
881#if defined(PNG_MMX_CODE_SUPPORTED)
882 png_uint_32 settable_mmx_flags = 0;
883
884 if (flag_select & PNG_SELECT_READ)
885 settable_mmx_flags |=
886 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
887 PNG_ASM_FLAG_MMX_READ_INTERLACE |
888 PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
889 PNG_ASM_FLAG_MMX_READ_FILTER_UP |
890 PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
891 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
892#if 0
893 /* GRR: no MMX write support yet, but someday... */
894 if (flag_select & PNG_SELECT_WRITE)
895 settable_mmx_flags |=
896 PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
897#endif /* 0 */
898
899 if (compilerID != NULL) {
900#ifdef PNG_USE_PNGVCRD
901 *compilerID = 1; /* MSVC */
902#else
903#ifdef PNG_USE_PNGGCCRD
904 *compilerID = 2; /* gcc/gas */
905#else
906 *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
907#endif
908#endif
909 }
910
911 return settable_mmx_flags; /* _theoretically_ settable capabilities only */
912#else
913 return (0L);
914#endif /* ?PNG_MMX_CODE_SUPPORTED */
915}
916
917/* this function was added to libpng 1.2.0 */
918png_byte PNGAPI
919png_get_mmx_bitdepth_threshold (png_structp png_ptr)
920{
921#if defined(PNG_MMX_CODE_SUPPORTED)
922 return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
923#else
924 return (png_ptr? 0: 0);
925#endif /* ?PNG_MMX_CODE_SUPPORTED */
926}
927
928/* this function was added to libpng 1.2.0 */
929png_uint_32 PNGAPI
930png_get_mmx_rowbytes_threshold (png_structp png_ptr)
931{
932#if defined(PNG_MMX_CODE_SUPPORTED)
933 return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
934#else
935 return (png_ptr? 0L: 0L);
936#endif /* ?PNG_MMX_CODE_SUPPORTED */
937}
938#endif /* ?PNG_1_0_X */
939#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
940
941#ifdef PNG_SET_USER_LIMITS_SUPPORTED
942/* these functions were added to libpng 1.2.6 */
943png_uint_32 PNGAPI
944png_get_user_width_max (png_structp png_ptr)
945{
946 return (png_ptr? png_ptr->user_width_max : 0);
947}
948png_uint_32 PNGAPI
949png_get_user_height_max (png_structp png_ptr)
950{
951 return (png_ptr? png_ptr->user_height_max : 0);
952}
953#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
954
955#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
Note: See TracBrowser for help on using the repository browser.