Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /* pngget.c - retrieval of values from info struct |
3 | | * |
4 | | * Copyright (c) 2018-2024 Cosmin Truta |
5 | | * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson |
6 | | * Copyright (c) 1996-1997 Andreas Dilger |
7 | | * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. |
8 | | * |
9 | | * This code is released under the libpng license. |
10 | | * For conditions of distribution and use, see the disclaimer |
11 | | * and license in png.h |
12 | | * |
13 | | */ |
14 | | |
15 | | #include "pngpriv.h" |
16 | | |
17 | | #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
18 | | |
19 | | png_uint_32 PNGAPI |
20 | | png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr, |
21 | | png_uint_32 flag) |
22 | 0 | { |
23 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
24 | 0 | { |
25 | 0 | #ifdef PNG_READ_tRNS_SUPPORTED |
26 | | /* png_handle_PLTE() may have canceled a valid tRNS chunk but left the |
27 | | * 'valid' flag for the detection of duplicate chunks. Do not report a |
28 | | * valid tRNS chunk in this case. |
29 | | */ |
30 | 0 | if (flag == PNG_INFO_tRNS && png_ptr->num_trans == 0) |
31 | 0 | return 0; |
32 | 0 | #endif |
33 | | |
34 | 0 | return info_ptr->valid & flag; |
35 | 0 | } |
36 | | |
37 | 0 | return 0; |
38 | 0 | } |
39 | | |
40 | | size_t PNGAPI |
41 | | png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr) |
42 | 0 | { |
43 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
44 | 0 | return info_ptr->rowbytes; |
45 | | |
46 | 0 | return 0; |
47 | 0 | } |
48 | | |
49 | | #ifdef PNG_INFO_IMAGE_SUPPORTED |
50 | | png_bytepp PNGAPI |
51 | | png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr) |
52 | 0 | { |
53 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
54 | 0 | return info_ptr->row_pointers; |
55 | | |
56 | 0 | return 0; |
57 | 0 | } |
58 | | #endif |
59 | | |
60 | | #ifdef PNG_EASY_ACCESS_SUPPORTED |
61 | | /* Easy access to info, added in libpng-0.99 */ |
62 | | png_uint_32 PNGAPI |
63 | | png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr) |
64 | 0 | { |
65 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
66 | 0 | return info_ptr->width; |
67 | | |
68 | 0 | return 0; |
69 | 0 | } |
70 | | |
71 | | png_uint_32 PNGAPI |
72 | | png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr) |
73 | 0 | { |
74 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
75 | 0 | return info_ptr->height; |
76 | | |
77 | 0 | return 0; |
78 | 0 | } |
79 | | |
80 | | png_byte PNGAPI |
81 | | png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr) |
82 | 0 | { |
83 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
84 | 0 | return info_ptr->bit_depth; |
85 | | |
86 | 0 | return 0; |
87 | 0 | } |
88 | | |
89 | | png_byte PNGAPI |
90 | | png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
91 | 0 | { |
92 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
93 | 0 | return info_ptr->color_type; |
94 | | |
95 | 0 | return 0; |
96 | 0 | } |
97 | | |
98 | | png_byte PNGAPI |
99 | | png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
100 | 0 | { |
101 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
102 | 0 | return info_ptr->filter_type; |
103 | | |
104 | 0 | return 0; |
105 | 0 | } |
106 | | |
107 | | png_byte PNGAPI |
108 | | png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
109 | 0 | { |
110 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
111 | 0 | return info_ptr->interlace_type; |
112 | | |
113 | 0 | return 0; |
114 | 0 | } |
115 | | |
116 | | png_byte PNGAPI |
117 | | png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
118 | 0 | { |
119 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
120 | 0 | return info_ptr->compression_type; |
121 | | |
122 | 0 | return 0; |
123 | 0 | } |
124 | | |
125 | | png_uint_32 PNGAPI |
126 | | png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp |
127 | | info_ptr) |
128 | 0 | { |
129 | 0 | #ifdef PNG_pHYs_SUPPORTED |
130 | 0 | png_debug(1, "in png_get_x_pixels_per_meter"); |
131 | |
|
132 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
133 | 0 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
134 | 0 | { |
135 | 0 | if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) |
136 | 0 | return info_ptr->x_pixels_per_unit; |
137 | 0 | } |
138 | | #else |
139 | | PNG_UNUSED(png_ptr) |
140 | | PNG_UNUSED(info_ptr) |
141 | | #endif |
142 | | |
143 | 0 | return 0; |
144 | 0 | } |
145 | | |
146 | | png_uint_32 PNGAPI |
147 | | png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp |
148 | | info_ptr) |
149 | 0 | { |
150 | 0 | #ifdef PNG_pHYs_SUPPORTED |
151 | 0 | png_debug(1, "in png_get_y_pixels_per_meter"); |
152 | |
|
153 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
154 | 0 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
155 | 0 | { |
156 | 0 | if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) |
157 | 0 | return info_ptr->y_pixels_per_unit; |
158 | 0 | } |
159 | | #else |
160 | | PNG_UNUSED(png_ptr) |
161 | | PNG_UNUSED(info_ptr) |
162 | | #endif |
163 | | |
164 | 0 | return 0; |
165 | 0 | } |
166 | | |
167 | | png_uint_32 PNGAPI |
168 | | png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr) |
169 | 0 | { |
170 | 0 | #ifdef PNG_pHYs_SUPPORTED |
171 | 0 | png_debug(1, "in png_get_pixels_per_meter"); |
172 | |
|
173 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
174 | 0 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
175 | 0 | { |
176 | 0 | if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER && |
177 | 0 | info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) |
178 | 0 | return info_ptr->x_pixels_per_unit; |
179 | 0 | } |
180 | | #else |
181 | | PNG_UNUSED(png_ptr) |
182 | | PNG_UNUSED(info_ptr) |
183 | | #endif |
184 | | |
185 | 0 | return 0; |
186 | 0 | } |
187 | | |
188 | | #ifdef PNG_FLOATING_POINT_SUPPORTED |
189 | | float PNGAPI |
190 | | png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp |
191 | | info_ptr) |
192 | 0 | { |
193 | 0 | #ifdef PNG_READ_pHYs_SUPPORTED |
194 | 0 | png_debug(1, "in png_get_pixel_aspect_ratio"); |
195 | |
|
196 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
197 | 0 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
198 | 0 | { |
199 | 0 | if (info_ptr->x_pixels_per_unit != 0) |
200 | 0 | return (float)info_ptr->y_pixels_per_unit |
201 | 0 | / (float)info_ptr->x_pixels_per_unit; |
202 | 0 | } |
203 | | #else |
204 | | PNG_UNUSED(png_ptr) |
205 | | PNG_UNUSED(info_ptr) |
206 | | #endif |
207 | | |
208 | 0 | return (float)0.0; |
209 | 0 | } |
210 | | #endif |
211 | | |
212 | | #ifdef PNG_FIXED_POINT_SUPPORTED |
213 | | png_fixed_point PNGAPI |
214 | | png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr, |
215 | | png_const_inforp info_ptr) |
216 | 0 | { |
217 | 0 | #ifdef PNG_READ_pHYs_SUPPORTED |
218 | 0 | png_debug(1, "in png_get_pixel_aspect_ratio_fixed"); |
219 | |
|
220 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
221 | 0 | (info_ptr->valid & PNG_INFO_pHYs) != 0 && |
222 | 0 | info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 && |
223 | 0 | info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX && |
224 | 0 | info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) |
225 | 0 | { |
226 | 0 | png_fixed_point res; |
227 | | |
228 | | /* The following casts work because a PNG 4 byte integer only has a valid |
229 | | * range of 0..2^31-1; otherwise the cast might overflow. |
230 | | */ |
231 | 0 | if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1, |
232 | 0 | (png_int_32)info_ptr->x_pixels_per_unit) != 0) |
233 | 0 | return res; |
234 | 0 | } |
235 | | #else |
236 | | PNG_UNUSED(png_ptr) |
237 | | PNG_UNUSED(info_ptr) |
238 | | #endif |
239 | | |
240 | 0 | return 0; |
241 | 0 | } |
242 | | #endif |
243 | | |
244 | | png_int_32 PNGAPI |
245 | | png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) |
246 | 0 | { |
247 | 0 | #ifdef PNG_oFFs_SUPPORTED |
248 | 0 | png_debug(1, "in png_get_x_offset_microns"); |
249 | |
|
250 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
251 | 0 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
252 | 0 | { |
253 | 0 | if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) |
254 | 0 | return info_ptr->x_offset; |
255 | 0 | } |
256 | | #else |
257 | | PNG_UNUSED(png_ptr) |
258 | | PNG_UNUSED(info_ptr) |
259 | | #endif |
260 | | |
261 | 0 | return 0; |
262 | 0 | } |
263 | | |
264 | | png_int_32 PNGAPI |
265 | | png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) |
266 | 0 | { |
267 | 0 | #ifdef PNG_oFFs_SUPPORTED |
268 | 0 | png_debug(1, "in png_get_y_offset_microns"); |
269 | |
|
270 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
271 | 0 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
272 | 0 | { |
273 | 0 | if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) |
274 | 0 | return info_ptr->y_offset; |
275 | 0 | } |
276 | | #else |
277 | | PNG_UNUSED(png_ptr) |
278 | | PNG_UNUSED(info_ptr) |
279 | | #endif |
280 | | |
281 | 0 | return 0; |
282 | 0 | } |
283 | | |
284 | | png_int_32 PNGAPI |
285 | | png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
286 | 0 | { |
287 | 0 | #ifdef PNG_oFFs_SUPPORTED |
288 | 0 | png_debug(1, "in png_get_x_offset_pixels"); |
289 | |
|
290 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
291 | 0 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
292 | 0 | { |
293 | 0 | if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) |
294 | 0 | return info_ptr->x_offset; |
295 | 0 | } |
296 | | #else |
297 | | PNG_UNUSED(png_ptr) |
298 | | PNG_UNUSED(info_ptr) |
299 | | #endif |
300 | | |
301 | 0 | return 0; |
302 | 0 | } |
303 | | |
304 | | png_int_32 PNGAPI |
305 | | png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
306 | 0 | { |
307 | 0 | #ifdef PNG_oFFs_SUPPORTED |
308 | 0 | png_debug(1, "in png_get_y_offset_pixels"); |
309 | |
|
310 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
311 | 0 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
312 | 0 | { |
313 | 0 | if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) |
314 | 0 | return info_ptr->y_offset; |
315 | 0 | } |
316 | | #else |
317 | | PNG_UNUSED(png_ptr) |
318 | | PNG_UNUSED(info_ptr) |
319 | | #endif |
320 | | |
321 | 0 | return 0; |
322 | 0 | } |
323 | | |
324 | | #ifdef PNG_INCH_CONVERSIONS_SUPPORTED |
325 | | static png_uint_32 |
326 | | ppi_from_ppm(png_uint_32 ppm) |
327 | 0 | { |
328 | | #if 0 |
329 | | /* The conversion is *(2.54/100), in binary (32 digits): |
330 | | * .00000110100000001001110101001001 |
331 | | */ |
332 | | png_uint_32 t1001, t1101; |
333 | | ppm >>= 1; /* .1 */ |
334 | | t1001 = ppm + (ppm >> 3); /* .1001 */ |
335 | | t1101 = t1001 + (ppm >> 1); /* .1101 */ |
336 | | ppm >>= 20; /* .000000000000000000001 */ |
337 | | t1101 += t1101 >> 15; /* .1101000000000001101 */ |
338 | | t1001 >>= 11; /* .000000000001001 */ |
339 | | t1001 += t1001 >> 12; /* .000000000001001000000001001 */ |
340 | | ppm += t1001; /* .000000000001001000001001001 */ |
341 | | ppm += t1101; /* .110100000001001110101001001 */ |
342 | | return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */ |
343 | | #else |
344 | | /* The argument is a PNG unsigned integer, so it is not permitted |
345 | | * to be bigger than 2^31. |
346 | | */ |
347 | 0 | png_fixed_point result; |
348 | 0 | if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, |
349 | 0 | 5000) != 0) |
350 | 0 | return (png_uint_32)result; |
351 | | |
352 | | /* Overflow. */ |
353 | 0 | return 0; |
354 | 0 | #endif |
355 | 0 | } |
356 | | |
357 | | png_uint_32 PNGAPI |
358 | | png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
359 | 0 | { |
360 | 0 | return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); |
361 | 0 | } |
362 | | |
363 | | png_uint_32 PNGAPI |
364 | | png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
365 | 0 | { |
366 | 0 | return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); |
367 | 0 | } |
368 | | |
369 | | png_uint_32 PNGAPI |
370 | | png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
371 | 0 | { |
372 | 0 | return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); |
373 | 0 | } |
374 | | |
375 | | #ifdef PNG_FIXED_POINT_SUPPORTED |
376 | | static png_fixed_point |
377 | | png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns) |
378 | 0 | { |
379 | | /* Convert from meters * 1,000,000 to inches * 100,000, meters to |
380 | | * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. |
381 | | * Notice that this can overflow - a warning is output and 0 is |
382 | | * returned. |
383 | | */ |
384 | 0 | return png_muldiv_warn(png_ptr, microns, 500, 127); |
385 | 0 | } |
386 | | |
387 | | png_fixed_point PNGAPI |
388 | | png_get_x_offset_inches_fixed(png_const_structrp png_ptr, |
389 | | png_const_inforp info_ptr) |
390 | 0 | { |
391 | 0 | return png_fixed_inches_from_microns(png_ptr, |
392 | 0 | png_get_x_offset_microns(png_ptr, info_ptr)); |
393 | 0 | } |
394 | | #endif |
395 | | |
396 | | #ifdef PNG_FIXED_POINT_SUPPORTED |
397 | | png_fixed_point PNGAPI |
398 | | png_get_y_offset_inches_fixed(png_const_structrp png_ptr, |
399 | | png_const_inforp info_ptr) |
400 | 0 | { |
401 | 0 | return png_fixed_inches_from_microns(png_ptr, |
402 | 0 | png_get_y_offset_microns(png_ptr, info_ptr)); |
403 | 0 | } |
404 | | #endif |
405 | | |
406 | | #ifdef PNG_FLOATING_POINT_SUPPORTED |
407 | | float PNGAPI |
408 | | png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) |
409 | 0 | { |
410 | | /* To avoid the overflow do the conversion directly in floating |
411 | | * point. |
412 | | */ |
413 | 0 | return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937); |
414 | 0 | } |
415 | | #endif |
416 | | |
417 | | #ifdef PNG_FLOATING_POINT_SUPPORTED |
418 | | float PNGAPI |
419 | | png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) |
420 | 0 | { |
421 | | /* To avoid the overflow do the conversion directly in floating |
422 | | * point. |
423 | | */ |
424 | 0 | return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937); |
425 | 0 | } |
426 | | #endif |
427 | | |
428 | | #ifdef PNG_pHYs_SUPPORTED |
429 | | png_uint_32 PNGAPI |
430 | | png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr, |
431 | | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) |
432 | 0 | { |
433 | 0 | png_uint_32 retval = 0; |
434 | |
|
435 | 0 | png_debug1(1, "in %s retrieval function", "pHYs"); |
436 | |
|
437 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
438 | 0 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
439 | 0 | { |
440 | 0 | if (res_x != NULL) |
441 | 0 | { |
442 | 0 | *res_x = info_ptr->x_pixels_per_unit; |
443 | 0 | retval |= PNG_INFO_pHYs; |
444 | 0 | } |
445 | |
|
446 | 0 | if (res_y != NULL) |
447 | 0 | { |
448 | 0 | *res_y = info_ptr->y_pixels_per_unit; |
449 | 0 | retval |= PNG_INFO_pHYs; |
450 | 0 | } |
451 | |
|
452 | 0 | if (unit_type != NULL) |
453 | 0 | { |
454 | 0 | *unit_type = (int)info_ptr->phys_unit_type; |
455 | 0 | retval |= PNG_INFO_pHYs; |
456 | |
|
457 | 0 | if (*unit_type == 1) |
458 | 0 | { |
459 | 0 | if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); |
460 | 0 | if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); |
461 | 0 | } |
462 | 0 | } |
463 | 0 | } |
464 | |
|
465 | 0 | return retval; |
466 | 0 | } |
467 | | #endif /* pHYs */ |
468 | | #endif /* INCH_CONVERSIONS */ |
469 | | |
470 | | /* png_get_channels really belongs in here, too, but it's been around longer */ |
471 | | |
472 | | #endif /* EASY_ACCESS */ |
473 | | |
474 | | |
475 | | png_byte PNGAPI |
476 | | png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
477 | 0 | { |
478 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
479 | 0 | return info_ptr->channels; |
480 | | |
481 | 0 | return 0; |
482 | 0 | } |
483 | | |
484 | | #ifdef PNG_READ_SUPPORTED |
485 | | png_const_bytep PNGAPI |
486 | | png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr) |
487 | 0 | { |
488 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
489 | 0 | return info_ptr->signature; |
490 | | |
491 | 0 | return NULL; |
492 | 0 | } |
493 | | #endif |
494 | | |
495 | | #ifdef PNG_bKGD_SUPPORTED |
496 | | png_uint_32 PNGAPI |
497 | | png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, |
498 | | png_color_16p *background) |
499 | 0 | { |
500 | 0 | png_debug1(1, "in %s retrieval function", "bKGD"); |
501 | |
|
502 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
503 | 0 | (info_ptr->valid & PNG_INFO_bKGD) != 0 && |
504 | 0 | background != NULL) |
505 | 0 | { |
506 | 0 | *background = &(info_ptr->background); |
507 | 0 | return PNG_INFO_bKGD; |
508 | 0 | } |
509 | | |
510 | 0 | return 0; |
511 | 0 | } |
512 | | #endif |
513 | | |
514 | | #ifdef PNG_cHRM_SUPPORTED |
515 | | /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the |
516 | | * same time to correct the rgb grayscale coefficient defaults obtained from the |
517 | | * cHRM chunk in 1.5.4 |
518 | | */ |
519 | | # ifdef PNG_FLOATING_POINT_SUPPORTED |
520 | | png_uint_32 PNGAPI |
521 | | png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr, |
522 | | double *white_x, double *white_y, double *red_x, double *red_y, |
523 | | double *green_x, double *green_y, double *blue_x, double *blue_y) |
524 | 0 | { |
525 | 0 | png_debug1(1, "in %s retrieval function", "cHRM"); |
526 | | |
527 | | /* Quiet API change: this code used to only return the end points if a cHRM |
528 | | * chunk was present, but the end points can also come from iCCP or sRGB |
529 | | * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and |
530 | | * the png_set_ APIs merely check that set end points are mutually |
531 | | * consistent. |
532 | | */ |
533 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
534 | 0 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
535 | 0 | { |
536 | 0 | if (white_x != NULL) |
537 | 0 | *white_x = png_float(png_ptr, |
538 | 0 | info_ptr->colorspace.end_points_xy.whitex, "cHRM white X"); |
539 | 0 | if (white_y != NULL) |
540 | 0 | *white_y = png_float(png_ptr, |
541 | 0 | info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y"); |
542 | 0 | if (red_x != NULL) |
543 | 0 | *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx, |
544 | 0 | "cHRM red X"); |
545 | 0 | if (red_y != NULL) |
546 | 0 | *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy, |
547 | 0 | "cHRM red Y"); |
548 | 0 | if (green_x != NULL) |
549 | 0 | *green_x = png_float(png_ptr, |
550 | 0 | info_ptr->colorspace.end_points_xy.greenx, "cHRM green X"); |
551 | 0 | if (green_y != NULL) |
552 | 0 | *green_y = png_float(png_ptr, |
553 | 0 | info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y"); |
554 | 0 | if (blue_x != NULL) |
555 | 0 | *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex, |
556 | 0 | "cHRM blue X"); |
557 | 0 | if (blue_y != NULL) |
558 | 0 | *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey, |
559 | 0 | "cHRM blue Y"); |
560 | 0 | return PNG_INFO_cHRM; |
561 | 0 | } |
562 | | |
563 | 0 | return 0; |
564 | 0 | } |
565 | | |
566 | | png_uint_32 PNGAPI |
567 | | png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr, |
568 | | double *red_X, double *red_Y, double *red_Z, double *green_X, |
569 | | double *green_Y, double *green_Z, double *blue_X, double *blue_Y, |
570 | | double *blue_Z) |
571 | 0 | { |
572 | 0 | png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)"); |
573 | |
|
574 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
575 | 0 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
576 | 0 | { |
577 | 0 | if (red_X != NULL) |
578 | 0 | *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X, |
579 | 0 | "cHRM red X"); |
580 | 0 | if (red_Y != NULL) |
581 | 0 | *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y, |
582 | 0 | "cHRM red Y"); |
583 | 0 | if (red_Z != NULL) |
584 | 0 | *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z, |
585 | 0 | "cHRM red Z"); |
586 | 0 | if (green_X != NULL) |
587 | 0 | *green_X = png_float(png_ptr, |
588 | 0 | info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X"); |
589 | 0 | if (green_Y != NULL) |
590 | 0 | *green_Y = png_float(png_ptr, |
591 | 0 | info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y"); |
592 | 0 | if (green_Z != NULL) |
593 | 0 | *green_Z = png_float(png_ptr, |
594 | 0 | info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z"); |
595 | 0 | if (blue_X != NULL) |
596 | 0 | *blue_X = png_float(png_ptr, |
597 | 0 | info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X"); |
598 | 0 | if (blue_Y != NULL) |
599 | 0 | *blue_Y = png_float(png_ptr, |
600 | 0 | info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y"); |
601 | 0 | if (blue_Z != NULL) |
602 | 0 | *blue_Z = png_float(png_ptr, |
603 | 0 | info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z"); |
604 | 0 | return PNG_INFO_cHRM; |
605 | 0 | } |
606 | | |
607 | 0 | return 0; |
608 | 0 | } |
609 | | # endif |
610 | | |
611 | | # ifdef PNG_FIXED_POINT_SUPPORTED |
612 | | png_uint_32 PNGAPI |
613 | | png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
614 | | png_fixed_point *int_red_X, png_fixed_point *int_red_Y, |
615 | | png_fixed_point *int_red_Z, png_fixed_point *int_green_X, |
616 | | png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, |
617 | | png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, |
618 | | png_fixed_point *int_blue_Z) |
619 | 0 | { |
620 | 0 | png_debug1(1, "in %s retrieval function", "cHRM_XYZ"); |
621 | |
|
622 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
623 | 0 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
624 | 0 | { |
625 | 0 | if (int_red_X != NULL) |
626 | 0 | *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X; |
627 | 0 | if (int_red_Y != NULL) |
628 | 0 | *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y; |
629 | 0 | if (int_red_Z != NULL) |
630 | 0 | *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z; |
631 | 0 | if (int_green_X != NULL) |
632 | 0 | *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X; |
633 | 0 | if (int_green_Y != NULL) |
634 | 0 | *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y; |
635 | 0 | if (int_green_Z != NULL) |
636 | 0 | *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z; |
637 | 0 | if (int_blue_X != NULL) |
638 | 0 | *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X; |
639 | 0 | if (int_blue_Y != NULL) |
640 | 0 | *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y; |
641 | 0 | if (int_blue_Z != NULL) |
642 | 0 | *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z; |
643 | 0 | return PNG_INFO_cHRM; |
644 | 0 | } |
645 | | |
646 | 0 | return 0; |
647 | 0 | } |
648 | | |
649 | | png_uint_32 PNGAPI |
650 | | png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
651 | | png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, |
652 | | png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, |
653 | | png_fixed_point *blue_x, png_fixed_point *blue_y) |
654 | 0 | { |
655 | 0 | png_debug1(1, "in %s retrieval function", "cHRM"); |
656 | |
|
657 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
658 | 0 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
659 | 0 | { |
660 | 0 | if (white_x != NULL) |
661 | 0 | *white_x = info_ptr->colorspace.end_points_xy.whitex; |
662 | 0 | if (white_y != NULL) |
663 | 0 | *white_y = info_ptr->colorspace.end_points_xy.whitey; |
664 | 0 | if (red_x != NULL) |
665 | 0 | *red_x = info_ptr->colorspace.end_points_xy.redx; |
666 | 0 | if (red_y != NULL) |
667 | 0 | *red_y = info_ptr->colorspace.end_points_xy.redy; |
668 | 0 | if (green_x != NULL) |
669 | 0 | *green_x = info_ptr->colorspace.end_points_xy.greenx; |
670 | 0 | if (green_y != NULL) |
671 | 0 | *green_y = info_ptr->colorspace.end_points_xy.greeny; |
672 | 0 | if (blue_x != NULL) |
673 | 0 | *blue_x = info_ptr->colorspace.end_points_xy.bluex; |
674 | 0 | if (blue_y != NULL) |
675 | 0 | *blue_y = info_ptr->colorspace.end_points_xy.bluey; |
676 | 0 | return PNG_INFO_cHRM; |
677 | 0 | } |
678 | | |
679 | 0 | return 0; |
680 | 0 | } |
681 | | # endif |
682 | | #endif |
683 | | |
684 | | #ifdef PNG_gAMA_SUPPORTED |
685 | | # ifdef PNG_FIXED_POINT_SUPPORTED |
686 | | png_uint_32 PNGAPI |
687 | | png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
688 | | png_fixed_point *file_gamma) |
689 | 0 | { |
690 | 0 | png_debug1(1, "in %s retrieval function", "gAMA"); |
691 | |
|
692 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
693 | 0 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && |
694 | 0 | file_gamma != NULL) |
695 | 0 | { |
696 | 0 | *file_gamma = info_ptr->colorspace.gamma; |
697 | 0 | return PNG_INFO_gAMA; |
698 | 0 | } |
699 | | |
700 | 0 | return 0; |
701 | 0 | } |
702 | | # endif |
703 | | |
704 | | # ifdef PNG_FLOATING_POINT_SUPPORTED |
705 | | png_uint_32 PNGAPI |
706 | | png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr, |
707 | | double *file_gamma) |
708 | 0 | { |
709 | 0 | png_debug1(1, "in %s retrieval function", "gAMA(float)"); |
710 | |
|
711 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
712 | 0 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && |
713 | 0 | file_gamma != NULL) |
714 | 0 | { |
715 | 0 | *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma, |
716 | 0 | "png_get_gAMA"); |
717 | 0 | return PNG_INFO_gAMA; |
718 | 0 | } |
719 | | |
720 | 0 | return 0; |
721 | 0 | } |
722 | | # endif |
723 | | #endif |
724 | | |
725 | | #ifdef PNG_sRGB_SUPPORTED |
726 | | png_uint_32 PNGAPI |
727 | | png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr, |
728 | | int *file_srgb_intent) |
729 | 0 | { |
730 | 0 | png_debug1(1, "in %s retrieval function", "sRGB"); |
731 | |
|
732 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
733 | 0 | (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL) |
734 | 0 | { |
735 | 0 | *file_srgb_intent = info_ptr->colorspace.rendering_intent; |
736 | 0 | return PNG_INFO_sRGB; |
737 | 0 | } |
738 | | |
739 | 0 | return 0; |
740 | 0 | } |
741 | | #endif |
742 | | |
743 | | #ifdef PNG_iCCP_SUPPORTED |
744 | | png_uint_32 PNGAPI |
745 | | png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, |
746 | | png_charpp name, int *compression_type, |
747 | | png_bytepp profile, png_uint_32 *proflen) |
748 | 0 | { |
749 | 0 | png_debug1(1, "in %s retrieval function", "iCCP"); |
750 | |
|
751 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
752 | 0 | (info_ptr->valid & PNG_INFO_iCCP) != 0 && |
753 | 0 | name != NULL && profile != NULL && proflen != NULL) |
754 | 0 | { |
755 | 0 | *name = info_ptr->iccp_name; |
756 | 0 | *profile = info_ptr->iccp_profile; |
757 | 0 | *proflen = png_get_uint_32(info_ptr->iccp_profile); |
758 | | /* This is somewhat irrelevant since the profile data returned has |
759 | | * actually been uncompressed. |
760 | | */ |
761 | 0 | if (compression_type != NULL) |
762 | 0 | *compression_type = PNG_COMPRESSION_TYPE_BASE; |
763 | 0 | return PNG_INFO_iCCP; |
764 | 0 | } |
765 | | |
766 | 0 | return 0; |
767 | |
|
768 | 0 | } |
769 | | #endif |
770 | | |
771 | | #ifdef PNG_sPLT_SUPPORTED |
772 | | int PNGAPI |
773 | | png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr, |
774 | | png_sPLT_tpp spalettes) |
775 | 0 | { |
776 | 0 | png_debug1(1, "in %s retrieval function", "sPLT"); |
777 | |
|
778 | 0 | if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) |
779 | 0 | { |
780 | 0 | *spalettes = info_ptr->splt_palettes; |
781 | 0 | return info_ptr->splt_palettes_num; |
782 | 0 | } |
783 | | |
784 | 0 | return 0; |
785 | 0 | } |
786 | | #endif |
787 | | |
788 | | #ifdef PNG_eXIf_SUPPORTED |
789 | | png_uint_32 PNGAPI |
790 | | png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr, |
791 | | png_bytep *exif) |
792 | 0 | { |
793 | 0 | png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1"); |
794 | 0 | PNG_UNUSED(info_ptr) |
795 | 0 | PNG_UNUSED(exif) |
796 | 0 | return 0; |
797 | 0 | } |
798 | | |
799 | | png_uint_32 PNGAPI |
800 | | png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr, |
801 | | png_uint_32 *num_exif, png_bytep *exif) |
802 | 0 | { |
803 | 0 | png_debug1(1, "in %s retrieval function", "eXIf"); |
804 | |
|
805 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
806 | 0 | (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL) |
807 | 0 | { |
808 | 0 | *num_exif = info_ptr->num_exif; |
809 | 0 | *exif = info_ptr->exif; |
810 | 0 | return PNG_INFO_eXIf; |
811 | 0 | } |
812 | | |
813 | 0 | return 0; |
814 | 0 | } |
815 | | #endif |
816 | | |
817 | | #ifdef PNG_hIST_SUPPORTED |
818 | | png_uint_32 PNGAPI |
819 | | png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr, |
820 | | png_uint_16p *hist) |
821 | 0 | { |
822 | 0 | png_debug1(1, "in %s retrieval function", "hIST"); |
823 | |
|
824 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
825 | 0 | (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL) |
826 | 0 | { |
827 | 0 | *hist = info_ptr->hist; |
828 | 0 | return PNG_INFO_hIST; |
829 | 0 | } |
830 | | |
831 | 0 | return 0; |
832 | 0 | } |
833 | | #endif |
834 | | |
835 | | png_uint_32 PNGAPI |
836 | | png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr, |
837 | | png_uint_32 *width, png_uint_32 *height, int *bit_depth, |
838 | | int *color_type, int *interlace_type, int *compression_type, |
839 | | int *filter_type) |
840 | 0 | { |
841 | 0 | png_debug1(1, "in %s retrieval function", "IHDR"); |
842 | |
|
843 | 0 | if (png_ptr == NULL || info_ptr == NULL) |
844 | 0 | return 0; |
845 | | |
846 | 0 | if (width != NULL) |
847 | 0 | *width = info_ptr->width; |
848 | |
|
849 | 0 | if (height != NULL) |
850 | 0 | *height = info_ptr->height; |
851 | |
|
852 | 0 | if (bit_depth != NULL) |
853 | 0 | *bit_depth = info_ptr->bit_depth; |
854 | |
|
855 | 0 | if (color_type != NULL) |
856 | 0 | *color_type = info_ptr->color_type; |
857 | |
|
858 | 0 | if (compression_type != NULL) |
859 | 0 | *compression_type = info_ptr->compression_type; |
860 | |
|
861 | 0 | if (filter_type != NULL) |
862 | 0 | *filter_type = info_ptr->filter_type; |
863 | |
|
864 | 0 | if (interlace_type != NULL) |
865 | 0 | *interlace_type = info_ptr->interlace_type; |
866 | | |
867 | | /* This is redundant if we can be sure that the info_ptr values were all |
868 | | * assigned in png_set_IHDR(). We do the check anyhow in case an |
869 | | * application has ignored our advice not to mess with the members |
870 | | * of info_ptr directly. |
871 | | */ |
872 | 0 | png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height, |
873 | 0 | info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, |
874 | 0 | info_ptr->compression_type, info_ptr->filter_type); |
875 | |
|
876 | 0 | return 1; |
877 | 0 | } |
878 | | |
879 | | #ifdef PNG_oFFs_SUPPORTED |
880 | | png_uint_32 PNGAPI |
881 | | png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr, |
882 | | png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) |
883 | 0 | { |
884 | 0 | png_debug1(1, "in %s retrieval function", "oFFs"); |
885 | |
|
886 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
887 | 0 | (info_ptr->valid & PNG_INFO_oFFs) != 0 && |
888 | 0 | offset_x != NULL && offset_y != NULL && unit_type != NULL) |
889 | 0 | { |
890 | 0 | *offset_x = info_ptr->x_offset; |
891 | 0 | *offset_y = info_ptr->y_offset; |
892 | 0 | *unit_type = (int)info_ptr->offset_unit_type; |
893 | 0 | return PNG_INFO_oFFs; |
894 | 0 | } |
895 | | |
896 | 0 | return 0; |
897 | 0 | } |
898 | | #endif |
899 | | |
900 | | #ifdef PNG_pCAL_SUPPORTED |
901 | | png_uint_32 PNGAPI |
902 | | png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, |
903 | | png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, |
904 | | png_charp *units, png_charpp *params) |
905 | 0 | { |
906 | 0 | png_debug1(1, "in %s retrieval function", "pCAL"); |
907 | |
|
908 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
909 | 0 | (info_ptr->valid & PNG_INFO_pCAL) != 0 && |
910 | 0 | purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && |
911 | 0 | nparams != NULL && units != NULL && params != NULL) |
912 | 0 | { |
913 | 0 | *purpose = info_ptr->pcal_purpose; |
914 | 0 | *X0 = info_ptr->pcal_X0; |
915 | 0 | *X1 = info_ptr->pcal_X1; |
916 | 0 | *type = (int)info_ptr->pcal_type; |
917 | 0 | *nparams = (int)info_ptr->pcal_nparams; |
918 | 0 | *units = info_ptr->pcal_units; |
919 | 0 | *params = info_ptr->pcal_params; |
920 | 0 | return PNG_INFO_pCAL; |
921 | 0 | } |
922 | | |
923 | 0 | return 0; |
924 | 0 | } |
925 | | #endif |
926 | | |
927 | | #ifdef PNG_sCAL_SUPPORTED |
928 | | # ifdef PNG_FIXED_POINT_SUPPORTED |
929 | | # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ |
930 | | defined(PNG_FLOATING_POINT_SUPPORTED) |
931 | | png_uint_32 PNGAPI |
932 | | png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
933 | | int *unit, png_fixed_point *width, png_fixed_point *height) |
934 | 0 | { |
935 | 0 | png_debug1(1, "in %s retrieval function", "sCAL"); |
936 | |
|
937 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
938 | 0 | (info_ptr->valid & PNG_INFO_sCAL) != 0) |
939 | 0 | { |
940 | 0 | *unit = info_ptr->scal_unit; |
941 | | /*TODO: make this work without FP support; the API is currently eliminated |
942 | | * if neither floating point APIs nor internal floating point arithmetic |
943 | | * are enabled. |
944 | | */ |
945 | 0 | *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width"); |
946 | 0 | *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), |
947 | 0 | "sCAL height"); |
948 | 0 | return PNG_INFO_sCAL; |
949 | 0 | } |
950 | | |
951 | 0 | return 0; |
952 | 0 | } |
953 | | # endif /* FLOATING_ARITHMETIC */ |
954 | | # endif /* FIXED_POINT */ |
955 | | # ifdef PNG_FLOATING_POINT_SUPPORTED |
956 | | png_uint_32 PNGAPI |
957 | | png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, |
958 | | int *unit, double *width, double *height) |
959 | 0 | { |
960 | 0 | png_debug1(1, "in %s retrieval function", "sCAL(float)"); |
961 | |
|
962 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
963 | 0 | (info_ptr->valid & PNG_INFO_sCAL) != 0) |
964 | 0 | { |
965 | 0 | *unit = info_ptr->scal_unit; |
966 | 0 | *width = atof(info_ptr->scal_s_width); |
967 | 0 | *height = atof(info_ptr->scal_s_height); |
968 | 0 | return PNG_INFO_sCAL; |
969 | 0 | } |
970 | | |
971 | 0 | return 0; |
972 | 0 | } |
973 | | # endif /* FLOATING POINT */ |
974 | | png_uint_32 PNGAPI |
975 | | png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr, |
976 | | int *unit, png_charpp width, png_charpp height) |
977 | 0 | { |
978 | 0 | png_debug1(1, "in %s retrieval function", "sCAL(str)"); |
979 | |
|
980 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
981 | 0 | (info_ptr->valid & PNG_INFO_sCAL) != 0) |
982 | 0 | { |
983 | 0 | *unit = info_ptr->scal_unit; |
984 | 0 | *width = info_ptr->scal_s_width; |
985 | 0 | *height = info_ptr->scal_s_height; |
986 | 0 | return PNG_INFO_sCAL; |
987 | 0 | } |
988 | | |
989 | 0 | return 0; |
990 | 0 | } |
991 | | #endif /* sCAL */ |
992 | | |
993 | | #ifdef PNG_pHYs_SUPPORTED |
994 | | png_uint_32 PNGAPI |
995 | | png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr, |
996 | | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) |
997 | 0 | { |
998 | 0 | png_uint_32 retval = 0; |
999 | |
|
1000 | 0 | png_debug1(1, "in %s retrieval function", "pHYs"); |
1001 | |
|
1002 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
1003 | 0 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
1004 | 0 | { |
1005 | 0 | if (res_x != NULL) |
1006 | 0 | { |
1007 | 0 | *res_x = info_ptr->x_pixels_per_unit; |
1008 | 0 | retval |= PNG_INFO_pHYs; |
1009 | 0 | } |
1010 | |
|
1011 | 0 | if (res_y != NULL) |
1012 | 0 | { |
1013 | 0 | *res_y = info_ptr->y_pixels_per_unit; |
1014 | 0 | retval |= PNG_INFO_pHYs; |
1015 | 0 | } |
1016 | |
|
1017 | 0 | if (unit_type != NULL) |
1018 | 0 | { |
1019 | 0 | *unit_type = (int)info_ptr->phys_unit_type; |
1020 | 0 | retval |= PNG_INFO_pHYs; |
1021 | 0 | } |
1022 | 0 | } |
1023 | |
|
1024 | 0 | return retval; |
1025 | 0 | } |
1026 | | #endif /* pHYs */ |
1027 | | |
1028 | | png_uint_32 PNGAPI |
1029 | | png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr, |
1030 | | png_colorp *palette, int *num_palette) |
1031 | 0 | { |
1032 | 0 | png_debug1(1, "in %s retrieval function", "PLTE"); |
1033 | |
|
1034 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
1035 | 0 | (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL) |
1036 | 0 | { |
1037 | 0 | *palette = info_ptr->palette; |
1038 | 0 | *num_palette = info_ptr->num_palette; |
1039 | 0 | png_debug1(3, "num_palette = %d", *num_palette); |
1040 | 0 | return PNG_INFO_PLTE; |
1041 | 0 | } |
1042 | | |
1043 | 0 | return 0; |
1044 | 0 | } |
1045 | | |
1046 | | #ifdef PNG_sBIT_SUPPORTED |
1047 | | png_uint_32 PNGAPI |
1048 | | png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, |
1049 | | png_color_8p *sig_bit) |
1050 | 0 | { |
1051 | 0 | png_debug1(1, "in %s retrieval function", "sBIT"); |
1052 | |
|
1053 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
1054 | 0 | (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL) |
1055 | 0 | { |
1056 | 0 | *sig_bit = &(info_ptr->sig_bit); |
1057 | 0 | return PNG_INFO_sBIT; |
1058 | 0 | } |
1059 | | |
1060 | 0 | return 0; |
1061 | 0 | } |
1062 | | #endif |
1063 | | |
1064 | | #ifdef PNG_TEXT_SUPPORTED |
1065 | | int PNGAPI |
1066 | | png_get_text(png_const_structrp png_ptr, png_inforp info_ptr, |
1067 | | png_textp *text_ptr, int *num_text) |
1068 | 0 | { |
1069 | 0 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) |
1070 | 0 | { |
1071 | 0 | png_debug1(1, "in text retrieval function, chunk typeid = 0x%lx", |
1072 | 0 | (unsigned long)png_ptr->chunk_name); |
1073 | |
|
1074 | 0 | if (text_ptr != NULL) |
1075 | 0 | *text_ptr = info_ptr->text; |
1076 | |
|
1077 | 0 | if (num_text != NULL) |
1078 | 0 | *num_text = info_ptr->num_text; |
1079 | |
|
1080 | 0 | return info_ptr->num_text; |
1081 | 0 | } |
1082 | | |
1083 | 0 | if (num_text != NULL) |
1084 | 0 | *num_text = 0; |
1085 | |
|
1086 | 0 | return 0; |
1087 | 0 | } |
1088 | | #endif |
1089 | | |
1090 | | #ifdef PNG_tIME_SUPPORTED |
1091 | | png_uint_32 PNGAPI |
1092 | | png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr, |
1093 | | png_timep *mod_time) |
1094 | 0 | { |
1095 | 0 | png_debug1(1, "in %s retrieval function", "tIME"); |
1096 | |
|
1097 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
1098 | 0 | (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL) |
1099 | 0 | { |
1100 | 0 | *mod_time = &(info_ptr->mod_time); |
1101 | 0 | return PNG_INFO_tIME; |
1102 | 0 | } |
1103 | | |
1104 | 0 | return 0; |
1105 | 0 | } |
1106 | | #endif |
1107 | | |
1108 | | #ifdef PNG_tRNS_SUPPORTED |
1109 | | png_uint_32 PNGAPI |
1110 | | png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr, |
1111 | | png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) |
1112 | 0 | { |
1113 | 0 | png_uint_32 retval = 0; |
1114 | |
|
1115 | 0 | png_debug1(1, "in %s retrieval function", "tRNS"); |
1116 | |
|
1117 | 0 | if (png_ptr != NULL && info_ptr != NULL && |
1118 | 0 | (info_ptr->valid & PNG_INFO_tRNS) != 0) |
1119 | 0 | { |
1120 | 0 | if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
1121 | 0 | { |
1122 | 0 | if (trans_alpha != NULL) |
1123 | 0 | { |
1124 | 0 | *trans_alpha = info_ptr->trans_alpha; |
1125 | 0 | retval |= PNG_INFO_tRNS; |
1126 | 0 | } |
1127 | |
|
1128 | 0 | if (trans_color != NULL) |
1129 | 0 | *trans_color = &(info_ptr->trans_color); |
1130 | 0 | } |
1131 | | |
1132 | 0 | else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ |
1133 | 0 | { |
1134 | 0 | if (trans_color != NULL) |
1135 | 0 | { |
1136 | 0 | *trans_color = &(info_ptr->trans_color); |
1137 | 0 | retval |= PNG_INFO_tRNS; |
1138 | 0 | } |
1139 | |
|
1140 | 0 | if (trans_alpha != NULL) |
1141 | 0 | *trans_alpha = NULL; |
1142 | 0 | } |
1143 | |
|
1144 | 0 | if (num_trans != NULL) |
1145 | 0 | { |
1146 | 0 | *num_trans = info_ptr->num_trans; |
1147 | 0 | retval |= PNG_INFO_tRNS; |
1148 | 0 | } |
1149 | 0 | } |
1150 | |
|
1151 | 0 | return retval; |
1152 | 0 | } |
1153 | | #endif |
1154 | | |
1155 | | #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED |
1156 | | int PNGAPI |
1157 | | png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr, |
1158 | | png_unknown_chunkpp unknowns) |
1159 | 0 | { |
1160 | 0 | if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) |
1161 | 0 | { |
1162 | 0 | *unknowns = info_ptr->unknown_chunks; |
1163 | 0 | return info_ptr->unknown_chunks_num; |
1164 | 0 | } |
1165 | | |
1166 | 0 | return 0; |
1167 | 0 | } |
1168 | | #endif |
1169 | | |
1170 | | #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED |
1171 | | png_byte PNGAPI |
1172 | | png_get_rgb_to_gray_status(png_const_structrp png_ptr) |
1173 | 0 | { |
1174 | 0 | return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); |
1175 | 0 | } |
1176 | | #endif |
1177 | | |
1178 | | #ifdef PNG_USER_CHUNKS_SUPPORTED |
1179 | | png_voidp PNGAPI |
1180 | | png_get_user_chunk_ptr(png_const_structrp png_ptr) |
1181 | 0 | { |
1182 | 0 | return (png_ptr ? png_ptr->user_chunk_ptr : NULL); |
1183 | 0 | } |
1184 | | #endif |
1185 | | |
1186 | | size_t PNGAPI |
1187 | | png_get_compression_buffer_size(png_const_structrp png_ptr) |
1188 | 0 | { |
1189 | 0 | if (png_ptr == NULL) |
1190 | 0 | return 0; |
1191 | | |
1192 | 0 | #ifdef PNG_WRITE_SUPPORTED |
1193 | 0 | if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) |
1194 | 0 | #endif |
1195 | 0 | { |
1196 | 0 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
1197 | 0 | return png_ptr->IDAT_read_size; |
1198 | | #else |
1199 | | return PNG_IDAT_READ_SIZE; |
1200 | | #endif |
1201 | 0 | } |
1202 | | |
1203 | 0 | #ifdef PNG_WRITE_SUPPORTED |
1204 | 0 | else |
1205 | 0 | return png_ptr->zbuffer_size; |
1206 | 0 | #endif |
1207 | 0 | } |
1208 | | |
1209 | | #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
1210 | | /* These functions were added to libpng 1.2.6 and were enabled |
1211 | | * by default in libpng-1.4.0 */ |
1212 | | png_uint_32 PNGAPI |
1213 | | png_get_user_width_max(png_const_structrp png_ptr) |
1214 | 0 | { |
1215 | 0 | return (png_ptr ? png_ptr->user_width_max : 0); |
1216 | 0 | } |
1217 | | |
1218 | | png_uint_32 PNGAPI |
1219 | | png_get_user_height_max(png_const_structrp png_ptr) |
1220 | 0 | { |
1221 | 0 | return (png_ptr ? png_ptr->user_height_max : 0); |
1222 | 0 | } |
1223 | | |
1224 | | /* This function was added to libpng 1.4.0 */ |
1225 | | png_uint_32 PNGAPI |
1226 | | png_get_chunk_cache_max(png_const_structrp png_ptr) |
1227 | 0 | { |
1228 | 0 | return (png_ptr ? png_ptr->user_chunk_cache_max : 0); |
1229 | 0 | } |
1230 | | |
1231 | | /* This function was added to libpng 1.4.1 */ |
1232 | | png_alloc_size_t PNGAPI |
1233 | | png_get_chunk_malloc_max(png_const_structrp png_ptr) |
1234 | 0 | { |
1235 | 0 | return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); |
1236 | 0 | } |
1237 | | #endif /* SET_USER_LIMITS */ |
1238 | | |
1239 | | /* These functions were added to libpng 1.4.0 */ |
1240 | | #ifdef PNG_IO_STATE_SUPPORTED |
1241 | | png_uint_32 PNGAPI |
1242 | | png_get_io_state(png_const_structrp png_ptr) |
1243 | 0 | { |
1244 | 0 | return png_ptr->io_state; |
1245 | 0 | } |
1246 | | |
1247 | | png_uint_32 PNGAPI |
1248 | | png_get_io_chunk_type(png_const_structrp png_ptr) |
1249 | 0 | { |
1250 | 0 | return png_ptr->chunk_name; |
1251 | 0 | } |
1252 | | #endif /* IO_STATE */ |
1253 | | |
1254 | | #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED |
1255 | | # ifdef PNG_GET_PALETTE_MAX_SUPPORTED |
1256 | | int PNGAPI |
1257 | | png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr) |
1258 | 0 | { |
1259 | 0 | if (png_ptr != NULL && info_ptr != NULL) |
1260 | 0 | return png_ptr->num_palette_max; |
1261 | | |
1262 | 0 | return -1; |
1263 | 0 | } |
1264 | | # endif |
1265 | | #endif |
1266 | | |
1267 | | #endif /* READ || WRITE */ |