CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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