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

/* pngget.c - retrieval of values from info struct
3
 *
4
 * Last changed in libpng 1.4.0 [June 25, 2009]
5
 * Copyright (c) 1998-2009 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 zlib/libpng license.
10 11
 * For conditions of distribution and use, see copyright notice, disclaimer,
 * and license in png.h
12
 *
13
 */
A
Andreas Dilger 已提交
14 15

#include "png.h"
16
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
17
#include "pngpriv.h"
18

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

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

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

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

39
#if defined(PNG_INFO_IMAGE_SUPPORTED)
40
png_bytepp PNGAPI
41 42 43 44
png_get_rows(png_structp png_ptr, png_infop info_ptr)
{
   if (png_ptr != NULL && info_ptr != NULL)
      return(info_ptr->row_pointers);
45

46 47 48 49 50
   else
      return(0);
}
#endif

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

59 60 61
   return (0);
}

62
png_uint_32 PNGAPI
63 64
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{
65
   if (png_ptr != NULL && info_ptr != NULL)
66
      return info_ptr->height;
67

68 69 70
   return (0);
}

71
png_byte PNGAPI
72 73
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
74
   if (png_ptr != NULL && info_ptr != NULL)
75
      return info_ptr->bit_depth;
76

77 78 79
   return (0);
}

80
png_byte PNGAPI
81 82
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
83
   if (png_ptr != NULL && info_ptr != NULL)
84
      return info_ptr->color_type;
85

86 87 88
   return (0);
}

89
png_byte PNGAPI
90 91
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{
92
   if (png_ptr != NULL && info_ptr != NULL)
93
      return info_ptr->filter_type;
94

95 96 97
   return (0);
}

98
png_byte PNGAPI
99 100
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{
101
   if (png_ptr != NULL && info_ptr != NULL)
102
      return info_ptr->interlace_type;
103

104 105 106
   return (0);
}

107
png_byte PNGAPI
108 109
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
110
   if (png_ptr != NULL && info_ptr != NULL)
111
      return info_ptr->compression_type;
112

113 114 115
   return (0);
}

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

125
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
126
          return (0);
127

128 129
      else
          return (info_ptr->x_pixels_per_unit);
130
   }
131 132
#else
   return (0);
133 134 135 136
#endif
   return (0);
}

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

146
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
147
          return (0);
148

149 150
      else
          return (info_ptr->y_pixels_per_unit);
151
   }
152 153
#else
   return (0);
154 155 156 157
#endif
   return (0);
}

158
png_uint_32 PNGAPI
159 160
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
161
   if (png_ptr != NULL && info_ptr != NULL)
162
#if defined(PNG_pHYs_SUPPORTED)
163
   if (info_ptr->valid & PNG_INFO_pHYs)
164
   {
165
      png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
166

167
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
168
         info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
169
          return (0);
170

171 172
      else
          return (info_ptr->x_pixels_per_unit);
173
   }
174 175
#else
   return (0);
176 177 178 179
#endif
   return (0);
}

180
#ifdef PNG_FLOATING_POINT_SUPPORTED
181
float PNGAPI
182 183
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
   {
184
   if (png_ptr != NULL && info_ptr != NULL)
185
#if defined(PNG_pHYs_SUPPORTED)
186

187
   if (info_ptr->valid & PNG_INFO_pHYs)
188
   {
189
      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
190
      if (info_ptr->x_pixels_per_unit == 0)
191
         return ((float)0.0);
192
      else
193 194
         return ((float)((float)info_ptr->y_pixels_per_unit
            /(float)info_ptr->x_pixels_per_unit));
195
   }
196
#else
197
      return (0.0);
198
#endif
199
   return ((float)0.0);
200
}
201
#endif
202

203
png_int_32 PNGAPI
204 205
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
206
   if (png_ptr != NULL && info_ptr != NULL)
207
#if defined(PNG_oFFs_SUPPORTED)
208

209
   if (info_ptr->valid & PNG_INFO_oFFs)
210
   {
211
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
212

213
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
214
          return (0);
215

216 217
      else
          return (info_ptr->x_offset);
218
   }
219
#else
220
      return (0);
221 222 223 224
#endif
   return (0);
}

225
png_int_32 PNGAPI
226 227
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
228
   if (png_ptr != NULL && info_ptr != NULL)
229

230
#if defined(PNG_oFFs_SUPPORTED)
231
   if (info_ptr->valid & PNG_INFO_oFFs)
232
   {
233
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
234

235
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
236
          return (0);
237

238 239
      else
          return (info_ptr->y_offset);
240
   }
241 242
#else
   return (0);
243 244 245 246
#endif
   return (0);
}

247
png_int_32 PNGAPI
248 249
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
250
   if (png_ptr != NULL && info_ptr != NULL)
251

252
#if defined(PNG_oFFs_SUPPORTED)
253
   if (info_ptr->valid & PNG_INFO_oFFs)
254
   {
255
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
256

257
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
258
          return (0);
259

260 261
      else
          return (info_ptr->x_offset);
262
   }
263 264
#else
   return (0);
265 266 267 268
#endif
   return (0);
}

269
png_int_32 PNGAPI
270 271
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
272
   if (png_ptr != NULL && info_ptr != NULL)
273

274
#if defined(PNG_oFFs_SUPPORTED)
275
   if (info_ptr->valid & PNG_INFO_oFFs)
276
   {
277
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
278

279
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
280
          return (0);
281

282 283
      else
          return (info_ptr->y_offset);
284
   }
285 286
#else
   return (0);
287 288 289 290
#endif
   return (0);
}

291
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
292
png_uint_32 PNGAPI
293 294 295
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
   return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
296
     *.0254 +.5));
297 298
}

299
png_uint_32 PNGAPI
300 301 302
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
   return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
303
     *.0254 +.5));
304 305
}

306
png_uint_32 PNGAPI
307 308 309
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
   return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
310
     *.0254 +.5));
311 312
}

313
float PNGAPI
314 315 316
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
317
     *.00003937);
318 319
}

320
float PNGAPI
321 322 323
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
324
     *.00003937);
325 326
}

327
#if defined(PNG_pHYs_SUPPORTED)
328
png_uint_32 PNGAPI
329 330 331 332 333
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
   png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
   png_uint_32 retval = 0;

334
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
335
   {
336
      png_debug1(1, "in %s retrieval function", "pHYs");
337 338 339 340 341 342 343 344 345 346 347 348 349 350
      if (res_x != NULL)
      {
         *res_x = info_ptr->x_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
      if (res_y != NULL)
      {
         *res_y = info_ptr->y_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
      if (unit_type != NULL)
      {
         *unit_type = (int)info_ptr->phys_unit_type;
         retval |= PNG_INFO_pHYs;
351
         if (*unit_type == 1)
352
         {
353 354
            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);
355 356 357 358 359
         }
      }
   }
   return (retval);
}
360
#endif /* PNG_pHYs_SUPPORTED */
361
#endif  /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
362 363

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

365 366
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

367
png_byte PNGAPI
A
Andreas Dilger 已提交
368 369
png_get_channels(png_structp png_ptr, png_infop info_ptr)
{
370
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
371 372
      return(info_ptr->channels);
   else
373
      return (0);
A
Andreas Dilger 已提交
374 375
}

376
png_bytep PNGAPI
A
Andreas Dilger 已提交
377 378
png_get_signature(png_structp png_ptr, png_infop info_ptr)
{
379
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
380 381
      return(info_ptr->signature);
   else
382
      return (NULL);
A
Andreas Dilger 已提交
383 384
}

385
#if defined(PNG_bKGD_SUPPORTED)
386
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
387 388 389
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
   png_color_16p *background)
{
390 391
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
      && background != NULL)
A
Andreas Dilger 已提交
392
   {
393
      png_debug1(1, "in %s retrieval function", "bKGD");
A
Andreas Dilger 已提交
394 395 396 397 398 399 400
      *background = &(info_ptr->background);
      return (PNG_INFO_bKGD);
   }
   return (0);
}
#endif

401
#if defined(PNG_cHRM_SUPPORTED)
402
#ifdef PNG_FLOATING_POINT_SUPPORTED
403
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
404 405 406 407
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
   double *white_x, double *white_y, double *red_x, double *red_y,
   double *green_x, double *green_y, double *blue_x, double *blue_y)
{
408
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
A
Andreas Dilger 已提交
409
   {
410
      png_debug1(1, "in %s retrieval function", "cHRM");
A
Andreas Dilger 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
      if (white_x != NULL)
         *white_x = (double)info_ptr->x_white;
      if (white_y != NULL)
         *white_y = (double)info_ptr->y_white;
      if (red_x != NULL)
         *red_x = (double)info_ptr->x_red;
      if (red_y != NULL)
         *red_y = (double)info_ptr->y_red;
      if (green_x != NULL)
         *green_x = (double)info_ptr->x_green;
      if (green_y != NULL)
         *green_y = (double)info_ptr->y_green;
      if (blue_x != NULL)
         *blue_x = (double)info_ptr->x_blue;
      if (blue_y != NULL)
         *blue_y = (double)info_ptr->y_blue;
      return (PNG_INFO_cHRM);
   }
   return (0);
}
#endif
432
#ifdef PNG_FIXED_POINT_SUPPORTED
433
png_uint_32 PNGAPI
434
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
435 436 437
   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)
438 439 440
{
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
   {
441
      png_debug1(1, "in %s retrieval function", "cHRM");
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
      if (white_x != NULL)
         *white_x = info_ptr->int_x_white;
      if (white_y != NULL)
         *white_y = info_ptr->int_y_white;
      if (red_x != NULL)
         *red_x = info_ptr->int_x_red;
      if (red_y != NULL)
         *red_y = info_ptr->int_y_red;
      if (green_x != NULL)
         *green_x = info_ptr->int_x_green;
      if (green_y != NULL)
         *green_y = info_ptr->int_y_green;
      if (blue_x != NULL)
         *blue_x = info_ptr->int_x_blue;
      if (blue_y != NULL)
         *blue_y = info_ptr->int_y_blue;
      return (PNG_INFO_cHRM);
   }
   return (0);
}
#endif
#endif
A
Andreas Dilger 已提交
464

465
#if defined(PNG_gAMA_SUPPORTED)
466
#ifdef PNG_FLOATING_POINT_SUPPORTED
467
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
468 469
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{
470 471
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
      && file_gamma != NULL)
A
Andreas Dilger 已提交
472
   {
473
      png_debug1(1, "in %s retrieval function", "gAMA");
A
Andreas Dilger 已提交
474 475 476 477 478 479
      *file_gamma = (double)info_ptr->gamma;
      return (PNG_INFO_gAMA);
   }
   return (0);
}
#endif
480
#ifdef PNG_FIXED_POINT_SUPPORTED
481
png_uint_32 PNGAPI
482
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
483
    png_fixed_point *int_file_gamma)
484 485 486 487
{
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
      && int_file_gamma != NULL)
   {
488
      png_debug1(1, "in %s retrieval function", "gAMA");
489 490 491 492 493 494
      *int_file_gamma = info_ptr->int_gamma;
      return (PNG_INFO_gAMA);
   }
   return (0);
}
#endif
495
#endif
A
Andreas Dilger 已提交
496

497
#if defined(PNG_sRGB_SUPPORTED)
498
png_uint_32 PNGAPI
499
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
500
{
501 502
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
      && file_srgb_intent != NULL)
503
   {
504
      png_debug1(1, "in %s retrieval function", "sRGB");
505
      *file_srgb_intent = (int)info_ptr->srgb_intent;
506 507 508 509 510 511
      return (PNG_INFO_sRGB);
   }
   return (0);
}
#endif

512
#if defined(PNG_iCCP_SUPPORTED)
513
png_uint_32 PNGAPI
514 515
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
             png_charpp name, int *compression_type,
516
             png_charpp profile, png_uint_32 *proflen)
517 518 519 520
{
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
      && name != NULL && profile != NULL && proflen != NULL)
   {
521
      png_debug1(1, "in %s retrieval function", "iCCP");
522 523
      *name = info_ptr->iccp_name;
      *profile = info_ptr->iccp_profile;
524 525 526
      /* Compression_type is a dummy so the API won't have to change
       * if we introduce multiple compression types later.
       */
527 528 529 530 531 532 533 534
      *proflen = (int)info_ptr->iccp_proflen;
      *compression_type = (int)info_ptr->iccp_compression;
      return (PNG_INFO_iCCP);
   }
   return (0);
}
#endif

535
#if defined(PNG_sPLT_SUPPORTED)
536
png_uint_32 PNGAPI
537
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
538
             png_sPLT_tpp spalettes)
539 540
{
   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
541
   {
542
     *spalettes = info_ptr->splt_palettes;
543 544 545
     return ((png_uint_32)info_ptr->splt_palettes_num);
   }
   return (0);
546 547 548
}
#endif

549
#if defined(PNG_hIST_SUPPORTED)
550
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
551 552
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
553 554
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
      && hist != NULL)
A
Andreas Dilger 已提交
555
   {
556
      png_debug1(1, "in %s retrieval function", "hIST");
A
Andreas Dilger 已提交
557 558 559 560 561 562 563
      *hist = info_ptr->hist;
      return (PNG_INFO_hIST);
   }
   return (0);
}
#endif

564
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
565 566 567 568
png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
   png_uint_32 *width, png_uint_32 *height, int *bit_depth,
   int *color_type, int *interlace_type, int *compression_type,
   int *filter_type)
569

A
Andreas Dilger 已提交
570
{
571
   if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
A
Andreas Dilger 已提交
572 573
      bit_depth != NULL && color_type != NULL)
   {
574
      png_debug1(1, "in %s retrieval function", "IHDR");
A
Andreas Dilger 已提交
575 576 577
      *width = info_ptr->width;
      *height = info_ptr->height;
      *bit_depth = info_ptr->bit_depth;
578
      if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
579 580
         png_error(png_ptr, "Invalid bit depth");

A
Andreas Dilger 已提交
581
      *color_type = info_ptr->color_type;
582

583
      if (info_ptr->color_type > 6)
584 585
         png_error(png_ptr, "Invalid color type");

A
Andreas Dilger 已提交
586 587
      if (compression_type != NULL)
         *compression_type = info_ptr->compression_type;
588

A
Andreas Dilger 已提交
589 590
      if (filter_type != NULL)
         *filter_type = info_ptr->filter_type;
591

A
Andreas Dilger 已提交
592 593
      if (interlace_type != NULL)
         *interlace_type = info_ptr->interlace_type;
594

595
      /* Check for potential overflow of rowbytes */
596
      if (*width == 0 || *width > PNG_UINT_31_MAX)
597
        png_error(png_ptr, "Invalid image width");
598

599
      if (*height == 0 || *height > PNG_UINT_31_MAX)
600
        png_error(png_ptr, "Invalid image height");
601

602 603 604 605 606 607
      if (info_ptr->width > (PNG_UINT_32_MAX
                 >> 3)      /* 8-byte RGBA pixels */
                 - 64       /* bigrowbuf hack */
                 - 1        /* filter byte */
                 - 7*8      /* rounding of width to multiple of 8 pixels */
                 - 8)       /* extra max_pixel_depth pad */
608
      {
609
         png_warning(png_ptr,
610
            "Width too large for libpng to process image data");
611
      }
612

A
Andreas Dilger 已提交
613 614 615 616 617
      return (1);
   }
   return (0);
}

618
#if defined(PNG_oFFs_SUPPORTED)
619
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
620
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
621
   png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
622
{
623 624
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
      && offset_x != NULL && offset_y != NULL && unit_type != NULL)
A
Andreas Dilger 已提交
625
   {
626
      png_debug1(1, "in %s retrieval function", "oFFs");
A
Andreas Dilger 已提交
627 628 629 630 631 632 633 634 635
      *offset_x = info_ptr->x_offset;
      *offset_y = info_ptr->y_offset;
      *unit_type = (int)info_ptr->offset_unit_type;
      return (PNG_INFO_oFFs);
   }
   return (0);
}
#endif

636
#if defined(PNG_pCAL_SUPPORTED)
637
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
638 639 640 641
png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
   png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
   png_charp *units, png_charpp *params)
{
642
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
643 644
       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
       nparams != NULL && units != NULL && params != NULL)
A
Andreas Dilger 已提交
645
   {
646
      png_debug1(1, "in %s retrieval function", "pCAL");
A
Andreas Dilger 已提交
647 648 649 650 651 652 653 654 655 656 657 658 659
      *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);
   }
   return (0);
}
#endif

660
#if defined(PNG_sCAL_SUPPORTED)
661
#ifdef PNG_FLOATING_POINT_SUPPORTED
662
png_uint_32 PNGAPI
663
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
664
             int *unit, double *width, double *height)
665
{
666
    if (png_ptr != NULL && info_ptr != NULL &&
667
        (info_ptr->valid & PNG_INFO_sCAL))
668 669 670 671 672 673 674 675
    {
        *unit = info_ptr->scal_unit;
        *width = info_ptr->scal_pixel_width;
        *height = info_ptr->scal_pixel_height;
        return (PNG_INFO_sCAL);
    }
    return(0);
}
676 677
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
678
png_uint_32 PNGAPI
679
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
680
             int *unit, png_charpp width, png_charpp height)
681
{
682
    if (png_ptr != NULL && info_ptr != NULL &&
683
        (info_ptr->valid & PNG_INFO_sCAL))
684 685 686 687 688 689 690 691 692
    {
        *unit = info_ptr->scal_unit;
        *width = info_ptr->scal_s_width;
        *height = info_ptr->scal_s_height;
        return (PNG_INFO_sCAL);
    }
    return(0);
}
#endif
693 694
#endif
#endif
695

696
#if defined(PNG_pHYs_SUPPORTED)
697
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
698 699 700
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
   png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
701 702
   png_uint_32 retval = 0;

703 704
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->valid & PNG_INFO_pHYs))
A
Andreas Dilger 已提交
705
   {
706
      png_debug1(1, "in %s retrieval function", "pHYs");
707

708
      if (res_x != NULL)
709 710
      {
         *res_x = info_ptr->x_pixels_per_unit;
711 712
         retval |= PNG_INFO_pHYs;
      }
713

714 715
      if (res_y != NULL)
      {
716 717 718
         *res_y = info_ptr->y_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
719

720 721 722 723 724
      if (unit_type != NULL)
      {
         *unit_type = (int)info_ptr->phys_unit_type;
         retval |= PNG_INFO_pHYs;
      }
A
Andreas Dilger 已提交
725
   }
726
   return (retval);
A
Andreas Dilger 已提交
727 728 729
}
#endif

730
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
731 732 733
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
   int *num_palette)
{
734 735
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       && palette != NULL)
A
Andreas Dilger 已提交
736
   {
737
      png_debug1(1, "in %s retrieval function", "PLTE");
A
Andreas Dilger 已提交
738 739
      *palette = info_ptr->palette;
      *num_palette = info_ptr->num_palette;
740
      png_debug1(3, "num_palette = %d", *num_palette);
A
Andreas Dilger 已提交
741 742 743 744 745
      return (PNG_INFO_PLTE);
   }
   return (0);
}

746
#if defined(PNG_sBIT_SUPPORTED)
747
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
748 749
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
750 751
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
      && sig_bit != NULL)
A
Andreas Dilger 已提交
752
   {
753
      png_debug1(1, "in %s retrieval function", "sBIT");
A
Andreas Dilger 已提交
754 755 756 757 758 759 760
      *sig_bit = &(info_ptr->sig_bit);
      return (PNG_INFO_sBIT);
   }
   return (0);
}
#endif

761
#if defined(PNG_TEXT_SUPPORTED)
762
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
763 764 765
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
   int *num_text)
{
766
   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
A
Andreas Dilger 已提交
767
   {
768
      png_debug1(1, "in %s retrieval function",
769 770
         (png_ptr->chunk_name[0] == '\0' ? "text"
             : (png_const_charp)png_ptr->chunk_name));
771

A
Andreas Dilger 已提交
772 773
      if (text_ptr != NULL)
         *text_ptr = info_ptr->text;
774

A
Andreas Dilger 已提交
775 776
      if (num_text != NULL)
         *num_text = info_ptr->num_text;
777

778
      return ((png_uint_32)info_ptr->num_text);
A
Andreas Dilger 已提交
779
   }
780 781
   if (num_text != NULL)
     *num_text = 0;
A
Andreas Dilger 已提交
782 783 784 785
   return(0);
}
#endif

786
#if defined(PNG_tIME_SUPPORTED)
787
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
788 789
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
790 791
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       && mod_time != NULL)
A
Andreas Dilger 已提交
792
   {
793
      png_debug1(1, "in %s retrieval function", "tIME");
A
Andreas Dilger 已提交
794 795 796 797 798 799 800
      *mod_time = &(info_ptr->mod_time);
      return (PNG_INFO_tIME);
   }
   return (0);
}
#endif

801
#if defined(PNG_tRNS_SUPPORTED)
802
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
803
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
804
   png_bytep *trans, int *num_trans, png_color_16p *trans_color)
A
Andreas Dilger 已提交
805
{
806
   png_uint_32 retval = 0;
807
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
A
Andreas Dilger 已提交
808
   {
809
      png_debug1(1, "in %s retrieval function", "tRNS");
810
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
A
Andreas Dilger 已提交
811
      {
812 813 814 815 816
          if (trans != NULL)
          {
             *trans = info_ptr->trans;
             retval |= PNG_INFO_tRNS;
          }
817

818 819
          if (trans_color != NULL)
             *trans_color = &(info_ptr->trans_color);
A
Andreas Dilger 已提交
820
      }
821
      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
A
Andreas Dilger 已提交
822
      {
823
          if (trans_color != NULL)
824
          {
825
             *trans_color = &(info_ptr->trans_color);
826 827
             retval |= PNG_INFO_tRNS;
          }
828

829
          if (trans != NULL)
830
             *trans = NULL;
A
Andreas Dilger 已提交
831
      }
832
      if (num_trans != NULL)
A
Andreas Dilger 已提交
833
      {
834 835
         *num_trans = info_ptr->num_trans;
         retval |= PNG_INFO_tRNS;
A
Andreas Dilger 已提交
836 837
      }
   }
838
   return (retval);
A
Andreas Dilger 已提交
839 840 841
}
#endif

842
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
843
png_uint_32 PNGAPI
844 845 846 847
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
             png_unknown_chunkpp unknowns)
{
   if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
848
   {
849
     *unknowns = info_ptr->unknown_chunks;
850 851 852
     return ((png_uint_32)info_ptr->unknown_chunks_num);
   }
   return (0);
853 854 855
}
#endif

856
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
857
png_byte PNGAPI
858 859
png_get_rgb_to_gray_status (png_structp png_ptr)
{
860
   return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
861 862
}
#endif
863

864
#if defined(PNG_USER_CHUNKS_SUPPORTED)
865
png_voidp PNGAPI
866 867
png_get_user_chunk_ptr(png_structp png_ptr)
{
868
   return (png_ptr? png_ptr->user_chunk_ptr : NULL);
869 870 871
}
#endif

872
#ifdef PNG_WRITE_SUPPORTED
873
png_size_t PNGAPI
874 875
png_get_compression_buffer_size(png_structp png_ptr)
{
876
   return (png_ptr ? png_ptr->zbuf_size : 0L);
877
}
878
#endif
879

880 881

#ifdef PNG_SET_USER_LIMITS_SUPPORTED
882
/* These functions were added to libpng 1.2.6 */
883 884 885 886 887 888 889 890 891 892
png_uint_32 PNGAPI
png_get_user_width_max (png_structp png_ptr)
{
    return (png_ptr? png_ptr->user_width_max : 0);
}
png_uint_32 PNGAPI
png_get_user_height_max (png_structp png_ptr)
{
    return (png_ptr? png_ptr->user_height_max : 0);
}
893 894 895 896 897 898 899
/* This function was added to libpng 1.4.0 */
png_uint_32 PNGAPI
png_get_chunk_cache_max (png_structp png_ptr)
{
    return (png_ptr? png_ptr->user_chunk_cache_max? 0x7fffffffL :
       png_ptr->user_chunk_cache_max - 1 : 0);
}
900
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
901

902 903 904 905 906 907 908 909 910 911 912 913 914 915
#ifdef PNG_IO_STATE_SUPPORTED
png_uint_32 PNGAPI
png_get_io_state (png_structp png_ptr)
{
    return png_ptr->io_state;
}

png_bytep PNGAPI
png_get_io_chunk_name (png_structp png_ptr)
{
   return png_ptr->chunk_name;
}
#endif /* ?PNG_IO_STATE_SUPPORTED */

916
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */