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