]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | |
2 | /* pngget.c - retrieval of values from info struct | |
3 | * | |
a626cc03 | 4 | * libpng 1.0.3 - January 14, 1999 |
c801d85f KB |
5 | * For conditions of distribution and use, see copyright notice in png.h |
6 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. | |
7 | * Copyright (c) 1996, 1997 Andreas Dilger | |
a626cc03 | 8 | * Copyright (c) 1998, 1999 Glenn Randers-Pehrson |
c801d85f KB |
9 | */ |
10 | ||
11 | #define PNG_INTERNAL | |
a626cc03 | 12 | #include "png.h" |
c801d85f KB |
13 | |
14 | png_uint_32 | |
15 | png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) | |
16 | { | |
17 | if (png_ptr != NULL && info_ptr != NULL) | |
18 | return(info_ptr->valid & flag); | |
19 | else | |
20 | return(0); | |
21 | } | |
22 | ||
23 | png_uint_32 | |
24 | png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) | |
25 | { | |
26 | if (png_ptr != NULL && info_ptr != NULL) | |
27 | return(info_ptr->rowbytes); | |
28 | else | |
29 | return(0); | |
30 | } | |
31 | ||
32 | #ifdef PNG_EASY_ACCESS_SUPPORTED | |
33 | /* easy access to info, added in libpng-0.99 */ | |
34 | png_uint_32 | |
35 | png_get_image_width(png_structp png_ptr, png_infop info_ptr) | |
36 | { | |
37 | if (png_ptr != NULL && info_ptr != NULL) | |
38 | { | |
39 | return info_ptr->width; | |
40 | } | |
41 | return (0); | |
42 | } | |
43 | ||
44 | png_uint_32 | |
45 | png_get_image_height(png_structp png_ptr, png_infop info_ptr) | |
46 | { | |
47 | if (png_ptr != NULL && info_ptr != NULL) | |
48 | { | |
49 | return info_ptr->height; | |
50 | } | |
51 | return (0); | |
52 | } | |
53 | ||
54 | png_byte | |
55 | png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) | |
56 | { | |
57 | if (png_ptr != NULL && info_ptr != NULL) | |
58 | { | |
59 | return info_ptr->bit_depth; | |
60 | } | |
61 | return (0); | |
62 | } | |
63 | ||
64 | png_byte | |
65 | png_get_color_type(png_structp png_ptr, png_infop info_ptr) | |
66 | { | |
67 | if (png_ptr != NULL && info_ptr != NULL) | |
68 | { | |
69 | return info_ptr->color_type; | |
70 | } | |
71 | return (0); | |
72 | } | |
73 | ||
74 | png_byte | |
75 | png_get_filter_type(png_structp png_ptr, png_infop info_ptr) | |
76 | { | |
77 | if (png_ptr != NULL && info_ptr != NULL) | |
78 | { | |
79 | return info_ptr->filter_type; | |
80 | } | |
81 | return (0); | |
82 | } | |
83 | ||
84 | png_byte | |
85 | png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) | |
86 | { | |
87 | if (png_ptr != NULL && info_ptr != NULL) | |
88 | { | |
89 | return info_ptr->interlace_type; | |
90 | } | |
91 | return (0); | |
92 | } | |
93 | ||
94 | png_byte | |
95 | png_get_compression_type(png_structp png_ptr, png_infop info_ptr) | |
96 | { | |
97 | if (png_ptr != NULL && info_ptr != NULL) | |
98 | { | |
99 | return info_ptr->compression_type; | |
100 | } | |
101 | return (0); | |
102 | } | |
103 | ||
104 | png_uint_32 | |
105 | png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) | |
106 | { | |
107 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) | |
108 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) | |
109 | { | |
110 | png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter"); | |
111 | if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) | |
112 | return (0); | |
113 | else return (info_ptr->x_pixels_per_unit); | |
114 | } | |
115 | else | |
116 | #endif | |
117 | return (0); | |
118 | } | |
119 | ||
120 | png_uint_32 | |
121 | png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) | |
122 | { | |
123 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) | |
124 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) | |
125 | { | |
126 | png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); | |
127 | if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) | |
128 | return (0); | |
129 | else return (info_ptr->y_pixels_per_unit); | |
130 | } | |
131 | else | |
132 | #endif | |
133 | return (0); | |
134 | } | |
135 | ||
136 | png_uint_32 | |
137 | png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) | |
138 | { | |
139 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) | |
140 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) | |
141 | { | |
142 | png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter"); | |
143 | if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER || | |
144 | info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) | |
145 | return (0); | |
146 | else return (info_ptr->x_pixels_per_unit); | |
147 | } | |
148 | else | |
149 | #endif | |
150 | return (0); | |
151 | } | |
152 | ||
153 | float | |
154 | png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) | |
155 | { | |
156 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) | |
157 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) | |
158 | { | |
159 | png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio"); | |
160 | if (info_ptr->x_pixels_per_unit == 0) | |
161 | return ((float)0.0); | |
162 | else | |
163 | return ((float)info_ptr->y_pixels_per_unit | |
164 | /(float)info_ptr->x_pixels_per_unit); | |
165 | } | |
166 | else | |
167 | #endif | |
168 | return ((float)0.0); | |
169 | } | |
170 | ||
171 | png_uint_32 | |
172 | png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) | |
173 | { | |
174 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) | |
175 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) | |
176 | { | |
177 | png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); | |
178 | if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) | |
179 | return (0); | |
180 | else return (info_ptr->x_offset); | |
181 | } | |
182 | else | |
183 | #endif | |
184 | return (0); | |
185 | } | |
186 | ||
187 | png_uint_32 | |
188 | png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) | |
189 | { | |
190 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) | |
191 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) | |
192 | { | |
193 | png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); | |
194 | if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) | |
195 | return (0); | |
196 | else return (info_ptr->y_offset); | |
197 | } | |
198 | else | |
199 | #endif | |
200 | return (0); | |
201 | } | |
202 | ||
203 | png_uint_32 | |
204 | png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) | |
205 | { | |
206 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) | |
207 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) | |
208 | { | |
209 | png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); | |
210 | if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) | |
211 | return (0); | |
212 | else return (info_ptr->x_offset); | |
213 | } | |
214 | else | |
215 | #endif | |
216 | return (0); | |
217 | } | |
218 | ||
219 | png_uint_32 | |
220 | png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) | |
221 | { | |
222 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) | |
223 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) | |
224 | { | |
225 | png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); | |
226 | if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) | |
227 | return (0); | |
228 | else return (info_ptr->y_offset); | |
229 | } | |
230 | else | |
231 | #endif | |
232 | return (0); | |
233 | } | |
234 | ||
235 | #ifdef PNG_INCH_CONVERSIONS | |
236 | png_uint_32 | |
237 | png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) | |
238 | { | |
239 | return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) | |
240 | *.03937 +.5) | |
241 | } | |
242 | ||
243 | png_uint_32 | |
244 | png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) | |
245 | { | |
246 | return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) | |
247 | *.03937 +.5) | |
248 | } | |
249 | ||
250 | png_uint_32 | |
251 | png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) | |
252 | { | |
253 | return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) | |
254 | *.03937 +.5) | |
255 | } | |
256 | ||
257 | float | |
258 | png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) | |
259 | { | |
260 | return ((float)png_get_x_offset_microns(png_ptr, info_ptr) | |
261 | *.03937/1000000. +.5) | |
262 | } | |
263 | ||
264 | float | |
265 | png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) | |
266 | { | |
267 | return ((float)png_get_y_offset_microns(png_ptr, info_ptr) | |
268 | *.03937/1000000. +.5) | |
269 | } | |
270 | ||
271 | #if defined(PNG_READ_pHYs_SUPPORTED) | |
272 | png_uint_32 | |
273 | png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, | |
274 | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) | |
275 | { | |
276 | png_uint_32 retval = 0; | |
277 | ||
278 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs) | |
279 | { | |
280 | png_debug1(1, "in %s retrieval function\n", "pHYs"); | |
281 | if (res_x != NULL) | |
282 | { | |
283 | *res_x = info_ptr->x_pixels_per_unit; | |
284 | retval |= PNG_INFO_pHYs; | |
285 | } | |
286 | if (res_y != NULL) | |
287 | { | |
288 | *res_y = info_ptr->y_pixels_per_unit; | |
289 | retval |= PNG_INFO_pHYs; | |
290 | } | |
291 | if (unit_type != NULL) | |
292 | { | |
293 | *unit_type = (int)info_ptr->phys_unit_type; | |
294 | retval |= PNG_INFO_pHYs; | |
295 | if(unit_type == 1) | |
296 | { | |
297 | if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50); | |
298 | if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50); | |
299 | } | |
300 | } | |
301 | } | |
302 | return (retval); | |
303 | } | |
a626cc03 | 304 | #endif /* PNG_READ_pHYs_SUPPORTED */ |
c801d85f KB |
305 | #endif /* PNG_INCH_CONVERSIONS */ |
306 | ||
307 | /* png_get_channels really belongs in here, too, but it's been around longer */ | |
a626cc03 | 308 | |
c801d85f KB |
309 | #endif /* PNG_EASY_ACCESS_SUPPORTED */ |
310 | ||
311 | png_byte | |
312 | png_get_channels(png_structp png_ptr, png_infop info_ptr) | |
313 | { | |
314 | if (png_ptr != NULL && info_ptr != NULL) | |
315 | return(info_ptr->channels); | |
316 | else | |
317 | return (0); | |
318 | } | |
319 | ||
320 | png_bytep | |
321 | png_get_signature(png_structp png_ptr, png_infop info_ptr) | |
322 | { | |
323 | if (png_ptr != NULL && info_ptr != NULL) | |
324 | return(info_ptr->signature); | |
325 | else | |
326 | return (NULL); | |
327 | } | |
328 | ||
329 | #if defined(PNG_READ_bKGD_SUPPORTED) | |
330 | png_uint_32 | |
331 | png_get_bKGD(png_structp png_ptr, png_infop info_ptr, | |
332 | png_color_16p *background) | |
333 | { | |
334 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) | |
335 | && background != NULL) | |
336 | { | |
337 | png_debug1(1, "in %s retrieval function\n", "bKGD"); | |
338 | *background = &(info_ptr->background); | |
339 | return (PNG_INFO_bKGD); | |
340 | } | |
341 | return (0); | |
342 | } | |
343 | #endif | |
344 | ||
345 | #if defined(PNG_READ_cHRM_SUPPORTED) | |
346 | png_uint_32 | |
347 | png_get_cHRM(png_structp png_ptr, png_infop info_ptr, | |
348 | double *white_x, double *white_y, double *red_x, double *red_y, | |
349 | double *green_x, double *green_y, double *blue_x, double *blue_y) | |
350 | { | |
351 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) | |
352 | { | |
353 | png_debug1(1, "in %s retrieval function\n", "cHRM"); | |
354 | if (white_x != NULL) | |
355 | *white_x = (double)info_ptr->x_white; | |
356 | if (white_y != NULL) | |
357 | *white_y = (double)info_ptr->y_white; | |
358 | if (red_x != NULL) | |
359 | *red_x = (double)info_ptr->x_red; | |
360 | if (red_y != NULL) | |
361 | *red_y = (double)info_ptr->y_red; | |
362 | if (green_x != NULL) | |
363 | *green_x = (double)info_ptr->x_green; | |
364 | if (green_y != NULL) | |
365 | *green_y = (double)info_ptr->y_green; | |
366 | if (blue_x != NULL) | |
367 | *blue_x = (double)info_ptr->x_blue; | |
368 | if (blue_y != NULL) | |
369 | *blue_y = (double)info_ptr->y_blue; | |
370 | return (PNG_INFO_cHRM); | |
371 | } | |
372 | return (0); | |
373 | } | |
374 | #endif | |
375 | ||
376 | #if defined(PNG_READ_gAMA_SUPPORTED) | |
377 | png_uint_32 | |
378 | png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) | |
379 | { | |
380 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) | |
381 | && file_gamma != NULL) | |
382 | { | |
383 | png_debug1(1, "in %s retrieval function\n", "gAMA"); | |
384 | *file_gamma = (double)info_ptr->gamma; | |
385 | return (PNG_INFO_gAMA); | |
386 | } | |
387 | return (0); | |
388 | } | |
389 | #endif | |
390 | ||
391 | #if defined(PNG_READ_sRGB_SUPPORTED) | |
392 | png_uint_32 | |
393 | png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) | |
394 | { | |
395 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) | |
396 | && file_srgb_intent != NULL) | |
397 | { | |
398 | png_debug1(1, "in %s retrieval function\n", "sRGB"); | |
399 | *file_srgb_intent = (int)info_ptr->srgb_intent; | |
400 | return (PNG_INFO_sRGB); | |
401 | } | |
402 | return (0); | |
403 | } | |
404 | #endif | |
405 | ||
406 | #if defined(PNG_READ_hIST_SUPPORTED) | |
407 | png_uint_32 | |
408 | png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) | |
409 | { | |
410 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) | |
411 | && hist != NULL) | |
412 | { | |
413 | png_debug1(1, "in %s retrieval function\n", "hIST"); | |
414 | *hist = info_ptr->hist; | |
415 | return (PNG_INFO_hIST); | |
416 | } | |
417 | return (0); | |
418 | } | |
419 | #endif | |
420 | ||
421 | png_uint_32 | |
422 | png_get_IHDR(png_structp png_ptr, png_infop info_ptr, | |
423 | png_uint_32 *width, png_uint_32 *height, int *bit_depth, | |
424 | int *color_type, int *interlace_type, int *compression_type, | |
425 | int *filter_type) | |
a626cc03 | 426 | |
c801d85f KB |
427 | { |
428 | if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && | |
429 | bit_depth != NULL && color_type != NULL) | |
430 | { | |
431 | int pixel_depth, channels; | |
432 | png_uint_32 rowbytes_per_pixel; | |
433 | ||
434 | png_debug1(1, "in %s retrieval function\n", "IHDR"); | |
435 | *width = info_ptr->width; | |
436 | *height = info_ptr->height; | |
437 | *bit_depth = info_ptr->bit_depth; | |
438 | *color_type = info_ptr->color_type; | |
439 | if (compression_type != NULL) | |
440 | *compression_type = info_ptr->compression_type; | |
441 | if (filter_type != NULL) | |
442 | *filter_type = info_ptr->filter_type; | |
443 | if (interlace_type != NULL) | |
444 | *interlace_type = info_ptr->interlace_type; | |
445 | ||
446 | /* check for potential overflow of rowbytes */ | |
447 | if (*color_type == PNG_COLOR_TYPE_PALETTE) | |
448 | channels = 1; | |
449 | else if (*color_type & PNG_COLOR_MASK_COLOR) | |
450 | channels = 3; | |
451 | else | |
452 | channels = 1; | |
453 | if (*color_type & PNG_COLOR_MASK_ALPHA) | |
454 | channels++; | |
455 | pixel_depth = *bit_depth * channels; | |
456 | rowbytes_per_pixel = (pixel_depth + 7) >> 3; | |
457 | if ((*width > (png_uint_32)2147483647L/rowbytes_per_pixel)) | |
458 | { | |
459 | png_warning(png_ptr, | |
460 | "Width too large for libpng to process image data."); | |
461 | } | |
462 | return (1); | |
463 | } | |
464 | return (0); | |
465 | } | |
466 | ||
467 | #if defined(PNG_READ_oFFs_SUPPORTED) | |
468 | png_uint_32 | |
469 | png_get_oFFs(png_structp png_ptr, png_infop info_ptr, | |
470 | png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type) | |
471 | { | |
472 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) | |
473 | && offset_x != NULL && offset_y != NULL && unit_type != NULL) | |
474 | { | |
475 | png_debug1(1, "in %s retrieval function\n", "oFFs"); | |
476 | *offset_x = info_ptr->x_offset; | |
477 | *offset_y = info_ptr->y_offset; | |
478 | *unit_type = (int)info_ptr->offset_unit_type; | |
479 | return (PNG_INFO_oFFs); | |
480 | } | |
481 | return (0); | |
482 | } | |
483 | #endif | |
484 | ||
485 | #if defined(PNG_READ_pCAL_SUPPORTED) | |
486 | png_uint_32 | |
487 | png_get_pCAL(png_structp png_ptr, png_infop info_ptr, | |
488 | png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, | |
489 | png_charp *units, png_charpp *params) | |
490 | { | |
491 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL && | |
492 | purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && | |
493 | nparams != NULL && units != NULL && params != NULL) | |
494 | { | |
495 | png_debug1(1, "in %s retrieval function\n", "pCAL"); | |
496 | *purpose = info_ptr->pcal_purpose; | |
497 | *X0 = info_ptr->pcal_X0; | |
498 | *X1 = info_ptr->pcal_X1; | |
499 | *type = (int)info_ptr->pcal_type; | |
500 | *nparams = (int)info_ptr->pcal_nparams; | |
501 | *units = info_ptr->pcal_units; | |
502 | *params = info_ptr->pcal_params; | |
503 | return (PNG_INFO_pCAL); | |
504 | } | |
505 | return (0); | |
506 | } | |
507 | #endif | |
508 | ||
509 | #if defined(PNG_READ_pHYs_SUPPORTED) | |
510 | png_uint_32 | |
511 | png_get_pHYs(png_structp png_ptr, png_infop info_ptr, | |
512 | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) | |
513 | { | |
514 | png_uint_32 retval = 0; | |
515 | ||
516 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs) | |
517 | { | |
518 | png_debug1(1, "in %s retrieval function\n", "pHYs"); | |
519 | if (res_x != NULL) | |
520 | { | |
521 | *res_x = info_ptr->x_pixels_per_unit; | |
522 | retval |= PNG_INFO_pHYs; | |
523 | } | |
524 | if (res_y != NULL) | |
525 | { | |
526 | *res_y = info_ptr->y_pixels_per_unit; | |
527 | retval |= PNG_INFO_pHYs; | |
528 | } | |
529 | if (unit_type != NULL) | |
530 | { | |
531 | *unit_type = (int)info_ptr->phys_unit_type; | |
532 | retval |= PNG_INFO_pHYs; | |
533 | } | |
534 | } | |
535 | return (retval); | |
536 | } | |
537 | #endif | |
538 | ||
539 | png_uint_32 | |
540 | png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, | |
541 | int *num_palette) | |
542 | { | |
543 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE && | |
544 | palette != NULL) | |
545 | { | |
546 | png_debug1(1, "in %s retrieval function\n", "PLTE"); | |
547 | *palette = info_ptr->palette; | |
548 | *num_palette = info_ptr->num_palette; | |
549 | png_debug1(3, "num_palette = %d\n", *num_palette); | |
550 | return (PNG_INFO_PLTE); | |
551 | } | |
552 | return (0); | |
553 | } | |
554 | ||
555 | #if defined(PNG_READ_sBIT_SUPPORTED) | |
556 | png_uint_32 | |
557 | png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) | |
558 | { | |
559 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT && | |
560 | sig_bit != NULL) | |
561 | { | |
562 | png_debug1(1, "in %s retrieval function\n", "sBIT"); | |
563 | *sig_bit = &(info_ptr->sig_bit); | |
564 | return (PNG_INFO_sBIT); | |
565 | } | |
566 | return (0); | |
567 | } | |
568 | #endif | |
569 | ||
570 | #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED) | |
571 | png_uint_32 | |
572 | png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, | |
573 | int *num_text) | |
574 | { | |
575 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) | |
576 | { | |
577 | png_debug1(1, "in %s retrieval function\n", | |
578 | (png_ptr->chunk_name[0] == '\0' ? "text" | |
579 | : (png_const_charp)png_ptr->chunk_name)); | |
580 | if (text_ptr != NULL) | |
581 | *text_ptr = info_ptr->text; | |
582 | if (num_text != NULL) | |
583 | *num_text = info_ptr->num_text; | |
584 | return ((png_uint_32)info_ptr->num_text); | |
585 | } | |
586 | return(0); | |
587 | } | |
588 | #endif | |
589 | ||
590 | #if defined(PNG_READ_tIME_SUPPORTED) | |
591 | png_uint_32 | |
592 | png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) | |
593 | { | |
594 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME && | |
595 | mod_time != NULL) | |
596 | { | |
597 | png_debug1(1, "in %s retrieval function\n", "tIME"); | |
598 | *mod_time = &(info_ptr->mod_time); | |
599 | return (PNG_INFO_tIME); | |
600 | } | |
601 | return (0); | |
602 | } | |
603 | #endif | |
604 | ||
605 | #if defined(PNG_READ_tRNS_SUPPORTED) | |
606 | png_uint_32 | |
607 | png_get_tRNS(png_structp png_ptr, png_infop info_ptr, | |
608 | png_bytep *trans, int *num_trans, png_color_16p *trans_values) | |
609 | { | |
610 | png_uint_32 retval = 0; | |
611 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS) | |
612 | { | |
613 | png_debug1(1, "in %s retrieval function\n", "tRNS"); | |
614 | if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | |
615 | { | |
616 | if (trans != NULL) | |
617 | { | |
618 | *trans = info_ptr->trans; | |
619 | retval |= PNG_INFO_tRNS; | |
620 | } | |
621 | if (trans_values != NULL) | |
622 | *trans_values = &(info_ptr->trans_values); | |
623 | } | |
624 | else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ | |
625 | { | |
626 | if (trans_values != NULL) | |
627 | { | |
628 | *trans_values = &(info_ptr->trans_values); | |
629 | retval |= PNG_INFO_tRNS; | |
630 | } | |
631 | if(trans != NULL) | |
632 | *trans = NULL; | |
633 | } | |
634 | if(num_trans != NULL) | |
635 | { | |
636 | *num_trans = info_ptr->num_trans; | |
637 | retval |= PNG_INFO_tRNS; | |
638 | } | |
639 | } | |
640 | return (retval); | |
641 | } | |
642 | #endif | |
643 | ||
a626cc03 RR |
644 | #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) |
645 | png_byte | |
646 | png_get_rgb_to_gray_status (png_structp png_ptr) | |
647 | { | |
648 | return png_ptr->rgb_to_gray_status; | |
649 | } | |
650 | #endif |