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 24, 2009]
5
 * For conditions of distribution and use, see copyright notice in png.h
6
 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 8
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9
 */
A
Andreas Dilger 已提交
10 11

#include "png.h"
12
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
13
#include "pngpriv.h"
14

15
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
16 17
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
{
18
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
19
      return(info_ptr->valid & flag);
20

A
Andreas Dilger 已提交
21 22 23 24
   else
      return(0);
}

25
png_size_t PNGAPI
A
Andreas Dilger 已提交
26 27
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
{
28
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
29
      return(info_ptr->rowbytes);
30

A
Andreas Dilger 已提交
31 32 33 34
   else
      return(0);
}

35
#if defined(PNG_INFO_IMAGE_SUPPORTED)
36
png_bytepp PNGAPI
37 38 39 40
png_get_rows(png_structp png_ptr, png_infop info_ptr)
{
   if (png_ptr != NULL && info_ptr != NULL)
      return(info_ptr->row_pointers);
41

42 43 44 45 46
   else
      return(0);
}
#endif

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

55 56 57
   return (0);
}

58
png_uint_32 PNGAPI
59 60
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{
61
   if (png_ptr != NULL && info_ptr != NULL)
62
      return info_ptr->height;
63

64 65 66
   return (0);
}

67
png_byte PNGAPI
68 69
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
70
   if (png_ptr != NULL && info_ptr != NULL)
71
      return info_ptr->bit_depth;
72

73 74 75
   return (0);
}

76
png_byte PNGAPI
77 78
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
79
   if (png_ptr != NULL && info_ptr != NULL)
80
      return info_ptr->color_type;
81

82 83 84
   return (0);
}

85
png_byte PNGAPI
86 87
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{
88
   if (png_ptr != NULL && info_ptr != NULL)
89
      return info_ptr->filter_type;
90

91 92 93
   return (0);
}

94
png_byte PNGAPI
95 96
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{
97
   if (png_ptr != NULL && info_ptr != NULL)
98
      return info_ptr->interlace_type;
99

100 101 102
   return (0);
}

103
png_byte PNGAPI
104 105
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
106
   if (png_ptr != NULL && info_ptr != NULL)
107
      return info_ptr->compression_type;
108

109 110 111
   return (0);
}

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

121
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
122
          return (0);
123

124 125
      else
          return (info_ptr->x_pixels_per_unit);
126
   }
127 128
#else
   return (0);
129 130 131 132
#endif
   return (0);
}

133
png_uint_32 PNGAPI
134 135
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
136
   if (png_ptr != NULL && info_ptr != NULL)
137
#if defined(PNG_pHYs_SUPPORTED)
138
   if (info_ptr->valid & PNG_INFO_pHYs)
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 (0);
144

145 146
      else
          return (info_ptr->y_pixels_per_unit);
147
   }
148 149
#else
   return (0);
150 151 152 153
#endif
   return (0);
}

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

163
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
164
         info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
165
          return (0);
166

167 168
      else
          return (info_ptr->x_pixels_per_unit);
169
   }
170 171
#else
   return (0);
172 173 174 175
#endif
   return (0);
}

176
#ifdef PNG_FLOATING_POINT_SUPPORTED
177
float PNGAPI
178 179
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
   {
180
   if (png_ptr != NULL && info_ptr != NULL)
181
#if defined(PNG_pHYs_SUPPORTED)
182

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

199
png_int_32 PNGAPI
200 201
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
202
   if (png_ptr != NULL && info_ptr != NULL)
203
#if defined(PNG_oFFs_SUPPORTED)
204

205
   if (info_ptr->valid & PNG_INFO_oFFs)
206
   {
207
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
208

209
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
210
          return (0);
211

212 213
      else
          return (info_ptr->x_offset);
214
   }
215
#else
216
      return (0);
217 218 219 220
#endif
   return (0);
}

221
png_int_32 PNGAPI
222 223
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
224
   if (png_ptr != NULL && info_ptr != NULL)
225

226
#if defined(PNG_oFFs_SUPPORTED)
227
   if (info_ptr->valid & PNG_INFO_oFFs)
228
   {
229
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
230

231
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
232
          return (0);
233

234 235
      else
          return (info_ptr->y_offset);
236
   }
237 238
#else
   return (0);
239 240 241 242
#endif
   return (0);
}

243
png_int_32 PNGAPI
244 245
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
246
   if (png_ptr != NULL && info_ptr != NULL)
247

248
#if defined(PNG_oFFs_SUPPORTED)
249
   if (info_ptr->valid & PNG_INFO_oFFs)
250
   {
251
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
252

253
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
254
          return (0);
255

256 257
      else
          return (info_ptr->x_offset);
258
   }
259 260
#else
   return (0);
261 262 263 264
#endif
   return (0);
}

265
png_int_32 PNGAPI
266 267
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
268
   if (png_ptr != NULL && info_ptr != NULL)
269

270
#if defined(PNG_oFFs_SUPPORTED)
271
   if (info_ptr->valid & PNG_INFO_oFFs)
272
   {
273
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
274

275
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
276
          return (0);
277

278 279
      else
          return (info_ptr->y_offset);
280
   }
281 282
#else
   return (0);
283 284 285 286
#endif
   return (0);
}

287
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
288
png_uint_32 PNGAPI
289 290 291
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)
292
     *.0254 +.5));
293 294
}

295
png_uint_32 PNGAPI
296 297 298
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)
299
     *.0254 +.5));
300 301
}

302
png_uint_32 PNGAPI
303 304 305
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)
306
     *.0254 +.5));
307 308
}

309
float PNGAPI
310 311 312
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
313
     *.00003937);
314 315
}

316
float PNGAPI
317 318 319
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
320
     *.00003937);
321 322
}

323
#if defined(PNG_pHYs_SUPPORTED)
324
png_uint_32 PNGAPI
325 326 327 328 329
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;

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

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

361 362
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

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

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

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

397
#if defined(PNG_cHRM_SUPPORTED)
398
#ifdef PNG_FLOATING_POINT_SUPPORTED
399
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
400 401 402 403
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)
{
404
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
A
Andreas Dilger 已提交
405
   {
406
      png_debug1(1, "in %s retrieval function", "cHRM");
A
Andreas Dilger 已提交
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
      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
428
#ifdef PNG_FIXED_POINT_SUPPORTED
429
png_uint_32 PNGAPI
430
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
431 432 433
   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)
434 435 436
{
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
   {
437
      png_debug1(1, "in %s retrieval function", "cHRM");
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
      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 已提交
460

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

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

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

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

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

560
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
561 562 563 564
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)
565

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

A
Andreas Dilger 已提交
577
      *color_type = info_ptr->color_type;
578

579
      if (info_ptr->color_type > 6)
580 581
         png_error(png_ptr, "Invalid color type");

A
Andreas Dilger 已提交
582 583
      if (compression_type != NULL)
         *compression_type = info_ptr->compression_type;
584

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

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

591
      /* Check for potential overflow of rowbytes */
592
      if (*width == 0 || *width > PNG_UINT_31_MAX)
593
        png_error(png_ptr, "Invalid image width");
594

595
      if (*height == 0 || *height > PNG_UINT_31_MAX)
596
        png_error(png_ptr, "Invalid image height");
597

598 599 600 601 602 603
      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 */
604
      {
605
         png_warning(png_ptr,
606
            "Width too large for libpng to process image data");
607
      }
608

A
Andreas Dilger 已提交
609 610 611 612 613
      return (1);
   }
   return (0);
}

614
#if defined(PNG_oFFs_SUPPORTED)
615
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
616
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
617
   png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
618
{
619 620
   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 已提交
621
   {
622
      png_debug1(1, "in %s retrieval function", "oFFs");
A
Andreas Dilger 已提交
623 624 625 626 627 628 629 630 631
      *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

632
#if defined(PNG_pCAL_SUPPORTED)
633
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
634 635 636 637
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)
{
638
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
639 640
       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
       nparams != NULL && units != NULL && params != NULL)
A
Andreas Dilger 已提交
641
   {
642
      png_debug1(1, "in %s retrieval function", "pCAL");
A
Andreas Dilger 已提交
643 644 645 646 647 648 649 650 651 652 653 654 655
      *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

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

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

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

704
      if (res_x != NULL)
705 706
      {
         *res_x = info_ptr->x_pixels_per_unit;
707 708
         retval |= PNG_INFO_pHYs;
      }
709

710 711
      if (res_y != NULL)
      {
712 713 714
         *res_y = info_ptr->y_pixels_per_unit;
         retval |= PNG_INFO_pHYs;
      }
715

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

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

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

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

A
Andreas Dilger 已提交
768 769
      if (text_ptr != NULL)
         *text_ptr = info_ptr->text;
770

A
Andreas Dilger 已提交
771 772
      if (num_text != NULL)
         *num_text = info_ptr->num_text;
773

774
      return ((png_uint_32)info_ptr->num_text);
A
Andreas Dilger 已提交
775
   }
776 777
   if (num_text != NULL)
     *num_text = 0;
A
Andreas Dilger 已提交
778 779 780 781
   return(0);
}
#endif

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

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

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

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

838
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
839
png_uint_32 PNGAPI
840 841 842 843
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)
844
   {
845
     *unknowns = info_ptr->unknown_chunks;
846 847 848
     return ((png_uint_32)info_ptr->unknown_chunks_num);
   }
   return (0);
849 850 851
}
#endif

852
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
853
png_byte PNGAPI
854 855
png_get_rgb_to_gray_status (png_structp png_ptr)
{
856
   return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
857 858
}
#endif
859

860
#if defined(PNG_USER_CHUNKS_SUPPORTED)
861
png_voidp PNGAPI
862 863
png_get_user_chunk_ptr(png_structp png_ptr)
{
864
   return (png_ptr? png_ptr->user_chunk_ptr : NULL);
865 866 867
}
#endif

868
#ifdef PNG_WRITE_SUPPORTED
869
png_size_t PNGAPI
870 871
png_get_compression_buffer_size(png_structp png_ptr)
{
872
   return (png_ptr ? png_ptr->zbuf_size : 0L);
873
}
874
#endif
875

876 877

#ifdef PNG_SET_USER_LIMITS_SUPPORTED
878
/* These functions were added to libpng 1.2.6 */
879 880 881 882 883 884 885 886 887 888
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);
}
889 890 891 892 893 894 895
/* 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);
}
896
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
897

898 899 900 901 902 903 904 905 906 907 908 909 910 911
#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 */

912
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */