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

/* pngget.c - retrieval of values from info struct
3
 *
4
 * Last changed in libpng 1.6.1 [March 28, 2013]
5
 * Copyright (c) 1998-2013 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
#endif
128

129 130 131
   return (0);
}

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

142
      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
143
         return (info_ptr->y_pixels_per_unit);
144 145
   }
#endif
146

147 148 149
   return (0);
}

150
png_uint_32 PNGAPI
151
png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
152
{
153
#ifdef PNG_pHYs_SUPPORTED
154
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
155
   {
156
      png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
157

158 159
      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
          info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
160
         return (info_ptr->x_pixels_per_unit);
161 162
   }
#endif
163

164 165 166
   return (0);
}

167
#ifdef PNG_FLOATING_POINT_SUPPORTED
168
float PNGAPI
169 170
png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
   info_ptr)
171
{
172
#ifdef PNG_READ_pHYs_SUPPORTED
173
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
174
   {
175
      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
176

177
      if (info_ptr->x_pixels_per_unit != 0)
178
         return ((float)((float)info_ptr->y_pixels_per_unit
179
             /(float)info_ptr->x_pixels_per_unit));
180
   }
181 182 183
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
184
#endif
185

186
   return ((float)0.0);
187
}
188
#endif
189

190 191
#ifdef PNG_FIXED_POINT_SUPPORTED
png_fixed_point PNGAPI
192 193
png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
    png_const_inforp info_ptr)
194 195 196
{
#ifdef PNG_READ_pHYs_SUPPORTED
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
197 198 199
       && 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)
200 201 202 203 204
   {
      png_fixed_point res;

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

205 206 207 208 209
      /* 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))
210
         return res;
211
   }
212 213 214
#else
   PNG_UNUSED(png_ptr)
   PNG_UNUSED(info_ptr)
215
#endif
216

217 218 219 220
   return 0;
}
#endif

221
png_int_32 PNGAPI
222
png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
223
{
224
#ifdef PNG_oFFs_SUPPORTED
225
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
226
   {
227
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
228

229
      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
230
         return (info_ptr->x_offset);
231 232
   }
#endif
233

234 235 236
   return (0);
}

237
png_int_32 PNGAPI
238
png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
239
{
240
#ifdef PNG_oFFs_SUPPORTED
241
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
242
   {
243
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
244

245
      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
246
         return (info_ptr->y_offset);
247 248
   }
#endif
249

250 251 252
   return (0);
}

253
png_int_32 PNGAPI
254
png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
255
{
256
#ifdef PNG_oFFs_SUPPORTED
257
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
258
   {
G
[devel]  
Glenn Randers-Pehrson 已提交
259
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
260

261
      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
262
         return (info_ptr->x_offset);
263 264
   }
#endif
265

266 267 268
   return (0);
}

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

277
      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
278
         return (info_ptr->y_offset);
279 280
   }
#endif
281

282 283 284
   return (0);
}

G
[devel]  
Glenn Randers-Pehrson 已提交
285 286 287 288 289
#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
static png_uint_32
ppi_from_ppm(png_uint_32 ppm)
{
#if 0
290
   /* The conversion is *(2.54/100), in binary (32 digits):
G
[devel]  
Glenn Randers-Pehrson 已提交
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
    * .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;
309 310
   if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
       5000))
G
[devel]  
Glenn Randers-Pehrson 已提交
311 312 313 314 315 316 317
      return result;

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

318
png_uint_32 PNGAPI
319
png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
320
{
G
[devel]  
Glenn Randers-Pehrson 已提交
321
   return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
322 323
}

324
png_uint_32 PNGAPI
325
png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
326
{
G
[devel]  
Glenn Randers-Pehrson 已提交
327
   return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
328 329
}

330
png_uint_32 PNGAPI
331
png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
332
{
G
[devel]  
Glenn Randers-Pehrson 已提交
333 334 335 336 337
   return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
}

#ifdef PNG_FIXED_POINT_SUPPORTED
static png_fixed_point
338
png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
G
[devel]  
Glenn Randers-Pehrson 已提交
339 340
{
   /* Convert from metres * 1,000,000 to inches * 100,000, meters to
341
    * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
G
[devel]  
Glenn Randers-Pehrson 已提交
342 343 344 345 346 347 348
    * 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
349 350
png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
    png_const_inforp info_ptr)
G
[devel]  
Glenn Randers-Pehrson 已提交
351 352
{
   return png_fixed_inches_from_microns(png_ptr,
353
       png_get_x_offset_microns(png_ptr, info_ptr));
G
[devel]  
Glenn Randers-Pehrson 已提交
354 355 356 357 358
}
#endif

#ifdef PNG_FIXED_POINT_SUPPORTED
png_fixed_point PNGAPI
359 360
png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
    png_const_inforp info_ptr)
G
[devel]  
Glenn Randers-Pehrson 已提交
361 362
{
   return png_fixed_inches_from_microns(png_ptr,
363
       png_get_y_offset_microns(png_ptr, info_ptr));
364
}
G
[devel]  
Glenn Randers-Pehrson 已提交
365
#endif
366

G
[devel]  
Glenn Randers-Pehrson 已提交
367
#ifdef PNG_FLOATING_POINT_SUPPORTED
368
float PNGAPI
369
png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
370
{
G
[devel]  
Glenn Randers-Pehrson 已提交
371 372 373
   /* To avoid the overflow do the conversion directly in floating
    * point.
    */
374
   return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
375
}
G
[devel]  
Glenn Randers-Pehrson 已提交
376
#endif
377

G
[devel]  
Glenn Randers-Pehrson 已提交
378
#ifdef PNG_FLOATING_POINT_SUPPORTED
379
float PNGAPI
380
png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
381
{
G
[devel]  
Glenn Randers-Pehrson 已提交
382 383 384
   /* To avoid the overflow do the conversion directly in floating
    * point.
    */
385
   return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
386
}
G
[devel]  
Glenn Randers-Pehrson 已提交
387
#endif
388

389
#ifdef PNG_pHYs_SUPPORTED
390
png_uint_32 PNGAPI
391
png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
392
    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
393 394 395
{
   png_uint_32 retval = 0;

396
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
397
   {
398
      png_debug1(1, "in %s retrieval function", "pHYs");
399

400 401 402 403 404
      if (res_x != NULL)
      {
         *res_x = info_ptr->x_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
405

406 407 408 409 410
      if (res_y != NULL)
      {
         *res_y = info_ptr->y_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
411

412 413 414 415
      if (unit_type != NULL)
      {
         *unit_type = (int)info_ptr->phys_unit_type;
         retval |= PNG_INFO_pHYs;
416

417
         if (*unit_type == 1)
418
         {
419 420
            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);
421 422 423
         }
      }
   }
424

425 426
   return (retval);
}
427
#endif /* PNG_pHYs_SUPPORTED */
G
[devel]  
Glenn Randers-Pehrson 已提交
428
#endif  /* PNG_INCH_CONVERSIONS_SUPPORTED */
429 430

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

432 433
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

434

435
png_byte PNGAPI
436
png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
A
Andreas Dilger 已提交
437
{
438
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
439
      return(info_ptr->channels);
440

441
   return (0);
A
Andreas Dilger 已提交
442 443
}

444
#ifdef PNG_READ_SUPPORTED
445
png_const_bytep PNGAPI
446
png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
A
Andreas Dilger 已提交
447
{
448
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
449
      return(info_ptr->signature);
450

451
   return (NULL);
A
Andreas Dilger 已提交
452
}
453
#endif
A
Andreas Dilger 已提交
454

455
#ifdef PNG_bKGD_SUPPORTED
456
png_uint_32 PNGAPI
457
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
A
Andreas Dilger 已提交
458 459
   png_color_16p *background)
{
460
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
461
       && background != NULL)
A
Andreas Dilger 已提交
462
   {
463
      png_debug1(1, "in %s retrieval function", "bKGD");
464

A
Andreas Dilger 已提交
465 466 467
      *background = &(info_ptr->background);
      return (PNG_INFO_bKGD);
   }
468

A
Andreas Dilger 已提交
469 470 471 472
   return (0);
}
#endif

473
#ifdef PNG_cHRM_SUPPORTED
474 475 476 477
/* 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
 */
478
#  ifdef PNG_FLOATING_POINT_SUPPORTED
479
png_uint_32 PNGAPI
480
png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
481 482
    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 已提交
483
{
484 485 486 487 488 489 490 491
   /* 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 已提交
492
   {
493
      png_debug1(1, "in %s retrieval function", "cHRM");
494

A
Andreas Dilger 已提交
495
      if (white_x != NULL)
496 497
         *white_x = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
A
Andreas Dilger 已提交
498
      if (white_y != NULL)
499 500
         *white_y = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
A
Andreas Dilger 已提交
501
      if (red_x != NULL)
502 503
         *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
            "cHRM red X");
A
Andreas Dilger 已提交
504
      if (red_y != NULL)
505 506
         *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
            "cHRM red Y");
A
Andreas Dilger 已提交
507
      if (green_x != NULL)
508 509
         *green_x = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
A
Andreas Dilger 已提交
510
      if (green_y != NULL)
511 512
         *green_y = png_float(png_ptr,
            info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
A
Andreas Dilger 已提交
513
      if (blue_x != NULL)
514 515
         *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
            "cHRM blue X");
A
Andreas Dilger 已提交
516
      if (blue_y != NULL)
517 518
         *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
            "cHRM blue Y");
A
Andreas Dilger 已提交
519 520
      return (PNG_INFO_cHRM);
   }
521

A
Andreas Dilger 已提交
522 523
   return (0);
}
524 525

png_uint_32 PNGAPI
526
png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
527 528 529 530
   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)
{
531 532
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
533
   {
534 535
      png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");

536
      if (red_X != NULL)
537 538
         *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
            "cHRM red X");
539
      if (red_Y != NULL)
540 541
         *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
            "cHRM red Y");
542
      if (red_Z != NULL)
543 544
         *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
            "cHRM red Z");
545
      if (green_X != NULL)
546 547
         *green_X = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
548
      if (green_Y != NULL)
549 550
         *green_Y = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
551
      if (green_Z != NULL)
552 553
         *green_Z = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
554
      if (blue_X != NULL)
555 556
         *blue_X = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
557
      if (blue_Y != NULL)
558 559
         *blue_Y = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
560
      if (blue_Z != NULL)
561 562
         *blue_Z = png_float(png_ptr,
            info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
563 564 565 566 567
      return (PNG_INFO_cHRM);
   }

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

570
#  ifdef PNG_FIXED_POINT_SUPPORTED
571
png_uint_32 PNGAPI
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
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,
610 611 612
    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)
613
{
614 615
   png_debug1(1, "in %s retrieval function", "cHRM");

616 617
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
618 619
   {
      if (white_x != NULL)
620
         *white_x = info_ptr->colorspace.end_points_xy.whitex;
621
      if (white_y != NULL)
622
         *white_y = info_ptr->colorspace.end_points_xy.whitey;
623
      if (red_x != NULL)
624
         *red_x = info_ptr->colorspace.end_points_xy.redx;
625
      if (red_y != NULL)
626
         *red_y = info_ptr->colorspace.end_points_xy.redy;
627
      if (green_x != NULL)
628
         *green_x = info_ptr->colorspace.end_points_xy.greenx;
629
      if (green_y != NULL)
630
         *green_y = info_ptr->colorspace.end_points_xy.greeny;
631
      if (blue_x != NULL)
632
         *blue_x = info_ptr->colorspace.end_points_xy.bluex;
633
      if (blue_y != NULL)
634
         *blue_y = info_ptr->colorspace.end_points_xy.bluey;
635 636
      return (PNG_INFO_cHRM);
   }
637

638 639
   return (0);
}
640
#  endif
641
#endif
A
Andreas Dilger 已提交
642

643
#ifdef PNG_gAMA_SUPPORTED
644 645 646
#  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 已提交
647
    png_fixed_point *file_gamma)
A
Andreas Dilger 已提交
648
{
649 650
   png_debug1(1, "in %s retrieval function", "gAMA");

651 652 653
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
      file_gamma != NULL)
A
Andreas Dilger 已提交
654
   {
655
      *file_gamma = info_ptr->colorspace.gamma;
A
Andreas Dilger 已提交
656 657
      return (PNG_INFO_gAMA);
   }
G
[devel]  
Glenn Randers-Pehrson 已提交
658

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

663
#  ifdef PNG_FLOATING_POINT_SUPPORTED
664
png_uint_32 PNGAPI
665
png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
666
    double *file_gamma)
667
{
668
   png_debug1(1, "in %s retrieval function", "gAMA(float)");
669

670 671 672 673 674 675 676 677
   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);
   }
678

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

684
#ifdef PNG_sRGB_SUPPORTED
685
png_uint_32 PNGAPI
686
png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
687
    int *file_srgb_intent)
688
{
689 690
   png_debug1(1, "in %s retrieval function", "sRGB");

691
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
692
       && file_srgb_intent != NULL)
693
   {
694
      *file_srgb_intent = info_ptr->colorspace.rendering_intent;
695 696
      return (PNG_INFO_sRGB);
   }
697

698 699 700 701
   return (0);
}
#endif

702
#ifdef PNG_iCCP_SUPPORTED
703
png_uint_32 PNGAPI
704
png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
705
    png_charpp name, int *compression_type,
G
[devel]  
Glenn Randers-Pehrson 已提交
706
    png_bytepp profile, png_uint_32 *proflen)
707
{
708 709
   png_debug1(1, "in %s retrieval function", "iCCP");

710
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
711 712
       && name != NULL && compression_type != NULL && profile != NULL &&
		 proflen != NULL)
713 714 715
   {
      *name = info_ptr->iccp_name;
      *profile = info_ptr->iccp_profile;
716 717 718
      *proflen = png_get_uint_32(info_ptr->iccp_profile);
      /* This is somewhat irrelevant since the profile data returned has
       * actually been uncompressed.
719
       */
720
      *compression_type = PNG_COMPRESSION_TYPE_BASE;
721 722
      return (PNG_INFO_iCCP);
   }
723

724 725 726 727
   return (0);
}
#endif

728
#ifdef PNG_sPLT_SUPPORTED
729 730
int PNGAPI
png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
731
    png_sPLT_tpp spalettes)
732 733
{
   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
734
   {
735
      *spalettes = info_ptr->splt_palettes;
736
      return info_ptr->splt_palettes_num;
737
   }
738

739
   return (0);
740 741 742
}
#endif

743
#ifdef PNG_hIST_SUPPORTED
744
png_uint_32 PNGAPI
745
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
746
    png_uint_16p *hist)
A
Andreas Dilger 已提交
747
{
748 749
   png_debug1(1, "in %s retrieval function", "hIST");

750
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
751
       && hist != NULL)
A
Andreas Dilger 已提交
752 753 754 755
   {
      *hist = info_ptr->hist;
      return (PNG_INFO_hIST);
   }
756

A
Andreas Dilger 已提交
757 758 759 760
   return (0);
}
#endif

761
png_uint_32 PNGAPI
762
png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
763 764 765
    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 已提交
766
{
767
   png_debug1(1, "in %s retrieval function", "IHDR");
768

769 770 771
   if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
       height == NULL || bit_depth == NULL || color_type == NULL)
      return (0);
772

773 774 775 776
   *width = info_ptr->width;
   *height = info_ptr->height;
   *bit_depth = info_ptr->bit_depth;
   *color_type = info_ptr->color_type;
777

778 779
   if (compression_type != NULL)
      *compression_type = info_ptr->compression_type;
780

781 782
   if (filter_type != NULL)
      *filter_type = info_ptr->filter_type;
783

784 785
   if (interlace_type != NULL)
      *interlace_type = info_ptr->interlace_type;
786

787 788 789 790 791
   /* 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.
    */
792
   png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
793 794
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
       info_ptr->compression_type, info_ptr->filter_type);
795

796
   return (1);
A
Andreas Dilger 已提交
797 798
}

799
#ifdef PNG_oFFs_SUPPORTED
800
png_uint_32 PNGAPI
801
png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
802
    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
803
{
804 805
   png_debug1(1, "in %s retrieval function", "oFFs");

806
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
807
       && offset_x != NULL && offset_y != NULL && unit_type != NULL)
A
Andreas Dilger 已提交
808 809 810 811 812 813
   {
      *offset_x = info_ptr->x_offset;
      *offset_y = info_ptr->y_offset;
      *unit_type = (int)info_ptr->offset_unit_type;
      return (PNG_INFO_oFFs);
   }
814

A
Andreas Dilger 已提交
815 816 817 818
   return (0);
}
#endif

819
#ifdef PNG_pCAL_SUPPORTED
820
png_uint_32 PNGAPI
821
png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
822 823
    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
    png_charp *units, png_charpp *params)
A
Andreas Dilger 已提交
824
{
825 826
   png_debug1(1, "in %s retrieval function", "pCAL");

827
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
828 829
       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
       nparams != NULL && units != NULL && params != NULL)
A
Andreas Dilger 已提交
830 831 832 833 834 835 836 837 838 839
   {
      *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);
   }
840

A
Andreas Dilger 已提交
841 842 843 844
   return (0);
}
#endif

845
#ifdef PNG_sCAL_SUPPORTED
846
#  ifdef PNG_FIXED_POINT_SUPPORTED
847 848
#    if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
         defined(PNG_FLOATING_POINT_SUPPORTED)
G
[devel]  
Glenn Randers-Pehrson 已提交
849
png_uint_32 PNGAPI
850
png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
G
[devel]  
Glenn Randers-Pehrson 已提交
851 852 853 854 855 856
    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;
857 858 859 860
      /*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 已提交
861 862 863 864 865 866 867 868
      *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);
}
869 870 871
#    endif /* FLOATING_ARITHMETIC */
#  endif /* FIXED_POINT */
#  ifdef PNG_FLOATING_POINT_SUPPORTED
872
png_uint_32 PNGAPI
873
png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
874 875 876 877 878 879
    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 已提交
880 881
      *width = atof(info_ptr->scal_s_width);
      *height = atof(info_ptr->scal_s_height);
882 883
      return (PNG_INFO_sCAL);
   }
884

885
   return(0);
886
}
887
#  endif /* FLOATING POINT */
888
png_uint_32 PNGAPI
889
png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
890
    int *unit, png_charpp width, png_charpp height)
891
{
892 893 894 895 896 897 898 899
   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);
   }
900

901
   return(0);
902
}
903
#endif /* sCAL */
904

905
#ifdef PNG_pHYs_SUPPORTED
906
png_uint_32 PNGAPI
907
png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
908
    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
A
Andreas Dilger 已提交
909
{
910 911
   png_uint_32 retval = 0;

912 913
   png_debug1(1, "in %s retrieval function", "pHYs");

914
   if (png_ptr != NULL && info_ptr != NULL &&
915
       (info_ptr->valid & PNG_INFO_pHYs))
A
Andreas Dilger 已提交
916
   {
917
      if (res_x != NULL)
918 919
      {
         *res_x = info_ptr->x_pixels_per_unit;
920 921
         retval |= PNG_INFO_pHYs;
      }
922

923 924
      if (res_y != NULL)
      {
925 926 927
         *res_y = info_ptr->y_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
928

929 930 931 932 933
      if (unit_type != NULL)
      {
         *unit_type = (int)info_ptr->phys_unit_type;
         retval |= PNG_INFO_pHYs;
      }
A
Andreas Dilger 已提交
934
   }
935

936
   return (retval);
A
Andreas Dilger 已提交
937
}
938
#endif /* pHYs */
A
Andreas Dilger 已提交
939

940
png_uint_32 PNGAPI
941
png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
942
    png_colorp *palette, int *num_palette)
A
Andreas Dilger 已提交
943
{
944 945
   png_debug1(1, "in %s retrieval function", "PLTE");

946 947
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       && palette != NULL)
A
Andreas Dilger 已提交
948 949 950
   {
      *palette = info_ptr->palette;
      *num_palette = info_ptr->num_palette;
951
      png_debug1(3, "num_palette = %d", *num_palette);
A
Andreas Dilger 已提交
952 953
      return (PNG_INFO_PLTE);
   }
954

A
Andreas Dilger 已提交
955 956 957
   return (0);
}

958
#ifdef PNG_sBIT_SUPPORTED
959
png_uint_32 PNGAPI
960
png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
961
    png_color_8p *sig_bit)
A
Andreas Dilger 已提交
962
{
963 964
   png_debug1(1, "in %s retrieval function", "sBIT");

965
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
966
       && sig_bit != NULL)
A
Andreas Dilger 已提交
967 968 969 970
   {
      *sig_bit = &(info_ptr->sig_bit);
      return (PNG_INFO_sBIT);
   }
971

A
Andreas Dilger 已提交
972 973 974 975
   return (0);
}
#endif

976
#ifdef PNG_TEXT_SUPPORTED
977 978
int PNGAPI
png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
979
    png_textp *text_ptr, int *num_text)
A
Andreas Dilger 已提交
980
{
981
   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
A
Andreas Dilger 已提交
982
   {
983 984
      png_debug1(1, "in 0x%lx retrieval function",
         (unsigned long)png_ptr->chunk_name);
985

A
Andreas Dilger 已提交
986 987
      if (text_ptr != NULL)
         *text_ptr = info_ptr->text;
988

A
Andreas Dilger 已提交
989 990
      if (num_text != NULL)
         *num_text = info_ptr->num_text;
991

992
      return info_ptr->num_text;
A
Andreas Dilger 已提交
993
   }
994

995
   if (num_text != NULL)
996
      *num_text = 0;
997

A
Andreas Dilger 已提交
998 999 1000 1001
   return(0);
}
#endif

1002
#ifdef PNG_tIME_SUPPORTED
1003
png_uint_32 PNGAPI
1004 1005
png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
    png_timep *mod_time)
A
Andreas Dilger 已提交
1006
{
1007 1008
   png_debug1(1, "in %s retrieval function", "tIME");

1009 1010
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       && mod_time != NULL)
A
Andreas Dilger 已提交
1011 1012 1013 1014
   {
      *mod_time = &(info_ptr->mod_time);
      return (PNG_INFO_tIME);
   }
1015

A
Andreas Dilger 已提交
1016 1017 1018 1019
   return (0);
}
#endif

1020
#ifdef PNG_tRNS_SUPPORTED
1021
png_uint_32 PNGAPI
1022
png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
1023
    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
A
Andreas Dilger 已提交
1024
{
1025
   png_uint_32 retval = 0;
1026
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
A
Andreas Dilger 已提交
1027
   {
1028
      png_debug1(1, "in %s retrieval function", "tRNS");
1029

1030
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
A
Andreas Dilger 已提交
1031
      {
1032 1033 1034 1035 1036 1037 1038 1039
         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 已提交
1040
      }
1041

1042
      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
A
Andreas Dilger 已提交
1043
      {
1044 1045 1046 1047 1048 1049 1050 1051
         if (trans_color != NULL)
         {
            *trans_color = &(info_ptr->trans_color);
            retval |= PNG_INFO_tRNS;
         }

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

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

1061
   return (retval);
A
Andreas Dilger 已提交
1062 1063 1064
}
#endif

1065
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1066
int PNGAPI
1067
png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
1068
    png_unknown_chunkpp unknowns)
1069 1070
{
   if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1071
   {
1072
      *unknowns = info_ptr->unknown_chunks;
1073
      return info_ptr->unknown_chunks_num;
1074
   }
1075

1076
   return (0);
1077 1078 1079
}
#endif

1080
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1081
png_byte PNGAPI
1082
png_get_rgb_to_gray_status (png_const_structrp png_ptr)
1083
{
1084
   return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
1085 1086
}
#endif
1087

1088
#ifdef PNG_USER_CHUNKS_SUPPORTED
1089
png_voidp PNGAPI
1090
png_get_user_chunk_ptr(png_const_structrp png_ptr)
1091
{
1092
   return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1093 1094 1095
}
#endif

1096
png_size_t PNGAPI
1097
png_get_compression_buffer_size(png_const_structrp png_ptr)
1098
{
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
   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
1117 1118
}

1119
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1120 1121
/* These functions were added to libpng 1.2.6 and were enabled
 * by default in libpng-1.4.0 */
1122
png_uint_32 PNGAPI
1123
png_get_user_width_max (png_const_structrp png_ptr)
1124
{
1125
   return (png_ptr ? png_ptr->user_width_max : 0);
1126
}
1127

1128
png_uint_32 PNGAPI
1129
png_get_user_height_max (png_const_structrp png_ptr)
1130
{
1131
   return (png_ptr ? png_ptr->user_height_max : 0);
1132
}
1133

1134
/* This function was added to libpng 1.4.0 */
1135
png_uint_32 PNGAPI
1136
png_get_chunk_cache_max (png_const_structrp png_ptr)
1137
{
1138
   return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1139
}
1140

1141
/* This function was added to libpng 1.4.1 */
1142
png_alloc_size_t PNGAPI
1143
png_get_chunk_malloc_max (png_const_structrp png_ptr)
1144
{
1145
   return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1146
}
1147
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1148

1149
/* These functions were added to libpng 1.4.0 */
1150 1151
#ifdef PNG_IO_STATE_SUPPORTED
png_uint_32 PNGAPI
1152
png_get_io_state (png_const_structrp png_ptr)
1153
{
1154
   return png_ptr->io_state;
1155 1156
}

1157
png_uint_32 PNGAPI
1158
png_get_io_chunk_type (png_const_structrp png_ptr)
1159
{
1160
   return png_ptr->chunk_name;
1161
}
1162
#endif /* ?PNG_IO_STATE_SUPPORTED */
1163

1164 1165 1166 1167
#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)
1168
{
1169 1170 1171 1172
   if (png_ptr != NULL && info_ptr != NULL)
      return png_ptr->num_palette_max;

   return (-1);
1173
}
1174 1175
#  endif
#endif
1176

1177
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */