pngget.c 32.4 KB
Newer Older
A
Andreas Dilger 已提交
1 2

/* pngget.c - retrieval of values from info struct
3
 *
4
 * Last changed in libpng 1.6.11 [June 5, 2014]
5
 * Copyright (c) 1998-2014 Glenn Randers-Pehrson
6 7
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
 * (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
 */
A
Andreas Dilger 已提交
14

15
#include "pngpriv.h"
16

17 18
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)

19
png_uint_32 PNGAPI
20
png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
21
    png_uint_32 flag)
A
Andreas Dilger 已提交
22
{
23
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
24
      return(info_ptr->valid & flag);
25

26
   return(0);
A
Andreas Dilger 已提交
27 28
}

29
png_size_t PNGAPI
30
png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
A
Andreas Dilger 已提交
31
{
32
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
33
      return(info_ptr->rowbytes);
34

35
   return(0);
A
Andreas Dilger 已提交
36 37
}

38
#ifdef PNG_INFO_IMAGE_SUPPORTED
39
png_bytepp PNGAPI
40
png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
41 42 43
{
   if (png_ptr != NULL && info_ptr != NULL)
      return(info_ptr->row_pointers);
44

45
   return(0);
46 47 48
}
#endif

49
#ifdef PNG_EASY_ACCESS_SUPPORTED
50
/* Easy access to info, added in libpng-0.99 */
51
png_uint_32 PNGAPI
52
png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
53
{
54
   if (png_ptr != NULL && info_ptr != NULL)
55
      return info_ptr->width;
56

57 58 59
   return (0);
}

60
png_uint_32 PNGAPI
61
png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
62
{
63
   if (png_ptr != NULL && info_ptr != NULL)
64
      return info_ptr->height;
65

66 67 68
   return (0);
}

69
png_byte PNGAPI
70
png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
71
{
72
   if (png_ptr != NULL && info_ptr != NULL)
73
      return info_ptr->bit_depth;
74

75 76 77
   return (0);
}

78
png_byte PNGAPI
79
png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
80
{
81
   if (png_ptr != NULL && info_ptr != NULL)
82
      return info_ptr->color_type;
83

84 85 86
   return (0);
}

87
png_byte PNGAPI
88
png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
89
{
90
   if (png_ptr != NULL && info_ptr != NULL)
91
      return info_ptr->filter_type;
92

93 94 95
   return (0);
}

96
png_byte PNGAPI
97
png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
98
{
99
   if (png_ptr != NULL && info_ptr != NULL)
100
      return info_ptr->interlace_type;
101

102 103 104
   return (0);
}

105
png_byte PNGAPI
106
png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
107
{
108
   if (png_ptr != NULL && info_ptr != NULL)
109
      return info_ptr->compression_type;
110

111 112 113
   return (0);
}

114
png_uint_32 PNGAPI
115 116
png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
   info_ptr)
117
{
118
#ifdef PNG_pHYs_SUPPORTED
119 120 121 122
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
      {
         png_debug1(1, "in %s retrieval function",
             "png_get_x_pixels_per_meter");
123

124 125 126
         if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
            return (info_ptr->x_pixels_per_unit);
      }
127 128 129
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
130
#endif
131

132 133 134
   return (0);
}

135
png_uint_32 PNGAPI
136 137
png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
    info_ptr)
138
{
139
#ifdef PNG_pHYs_SUPPORTED
140
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
141
   {
142 143
      png_debug1(1, "in %s retrieval function",
          "png_get_y_pixels_per_meter");
144

145
      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
146
         return (info_ptr->y_pixels_per_unit);
147
   }
148 149 150
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
151
#endif
152

153 154 155
   return (0);
}

156
png_uint_32 PNGAPI
157
png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
158
{
159
#ifdef PNG_pHYs_SUPPORTED
160
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
161
   {
162
      png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
163

164 165
      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
          info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
166
         return (info_ptr->x_pixels_per_unit);
167
   }
168 169 170
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
171
#endif
172

173 174 175
   return (0);
}

176
#ifdef PNG_FLOATING_POINT_SUPPORTED
177
float PNGAPI
178 179
png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
   info_ptr)
180
{
181
#ifdef PNG_READ_pHYs_SUPPORTED
182
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
183
   {
184
      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
185

186
      if (info_ptr->x_pixels_per_unit != 0)
187
         return ((float)((float)info_ptr->y_pixels_per_unit
188
             /(float)info_ptr->x_pixels_per_unit));
189
   }
190 191 192
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
193
#endif
194

195
   return ((float)0.0);
196
}
197
#endif
198

199 200
#ifdef PNG_FIXED_POINT_SUPPORTED
png_fixed_point PNGAPI
201 202
png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
    png_const_inforp info_ptr)
203 204 205
{
#ifdef PNG_READ_pHYs_SUPPORTED
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
206 207 208
       && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
       && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
       && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
209 210 211 212 213
   {
      png_fixed_point res;

      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");

214 215 216 217 218
      /* The following casts work because a PNG 4 byte integer only has a valid
       * range of 0..2^31-1; otherwise the cast might overflow.
       */
      if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
          (png_int_32)info_ptr->x_pixels_per_unit))
219
         return res;
220
   }
221 222 223
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
224
#endif
225

226 227 228 229
   return 0;
}
#endif

230
png_int_32 PNGAPI
231
png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
232
{
233
#ifdef PNG_oFFs_SUPPORTED
234
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
235
   {
236
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
237

238
      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
239
         return (info_ptr->x_offset);
240
   }
241 242 243
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
244
#endif
245

246 247 248
   return (0);
}

249
png_int_32 PNGAPI
250
png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
251
{
252
#ifdef PNG_oFFs_SUPPORTED
253
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
254
   {
255
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
256

257
      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
258
         return (info_ptr->y_offset);
259
   }
260 261 262
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
263
#endif
264

265 266 267
   return (0);
}

268
png_int_32 PNGAPI
269
png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
270
{
271
#ifdef PNG_oFFs_SUPPORTED
272
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
273
   {
G
[devel]  
Glenn Randers-Pehrson 已提交
274
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
275

276
      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
277
         return (info_ptr->x_offset);
278
   }
279 280 281
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
282
#endif
283

284 285 286
   return (0);
}

287
png_int_32 PNGAPI
288
png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
289
{
290
#ifdef PNG_oFFs_SUPPORTED
291
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
292
   {
G
[devel]  
Glenn Randers-Pehrson 已提交
293
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
294

295
      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
296
         return (info_ptr->y_offset);
297
   }
298 299 300
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
301
#endif
302

303 304 305
   return (0);
}

G
[devel]  
Glenn Randers-Pehrson 已提交
306 307 308 309 310
#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
static png_uint_32
ppi_from_ppm(png_uint_32 ppm)
{
#if 0
311
   /* The conversion is *(2.54/100), in binary (32 digits):
G
[devel]  
Glenn Randers-Pehrson 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
    * .00000110100000001001110101001001
    */
   png_uint_32 t1001, t1101;
   ppm >>= 1;                  /* .1 */
   t1001 = ppm + (ppm >> 3);   /* .1001 */
   t1101 = t1001 + (ppm >> 1); /* .1101 */
   ppm >>= 20;                 /* .000000000000000000001 */
   t1101 += t1101 >> 15;       /* .1101000000000001101 */
   t1001 >>= 11;               /* .000000000001001 */
   t1001 += t1001 >> 12;       /* .000000000001001000000001001 */
   ppm += t1001;               /* .000000000001001000001001001 */
   ppm += t1101;               /* .110100000001001110101001001 */
   return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
#else
   /* The argument is a PNG unsigned integer, so it is not permitted
    * to be bigger than 2^31.
    */
   png_fixed_point result;
330 331
   if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
       5000))
G
[devel]  
Glenn Randers-Pehrson 已提交
332 333 334 335 336 337 338
      return result;

   /* Overflow. */
   return 0;
#endif
}

339
png_uint_32 PNGAPI
340
png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
341
{
G
[devel]  
Glenn Randers-Pehrson 已提交
342
   return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
343 344
}

345
png_uint_32 PNGAPI
346
png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
347
{
G
[devel]  
Glenn Randers-Pehrson 已提交
348
   return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
349 350
}

351
png_uint_32 PNGAPI
352
png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
353
{
G
[devel]  
Glenn Randers-Pehrson 已提交
354 355 356 357 358
   return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
}

#ifdef PNG_FIXED_POINT_SUPPORTED
static png_fixed_point
359
png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
G
[devel]  
Glenn Randers-Pehrson 已提交
360 361
{
   /* Convert from metres * 1,000,000 to inches * 100,000, meters to
362
    * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
G
[devel]  
Glenn Randers-Pehrson 已提交
363 364 365 366 367 368 369
    * Notice that this can overflow - a warning is output and 0 is
    * returned.
    */
   return png_muldiv_warn(png_ptr, microns, 500, 127);
}

png_fixed_point PNGAPI
370 371
png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
    png_const_inforp info_ptr)
G
[devel]  
Glenn Randers-Pehrson 已提交
372 373
{
   return png_fixed_inches_from_microns(png_ptr,
374
       png_get_x_offset_microns(png_ptr, info_ptr));
G
[devel]  
Glenn Randers-Pehrson 已提交
375 376 377 378 379
}
#endif

#ifdef PNG_FIXED_POINT_SUPPORTED
png_fixed_point PNGAPI
380 381
png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
    png_const_inforp info_ptr)
G
[devel]  
Glenn Randers-Pehrson 已提交
382 383
{
   return png_fixed_inches_from_microns(png_ptr,
384
       png_get_y_offset_microns(png_ptr, info_ptr));
385
}
G
[devel]  
Glenn Randers-Pehrson 已提交
386
#endif
387

G
[devel]  
Glenn Randers-Pehrson 已提交
388
#ifdef PNG_FLOATING_POINT_SUPPORTED
389
float PNGAPI
390
png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
391
{
G
[devel]  
Glenn Randers-Pehrson 已提交
392 393 394
   /* To avoid the overflow do the conversion directly in floating
    * point.
    */
395
   return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
396
}
G
[devel]  
Glenn Randers-Pehrson 已提交
397
#endif
398

G
[devel]  
Glenn Randers-Pehrson 已提交
399
#ifdef PNG_FLOATING_POINT_SUPPORTED
400
float PNGAPI
401
png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
402
{
G
[devel]  
Glenn Randers-Pehrson 已提交
403 404 405
   /* To avoid the overflow do the conversion directly in floating
    * point.
    */
406
   return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
407
}
G
[devel]  
Glenn Randers-Pehrson 已提交
408
#endif
409

410
#ifdef PNG_pHYs_SUPPORTED
411
png_uint_32 PNGAPI
412
png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
413
    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
414 415 416
{
   png_uint_32 retval = 0;

417
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
418
   {
419
      png_debug1(1, "in %s retrieval function", "pHYs");
420

421 422 423 424 425
      if (res_x != NULL)
      {
         *res_x = info_ptr->x_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
426

427 428 429 430 431
      if (res_y != NULL)
      {
         *res_y = info_ptr->y_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
432

433 434 435 436
      if (unit_type != NULL)
      {
         *unit_type = (int)info_ptr->phys_unit_type;
         retval |= PNG_INFO_pHYs;
437

438
         if (*unit_type == 1)
439
         {
440 441
            if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
            if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
442 443 444
         }
      }
   }
445

446 447
   return (retval);
}
448
#endif /* PNG_pHYs_SUPPORTED */
G
[devel]  
Glenn Randers-Pehrson 已提交
449
#endif  /* PNG_INCH_CONVERSIONS_SUPPORTED */
450 451

/* png_get_channels really belongs in here, too, but it's been around longer */
452

453 454
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

455

456
png_byte PNGAPI
457
png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
A
Andreas Dilger 已提交
458
{
459
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
460
      return(info_ptr->channels);
461

462
   return (0);
A
Andreas Dilger 已提交
463 464
}

465
#ifdef PNG_READ_SUPPORTED
466
png_const_bytep PNGAPI
467
png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
A
Andreas Dilger 已提交
468
{
469
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
470
      return(info_ptr->signature);
471

472
   return (NULL);
A
Andreas Dilger 已提交
473
}
474
#endif
A
Andreas Dilger 已提交
475

476
#ifdef PNG_bKGD_SUPPORTED
477
png_uint_32 PNGAPI
478
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
A
Andreas Dilger 已提交
479 480
   png_color_16p *background)
{
481
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
482
       && background != NULL)
A
Andreas Dilger 已提交
483
   {
484
      png_debug1(1, "in %s retrieval function", "bKGD");
485

A
Andreas Dilger 已提交
486 487 488
      *background = &(info_ptr->background);
      return (PNG_INFO_bKGD);
   }
489

A
Andreas Dilger 已提交
490 491 492 493
   return (0);
}
#endif

494
#ifdef PNG_cHRM_SUPPORTED
495 496 497 498
/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
 * same time to correct the rgb grayscale coefficient defaults obtained from the
 * cHRM chunk in 1.5.4
 */
499
#  ifdef PNG_FLOATING_POINT_SUPPORTED
500
png_uint_32 PNGAPI
501
png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
502 503
    double *white_x, double *white_y, double *red_x, double *red_y,
    double *green_x, double *green_y, double *blue_x, double *blue_y)
A
Andreas Dilger 已提交
504
{
505 506 507 508 509 510 511 512
   /* Quiet API change: this code used to only return the end points if a cHRM
    * chunk was present, but the end points can also come from iCCP or sRGB
    * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
    * the png_set_ APIs merely check that set end points are mutually
    * consistent.
    */
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
A
Andreas Dilger 已提交
513
   {
514
      png_debug1(1, "in %s retrieval function", "cHRM");
515

A
Andreas Dilger 已提交
516
      if (white_x != NULL)
517 518
         *white_x = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
A
Andreas Dilger 已提交
519
      if (white_y != NULL)
520 521
         *white_y = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
A
Andreas Dilger 已提交
522
      if (red_x != NULL)
523 524
         *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
            "cHRM red X");
A
Andreas Dilger 已提交
525
      if (red_y != NULL)
526 527
         *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
            "cHRM red Y");
A
Andreas Dilger 已提交
528
      if (green_x != NULL)
529 530
         *green_x = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
A
Andreas Dilger 已提交
531
      if (green_y != NULL)
532 533
         *green_y = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
A
Andreas Dilger 已提交
534
      if (blue_x != NULL)
535 536
         *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
            "cHRM blue X");
A
Andreas Dilger 已提交
537
      if (blue_y != NULL)
538 539
         *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
            "cHRM blue Y");
A
Andreas Dilger 已提交
540 541
      return (PNG_INFO_cHRM);
   }
542

A
Andreas Dilger 已提交
543 544
   return (0);
}
545 546

png_uint_32 PNGAPI
547
png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
548 549 550 551
   double *red_X, double *red_Y, double *red_Z, double *green_X,
   double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
   double *blue_Z)
{
552 553
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
554
   {
555 556
      png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");

557
      if (red_X != NULL)
558 559
         *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
            "cHRM red X");
560
      if (red_Y != NULL)
561 562
         *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
            "cHRM red Y");
563
      if (red_Z != NULL)
564 565
         *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
            "cHRM red Z");
566
      if (green_X != NULL)
567 568
         *green_X = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
569
      if (green_Y != NULL)
570 571
         *green_Y = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
572
      if (green_Z != NULL)
573 574
         *green_Z = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
575
      if (blue_X != NULL)
576 577
         *blue_X = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
578
      if (blue_Y != NULL)
579 580
         *blue_Y = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
581
      if (blue_Z != NULL)
582 583
         *blue_Z = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
584 585 586 587 588
      return (PNG_INFO_cHRM);
   }

   return (0);
}
589
#  endif
G
[devel]  
Glenn Randers-Pehrson 已提交
590

591
#  ifdef PNG_FIXED_POINT_SUPPORTED
592
png_uint_32 PNGAPI
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
    png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
    png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
    png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
    png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
    png_fixed_point *int_blue_Z)
{
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
   {
      png_debug1(1, "in %s retrieval function", "cHRM_XYZ");

      if (int_red_X != NULL)
         *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
      if (int_red_Y != NULL)
         *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
      if (int_red_Z != NULL)
         *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
      if (int_green_X != NULL)
         *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
      if (int_green_Y != NULL)
         *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
      if (int_green_Z != NULL)
         *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
      if (int_blue_X != NULL)
         *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
      if (int_blue_Y != NULL)
         *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
      if (int_blue_Z != NULL)
         *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
      return (PNG_INFO_cHRM);
   }

   return (0);
}

png_uint_32 PNGAPI
png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
631 632 633
    png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
    png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
    png_fixed_point *blue_x, png_fixed_point *blue_y)
634
{
635 636
   png_debug1(1, "in %s retrieval function", "cHRM");

637 638
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
639 640
   {
      if (white_x != NULL)
641
         *white_x = info_ptr->colorspace.end_points_xy.whitex;
642
      if (white_y != NULL)
643
         *white_y = info_ptr->colorspace.end_points_xy.whitey;
644
      if (red_x != NULL)
645
         *red_x = info_ptr->colorspace.end_points_xy.redx;
646
      if (red_y != NULL)
647
         *red_y = info_ptr->colorspace.end_points_xy.redy;
648
      if (green_x != NULL)
649
         *green_x = info_ptr->colorspace.end_points_xy.greenx;
650
      if (green_y != NULL)
651
         *green_y = info_ptr->colorspace.end_points_xy.greeny;
652
      if (blue_x != NULL)
653
         *blue_x = info_ptr->colorspace.end_points_xy.bluex;
654
      if (blue_y != NULL)
655
         *blue_y = info_ptr->colorspace.end_points_xy.bluey;
656 657
      return (PNG_INFO_cHRM);
   }
658

659 660
   return (0);
}
661
#  endif
662
#endif
A
Andreas Dilger 已提交
663

664
#ifdef PNG_gAMA_SUPPORTED
665 666 667
#  ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32 PNGAPI
png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
G
[devel]  
Glenn Randers-Pehrson 已提交
668
    png_fixed_point *file_gamma)
A
Andreas Dilger 已提交
669
{
670 671
   png_debug1(1, "in %s retrieval function", "gAMA");

672 673 674
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
      file_gamma != NULL)
A
Andreas Dilger 已提交
675
   {
676
      *file_gamma = info_ptr->colorspace.gamma;
A
Andreas Dilger 已提交
677 678
      return (PNG_INFO_gAMA);
   }
G
[devel]  
Glenn Randers-Pehrson 已提交
679

A
Andreas Dilger 已提交
680 681
   return (0);
}
682 683
#  endif

684
#  ifdef PNG_FLOATING_POINT_SUPPORTED
685
png_uint_32 PNGAPI
686
png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
687
    double *file_gamma)
688
{
689
   png_debug1(1, "in %s retrieval function", "gAMA(float)");
690

691 692 693 694 695 696 697 698
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
      file_gamma != NULL)
   {
      *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
         "png_get_gAMA");
      return (PNG_INFO_gAMA);
   }
699

700
   return (0);
701
}
702
#  endif
703
#endif
A
Andreas Dilger 已提交
704

705
#ifdef PNG_sRGB_SUPPORTED
706
png_uint_32 PNGAPI
707
png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
708
    int *file_srgb_intent)
709
{
710 711
   png_debug1(1, "in %s retrieval function", "sRGB");

712
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
713
       && file_srgb_intent != NULL)
714
   {
715
      *file_srgb_intent = info_ptr->colorspace.rendering_intent;
716 717
      return (PNG_INFO_sRGB);
   }
718

719 720 721 722
   return (0);
}
#endif

723
#ifdef PNG_iCCP_SUPPORTED
724
png_uint_32 PNGAPI
725
png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
726
    png_charpp name, int *compression_type,
G
[devel]  
Glenn Randers-Pehrson 已提交
727
    png_bytepp profile, png_uint_32 *proflen)
728
{
729 730
   png_debug1(1, "in %s retrieval function", "iCCP");

731
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
732 733
       && name != NULL && compression_type != NULL && profile != NULL &&
		 proflen != NULL)
734 735 736
   {
      *name = info_ptr->iccp_name;
      *profile = info_ptr->iccp_profile;
737 738 739
      *proflen = png_get_uint_32(info_ptr->iccp_profile);
      /* This is somewhat irrelevant since the profile data returned has
       * actually been uncompressed.
740
       */
741
      *compression_type = PNG_COMPRESSION_TYPE_BASE;
742 743
      return (PNG_INFO_iCCP);
   }
744

745 746 747 748
   return (0);
}
#endif

749
#ifdef PNG_sPLT_SUPPORTED
750 751
int PNGAPI
png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
752
    png_sPLT_tpp spalettes)
753 754
{
   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
755
   {
756
      *spalettes = info_ptr->splt_palettes;
757
      return info_ptr->splt_palettes_num;
758
   }
759

760
   return (0);
761 762 763
}
#endif

764
#ifdef PNG_hIST_SUPPORTED
765
png_uint_32 PNGAPI
766
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
767
    png_uint_16p *hist)
A
Andreas Dilger 已提交
768
{
769 770
   png_debug1(1, "in %s retrieval function", "hIST");

771
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
772
       && hist != NULL)
A
Andreas Dilger 已提交
773 774 775 776
   {
      *hist = info_ptr->hist;
      return (PNG_INFO_hIST);
   }
777

A
Andreas Dilger 已提交
778 779 780 781
   return (0);
}
#endif

782
png_uint_32 PNGAPI
783
png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
784 785 786
    png_uint_32 *width, png_uint_32 *height, int *bit_depth,
    int *color_type, int *interlace_type, int *compression_type,
    int *filter_type)
A
Andreas Dilger 已提交
787
{
788
   png_debug1(1, "in %s retrieval function", "IHDR");
789

790 791 792
   if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
       height == NULL || bit_depth == NULL || color_type == NULL)
      return (0);
793

794 795 796 797
   *width = info_ptr->width;
   *height = info_ptr->height;
   *bit_depth = info_ptr->bit_depth;
   *color_type = info_ptr->color_type;
798

799 800
   if (compression_type != NULL)
      *compression_type = info_ptr->compression_type;
801

802 803
   if (filter_type != NULL)
      *filter_type = info_ptr->filter_type;
804

805 806
   if (interlace_type != NULL)
      *interlace_type = info_ptr->interlace_type;
807

808 809 810 811 812
   /* This is redundant if we can be sure that the info_ptr values were all
    * assigned in png_set_IHDR().  We do the check anyhow in case an
    * application has ignored our advice not to mess with the members
    * of info_ptr directly.
    */
813
   png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
814 815
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
       info_ptr->compression_type, info_ptr->filter_type);
816

817
   return (1);
A
Andreas Dilger 已提交
818 819
}

820
#ifdef PNG_oFFs_SUPPORTED
821
png_uint_32 PNGAPI
822
png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
823
    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
824
{
825 826
   png_debug1(1, "in %s retrieval function", "oFFs");

827
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
828
       && offset_x != NULL && offset_y != NULL && unit_type != NULL)
A
Andreas Dilger 已提交
829 830 831 832 833 834
   {
      *offset_x = info_ptr->x_offset;
      *offset_y = info_ptr->y_offset;
      *unit_type = (int)info_ptr->offset_unit_type;
      return (PNG_INFO_oFFs);
   }
835

A
Andreas Dilger 已提交
836 837 838 839
   return (0);
}
#endif

840
#ifdef PNG_pCAL_SUPPORTED
841
png_uint_32 PNGAPI
842
png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
843 844
    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
    png_charp *units, png_charpp *params)
A
Andreas Dilger 已提交
845
{
846 847
   png_debug1(1, "in %s retrieval function", "pCAL");

848
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
849 850
       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
       nparams != NULL && units != NULL && params != NULL)
A
Andreas Dilger 已提交
851 852 853 854 855 856 857 858 859 860
   {
      *purpose = info_ptr->pcal_purpose;
      *X0 = info_ptr->pcal_X0;
      *X1 = info_ptr->pcal_X1;
      *type = (int)info_ptr->pcal_type;
      *nparams = (int)info_ptr->pcal_nparams;
      *units = info_ptr->pcal_units;
      *params = info_ptr->pcal_params;
      return (PNG_INFO_pCAL);
   }
861

A
Andreas Dilger 已提交
862 863 864 865
   return (0);
}
#endif

866
#ifdef PNG_sCAL_SUPPORTED
867
#  ifdef PNG_FIXED_POINT_SUPPORTED
868 869
#    if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
         defined(PNG_FLOATING_POINT_SUPPORTED)
G
[devel]  
Glenn Randers-Pehrson 已提交
870
png_uint_32 PNGAPI
871
png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
G
[devel]  
Glenn Randers-Pehrson 已提交
872 873 874 875 876 877
    int *unit, png_fixed_point *width, png_fixed_point *height)
{
   if (png_ptr != NULL && info_ptr != NULL &&
       (info_ptr->valid & PNG_INFO_sCAL))
   {
      *unit = info_ptr->scal_unit;
878 879 880 881
      /*TODO: make this work without FP support; the API is currently eliminated
       * if neither floating point APIs nor internal floating point arithmetic
       * are enabled.
       */
G
[devel]  
Glenn Randers-Pehrson 已提交
882 883 884 885 886 887 888 889
      *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
      *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
         "sCAL height");
      return (PNG_INFO_sCAL);
   }

   return(0);
}
890 891 892
#    endif /* FLOATING_ARITHMETIC */
#  endif /* FIXED_POINT */
#  ifdef PNG_FLOATING_POINT_SUPPORTED
893
png_uint_32 PNGAPI
894
png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
895 896 897 898 899 900
    int *unit, double *width, double *height)
{
   if (png_ptr != NULL && info_ptr != NULL &&
       (info_ptr->valid & PNG_INFO_sCAL))
   {
      *unit = info_ptr->scal_unit;
G
[devel]  
Glenn Randers-Pehrson 已提交
901 902
      *width = atof(info_ptr->scal_s_width);
      *height = atof(info_ptr->scal_s_height);
903 904
      return (PNG_INFO_sCAL);
   }
905

906
   return(0);
907
}
908
#  endif /* FLOATING POINT */
909
png_uint_32 PNGAPI
910
png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
911
    int *unit, png_charpp width, png_charpp height)
912
{
913 914 915 916 917 918 919 920
   if (png_ptr != NULL && info_ptr != NULL &&
       (info_ptr->valid & PNG_INFO_sCAL))
   {
      *unit = info_ptr->scal_unit;
      *width = info_ptr->scal_s_width;
      *height = info_ptr->scal_s_height;
      return (PNG_INFO_sCAL);
   }
921

922
   return(0);
923
}
924
#endif /* sCAL */
925

926
#ifdef PNG_pHYs_SUPPORTED
927
png_uint_32 PNGAPI
928
png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
929
    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
A
Andreas Dilger 已提交
930
{
931 932
   png_uint_32 retval = 0;

933 934
   png_debug1(1, "in %s retrieval function", "pHYs");

935
   if (png_ptr != NULL && info_ptr != NULL &&
936
       (info_ptr->valid & PNG_INFO_pHYs))
A
Andreas Dilger 已提交
937
   {
938
      if (res_x != NULL)
939 940
      {
         *res_x = info_ptr->x_pixels_per_unit;
941 942
         retval |= PNG_INFO_pHYs;
      }
943

944 945
      if (res_y != NULL)
      {
946 947 948
         *res_y = info_ptr->y_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
949

950 951 952 953 954
      if (unit_type != NULL)
      {
         *unit_type = (int)info_ptr->phys_unit_type;
         retval |= PNG_INFO_pHYs;
      }
A
Andreas Dilger 已提交
955
   }
956

957
   return (retval);
A
Andreas Dilger 已提交
958
}
959
#endif /* pHYs */
A
Andreas Dilger 已提交
960

961
png_uint_32 PNGAPI
962
png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
963
    png_colorp *palette, int *num_palette)
A
Andreas Dilger 已提交
964
{
965 966
   png_debug1(1, "in %s retrieval function", "PLTE");

967 968
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       && palette != NULL)
A
Andreas Dilger 已提交
969 970 971
   {
      *palette = info_ptr->palette;
      *num_palette = info_ptr->num_palette;
972
      png_debug1(3, "num_palette = %d", *num_palette);
A
Andreas Dilger 已提交
973 974
      return (PNG_INFO_PLTE);
   }
975

A
Andreas Dilger 已提交
976 977 978
   return (0);
}

979
#ifdef PNG_sBIT_SUPPORTED
980
png_uint_32 PNGAPI
981
png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
982
    png_color_8p *sig_bit)
A
Andreas Dilger 已提交
983
{
984 985
   png_debug1(1, "in %s retrieval function", "sBIT");

986
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
987
       && sig_bit != NULL)
A
Andreas Dilger 已提交
988 989 990 991
   {
      *sig_bit = &(info_ptr->sig_bit);
      return (PNG_INFO_sBIT);
   }
992

A
Andreas Dilger 已提交
993 994 995 996
   return (0);
}
#endif

997
#ifdef PNG_TEXT_SUPPORTED
998 999
int PNGAPI
png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
1000
    png_textp *text_ptr, int *num_text)
A
Andreas Dilger 已提交
1001
{
1002
   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
A
Andreas Dilger 已提交
1003
   {
1004 1005
      png_debug1(1, "in 0x%lx retrieval function",
         (unsigned long)png_ptr->chunk_name);
1006

A
Andreas Dilger 已提交
1007 1008
      if (text_ptr != NULL)
         *text_ptr = info_ptr->text;
1009

A
Andreas Dilger 已提交
1010 1011
      if (num_text != NULL)
         *num_text = info_ptr->num_text;
1012

1013
      return info_ptr->num_text;
A
Andreas Dilger 已提交
1014
   }
1015

1016
   if (num_text != NULL)
1017
      *num_text = 0;
1018

A
Andreas Dilger 已提交
1019 1020 1021 1022
   return(0);
}
#endif

1023
#ifdef PNG_tIME_SUPPORTED
1024
png_uint_32 PNGAPI
1025 1026
png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
    png_timep *mod_time)
A
Andreas Dilger 已提交
1027
{
1028 1029
   png_debug1(1, "in %s retrieval function", "tIME");

1030 1031
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       && mod_time != NULL)
A
Andreas Dilger 已提交
1032 1033 1034 1035
   {
      *mod_time = &(info_ptr->mod_time);
      return (PNG_INFO_tIME);
   }
1036

A
Andreas Dilger 已提交
1037 1038 1039 1040
   return (0);
}
#endif

1041
#ifdef PNG_tRNS_SUPPORTED
1042
png_uint_32 PNGAPI
1043
png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
1044
    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
A
Andreas Dilger 已提交
1045
{
1046
   png_uint_32 retval = 0;
1047
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
A
Andreas Dilger 已提交
1048
   {
1049
      png_debug1(1, "in %s retrieval function", "tRNS");
1050

1051
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
A
Andreas Dilger 已提交
1052
      {
1053 1054 1055 1056 1057 1058 1059 1060
         if (trans_alpha != NULL)
         {
            *trans_alpha = info_ptr->trans_alpha;
            retval |= PNG_INFO_tRNS;
         }

         if (trans_color != NULL)
            *trans_color = &(info_ptr->trans_color);
A
Andreas Dilger 已提交
1061
      }
1062

1063
      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
A
Andreas Dilger 已提交
1064
      {
1065 1066 1067 1068 1069 1070 1071 1072
         if (trans_color != NULL)
         {
            *trans_color = &(info_ptr->trans_color);
            retval |= PNG_INFO_tRNS;
         }

         if (trans_alpha != NULL)
            *trans_alpha = NULL;
A
Andreas Dilger 已提交
1073
      }
1074

1075
      if (num_trans != NULL)
A
Andreas Dilger 已提交
1076
      {
1077 1078
         *num_trans = info_ptr->num_trans;
         retval |= PNG_INFO_tRNS;
A
Andreas Dilger 已提交
1079 1080
      }
   }
1081

1082
   return (retval);
A
Andreas Dilger 已提交
1083 1084 1085
}
#endif

1086
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1087
int PNGAPI
1088
png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
1089
    png_unknown_chunkpp unknowns)
1090 1091
{
   if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1092
   {
1093
      *unknowns = info_ptr->unknown_chunks;
1094
      return info_ptr->unknown_chunks_num;
1095
   }
1096

1097
   return (0);
1098 1099 1100
}
#endif

1101
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1102
png_byte PNGAPI
1103
png_get_rgb_to_gray_status (png_const_structrp png_ptr)
1104
{
1105
   return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
1106 1107
}
#endif
1108

1109
#ifdef PNG_USER_CHUNKS_SUPPORTED
1110
png_voidp PNGAPI
1111
png_get_user_chunk_ptr(png_const_structrp png_ptr)
1112
{
1113
   return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1114 1115 1116
}
#endif

1117
png_size_t PNGAPI
1118
png_get_compression_buffer_size(png_const_structrp png_ptr)
1119
{
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
   if (png_ptr == NULL)
      return 0;

#  ifdef PNG_WRITE_SUPPORTED
      if (png_ptr->mode & PNG_IS_READ_STRUCT)
#  endif
   {
#     ifdef PNG_SEQUENTIAL_READ_SUPPORTED
         return png_ptr->IDAT_read_size;
#     else
         return PNG_IDAT_READ_SIZE;
#     endif
   }

#  ifdef PNG_WRITE_SUPPORTED
      else
         return png_ptr->zbuffer_size;
#  endif
1138 1139
}

1140
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1141 1142
/* These functions were added to libpng 1.2.6 and were enabled
 * by default in libpng-1.4.0 */
1143
png_uint_32 PNGAPI
1144
png_get_user_width_max (png_const_structrp png_ptr)
1145
{
1146
   return (png_ptr ? png_ptr->user_width_max : 0);
1147
}
1148

1149
png_uint_32 PNGAPI
1150
png_get_user_height_max (png_const_structrp png_ptr)
1151
{
1152
   return (png_ptr ? png_ptr->user_height_max : 0);
1153
}
1154

1155
/* This function was added to libpng 1.4.0 */
1156
png_uint_32 PNGAPI
1157
png_get_chunk_cache_max (png_const_structrp png_ptr)
1158
{
1159
   return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1160
}
1161

1162
/* This function was added to libpng 1.4.1 */
1163
png_alloc_size_t PNGAPI
1164
png_get_chunk_malloc_max (png_const_structrp png_ptr)
1165
{
1166
   return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1167
}
1168
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1169

1170
/* These functions were added to libpng 1.4.0 */
1171 1172
#ifdef PNG_IO_STATE_SUPPORTED
png_uint_32 PNGAPI
1173
png_get_io_state (png_const_structrp png_ptr)
1174
{
1175
   return png_ptr->io_state;
1176 1177
}

1178
png_uint_32 PNGAPI
1179
png_get_io_chunk_type (png_const_structrp png_ptr)
1180
{
1181
   return png_ptr->chunk_name;
1182
}
1183
#endif /* ?PNG_IO_STATE_SUPPORTED */
1184

1185 1186 1187 1188
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
#  ifdef PNG_GET_PALETTE_MAX_SUPPORTED
int PNGAPI
png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1189
{
1190 1191 1192 1193
   if (png_ptr != NULL && info_ptr != NULL)
      return png_ptr->num_palette_max;

   return (-1);
1194
}
1195 1196
#  endif
#endif
1197

1198
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */